| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/citysuper/webadmin/ |
Upload File : |
<?php
include_once("../webadmin/configure.php");
if (isset($_SESSION["vip_code"])) {
$vip_code = $_SESSION["vip_code"];
} else {
$vip_code = 0;
}
/***************************************************
* _member
*/
if (!function_exists('all_member_info')) {
function all_member_info()
{
global $dbh;
$sql = "select * from member where deleted = ? ";
$parameters = array("0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll();
}
}
/***************************************************
* _category
*/
if (!function_exists('get_category_info')) {
function get_category_info($categoryid)
{
global $dbh;
$sql = "select * from pro_category where categoryid = ? and status = ? and deleted = ?";
$parameters = array($categoryid, "1", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetch(PDO::FETCH_ASSOC);
}
}
if (!function_exists('get_default_cid_pcid')) {
function get_default_cid_pcid($productid)
{
global $dbh;
$sql = "select * from pro_product_category ppcate inner join pro_category pcate on ppcate.categoryid = pcate.categoryid where ppcate.productid = ? and pcate.status = ? and deleted = ? order by ppcate.procatsort ASC";
$parameters = array($productid, "1", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$result = $sth->fetch(PDO::FETCH_ASSOC);
$cid_pcid_array = array("cid" => $result{"categoryid"}, "pcid" => $result{"parentid"});
return $cid_pcid_array;
}
}
/***************************************************
* _product
*/
if (!function_exists('get_product_info')) {
function get_product_info($productid)
{
global $dbh;
$sql = "select * from pro_product where productid = ? and status = ? and deleted = ? and old_record = ? order by lastupdate DESC limit 1";
$parameters = array($productid, "1", "0", "0");
return bind_pdo($sql, $parameters, "selectone");
}
}
if (!function_exists('get_product_image')) {
function get_product_image($productid)
{
global $dbh;
$sql = "select * from pro_image where productid = ? and status = ? and deleted = ? order by sort ASC";
$parameters = array($productid, "1", "0");
return bind_pdo($sql, $parameters, "selectall");
}
}
if (!function_exists('get_category_product')) {
function get_category_product($categoryid)
{
global $dbh, $langcode;
$sql = "SELECT *, pd.createdate as pd_createdate FROM pro_product pd INNER JOIN pro_product_category pdc ON pd.productid = pdc.productid INNER JOIN pro_category pc ON pc.categoryid = pdc.categoryid WHERE pd.deleted = ? and pd.old_record = ? AND pdc.categoryid = ? and pc.status = ? and pc.deleted = ? ORDER BY pd.sort ASC ";
$parameters = array("0", "0", (int)$categoryid, "1", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$all_product_info = $sth->fetchAll();
$real_all_product_info = array(array());
$count = 0;
foreach ($all_product_info as $key => $product_info) {
$sku_info = get_default_sku($product_info{"productid"});
if ($sku_info) {
$sku_sale_price_info = get_product_discount($sku_info{"proskuid"});
$real_all_product_info[$count]["categoryid"] = $product_info{"categoryid"};
$real_all_product_info[$count]["categoryname"] = $product_info{"categoryname_" . $langcode};
$real_all_product_info[$count]["pcategoryid"] = $product_info{"parentid"};
$product_img_info = get_product_image($product_info{"productid"});
if ($product_img_info) {
$real_all_product_info[$count]["image"] = $product_img_info[0]{"photo"};
} else {
$real_all_product_info[$count]["image"] = "";
}
$real_all_product_info[$count]["productname"] = $product_info{"productname_" . $langcode};
$real_all_product_info[$count]["price"] = $product_info{"categoryid"};
$real_all_product_info[$count]["productid"] = $product_info{"productid"};
$real_all_product_info[$count]["createdate"] = $product_info{"pd_createdate"};
if ($sku_sale_price_info) {
$real_all_product_info[$count]["price"] = $sku_sale_price_info{"sale_price"};
} else {
$real_all_product_info[$count]["price"] = $sku_info{"standardprice"};
}
$count++;
}
}
return $real_all_product_info;
}
}
/*if (!function_exists('product_share')) {
function product_share($from_vip_code, $to_vip_code, $productid, $message_content)
{
global $dbh;
$sql = "insert into (message_type, from_vip_code, to_vip_code,productid, message_title_en, message_title_tc, message_title_sc, message_content, createby, createdate, lastupby, lastupdate) values (?,?,?,?,?,?,?,?,?,?,?,?)";
$product_info = get_product_info($productid);
$message_title_en = "SHARE: I want to share product (" . $product_info{"productname_en"} . "-" . $product_info{"productitemcode"} . ") to you.";
$message_title_tc = "分享: 我想分享有關 (" . $product_info{"productname_tc"} . "-" . $product_info{"productitemcode"} . ") 的資訊給你";
$message_title_sc = "分享: 我想分享有? (" . $product_info{"productname_sc"} . "-" . $product_info{"productitemcode"} . ") 的???你";
$parameters = array("2", $from_vip_code, $to_vip_code, $productid, $message_title_en, $message_title_tc, $message_title_sc, $message_content, "0", date("Y-m-d H:i:s"), "0", date("Y-m-d H:i:s"),);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
}
}*/
/***************************************************
* product sku
*/
if (!function_exists('get_all_sku')) {
function get_all_sku($productid)
{
global $dbh;
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? order by sort";
$parameters = array($productid, "1", "0", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll();
}
}
if (!function_exists('get_default_sku')) {
function get_default_sku($productid)
{
global $dbh;
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? order by sort ASC, lastupdate DESC limit 1";
$parameters = array($productid, "1", "0", "0");
return bind_pdo($sql, $parameters, "selectone");
}
}
if (!function_exists('get_product_size')) {
function get_product_size($productid)
{
global $dbh;
$sql = "SELECT * FROM ( select * from `pro_product_sku` order by sort ASC) as prosku_temp where productid = ? and status = ? and deleted = ? and old_record = ? group by size_code order by sort ASC";
$parameters = array($productid, "1", "0", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll();
}
}
if (!function_exists('get_product_color')) {
function get_product_color($productid, $size_code)
{
global $dbh;
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? and size_code = ? order by sort ASC";
$parameters = array($productid, "1", "0", "0", $size_code);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll();
}
}
if (!function_exists('get_sku_info')) {
function get_sku_info($proskuid)
{
global $dbh;
$sql = "select * from pro_product_sku where proskuid = ? and status = ? and deleted = ? and old_record = ? order by lastupdate DESC limit 1";
$parameters = array($proskuid, "1", "0", "0");
$sku_info = bind_pdo($sql, $parameters, "selectone");
if(!empty($sku_info)){
$sku_discount_info = get_product_discount($proskuid);
if (!$sku_discount_info) { //no discount, show standard price
$price = $sku_info{"standardprice"};
} else {
$price = $sku_discount_info{"sale_price"};
}
$sku_info["saleprice"] = $price;
}
return $sku_info;
}
}
if (!function_exists('get_sku_info2')) {
function get_sku_info2($productid, $size_code, $color_code)
{
global $dbh;
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and size_code = ? and color_code = ? and old_record = ? order by lastupdate DESC";
$parameters = array($productid, "1", "0", $size_code, $color_code, "0");
return bind_pdo($sql, $parameters, "selectone");
}
}
/*if (!function_exists('matched_sku_info')) {
function matched_sku_info($product_group)
{
if (!empty($product_group)) {
global $dbh;
$matched_sku = array(array());
$sql2 = "select * from product_group where progroup_id = ? and old_record = ? and deleted = ?";
$parameters2 = array($product_group, "0", "0");
if (!($sth2 = $dbh->prepare($sql2))) {
throw new Exception('[' . $sth2->errorCode() . ']: ' . print_r($sth2->errorInfo()));
exit;
}
if (!$sth2->execute($parameters2)) {
throw new Exception('[' . $sth2->errorCode() . ']: ' . print_r($sth2->errorInfo()));
exit;
}
$product_group_info = $sth2->fetch(PDO::FETCH_ASSOC);
$proskuids = $product_group_info{"proskuids"};
$proskuids = explode($proskuids, ",");
//search this proskuid in ord_list
foreach ($proskuids as $proskuid) {
$sql3 = "select * from ord_list_temp temp, pro_product_sku sku where temp.vip_code = ? and temp.proskuid = sku.proskuid and temp.proskuid = ?";
$parameters3 = array($_SESSION["vip_code"], $proskuid);
if (!($sth3 = $dbh->prepare($sql3))) {
throw new Exception('[' . $sth3->errorCode() . ']: ' . print_r($sth3->errorInfo()));
}
if (!$sth3->execute($parameters3)) {
throw new Exception('[' . $sth3->errorCode() . ']: ' . print_r($sth3->errorInfo()));
}
$matched_sku[] = $sth3->fetch(PDO::FETCH_ASSOC);
}
return $matched_sku;
}
}
}*/
/***************************************************
* member
*/
if (!function_exists('get_member_info')) {
function get_member_info($vip_code)
{
global $dbh;
$sql = "select * from VIP where VIP_CODE = ? ";
$parameters = array($vip_code);
$member_info = bind_pdo($sql, $parameters, "selectone");
if(!empty($member_info)){
$sql2 = "select * from VIPVerifingTel where verifyingTel = ?";
$parameters2 = array("852".$member_info{"VIP_TEL"});
$active_member_info = bind_pdo($sql2, $parameters2, "selectone");
}
if(!empty($active_member_info)){
$sql = "select * from jPOS_VIPGrade where VIP_GRADE = ?";
$parameters = array($member_info{"VIP_GRADE"});
$vip_grade_info = bind_pdo($sql, $parameters, "selectone");
$member_info["VIP_LEVEL_DISCOUNT_RATE"] = (float)$vip_grade_info{"VIP_LEVEL_DISCOUNT_RATE"};
return $member_info;
}else{
return NULL;
}
}
}
if (!function_exists('get_member_name')) {
function get_member_name($member_info)
{
global $dbh;
//if (preg_match("/[a-zA-Z]/", $member_info{"VIP_LAST_NAME"}) && preg_match("/[a-zA-Z]/", $member_info{"VIP_FIRST_NAME"})) {
if (preg_match('/^([a-zA-Z\s]+)$/', $member_info{"VIP_LAST_NAME"}) && preg_match('/^([a-zA-Z\s]+)$/', $member_info{"VIP_FIRST_NAME"})) {
$member_name = $member_info{"VIP_FIRST_NAME"} . " " . $member_info{"VIP_LAST_NAME"};
} else {
$member_name = $member_info{"VIP_LAST_NAME"} . $member_info{"VIP_FIRST_NAME"};
}
return $member_name;
}
}
if (!function_exists('check_member_login')) {
function check_member_login()
{
if (empty($_SESSION["vip_code"]) || !isset($_SESSION["vip_code"])) {
return "<script>alert('Please login first.');top.location.href='member_login.php'; </script>";
}else{
return NULL;
}
}
}
/***************************************************
* discount
*/
if (!function_exists('get_product_discount')) {
function get_product_discount($proskuid)
{
global $dbh;
$sql = "select * from product_discount where proskuid = ? and status = ? and deleted = ? and ? between start_date and end_date";
$parameters = array($proskuid, "1", "0", date('Y-m-d'));
return bind_pdo($sql, $parameters, "selectone");
}
}
if (!function_exists('get_discount_info')) {
function get_discount_info($discount_id = NULL)
{
global $dbh;
if(empty($discount_id)){
$sql = "select * from discount where status = ? and deleted = ? and old_record = ? and ? between datefrom and dateto order by priority ASC";
$parameters = array(1, 0, 0, date("Y-m-d"));
$discount_info = bind_pdo($sql, $parameters, "selectall");
}else{
$sql = "select * from discount where discount_id = ?";
$parameters = array($discount_id);
$discount_info = bind_pdo($sql, $parameters, "selectone");
}
return $discount_info;
}
}
/***************************************************
* _checkout _order
*/
if (!function_exists('get_order_info')) {
function get_order_info($vip_code, $order_id = NULL){
global $dbh;
//display temp order
if(empty($order_id)){
$sql = "select * from `order` where vip_code = ? and temp = ? order by lastupdate DESC limit 1 ";
$parameters = array($vip_code, 1);
$order_info = bind_pdo($sql, $parameters, "selectone");
}else{ //display real order
//$sql = "select order_id,vip_code,INV_NO,ordernumber,subtotal,totalamount,mvip_discount,member_deduct,coupon_deduct,point_deduct,discount_deduct,specialgift_deduct,order_status,lastname,firstname,telephone,shipping_method,address,district_id,store_id,createdate from `order` where vip_code = ? and temp = ? and order_id = ? order by lastupdate DESC limit 1 ";
$sql = "select * from `order` where vip_code = ? and temp = ? and order_id = ? order by lastupdate DESC limit 1 ";
$parameters = array($vip_code, 0, $order_id);
$order_info = bind_pdo($sql, $parameters, "selectone");
}
return $order_info;
}
}
if (!function_exists('order_temp_total')) {
function order_temp_total($vip_code)
{
global $dbh;
$order_temp_total = 0;
$result = get_order_temp($vip_code);
//add more info in temp order list pool
foreach ($result as $key => $temp_order) {
$sku_info = get_sku_info($temp_order["proskuid"]);
$order_temp_total += ($sku_info["standardprice"]*$temp_order["quantity"]);
}
return $order_temp_total;
}
}
if (!function_exists('onchange_size_color')) {
function onchange_size($productid, $size_code, $color_code)
{
global $dbh;
$result = array(
"chanage_price" => "",
"change color" => "",
"change_promotion_package" => "",
"change_others_promotion" => "",
);
//both change
//find the proskuid
if (empty($color_code)) {
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? and size_code = ? order by sort limit 1";
$parameters = array($productid, "1", "0", "0", $size_code);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$proskuid = $sth->fetch(PDO::FETCH_ASSOC);
$product_color = get_product_color($productid, $size_code);
$product_color_html = "";
foreach ($product_color as $this_color) {
//sample
$product_color_html .= "<div class='' id='" . $this_color{"color_code"} . "' style=\"border: 1px solid #b3b3b3; background: url('../images/color_images/" . $this_color{"color_img"} . "') no-repeat; width: 50px; height:50px;float:left;margin-right:10px;\" > </div>";
}
//html with change color
$result["change color"] = $product_color_html;
} else {
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? and size_code = ? and color_code = ? limit 1";
$parameters = array($productid, "1", "0", "0", $size_code, $color_code);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$proskuid = $sth->fetch(PDO::FETCH_ASSOC);
}
//change price
$prosku_discount = get_product_discount($proskuid);
if (!empty($prosku_discount)) {
//html with sale price and ori price
$result["chanage_price"] = "";
} else {
//html with ori price
$result["chanage_price"] = "";
}
//change promotion package
//array 0 = promotion package, array 1 = others promotion
$discount_info = get_valid_discount($proskuid);
$promotion_package = $discount_info[0];
$others_promotion = $discount_info[1];
if (!empty($promotion_package)) {
//html with promotion package, should include pop up css
$result["promotion_package"] = "";
} else {
//no promotion package
}
if (!empty($others_promotion)) {
//html with others promotion
$result["others_promotion"] = "";
} else {
}
return json_encode($result);
}
}
//similar to onchange_size_color
//ajax function, direct display html as result
if (!function_exists('pop_up_onchange_size_color')) {
function pop_up_onchange_size_color($productid, $size_code, $color_code)
{
global $dbh;
$result2 = array(
"'pop_up_chanage_price" => "",
"'pop_up_hange color" => "",
);
//both change
//find the proskuid
if (empty($color_code)) {
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? and size_code = ? order by sort limit 1";
$parameters = array($productid, "1", "0", "0", $size_code);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$proskuid = $sth->fetch(PDO::FETCH_ASSOC);
$product_color = get_product_color($productid, $size_code);
$product_color_html = "";
foreach ($product_color as $this_color) {
//sample
$product_color_html .= "<div class='' id='" . $this_color{"color_code"} . "' style=\"border: 1px solid #b3b3b3; background: url('../images/color_images/" . $this_color{"color_img"} . "') no-repeat; width: 50px; height:50px;float:left;margin-right:10px;\" > </div>";
}
//html with change color
$result2["change color"] = $product_color_html;
} else {
$sql = "select * from pro_product_sku where productid = ? and status = ? and deleted = ? and old_record = ? and size_code = ? and color_code = ? limit 1";
$parameters = array($productid, "1", "0", "0", $size_code, $color_code);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$proskuid = $sth->fetch(PDO::FETCH_ASSOC);
}
//change price
$prosku_discount = get_product_discount($proskuid);
if (!empty($prosku_discount)) {
//html with sale price and ori price
$result2["chanage_price"] = "";
} else {
//html with ori price
$result2["chanage_price"] = "";
}
}
}
if (!function_exists('get_shipping_info')) {
function get_shipping_info($location_id)
{
global $dbh;
$sql = "select * from shipping_fee where location_id = ? ";
$parameters = array($location_id);
return bind_pdo($sql, $parameters, "selectone");
}
}
/***************************************************
* _others function
*/
if (!function_exists('get_user_visit')) {
function get_user_visit($current_productid)
{
global $dbh, $vip_code, $langcode;
$real_product_info = array(array());
if (!empty($vip_code)) { //get user visit by cookies
$sql = "select * from user_visit where vip_code = ? and productid != ? group by productid";
$parameters = array($vip_code, $current_productid);
} else { //get user visit by member
if (isset($_COOKIE['sinomax_user_visit'])) {
$sql = "select * from user_visit where user_cookies = ? and productid != ? group by productid";
$parameters = array($_COOKIE['sinomax_user_visit'], $current_productid);
} else {
return NULL;
}
}
$user_visit_info = bind_pdo($sql, $parameters, "selectall");
$count = 0;
foreach ($user_visit_info as $user_visit) {
$productid = $user_visit{"productid"};
$sql = "SELECT *, pd.createdate as pd_createdate FROM pro_product pd INNER JOIN pro_product_category pdc ON pd.productid = pdc.productid INNER JOIN pro_category pc ON pc.categoryid = pdc.categoryid WHERE pd.deleted = ? and pd.old_record = ? AND pd.productid = ? and pc.status = ? and pc.deleted = ? ORDER BY pd.sort ASC limit 1";
$parameters = array("0", "0", $productid, "1", "0");
$product_info = bind_pdo($sql, $parameters, "selectone");
$sku_info = get_default_sku($product_info{"productid"});
if ($sku_info) {
$sku_sale_price_info = get_product_discount($sku_info{"proskuid"});
$real_product_info[$count]["categoryid"] = $product_info{"categoryid"};
$real_product_info[$count]["categoryname"] = $product_info{"categoryname_" . $langcode};
$real_product_info[$count]["pcategoryid"] = $product_info{"parentid"};
$product_img_info = get_product_image($product_info{"productid"});
$real_product_info[$count]["image"] = $product_img_info[0]{"photo"};
$real_product_info[$count]["productname"] = $product_info{"productname_" . $langcode};
$real_product_info[$count]["productid"] = $product_info{"productid"};
if ($sku_sale_price_info) {
$real_product_info[$count]["price"] = $sku_sale_price_info{"sale_price"};
} else {
$real_product_info[$count]["price"] = $sku_info{"standardprice"};
}
$count++;
}
}
return $real_product_info;
}
}
if (!function_exists('large_to_small')) {
function large_to_small($a, $b)
{
if ($a["product_count"] == $b["product_count"]) {
return 0;
}
return ($a["product_count"] > $b["product_count"]) ? -1 : 1;
}
}
if (!function_exists('numberformat')) {
function numberformat($data)
{
return number_format($data, "2", ".", ",");
}
}
include_once('device_detect.php');
$device_detect = new Mobile_Detect();
$deviceType = ($device_detect->isMobile() ? ($device_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$scriptVersion = $device_detect->getScriptVersion();
/***************************************************
* _VIP function
*/
/*if (!function_exists('vip_upgrade_checking')) {
function vip_upgrade_checking($member_info)
{
$message = "1";
global $dbh;
//this vip type can upgrade to next level
if ($member_info{"mvip_upgrade"} == 1 && !empty($member_info{"next_vip_level"})) {
$message = "2";
$pass_one_bill_over = false; //condition 1
$pass_accumulate = false; //condition 2
$vip_code = $_SESSION["vip_code"];
$sql = "select * from member_vip where mvip_type = ? and old_record = ? and deleted = ?";
$parameters = array($member_info{"next_vip_level"}, "0", "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$next_vip_level_info = $sth->fetch(PDO::FETCH_ASSOC);
if ($next_vip_level_info) {
$message = "3";
//check if pass one bill over
$sql = "select * from `order` where vip_code = ? and temp = ? and deleted = ? and order_status = ?";
$parameters = array($vip_code, "0", "0", "4");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
//looping each `order` and check if any bill over one bill amount
while ($order_info = $sth->fetch(PDO::FETCH_ASSOC)) {
if ($order_info{"totalamount"} >= $next_vip_level_info{"one_bill_over"}) {
$pass_one_bill_over = true;
break;
}
}
//check if user total amount accumulate over defined year and defined points
$accumulate_total_amount = 0;
$sql = "select * from `order` where vip_code = ? and temp = ? and deleted = ? and order_status = ? and createdate between ? and ?";
$parameters = array($vip_code, "0", "0", "5", date("Y-m-d H:i:s"),
date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "-" . $next_vip_level_info{"year_required"} . " year")));
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
while ($order_info = $sth->fetch(PDO::FETCH_ASSOC)) {
$accumulate_total_amount += $order_info{"totalamount"};
}
if ($accumulate_total_amount >= $next_vip_level_info{"year_required_points"}) {
$pass_accumulate = true;
}
//user allow to update
if ($pass_one_bill_over || $pass_accumulate) {
$message = "4";
//check if this message already post
$sql = "select * from message where to_vip_code = ? and message_type = ? and from_admin = ? and createdate > ? and deleted = ?";
$parameters = array($member_info{"vip_code"}, "3", "1", date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s") . "-1 month")), "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if ($sth->rowCount() <= 0) { //allow to post a new message
$message = "5";
//system message: user can upgrade
$sql = "insert into (message_type, from_admin, to_vip_code, message_title_en, message_title_tc, message_title_sc, message_content_en, message_content_tc, message_content_sc,system_message_flag, createby, createdate, lastupby, lastupdate) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
$message_title_en = "Congratulation! You can upgrade to next vip level. You can click the 'Upgrade' button and we will approve it as soon as possible.";
$message_title_tc = "恭喜您,你的會員級別已經可以晉升,請按'晉升'按鈕,我們將盡快升級您的會員級別。";
$message_title_sc = "恭喜您,你的会员级别已经可以晋升,请按'晋升'按钮,我们将尽快升级您的会员级别。";
$message_content_en = "Congratulation! You can upgrade to next vip level. You can click the 'upgrade button' and we will approve it as soon as possible.";
$message_content_tc = "恭喜您,你的會員級別已經可以晉升,請按'晉升'按鈕,我們將盡快升級您的會員級別。";
$message_content_sc = "恭喜您,你的会员级别已经可以晋升,请按'晋升'按钮,我们将尽快升级您的会员级别。";
$parameters = array("3", "1", $member_info{"vip_code"}, $message_title_en, $message_title_tc, $message_title_sc, $message_content_en, $message_content_tc, $message_content_sc, "1", "0", date("Y-m-d H:i:s"), "0", date("Y-m-d H:i:s"),);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
}
}
}
}
return $message;
}
}
if (!function_exists('vip_downgrade_checking')) {
function vip_downgrade_checking($member_info)
{
global $dbh;
if ($member_info{"mvip_downgrade"} == 1 && !empty($member_info{"down_vip_level"}) && $member_info{"permanent"} == 0 && !empty($member_info{"mvip_year"})) {
//membership expired
if (date("Y-m-d H:i:s") > strtotime("+" . $member_info{"mvip_year"} . " year", $member_info{"member_createdate"})) {
$can_downgrade = true;
//insert record to membership for remark and update member record
$sql = "insert into membership set(vip_code, current_mvip_id, down_mvip_id, createby, createdate, lastupby, lastupdaet) values (?,?,?,?,?,?,?)";
$parameters = array($member_info{"vip_code"}, $member_info{"mvip_id"}, $member_info{"down_vip_level"}, "0", date("Y-m-d H:i:s"), "0", date("Y-m-d H:i:s"));
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
//system message: user can downgrade
$sql = "insert into (message_type, from_admin, to_vip_code, message_title_en, message_title_tc, message_title_sc, message_content_en, message_content_tc, message_content_sc,system_message_flag, createby, createdate, lastupby, lastupdate) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
$message_title_en = "Your VIP level has been downgraded. Please check current VIP level in your profile.";
$message_title_tc = "你的會員級別已被降級,請到個人資料中查看你現在的會員等級。";
$message_title_sc = "你的会员级别已被降级,请到个人资料中查看你现在的会员等级。";
$message_content_en = "Your VIP level has been downgraded. Please check current VIP level in your profile.";
$message_content_tc = "你的會員級別已被降級,請到個人資料中查看你現在的會員等級。";
$message_content_sc = "你的会员级别已被降级,请到个人资料中查看你现在的会员等级。";
$parameters = array("3", "1", $member_info{"vip_code"}, $message_title_en, $message_title_tc, $message_title_sc, $message_content_en, $message_content_tc, $message_content_sc, "2", "0", date("Y-m-d H:i:s"), "0", date("Y-m-d H:i:s"));
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
}
}
}
}*/
if (!function_exists('get_member_cart_num')) {
function get_member_cart_num()
{
global $dbh;
if (!empty($_SESSION["vip_code"])) {
$sql = "select * from ord_list_temp where vip_code = ? and special_gift = ?";
$parameters = array($_SESSION["vip_code"], "0");
} else {
$sql = "select * from ord_list_temp where session_id = ? and special_gift = ?";
$parameters = array(session_id(), "0");
}
$all_order_temp_info = bind_pdo($sql, $parameters, "selectall");
$ori_cart_num = count($all_order_temp_info);
foreach ($all_order_temp_info as $order_temp_info) {
$sku_info = get_sku_info($order_temp_info{"proskuid"});
if (empty($sku_info)) {
//delete this old sku
$sql2 = "delete from ord_list_temp where ordtemp_id = ?";
$parameters2 = array($order_temp_info{"ordtemp_id"});
bind_pdo($sql2, $parameters2);
$ori_cart_num--;
}
}
return $ori_cart_num;
}
}
if (!function_exists('get_order_temp')) {
function get_order_temp($vip_code )
{
global $dbh;
if (!empty($vip_code)) {
$sql = "select * from ord_list_temp where vip_code = ? and special_gift = ?";
$parameters = array($vip_code, 0);
} else {
$sql = "select * from ord_list_temp where session_id = ? and special_gift = ?";
$parameters = array(session_id(), 0);
}
$result = bind_pdo($sql, $parameters, "selectall");
return $result;
}
}
if (!function_exists('get_member_order')) {
function get_member_order($order_id, $vip_code)
{
global $dbh;
$sql = "select * from ord_list ord_list inner join `order` `order` on ord_list.order_id = `order`.order_id where `order`.order_id = ? and `order`.vip_code = ? and ord_list.special_gift = ? ";
$parameters = array($order_id, $vip_code, "0");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll();
}
}
if (!function_exists('get_order_points')) {
function get_order_points($order_id, $vip_code)
{
global $dbh;
$sql = "select * from point_record where order_id = ? and vip_code = ? and deleted = ? and add_deduct = ? ";
$parameters = array($order_id, $vip_code, "0", "+");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$point_record_info = $sth->fetch(PDO::FETCH_ASSOC);
return $point_record_info{"point_change"};
}
}
if (!function_exists('langcode_translate')) {
function langcode_translate($langcode)
{
if($langcode == "en")
return "en";
else if($langcode == "tc")
return "zh";
else if($langcode == "sc")
return "cn";
else
return NULL;
}
}
if (!function_exists('product_detail_img_style')) {
function product_detail_img_style($img_src)
{
list($width, $height, $type, $attr) = getimagesize($img_src);
if($width >= $height){
$style = "width:100%; height:auto";
}else{
$style = "width: auto; height:100%";
}
return $style;
}
}
if (!function_exists('get_redeem_order')) {
function get_redeem_order()
{
global $dbh;
$sql = "select * from `order` where vip_code = ? and temp = ? and deleted = ? and redeem = ?";
$parameters = array($_SESSION["vip_code"], "1", "0", "1");
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetch(PDO::FETCH_ASSOC);
}
}
//call functions
if (isset($_SESSION["vip_code"])) {
$member_info = get_member_info($vip_code);
$order_info = get_order_info($vip_code);
}
//check if cookies exist
if (isset($_COOKIE['sinomax_user_visit']) || isset($_SESSION['sinomax_user_visit'])) {
$_SESSION['sinomax_user_visit'] = $_COOKIE['sinomax_user_visit'];
} else {
$cookie_code = random_string(20);
unset($_COOKIE['sinomax_user_visit']);
setcookie('sinomax_user_visit', $cookie_code, time() + 3600 * 24 * 365 * 10, '/');
//setcookie("sinomax_user_visit", $cookie_code, time() + 3600 * 24 * 365 * 10);
$_SESSION['sinomax_user_visit'] = $cookie_code;
}
//auto login - get the cookies and checking
if (isset($_COOKIE["sinomax_cookies1"]) && isset($_COOKIE["sinomax_cookies2"]) && empty($_SESSION["vip_code"])) { //user has cookies and not login yet
$temp_var = rsa_crypt($_COOKIE["sinomax_cookies1"], 2); //decrypt cookies
$sql = "select * from auto_login where expired_date >= ? and http_user_agent = ? and temp_var = ?";
$parameters = array($nowdate, $_SERVER["HTTP_USER_AGENT"], $_COOKIE["sinomax_cookies1"]);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
$valid_cookies_info = $sth->fetch(PDO::FETCH_ASSOC);
$_SESSION["vip_code"] = $valid_cookies_info{"vip_code"};
$_SESSION["autologin_lasturl"] = $_SERVER['REQUEST_URI'];
//make sure all login should visit index page
header("Location: ../" . $_COOKIE["sinomax_cookies2"] . "/index.php");;
}