<?php

 function imagecrop($img_name,$newname,$type,$modwidth,$modheight)

{



	    list($width, $height) = getimagesize($img_name) ;



          $tn = imagecreatetruecolor($modwidth, $modheight) ; 

	if(!strcmp("image/png",$type))

	{

	imagealphablending($tn, false);

	imagesavealpha($tn, true);  

	}

		  

		  



   if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))

        $src_img=imagecreatefromjpeg($img_name);



    if(!strcmp("image/png",$type))

        $src_img=imagecreatefrompng($img_name);



    if(!strcmp("image/gif",$type))

        $src_img=imagecreatefromgif($img_name);



          imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

		  

		  

   if(!strcmp("image/png",$type))  

   {

   imagesavealpha($src_img, true);

   $ok=imagepng($tn,$newname);

   }

   else if(!strcmp("image/gif",$type))  

   {

   $ok=imagegif($tn,$newname);

   }

   else 

   {

   $ok=imagejpeg($tn,$newname);

   }



if($ok==1)

  {

//	header('location:?type='.$_GET['type']);

  }

} 



function menucrop($img_name,$newname,$type,$filename)

{



list($width, $height) = getimagesize($img_name) ;

$modwidth=140;

$modheight=37;

          $tn = imagecreatetruecolor($modwidth, $modheight) ; 

	if(!strcmp("image/png",$type))

	{

	imagealphablending($tn, false);

	imagesavealpha($tn, true);  

	}

		  



   if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))

        $src_img=imagecreatefromjpeg($img_name);



    if(!strcmp("image/png",$type))

        $src_img=imagecreatefrompng($img_name);



    if(!strcmp("image/gif",$type))

        $src_img=imagecreatefromgif($img_name);



          imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

		  

		  

   if(!strcmp("image/png",$type))  

   {

   imagesavealpha($src_img, true);

   $ok=imagepng($tn,$newname);

   }

   else if(!strcmp("image/gif",$type))  

   {

   $ok=imagegif($tn,$newname);

   }

   else 

   {

   $ok=imagejpeg($tn,$newname);

   }

   if(isset($_GET['id']))

   {

   unlink($filename);

mysql_query("UPDATE astro_menus SET menu_path='".$newname."',title='".$_POST['title']."',description='".$_POST['desc']."' where cid='".$_GET['id']."'");

	unlink($img_name);

   }

   else

   {

	mysql_query("INSERT INTO astro_menus (menu_path,title,description) VALUES ('".$newname."','".$_POST['title']."','".$_POST['desc']."')");

	unlink($img_name);

   }

	header("location:menumanager.php");

} 



function logocrop($img_name,$newname,$type)

{

list($width, $height) = getimagesize($img_name) ;

$modwidth=352;

$modheight=168;



    $tn = imagecreatetruecolor($modwidth, $modheight) ;

	if(!strcmp("image/png",$type))

	{

	imagealphablending($tn, false);

	imagesavealpha($tn, true);  

	}





   if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))

        $src_img=imagecreatefromjpeg($img_name);



    if(!strcmp("image/png",$type))

	{

        $src_img=imagecreatefrompng($img_name);

		imagealphablending($src_img, true);

	}



    if(!strcmp("image/gif",$type))

        $src_img=imagecreatefromgif($img_name);



          imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 

		  

		  

   if(!strcmp("image/png",$type))  

   {

   imagesavealpha($src_img, true);

   $ok=imagepng($tn,$newname);

   }

   else if(!strcmp("image/gif",$type))  

   {

   $ok=imagegif($tn,$newname);

   }

   else 

   {

   $ok=imagejpeg($tn,$newname);

   }

	mysql_query("INSERT INTO astro_front_page (f_name,f_loc,f_type) VALUES ('logo','".$newname."','logo')");

	unlink($img_name);

}



function swapsort($order,$hide,$table,$column1,$column2)

