0) { foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; if(!$natsort) { if ($order=='asc') asort($temp); else arsort($temp); } else { if ($case_sensitive===true) natsort($temp); else natcasesort($temp); if($order!='asc') $temp=array_reverse($temp,TRUE); } foreach(array_keys($temp) as $key) if (is_numeric($key)) $sorted[]=$array[$key]; else $sorted[$key]=$array[$key]; return $sorted; } return $sorted; } function getTime2($name, $class, $value){ $html = " "; return $html; } function getMin2($name, $class, $value){ $html = " "; return $html; } function show_online() { $logouttime = 300; $timenow = time(); // $timenow = (date("YmdHis", time())) + 0; //echo "

".$timenow; $loggedtime = $timenow - $logouttime; $loggedtime = date("Y-m-d H:i:s", $loggedtime); //echo "

".$loggedtime; //echo "

".base_convert($loggedtime, 16, 10); $sql = "SELECT `fname` FROM `member` WHERE `logtime` >= '".$loggedtime."'"; //Change '5 MINUTE' to anything. //5 MINUTE means that it'll display anyone online in the last 5 mins. $query = mysql_query($sql) or die (mysql_error()); $total = mysql_num_rows($query); if ($total != 0) { echo "("; $i = 0; while($row = mysql_fetch_array($query)) { $i++; if ($i == $total) { echo $row['fname']. ""; } else { echo $row['fname']. ", "; } } echo ")"; } else { echo ""; } } function update_online($mem) { $timenow = date("Y-m-d H:i:s", time()); if ($mem != "") { $conn = connectdb(); $sql = "update member set logtime='".$timenow."' where mem_id='".$mem."'"; $query = mysql_query($sql, $conn) or die (mysql_error()); } } function setPoint($action_id, $member_id){ $conn = connectdb(); $sql = "select * from `action` where action_id = '$action_id' and status = 'activate'"; $result = mysql_query($sql, $conn) or die ("select failed"); if ($myrow = mysql_fetch_object($result)){ $sql2 = "INSERT INTO `point` ( `point_id` , `member_id` , `point` , `desc` , `action_date` , `status` ) VALUES ('', '$member_id', '$myrow->point', '$myrow->desc', NOW(), 'activate')"; mysql_query($sql2, $conn) or die ("insert failed"); } } function getPrice($book_id){ $book_id = addslashes($book_id); $conn = connectdb(); $sql = "select * from book where book_id = '$book_id'"; $result = mysql_query($sql, $conn) or die("Failed to get clients' info
".mysql_error()."
"); if($myrow = mysql_fetch_object($result)){ $price = $myrow->price; } $mydiscount = getDiscount($book_id); return $price * (100 - $mydiscount)/100; } function getDiscount($book_id){ $book_id = addslashes($book_id); $conn = connectdb(); $sql = "select * from book where book_id = '$book_id'"; $result = mysql_query($sql, $conn) or die("Failed to get clients' info
".mysql_error()."
"); if($myrow = mysql_fetch_object($result)){ $mydiscount = $myrow->discount; } $sql = "select max(discount) podiscount from promotion, promotion_book where promotion.status = 'activate' and start_date < now() and date_add(end_date, interval 1 day) > now() and promotion_book.promotion_id = promotion.promotion_id and promotion_book.book_id = '$book_id' "; $result = mysql_query($sql, $conn) or die("Failed to get clients' info
".mysql_error()."
"); if($myrow = mysql_fetch_object($result)){ if($mydiscount < $myrow->podiscount){ $mydiscount = $myrow->podiscount; } } return $mydiscount; } function genPwd(){ $pwdLen = 6; $goodPwd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; $pwd = ""; for($i=0; $i < $pwdLen; $i++){ $r = rand(0, 61); $pwd .= substr($goodPwd, $r, 1); } return $pwd; } function toPrice($s){ if ((int)($s) != $s){ $s = $s + 0.04; } $s = round($s, 1); return number_format($s, 1); } function toOrderId($id){ return str_pad($id, 7, "0", STR_PAD_LEFT); } function getExt($f){ if (strrpos($f, ".") != false){ $ext = substr($f, strrpos($f, ".")); return $ext; }else{ return false; } } function LF2BR($stext){ $LF = chr(13); $stext = str_replace($LF, "
", $stext); return $stext; } function sprint($stext){ return htmlspecialchars(stripslashes($stext), ENT_QUOTES); } function chi_sprint($stext){ $my_stext = stripslashes($stext); $my_stext = str_replace ('\'', ''', $my_stext ); $my_stext = str_replace ('"', '"', $my_stext ); return $my_stext; } function remove_spring($stext){ $my_stext = stripslashes($stext); $my_stext = str_replace (' ', '', $my_stext ); $my_stext = str_replace ('(', '', $my_stext ); $my_stext = str_replace (')', '', $my_stext ); $my_stext = str_replace ('-', '', $my_stext ); $my_stext = str_replace (' ', '', $my_stext ); return $my_stext; } function check_email($str) { //returns 1 if valid email, 0 if not if(ereg("^.+@.+\\..+$", $str)) return 1; else return 0; } function ImageResize(&$src, $x, $y){ $dst = imagecreatetruecolor($x, $y); $pals = ImageColorsTotal($src); for ($i = 0; $i < $pals; $i++){ $colors = ImageColorsForIndex ($src, $i); ImageColorAllocate($dst, $colors['red'], $colors['green'], $colors['blue']); } $scX = (imagesx($src)) / $x; $scY = (imagesy($src)) / $y; $scX2 = intval($scX / 2); $scY2 = intval($scY / 2); for ($j = 0; $j < ($y); $j++){ $sY = intval($j * $scY); $y13 = $sY + $scY2; for ($i = 0; $i < ($x); $i++){ $sX = intval($i * $scX); $x34 = $sX + $scX2; $c1 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $y13)); $c2 = ImageColorsForIndex($src, ImageColorAt($src, $sX, $sY)); $c3 = ImageColorsForIndex($src, ImageColorAt($src, $x34,$y13)); $c4 = ImageColorsForIndex($src, ImageColorAt($src, $x34,$sY)); $r = ($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4; $g = ($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4; $b = ($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4; ImageSetPixel ($dst, $i, $j, ImageColorClosest($dst, $r, $g, $b)); } } return ($dst); } function makeImage($filepath, $width, $height, $targetfile){ //$im = imagecreatefromjpeg($filepath); $ext = strtolower(getExt($targetfile)); if ($ext == ".jpg" || $ext == ".jpeg"){ $im = imagecreatefromjpeg($filepath); }elseif ($ext == ".png"){ $im = imagecreatefrompng($filepath); }elseif ($ext == ".gif"){ $im = imagecreatefromgif($filepath); }else{ return false; } if ($height == 0 && $width == 0) return false; else{ if ($height == 0){ $scX = (imagesx($im)) / $width; $height = (imagesy($im)) / $scX; } if ($width == 0){ $scY = (imagesy($im)) / $height; $width = (imagesx($im)) / $scY; } $imB = imagecreatetruecolor($width, $height); $imB = ImageResize($im, $width, $height); if ($ext == ".jpg" || $ext == ".jpeg"){ imagejpeg($imB, $targetfile, 100); return true; }elseif ($ext == ".png"){ imagepng($imB, $targetfile, 100); return true; }elseif ($ext == ".gif"){ imagegif($imB, $targetfile); return true; }else{ return false; } } } function spic_upload($product_image, $width, $height, $destination, $wm="N", $pos=1){ //$img = ImageCreateFromJpeg($product_image); $ext = strtolower(getExt($destination)); if ($ext == ".jpg" || $ext == ".jpeg"){ $img = imagecreatefromjpeg($product_image); }elseif ($ext == ".png"){ $img = imagecreatefrompng($product_image); }elseif ($ext == ".gif"){ $img = imagecreatefromgif($product_image); }else{ return false; } $y = ImageSY($img); $x = ImageSX($img); if (($y != "") && ($x != "")){ if($y * $width >= $x * $height){ if ($height == 0) makeImage($product_image, 0, $y, $destination) or die("Cannot upload the image"); elseif ($y >= $height) makeImage($product_image, 0, $height, $destination) or die("Cannot upload the image"); else makeImage($product_image, 0, $y, $destination) or die("Cannot upload the image"); }else{ if ($width == 0) makeImage($product_image, $x, 0, $destination) or die("Cannot upload the image"); elseif ($x >= $width) makeImage($product_image, $width, 0, $destination) or die("Cannot upload the image"); else makeImage($product_image, $x, 0, $destination) or die("Cannot upload the image"); } if($wm == "Y") waterMark($destination, "../img/baozon_watermark.gif", $pos); return true; } else return false; } function showimage($imagepath, $imagewidth, $imageheight, $error_msg="No image", $imageid=""){ if(is_file($imagepath)){ $img = ImageCreateFromJpeg($imagepath); $y = ImageSY($img); $x = ImageSX($img); if($y >= $x){ if($y > $imageheight) $myphoto = ""; else $myphoto = ""; }else{ if($x > $imagewidth) $myphoto = ""; else $myphoto = ""; } } else $myphoto = "$error_msg"; if($myphoto != "") echo "$myphoto"; } function GetCartId(){ if($_COOKIE["cartId"] != ""){ return $_COOKIE["cartId"]; } else{ setcookie("cartId", session_id(), time() + ((3600 * 24) * 3), "/"); return session_id(); } } function substr_big5($str,$ct) { if(strlen($str) > $ct) { for($i=0;$i<$ct;$i++) { $ch=substr($str,$i,1); if(ord($ch)>127) $i++; } $str= substr($str,0,$i); } return $str; } function substr_utf8($str,$ct) { if(strlen($str) > $ct) { for($i=0;$i<$ct;$i++) { $ch=substr($str,$i,1); if(ord($ch)>255) $i++; } $str= substr($str,0,$i); } return $str; } function utf8_substr($str,$from,$len){ return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'. '((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s', '$1',$str); } function subEng($str, $ct){ $i = 0; while (strlen($str) > $ct){ if (strrpos($str, ' ') > 0){ $i = strrpos($str, ' '); }else{ $i = $ct; } $str = substr($str,0, $i); } return $str; } function waterMark($fileInHD, $wmFile, $pos = 1, $transparency = 100, $jpegQuality = 90, $margin = 5) { $wmImg = imageCreateFromGIF($wmFile); $jpegImg = imageCreateFromJPEG($fileInHD); if ($pos == 1){ $wmX = $margin; $wmY = $margin; } if ($pos == 2){ $wmX = (imageSX($jpegImg) - imageSX($wmImg)) - $margin; $wmY = $margin; } if ($pos == 3){ $wmX = $margin; $wmY = (imageSY($jpegImg) - imageSY($wmImg)) - $margin; } if ($pos == 4){ $wmX = (imageSX($jpegImg) - imageSX($wmImg)) - $margin; $wmY = (imageSY($jpegImg) - imageSY($wmImg)) - $margin; } // Water mark random position // $wmX = (imageSX($jpegImg) - imageSX($wmImg)) - $margin; //$wmX = $margin; //$wmY = (imageSY($jpegImg) - imageSY($wmImg)) - $margin; // Water mark process imageCopyMerge($jpegImg, $wmImg, $wmX, $wmY, 0, 0, imageSX($wmImg), imageSY($wmImg), $transparency); // Overwriting image ImageJPEG($jpegImg, $fileInHD, $jpegQuality); } function merge3Image($headImage, $bodyImage, $footImage){ if (trim($headImage) == "" || trim($bodyImage) == "" || trim($footImage) == ""){ return false; } if (imageSource($headImage) == false || imageSource($bodyImage) == false || imageSource($footImage) == false){ return false; } $imgHead = imageSource($headImage); $imgBody = imageSource($bodyImage); $imgFoot = imageSource($footImage); $imgHeadWidth = imagesx ($imgHead); $imgBodyWidth = imagesx ($imgBody); $imgFootWidth = imagesx ($imgFoot); $imgHeadHeight = imagesy ($imgHead); $imgBodyHeight = imagesy ($imgBody); $imgFootHeight = imagesy ($imgFoot); //$imgWidth = 0; //$imgHeight = 270; //if ($imgHeadWidth >= $imgBodyWidth && $imgHeadWidth >= $imgFootWidth) // $imgWidth = $imgHeadWidth; //elseif($imgBodyWidth >= $imgHeadWidth && $imgHeadWidth >= $imgFootWidth) // $imgWidth = $imgBodyWidth; //elseif($imgFootWidth >= $imgHeadWidth && $imgHeadWidth >= $imgBodyWidth) // $imgWidth = $imgFootWidth; // //$imResult = imagecreatetruecolor($imgWidth, $imgHeight); $imResult = imagecreatefromjpeg("../com/cartoon.jpg"); $imgWidth = imagesx($imResult); $imgHeight = imagesy($imResult); $resultX = ($imgWidth - $imgFootWidth) / 2; $resultY = 165; imagecopymerge($imResult, $imgFoot, $resultX, $resultY, 0, 0, $imgFootWidth, $imgFootHeight, 100); $resultX = ($imgWidth - $imgBodyWidth) / 2; $resultY = 70; imagecopymerge($imResult, $imgBody, $resultX, $resultY, 0, 0, $imgBodyWidth, $imgBodyHeight, 100); $resultX = ($imgWidth - $imgHeadWidth) / 2; $resultY = 0; imagecopymerge($imResult, $imgHead, $resultX, $resultY, 0, 0, $imgHeadWidth, $imgHeadHeight, 100); return $imResult; } function isImage($fileImage){ if (strtolower(getExt($fileImage)) != ".gif" && strtolower(getExt($fileImage)) != ".jpg" && strtolower(getExt($fileImage)) != ".jpeg" && strtolower(getExt($fileImage)) != ".png"){ return false; }else{ return true; } } function imageSource($fileImage){ if (isImage($fileImage) == true){ $ext = strtolower(getExt($fileImage)); switch($ext){ case ".gif": $imgs = imagecreatefromgif($fileImage); break; case ".jpg": $imgs = imagecreatefromjpeg($fileImage); break; case ".jpeg": $imgs = imagecreatefromjpeg($fileImage); break; case ".png": $imgs = imagecreatefrompng($fileImage); break; } return $imgs; }else{ return false; } } function zen_validate_password($plain, $encrypted) { if (zen_not_null($plain) && zen_not_null($encrypted)) { // split apart the hash / salt $stack = explode(':', $encrypted); if (sizeof($stack) != 2) return false; if (md5($stack[1] . $plain) == $stack[0]) { return true; } } return false; } //// // This function makes a new password from a plaintext password. function zen_encrypt_password($plain) { $password = ''; for ($i=0; $i<10; $i++) { $password .= zen_rand(); } $salt = substr(md5($password), 0, 2); $password = md5($salt . $plain) . ':' . $salt; return $password; } function zen_rand($min = null, $max = null) { static $seeded; if (!isset($seeded)) { mt_srand((double)microtime()*1000000); $seeded = true; } if (isset($min) && isset($max)) { if ($min >= $max) { return $min; } else { return mt_rand($min, $max); } } else { return mt_rand(); } } function zen_not_null($value) { if (is_array($value)) { if (sizeof($value) > 0) { return true; } else { return false; } } else { if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) { return true; } else { return false; } } } function zen_create_random_value($length, $type = 'mixed') { if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false; $rand_value = ''; while (strlen($rand_value) < $length) { if ($type == 'digits') { $char = zen_rand(0,9); } else { $char = chr(zen_rand(0,255)); } if ($type == 'mixed') { if (eregi('^[a-z0-9]$', $char)) $rand_value .= $char; } elseif ($type == 'chars') { if (eregi('^[a-z]$', $char)) $rand_value .= $char; } elseif ($type == 'digits') { if (ereg('^[0-9]$', $char)) $rand_value .= $char; } } return $rand_value; } ?>