/******** class_resize.php ***********
Creator : Bruno VIBERT
E-mail : bvibert@mytracer.com
Date : 01/20/2003
Version : First and last
Descripton : Copy uploaded image keeping aspect ratio
*********************************/
class resizeImg
{
var $iOrig = array(); // uploaded image
var $iNew = object; // image created object
// Contructor resize( ARRAY postimage [, INT mawWidth, INT maxHeight])
// Resize the uploaded image and sets width and/or height to the maximum
// value, keeping the aspect ratio
// ie resise( var, 100, 50 ) an image that size is 200x50 will return an image of 100x25
function resizeImg(){
}
function resize($fth, $postImage, $maxWidth = 10000, $maxHeight = 10000 )
{
$this -> iOrig = $fth[$postImage];
$this -> type = $this -> imageType( );
$picInfos = getimagesize( $this -> iOrig[ 'tmp_name' ] );
$width = $picInfos[0];
$height = $picInfos[1];
if( $width > $maxWidth & $height <= $maxHeight )
{
$ratio = $maxWidth / $width;
}
elseif( $height > $maxHeight & $width <= $maxWidth )
{
$ratio = $maxHeight / $height;
}
elseif( $width > $maxWidth & $height > $maxHeight )
{
$ratio1 = $maxWidth / $width;
$ratio2 = $maxHeight / $height;
$ratio = ($ratio1 < $ratio2)? $ratio1:$ratio2;
}
else
{
$ratio = 1;
}
$nWidth = floor($width*$ratio);
$nHeight = floor($height*$ratio);
if( $this -> type == 'jpg' )
$origPic = imagecreatefromjpeg( $this->iOrig[ 'tmp_name' ] );
elseif( $this -> type == 'png' )
$origPic = imagecreatefrompng( $this->iOrig[ 'tmp_name' ] );
elseif( $this -> type == 'gif' )
$origPic = imagecreatefromgif( $this->iOrig[ 'tmp_name' ] );
//echo "Width: ".$nWidth." - Height: ".$nHeight;
$this->iNew = imagecreatetruecolor($nWidth,$nHeight);
imagecopyresampled($this->iNew, $origPic, 0, 0, 0, 0, $nWidth, $nHeight, $width, $height);
}
// function imageType(); return JPG/PNG (so cool !)
function imageType( )
{
if( eregi( "jpeg", $this -> iOrig[ 'type' ]) ) // JPG
return "jpg";
elseif( eregi( "png", $this -> iOrig[ 'type' ] ) ) // PNG
return "png";
elseif( eregi( "gif", $this -> iOrig[ 'type' ] ) ) // GIF
return "gif";
}
// function saveTo( STRING name [, STRING path ] )
// save the new image in the specified path, with the specified name
function saveTo( $name = '', $path = "./" )
{
if( empty( $name ) )
echo "name!";
elseif( !is_dir( $path ) )
echo "$path is not a directory!";
else
{
if( $this -> type == 'jpg' ){
@imagejpeg( $this->iNew, $path.$name,100 );
@chmod($path.$name, 0777);
}
elseif( $this -> type == 'png' )
{
@imagepng( $this->iNew, $path.$name );
@chmod($path.$name, 0777);
}
elseif( $this -> type == 'gif' )
{
@imagegif( $this->iNew, $path.$name );
@chmod($path.$name, 0777);
}
}
}
}
?>
/**
* DBLIB Library to abstract the database functions, simply replicates mysql
* functions, easy to run query
* @author: Exa
* @version: 1.2
* @date: 19th July 2003
*
**/
if(!$CFG->innercall){
$strmsg = "!Error occurred while processing your request, \nhowever we have recorded your IP address:".$_SERVER['REMOTE_ADDR'] . " for security/debugging reasons ";
die($strmsg);
}
// connect to the database $dbname on $dbhost with the user/password pair
// $dbuser and $dbpass.
function db_connect($dbhost, $dbname, $dbuser, $dbpass)
{
global $CFG;
$errors_msg = "";
if (! $dbh = mysql_connect($dbhost, $dbuser, $dbpass))
{
if ($CFG->db_debug)
{
$errors_msg .= "
Can't connect to $dbhost as $dbuser ";
$errors_msg .= "MySQL Error: ". mysql_error() . " ";
$CFG->dbstatus = false;
}
else
{
//$errors_msg .= "Database error encountered ";
$CFG->dbstatus = false;
}
if ($CFG->db_die)
{
$errors_msg .= "This script cannot continue, terminating. ";
//print_error($errors_msg);
$CFG->dbstatus = false;
//die();
}
else{
$CFG->dbstatus = false;
}
if(!empty($errors_msg))
print_error($errors_msg);
}
if (! mysql_select_db($dbname))
{
if ($CFG->db_debug)
{
//$errors_msg = "Can't select database $dbname ";
//$errors_msg .= "MySQL Error: ". mysql_error() . " ";
$CFG->dbstatus = false;
}
else
{
//$errors_msg .= "Database error encountered ";
$CFG->dbstatus = false;
}
if ($CFG->db_die)
{
$errors_msg .= "This script cannot continue, terminating.";
//print_error($errors_msg);
$CFG->dbstatus = false;
//die();
}
else{
$CFG->dbstatus = false;
}
}
if(!empty($errors_msg))
//print_error($errors_msg);
return $dbh;
}
// disconnect from the database, we normally don't have to call this function
// because PHP will handle it
function db_disconnect()
{
mysql_close();
}
// run the query $query against the current database. if $debug is true, then
// we will just display the query on screen. if $die_on_debug is true, and
// $debug is true, then we will stop the script after printing he debug message,
// otherwise we will run the query. if $silent is true then we will surpress
// all error messages, otherwise we will print out that a database error has
// occurred
function db_query($query, $debug=false, $die_on_debug=true, $silent=false)
{
global $CFG;
$errors_msg = "";
if ($debug)
{
$errors_msg .= "" . htmlspecialchars($query) . " ";
//print_error($errors_msg);
if ($CFG->db_die) {
//die;
$CFG->dbstatus = false;
}
}
$qid = mysql_query($query);
if (! $qid && ! $silent)
{
if ($CFG->db_debug)
{
$errors_msg .= "Can't execute query \n";
$errors_msg .= "" . htmlspecialchars("".$query) . " \n";
$errors_msg .= "MySQL Error : ". mysql_error();
$err = mysql_error();
//echo $errors_msg;
}
else
{
$errors_msg .= "
Database error encountered ";
$err = mysql_error();
$CFG->dbstatus = false;
}
if ($CFG->db_die)
{
$errors_msg .= "This script cannot continue, terminating";
$err = mysql_error();
//print_error($errors_msg);
//die();
}
else{
$CFG->dbstatus = false;
}
if($errors_msg != ''){
//echo $error_msg;
//echo $err;
mail_db_error($errors_msg,$err);
}
//print_error($errors_msg);
}
return $qid;
}
//grab the next row from the query result identifier $qid, and return it
//as an associative array. if there are no more results, return FALSE
function db_fetch_array($qid)
{
return mysql_fetch_array($qid);
}
// grab the next row from the query result identifier $qid, and return it
// as an array. if there are no more results, return FALSE
function db_fetch_row($qid)
{
return mysql_fetch_row($qid);
}
// grab the next row from the query result identifier $qid, and return it
// as an object. if there are no more results, return FALSE
function db_fetch_object($qid)
{
return mysql_fetch_object($qid);
}
/* return the number of records (rows) returned from the SELECT query with
* the query result identifier $qid. */
function db_num_rows($qid)
{
return mysql_num_rows($qid);
}
/* return the number of rows affected by the last INSERT, UPDATE, or DELETE
* query */
function db_affected_rows()
{
return mysql_affected_rows();
}
/* if you just INSERTed a new row into a table with an autonumber, call this
* function to give you the ID of the new autonumber value */
function db_insert_id()
{
return mysql_insert_id();
}
/* free up the resources used by the query result identifier $qid */
function db_free_result($qid)
{
mysql_free_result($qid);
}
/* return the number of fields returned from the SELECT query with the
* identifier $qid */
function db_num_fields($qid)
{
return mysql_num_fields($qid);
}
/* return the name of the field number $fieldno returned from the SELECT query
* with the identifier $qid */
function db_field_name($qid, $fieldno)
{
return mysql_field_name($qid, $fieldno);
}
/* move the database cursor to row $row on the SELECT query with the identifier
* $qid */
function db_data_seek($qid, $row)
{
if (db_num_rows($qid))
{
return mysql_data_seek($qid, $row);
}
}
function db_get_insert_query($qid_fields, $qid_values, $tableName){
$qid_query = "";
$temp = " INSERT INTO " . $tableName . " ( ";
$temp2 = ") VALUES (";
$temp3 = " ";
if(count($qid_fields) == count($qid_values)){
for($i=0; $i Error:".$error,"From: admin@mountviewestate.com.au");
@mail("kunalgandhi24@gmail.com","Database Error !!, Dte:".date("d/m/Y H:i:s"),"Error Message Displayed:".$msg." Error:".$error,"From: admin@mountviewestate.com.au");
}
function db_get_page($page){
if($page <= 0){
$page = 1;
}
return $page;
}
function db_get_limit($limit){
if(intval($limit) <= 0){
$limit = 10;
}
return intval($limit);
}
function db_get_limitvalue($page, $limit){
return $page * $limit - ($limit);
}
function db_check_orderby($orderBy, $validSortOrders){
if(is_array($validSortOrders)){
if(!in_array($orderBy, $validSortOrders)){
$orderBy = "id";
}
}
return $orderBy;
}
?>
/* Standard Library :: useful functions - MK
* @author: Exa
* @version: 1.0
* @date: 19/07/03
*/
/* if $var is undefined, set it to $default. otherwise leave it alone */
if(!$CFG->innercall){
$strmsg = "!Error occurred while processing your request, \nhowever we have recorded your IP address:".$_SERVER['REMOTE_ADDR'] . " for security/debugging reasons ";
die($strmsg);
}
function setdefault(&$var, $default="")
{
if (!isset($var) || empty($var))
{
$var = $default;
}
}
/* if $var is undefined, return $default, otherwise return $var */
function nvl(&$var, $default="")
{
return isset($var) ? $var : $default;
}
/* returns $var with the HTML characters (like "<", ">", etc.) properly quoted,
* or if $var is undefined, will return an empty string. note this function
* must be called with a variable, for normal strings or functions use o() */
function ov(&$var)
{
return isset($var) ? htmlSpecialChars(stripslashes($var)) : "";
}
/* prints $var with the HTML characters (like "<", ">", etc.) properly quoted,
* or if $var is undefined, will print an empty string. note this function
* must be called with a variable, for normal strings or functions use p() */
function pv(&$var)
{
echo isset($var) ? htmlSpecialChars(stripslashes($var)) : "";
}
function pv_br(&$var)
{
echo isset($var) ? " ".htmlSpecialChars(stripslashes($var)) : "";
}
function pv_comma(&$var)
{
echo isset($var) ? ",".htmlSpecialChars(stripslashes($var)) : "";
}
function pv_lim(&$var, $lim)
{
echo isset($var) ? htmlSpecialChars(stripslashes(substr(($var), 0, $lim)))."..." : "";
}
/*this function can be used to print an entire word if the user has specified a limit
which breaks a single word*/
function pv_lim1(&$var,$lim)
{
//to find the last position of space in a string
$pos1 = strrpos($var," ");
//to get the substring with the specified limit
$substring = htmlSpecialChars(stripslashes(substr(($var), 0, $lim)));
//to check the next char of the string which was returned using the limit specified by the user
$s2 = substr($var,0,$lim+1);
//to get the last position of space in string s2
$pos = strrpos($s2, " ");
//if limit specified by user is greater than pos1 then print the whole string submitted as a parameter
if($lim > $pos1)
{
echo $var;
}//go on checking the next char of the substring returned using the limit specified
else{
if($pos!= $lim)
{
pv_lim1($var,$lim+1);
if($pos== $lim){
break; }
}
else{
echo $s2."...";
}
}
}
function pv_err(&$var)
{
echo "";
echo isset($var) ? (stripslashes($var)) : "";
echo " ";
}
/* returns $var with HTML characters (like "<", ">", etc.) properly quoted,
* or if $var is empty, will return an empty string. */
function o($var)
{
return empty($var) ? "" : htmlSpecialChars(stripslashes($var));
}
/* prints $var with HTML characters (like "<", ">", etc.) properly quoted,
* or if $var is empty, will print an empty string. */
function p($var)
{
echo empty($var) ? "" : htmlSpecialChars(stripslashes($var));
}
/* this is an internal function and normally isn't called by the user. it
* loops through the results of a select query $query and prints HTML
* around it, for use by things like listboxes and radio selections
*
* NOTE: this function uses dblib.php */
function db_query_loop($query, $prefix, $suffix, $found_str, $default="")
{
$output = "";
$result = db_query($query);
while (list($val, $label) = db_fetch_row($result))
{
if (is_array($default)) {
$selected = empty($default[$val]) ? "" : $found_str;
} else {
$selected = $val == $default ? $found_str : "";
}
$output .= "$prefix value='$val' $selected>$label$suffix";
}
return $output;
}
/* generate the statements for a listbox, based on the
* results of a SELECT query ($query). any results that match $default
* are pre-selected, $default can be a string or an array in the case of
* multi-select listboxes. $suffix is printed at the end of each
* statement, and normally is just a line break */
function db_listbox($query, $default="", $suffix=" \n")
{
return db_query_loop($query, "\n")
{
return db_query_loop2($query, " ";
if (!empty($message))
{
echo "$message
";
}
die;
}
/* return a (big) string containing the contents of a template file with all
* the variables interpolated. all the variables must be in the $var[] array or
* object (whatever you decide to use).
*
* WARNING: do not use this on big files!! */
function read_template($filename, &$var)
{
$temp = str_replace("\\", "\\\\", implode("",file($filename)));
$temp = str_replace('"', '\"', $temp);
eval("\$template = \"$temp\";");
return $template;
}
/* if variable is set, set it to the set_value otherwise set it to the
* unset_value. used to handle checkboxes when you are expecting them from
* a form */
function checked(&$var, $set_value = 1, $unset_value = 0)
{
if (empty($var))
{
$var = $unset_value;
} else {
$var = $set_value;
}
}
/* prints the word "checked" if a variable is true, otherwise prints nothing,
* used for printing the word "checked" in a checkbox form input */
function frmchecked(&$var, $true_value = "checked", $false_value = "")
{
if ($var)
{
echo $true_value;
} else {
echo $false_value;
}
}
/**
* Automatic links -- inspired from PhpCollab - MK
* @param string $data Text to parse
* @return newText with links for www, http, mailto, ftp etc.
* @access public
**/
function autoLinks($data , $style)
{
$newText = "";
$lines = explode("\n", $data);
while (list ($key, $line) = each ($lines))
{
$line = eregi_replace("([ \t]|^)www\.", " http://www.", $line);
$line = eregi_replace("([ \t]|^)ftp\.", " ftp://ftp.", $line);
$line = eregi_replace("(http://[^ )\r\n]+)", "\\1 ", $line);
$line = eregi_replace("(https://[^ )\r\n]+)", "\\1 ", $line);
$line = eregi_replace("(ftp://[^ )\r\n]+)", "\\1 ", $line);
$line = eregi_replace("([-a-z0-9_]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)+))", "\\1 ", $line);
if (empty($newText))
{
$newText = $line;
} else {
$newText .= "\n$line";
}
}
return $newText;
}
function debug($msg, $vari)
{
echo "[debug] " . $msg . " => " . $vari . " ";
}
function check_file($src) {
$tmp = find_ext($src);
if (!$tmp) {
if (file_exists($src)) {
return true;
}
} else {
return false;
}
return false;
}
function find_ext($src) {
$t = array();
$t = explode(".", $src);
if(count($t) >= 1){
return $t[1];
}else
{
return false;
}
}
function upload_file($file_object, $file_name, $path) {
if($file_object != "") {
$path .= "/" . $file_name;
$test = move_uploaded_file($file_object, $path);
chmod($path, 0666);
if (file_exists($path)) {
return(true);
}
}
return false;
}
function upload_get_file_name($fth_item, $nid,$upload_path)
{
$filepath = $upload_path;
$imagename = "" ;
$ext = "";
$t = explode(".", $fth_item['name']);
if(count($t) >= 1)
$ext = $t[1];
//echo $ext;
$imagename = $nid . "." . $ext;
if(check_file($filepath."/".$imagename))
{
@unlink($filepath."/".$imagename) ;
upload_file($fth_item['tmp_name'], $imagename, $filepath);
}
else
{
upload_file($fth_item['tmp_name'], $imagename, $filepath);
}
return $imagename;
}
function resize_image($src_path, $width, $ext) {
$original_size = getImageSize($src_path);
print($scr_path);
$height = (($original_size[1] * $width) / $original_size[0]);
if ($ext == "gif") {
$src_img = imagecreatefromgif($src_path);
//$dst_img = imagecreate($width, $height);
//imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $width, $height, imagesx($src_img), imagesy($src_img));
//imagegif($dst_img, $src_path, 100);
}
elseif ($ext == "jpg") {
$src_img = imagecreatefromjpeg($src_path);
}
$dst_img = imagecreatetruecolor($width, $height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, imagesx($src_img), imagesy($src_img));
imagejpeg($dst_img, $src_path, 100);
imagedestroy($src_img);
imagedestroy($dst_img);
}
function check_email($address)
{
/* Check for last character */
$last = substr($address,strlen($address)-1, 1);
if (($last == ".") || ($last == "@")) {
return false;
}
/* Check for first character */
$first = substr($address,0, 1);
if (($first == ".") || ($first == "@")) {
return false;
}
/* Check if contain @ */
$temp = explode("@", $address);
if (count($temp) != 2) {
return false;
}
/* Check if contain .'s */
$temp = explode(".", $address);
if (count($temp) < 2) {
return false;
}
/* Check for individual char */
$illegal_char = array(
"!", "#", "$", "%", "^",
"&", "*", "(", ")", "+",
"=", "|", "\\", "{", "[",
"}", "]", ":", ";", "\"",
"'", "<", ",", ">", "?", "/",
"~", "`"
);
/* Check for a dot just before @ and just after @ */
$temp = explode('@',$address);
$len = strlen($temp[0]);
$char = substr($temp[0],$len,1);
if($char == '.'){
return false;
}
$char = substr($temp[1],0,1);
if($char == '.'){
return false;
}
for ($i = 0; $i";
//print_r($arr);
//echo "";
//echo $val;
if($val == 1){
return true;
}
else{
return false;
}
}
function check_password($pass){
if(empty($pass) || strlen($pass)<3 || strlen($pass)>20){
return false;
}
/* Check for individual char */
$illegal_char = array(
"!", "#", "$", "%", "^",
"&", "*", "(", ")", "+",
"=", "|", "\\", "{", "[",
"}", "]", ":", ";", "\"",
"'", "<", ",", ">", "?", "/",
"~", "`"
);
for ($i = 0; $iFrom = $from;
$mail->FromName = $fromName;
$mail->AddAddress($to, $toName);
if($CFG->debug){
$mail->AddAddress($CFG->siteAdminEmail, $CFG->siteAdminName);
}
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->Body = $htmlContent;
$mail->AltBody = $txtConent;
$mail->Send();
}
function getQryString($total_rows=0, $exArr=array()){
$queryString_prdrec = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "page") == false &&
stristr($param, "total_rows") == false && !in_array(getParamName($param), $exArr)) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_prdrec = "&" . implode("&", $newParams);
}
}
$queryString_prdrec = sprintf("&total_rows=%d%s", $total_rows, $queryString_prdrec);
$queryString_prdrec = str_replace("&&","",$queryString_prdrec);
return $queryString_prdrec;
}
function getParamName($param){
if ($commapos = strpos($param, '='))
{
return substr($param, 0, $commapos);
} else {
return $param;
}
}
function get_dte($format="d/m/Y H:i:s",$dte=""){
$date="";
$dt=array();
if(!empty($dte) && strlen($dte)==14){
$dt['Y'] = substr($dte,0,4);
$dt['m'] = substr($dte,4,2);
$dt['d'] = substr($dte,6,2);
$dt['H'] = substr($dte,8,2);
$dt['i'] = substr($dte,10,2);
$dt['s'] = substr($dte,12,2);
}
$date = date($format, mktime($dt['H'],$dt['i'],$dt['s'],$dt['m'],$dt['d'],$dt['Y']));
return $date;
}
function set_dte($format="d/m/Y H:i:s", $date=""){
$dte="";
if(!empty($date)){
}
return $dte;
}
function upload_get_file_name1($fth_item, $nid,$upload_path)
{
$filepath = $upload_path;
$imagename = "" ;
$ext = "";
$t = explode(".", $fth_item['name']);
if(count($t) >= 1)
$ext = $t[1];
$fn = $t[0];
$imagename = $fn."_".$nid . "." . $ext;
if(check_file($filepath."/".$imagename))
{
@unlink($filepath."/".$imagename) ;
upload_file($fth_item['tmp_name'], $imagename, $filepath);
}
else
{
upload_file($fth_item['tmp_name'], $imagename, $filepath);
}
return $imagename;
}
function days_in_month($_month, $_year)
{
if ($_month == 02) {
return days_in_feb($_year);
} else {
if ($_month == 01 || $_month == 03 || $_month == 05 || $_month == 07 || $_month == 08 || $_month == 10 || $_month == 12) {
return(31);
} else {
return(30);
}
}
}
function days_in_feb($year)
{
// $year must be YYYY
// [gregorian] leap year math :
if ($year < 0) $year++;
$year += 4800;
if (($year % 4) == 0) {
if (($year % 100) == 0) {
if (($year % 400) == 0) {
return(29);
} else {
return(28);
}
} else {
return(29);
}
} else {
return(28);
}
}
/*function generate_ammount($adate , $ddate , $package, $num, $chk_lenght){
//echo $package;
//echo $adate;
//echo $ddate;
if($package == 3 || $package == 2 || $package == 1){ /// Decide Wheter Package is a Wedding or Retreat Accomodation one.
$date_arr = explode('/',$adate); ///Split all dates into months and years and days
$day_arr = $date_arr[0];
$month_arr = $date_arr[1];
$year_arr = $date_arr[2];
$date_dep = explode('/',$ddate);
$day_dep = $date_dep[0];
$month_dep = $date_dep[1];
$year_dep = $date_dep[2];
if($year_arr < $year_dep){
$year = $year_arr+1;
}
//echo $year;
$no_months = ($month_dep - $month_arr); /// Calculate period of stay in number months
if($no_months < 0){
$no_months = 12+$no_months;
}
//echo $no_months;
if($no_months == 0){ /// If gonna stay for less than a month
$days = ($day_dep-$day_arr); // Decide no of days of stay
if($days == 0 ){
$days = 1;
}
if($month_arr == '4' || $month_arr == '5' || $month_arr == '6' || $month_arr == '7' || $month_arr == '8')
{ ///// Decide wheter a peak period stay or slack.
for($i=0; $i<$days; $i++)
{
$day_slack = $day_slack+1;
}
}
else
{
for($i=0; $i<$days; $i++)
{
$day_peak = $day_peak+1;
}
}
}
else{
//echo $no_months;
for($i=0; $i<=$no_months; $i++){
$month_calc = ($month_arr+$i);
if($i == 0 )
{
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_slack = $day_slack+1;
}
}
else
{
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_peak = $day_peak+1;
}
}
}
elseif($i == $no_months)
{
//echo 'in elseif';
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_slack = $day_slack+1;
}
}
else
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_peak = $day_peak+1;
//echo $day_peak;
}
}
}
else
{
if($i == 11){
$year = $year+1;
}
$days_calc = days_in_month($month_calc ,$year);
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
for($j=0; $j<$days_calc; $j++){
$day_slack = $day_slack+1;
}
}
else
{
for($j=0; $j<$days_calc; $j++){
$day_peak = $day_peak+1;
}
}/// End of inner for
}//// End of last else
}//// End of for
}//// End of else
$tot = $day_peak+$day_slack;
//echo $chk_lenght;
//echo $tot;
if($tot > 21){
$_SESSION['too_long'] = 1;
}
//echo $day_peak;
//echo $day_slack;
if($chk_lenght == '0')
{
if($package == 3)
{
$plp = 8;
$ammount = (4000*$day_peak);
$ammount = $ammount+(3300*$day_slack);
return $ammount;
}
elseif($package == 2)
{
$plp = 8;
$ammount = 2200*$day_peak;
$ammount = $ammount+(1760*$day_slack);
return $ammount;
}
elseif($package == 1){
$plp = 8;
$ammount = 1500*$day_peak;
$ammount = $ammount+(1350*$day_slack);
return $ammount;
}
}
else{
//echo 'in else';
return $tot;
}
}
//echo $package;
if($package == 4 ){
//echo 'in main form';
$date_arr = explode('/',$adate);
$day_arr = $date_arr[0];
$month_arr = $date_arr[1];
$year_arr = $date_arr[2];
//print_r($date_arr);
$date_dep = explode('/',$ddate);
$day_dep = $date_dep[0];
$month_dep = $date_dep[1];
$year_dep = $date_dep[2];
if($year_arr < $year_dep){
$year = $year_arr+1;
}
$no_months = ($month_dep - $month_arr);
if($no_months < 0){
$no_months = 12+$no_months;
}
if($no_months == 0){
$days = ($day_dep-$day_arr);
if($days == 0){
$days = 1;
}
//echo $month_arr;
if($month_arr == '4' || $month_arr == '5' || $month_arr == '6' || $month_arr == '7' || $month_arr == '8')
{
for($j=0; $j<$days; $j++)
{
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j),$year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
//echo 'else';
for($j=0; $j<$days; $j++)
{
//echo 'in for';
//echo $month_arr;
//echo $day_arr+$j;
//echo date('Y');
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j), $year_arr));
//echo $date;
//$day_type = date("w", $date);
//echo $day_type;
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
//echo $day_end_peak;
}
else{
$day_start_peak = $day_start_peak+1;
//echo $day_start_peak;
}
}
}
}
else{
//echo $no_months;
for($i=0; $i<=$no_months; $i++){
//echo 'in for';
$month_calc = ($month_arr+$i);
if($i == 0 )
{
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j), $year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
//echo $day_arr;
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j),$year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}
}
elseif($i == $no_months)
{
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_dep, (1+$j), $year_dep));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_dep, (1+$j), $year_dep));
//$day_type = date("w", $date);
//echo 'day type'.$day_type;
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}
}
else
{
if($i == 11){
$year = $year+1;
}
$days_calc = days_in_month($month_calc ,$year);
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, ($month_calc), (1+$j), $year));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_calc, (1+$j), $year));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}/// End of ineer for
}//// End of last else
}//// End of for
}//// Enfd of main loop
$ammount = 0;
if($package == 4)
{
$tot = $day_end_peak+$day_end_slack+$day_start_peak+$day_start_slack;
//echo '>>>'.$tot;
script_debug($tot);
if($tot > 21){
$_SESSION['too_long'] = 1;
}
//$day_end_peak = ceil($day_end_peak/2);
if($day_end_peak > 1){
$day_end_peak = ceil($day_end_peak/2);
}
elseif($day_end_peak > 0){
$day_end_peak = ceil($day_end_peak/2);
$_SESSION['warning'] = 1;
}
if($day_end_slack > 1){
$day_end_slack = ceil($day_end_slack/2);
}
elseif($day_end_slack > 0){
$day_end_slack = ceil($day_end_slack/2);
$_SESSION['warning'] = 1;
}
//$day_end_slack = ceil($day_end_slack/2);
if(($day_start_peak == 1 && $day_end_peak == 0 && $day_end_slack == 0 && $day_start_slack == 0)){
//echo 'in if';
$day_start_peak = 2;
$_SESSION['warning'] = 1;
}
if(($day_start_slack == 1 && $day_end_peak == 0 && $day_end_slack == 0 && $day_start_peak == 0)){
//echo 'in if';
$day_start_slack = 2;
$_SESSION['warning'] = 1;
}
//echo $day_start_peak;
//echo ',,,,'.$day_start_slack;
//echo ',,,'.$day_end_slack;
//echo ',,,'.$day_end_peak;
//// The code below was used for price plan provided in job file v7
//// For Weekdays and months (September - March)
/*if($num <=4){
$ammount = (300*$day_start_peak);
}
else{
$ammount = (300*$day_start_peak);
$cnt = ($num-4);
for($i=0; $i<$cnt; $i++){
$ammount = ($ammount+(75*$day_start_peak));
}
}*/
/// the price plan according to job file v8
//$ammount = $ammount+(500*$day_start_peak);
//// The code below was used for price plan provided in job file v7
//// For Weekdays and months (April - August)
/*if($num <=4){
$ammount = $ammount+(260*$day_start_slack);
}
else{
$ammount = $ammount+(260*$day_start_slack);
$cnt = ($num-4);
for($i=0; $i<$cnt; $i++){
$ammount = ($ammount+(65*$day_start_slack));
}
}*/
/// the price plan according to job file v8
//$ammount = $ammount+(400*$day_start_slack);
//// The code below was used for price plan provided in job file v7
/// For Weekends and months (September - March)
/*if($num <=6){
$ammount = $ammount+(1300*$day_end_peak);
}
else{
$ammount = $ammount+(1300*$day_end_peak);
$cnt = ($num-6);
for($i=0; $i<$cnt; $i++){
$ammount = ($ammount+(190*$day_end_peak));
}
}*/
/// the price plan according to job file v8
//$ammount = $ammount+(1600*$day_end_peak);
//// The code below was used for price plan provided in job file v7
/// For Weekends and months (April - August)
/*if($num <=6){
$ammount = $ammount+(1200*$day_end_slack);
}
else{
$ammount = $ammount+(1200*$day_end_slack);
$cnt = ($num-6);
for($i=0; $i<$cnt; $i++){
$ammount = ($ammount+(120*$day_end_slack));
}
}*/
/// the price plan according to job file v8
//$ammount = $ammount+(1450*$day_end_slack);
/*return $ammount;
}
//// The code below was used for price plan provided in job file v7
/*elseif($package == 1)
{
$tot = $day_end_peak+$day_end_slack+$day_start_peak+$day_start_slack;
script_debug($tot);
if($tot > 21){
$_SESSION['too_long'] = 1;
}
/*echo $day_start_peak;
echo $day_end_peak;
echo $day_start_slack;
echo $day_end_slack;*/
/*$ammount = 0;
for($i=0; $i<$num;$i++){
$ammount = $ammount+(105*$day_end_peak);
}
//echo $ammount;
for($i=0; $i<$num;$i++){
$ammount = $ammount+(90*$day_end_slack);
}
//echo $ammount;
for($i=0; $i<$num;$i++){
$ammount = $ammount+(90*$day_start_peak);
}
for($i=0; $i<$num;$i++){
$ammount = $ammount+(65*$day_start_slack);
}
//script_debug($_SESSION['too_long']);
return $ammount;
} */
/* }
}
*/
function generate_ammount($adate , $ddate , $package, $num, $chk_lenght, $reduce='0'){
global $CFG;
/*echo '';
print_r($CFG);
echo ' ';*/
$reduce = $reduce;
$date_arr = explode('/',$adate);
$day_arr = $date_arr[0];
$month_arr = $date_arr[1];
$year_arr = $date_arr[2];
//print_r($date_arr);
$date_dep = explode('/',$ddate);
$day_dep = $date_dep[0];
$month_dep = $date_dep[1];
$year_dep = $date_dep[2];
if($year_arr < $year_dep){
$year = $year_arr+1;
}
$no_months = ($month_dep - $month_arr);
if($no_months < 0){
$no_months = 12+$no_months;
}
if($no_months == 0){
$days = ($day_dep-$day_arr);
if($days == 0){
$days = 1;
}
//echo $month_arr;
if($month_arr == '4' || $month_arr == '5' || $month_arr == '6' || $month_arr == '7' || $month_arr == '8')
{
for($j=0; $j<$days; $j++)
{
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j),$year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
//echo 'else';
for($j=0; $j<$days; $j++)
{
//echo 'in for';
//echo $month_arr;
//echo $day_arr+$j;
//echo date('Y');
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j), $year_arr));
//echo $date;
//$day_type = date("w", $date);
//echo $day_type;
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
//echo $day_end_peak;
}
else{
$day_start_peak = $day_start_peak+1;
//echo $day_start_peak;
}
}
}
}
else{
//echo $no_months;
for($i=0; $i<=$no_months; $i++){
//echo 'in for';
$month_calc = ($month_arr+$i);
if($i == 0 )
{
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j), $year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
//echo $day_arr;
$days_calc = days_in_month($month_calc ,$year_arr);
$days_calc = ($days_calc-$day_arr)+1;
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_arr, ($day_arr+$j),$year_arr));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}
}
elseif($i == $no_months)
{
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_dep, (1+$j), $year_dep));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
$days_calc = ($day_dep-1);
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_dep, (1+$j), $year_dep));
//$day_type = date("w", $date);
//echo 'day type'.$day_type;
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}
}
else
{
if($i == 11){
$year = $year+1;
}
$days_calc = days_in_month($month_calc ,$year);
if($month_calc == '4' || $month_calc == '5' || $month_calc == '6' || $month_calc == '7' || $month_calc == '8')
{
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, ($month_calc), (1+$j), $year));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_slack = $day_end_slack+1;
}
else{
$day_start_slack = $day_start_slack+1;
}
}
}
else
{
for($j=0; $j<$days_calc; $j++){
$day_type = date('w',mktime(0, 0, 0, $month_calc, (1+$j), $year));
//$day_type = date("w", $date);
if($day_type > 4){
$day_end_peak = $day_end_peak+1;
}
else{
$day_start_peak = $day_start_peak+1;
}
}
}/// End of ineer for
}//// End of last else
}//// End of for
}//// Enfd of main loop
/*echo 'dsp'.$day_start_peak;
echo 'dep'.$day_end_peak;
echo 'dss'.$day_start_slack;
echo 'des'.$day_end_slack;*/
//$day_peak = $day_start_peak+$day_end_peak;
//$day_slack = $day_start_slack+$day_end_slack;
//echo $day_peak;
//echo $day_slack;
if($package == 1 || $package == 2){
$plp = 8;
/*echo 'pprice'.$CFG->cpprice;
echo 'sprice'.$CFG->csprice;
echo 'p day'.$day_peak;
echo 's day'.$day_slack;
echo 'amount'.$ammount;*/
if($day_end_peak%2 > 0 && $day_end_slack == 0){
$day_end_peak = $day_end_peak+1;
}
if($day_end_slack%2 > 0 && $day_end_peak == 0){
$day_end_slack = $day_end_slack+1;
}
$ammount = $ammount+(($CFG->ppprice/2)*$day_end_peak);
//echo 'amo1'.$ammount;
$ammount = $ammount+(($CFG->psprice/2)*$day_end_slack);
//echo $CFG->psprice;
//echo 'amo2'.$ammount;
$ammount = $ammount+($CFG->cpprice*$day_start_peak);
//echo 'amo3'.$ammount;
$ammount = $ammount+($CFG->csprice*$day_start_slack);
//echo 'amo4'.$ammount;
//echo '..'.$CFG->csprice;
//echo $ammount;
return $ammount;
}
if($chk_lenght == '0')
{
if($package != 1)
{
$tot = $day_end_peak+$day_end_slack+$day_start_peak+$day_start_slack;
//echo '>>>'.$tot;
script_debug($tot);
if($tot > 21){
$_SESSION['too_long'] = 1;
}
if($reduce == 1){
if($day_end_peak == 1 && $day_start_peak ==0 && $day_end_slack == 0 && $day_start_slack == 0){
$day_end_peak = 2;
if($package != 2 || $package != 3)
$_SESSION['warning'] = 1;
}
if($day_end_slack == 1 && $day_start_peak == 1 && $day_end_peak == 0 && $day_start_slack == 0){
$day_end_slack = 2;
if($package != 2 || $package != 3)
$_SESSION['warning'] = 1;
}
if(($day_start_peak == 1 && $day_end_peak == 0 && $day_end_slack == 0 && $day_start_slack == 0)){
$day_start_peak = 2;
$_SESSION['warning'] = 1;
}
if(($day_start_slack == 1 && $day_end_peak == 0 && $day_end_slack == 0 && $day_start_peak == 0)){
echo 'in if';
$day_start_slack = 2;
$_SESSION['warning'] = 1;
}
$tot = $day_start_peak+$day_end_peak+$day_start_slack+$day_end_slack;
//echo $tot;
$val = floor($tot/6);
if($val >= 1){
if($day_start_slack > 1){
$day_start_slack = $day_start_slack-$val;
}
elseif($day_start_peak>1){
$day_start_peak = $day_start_peak-$val;
}
elseif($day_end_slack > 1){
$day_end_slack = $day_end_slack-$val;
}
elseif($day_end_peak>1){
$day_end_peak = $day_end_peak-$val;
}
}
}
/*echo 'pprice'.$CFG->cpprice;
echo 'sprice'.$CFG->csprice;
echo 'p day'.$day_peak;
echo 's day'.$day_slack;
echo 'amount'.$ammount;*/
$ammount = $ammount+(($CFG->awpeak/2)*$day_start_peak);
//echo '1'.$ammount.'';
$ammount = $ammount+(($CFG->awslack/2)*$day_start_slack);
echo $day_start_slack;
echo $CFG->awslack;
echo '2'.$ammount.'';
$ammount = $ammount+(($CFG->aepeak/2)*$day_end_peak);
//echo '3'.$ammount.'';
$ammount = $ammount+(($CFG->aeslack/2)*$day_end_slack);
//echo '4'.$ammount;
return $ammount;
}
else{
//echo 'in else';
return $tot;
}
}
}
function get_date_ymd($dte)
{
$qdate = explode("/", $dte);
return $qdate[2].$qdate[1].$qdate[0];
}
function script_debug($msg){
global $CFG;
if($CFG->scriptDebug){
echo $msg;
}
}
function return_value($val){
if($val == ''){
return 'N/A';
}
else{
return $val;
}
}
?>