{

	if(is_array($order) && is_array($hide))

	{

		for($i=0;$i<count($order);$i++)

		{

		$have_order=$have_order."$order[$i],";

		$have_hide=$have_hide."$hide[$i],";

		mysql_query("UPDATE ".$table." SET ".$column1."='".$order[$i]."' WHERE ".$column2."='".$hide[$i]."'");

			if(mysql_errno()=='1062')

			{

			$_SESSION['sort_error']="Cannot Modify,Because Dublicate Sort ID";

			}

		}

	}

}



function charset_decode_utf_8 ($string) 

{

    if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))

        return $string;



    // decode three byte unicode characters

    $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",       

    "'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",   

    $string);



    // decode two byte unicode characters

    $string = preg_replace("/([\300-\337])([\200-\277])/e",

    "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",

    $string);



    return $string;

}



class usersOnline {



	var $timeout = 600;

	var $count = 0;

	var $error;

	var $i = 0;

	

	function usersOnline () {

		$this->timestamp = time();

		$this->ip = $this->ipCheck();

		$this->new_user();

		$this->delete_user();

		$this->count_users();

	}

	

	function ipCheck() {

if (getenv('HTTP_CLIENT_IP')) {

			$ip = getenv('HTTP_CLIENT_IP');

		}

		elseif (getenv('HTTP_X_FORWARDED_FOR')) {

			$ip = getenv('HTTP_X_FORWARDED_FOR');

		}

		elseif (getenv('HTTP_X_FORWARDED')) {

			$ip = getenv('HTTP_X_FORWARDED');

		}

		elseif (getenv('HTTP_FORWARDED_FOR')) {

			$ip = getenv('HTTP_FORWARDED_FOR');

		}

		elseif (getenv('HTTP_FORWARDED')) {

			$ip = getenv('HTTP_FORWARDED');

		}

		else {

			$ip = $_SERVER['REMOTE_ADDR'];

		}

		return $ip;

	}

	

	function new_user() {

		$insert = mysql_query ("INSERT INTO astro_useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')");

		if (!$insert) {

			$this->error[$this->i] = "Unable to record new visitor\r\n";			

			$this->i ++;

		}

	}

	

	function delete_user() {

		$delete = mysql_query ("DELETE FROM astro_useronline WHERE timestamp < ($this->timestamp - $this->timeout)");

		if (!$delete) {

			$this->error[$this->i] = "Unable to delete visitors";

			$this->i ++;

		}

	}

	

	function count_users() {

		if (count($this->error) == 0) {

			$count = mysql_num_rows ( mysql_query("SELECT DISTINCT ip FROM astro_useronline"));

			return $count;

		}

	}



}



function video_upload($newname)

{

function valid($img_ext){

$ext = array('video/wmv' => 'wmv','video/mov' => 'mov');



if(array_key_exists($img_ext, $ext)){

return true;

break;

}

else

return false;

}



if(valid($_FILES['image']['type']) == true){



if ($_FILES["image"]["size"] < 10240000){

if ($_FILES["image"]["error"] == false){

//Uploads and stores in temporary location for further verification

$_FILES["image"]["$name"];

$_FILES["image"]["tmp_name"];



if (file_exists($newname)){

echo $_FILES["image"]["name"], " already exists. ";

}

else{

move_uploaded_file($_FILES["image"]["tmp_name"], $newname);

//calls the thumbnail maker function

//imageThmb();

$src = $_FILES["image"]["name"];

$thumb = "thmb_".basename($_FILES['image']['name']);

}

}

//Prints an error if image failed to upload

else{

echo "Error: ".$_FILES["image"]["error"]."<br />";

}

}

else{

//alerts user that the image is too large

echo "<script>alert('The image you are trying to upload is too large.')</script>";

}

} 

}



function mysql_fetch_full_result_array($result)

{

    $table_result=array();

    $r=0;

    while($row = mysql_fetch_assoc($result)){

        $arr_row=array();

        $c=0;

        while ($c < mysql_num_fields($result)) {       

            $col = mysql_fetch_field($result, $c);   

            $arr_row[$col -> name] = $row[$col -> name];           

            $c++;

        }   

        $table_result[$r] = $arr_row;

        $r++;

    }   

    return $table_result;

}

?>

