connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); /*session_start();*/ require_once("include2/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; } } /* Resize and Crop Photo */ if (!function_exists("genphoto_cropResize")){ function genphoto_cropResize($file, $source, $destination, $width="", $height="",$prefix=""){ if($file!=""){ list ($sWidth, $sHeight) = getimagesize($source.$file); $rW = $width / $sWidth; $rH = $height / $sHeight; $ratio = ($sHeight * $rW >= $height) ? $rW : $rH; $tW = $sWidth * $ratio; $tH = $sHeight * $ratio; $sX = ($tW - $width) / 2; $dX = $sX + $width; $sY = ($tH - $height) / 2; $dY = $sY + $height; $imgResize = new imageTransform(); $imgResize->sourceFile = $source.$file; $imgResize->targetFile = $destination.$prefix."_".$file; $imgResize->chmodValue = 0777; $imgResize->resizeToWidth = $tW; $imgResize->resizeToHeight = $tH; $imgResize->jpegOutputQuality = 95; $imgResize->resizeIfSmaller = true; $imgResize->resize(); $imgCrop = new imageTransform(); $imgCrop->sourceFile = $destination.$prefix."_".$file; $imgCrop->targetFile = $destination.$prefix."_".$file; $imgCrop->chmodValue = 0777; $imgCrop->jpegOutputQuality = 95; $imgCrop->crop($sX, $sY, $dX, $dY); }}} 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 upload_excel($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; } $file_array = array(); $file_array["filename"] = $filename; $file_array["realname"] = $realname; $file_array["colname"] = $colname; return $file_array; } } 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"]); @unlink($destination."flash_".$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 '
'.funMakeImage("../../".$file,80,80,1).'
'; } } /* function randStr($len,$format) { switch($format) { case 'ALL': $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break; case 'CHAR': $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break; case 'NUMBER': $chars='0123456789'; break; default : $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break; } mt_srand((double)microtime()*1000000*getmypid()); $password=""; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return $password; } */ function displaystr($display, $lang="en") { $str = ""; if ($display == 1) { if ($lang == "chi") { $str = '顯示'; } else { $str = 'Display'; } } else { if ($lang == "chi") { $str = '隱藏'; } else { $str = 'Hidden'; } } return $str; } function enablestr($enable, $lang="en") { $str = ""; if ($enable == 1) { if ($lang == "chi") { $str = '啟用'; } else { $str = 'Enable'; } } else { if ($lang == "chi") { $str = '停用'; } else { $str = 'Disable'; } } return $str; } ?>