result=array(); $this->counter=0; $this->image_path_tree=array(); $this->msg=""; } function addImage($vals,$image=""){ extract($vals); if($type==1) { $typename="Image"; } elseif($type==0) { $typename="Image"; } $imageLimitOfCategory=$this->getImageLimitOfCategory($parent_id); $numOfImagesInCategory=$this->getNumOfImagesIn($parent_id); if(($imageLimitOfCategory=="") || ($imageLimitOfCategory>$numOfImagesInCategory)){ //if ($this->getNumOfItemsByTitleUnderParentItem(trim($title),$parent_id,$type) == 0) { $this->updateAllShowOrders($parent_id,$showorder); if ($showorder == "begining") { $showorder_num=1; } else if ($showorder == "end") { $showorder_num=(int)($this->getMaxShowOrderUnderPerentImage($parent_id))+1; } else { $showorder_num=(int)$showorder+1; } if(!get_magic_quotes_gpc()) { $title=addslashes(trim($title)); $type=addslashes(trim($type)); } $imgname=$this->uploadImage($image); if ($imgname === false) { return false; } else { //$sql_cnt="insert into ".TBLIMAGE." set title='".addslashes(trim($title))."', link='".addslashes(trim($link))."', type='".$type."', parent_id='".$parent_id."',showorder='".$showorder_num."'"; $sql_cnt="insert into ".TBLIMAGE." set title='".$title."', heading='".$heading."', type='".$type."', description='".$description."', price='".$price."', imgname='".$imgname."', parent_id='".$parent_id."', code='".$code."', showorder='".$showorder_num."' , imagelimit ='".$imagelimit ."'"; mysql_query($sql_cnt); $id=mysql_insert_id(); $this->msg=$typename." added successfully."; return $id; } // } else { // $this->msg="Can not create this ".$typename.". A ".$typename." with same name already exists. Please try with a different name."; // return false; // } } else { $this->msg="You can not upload more than ".$imageLimitOfCategory." image(s) here"; return false; } } ################################## Function updateAllShowOrders() : Start ############################################# ############################ Purpose : To update all the other images' showorder values while creating a new image or updating a image##### ################ Parameters : $parent_id=>id of the parent image item (under which new or current image is in) ################################ ################ Parameters : $showorder=>the new showorder value of the new or updated image ### ################ Parameters : $current_showorder=> if updating a image, then its' current showorder value. if adding a new image , it is not required ### function updateAllShowOrders($parent_id,$showorder,$current_showorder=-1) { if($current_showorder != $showorder) { $sql_p=""; if($showorder == "begining") { $sql_p="update ".TBLIMAGE." set showorder=showorder+1 where parent_id='".$parent_id."'"; if($current_showorder != -1) { $sql_p="update ".TBLIMAGE." set showorder=showorder+1 where parent_id='".$parent_id."'"." and showorder<".$current_showorder; } } else if ($showorder == "end") { if($current_showorder != -1) { $sql_p="update ".TBLIMAGE." set showorder=showorder-1 where parent_id='".$parent_id."' and showorder>=".$current_showorder; } } else { $sql_p="update ".TBLIMAGE." set showorder=showorder+1 where parent_id='".$parent_id."' and showorder>".$showorder; if($current_showorder != -1) { if($current_showorder > $showorder) { $sql_p="update ".TBLIMAGE." set showorder=showorder+1 where parent_id='".$parent_id."' and showorder>".$showorder." and showorder<".$current_showorder; } else if ($current_showorder < $showorder) { $sql_p="update ".TBLIMAGE." set showorder=showorder-1 where parent_id='".$parent_id."' and showorder>".$current_showorder." and showorder<=".$showorder; } } } if($sql_p != "") { $rec_p=mysql_query($sql_p); } } } ################################## Function updateAllShowOrders() : End ############################################# function updateImage($vars,$image=""){ extract($vars); if($type==1) { $typename="Image"; } elseif($type==0) { $typename="Image"; } //to show in the message // if ($this->getNumOfItemsByTitleUnderParentItem(trim($title),$parent_id,$type,$id) == 0) { $imageinfo=$this->getImageByID($id); $parent_id=$imageinfo['parent_id']; $current_showorder=$imageinfo['showorder']; if($current_showorder != $showorder) { $this->updateAllShowOrders($parent_id,$showorder,$current_showorder); if ($showorder == "begining") { $showorder_num=1; } else if ($showorder == "end") { $showorder_num=(int)($this->getMaxShowOrderUnderPerentImage($parent_id))+1; } else { if ($current_showorder>$showorder) { $showorder_num=(int)$showorder+1; } else if ($current_showorder<$showorder){ $showorder_num=(int)$showorder; } } } else { $showorder_num=(int)$showorder; } if(!get_magic_quotes_gpc()) { $title=addslashes(trim($title)); $link=addslashes(trim($link)); } //$sql_p="update ".TBLIMAGE." set title='".$title."', link='".$link."', showorder='".$showorder_num."' where id='".$id."'"; $sql_p="update ".TBLIMAGE." set title='".$title."', heading='".$heading."', type='".$type."', description='".$description."', price='".$price."', code='".$code."', showorder='".$showorder_num."' where id='".$id."'"; $rec_p=mysql_query($sql_p); $imgname=$this->uploadImage($image); if ($imgname === false) { $this->msg=$typename." Information updated successfully! But image could not be updated. ".$this->msg; return false; } else if ($imgname === NULL) { $this->msg=$typename." updated successfully!"; return true; } else { $image_info=$this->getImageByID($id); $sql_p="update ".TBLIMAGE." set imgname='".$imgname."' where id='".$id."'"; $rec_p=mysql_query($sql_p); $old_imgname=$image_info['imgname']; $old_imgpath="bgcatimageimg/" .$old_imgname; $old_thumbimgpath="catimageimg/" .$old_imgname; if(file_exists($old_imgpath)) unlink($old_imgpath); if(file_exists($old_thumbimgpath)) unlink($old_thumbimgpath); $this->msg=$typename." updated successfully!"; return true; } // } else { // $this->msg="Can not update the ".$typename." name. A ".$typename." with same name already exists. Please try with a different name."; // return false; // } } function deletepro($id){ $imageinfo=$this->getImageByID($id); $parent_id=$imageinfo['parent_id']; $current_showorder=$imageinfo['showorder']; $sqltxt="select * from ".TBLIMAGE." where parent_id=".$id; $restxt=mysql_query($sqltxt); if(mysql_num_rows($restxt)>0) { while ($var=mysql_fetch_array($restxt)) { $this->deletepro($var['id']); } } $sqltxt_del="delete from ".TBLIMAGE." where id=".$id; mysql_query($sqltxt_del); $old_imgname=$imageinfo['imgname']; $old_imgpath="bgcatimageimg/" .$old_imgname; $old_thumbimgpath="catimageimg/" .$old_imgname; if(file_exists($old_imgpath)) unlink($old_imgpath); if(file_exists($old_thumbimgpath)) unlink($old_thumbimgpath); $sql_p="update ".TBLIMAGE." set showorder=showorder-1 where parent_id='".$parent_id."' and showorder>".$current_showorder; mysql_query($sql_p); $type=$imageinfo['type']; if($type==1) { $typename="Image"; } elseif($type==0) { $typename="Image"; } //to show in the message $this->msg=$typename.' deleted successfully!'; return true; } function statpro($stat,$id){ if($stat==1) $doStat=0; elseif($stat==0) $doStat=1; $sqltxt_del="update ".TBLIMAGE." set showStatus=".$doStat." where id='".$id."'"; mysql_query($sqltxt_del); } function getMaxShowOrderUnderPerentImage($parent_id) { $sql="select MAX(showorder) as SO from ".TBLIMAGE." where parent_id='".$parent_id."'"; $maxSO=mysql_fetch_array(mysql_query($sql)); return $maxSO[SO]; } ################################## Function getImages() : Start ############################################# ############################ Purpose : To get the child images under a parent with pagination parameters ##### ################ Parameters : $parent_id=>id of the parent image item ################################ ################ Parameters : $status=>(0 or 1 or "") for getting (unpublished or published or all) images ### ################ Parameters : $start,$limit=> limit parameters, left $limit blank if need all the child images ### function getImages($parent_id=0,$status="",$start=0,$limit=""){ //fecth images and categories both $result=array(); $condition=" where parent_id='".$parent_id."' "; $condition.=($status == "")?"":" AND showStatus='".$status."'"; $limit=(isset($limit) && trim($limit)!="")?" limit $start , $limit ":""; $sql="select * from ".TBLIMAGE.$condition." order by showorder".$limit; $res=mysql_query($sql); while($rs=mysql_fetch_array($res)) { array_push($result,$rs); } return $result; } ################################## Function getImages() : End ############################################# function getOnlyImages($condition,$start=0,$limit=""){ //get images only by condition $result=array(); $limit=(isset($limit) && trim($limit)!="")?" limit $start , $limit ":""; $sql="select * from ".TBLIMAGE." ".$condition." ".$limit; $res=mysql_query($sql); while($rs=mysql_fetch_array($res)) { array_push($result,$rs); } return $result; } ################################## Function getNumOfImages() : Start ############################################# ################ Parameters : $parent_id=>id of the parent image item ################################ ################ Parameters : $status=>(0 or 1 or "") for getting (unpublished or published or all) images ### ################ Return Value : The number of child images directly under parent image with $parent_id ### function getNumOfImages($parent_id=0,$status=""){ $condition=" where parent_id='".$parent_id."' "; $condition.=($status == "")?"":" AND showStatus='".$status."'"; $sql="select COUNT(*) as CNT from ".TBLIMAGE.$condition." order by showorder".$limit; $res=mysql_query($sql); $rs=mysql_fetch_array($res); return $rs['CNT']; } ################################## Function getNumOfImages() : End ############################################# function getAllChildImageIds($id){ static $image_list=array(); $sqltxt="select `id` from ".TBLIMAGE." where parent_id=".$id; $restxt=mysql_query($sqltxt); if(mysql_num_rows($restxt)>0) { while ($var=mysql_fetch_assoc($restxt)) { array_push($image_list,$var['id']); $this->getAllChildImageIds($var['id']); } } return $image_list; } ################################## Function getImagePathTree() : Start ############################################# ################ To get the image path from the top level image to the current child image ####################### ################ Parameters : $id=>primary key ('id') of the current image item ################################ ################ Parameters : $start=>must set 'true' if it is the first/initial call to this recursive function from anywhere ### /*function getImagePathTree($id,$start=true){ if ($start) { $this->image_path_tree=array(); } $imagedata=$this->getImageByID($id); array_push($this->image_path_tree,$imagedata); if($imagedata['parent_id']!=0) { $this->getImagePathTree($imagedata['parent_id'],false); } else { return $this->image_path_tree; } return array_reverse($this->image_path_tree); }*/ function getImagePathTree($id,$image_path_tree=array(),$start=true){ if($id != 0) { $imagedata=$this->getImageByID($id); array_push($image_path_tree,$imagedata); if($imagedata['parent_id']!=0) { $image_path_tree=$this->getImagePathTree($imagedata['parent_id'],$image_path_tree,false); } if ($start) { $image_path_tree=array_reverse($image_path_tree); } } return $image_path_tree; } ################################## Function getImagePathTree() : End ############################################# function getImageByID($id){ $result=array(); $sql="select * from ".TBLIMAGE." where id=".$id; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); return $rs; } function getImageByTitle($title){ $result=array(); $sql="select * from ".TBLIMAGE." where title='".$title."'"; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); return $rs; } function hasAnyChildCategory($parent_id) { $sql="select count(id) as cntcat from ".TBLIMAGE." where parent_id='".$parent_id."' and type=0"; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); if ((int)$rs['cntcat'] > 0) { return true; } else { return false; } } function hasAnyChildImage($parent_id) { $sql="select count(id) as cntcat from ".TBLIMAGE." where parent_id='".$parent_id."' and type=1"; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); if ((int)$rs['cntcat'] > 0) { return true; } else { return false; } } function validateAddEdit($vars){ extract($vars); if(isset($title) && trim($title)==""){ regis_error('title_err',"Your didn\'t give title."); } if(isset($calendar) && trim($calendar)==""){ regis_error('date_err',"Your didn\'t select the Date and Time."); } if(isset($venue) && trim($venue)==""){ regis_error('ven_err',"Your didn\'t enter the venue."); } if(countallerrors()>0){ return(false); } else{ return(true); } } function getNumOfImagesIn($parent_id){ $sql="select COUNT(*) as CNT from ".TBLIMAGE." where `parent_id`='".$parent_id."'"; $numR=mysql_fetch_assoc(mysql_query($sql)); return $numR['CNT']; } function getMaxID($status=0){ $stat=(!empty($status) && trim($status)!='')?" where showStatus=$status ":" where 1 ";; $sql="select MAX(event_id) as ID from ".TBLBLOG.$stat; $maxID=mysql_fetch_array(mysql_query($sql)); return $maxID[ID]; } function LastInsert(){ $sql="select LAST_INSERT_ID() as mxid from ".TBLBLOG; $rs=mysql_fetch_array(mysql_query($sql)); return $rs['mxid']; } function uploadImage($image="") { if(!is_array($image)) { return NULL; } else { //if $image is an array if(trim($image['name']) == "") { return NULL; } } $size = GetImageSize($image['tmp_name']); $nwname=time().$image['name']; $newfilename = "catimageimg/" .$nwname; $newfilename1 = "bgcatimageimg/" .$nwname; $imname=$image['name']; $blanc=""; $format=ereg_replace(".*\.(.*)$","\\1",$image['name']); $filesize=$image['size']; $format=strtoupper($format); if($size[0]<=1000 && $size[1]<=1000) { if($format=="JPG" || $format=="JPEG" || $format=="GIF" || $format=="PNG") { if($filesize <= '6048576') { //////////////////////////// if(move_uploaded_file($image['tmp_name'],$newfilename1)) { chmod($newfilename1, 0755); $this->imgresize($newfilename1,$blanc,$newfilename,200,125,false); chmod($newfilename, 0755); $this->msg="Image has been added successfully."; return $nwname; } } else { $this->msg="Please upload image less than or equal to 5MB."; return false; } } else { $this->msg="Please upload JPG,JPEG,GIF or PNG image."; return false; } } else { $this->msg="The image size should not be greater than the size 1000x1000 (Width x Height)"; return false; } } function imgresize($imgfile,$newfilename2,$savelocation,$max_width,$max_height) { //$savelocation = "../thumbimg/"; $format=ereg_replace(".*\.(.*)$","\\1",$imgfile); $format=strtoupper($format); if (!$max_width) $max_width = 120; if (!$max_height) $max_height = 160; $size = GetImageSize($imgfile); $width = $size[0]; $height = $size[1]; $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if (($width <= $max_width) && ($height <= $max_height)) { $tn_width = $width; $tn_height = $height; } else if (($x_ratio * $height) < $max_height) { $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; } else { $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } ////$thumb = ImageCreateTrueColor($tn_width,$tn_height); $thumb = imagecreatetruecolor($tn_width,$tn_height); //$thumb = @imagecreate($tn_width,$tn_height); if ($format=="JPG" || $format=="JPEG") { //JPEG $format="JPEG"; $source=ImageCreateFromJPEG ($imgfile); imagecopyresized($thumb, $source, 0, 0, 0, 0, $tn_width ,$tn_height, $width, $height); imagejpeg($thumb,"$savelocation".$newfilename2); } if($format=="GIF") { //GIF $format="GIF"; $source = ImageCreateFromGIF ($imgfile); imagecopyresized($thumb, $source, 0, 0, 0, 0, $tn_width ,$tn_height, $width, $height); imagegif($thumb,"$savelocation".$newfilename2); } if($format=="PNG") { //GIF $format="PNG"; $source = ImageCreateFromPNG($imgfile); imagecopyresized($thumb, $source, 0, 0, 0, 0, $tn_width ,$tn_height, $width, $height); imagepng($thumb,"$savelocation".$newfilename2); } } function getNumOfItemsByTitleUnderParentItem($title,$parent_id,$type="",$id="") { $optional_cond=""; if($type!="") { $optional_cond.=" and type='".$type."' "; } if($id!="") { //If checking for duplicatate values while updating an item $optional_cond.=" and id<>'".$id."' "; } $sql="select count(id) as cnt from ".TBLIMAGE." where title='".$title."' and parent_id='".$parent_id."'".$optional_cond; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); return $rs['cnt']; } function getImageLimitOfCategory($id) { $sql="select `imagelimit` from ".TBLIMAGE." where `id`='".$id."'"; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); return $rs['imagelimit']; } function isAnyParentExistWithTitle($id,$title) { $image_path_array=$this->getImagePathTree($id); foreach($image_path_array as $image_path) { if($image_path['title']==$title) { return true; } } return false; } ############################## Function getLanguage() ################## function getLanguage(){ //ftech all languages $result=array(); $sql="select * from ".LANGUAGEMASTER." "; $res=mysql_query($sql); while($rs=mysql_fetch_array($res)) { array_push($result,$rs); } return $result; } function getLangugeByTitle($language){ $result=array(); $sql="select * from ".LANGUAGEMASTER." where name='".$language."'"; $res=mysql_query($sql); $rs=mysql_fetch_assoc($res); return $rs; } function setIMAGEDetails($description,$page_heading,$image_id,$title,$language_id=""){ if ($language_id=="") { $language_id=$this->getLanguageId(); //Get the default Language Id } if(!get_magic_quotes_gpc()) { $content=addslashes($content); $page_heading=addslashes($page_heading); } $is_content_exist=$this->isContentExist($image_id,$language_id); if($is_content_exist) { $sql="update ".TBLIMAGELANG." set description='".$description."', heading='".$page_heading."' ,title='".$title."' where image_id='".$image_id."' and language_id='".$language_id."'"; } else { $sql="insert into ".TBLIMAGELANG." set description='".$description."', heading='".$page_heading."',title='".$title."', image_id='".$image_id."', language_id='".$language_id."'"; } mysql_query($sql); } function isContentExist($image_id,$language_id="") { if ($language_id=="") { $language_id=$this->getLanguageId(); //Get the default Language Id } $sql="select * from ".TBLIMAGELANG." where image_id='".$image_id."' and language_id='".$language_id."'"; $res=mysql_query($sql); $numrow=mysql_num_rows($res); $con_exist=(($numrow==0)?false:true); return $con_exist; } function getIMAGEDetails($image_id,$language_id=""){ if ($language_id=="") { $language_id=$this->getLanguageId(); //Get the default Language Id } $sql="select * from ".TBLIMAGELANG." where image_id='".$image_id."' and language_id='".$language_id."'"; $res=mysql_query($sql); $row=mysql_fetch_assoc($res); return $row; } function getLanguageId($language_name="English"){ $sql="select id from ".LANGUAGEMASTER." where name='".$language_name."'"; $res=mysql_query($sql); $row=mysql_fetch_assoc($res); return $row['id']; } function deleteIMAGEDetails($image_id,$language_id=""){ if ($language_id=="") { $language_id=$this->getLanguageId(); //Get the default Language Id } //$sql="delete from ".TBLCMS." where menu_id='".$menu_id."' and language_id='".$language_id."'"; $sql="delete from ".TBLIMAGELANG." where image_id='".$image_id."' "; mysql_query($sql); } } ?>