MOON
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4
System: Linux vps.panamaemb.org.sg 3.10.0-1160.80.1.vz7.191.4 #1 SMP Thu Dec 15 20:31:06 MSK 2022 x86_64
User: panama (500)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: /home/panama/public_html_old/include/functions/function.php
<?
/*
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Please do not edit this class or any variable.
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
*/
	class functions
	{
		// Function to get Clients Machine IP Address
		function getRealIpAddr()
		{
			if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
			{
			  $ip=$_SERVER['HTTP_CLIENT_IP'];
			}
			elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
			{
			  $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
			}
			else
			{
			  $ip=$_SERVER['REMOTE_ADDR'];
			}
			return $ip;
		}
		
		//function to find country and city from IP address		
		function countryCityFromIP($ipAddr)
		{
			//verify the IP address for the
			ip2long($ipAddr)== -1 || ip2long($ipAddr) === false ? trigger_error("Invalid IP", E_USER_ERROR) : "";
			$ipDetail=array(); //initialize a blank array
			
			//get the XML result from hostip.info
			$xml = file_get_contents("http://api.hostip.info/?ip=".$ipAddr);
			
			//get the city name inside the node <gml:name> and </gml:name>
			preg_match("@<Hostip>(\s)*<gml:name>(.*?)</gml:name>@si",$xml,$match);
			
			//assing the city name to the array
			$ipDetail['city']=$match[2]; 
			
			//get the country name inside the node <countryName> and </countryName>
			preg_match("@<countryName>(.*?)</countryName>@si",$xml,$matches);
			
			//assign the country name to the $ipDetail array
			$ipDetail['country']=$matches[1];
			
			//get the country name inside the node <countryName> and </countryName>
			preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
			$ipDetail['country_code']=$cc_match[1]; //assing the country code to array
			
			//return the array containing city, country and country code
			return $ipDetail;
		}
		
		// function to return part of the day
		function findPartOfDay($date='') {
			if($date != '') {
				$date = explode(" ", $date);
				$h    = substr($date[1],0,2);
			} 
			if($h=='') { $h = date("H"); }
			if($h < 12) { $partOfDay = "Morning"; } 
			elseif($h > 11 && $h < 18) { $partOfDay = "Afternoon"; } 
			elseif($h > 17) { $partOfDay = "Evening"; }
			return $partOfDay;
		}
		
		//sql injection for invalid inputs.
		function anti_injection($dirty)
		{
			if (get_magic_quotes_gpc()) 
			{
				$clean = mysql_real_escape_string(stripslashes($dirty));
			}else{
				$clean = mysql_real_escape_string($dirty);
			}
			return $clean;
		}	
		
		//currently call this function in connection.php file 
		function setPageSession($value='')
		{
			$filename = rtrim(basename($_SERVER['PHP_SELF']));
			//get group id
			$db = new database();
			$db->where("ag_filename='".$filename."'");
			$db->selectstmt("admin_group");
			return $db->{$value};
		}
		
		
		function isValidJpeg($image,$size=0,$mb=5)
		{
			if (($image == "image/pjpeg") || ($image == "image/jpg") || ($image == "image/jpeg"))
				return 1;
			else
				return 0;
		}		
		
		function isValidImage($image,$size=0,$mb=5)
		{
			if(ceil($size/1024000) < $mb)
			{
				if (($image == "image/gif") || ($image == "image/jpeg") || ($image == "image/pjpeg") 	|| ($image == "image/jpg") || ($image == "image/png"))
				return 1;
			else
				return 0;
			}
			else
			{
				return 0;
			}
		}
		
		function isValidPDF($name,$type)
		{
			$filename = basename($name);
			$ext = substr($filename, strrpos($filename, '.') + 1);
			if (($ext == "pdf" or $ext == "PDF")  && ($type == "application/pdf"))
				return 1;
			else
				return 0;
		}
		
		function unlink($path)
		{
			if(is_file($path))
				unlink($path);
		}
		
		function showPaging($pages=1,$numofpages=0,$page=0,$filename='',$class='WhiteLink',$displayPages=10,$link='pages,page')
		{
			if($numofpages > 0)
			{
				$displayPages = $displayPages; 
				//$displayPages = 2; 
				
				$link = split(",",$link);
				
				if(strlen(trim($filename)) > 0)
				{			
					$file = split("-",$filename);
					if(sizeof($file) == 1)
					{
						$_file = $file[0]."?";
					}
					else
					{
						for($m=1;$m<sizeof($file);$m++)	{	$fn.= $file[$m]."&";	}
						$_file = $file[0]."?".$fn;
					}
				}
	
				$__page = "<div style=\"padding:0px 10px 0px 0px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;color:#999999;\">Page ";
				
				if($pages > 1)
				{
					$pageprev = $pages-$displayPages;
					$pp = "<a href=".$_file.$link[0]."=".$pageprev."&".$link[1]."=".($page-1)." class='$class'>PREV</a>&nbsp;";
				}
				
	
				for($i = $pages; $i < $pages + $displayPages; $i++)
				{
					if($i <= $numofpages) 
					{
						//$selectedPage = (($page == $i)?"style='text-decoration:underline; font-weight:bold;'":"");
										
						$__Paging.= "<a href=".$_file.$link[0]."=".$pages."&".$link[1]."=".$i." $selectedPage class='$class'>$i</a>&nbsp;";
					}
				}
				

				echo $__page.$__Paging.$__total."of ".$numofpages."</div>";
				
				if($pages + $displayPages <= $numofpages)
				{
					$pagenext = ($pages + $displayPages);
					$pn = "<a href=".$_file.$link[0]."=".$pagenext."&".$link[1]."=".($page+1)." class='$class'>NEXT</a>";
				}
				
				echo "<div style=\"padding:5px 10px 0px 0px;\">".$pp.$pn."</div>";
			}
		}
		
		function Paging($tbl_name,$targetpage,$limit,$page)
		{
			
			//$tbl_name="shopitup_productmaster";		//your table name
			// How many adjacent pages should be shown on each side?
			$adjacents = 3;
			
			/* 
			   First get total number of rows in data table. 
			   If you have a WHERE clause in your query, make sure you mirror it here.
			*/
			$query = "SELECT COUNT(*) as num FROM $tbl_name";
			$total_pages = mysql_fetch_array(mysql_query($query));
			$total_pages = $total_pages[num];
			
			/* Setup vars for query. */
			//$targetpage = "paging.php"; 	//your file name  (the name of this file)
			//$limit = 2; 								//how many items to show per page
			//$page = $_GET['page'];
			if($page) 
				$start = ($page - 1) * $limit; 			//first item to display on this page
			else
				$start = 0;								//if no page var is given, set start to 0
			
			/* Get data. */
			$sql = "SELECT productname FROM $tbl_name LIMIT $start, $limit";
			$result = mysql_query($sql);
			
			/* Setup page vars for display. */
			if ($page == 0) $page = 1;					//if no page var is given, default to 1.
			$prev = $page - 1;							//previous page is page - 1
			$next = $page + 1;							//next page is page + 1
			$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
			$lpm1 = $lastpage - 1;						//last page minus 1			
			
			$pagination = "";
			if($lastpage > 1)
			{	
				$pagination .= "<div class=\"pagination\">";
				//previous button
				if ($page > 1) 
					$pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
				else
					$pagination.= "<span class=\"disabled\">« previous</span>";	
				
				//pages	
				if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
				{	
					for ($counter = 1; $counter <= $lastpage; $counter++)
					{
						if ($counter == $page)
							$pagination.= "<span class=\"current\">$counter</span>";
						else
							$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
					}
				}
				elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
				{
					//close to beginning; only hide later pages
					if($page < 1 + ($adjacents * 2))		
					{
						for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
						}
						$pagination.= "...";
						$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
						$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
					}
					//in middle; hide some front and some back
					elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
					{
						$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
						$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
						$pagination.= "...";
						for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
						}
						$pagination.= "...";
						$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
						$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
					}
					//close to end; only hide early pages
					else
					{
						$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
						$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
						$pagination.= "...";
						for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
						{
							if ($counter == $page)
								$pagination.= "<span class=\"current\">$counter</span>";
							else
								$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";					
						}
					}
				}
				
				//next button
				if ($page < $counter - 1) 
					$pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
				else
					$pagination.= "<span class=\"disabled\">next »</span>";
				$pagination.= "</div>\n";		
			}			
			echo $pagination;
		}
		
		function showAjaxPaging($pages=1,$numofpages=0,$page=0,$filename='',$class='WhiteLink',$displayPages=10)
		{
			$displayPages = $displayPages; 
			//$displayPages = 2; 
			
			if(strlen(trim($filename)) > 0)
			{			
				$file = split("-",$filename);
				if(sizeof($file) == 1)
				{
					$_file = $file[0]."?";
				}
				else
				{
					for($m=1;$m<sizeof($file);$m++)	{	$fn.= $file[$m]."&";	}
					$_file = $file[0]."?".$fn;
				}
			}
						
			if($pages > 1)
			{
				$pageprev = $pages-$displayPages;
				echo ("<a href=\"#\" class='$class' onclick=\"javascript:MyClass.MyAjaxPaging('".$_file."pages=".$pageprev."','MyAjax',1)\">PREV</a>");
			}
			
			for($i = $pages; $i < $pages + $displayPages; $i++)
			{
				if($i <= $numofpages) 
				{
					$selectedPage = (($page == $i)?"style='text-decoration:underline; font-weight:bold;'":"");
					echo("<a href=\"javascript:MyClass.MyAjaxPaging('".$_file."pages=".$pages."&page=".$i."','MyAjax',1);\" $selectedPage class='$class'>$i</a>&nbsp;");
				}
			}
			
			if($pages + $displayPages <= $numofpages)
			{
				$pagenext = ($pages + $displayPages);
				echo ("<a href=\"#\" class='$class' onclick=\"javascript:MyClass.MyAjaxPaging('".$_file."pages=".$pagenext."','MyAjax',1)\">NEXT</a>");
			}
		}	

		//for show time range for ex: 	Posted 1 hour ago.
		function insert_time_range($info)
		{
		
			//echo $info;
			$present=time();
			$addtime=$info;
			$interval=$present-$addtime;
			if($interval>0)
			{
				$day=$interval/(60*60*24);
				if($day>=1) {$range=floor($day)." days ";$interval=$interval-(60*60*24*floor($day));}
				if($interval>0 && $range=="")
				{
					$hour=$interval/(60*60);
					if($hour>=1) {$range=floor($hour)." hours ";$interval=$interval-(60*60*floor($hour));}
				}
				if($interval>0 && $range=="")
				{
					$min=$interval/(60);
					if($min>=1) {$range=floor($min)." minutes ";$interval=$interval-(60*floor($min));}
				}
				if($interval>0 && $range=="")
				{
					$scn=$interval;
					if($scn>=1) {$range=$scn." seconds ";}
				}
				if($range!="")$range=$range." ago"; else $range="just now";
				{
					//echo $range;
					return $range;
				}
			}
		}

	function rotatePix($sourcefile, $targetfile, $degrees)
	{
		$img_size = getImageSize($sourcefile);
		$x = $img_size[0];
		$y = $img_size[1];
		if ($x > $y)
		{
				$dst_x = 0;
				$dst_y = $x - $y;
				$newd = $x;
		}
		else
		{
				$dst_x = $y - $x;
				$dst_y = 0;
				$newd = $y;
		}
		$src_img = ImageCreateFromJPEG($sourcefile);
		$dst_img = ImageCreateTrueColor($newd,$newd);
		
		if ((($x > y) && ($degrees < 180)) || (($y > $x) && ($degrees > 180)))
				ImageCopyResampled($dst_img,$src_img,0,0,0,0,$x,$y,$x,$y);
		else
				ImageCopyResampled($dst_img,$src_img,$dst_x,$dst_y,0,0,$x,$y,$x,$y);
		
		$bgColour = 0;
		$rotated_img = ImageRotate($dst_img, $degrees,$bgColour);
		
		if ($degrees != 180)
		{
				//90 CounterClockWise or Clockwise
				$final_img = ImageCreateTrueColor($y,$x);
				ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$y,$x,$y,$x);
		}
		else
		{
				//180 Degrees
				$final_img = ImageCreateTrueColor($x,$y);
				ImageCopyResampled($final_img,$rotated_img,0,0,0,0,$x,$y,$x,$y);
		}
		ImageJPEG($final_img, $targetfile);     
	}

	function image_resize_jpeg($img_source, $img_dest, $img_quality, $size_limit,$limit=0)//, $watermark)
	{
			$image = @getImageSize($img_source);
			$img_flg=$image[2];
			/*print_r($image);
			echo $image[2];
			die();
			*/
		if ( !file_exists( $img_source ) )
		{
			return (1); //file not found return 1
		}
		
		// increase the $size_limit variable by 1 as it is going to be chopped by 1 below
		$size_limit++;
		
		//load the original image and put its hieght/width in $img_info
		$img_info = @getimagesize ( $img_source ); 
		
		//$img_info ARRAY KEY
		//0 = width
		//1 = hieght
		//2 = image type
		//3 = hight and width string
		$orig_height = $img_info[1]; //source hieght from $img_info	 
		$orig_width = $img_info[0]; //source width from $img_info


		$jpegQuality = $img_quality; //quality of the JPG
		
		//if(($orig_width > $size_limit) || ($orig_height > $size_limit)) //make sure the image isnt already resized
		//{ 
		if ( $orig_height > $orig_width )
			$scaledown = $orig_height;
		else
			$scaledown = $orig_width;
		$newscale = $size_limit / $scaledown; //set the new scale size
		
		//calculate the new aspect ratio
		$new_w = (int)abs($orig_width * $newscale);
		$new_h = (int)abs($orig_height * $newscale);

		//echo $this->imageResize($orig_width,$orig_height,$size_limit);
		if($new_h > $orig_height)
			$new_h = $orig_height;
			
		if($new_w > $orig_width)
			$new_w = $orig_width;

		if($limit > 0)
		{
			if($orig_height > $limit)
				$new_h = $size_limit;
				
			if($orig_width > $limit)
				$new_w = $size_limit;
		}
						
		//create the blank limited-palette image
		// $base_image = imageCreate($new_w, $new_h);//For Local
		$base_image = ImageCreateTrueColor($new_w, $new_h);//For server 
		
		//convert and save it to temp.jpg
		$tmpfname = tempnam ("/tmp", "FOO"); 
		
		if($img_flg=='1')
		{
			imagegif($base_image, $tmpfname);
			imagedestroy($base_image);
			//get the image pointer to the temp jpeg
			$image = imageCreateFromgif($tmpfname);
			// get the image pointer to the original image
			$imageToResize = imageCreateFromgif("$img_source");
			imageCopyResampled($image, $imageToResize, 0, 0, 0, 0, $new_w, $new_h, $orig_width, $orig_height);// For Server
			$new_image = ImageCreateTrueColor($new_w - 1, $new_h - 1);//For Server
			imagecopy ($new_image, $image, 0, 0, 0, 0, $new_w - 1, $new_h - 1);
			imagegif($new_image, "$img_dest", $jpegQuality); //image destination
		}
		
		if($img_flg=='2')
		{
			imagejpeg($base_image, $tmpfname);
			imagedestroy($base_image);
			//get the image pointer to the temp jpeg
			$image = imageCreateFromJpeg($tmpfname);
			// get the image pointer to the original image
			$imageToResize = imageCreateFromJpeg("$img_source");
			imageCopyResampled($image, $imageToResize, 0, 0, 0, 0, $new_w, $new_h, $orig_width, $orig_height);// For Server
			$new_image = ImageCreateTrueColor($new_w - 1, $new_h - 1);//For Server
			imagecopy ($new_image, $image, 0, 0, 0, 0, $new_w - 1, $new_h - 1);
			imageJpeg($new_image, "$img_dest", $jpegQuality); //image destination
		}
		
		if($img_flg=='3')
		{
			imagepng($base_image, $tmpfname);
			imagedestroy($base_image);
			//get the image pointer to the temp jpeg
			$image = imagecreatefrompng($tmpfname);
			// get the image pointer to the original image
			$imageToResize = imagecreatefrompng("$img_source");
			imageCopyResampled($image, $imageToResize, 0, 0, 0, 0, $new_w, $new_h, $orig_width, $orig_height);// For Server
			$new_image = ImageCreateTrueColor($new_w - 1, $new_h - 1);//For Server
			imagecopy ($new_image, $image, 0, 0, 0, 0, $new_w - 1, $new_h - 1);
			imagepng($new_image, "$img_dest", $jpegQuality); //image destination
		}
		
		
		imagedestroy($image);
		imagedestroy($new_image);
		imagedestroy($imageToResize);
		unlink($tmpfname); //del the temp image file
		return (2); //completed successfully
		//}
		//else
		// {
		//   return(3); //errors occured
		//}
	} // end of function image_resize_jpeg

		function send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments=false)
		{
			$eol="\r\n";
			$mime_boundary=md5(time());
			
			# Common Headers
			$headers .= 'From: webminds <'.$fromaddress.'>'.$eol;
			$headers .= 'Reply-To: webminds <'.$fromaddress.'>'.$eol;
			$headers .= 'Return-Path: webminds <'.$fromaddress.'>'.$eol;    // these two to set reply address
			$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
			$headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters
			
			# Boundry for marking the split & Multitype Headers
			$headers .= 'MIME-Version: 1.0'.$eol;
			$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
			
			$msg = "";     
			
			if ($attachments !== false)
			{
				for($i=0; $i < count($attachments); $i++)
				{
					if (is_file($attachments[$i]["file"]))
					{ 
						# File for Attachment
						$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1));
						
						$handle=fopen($attachments[$i]["file"], 'rb');
						$f_contents=fread($handle, filesize($attachments[$i]["file"]));
						$f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
						fclose($handle);
						
						# Attachment
						$msg .= "--".$mime_boundary.$eol;
						$msg .= "Content-Type: ".$attachments[$i]["content_type"]."; name=\"".$file_name."\"".$eol;
						$msg .= "Content-Transfer-Encoding: base64".$eol;
						$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
						$msg .= $f_contents.$eol.$eol;
					}
				}
			}
			# Setup for text OR html
			$msg .= "Content-Type: multipart/alternative".$eol;
			
			# Text Version
			$msg .= "--".$mime_boundary.$eol;
			$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
			$msg .= "Content-Transfer-Encoding: 8bit".$eol;
			$msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
			
			# HTML Version
			$msg .= "--".$mime_boundary.$eol;
			$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
			$msg .= "Content-Transfer-Encoding: 8bit".$eol;
			$msg .= $body.$eol.$eol;
			
			# Finished
			$msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.
			
			# SEND THE EMAIL
			ini_set(sendmail_from,$fromaddress);  // the INI lines are to force the From Address to be used !
			mail($emailaddress, $emailsubject, $msg, $headers);
			ini_restore(sendmail_from);
		}
		
		function dir_opration($name,$flag=1)
		{
			if($flag==1)
			{
				if(!is_dir($name))
				{
					@mkdir($name,0777);
					//chmod($name,0777);
				}
			}
			else
			{
				if(!is_dir($name))
				{
					deldir($name);
				}
			}

		}
		
		function deldir($dir)
		{
		$current_dir = opendir($dir);
		 while($entryname = readdir($current_dir))
		 {
		   if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!=".."))
		   {
			   deldir("${dir}/${entryname}");
			}
			elseif($entryname != "." and $entryname!="..")
			{
			   unlink("${dir}/${entryname}");
			}
		 }
		 closedir($current_dir);
		 rmdir(${dir});
		}

		/*
		$interval can be:
		yyyy - Number of full years
		q - Number of full quarters
		m - Number of full months
		y - Difference between day numbers
		(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
		d - Number of full days
		w - Number of full weekdays
		ww - Number of full weeks
		h - Number of full hours
		n - Number of full minutes
		s - Number of full seconds (default)
		*/
		
		function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
		
		/*
		$interval can be:
		yyyy - Number of full years
		q - Number of full quarters
		m - Number of full months
		y - Difference between day numbers
		(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
		d - Number of full days
		w - Number of full weekdays
		ww - Number of full weeks
		h - Number of full hours
		n - Number of full minutes
		s - Number of full seconds (default)
		*/

		if (!$using_timestamps) 
		{
			$datefrom = strtotime($datefrom, 0);
			$dateto = strtotime($dateto, 0);
		}
		
		$difference = $dateto - $datefrom; // Difference in seconds
		
		switch($interval) 
		{
			case 'yyyy': // Number of full years
			$years_difference = floor($difference / 31536000);
			if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) 
			{
				$years_difference--;
			}
			if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) 
			{
				$years_difference++;
			}
				$datediff = $years_difference;
			break;
		
			case "q": // Number of full quarters
		
				$quarters_difference = floor($difference / 8035200);
				while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) 
				{
					$months_difference++;
				}
				$quarters_difference--;
				$datediff = $quarters_difference;
				break;
		
		case "m": // Number of full months
		
		$months_difference = floor($difference / 2678400);
		while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
		$months_difference++;
		}
		$months_difference--;
		$datediff = $months_difference;
		break;
		
		case 'y': // Difference between day numbers
		
		$datediff = date("z", $dateto) - date("z", $datefrom);
		break;
		
		case "d": // Number of full days
		
		$datediff = floor($difference / 86400);
		break;
		
		case "w": // Number of full weekdays
		
		$days_difference = floor($difference / 86400);
		$weeks_difference = floor($days_difference / 7); // Complete weeks
		$first_day = date("w", $datefrom);
		$days_remainder = floor($days_difference % 7);
		$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
		if ($odd_days > 7) { // Sunday
		$days_remainder--;
		}
		if ($odd_days > 6) { // Saturday
		$days_remainder--;
		}
		$datediff = ($weeks_difference * 5) + $days_remainder;
		break;
		
		case "ww": // Number of full weeks
		
		$datediff = floor($difference / 604800);
		break;
		
		case "h": // Number of full hours
		
		$datediff = floor($difference / 3600);
		break;
		
		case "n": // Number of full minutes
		
		$datediff = floor($difference / 60);
		break;
		
		default: // Number of full seconds (default)
		
		$datediff = $difference;
		break;
		}
		
		return $datediff;
		
		}
	}
?>