'); insertPluginJS(''); // 選單列表 function mallCategoryModify($blockInfo){ global $db,$perm,$smarty, $df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_P_CATE); $store_id = $GLOBALS['STORE_ID']; $parent_id = isset($_GET['parent_id']) ? (int) $_GET['parent_id'] : 0; $thidAdmin = $perm->havePerm("ProductsModify"); #是否為呼叫產品清單模組 $cate_mode = isset($_GET['module'],$_GET['func']) ? ($_GET['module']=='mall'&& $_GET['func']=='ProductsList' ? 1 : 0) : 0; $bid = $blockInfo['bid']; $cate_desc = get_all_cate(); $multiple_cate = getSysOption('mall_multiple') ; #INSERT Javascript insertJS(''); if(!$thidAdmin){ insertPluginJS(''); } # $smarty->assign("content",$content); $smarty->assign("bid",$bid); $smarty->assign("cate_mode",$cate_mode); $smarty->assign("thisAdmin",$thidAdmin); $smarty->assign("parent_id",$parent_id); $smarty->assign("cate_desc",$cate_desc); $smarty->assign("multiple_cate",$multiple_cate); $smarty->assign("root_id",get_root_id($parent_id)); $smarty->assign("categories_id",(int)@$_REQUEST["cate_id"]); $ret['title'] = $blockInfo['name'] ? $blockInfo['name'] : MALL_P_CATE; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/categories_modify.htm"); return $ret; } # 取得所有產品分類 function get_all_cate() { global $db,$df_lang; #20180410-增加產品分類可在不同頁面顯示-modify-1 $store_id = $GLOBALS['STORE_ID']; //$bid = $GLOBALS['CurBID'] ; $sid = $GLOBALS['SECTION'] ; $multiple_mall = getSysOption('mall_multiple') ; $db->query("select count(Auto_SN) as c from section_category where Section_SN=$sid") ; $db->next_record(); $secCatCount = $db->f('c') ; $ret = array(); #20180410-增加產品分類可在不同頁面顯示-modify-2 if (isset($multiple_mall) && $multiple_mall == 1 && $secCatCount > 0) { $db->query("select Category_SN from section_category where Section_SN = $sid") ; $showListBySection = array() ; while($db->next_record()){ array_push($showListBySection, $db->f('Category_SN')); } } $db->query("SELECT a.parent_id, a.show_flag, a.categories_id, a.sort_order, b.categories_name, count( d.products_id ) AS counts FROM categories AS a LEFT JOIN categories_description AS b ON a.categories_id = b.categories_id AND b.language_id = '$df_lang' LEFT JOIN products_to_categories AS c ON (a.categories_id = c.categories_id OR a.categories_id = c.sub_cate_1 OR a.categories_id = c.sub_cate_2) left join products as d on c.products_id=d.products_id and d.products_status=1 GROUP BY a.categories_id ORDER BY a.parent_id, a.sort_order"); while($db->next_record()){ if(!isset($ret[$db->f("parent_id")])) $ret[$db->f("parent_id")] = array(); #20180410-增加產品分類可在不同頁面顯示-modify-3 if (isset($multiple_mall) && $multiple_mall == 1) { $showFlag = (in_array($db->f("categories_id"), $showListBySection)) ? '1' : '0' ; } else { $showFlag = $db->f("show_flag") ; } array_push($ret[$db->f("parent_id")] , array( 'AutoSN'=>$db->f("categories_id"), 'text'=>$db->f("categories_name"), 'show'=>$showFlag, //'show'=>$db->f("show_flag"), 'sort'=>$db->f("sort_order"), 'count'=>$db->f("counts"), 'parent_id'=>$db->f("parent_id") ) ); } return $ret; } function get_all_prod($sort=""){ global $db,$df_lang; $ret = array(); $sort_str = $sort=="" ? "order by a.products_id ASC":"order by ".$sort; /*$db->query("select a.*, b.products_name, b.products_description from products as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' $sort_str");*/ //產品管理加入搜尋產品功能 by Grace in 20160608 $pro_sql="select a.*, b.products_name, b.products_description, c.categories_id, d.categories_name from products as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' left join products_to_categories as c on a.products_id=c.products_id and b.language_id='$df_lang' left join categories_description as d on c.categories_id=d.categories_id and d.language_id='$df_lang' $sort_str"; if($_POST['P_NAME']!="" or $_POST['P_NO']!="" or $_POST['P_INVABLE']!=""){ $P_NO=$_POST['P_NO']; $P_NAME=$_POST['P_NAME']; $P_INVABLE=$_POST['P_INVABLE']; $search_str1=$search_str1=="" ? " and products.products_no like '%$P_NO%'":" ".$search_str2; $search_str2=$search_str2=="" ? " and products_description.products_name like '%$P_NAME%'":" ".$search_str2; $search_str3=$search_str3=="" ? " and products.products_date_invalid like '%$P_INVABLE%'":" ".$search_str3; $search_str=$search_str1.$search_str2.$search_str3; $pro_sql="select * from products, products_description where products.products_id=products_description.products_id $search_str and products_description.language_id='$df_lang'"; } $db->query($pro_sql); //Added End <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< while($db->next_record()){ if(!isset($ret[$db->f("products_id")])) $ret[$db->f("products_id")] = array(); $ret[$db->f("products_id")] = array( 'AutoSN'=> $db->f("products_id"), 'no' => $db->f("products_no"), 'text' => html_entity_decode($db->f("products_name")), 'desc' => $db->f("products_description"), 'price' => $db->f("products_price"), 'show' => $db->f("products_status"), 'expire'=> $db->f("products_date_invalid"), 'cate_id'=> $db->f("categories_id"), 'cate_text'=> $db->f("categories_name"), 'upon' => $db->f("products_date_available") ); } return $ret; } # 分類顯示設定 function mallCategorySet(){ global $db,$perm,$smarty,$df_lang; $store_id = $GLOBALS['STORE_ID']; if(!$perm->havePerm("ProductsModify")) errorShow(MALL_CETA_SET.SYSERROR_3); $cate_list = get_all_cate(); #插入JS insertJS(''); #算出每一個群組裡總共幾個 $cate_count = array(); foreach($cate_list as $k=>$cate){ $cate_count[$k] = count($cate); } $smarty->assign('ref',isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER']: WM_HTML_ROOT."/"); $smarty->assign("cate_list" ,$cate_list ); $smarty->assign("cate_count",$cate_count); $smarty->assign("action",WM_HTML_ROOT."/?module=mall&func=CategorySetUpdate"); //debug //$smarty->assign('debug', $store_id) ; //$smarty->assign('section', $GLOBALS['SECTION']) ; //debug $ret['title'] = MALL_CETA_SET; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/categories_set.htm"); $ret['store_id'] = $store_id ; return $ret; } #分類顯示設定 的資料更新 function mallCategorySetUpdate(){ global $db,$perm,$smarty,$df_lang; $store_id = $GLOBALS['STORE_ID']; $section_id = $GLOBALS['SECTION'] ; if(!$perm->havePerm("ProductsModify")) errorShow(MALL_CETA_SET.SYSERROR_3); foreach($_POST as $k=>$v) $$k = $v; #更新顯示 開關 if(isset($show_cate) && is_array($show_cate)){ #先把全部的分類都設為隱藏 $db->query("update categories set show_flag='0' where store_id='$store_id'"); foreach($show_cate as $AutoSN){ $db->query("update categories set show_flag='1' where categories_id='$AutoSN' and store_id='$store_id'"); } #20180410-增加產品分類可在不同頁面顯示-modify-4 $db->query("delete from section_category where Section_SN=$section_id") ; foreach($show_cate as $AutoSN){ $db->query("insert into section_category (Section_SN, Category_SN) values ($section_id, $AutoSN)") ; } }else{ #沒此參數表示 全部都沒勾 $db->query("update categories set show_flag='0' where store_id='$store_id'"); $db->query("delete from section_category where Section_SN=$section_id") ; } # 更新排序 if(is_array($sort_data)){ foreach($sort_data as $AutoSN=>$sort){ $db->query("UPDATE categories set sort_order='$sort' where categories_id='$AutoSN' "); } } $ref = WM_HTML_ROOT."/?section=" . $section_id; header("Location:".$ref); exit; } function mallCategoryEdit(){ global $db,$perm,$smarty; $store_id = $GLOBALS['STORE_ID']; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3); $admin = true; //$perm->havePerm("MenuModify"); $content = array(); $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : WM_HTML_ROOT."/"; $parent_id = 0; // 修改 if ((int)@$_REQUEST["cate_id"] != "0" && $_GET['func']=='CategoryEdit'){ $sql = "Select * from categories where store_id = '$store_id' and categories_id = ". @$_REQUEST["cate_id"]; $db->query($sql); if($db->next_record()) { $store_id = $db->f("store_id"); $categories_id = $db->f("categories_id"); $parent_id = $db->f("parent_id"); } $ret['title'] = MALL_CAT_EDIT; } else { $categories_id = ""; $parent_id = isset($_REQUEST["parent_id"]) ? $_REQUEST["parent_id"] : 0; $ret['title'] = $parent_id==0 ? MALL_NEW_BIGCETA : MALL_NEW_SMLCETA ; } if($parent_id==0) $desc = false; else $desc = true; # init Lang Calss Usage : # # new Lang( String @ $table , # Array @ columns_array , # String @ key_column , # String @ key_value , # String @ language_id_column_name # ); # $lang = new Lang('categories_description',array('categories_name','categories_description'),'categories_id' , $categories_id ,'language_id'); # return $detail['categories_name'][language_id] = Data ; $detail = $lang->getMultiText(); # status_key 是依個陣列 紀錄哪個language id是需要新增的 $detail_key = $lang->status_key; $detail_key; #INSERT Javascript insertJS(''); #set language list in smarty : var xxx = new Array({$LANG}); $LANG = array_keys($_SESSION['LANG']) ; $LANG = count($LANG)==1 ? "'".$LANG[0]."'" : implode(',',$LANG) ; $smarty->assign("content",$content); $smarty->assign("LANG", $LANG ); # 所有的語系ID $smarty->assign("store_id", $store_id); $smarty->assign("desc", $desc); $smarty->assign("ref", $ref); $smarty->assign("categories_id",$categories_id); $smarty->assign("parent_id",$parent_id); $smarty->assign("detail_key",$detail_key); #assign to smarty for hidden form inputs $smarty->assign("detail",$detail); $smarty->assign("action",WM_HTML_ROOT."/?module=mall&func=CategoryUpdate"); $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/categories_edit.htm"); return $ret; } function mallCategoryUpdate() { global $db,$perm,$smarty; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3); $store_id = $GLOBALS['STORE_ID']; $Category_Name = $_REQUEST["Category_Name"]; $categories_description = $_POST['categories_description'] ; $parent_id = (int)@$_REQUEST["parent_id"]; $categories_id = @$_REQUEST["categories_id"]; $detail_key = @$_REQUEST["detail_key"]; $ref=$_POST['ref']; #處理字串HTML跳脫自元 foreach($Category_Name as $k=>$v){ if($Category_Name[$k] == '') errorShow(sprintf(MALL_DATA_EMPTY,MALL_CNAME)); $Category_Name[$k] = htmlspecialchars( mb_substr($v,0,32,'utf-8') , ENT_QUOTES ); } foreach($categories_description as $k=>$v){ $categories_description[$k] = htmlspecialchars( $v, ENT_QUOTES ); } #新增 if ($categories_id == ""){ #find sort $add_sort =0 ; $db->query("select max(sort_order) as max_sort from categories where parent_id = '$parent_id'"); $db->next_record(); if($db->f("max_sort")!=NULL) { $add_sort = $db->f("max_sort")+1; } $sql = "Insert into categories (store_id, categories_image, parent_id, date_added, sort_order ) values('$store_id', null, $parent_id, now(), '$add_sort')"; $db->query($sql); $categories_id = mysql_insert_id(); } else{ } #處理語系的部份 $lang = new Lang('categories_description',array('categories_name','categories_description'),'categories_id' , $categories_id ,'language_id'); #設定把字串拆解為htmlspecialchars $lang->entity=1; #重要:把$detail_key帶進來 $lang->status_key = $detail_key ; # 新增&更新共用 $lang->addMultiText( $Category_Name ,$categories_description ); #20180410-增加產品分類可在不同頁面顯示-modify-5 $section_id = $GLOBALS['SECTION'] ; $db->query("insert into section_category (Section_SN, Category_SN) values ($section_id, $categories_id)") ; header("Location:".$ref); exit; } #刪除分類 function mallCategoryDelete(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3); $cid = (int)$_GET['id']; $ref= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : WM_HTML_ROOT.'/'; $db->query("select * from categories where parent_id ='$cid'"); if($db->nf()>0) errorShow(MALL_CATEDESC_22,$ref); #下面有次分類,無法刪除 #找出目前排序值 $db->query("select sort_order,parent_id from categories where categories_id ='$cid'"); $db->next_record(); $sort = $db->f("sort_order"); $parent = $db->f("parent_id"); $db->query("delete from categories where categories_id ='$cid'"); $db->query("delete from categories_description where categories_id ='$cid'"); #更新排序 $db->query("update categories set sort_order=sort_order-1 where parent_id='$parent' and sort_order>$sort"); #將原本分類中的產品移到未分類 $db->query("update products_to_categories set categories_id=0 where categories_id='$cid' "); $db->query("update products_to_categories set sub_cate_1=0 where sub_cate_1='$cid' "); $db->query("update products_to_categories set sub_cate_2=0 where sub_cate_2='$cid' "); #20180410-增加產品分類可在不同頁面顯示-modify-6 $section_id = $GLOBALS['SECTION'] ; $db->query("delete from section_category where Section_SN=$section_id and Category_SN='$cid'") ; errorShow(MALL_CATEDESC_23,$ref); } # 購物首頁區塊的內容顯示 function mallShowMainCategory(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_HOME); $store_id = $GLOBALS['STORE_ID']; $data = array(); $db->query("select b.products_name, b.products_description, b.products_id, c.products_price, c.products_image, c.products_date_available, c.products_date_invalid, a.cType, a.cOption from categories_set as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' left join products as c on a.products_id=c.products_id where c.products_status=1 order by a.sort"); while($db->next_record()){ if(!isset($data[$db->f("cType")])) $data[$db->f("cType")] = array(); #判斷是否沒上架或已經下架 if(date("Y-m-d H:i:s")>$db->f("products_date_invalid")) { $invaild = MALL_P_INVABLE_1; }else if(date("Y-m-d H:i:s")<$db->f("products_date_available")){ $invaild = MALL_P_AVAIABLE_1; }else { $invaild = ''; } array_push( $data[$db->f("cType")] , array( 'name'=>$db->f("products_name") , 'id' =>$db->f("products_id") , 'text'=>$db->f("cOption"), 'img' =>$db->f("products_image")=='' ? "/images/system/default_item.gif" : $db->f("products_image"), 'price'=>$db->f("products_price"), 'desc'=> html_entity_decode($db->f("products_description")), 'invaild'=>$invaild ) ); } #標題背景 $bar_img = array(); $bar_img[1] = getSysOption('mall_special_img'); $bar_img[2] = getSysOption('mall_promote_img'); $bar_img[3] = getSysOption('mall_hot_img'); $smarty->assign('cart_flag',getSysOption('cart_flag')); $smarty->assign("bar_img",$bar_img); $smarty->assign("data",$data); $smarty->assign('isAdmin', $perm->havePerm("ProductsModify") ); //$ret['title'] = MALL_HOME; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/categories_main.htm"); return $ret; } # 購物中心首頁的內容顯示編輯 function mallShowMainCategoryEdit(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_CATEDESC_15); $store_id = $GLOBALS['STORE_ID']; $cType = isset($_GET['cType']) ? $_GET['cType'] : 0; $title = array(1=>MALL_CATEDESC_4 , 2=> MALL_CATEDESC_7 , 3=>MALL_CATEDESC_8); $title_desc = array(1=>MALL_CATEDESC_6 ,2=>MALL_CATEDESC_9 , 3=>MALL_CATEDESC_10); $bar_desc = array(1=>MALL_CATEDESC_17 ,2=>MALL_CATEDESC_18 , 3=>MALL_CATEDESC_19); $bar_img_list = array(1=>'mall_special_img',2=>'mall_promote_img',3=>'mall_hot_img'); $default_img = array(1=>'/images/system/bar_special.gif',2=>'/images/system/bar_promote.gif',3=>'/images/system/bar_hot.gif'); $prod_select= array() ; $cOption = array(); $all_prod = get_all_prod(); $ref = explode('?',$_SERVER['HTTP_REFERER']) ; $ref = isset($ref[1]) ? $ref[1]:''; $hasDisabledProduct = false; $_SESSION['ref'] = $ref; if($cType<1 || $cType>3) errorShow(SYSERROR_1); $db->query("select b.products_id,b.products_name, a.cOption from categories_set as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' where a.cType='$cType' order by a.sort"); while($db->next_record()){ $prod_select[$db->f("products_id")] = $db->f("products_name"); $cOption[$db->f("products_id")] = $db->f("cOption"); } foreach($all_prod as $pid=>$data){ if(array_key_exists($pid,$prod_select)){ unset($all_prod[$pid]); #如果該產品是停用~要出現訊息 if($data['show']==0) { $prod_select[$pid] .= " ("._OFF.")"; $hasDisabledProduct = true; } if($data['expire']date("Y-m-d H:i:s")){ #產品尚未上架 $prod_select[$pid] .= " (".MALL_P_AVAIABLE_1.")"; } }else { if($data['show']==0){ $all_prod[$pid]['text'] .= " ("._OFF.")"; } if($data['expire']date("Y-m-d H:i:s")){ #產品尚未上架 $all_prod[$pid]['text'] .= " (".MALL_P_AVAIABLE_1.")"; } } } #INSERT Javascript insertJS(''); $smarty->assign("title_desc",$title_desc[$cType]); $smarty->assign("bar_desc",$bar_desc[$cType]); $smarty->assign("bar_img",getSysOption($bar_img_list[$cType])); # 標題背景 $smarty->assign("default_img",$default_img[$cType]); $smarty->assign("hasDisabledProduct",$hasDisabledProduct); $smarty->assign("prod_select",$prod_select); $smarty->assign("all_prod",$all_prod); $smarty->assign("cOption",$cOption); $smarty->assign("cType",$cType); $smarty->assign("action",WM_HTML_ROOT."/?module=mall&func=ShowMainCategoryUpdate"); $ret['title'] = $title[$cType]; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/categories_main_edit.htm"); return $ret; } #更新購物中心首頁顯示設定 function mallShowMainCategoryUpdate(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_CATEDESC_15); #匯入表單參數 foreach($_POST as $k=>$v) $$k = $v; #如果什麼也沒選 if(!isset($cText_data)) $cText_data = array(); if(!isset($sort_data)) $sort_data = array(); #處理字串 foreach($cText_data as $mid=>$v) $cText_data[$mid] = htmlspecialchars( mb_substr($v,0,32,'utf-8') , ENT_QUOTES ); #$cText_data = array_flip($cText_data); $sort_data = array_flip($sort_data); # 找出既有的選取商品 $org = array(); $db->query("select * from categories_set where cType='$cType' "); while($db->next_record()){ $org[$db->f("sort")] = $db->f("products_id"); } $insert_array = array_diff($sort_data , $org ); $delete_array = array_diff($org , $sort_data ); $update_array = array_intersect($sort_data,$org); $sql = array(); # INSERT foreach($insert_array as $sort =>$mid){ $cOption = $cType==2 ? $cText_data[$mid] : ''; $sql_ = "insert into categories_set (products_id, cType, cOption, sort) values('$mid', '$cType', '$cOption', '$sort')"; array_push($sql,$sql_); } # DELETE foreach($delete_array as $sort=>$mid){ $sql_ = "delete from categories_set where products_id='$mid' and cType='$cType' "; array_push($sql,$sql_); } # UPDATE foreach($update_array as $sort=>$mid){ $cOption = $cType==2 ? $cText_data[$mid] : ''; $sql_ = "update categories_set set sort='$sort' ,cOption='$cOption' where products_id='$mid' and cType='$cType'"; array_push($sql,$sql_); } foreach($sql as $s_) {$db->query($s_);} #標題背景更新 $bar_img_list = array(1=>'mall_special_img',2=>'mall_promote_img',3=>'mall_hot_img'); $bar_img_op = $bar_img_list[$cType]; $db->query("update system_option set op_value='$bar_img' where op_name='$bar_img_op' " ); if(isset($_SESSION['ref'])) { $ref = $_SESSION['ref'] ; unset($_SESSION['ref']); }else $ref = ''; header("Location:".WM_HTML_ROOT."/?".$ref); exit; } // ----------------------------------------------------------------------- // 產品顯示 // function mallProductsList($blockInfo) { global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_DETAIL); $parent_id = (int)@$_GET["parent_id"]; $cart_flag = getSysOption('cart_flag'); $store_id = $GLOBALS['STORE_ID']; $limit = ""; $bid = $blockInfo['bid']; $sort = $sort_url = $order = ""; $cart_hisroty = getSysOption('mall_history_view')>0 ; #取得所有產品列表 #$all_cate = get_all_cate(); #區塊顯示設定 if($bid!=0){#區塊的產品列表 $display_op = getBlockOption($bid); $parent_id = $display_op['prod_list_cate']; $display_op['prod_list_num'] = isset($display_op['prod_list_num']) ? (int) $display_op['prod_list_num'] : 12; if($display_op['prod_list_num'] == 0 ) $display_op['prod_list_num'] = 6; $limit = "limit ".$display_op['prod_list_num']; $page_info = array(); $page_info['page'] = isset($_GET['page']) ? (int)$_GET['page'] : 1; /*$sql = "Select a.store_id, a.products_id, a.sort_order , b.products_no, b.products_image, b.products_price, c.* from products_pick as a , products as b , products_description as c where a.products_id=b.products_id and a.bid='$bid' and a.products_id = c.products_id and a.store_id = 1 and b.products_status=1 and language_id='$df_lang' and a.store_id='$store_id' order by a.sort_order DESC";*/ $sql = "Select a.store_id, a.products_id, a.sort_order , b.*, c.* from products_pick as a, products as b, products_description as c where a.products_id=b.products_id and a.bid='$bid' and a.products_id = c.products_id and a.store_id = 1 and b.products_status=1 and language_id='$df_lang' and a.store_id='$store_id' order by a.sort_order DESC"; $db->query($sql); $page_info['per_page'] = getSysOption('mall_per_page'); $page_info['max_page'] =ceil( $db->nf()/$page_info['per_page']); $limit = " limit ".$page_info['per_page']." offset ".($page_info['page']-1)*$page_info['per_page']; $sql .= $limit ; $page_info['url'] = WM_HTML_ROOT."/?section=" . $blockInfo['sid']; $smarty->assign('page_info',$page_info); }else{#檢視某分類的產品列表 #排序方式 $sort_url = WM_HTML_ROOT.'/?module=mall&func=ProductsList&parent_id='.$parent_id ; $sort_list = array(0=>'b.products_id',1=>'b.products_date_available',2=>'b.products_price'); $sort = isset($_GET['sort']) && (int)$_GET['sort']>0 && (int)$_GET['sort']<3 ? (int)$_GET['sort'] : 0 ; $order = isset($_GET['order'])&&(int)$_GET['order']>0 ? 1 : 0 ; $order_str = $order==0 ? ' DESC':' ASC'; $sort_str = $sort_list[$sort].$order_str ; #分頁 $page_info = array(); $page_info['page'] = isset($_GET['page']) ? (int)$_GET['page'] : 1; #抓分類敘述 $db->query("select * from categories_description where categories_id=$parent_id and language_id='$df_lang' "); $db->next_record(); $cate_desc = array( 'name'=>$db->f("categories_name") , 'desc'=> html_entity_decode($db->f("categories_description")) ); $smarty->assign("cate_desc",$cate_desc); /*$sql = "Select a.store_id, a.products_id, a.categories_id, b.products_no, b.products_image, b.products_price, c.* from products_to_categories as a, products as b, products_description as c where a.products_id = b.products_id and a.products_id = c.products_id and a.store_id = 1 and (a.categories_id = $parent_id or a.sub_cate_1='$parent_id' or a.sub_cate_2='$parent_id') and b.products_status=1 and c.language_id='$df_lang' and a.store_id='$store_id' order by $sort_str" ;*/ $sql = "Select a.store_id, a.products_id, a.categories_id, b.*, c.* from products_to_categories as a, products as b, products_description as c where a.products_id = b.products_id and a.products_id = c.products_id and a.store_id = 1 and (a.categories_id = $parent_id or a.sub_cate_1='$parent_id' or a.sub_cate_2='$parent_id') and b.products_status=1 and c.language_id='$df_lang' and a.store_id='$store_id' order by $sort_str" ; $db->query($sql); $page_info['per_page'] = getSysOption('mall_per_page'); $page_info['max_page'] =ceil( $db->nf()/$page_info['per_page']); $limit = " limit ".$page_info['per_page']." offset ".($page_info['page']-1)*$page_info['per_page']; $sql .= $limit ; $page_info['url'] = WM_HTML_ROOT."/?module=mall&func=ProductsList&sort=$sort&order=$order&parent_id=$parent_id"; $smarty->assign('page_info',$page_info); } //echo $sql; $db->query($sql); $admin = $perm->havePerm("ProductsModify"); $content = array(); while($db->next_record()) { #判斷是否沒上架或已經下架 if(date("Y-m-d H:i:s")>$db->f("products_date_invalid")) { $invaild_note = MALL_P_INVABLE_1; }else if(date("Y-m-d H:i:s")<$db->f("products_date_available")){ $invaild_note = MALL_P_AVAIABLE_1; }else { $invaild_note = ""; } array_push($content, array( "store_id" => $db->f("store_id"), "products_id" => $db->f("products_id"), "products_price" => number_format($db->f("products_price")), "products_no" => $db->f("products_no"), //"products_name"=> $db->f("products_name"), "products_name" => html_entity_decode($db->f("products_name")), "products_introduction" => html_entity_decode($db->f("products_introduction")), "products_url" => $db->f("products_url"), "products_image"=> $db->f("products_image"), "products_invalid"=> $invaild_note ) ); } // Added by Steve@2014/11/16 - to group paging $groupItems = 6 ; $minItems = $groupItems + 3 ; if ($page_info['max_page'] < $minItems) { $beginOfLeft = 1 ; $endOfLeft = $page_info['max_page'] ; $beginOfRight = 0 ; $endOfRight = -1 ; $beginOfMiddle = 0 ; $endOfMiddle = -1 ; $glueLeft = '' ; $glueRight = '' ; } else { if ($page_info['page'] < $groupItems) { $beginOfLeft = 1 ; $endOfLeft = $groupItems ; $beginOfRight = $page_info['max_page'] - 1 ; $endOfRight = $page_info['max_page'] ; $beginOfMiddle = 0 ; $endOfMiddle = -1 ; $glueLeft = '' ; $glueRight = '...' ; } else if ($page_info['page'] >= $page_info['max_page'] - $groupItems + 1) { $beginOfLeft = 1 ; $endOfLeft = 2 ; $beginOfRight = $page_info['max_page'] - $groupItems + 1 ; $endOfRight = $page_info['max_page'] ; $beginOfMiddle = 0 ; $endOfMiddle = -1 ; $glueLeft = '...' ; $glueRight = '' ; } else { $beginOfLeft = 1 ; $endOfLeft = 2 ; $beginOfRight = $page_info['max_page'] - 1 ; $endOfRight = $page_info['max_page'] ; $beginOfMiddle = $page_info['page'] -2 ; $endOfMiddle = $page_info['page'] +2 ; $glueLeft = '...' ; $glueRight = '...' ; } } for ($i = $beginOfLeft; $i <= $endOfLeft; $i++) { $pageLeft[] = $i ; } for ($i = $beginOfRight; $i <= $endOfRight; $i++) { $pageRight[] = $i ; } for ($i = $beginOfMiddle; $i <= $endOfMiddle; $i++) { $pageMiddle[] = $i ; } $smarty->assign("pageLeft", $pageLeft) ; $smarty->assign("pageRight", $pageRight) ; $smarty->assign("pageMiddle", $pageMiddle) ; $smarty->assign("glueLeft", $glueLeft) ; $smarty->assign("glueRight", $glueRight) ; // -- end of group paging $smarty->assign("bid",$bid); $smarty->assign("pricePerm",$perm->havePerm("ShowPrice")); $smarty->assign("content",$content); $smarty->assign("sort_url",$sort_url); $smarty->assign("sort",$sort); $smarty->assign("order_d",$order); $smarty->assign('cart_flag',$cart_flag); $smarty->assign('cart_hisroty',$cart_hisroty); $smarty->assign("parent_id",$parent_id); $smarty->assign("thisAdmin",$admin); $smarty->assign("root_path",WM_REAL_PATH); //$ret['title'] = !$blockInfo['name'] ? MALL_P_LIST : $blockInfo['name'] ; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/productsList.htm"); return $ret; } function mallProductsPick(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_P_PICK_2); #INSERT Javascript insertJS(''); $prod_select = array(); $hasDisabledProduct = false; $all_prod = get_all_prod(); $store_id = $GLOBALS['STORE_ID']; $ref = explode('?',$_SERVER['HTTP_REFERER']) ; $ref = isset($ref[1]) ? $ref[1]:''; $bid = isset($_GET['bid']) ? $_GET['bid']:0; if($bid==0) errorShow(MALL_P_PICK_2.SYSERROR_1); $db->query("Select a.store_id, a.products_id, a.sort_order , c.products_name from products_pick as a , products_description as c where a.bid='$bid' and a.products_id = c.products_id and a.store_id = 1 and language_id='$df_lang' and a.store_id='$store_id' order by a.sort_order"); while($db->next_record()){ $prod_select[$db->f("products_id")] = html_entity_decode($db->f("products_name")); } foreach($all_prod as $pid=>$data){ if(array_key_exists($pid,$prod_select)){ unset($all_prod[$pid]); #如果該產品是停用~要出現訊息 if($data['show']==0) { $prod_select[$pid] .= " ("._OFF.")"; $hasDisabledProduct = true; } if($data['expire']date("Y-m-d H:i:s")){ #產品尚未上架 $prod_select[$pid] .= " (".MALL_P_AVAIABLE_1.")"; } }else { if($data['show']==0){ $all_prod[$pid]['text'] .= " ("._OFF.")"; } if($data['expire']date("Y-m-d H:i:s")){ #產品尚未上架 $all_prod[$pid]['text'] .= " (".MALL_P_AVAIABLE_1.")"; } } } #為了能讀取HTML標籤, 特獨立出產品名稱 -- Added in 2170410 by Grace -- $prod_name = $all_prod['text']; $smarty->assign("all_prod",$all_prod); $smarty->assign("prod_name",$prod_name); $smarty->assign("prod_select",$prod_select); $smarty->assign("ref",$ref); $smarty->assign("hasDisabledProduct",$hasDisabledProduct); $smarty->assign("cType",3); $smarty->assign("bid",$bid); $smarty->assign("action",WM_HTML_ROOT.'/?module=mall&func=ProductsPickUpdate'); $ret['title'] = MALL_P_PICK_2 ; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/products_pick.htm"); return $ret; } #區塊的選取商品更新 function mallProductsPickUpdate(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_P_PICK_2); $store_id = $GLOBALS['STORE_ID']; foreach($_POST as $k=>$v) $$k=$v; $url = $ref==''? WM_HTML_ROOT."/":WM_HTML_ROOT."/?".$ref; #如果什麼也沒選,表示都刪掉了 if(!isset($sort_data)){ $sql_ = "delete from products_pick where bid='$bid' "; $db->query($sql_); header("Location:".$url); exit; } $sort_data = array_flip($sort_data); # 找出既有的選取商品 $org = array(); $db->query("select * from products_pick where bid='$bid' and store_id='$store_id'"); while($db->next_record()){ $org[$db->f("sort_order")] = $db->f("products_id"); } $insert_array = array_diff($sort_data , $org ); $delete_array = array_diff($org , $sort_data ); $update_array = array_intersect($sort_data,$org); $sql = array(); # INSERT foreach($insert_array as $sort =>$mid){ $cOption = $cType==2 ? $cText_data[$mid] : ''; $sql_ = "insert into products_pick (products_id, bid, sort_order) values('$mid', '$bid', '$sort')"; array_push($sql,$sql_); } # DELETE foreach($delete_array as $sort=>$mid){ $sql_ = "delete from products_pick where products_id='$mid' and bid='$bid' "; array_push($sql,$sql_); } # UPDATE foreach($update_array as $sort=>$mid){ $cOption = $cType==2 ? $cText_data[$mid] : ''; $sql_ = "update products_pick set sort_order='$sort' where products_id='$mid' and bid='$bid'"; array_push($sql,$sql_); } foreach($sql as $s_) { #trace($s_); $db->query($s_); } header("Location:".$url); exit; } function mallAdminProducts() { global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_P_EDIT); $store_id = $GLOBALS['STORE_ID']; $cart_flag = getSysOption('cart_flag'); #排序方式 $sort_list = array(0=>'a.products_id',1=>'a.products_no',2=>'b.products_name',3=>'a.products_price',4=>'a.products_date_invalid'); $sort = isset($_GET['sort']) && (int)$_GET['sort']<5 ? $_GET['sort'] : 0; $order= isset($_GET['order']) ? $_GET['order']: 0; $order_str = $order==0 ? ' DESC':' ASC'; $sort_str = $sort_list[$sort].$order_str; //產品分頁顯示設定 Add by Grace in 20160901 $mall_options = 'mall_per_page' ; if(isset($_POST['post_flag'])) { $mall_per_page = (int) $_POST['mall_per_page'] ; $db->query("update system_option set op_value='".$mall_per_page."' where op_name='".$mall_options."' "); errorShow(MALL_OPSET_33,WM_HTML_ROOT."/?module=mall&func=AdminProducts"); } $value = getSysOption($mall_options); // Add End----------------------------------------------------------------- #trace($sort_str); $data = get_all_prod($sort_str); $smarty->assign("cart_flag", $cart_flag) ; $smarty->assign("sort", $sort) ; $smarty->assign("order",$order); $smarty->assign("value", $value); $smarty->assign("data", $data) ; $smarty->assign('per_page', array(3=>3,6=>6,9=>9,12=>12,15=>15,18=>18,21=>21,27=>27,30=>30)); $smarty->assign("nums", sprintf(MALL_P_TOTAL,count($data))); $ret['title'] = MALL_P_MANAGE ; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/mall_admin_prod.htm"); return $ret; } //----------------------------------------------------------------------------- // 商品明細 function mallProductsDetail($blockInfo) { global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_DETAIL); $products_id = (int)@$_REQUEST["prod_id"]; $cart_flag = getSysOption('cart_flag'); //trace($blockInfo);/**/ insertPluginJS(''); $store_id = $GLOBALS['STORE_ID']; $parent_id = (int)@$_GET["parent_id"]; $bid = $_REQUEST['bid'] ; if($bid!=0){ $sqlProductList = "Select a.products_id from products_pick as a, products as b where a.products_id=b.products_id and a.bid='$bid' and a.store_id = '$store_id' and b.products_status=1 order by a.sort_order" ; /*$sqlProductList = " Select a.products_id from products_pick as a, products as b, products_to_categories as c where a.products_id=b.products_id and a.products_id = c.products_id and a.store_id = '$store_id' and (c.categories_id = $parent_id or c.sub_cate_1='$parent_id' or c.sub_cate_2='$parent_id') and b.products_status=1 order by a.sort_order" ; */ // echo($sqlProductList) ; } else { $sqlProductList = "Select a.store_id, a.products_id, a.categories_id, b.products_no, b.products_image, b.products_price, c.* from products_to_categories as a, products as b, products_description as c where a.products_id = b.products_id and a.products_id = c.products_id and a.store_id = 1 and (a.categories_id = $parent_id or a.sub_cate_1='$parent_id' or a.sub_cate_2='$parent_id') and b.products_status=1 and c.language_id='$df_lang' and a.store_id='$store_id' order by b.products_id " ; } $db->query($sqlProductList) ; $prodList = array() ; while ($db->next_record()) { $prodList[] = $db->f("products_id") ; } $p = array_search($products_id, $prodList) ; $prevId = (($p-1) < 0) ? -1 : $prodList[$p-1] ; $nextId = ( ($p+1) >= (count($prodList)) ) ? -1 : $prodList[$p+1] ; //if(!$perm->havePerm("NewsModify")) errorShow(SYSERROR_3); $sql = " Select a.store_id, a.products_id, a.categories_id, b.*, c.* from products_to_categories as a, products as b, products_description as c where a.products_id = b.products_id and a.products_id = c.products_id and b.products_status=1 and a.store_id = 1 and a.products_id = $products_id"; //trace($sql); //echo $sql; $db->query($sql); #查無此產品資料 if($db->nf()==0) errorShow(MALL_P_NODATA); $admin = $perm->havePerm("ProductsModify"); $content = array(); if($db->next_record()) { $store_id = $db->f("store_id"); $categories_id = $db->f("categories_id"); $products_id = $db->f("products_id"); //$products_name = $db->f("products_name"); $products_name = htmlspecialchars($db->f("products_name")); $products_no = $db->f("products_no"); $products_image = $db->f("products_image"); $products_quantity = $db->f("products_quantity"); $products_unlimited = $db->f("products_unlimited"); $products_market_price = $db->f("products_market_price"); $products_stock_check = $db->f("products_stock_check"); $products_alert_stock = $db->f("products_alert_stock"); $products_price = number_format($db->f("products_price")); $products_market_price = number_format($db->f("products_market_price")); #if ($products_market_price == 0) { $products_market_price = "" ; } $products_wholesale_price = number_format($db->f("products_wholesale_price")); $products_introduction = html_entity_decode($db->f("products_introduction")); $products_description = $db->f("products_description"); $products_description_2 = $db->f("products_description_2"); $products_date_available = date("Y-m-d",strtotime($db->f("products_date_available"))); $products_date_invalid = date("Y-m-d",strtotime($db->f("products_date_invalid"))); $products_url = $db->f("products_url"); $show_market_price = ($db->f("products_market_price")-$db->f("products_price"))>0 ? 1:0; } // 預設圖檔 $default_img = "/images/system/default_item.gif"; $s_file = $products_image; $m_file = img_size($products_image,"m"); $l_file = img_size($products_image,"l"); if (!file_exists(WM_REAL_PATH.$s_file)){ $s_file = $default_img; } // 檢查圖檔是否存在 if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $m_file)) $m_file = $products_image; if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $l_file)) $l_file = $products_image; //$lang = new Lang('products_description',array('products_name','products_description'),'products_id' , $products_id ,'language_id'); $lang = new Lang('products_description',array('products_name','products_description','products_description_2'),'products_id' , $products_id ,'language_id'); $products = $lang->getMultiDefaultText(); #上下架日期判斷 $invaild_note = ""; if(strtotime($products_date_available)>mktime()) $invaild_note = MALL_P_AVAIABLE_1; else if(strtotime($products_date_invalid)havePerm("ProductsModify"); $ask_price = getSysOption('mall_ask_price'); #產品屬性 $attr = array(); $attr_op = array(); $db->query("select a.*,b.products_options_name,c.products_options_values_name from products_attributes as a left join products_options as b on a.options_id=b.products_options_id and b.language_id='$df_lang' left join products_options_values as c on c.products_options_values_id=a.options_values_id and c.language_id='$df_lang' where a.products_id='$products_id' order by a.sort_order"); while($db->next_record()) { if(!isset($attr[$db->f("options_id")]))$attr[$db->f("options_id")]=array(); #選項類別名稱 $attr_op[$db->f("options_id")] = $db->f("products_options_name"); #選項的下拉選單內容 if($db->f("options_values_price")>0) { $attr[$db->f("options_id")][$db->f("products_attributes_id")] = $db->f("products_options_values_name") ." ( ".$db->f("price_prefix")." $".number_format($db->f("options_values_price")).")"; }else{ $attr[$db->f("options_id")][$db->f("products_attributes_id")] = $db->f("products_options_values_name") ; } } // >>> Add 3 more images for product detail $sql = "select products_image from products_extra_image where products_id = $products_id" ; $db->query($sql) ; while($db->next_record()) { $extraImages[] = $db->f("products_image") ; } // <<< Add 3 more images for product detail // <<< Add pdf file for product detail $sql = "select products_pdf from products where products_id = $products_id" ; $db->query($sql) ; $db->next_record() ; $pdf = trim($db->f('products_pdf')); if (! ( file_exists($_SERVER['DOCUMENT_ROOT'] . $pdf) && is_file($_SERVER['DOCUMENT_ROOT'] . $pdf) )) { $pdf = "" ; } #Social share $og_image = $l_file; $og_url = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $og_title = $products["products_name"]; $og_description = strip_tags($products_introduction); getSocialShare($og_image, $og_url, $og_title, $og_description); $smarty->assign("thisAdmin", $thisAdmin ); $smarty->assign("attr_op", $attr_op ); $smarty->assign("attr", $attr ); $smarty->assign("ask_price", getSysOption('mall_ask_price') ); $smarty->assign("content",$content); $smarty->assign("store_id",$store_id); $smarty->assign("pricePerm",$perm->havePerm("ShowPrice")); $smarty->assign("categories_id",$categories_id); $smarty->assign('cart_flag',$cart_flag); $smarty->assign('social_flag',getSysOption('social_flag')); $smarty->assign('invaild_note',$invaild_note); $smarty->assign("parent_id",isset($_GET['parent_id']) ? $_GET['parent_id'] : 0); $smarty->assign("products_id",$products_id); $smarty->assign("products_no",$products_no); $smarty->assign("products",$products); $smarty->assign("products_image", $m_file); $smarty->assign("products_l_image", $l_file); $smarty->assign("products_quantity",$products_quantity); $smarty->assign("products_market_price",$products_market_price); $smarty->assign("products_unlimited",$products_unlimited); $smarty->assign("products_stock_check",$products_stock_check); $smarty->assign("products_alert_stock",$products_alert_stock); $smarty->assign("products_price",$products_price); $smarty->assign("products_market_price",$products_market_price); $smarty->assign("products_wholesale_price",$products_wholesale_price); $smarty->assign("products_introduction",$products_introduction); $smarty->assign("products_description",$products_description); $smarty->assign("products_description_2",$products_description_2); $smarty->assign("products_date_available",$products_date_available); $smarty->assign("products_date_invalid",$products_date_invalid); $smarty->assign("show_market_price",$show_market_price); $smarty->assign("products_image_1", $products_image_1) ; $smarty->assign("products_image_2", $products_image_2) ; $smarty->assign("products_image_3", $products_image_3) ; $smarty->assign("extra_images", $extraImages) ; $smarty->assign("products_url", $products_url) ; $smarty->assign("prev_id", $prevId) ; $smarty->assign("next_id", $nextId) ; $smarty->assign("parent_id", $parent_id) ; $smarty->assign("bid", $bid) ; $smarty->assign('pdf', $pdf); $smarty->assign("thisAdmin",$admin); $smarty->assign("sign_in", $signIn) ; $smarty->assign("is_agency", $isAgency) ; //$ret['title'] = MALL_DETAIL; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/products_detail.htm"); return $ret; } //----------------------------------------------------------------------------- // 商品維護 // function mallProductsEdit(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3); unset($_SESSION["error_message"]); $content = array(); $ref = ''; $parent_id = (int)@$_REQUEST["parent_id"]; $products_id = (int)@$_REQUEST["prod_id"]; $store_id = $GLOBALS['STORE_ID']; # 有SESSION的話帶入SESSION if (isset($_GET["err"]) && isset($_SESSION["sess_prod_edit"])) { $product_data = $_SESSION["sess_prod_edit"]; $ret['title'] = $product_data->products_id>0 ? MALL_P_EDIT : MALL_NEW_PROD; } else { // 修改 if ($products_id != "0"){ $sql = " Select a.categories_id, a.sub_cate_1, a.sub_cate_2, b.*, c.* from products_to_categories as a, products as b, products_description as c where a.products_id=b.products_id and b.products_id = c.products_id and b.store_id = 1 and b.products_id = $products_id"; $db->query($sql); if($db->next_record()) { $product_data = $db->Record ; $product_data->products_introduction = html_entity_decode($db->f("products_introduction")); } $product_data->categories_id = array(); $db->query("select categories_id from products_to_categories where products_id='$products_id' and store_id='$store_id' "); while($db->next_record()){ array_push($product_data->categories_id,$db->f("categories_id")); } $ret['title'] = MALL_P_EDIT; }else{ class B{} $product_data = new B ; $product_data->products_date_invalid = strtotime("now +5 year"); $product_data->store_id = $store_id; $product_data->products_id = 0; $product_data->products_status = 0; $product_data->categories_id = array(); $product_data->products_image = WM_HTML_ROOT . '/uploads/images/1_images/products/no_pic.png' ; $ret['title'] = MALL_NEW_PROD; } } //$lang = new Lang('products_description',array('products_name','products_description'),'products_id' , $products_id ,'language_id'); $lang = new Lang('products_description',array('products_name','products_description','products_description_2'),'products_id' , $products_id ,'language_id'); $products = $lang->getMultiText(); $product_key = $lang->status_key; $products['products_name'] = isset($_SESSION["sess_prod_edit"]) ? $_SESSION["sess_prod_edit"]->products_name : $products['products_name']; $products['products_description'] = isset($_SESSION["sess_prod_edit"]) ? $_SESSION["sess_prod_edit"]->products_description : $products['products_description']; $products['products_description_2'] = isset($_SESSION["sess_prod_edit"]) ? $_SESSION["sess_prod_edit"]->products_description_2 : $products['products_description_2']; $image_path = WM_HTML_ROOT."/uploads/images/".$store_id."_images/products/"; #繞出 分群組的SELECT OPTION資料結構 $all_cate = get_all_cate(); $big_cate = isset($all_cate[0]) ? $all_cate[0] : array(); $prod_cate = array(0=>MALL_P_CATE_NONE); foreach($big_cate as $k=>$v){ $this_cate = array(); if(isset($all_cate[$v['AutoSN']]) && is_array($all_cate[$v['AutoSN']])){ foreach($all_cate[$v['AutoSN']] as $small_cate){ $this_cate[$small_cate['AutoSN']] = $small_cate['text']; } } $prod_cate[$v['text']] = $this_cate; } #插入javascript insertJS(''); #來源網址(存檔後轉址用) if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=''){ $ref = explode('?',$_SERVER['HTTP_REFERER']); $ref = isset($ref[1]) ? $ref[1] : ''; }else if(isset($product_data->ref)){ $ref = $product_data->ref ; } // >>> Add 3 more images for product detail for ($i = 0; $i < 3; $i++) { $extraImages[$i]["no"] = "new_" . $i ; $extraImages[$i]["image_url"] = WM_HTML_ROOT . '/uploads/images/1_images/products/no_pic.png' ; $extraImages[$i]["delete"] = 0 ; } $sql = "select no, products_image from products_extra_image where products_id = $products_id" ; $db->query($sql) ; $i = 0 ; while($db->next_record()) { $extraImages[$i]["no"] = "old_" . $db->f("no") ; $extraImages[$i]["image_url"] = $db->f("products_image") ; $extraImages[$i]["delete"] = 'del_' . $db->f("no") ; $i++; } // <<< Add 3 more images for product detail // Fetch PDF url $sql = "select products_pdf from products where products_id = $products_id" ; $db->query($sql) ; $db->next_record() ; $pdf = $db->f('products_pdf'); //echo $image_path.@$products_image; $smarty->assign("show_hide",array(0=>_OFF,1=>_ON)); $smarty->assign("product_data",$product_data); $smarty->assign("products",$products); $smarty->assign("product_key",$product_key); $smarty->assign("products_cate", $prod_cate); $smarty->assign('ref',$ref); $smarty->assign("extra_images", $extraImages) ; $smarty->assign('pdf', $pdf) ; $smarty->assign("action",WM_HTML_ROOT."/?module=mall&func=ProductsUpdate"); $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/products_edit.htm"); return $ret; } // 商品儲存 function mallProductsUpdate() { global $db,$perm,$smarty; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3); foreach($_REQUEST as $key => $value) { if(!is_array($value)) $$key = common_stripslashes($value); else $$key = $value; } $products_date_available = date("Y-m-d", strtotime("$UpDateYear-$UpDateMonth-$UpDateDay")); $products_date_invalid = date("Y-m-d", strtotime("$DownDateYear-$DownDateMonth-$DownDateDay")); $action = isset($action) ? $action : ''; $products_unlimited = isset($products_unlimited) ? $products_unlimited : 0 ; $products_stock_check = isset($products_stock_check ) ? $products_stock_check : 0; $product_key = $_REQUEST['product_key']; unset($_SESSION["sess_prod_edit"]); session_register("sess_prod_edit"); $err_msg = ""; if ($action != "delete_product") { if ($products_no =="") $err_msg = sprintf(MALL_DATA_EMPTY, MALL_P_NO); //else if ($products_price =="") $err_msg = sprintf(MALL_DATA_EMPTY, MALL_P_PRICE); //else if ($products_market_price =="") $err_msg = sprintf(MALL_DATA_EMPTY, MALL_P_MARKET_PRICE); if(is_array($products_name)){ foreach($products_name as $v) if($v=='') $err_msg = sprintf(MALL_DATA_EMPTY, MALL_P_NAME); } #若為新增產品,檢查產品編號有沒有重複 if($prod_id == "0" || $prod_id == ""){ $sql = "select products_no from products where products_no='$products_no' "; }else{ $sql = "select products_no from products where products_no='$products_no' and products_id<>'$prod_id' "; } $db->query($sql); if($db->nf()>0) $err_msg = sprintf(MALL_P_MSG_1); } if ($err_msg != ""){ $_SESSION["error_message"] = $err_msg; $_SESSION["sess_prod_edit"]->store_id = $store_id; $_SESSION["sess_prod_edit"]->products_id = $prod_id; $_SESSION["sess_prod_edit"]->categories_id = $categories_id; $_SESSION["sess_prod_edit"]->sub_cate_1 = $sub_cate_1; $_SESSION["sess_prod_edit"]->sub_cate_2 = $sub_cate_2; $_SESSION["sess_prod_edit"]->products_quantity = $products_quantity; $_SESSION["sess_prod_edit"]->products_image = $products_image; $_SESSION["sess_prod_edit"]->products_unlimited = $products_unlimited; $_SESSION["sess_prod_edit"]->products_stock_check = $products_stock_check; $_SESSION["sess_prod_edit"]->products_alert_stock = $products_alert_stock; $_SESSION["sess_prod_edit"]->products_no = $products_no; $_SESSION["sess_prod_edit"]->products_price = $products_price; $_SESSION["sess_prod_edit"]->products_market_price = $products_market_price; $_SESSION["sess_prod_edit"]->products_wholesale_price = $products_wholesale_price; $_SESSION["sess_prod_edit"]->products_name = $products_name; $_SESSION["sess_prod_edit"]->products_introduction = $products_introduction; $_SESSION["sess_prod_edit"]->products_description = $products_description; $_SESSION["sess_prod_edit"]->products_description_2 = $products_description_2; $_SESSION["sess_prod_edit"]->products_date_available = $products_date_available; $_SESSION["sess_prod_edit"]->products_date_invalid = $products_date_invalid; $_SESSION["sess_prod_edit"]->products_status = $products_status; $_SESSION["sess_prod_edit"]->products_url = $products_url; $_SESSION["sess_prod_edit"]->ref = $ref; errorShow($err_msg,WM_HTML_ROOT."/?module=mall&func=ProductsEdit&prod_id=$prod_id&err=1"); } $upload_path = WM_REAL_PATH . '/uploads/images/1_images/products' ; $upload_url = WM_HTML_ROOT . "/uploads/images/1_images/products" ; if ($prod_id == "0" || $prod_id == ""){ $majorImage = uploadFile('file_1', $upload_path, true, MALL_PROD_IMAGE_WIDTH) ; $majorImage = $upload_url . '/' . $majorImage ; $pdf = uploadFile('file_pdf', $upload_path) ; $pdf = $upload_url . '/' . $pdf ; // # PROCESS IMAGE // if(isset($_POST['org']) && $_POST['org']==1) { // #照原尺寸 上傳 // $width_arr = array('o'=>2480); // $org=1; // }else { // # 分三種大小 // $width_arr = array('s'=>200,'m'=>300,'l'=>720); // $org=0; // } // // foreach($width_arr as $size=>$newWidth) { // #判斷圖片是否太小 // if( (isset($ex_width) && $info[0]>$ex_width) || !isset($ex_width) ) { // #如果用縮的 // if(!$org) // $newFileName = $image->Resample($size."_".$fileName,$newWidth ,$newWidth); // #如果原尺寸用COPY的 // else{ // $newFileName = $image->copyTo($size."_".$fileName); // } // if($newFileName) { // $file = $newFileName; // $db=new DB_SiS("INSERT INTO fileList (filename, dir, image_size, category,postdate,custname) // values('$file','$dir', '$size', 'image',now(),'$custname')"); // }else $msg = SYSIMAGE_EDIT_7; // $ex_width = $newWidth; // // #產生圖片的訊息 // if($org) $up_msg .= sprintf( SYSIMAGE_EDIT_19, $info[0], $info[1] ).SYSIMAGE_EDIT_20; // else if($size=='s') // $up_msg .= sprintf( SYSIMAGE_EDIT_19, $info[0], $info[1] ).sprintf(SYSIMAGE_EDIT_23,$newWidth)."
"; // else if($size=='m') // $up_msg .= sprintf( SYSIMAGE_EDIT_19, $info[0], $info[1] ).sprintf(SYSIMAGE_EDIT_22,$newWidth)."
"; // else if($size=='l') // $up_msg .= sprintf( SYSIMAGE_EDIT_19, $info[0], $info[1] ).sprintf(SYSIMAGE_EDIT_21,$newWidth)."
"; // } // } $sql = "Insert into products (store_id, products_no, products_image, products_price, products_market_price, products_wholesale_price, products_date_available, products_date_invalid, products_date_added, products_status, products_pdf) values(".$store_id.", '". $products_no . "', '". $majorImage . "', '". $products_price . "', ' ". $products_market_price . "', ' ". $products_wholesale_price . "', ' ". $products_date_available . "', ' ". $products_date_invalid . "', now(), '".$products_status."', '$pdf')"; //Insert into products //(store_id, products_no, products_image, products_price, products_market_price, products_date_available, products_date_invalid, products_date_added, products_status) //values(".$store_id.", '". // $products_no . "', '". //$products_price . "', ' ". //$products_market_price . "', ' ". //$products_date_available . "', ' ". //$products_date_invalid . "', now(), '".$products_status."')"; $db->query($sql); $products_id = mysql_insert_id(); $prod_id=$products_id; $sql = "Insert into products_to_categories (store_id, products_id, categories_id, sub_cate_1, sub_cate_2) values($store_id, $products_id, $categories_1, $categories_2, $categories_3)"; $db->query($sql); for ($i = 0; $i < 3; $i++) { $imageParam = 'new_' . $i ; $newImage = uploadFile($imageParam, $upload_path, true, MALL_PROD_IMAGE_WIDTH) ; if ($newImage) { $sql = "insert into products_extra_image values (null, $prod_id, '" . $upload_url . "/" . $newImage . "')" ; $db->query($sql) ; } } } else if ($prod_id > 0 ){ $sql = " Update products set products_no = '$products_no' , products_image = '$products_image', products_price = '". (int)$products_price ."', products_market_price = '". (int)$products_market_price ."', products_wholesale_price = '". (int)$products_wholesale_price ."', products_date_available = '$products_date_available', products_status = '$products_status' , products_date_invalid = '$products_date_invalid' where products_id = ". (int)$prod_id; $db->query($sql); //products_image = '$products_image', $sql = "update products_to_categories set categories_id='$categories_1', sub_cate_1='$categories_2', sub_cate_2='$categories_3' where products_id='$prod_id' and store_id='$store_id' "; $db->query($sql); // Handle uploaded image files $majorImage = uploadFile('file_1', $upload_path, true, MALL_PROD_IMAGE_WIDTH) ; if ($majorImage) { $sql = "update products set products_image='" . $upload_url . '/' . $majorImage . "' where products_id=$prod_id"; $db->query($sql); } // Handle uploaded pdf files $pdf = uploadFile('file_pdf', $upload_path) ; if ($pdf) { $sql = "update products set products_pdf='" . $upload_url . '/' . $pdf . "' where products_id=$prod_id"; $db->query($sql); } if ($_REQUEST['del_pdf'] == 1) { $sql = "update products set products_pdf='' where products_id=$prod_id"; $db->query($sql); } $sql = "select no from products_extra_image where products_id = $prod_id" ; $db->query($sql) ; $oldNums = array() ; while ($db->next_record()) { $oldNums[] = $db->f("no") ; } for ($i = 0; $i < count($oldNums); $i++) { $index = $oldNums[$i] ; $newImage = uploadFile('old_' . $index, $upload_path, true, MALL_PROD_IMAGE_WIDTH) ; if ($newImage) { $sql = "update products_extra_image set products_image = '" . $upload_url . "/" . $newImage . "' where no = $index" ; $db->query($sql) ; } if ($_REQUEST['del_' . $index] == 1) { $sql = "delete from products_extra_image where no=$index" ; $db->query($sql) ; } } for ($i = 0; $i < 3; $i++) { $newImage = uploadFile('new_' . $i, $upload_path, true, MALL_PROD_IMAGE_WIDTH) ; if ($newImage) { $sql = "insert into products_extra_image values (null, $prod_id, '" . $upload_url . "/" . $newImage . "')" ; $db->query($sql) ; } } } #處理語系的部份 $products_id = $prod_id; foreach($products_name as $k=> $v) $products_name[$k] = htmlspecialchars( $v, ENT_QUOTES) ; foreach($products_description as $k=> $v) $products_description[$k] = htmlspecialchars( $v, ENT_QUOTES) ; //$lang = new Lang('products_description',array('products_name','products_description'),'products_id' , $products_id ,'language_id'); $lang = new Lang('products_description',array('products_name','products_description','products_description_2'),'products_id' , $products_id ,'language_id'); $lang->entity=1; $lang->status_key = $product_key ; //$lang->addMultiText( $products_name ,$products_description ); $lang->addMultiText( $products_name, $products_description, $products_description_2 ); $sql = "update products_description set products_introduction='$products_introduction', products_url='$products_url' where products_id='$prod_id' "; $db->query($sql); #4順利處理完資料就刪掉SESSION unset($_SESSION["sess_prod_edit"]); //$db->CompleteTrans(); if($ref!='') $url = WM_HTML_ROOT."/?".$ref ; else $url = WM_HTML_ROOT."/"; header("Location:".html_entity_decode($url)); exit; } #刪除產品 function mallProductsDelete(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_P_MANAGE); $pid = (int)$_GET['id']; $db->query("select * from orders_products where products_id ='$pid'"); if($db->nf()>0) errorShow(MALL_P_NODEL); #產品已經跟訂單有關聯 $db->query("delete from products where products_id ='$pid'"); $db->query("delete from products_description where products_id ='$pid'"); $db->query("delete from products_pick where products_id ='$pid'"); $db->query("delete from products_to_categories where products_id ='$pid'"); $ref= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : WM_HTML_ROOT.'/'; errorShow(MALL_P_DELED,$ref); } // 購物車清單 function mallCheckoutSelect() { global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_CAR_SELECT); # Insert JS insertJS(''); if (!isset($_SESSION["card"])) $_SESSION["card"] = array(); #抓ref $ref = ''; if(!isset($_SESSION['cart_ref'])){ if(isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']!=''&&strpos($_SERVER['HTTP_REFERER'],'?module=mall&func=CheckoutSelect')===false){ $ref_http = explode('?',$_SERVER['HTTP_REFERER']); if(isset($ref_http[1])) { $ref = '?'.$ref_http[1]; } } $_SESSION['cart_ref'] = $ref ; }else $ref = $_SESSION['cart_ref'] ; #產品屬性的價格差 $attr = array(); $db->query("select a.*,b.products_options_values_name from products_attributes as a left join products_options_values as b on a.options_values_id=b.products_options_values_id and b.language_id='$df_lang'"); while($db->next_record()){ $diff = (int)$db->f("options_values_price")>0 ? intval($db->f("price_prefix").$db->f("options_values_price")):0 ; $attr[$db->f("products_attributes_id")] = array('price'=>$diff,'name'=>$db->f("products_options_values_name")); } switch(@$_GET["action"]) { case "add_product": // 新增 if (!in_car(@$_GET["prod_id"])) add_car(@(int)$_GET["prod_id"]); //echo(json_encode(array('message'=>'本商品已加入購物車 !'))) ; //exit() ; break; case "update_product": // 修改 #$_SESSION["card"] = array(); if(!isset($_POST["prod_id"])){ break; } foreach($_POST["prod_id"] as $i=>$pd) { if((int)$_POST["qty"][$i] == 0) { move_car($pd); continue; } $_SESSION["card"][$pd]['product_qty'] = (int) $_POST["qty"][$i]; #add_car($_POST["prod_id"][$i], $qty ); } if (isset($_POST["product_del_no"])) { foreach($_POST["product_del_no"] as $k => $value) move_car($value); } #if(isset($qty_msg)&& $qty_msg!="") $_SESSION['qty_msg'] = $qty_msg; # 是否要結帳了 if(isset($_POST['isCheckOut']) && $_POST['isCheckOut']>0) $url = WM_HTML_ROOT."/?module=mall&func=CheckoutPaymentConfirm&step=1"; else $url =WM_HTML_ROOT."/?module=mall&func=CheckoutSelect&action=update_product" ; header("Location:".$url); exit; break; case "move_product": // 移除 $_SESSION["card"] = array(); break; case "continue_shopping": //繼續購物 unset($_SESSION['cart_ref']); header("Location:".WM_HTML_ROOT."/".$ref); exit; } $cars_list = array(); // 顯示購物清單 $total = 0; #for($i=0;$i$sv) { $products_id = $_SESSION["card"][$i]["product_id"]; $prod_info = get_products_info($products_id); $tmp = array( "products_id" => $prod_info["products_id"], "products_image" => $prod_info["products_image"], "products_price" => (int)$prod_info["products_price"], "products_qty" => $_SESSION["card"][$i]["product_qty"], "products_name" => $prod_info["products_name"], "products_sub" => (int)$prod_info["products_price"]*$_SESSION["card"][$i]["product_qty"] ); if(isset($_SESSION["card"][$i]['attr'])) { foreach($_SESSION["card"][$i]['attr'] as $att_id){ if($attr[$att_id]['price']!=0){ $tmp['products_price'] = $tmp['products_price'] + $attr[$att_id]['price'] ; } $tmp['products_name'] .= " (".$attr[$att_id]['name'].")"; } $tmp['products_sub'] = intval($tmp['products_qty']*($tmp['products_price'])); $tmp['products_price'] = number_format($tmp['products_price']); } array_push( $cars_list, $tmp ); #$total = $total+(int)$prod_info["products_price"]*$_SESSION["card"][$i]["product_qty"]; $total = $total+$tmp['products_sub']; } #判斷運費有沒有優惠 $commit = getSysOption('mall_free_freight'); $free_msg = ''; if($commit>0 ){ #有優惠 $free_msg = sprintf(MALL_CAR_FREE_NOTE,$commit); } $content = array(); $smarty->assign('total', number_format($total)); $smarty->assign('cars_list', $cars_list); $smarty->assign('ref_http',$ref); $smarty->assign('free_msg',$free_msg); /* 購物數量的message SESSION if(isset($_SESSION['qty_msg'])){ $smarty->assign('qty_msg', $_SESSION['qty_msg']); unset($_SESSION['qty_msg']); }*/ $smarty->assign('action', WM_HTML_ROOT."/?module=mall&func=CheckoutSelect&action=update_product"); $ret['title'] = MALL_CAR_SELECT; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/checkout_select.htm"); return $ret; } //詢價功能 function mallAskProductPrice(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_AP_1); if(!isset($_GET['prod'])){ errorShow(SYSERROR_1.MALL_AP_1); } if(getSysOption('mall_ask_price')!=1 || getSysOption('cart_flag')!=0){ errorShow(MALL_AP_8); } $store_id = $GLOBALS['STORE_ID']; $pid = (int) $_GET['prod']; $data=array(); $db->query("select products_name from products_description where products_id='$pid' and language_id='$df_lang' and store_id='$store_id'"); $db->next_record(); $products_name = $db->f("products_name"); if($products_name=='') errorShow(MALL_P_NODATA) ; $uid = $_SESSION['user']['uid']; $user_id = isset( $_SESSION['user']['id']) ? $_SESSION['user']['id'] : ''; $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : WM_HTML_ROOT."/"; $db->query("select a.name,b.customers_email_address, b.customers_telephone from member as a left join customers as b on a.AutoSN=b.customers_id where a.AutoSN='$uid'"); $db->next_record(); $data = $db->Record ; $smarty->assign('data', get_object_vars($data)); $smarty->assign('products_name', $products_name); $smarty->assign('customers_id',$user_id); $smarty->assign('pid', $pid); $smarty->assign('ref', $ref); //$ret['title'] = MALL_AP_1; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/ask_price.htm"); return $ret; } function mallSendAskPrice(){ global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsAccess")) errorShow(SYSERROR_3.MALL_AP_1); if(getSysOption('mall_ask_price')!=1 || getSysOption('cart_flag')!=0){ #檢查詢價是否啟用 errorShow(MALL_AP_8); } foreach($_POST as $k=>$v) $$k = htmlspecialchars( $v, ENT_QUOTES); #驗證碼 if(isset($_REQUEST['authcode'])) { $array="7519036284"; $tauthnum=""; for($i=0;$i<4;$i++) { $tauthnum .=substr($array,substr($_REQUEST['authcode'],$i,1),1); } if(strcmp($_REQUEST['authnum'],$tauthnum)!=0) { $tmsg = MALL_AP_14; } else { $tmsg = "" ; } } else { $tmsg = MALL_AP_14; } if ($tmsg != "") { $redirect = WM_HTML_ROOT; errorShow(MALL_AP_14, $redirect) ; exit() ; } //------ if($customer_id!='' ) $contact_name .= sprintf(MALL_AP_9,$customer_id) ; #若是會員則註明 $contact = nl2br($contact); $prod_url = 'http://'.$_SERVER['SERVER_NAME'].WM_HTML_ROOT."/?module=mall&func=ProductsDetail&prod_id=".$products_id; $site_name = getSysOption('mall_site_name'); $site_name = $site_name==''?'WebMaster產品中心':$site_name; $smarty->assign('site_name', $site_name); $smarty->assign('products_name', $products_name); $smarty->assign('contact_name', $contact_name); $smarty->assign('contact_company', $contact_company); $smarty->assign('contact_mail', $contact_mail); $smarty->assign('contact_tel', $contact_tel); $smarty->assign('contact', $contact); $smarty->assign('prod_url', $prod_url); $html = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/ask_price_send.htm"); #trace($html); $subject = MALL_AP_11; $admin_mail = getSysOption('mall_service_mail'); #如果信箱是空值,則使用系統管理者的信箱 if($admin_mail=='') { $db->query("select b.customers_email_address from member as a left join customers as b on a.AutoSN=b.customers_id where gid=2"); $db->next_record(); $admin_mail=$db->f("customers_email_address"); } initMail(); $mail = new SMTP; $mail->Delivery('local'); $mail->setCharset(CHARSET); $mail->AddTo($admin_mail,'admin'); // $mail->AddCc('信箱地址','寄件者名稱'); $mail->AddHeader('Reply-To',$admin_mail ); $mail->From($admin_mail,$site_name); $mail->Html($html,CHARSET); $send = $mail->Send($subject); #trace($ref); if($send) errorShow(MALL_AP_12,$ref); else errorShow(MALL_ORDER_S37,$ref); } // 管理區域 function mallMallAdmin() { global $db,$perm,$smarty,$df_lang; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_ADMIN); $cart_flag = getSysOption('cart_flag'); $prod_list = array(); $overvaild = array(); $invaild = array(); $total_order = array(); #統計的訂單 $status = array(1=>MALL_ORDER_STATUS_1 , 2=>MALL_ORDER_STATUS_2 , 3=>MALL_ORDER_STATUS_3 , 4=>MALL_ORDER_STATUS_4 , 5=>MALL_ORDER_STATUS_5 , 6=>MALL_ORDER_STATUS_6 , 7=>MALL_ORDER_STATUS_7 , 8=>MALL_ORDER_STATUS_8 ); if($cart_flag==1){ /*#庫存不足產品的警告 $db->query("select a.products_id, a.products_quantity ,b.products_name from products as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' where a.products_quantity<=a.products_alert_stock and a.products_stock_check=1 and a.products_unlimited=0"); while($db->next_record()){ $alert_prod = array(); $alert_prod['id'] = $db->f("products_id"); $alert_prod['desc'] = sprintf(MALL_P_QTY_ALERT_1 , $db->f("products_name") , $db->f("products_quantity") ); array_push($prod_list,$alert_prod); }*/ #訂單統計 $db->query("select DISTINCT orders_status ,count(orders_id) as cnt from orders GROUP BY orders_status"); while($db->next_record()){ $total_order[$db->f("orders_status")] = sprintf(MALL_P_ORDER_CNT_1, ''.$status[$db->f("orders_status")].' ' , $db->f("cnt")); } #已下架商品列表 $db->query("select a.products_id , a.products_date_invalid , b.products_name from products as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' where a.products_date_invalidnext_record()){ $alert_prod = array(); $alert_prod['id'] = $db->f("products_id"); $alert_prod['desc'] = sprintf(MALL_P_INVABLE_3 , $db->f("products_name") , $db->f("products_date_invalid") ); array_push($overvaild,$alert_prod); } #未上架商品列表 $db->query("select a.products_id , a.products_date_available , b.products_name from products as a left join products_description as b on a.products_id=b.products_id and b.language_id='$df_lang' where a.products_date_available>now() "); while($db->next_record()){ $alert_prod = array(); $alert_prod['id'] = $db->f("products_id"); $alert_prod['desc'] = sprintf(MALL_P_AVAIABLE_3 , $db->f("products_name") , $db->f("products_date_available") ); array_push($invaild,$alert_prod); } } $ret = array(); $ret['title'] = MALL_ADMIN; $smarty->assign('prod_list',$prod_list); $smarty->assign('overvaild',$overvaild); $smarty->assign('invaild',$invaild); $smarty->assign('total_order',$total_order); $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/mall_admin.htm"); return $ret; } function malloptionSet(){ global $db,$perm,$smarty; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_ADMIN_CONFIG); /*$mall_options = array( 'cart_flag', 'order_thanks_word', 'mall_ask_price', 'mall_free_freight', 'mall_per_page', 'mall_service_mail', 'mall_order_note', 'mall_return_day', 'mall_return_flag', 'mall_freight_type', 'mall_site_name', 'mall_phone_num', 'mall_history_view', 'mall_invoice_flag' );*/ $mall_options = array( 'cart_flag', 'order_thanks_word', 'mall_ask_price', 'mall_free_freight', 'mall_per_page', 'mall_order_note', 'mall_return_day', 'mall_return_flag', 'mall_freight_type', 'mall_history_view', 'mall_invoice_flag' ); #更新 if(isset($_POST['post_flag'])) { $cart_flag = $_POST['cart_flag']; $order_thanks_word = htmlspecialchars( $_POST['order_thanks_word'], ENT_QUOTES); $mall_ask_price = (int)$_POST['mall_ask_price']>=1 ? 1 : 0; $mall_free_freight = (int)$_POST['mall_free_freight'] ; $mall_per_page = (int) $_POST['mall_per_page'] ; //$mall_service_mail = htmlspecialchars(str_replace(' ','',$_POST['mall_service_mail']), ENT_QUOTES); $mall_order_note = htmlspecialchars( $_POST['mall_order_note'], ENT_QUOTES); //$mall_mail_note = htmlspecialchars( $_POST['mall_mail_note'], ENT_QUOTES); $mall_return_day = (int)$_POST['mall_return_day'] ; $mall_return_flag = (int)$_POST['mall_return_flag']; $mall_freight_type = (int)$_POST['mall_freight_type']; $mall_history_view = (int)$_POST['mall_history_view']; $mall_invoice_flag = (int)$_POST['mall_invoice_flag']; //$mall_site_name = htmlspecialchars( $_POST['mall_site_name'], ENT_QUOTES); //$mall_phone_num = htmlspecialchars( $_POST['mall_phone_num'], ENT_QUOTES); #若EMAIL為空 /*if($mall_service_mail==''){ $db->query("select b.customers_email_address from member as a left join customers as b on a.AutoSN=b.customers_id where gid=2"); $db->next_record(); $mall_service_mail=$db->f("customers_email_address"); }*/ foreach($mall_options as $op){ $db->query("update system_option set op_value='".$$op."' where op_name='$op' "); } errorShow(MALL_OPSET_3,WM_HTML_ROOT."/?module=mall&func=MallAdmin"); } $cart_flag = getSysOption('cart_flag'); #$order_thanks = html_entity_decode(getSysOption('order_thanks_word')); $data = array(); foreach($mall_options as $op ){ $value = getSysOption($op); $data[$op] = html_entity_decode($value); } $list = array(0=>_OFF,1=>_ON); $smarty->assign('cart_flag', $cart_flag); $smarty->assign('list', $list); $smarty->assign('data', $data); $smarty->assign('per_page', array(3=>3,6=>6,9=>9,12=>12,15=>15,18=>18,21=>21,27=>27,30=>30)); $smarty->assign('return_day', array(7=>7,14=>14,20=>20,30=>30,35=>35)); $smarty->assign('order_thanks', FCKeditor("order_thanks_word",$data['order_thanks_word'])); $smarty->assign('mall_order_note', FCKeditor("mall_order_note",$data['mall_order_note'])); # $smarty->assign('mall_mail_note', FCKeditor("mall_mail_note",$data['mall_mail_note'])); $ret['title'] = MALL_ADMIN_CONFIG; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/mall_admin_option.htm"); return $ret; } function mallMailOption(){ global $db,$perm,$smarty; if(!$perm->havePerm("ProductsModify")) errorShow(SYSERROR_3.MALL_MAIL_1); $mall_options = array( 'mall_mail_note', 'mall_mail_out', 'mall_mail_canceling', 'mall_mail_canceled', 'mall_mail_return', 'mall_mail_returned', 'mall_mail_lack', 'mall_mail_flag_note', 'mall_mail_flag_out', 'mall_mail_flag_canceling', 'mall_mail_flag_canceled', 'mall_mail_flag_return', 'mall_mail_flag_returned', 'mall_mail_flag_lack' ); if(isset($_POST['post_flag'])) { $mall_mail_note = htmlspecialchars( $_POST['mall_mail_note'], ENT_QUOTES); $mall_mail_out = htmlspecialchars( $_POST['mall_mail_out'], ENT_QUOTES); $mall_mail_canceling= htmlspecialchars( $_POST['mall_mail_canceling'], ENT_QUOTES); $mall_mail_canceled = htmlspecialchars( $_POST['mall_mail_canceled'], ENT_QUOTES); $mall_mail_return = htmlspecialchars( $_POST['mall_mail_return'], ENT_QUOTES); $mall_mail_returned = htmlspecialchars( $_POST['mall_mail_returned'], ENT_QUOTES); $mall_mail_lack = htmlspecialchars( $_POST['mall_mail_lack'], ENT_QUOTES); $mall_mail_flag_note = (int)$_POST['mall_mail_flag_note']; $mall_mail_flag_out = (int)$_POST['mall_mail_flag_out']; $mall_mail_flag_canceling = (int)$_POST['mall_mail_flag_canceling']; $mall_mail_flag_canceled = (int)$_POST['mall_mail_flag_canceled']; $mall_mail_flag_return = (int)$_POST['mall_mail_flag_return']; $mall_mail_flag_returned = (int)$_POST['mall_mail_flag_returned']; $mall_mail_flag_lack = (int)$_POST['mall_mail_flag_lack']; #更新 foreach($mall_options as $op){ $db->query("update system_option set op_value='".$$op."' where op_name='$op' "); } errorShow(MALL_MAIL_2,WM_HTML_ROOT."/?module=mall&func=MallAdmin"); } #$list = array(0=>_OFF,1=>_ON); $data = array(); foreach($mall_options as $op ){ $value = getSysOption($op); $data[$op] = html_entity_decode($value); } $smarty->assign('list', array(0=>_OFF,1=>_ON)); $smarty->assign('data', $data); $smarty->assign('mall_mail_note', FCKeditor("mall_mail_note",$data['mall_mail_note'],'100%','260px')); $smarty->assign('mall_mail_out', FCKeditor("mall_mail_out",$data['mall_mail_out'],'100%','260px')); $smarty->assign('mall_mail_canceling', FCKeditor("mall_mail_canceling",$data['mall_mail_canceling'],'100%','260px')); $smarty->assign('mall_mail_canceled', FCKeditor("mall_mail_canceled",$data['mall_mail_canceled'],'100%','260px')); $smarty->assign('mall_mail_return', FCKeditor("mall_mail_return",$data['mall_mail_return'],'100%','260px')); $smarty->assign('mall_mail_returned', FCKeditor("mall_mail_returned",$data['mall_mail_returned'],'100%','260px')); $smarty->assign('mall_mail_lack', FCKeditor("mall_mail_lack",$data['mall_mail_lack'],'100%','260px')); $ret['title'] = MALL_MAIL_1; $ret['content'] = $smarty->fetch(WM_REAL_PATH."/modules/mall/templates/mall_mail_option.htm"); return $ret; } ////====================================================================================== //// function area //// moved to includes/function.php // ////20160414 Add upload file's for PDF //function uploadFile($in_upfile, $in_path, $resize=false) { // // $sRet=''; // // if(!empty($_FILES[$in_upfile]['name'])) // 上傳檔名不為空-->有檔案上傳 // { // $filename = $_FILES[$in_upfile]['name']; // 原始檔名 // if (strlen(strrpos($filename, "."))==0) // { // $ext=""; // } // else // { // $ext=substr($filename,strrpos($filename, "."),strlen($filename)); //附加檔名 // } // // $newfilename = date("YmdHis"). sprintf("%03s",rand(0, 999)); // // if (!file_exists($in_path)){ // @mkdir($in_path, 0777); // } // @chmod($in_path, 0777); // // if ($resize) { // include_once(WM_INCLUDE_PATH."/image/image.php"); // $image = new wm_image($in_path . '/' , $_FILES[$in_upfile]) ; // $info = getimagesize($_FILES[$in_upfile]["tmp_name"]); // # 一律用寬度720px的圖片 // $ex_width = 720; // if( $info[0]>$ex_width ) { // $newWidth = 720 ; // $newHeight = (int)(720/$info[0]*$info[1]) ; // $newfilename = $image->Resample($newfilename, $newWidth, $newHeight); // } // else { // $newfilename = $newfilename . $ext; // move_uploaded_file($_FILES[$in_upfile]['tmp_name'], $in_path. '/' . $newfilename); // } // } // else { // $newfilename = $newfilename . $ext; // move_uploaded_file($_FILES[$in_upfile]['tmp_name'], $in_path. '/' . $newfilename); // } // //// if (!file_exists($in_path . $newfilename)){ //// @chmod( $in_path . $newfilename, 0777); //// } // // $sRet=trim($newfilename); // //// //刪除檔案 //// if (!empty($_FILES[$in_upfile."_old"]['name']) and file_exists($in_path.$IN_FILES[$in_upfile."_old"]['name'])) {unlink($in_path.$IN_FILES[$in_upfile."_old"]['name']); } // } // return $sRet; //} ?> 芳岳茶園