require_once("config.inc.php"); require_once("include/class.database.php"); require_once("include/class.page.php"); require_once("include/class.imagetransform.php"); $db = new database; $db->connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); /*session_start();*/ require_once("include/function.jason.php"); function escapeit($text) { if ( !is_numeric($text) ) { if(version_compare(phpversion(),"4.3.0")=="-1") { $text = mysql_escape_string($text); } else { $text = mysql_real_escape_string($text); } } return $text; } // Translate function getpost() { if(count($_POST)) { foreach($_POST as $key => $value) { global ${$key}; ${$key} = $value; } } } function getget() { if(count($_GET)) { foreach($_GET as $key => $value) { global ${$key}; $$key=($value); } } } $id=htmlspecialchars($id); function gen_resize_photo_rotate($file , $source_folder,$destination, $width="", $height="", $prefix="") { if ($file != "") { $imgTrans = new imageTransform(); $imgTrans->sourceFile = $source_folder.$file; $imgTrans->targetFile = $destination.$prefix."_".$file; $imgTrans->chmodValue = 0777; $imgTrans->rotate(90,0); $imgTrans->sourceFile = $destination.$prefix."_".$file; $imgTrans->targetFile = $destination.$prefix."_".$file; $imgTrans->resizeToWidth = $width; $imgTrans->resizeToHeight = $height; $imgTrans->jpegOutputQuality = 95; $imgTrans->resize(); }else{ return false; } } function gen_resize_photo($file , $source_folder,$destination, $width="", $height="", $prefix="") { if ($file != "") { $imgTrans = new imageTransform(); $imgTrans->sourceFile = $source_folder.$file; $imgTrans->targetFile = $destination.$prefix."_".$file; $imgTrans->chmodValue = 0777; $imgTrans->resizeIfSmaller = false; /* 2007/12/19 */ $imgTrans->resizeToWidth = $width; $imgTrans->resizeToHeight = $height; $imgTrans->jpegOutputQuality = 95; $imgTrans->resize(); }else{ return false; } } function genphoto($file, $destination, $width="", $height="", $prefix="") { if ($file != "") { $temp = 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 = 95; $imgTrans->resize(); } } function add_attachment($file, $destination, $path, $table_name, $table_id="", $temp_id="", $col_name, $sorting=0) { global $db; if ($file != "") { $realname = $file["name"]; $temp = split("\.", $realname); $ext = $temp[count($temp)-1]; $ext=strtolower($ext); $filename = randStr(12, "NUMBER").".".$ext; while (file_exists($destination.$filename)) { $filename = randStr(12, "NUMBER").".".$ext; } //move_uploaded_file($file, $destination.$filename); move_uploaded_file($file["tmp_name"], $destination.$filename); chmod($destination.$filename, 0777); if ($re_name != "") { $filename = $re_name."_".$filename; } $sql = "SELECT `attachment_id`, `file_name` FROM `attachment` 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 && $table_id!="") { $rowfile = $db->fetch_array($rs); @unlink($destination.$rowfile["file_name"]); @unlink($destination."s_".$rowfile["file_name"]); @unlink($destination."m_".$rowfile["file_name"]); @unlink($destination."l_".$rowfile["file_name"]); $sql = "UPDATE `attachment` SET `path` = '".$path."', `file_name` = '".$filename."', `real_name` = '".$realname."', `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."'"; $db->query($sql); } else { $sql = "INSERT INTO `attachment` ( `attachment_id` , `table_name` , `table_id` , `temp_id`, `col_name`, `file_name` , `real_name` , `path` , `sorting` , `upload_date` , `upload_time` , `user_id` ) VALUES ( NULL , '".$table_name."', '".$table_id."', '".$temp_id."', '".$col_name."', '".$filename."', '".$realname."', '".$path."', '".$sorting."', '".date("Y-m-d")."', '".date("H:i:s")."', '0' );"; $db->query($sql); } $file_array = array(); $file_array["filename"] = $filename; $file_array["realname"] = $realname; $file_array["colname"] = $colname; return $file_array; } } function del_all_attachment($tbname,$value,$prefix_path="../../"){ global $db; $attachment_Array=get_all_attachment($tbname,$value); if(!empty($attachment_Array) ){ foreach($attachment_Array as $filename){ @unlink($prefix_path.$filename); @unlink($prefix_path.add_prefix($filename,"s")); @unlink($prefix_path.add_prefix($filename,"m")); @unlink($prefix_path.add_prefix($filename,"l")); } } $sql = "DELETE FROM `attachment` WHERE `table_name` = '$tbname' and `table_id` = '$value'"; $db->query($sql); } function get_attachment($table_name,$table_id,$col_name){ global $db; $sql = " SELECT path, 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); if($row[path].$row[file_name]!=""){ return "".$row[path].$row[file_name]; }else{ return ""; } } 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 '