connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); session_start(); //cart session /* if (!isset($_SESSION["cart"])) { $_SESSION["cart"] = & new classCart(); } $cart = &$_SESSION["cart"]; */ //clear outdate session $cart->clearOutdate(); // Translate function getpost() { if(count($_POST)) { foreach($_POST as $key => $value) { global ${$key}; if (is_array($value)) { $temp_array = array(); foreach($value as $key2 => $value2) { if (get_magic_quotes_gpc() == 1) { $temp_array[$key2] = stripslashes(trim($value2)); } else { $temp_array[$key2] = trim($value2); } } ${$key} = $temp_array; } else { if (get_magic_quotes_gpc() == 1) { ${$key} =stripslashes(trim($value)); } else { ${$key} = trim($value); } } } } } function getget() { if(count($_GET)) { foreach($_GET as $key => $value) { global ${$key}; if (is_array($value)) { $temp_array = array(); foreach($value as $key2 => $value2) { if (get_magic_quotes_gpc() == 1) { $temp_array[$key2] = stripslashes(trim($value2)); } else { $temp_array[$key2] = trim($value2); } } ${$key} = $temp_array; } else { if (get_magic_quotes_gpc() == 1) { ${$key} =stripslashes(trim($value)); } else { ${$key} = trim($value); } } } } } function escapeit($text) { if (get_magic_quotes_gpc() == 1) { $text = stripslashes($text); } if ( !is_numeric($text) ) { $text = mysql_real_escape_string($text); } return $text; } function genphoto($file, $destination, $width="", $height="", $prefix="") { if ($file != "") { $temp = explode(".", $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(); } } function resize_photo($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 = 80; $imgTrans->resizeIfSmaller = false; $imgTrans->resize(); } } function apply_watermark($input, $output) { $output_filename = $input; $phpThumb = new phpThumb(); $phpThumb->setSourceFilename($output); $phpThumb->setParameter('q', 100); $phpThumb->setParameter('fltr', 'wmi|watermark.png|C'); if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($output_filename); } } function add_attachment($file, $destination, $destination2, $destination3, $destination4, $destination5, $path, $table_name, $table_id="", $temp_id="", $col_name, $sorting=0) { global $db; if ($file != "") { $realname = $file["name"]; $temp = explode(".", $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, $destination.$filename); move_uploaded_file($file["tmp_name"], $destination.$filename); chmod($destination.$filename, 0777); if ($re_name != "") { $filename = $re_name."_".$filename; } if ($table_id != "") { $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 && (trim($table_id) != "")) { $rowfile = $db->fetch_array($rs); if ($destination != "") { @unlink($destination.$rowfile["file_name"]); } if ($destination2 != "") { @unlink($destination2.$rowfile["file_name"]); } if ($destination3 != "") { @unlink($destination3.$rowfile["file_name"]); } if ($destination4 != "") { @unlink($destination4.$rowfile["file_name"]); } if ($destination5 != "") { @unlink($destination5.$rowfile["file_name"]); } $attachment_id = $rowfile["attachment_id"]; $sql = "UPDATE `attachment` SET `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); $attachment_id = $db->insert_id(); } } else if ($temp_id != "") { $sql = "SELECT `attachment_id`, `file_name` FROM `attachment` WHERE `table_name` = '".$table_name."' AND `temp_id` = '".$temp_id."' AND `col_name` = '".$col_name."'"; $rs = $db->query($sql); if (mysql_num_rows($rs) > 0 && (trim($temp_id) != "")) { $rowfile = $db->fetch_array($rs); if ($destination != "") { @unlink($destination.$rowfile["file_name"]); } if ($destination2 != "") { @unlink($destination2.$rowfile["file_name"]); } if ($destination3 != "") { @unlink($destination3.$rowfile["file_name"]); } if ($destination4 != "") { @unlink($destination4.$rowfile["file_name"]); } if ($destination5 != "") { @unlink($destination5.$rowfile["file_name"]); } $attachment_id = $rowfile["attachment_id"]; $sql = "UPDATE `attachment` SET `file_name` = '".$filename."', `real_name` = '".$realname."', `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."'"; $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' );"; //echo $sql; //exit(); $db->query($sql); $attachment_id = $db->insert_id(); } } $file_array = array(); $file_array["attachment_id"] = $attachment_id; $file_array["path"] = $path; $file_array["filename"] = $filename; $file_array["realname"] = $realname; $file_array["colname"] = $colname; return $file_array; } } function del_attachment($attachment_id,$prefix_path="../../"){ global $db; $sql = "SELECT `file_name`, `path` FROM `attachment` WHERE `attachment_id` = '".escapeit($attachment_id)."'"; $row = $db->getrow($sql); @unlink($prefix_path.$row["path"]."original/".$row["file_name"]); @unlink($prefix_path.$row["path"]."thumb_s/".$row["file_name"]); @unlink($prefix_path.$row["path"]."thumb_m/".$row["file_name"]); $sql = "DELETE FROM `attachment` WHERE `attachment_id` = '".escapeit($attachment_id)."'"; $db->query($sql); } function del_all_attachment($table_name,$value,$prefix_path="../../"){ global $db; $sql = "SELECT `file_name`, `path` FROM `attachment` WHERE `table_name` = '".escapeit($table_name)."' AND `table_id` = '".escapeit($value)."'"; $rs = $db->query($sql); while ($row = $db->fetch_array($rs)) { @unlink($prefix_path.$row["path"]."original/".$row["file_name"]); @unlink($prefix_path.$row["path"]."thumb_s/".$row["file_name"]); @unlink($prefix_path.$row["path"]."thumb_m/".$row["file_name"]); } $sql = "DELETE FROM `attachment` WHERE `table_name` = '".escapeit($table_name)."' AND `table_id` = '".escapeit($value)."'"; $db->query($sql); } function get_attachment($table_name,$table_id,$col_name){ global $db; // $sql = " SELECT `attachment_id`, `path`, `real_name`, `file_name` FROM `attachment` WHERE `table_name`='".$table_name."' and `table_id`='".$table_id."' and `col_name`='".$col_name."' "; // $sql = "SELECT `path`, `file_name`, `real_name`, upload_date FROM `tb_product_attachment` WHERE `table_id` = '".$id."'"; $sql = " SELECT `attachment_id`, `path`, `real_name`, `file_name`,upload_date FROM `tb_product_attachment` WHERE `table_id`='".$table_id."' "; $result = $db->query($sql); $row = mysql_fetch_assoc($result); $array["attachment_id"] = $row["attachment_id"]; $array["path"] = $row["path"]; $array["real_name"] = $row["real_name"]; $array["upload_date"] = $row["upload_date"]; $array["file_name"] = $row["file_name"]; return $array; } 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."' "; $sql = " SELECT `attachment_id`, `path`, `real_name`, `file_name`,upload_date FROM `tb_product_attachment` WHERE `table_id`='".$table_id."' "; $result = $db->query($sql); while($row = mysql_fetch_assoc($result)){ $myAttachment[$row["col_name"]]=$row["path"].$row["upload_date"].$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 = 'Show'; } } else { if ($lang == "chi") { $str = '隱藏'; } else { $str = 'Hidden'; } } return $str; } function imageresize($width, $height, $targetw, $targeth) { $percentage = 1; if (($width > $targetw) || ($height > $targeth)) { $width_diff = $width - $targetw; $height_diff = $height - $targeth; if ($width_diff >= $height_diff) { $percentage = ($targetw / $width); } else { $percentage = ($targeth / $height); } } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); $resize[0] = $width; $resize[1] = $height; return $resize; } function getCurrentURL() { $php_selfs = explode("/" , $_SERVER['PHP_SELF']); $from_filename = $php_selfs[sizeof($php_selfs)-1]; if ($_SERVER['QUERY_STRING'] != "") { $from_filename .= "?".$_SERVER['QUERY_STRING']; } return $from_filename; } function getSysVar($name) { global $db; $sql = "SELECT `value` FROM `setting` WHERE `name` = '".escapeit($name)."'"; $row = $db->getrow($sql); return $row["value"]; } ?>