connect($dbhost, $dbuser, $dbpw, $dbname); unset($dbhost, $dbuser, $dbpw, $dbname); session_start(); // set timeout period in seconds $inactive = 60000000000; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive){ session_destroy(); } } $_SESSION['timeout'] = time(); //cart session /*if (!isset($_SESSION["cart"])) { $_SESSION["cart"] = & new classCart(); } $cart = &$_SESSION["cart"]; */ if ( !function_exists('json_decode') ){ function json_decode($json) { $comment = false; $out = '$x='; for ($i=0; $i $value ) { $items[] = json_encode("$key") . ':' . json_encode($value); } $json = '{' . implode(',', $items) . '}'; } } elseif( is_string($data) ) { # Escape non-printable or Non-ASCII characters. # I also put the \\ character first, as suggested in comments on the 'addclashes' page. $string = '"' . addcslashes($data, "\\\"\n\r\t/" . chr(8) . chr(12)) . '"'; $json = ''; $len = strlen($string); # Convert UTF-8 to Hexadecimal Codepoints. for( $i = 0; $i < $len; $i++ ) { $char = $string[$i]; $c1 = ord($char); # Single byte; if( $c1 <128 ) { $json .= ($c1 > 31) ? $char : sprintf("\\u%04x", $c1); continue; } # Double byte $c2 = ord($string[++$i]); if ( ($c1 & 32) === 0 ) { $json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128); continue; } # Triple $c3 = ord($string[++$i]); if( ($c1 & 16) === 0 ) { $json .= sprintf("\\u%04x", (($c1 - 224) <<12) + (($c2 - 128) << 6) + ($c3 - 128)); continue; } # Quadruple $c4 = ord($string[++$i]); if( ($c1 & 8 ) === 0 ) { $u = (($c1 & 15) << 2) + (($c2>>4) & 3) - 1; $w1 = (54<<10) + ($u<<6) + (($c2 & 15) << 2) + (($c3>>4) & 3); $w2 = (55<<10) + (($c3 & 15)<<6) + ($c4-128); $json .= sprintf("\\u%04x\\u%04x", $w1, $w2); } } } else { # int, floats, bools, null $json = strtolower(var_export( $data, true )); } return $json; } } 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 = 80; $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; if(!empty($width)){ $imgTrans->resizeToWidth = $width; } if(!empty($height)){ $imgTrans->resizeToHeight = $height; } $imgTrans->jpegOutputQuality = 100; $imgTrans->resizeIfSmaller = false; $imgTrans->resize(); } } function add_attachment_formulti($file, $destination, $path, $small_path, $medium_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["tmp_name"], $destination.$filename); chmod($destination.$filename, 0777); if ($re_name != "") { $filename = $re_name."_".$filename; } $sql = "INSERT INTO `attachment` ( `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; } } 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' );"; $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; } } 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 `attachment2` WHERE `table_name`='".$table_name."' and `table_id`='".$table_id."' and `col_name`='".$col_name."' "; $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["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 `attachment2` 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 displaystr($display, $lang="chi") { $str = ""; if ($display == 1) { if ($lang == "chi") { $str = '顯示'; } else { $str = 'Display'; } } else { if ($lang == "chi") { $str = '隱藏'; } else { $str = 'Hidden'; } } return $str; } function displaystr2($display, $lang="chi") { $str = ""; if ($display == 1) { if ($lang == "chi") { $str = '顯示'; } else { $str = 'Yes'; } } else { if ($lang == "chi") { $str = '隱藏'; } else { $str = 'No'; } } 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; } //--- End Send email function --- ?>