connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); //--- End Connect database part --- //--- Create ui form --- $form_ui = new form_ui(); //--- End Create ui form --- //--- Translate for post form --- function getpost() { if(count($_POST)) { foreach($_POST as $key => $value) { global ${$key}; ${$key} = $value; } } } //--- Translate for post form --- //--- Translate for get form --- function getget() { if(count($_GET)) { foreach($_GET as $key => $value) { global ${$key}; ${$key}=($value); } } } //--- Translate for get form --- //--- escape special character --- function escapeit($text) { if (get_magic_quotes_gpc()) { $text = stripslashes($text); } if ( !is_numeric($text) ) { $text = mysql_real_escape_string($text); } return $text; } //--- End escape special character --- //--- Resize photo (generate filename)--- function genphoto($file, $destination, $width="", $height="", $prefix="") { if ($file != "") { $temp = new_split("\.", $file); $ext = $temp[count($temp)-1]; $filename = randStr(12, "NUMBER").".".$ext; $imgTrans = new imageTransform(); $imgTrans->sourceFile = $destination.$file; $imgTrans->targetFile = $destination.$prefix."_".$filename; $imgTrans->chmodValue = 0777; $imgTrans->resizeToWidth = $width; $imgTrans->resizeToHeight = $height; $imgTrans->jpegOutputQuality = 100; $imgTrans->resize(); } } //--- End Resize photo (generate filename)--- //--- Resize photo only --- function genphoto_only($file, $source, $destination, $width="", $height="") { if ($file != "") { $filename = $file; $imgTrans = new imageTransform(); $imgTrans->sourceFile = $source.$file; $imgTrans->targetFile = $destination.$filename; $imgTrans->chmodValue = 0777; $imgTrans->resizeToWidth = $width; $imgTrans->resizeToHeight = $height; $imgTrans->jpegOutputQuality = 100; $imgTrans->resize(); } } //--- End Resize photo only --- //--- Our resize image method (include white background) --- function uploadImageFileResizeBGcolor($filename, $uploadpath, $maxfilesize, $index, $nwidth, $nheight) { $datekey = date("YmjHis"); //$generateipanddate->genDateForFile(); //get the date key for upload file $sessionid = md5(time());//$generatesessionid->getSessionID(); //get the session id for upload file $filetype = strtoupper(trim(substr($filename, -3))); //get the file type name $newfilename = $filename; //.".".$filetype; //$sessionid.$datekey.$index.".".$filetype; //make the new file name for upload //110000 --> 110KB $isneedresizeornot = 0; //0 - no need resize, 1 - need resize $isneedresizeornot = 1; if($isneedresizeornot == 1) { list($width, $height) = getimagesize(($uploadpath).$newfilename); $newwidth = 0; $newheiht = 0; $newx = 0; $newy = 0; $handwradio = ($height/$width); $wandhradio = ($width/$height); if($handwradio <= 1){ $newwidth = $nwidth;//152; $newheight = ($nwidth*$handwradio); //152 $newx = 0; $newy = (($nheight-$newheight)/2); //192 if($newheight > $nheight) { $newheight = $nheight; //192 $newwidth = ($nheight*$wandhradio); //192 $newx = (($nwidth-$newwidth)/2); //152 $newy = 0; } }else if($wandhradio <= 1){ $newheight = $nheight; //192 $newwidth = ($nheight*$wandhradio); //192 $newx = (($nwidth-$newwidth)/2); //152 $newy = 0; if($newwidth > $nwidth) { $newwidth = $nwidth;//152; $newheight = ($nwidth*$handwradio); //152 $newx = 0; $newy = (($nheight-$newheight)/2); //192 } } if($filetype == "JPG"){ $source = imagecreatefromjpeg(($uploadpath).$newfilename); }else if($filetype == "PNG"){ $source = imagecreatefrompng(($uploadpath).$newfilename); }else if($filetype == "GIF"){ $source = imagecreatefromgif(($uploadpath).$newfilename); } if($filetype == "JPG" || $filetype == "PNG" || $filetype == "GIF"){ $thumb = ImageCreateTrueColor($nwidth, $nheight); imagefill($thumb,0,0,imagecolorallocate($thumb, 255, 255, 255)); // --- Insert the white color background --- imagecopyresampled($thumb, $source, $newx, $newy, 0, 0, $newwidth, $newheight, $width, $height); if($filetype == "JPG"){ imagejpeg($thumb,($uploadpath).$newfilename); }else if($filetype == "PNG"){ imagepng($thumb,($uploadpath).$newfilename); }else if($filetype == "GIF"){ imagegif($thumb,($uploadpath).$newfilename); } ImageDestroy($source); @fclose($sourcefilehandle); } return $newfilename; } return "-1"; //express error } //--- End Our resize image method (include white background)--- //--- Add attachment function for multiple upload function --- function add_attachment_formulti($attachment_tbname, $file, $destination, $path, $table_name, $table_id="", $temp_id="", $col_name, $sorting=0){ global $db; if ($file != "") { $realname = $file["name"]; $temp = new_split("\.", $realname); $ext = $temp[count($temp)-1]; $filename = randStr(12, "NUMBER").".".$ext; while (file_exists($destination.$filename)) { $filename = randStr(12, "NUMBER").".".$ext; } move_uploaded_file($file["tmp_name"], $destination.$filename); chmod($destination.$filename, 0777); if ($re_name != "") { $filename = $re_name."_".$filename; } $sql = "INSERT INTO `".$attachment_tbname."` ( `attachment_id` , `table_name` , `table_id` , `temp_id`, `col_name`, `file_name` , `real_name` , `path` , `sorting` , `upload_date` , `upload_time`) VALUES (NULL , '".$table_name."', '".$table_id."', '".$temp_id."', '".$col_name."', '".$filename."', '".$realname."', '".$path."', '".$sorting."', '".date("Y-m-d")."', '".date("H:i:s")."');"; $db->query($sql); $attachment_id = $db->insert_id(); $file_array = array(); $file_array["attachment_id"] = $attachment_id; $file_array["filename"] = $filename; $file_array["realname"] = $realname; $file_array["colname"] = $colname; return $file_array; } } //--- End Add attachment function for multiple upload function --- //--- Add attachment function for normal function --- function add_attachment($attachment_tbname, $file, $destination, $path, $table_name, $table_id="", $temp_id="", $col_name, $sorting=0) { // $small_path, $medium_path, global $db; if ($file != "") { $realname = $file["name"]; $temp = new_split("\.", $realname); $ext = $temp[count($temp)-1]; $filename = randStr(12, "NUMBER").".".$ext; //--- Check file exist --- while (file_exists($destination.$filename)) { $filename = randStr(12, "NUMBER").".".$ext; } //--- End Check file exist --- //--- Copy file and grant permission --- move_uploaded_file($file["tmp_name"], $destination.$filename); chmod($destination.$filename, 0777); //--- End Copy file and grant permission --- if ($re_name != "") { $filename = $re_name."_".$filename; } $sql = "SELECT * FROM `".$attachment_tbname."` WHERE `table_name` = '".$table_name."' AND `table_id` = '".$table_id."' AND `col_name` = '".$col_name."'"; $rs = $db->query($sql); if (mysql_num_rows($rs) > 0 && trim($table_id) != "") { $rowfile = $db->fetch_array($rs); //---- Delete before upload file --- $attachment_id = $rowfile["attachment_id"]; $youtube_code = $rowfile["youtube_code"]; delete_attachment_file("", $destination, $rowfile2["file_name"], $youtube_code); //---- End Delete before upload file --- //---- Update attachment information ---- $sql = "UPDATE `".$attachment_tbname."` SET `file_name` = '".$filename."', `real_name` = '".$realname."', `path` = '".$path."', `upload_date` = '".date("Y-m-d")."', `upload_time` = '".date("H:i:s")."' WHERE `table_name` = '".$table_name."' AND `table_id` = '".$table_id."' AND `col_name` = '".$col_name."'"; //`medium_path` = '".$medium_path."', `small_path` = '".$small_path."', $db->query($sql); //---- End Update attachment information ---- } else { $sql = "SELECT * FROM `".$attachment_tbname."` WHERE `table_name` = '".$table_name."' AND `temp_id` = '".$temp_id."' AND `col_name` = '".$col_name."'"; $rs2 = $db->query($sql); if(mysql_num_rows($rs2) > 0 && trim($temp_id) != ""){ $rowfile2 = $db->fetch_array($rs2); //---- Delete before upload file --- $attachment_id = $rowfile2["attachment_id"]; $youtube_code = $rowfile2["youtube_code"]; delete_attachment_file("", $destination, $rowfile2["file_name"], $youtube_code); //---- End Delete before upload file --- //---- Update attachment information ---- $sql = "UPDATE `".$attachment_tbname."` SET `file_name` = '".$filename."', `real_name` = '".$realname."', `path` = '".$path."', `upload_date` = '".date("Y-m-d")."', `upload_time` = '".date("H:i:s")."' WHERE `table_name` = '".$table_name."' AND `temp_id` = '".$temp_id."' AND `col_name` = '".$col_name."'"; // `medium_path` = '".$medium_path."',`small_path` = '".$small_path."', $db->query($sql); //---- End Update attachment information ---- }else{ //---- Insert attachment information ---- $sql = "INSERT INTO `".$attachment_tbname."` ( `attachment_id` , `table_name` , `table_id` , `temp_id`, `col_name`, `file_name` , `real_name` , `path` , `sorting` , `upload_date` , `upload_time`) VALUES ( NULL , '".$table_name."', '".$table_id."', '".$temp_id."', '".$col_name."', '".$filename."', '".$realname."', '".$path."', '".$sorting."', '".date("Y-m-d")."', '".date("H:i:s")."' );"; //'".$medium_path."', '".$small_path."', `medium_path`, `small_path`, $db->query($sql); $attachment_id = $db->insert_id(); //---- End Insert attachment information ---- } } $file_array = array(); $file_array["attachment_id"] = $attachment_id; $file_array["filename"] = $filename; $file_array["realname"] = $realname; $file_array["colname"] = $colname; return $file_array; } } //--- End Add attachment function for normal function --- //---- Update the youtube attachment information ---- function update_attachment_youtube($attachment_tbname, $attachment_id, $path, $filename){ global $db; global $google_youtube_username, $google_youtube_password, $google_authentication_url, $gooel_youtube_upload_url, $google_youtube_developer_key, $google_youtube_category_name, $google_youtube_application_Id, $google_youtube_client_Id, $google_youtube_service, $google_youtube_source; list($name, $ext) = explode(".", $filename); $ext = strtolower($ext); $youtube_code = ""; if($ext == "webm" || $ext == "mpeg4" || ($ext == "3gp" || $ext == "3gp2") || $ext == "avi" || $ext == "avi" || $ext == "wmv" || $ext == "mp4" || $ext == "flv"){ //--- Create the youtube object --- //---- Youtube HandShake --- $yt = new youtube(); $yt->set_youtube_username($google_youtube_username); $yt->set_youtube_password($google_youtube_password); $yt->set_authentication_URL($google_authentication_url); $yt->set_upload_URL($gooel_youtube_upload_url); $yt->set_developer_Key($google_youtube_developer_key); $yt->set_application_Id($google_youtube_application_Id); $yt->set_client_Id($google_youtube_client_Id); $yt->set_youtube_service($google_youtube_service); $yt->set_youtube_source($google_youtube_source); //---- End Youtube HandShake --- $youtube_title = $filename; $$youtube_desc = $filename; //--- Upload file to youtube --- $video_entry = $yt->add_youtube($path, $filename, $youtube_title, $youtube_desc, $google_youtube_category_name, $google_youtube_category_name, "", ""); //--- End Upload file to youtube --- //--- Get all upload youtube information --- $all_video_entry_info = $yt->get_video_entry_info($video_entry); //--- End Get all upload youtube information --- $youtube_code = $all_video_entry_info["video_id"]; //--- End Create the youtube object --- $sql = "update `".$attachment_tbname."` set `youtube_code` = '".$youtube_code."' where `attachment_id`='".$attachment_id."'"; $db->query($sql); } return $youtube_code; } //---- End Update the youtube attachment information ---- //---- Delete youtube file on youtube server ----- function del_attachment_youtube($youtube_code){ global $db; global $google_youtube_username, $google_youtube_password, $google_authentication_url, $gooel_youtube_upload_url, $google_youtube_developer_key, $google_youtube_category_name, $google_youtube_application_Id, $google_youtube_client_Id, $google_youtube_service, $google_youtube_source; //---- Youtube HandShake --- $yt = new youtube(); $yt->set_youtube_username($google_youtube_username); $yt->set_youtube_password($google_youtube_password); $yt->set_authentication_URL($google_authentication_url); $yt->set_upload_URL($gooel_youtube_upload_url); $yt->set_developer_Key($google_youtube_developer_key); $yt->set_application_Id($google_youtube_application_Id); $yt->set_client_Id($google_youtube_client_Id); $yt->set_youtube_service($google_youtube_service); $yt->set_youtube_source($google_youtube_source); //---- End Youtube HandShake --- $result = $yt->delete_youtube($youtube_code); if($result == true){ return true; }else{ return false; } } //---- End Delete youtube file on youtube server ----- //---- Delete a attachment ---- function del_attachment($attachment_tbname, $attachment_id,$prefix_path="../../"){ //, $is_youtube_upload = "N"){ global $db; $sql = "SELECT * FROM `".$attachment_tbname."` WHERE `attachment_id` = '".escapeit($attachment_id)."'"; $row = $db->getrow($sql); $path = $row["path"]; $file_name = $row["file_name"]; $youtube_code = $row["youtube_code"]; //--- Delete attachment file --- delete_attachment_file($prefix_path, $path, $file_name, (($youtube_code != "") ? $youtube_code : "")); //--- End Delete attachment file --- //--- Delete the attachment record --- $sql = "DELETE FROM `".$attachment_tbname."` WHERE `attachment_id` = '".escapeit($attachment_id)."'"; $db->query($sql); //--- End Delete the attachment record --- } //---- End Delete a attachment ---- //---- Delete all attachment ---- function del_all_attachment($attachment_tbname, $table_name,$value,$prefix_path="../../"){ //, $is_youtube_upload = "N"){ global $db; $sql = "SELECT * FROM `".$attachment_tbname."` WHERE `table_name` = '".escapeit($table_name)."' AND `table_id` = '".escapeit($value)."'"; $rs = $db->query($sql); while ($row = $db->fetch_array($rs)) { $path = $row["path"]; $file_name = $row["file_name"]; $youtube_code = $row["youtube_code"]; //--- Delete attachment file --- delete_attachment_file($prefix_path, $path, $file_name, (($youtube_code != "") ? $youtube_code : "")); //--- End Delete attachment file --- } //--- Delete the attachment record --- $sql = "DELETE FROM `attachment` WHERE `table_name` = '".escapeit($table_name)."' AND `table_id` = '".escapeit($value)."'"; $db->query($sql); //--- End Delete the attachment record --- } //---- End Delete all attachment ---- //--- Delete the attachment file function --- function delete_attachment_file($prefix_path, $path, $file_name, $youtube_code){ //--- Delete file --- @unlink($prefix_path.$path."small/".$file_name); @unlink($prefix_path.$path."medium/".$file_name); @unlink($prefix_path.$path."original/".$file_name); //--- End Delete file --- //--- Delete the youtube file --- if($youtube_code != ""){ del_attachment_youtube($youtube_code); } //--- End Delete the youtube file --- } //--- End Delete the attachment file function --- function get_attachment($table_name,$table_id,$col_name){ global $db; $sql = " SELECT file_name FROM `attachment` WHERE `table_name`='".$table_name."' and `table_id`='".$table_id."' and `col_name`='".$col_name."' "; $result = $db->query($sql); $row = mysql_fetch_assoc($result); return $row["file_name"]; } function get_all_attachment($table_name,$table_id){ global $db; $sql = " SELECT col_name,path,file_name FROM `attachment` WHERE `table_name`='".$table_name."' and `table_id`='".$table_id."' "; $result = $db->query($sql); while($row = mysql_fetch_assoc($result)){ $myAttachment[$row["col_name"]]=$row["path"].$row["file_name"]; } return $myAttachment; } function show_attachment($file){ $lower_filename=strtolower($file); if( strstr($lower_filename,".jpg") || strstr($lower_filename,".jpeg") || strstr($lower_filename,".gif") || strstr($lower_filename,".png") ){ return '