source: temp/branches/ec-cube-beta/html/campaign/default/index.php @ 11131

Revision 11131, 9.6 KB checked in by uehara, 19 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../../require.php");
8
9//---- ¥Ú¡¼¥¸É½¼¨¥¯¥é¥¹
10class LC_Page {
11   
12    function LC_Page() {
13        $this->tpl_mainpage = TEMPLATE_DIR . '/campaign/index.tpl';
14    }
15}
16
17$objPage = new LC_Page();
18$objView = new SC_SiteView(false);
19$objQuery = new SC_Query();
20$objCampaignSess = new SC_CampaignSession();
21
22// ¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¼èÆÀ
23$dir_name = dirname($_SERVER['PHP_SELF']);
24$arrDir = split('/', $dir_name);
25$dir_name = $arrDir[count($arrDir) -1];
26
27/* ¥»¥Ã¥·¥ç¥ó¤Ë¥­¥ã¥ó¥Ú¡¼¥ó¥Ç¡¼¥¿¤ò½ñ¤­¹þ¤à */
28// ¥­¥ã¥ó¥Ú¡¼¥ó¤«¤é¤ÎÁ«°Ü¤È¤¤¤¦¾ðÊó¤òÊÝ»ý
29$objCampaignSess->setIsCampaign();
30// ¥­¥ã¥ó¥Ú¡¼¥óID¤òÊÝ»ý
31$campaign_id = $objQuery->get("dtb_campaign", "campaign_id", "directory_name = ?", array($dir_name));
32$objCampaignSess->setCampaignId($campaign_id);
33// ¥­¥ã¥ó¥Ú¡¼¥ó¥Ç¥£¥ì¥¯¥È¥ê̾¤òÊÝ»ý
34$objCampaignSess->setCampaignDir($dir_name);
35
36// ¥­¥ã¥ó¥Ú¡¼¥ó¤¬³«ºÅÃæ¤«¤ò¥Á¥§¥Ã¥¯
37if(lfCheckLimitDate($dir_name)) {
38    $status = CAMPAIGN_TEMPLATE_ACTIVE;
39} else {
40    $status = CAMPAIGN_TEMPLATE_END;
41}
42
43if($_GET['init'] != "") {
44    $objPage->tpl_init = 'false';
45    lfDispProductsList($_GET['ids']);
46} else {
47    $objPage->tpl_init = 'true';   
48}
49
50switch($_POST['mode']) {
51
52case 'cart':
53    $objPage->arrErr = lfCheckError($_POST['product_id']);
54    if(count($objPage->arrErr) == 0) {
55        $objCartSess = new SC_CartSession();
56        $classcategory_id = "classcategory_id". $_POST['product_id'];
57        $classcategory_id1 = $_POST[$classcategory_id. '_1'];
58        $classcategory_id2 = $_POST[$classcategory_id. '_2'];
59        $quantity = "quantity". $_POST['product_id'];
60        // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç
61        if(!$objPage->tpl_classcat_find1[$_POST['product_id']]) {
62            $classcategory_id1 = '0';
63        }
64        // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç
65        if(!$objPage->tpl_classcat_find2[$_POST['product_id']]) {
66            $classcategory_id2 = '0';
67        }
68        $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
69        $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]);
70        header("Location: " . URL_CART_TOP);
71        exit;
72    }
73    break;
74default :
75    break;
76}
77// ÆþÎϾðÊó¤òÅϤ¹
78$objPage->arrForm = $_POST;
79$objPage->tpl_dir_name = CAMPAIGN_TEMPLATE_PATH . $dir_name  . "/" . $status;
80
81//----¡¡¥Ú¡¼¥¸É½¼¨
82$objView->assignobj($objPage);
83$objView->display($objPage->tpl_mainpage);
84
85
86//---------------------------------------------------------------------------------------------------------------------------------------------------------
87/*
88 * ´Ø¿ô̾¡§lfCheckLimitDate()
89 * °ú¿ô1 ¡§¥Ç¥£¥ì¥¯¥È¥ê̾
90 * ÀâÌÀ¡¡¡§¥­¥ã¥ó¥Ú¡¼¥óÃæ¤«¥Á¥§¥Ã¥¯
91 * Ìá¤êÃÍ¡§¥­¥ã¥ó¥Ú¡¼¥óÃæ¤Ê¤é true ½ªÎ»¤Ê¤é false
92 */
93function lfCheckLimitDate($directory_name) {
94   
95    global $objQuery;
96   
97    $col = "start_date,end_date";
98    $arrRet = $objQuery->select($col, "dtb_campaign", "directory_name = ? AND del_flg = 0", array($directory_name));
99
100    // ³«»ÏÆü»þ¡¦Ää»ßÆü»þ¤òÀ®·¿
101    $start_date = (date("YmdHis", strtotime($arrRet[0]['start_date'])));
102    $end_date = (date("YmdHis", strtotime($arrRet[0]['end_date'])));
103    $now_date = (date("YmdHis"));
104
105    // ¥­¥ã¥ó¥Ú¡¼¥ó¤¬³«ºÅÃæ¤«¥Á¥§¥Ã¥¯
106    if($now_date > $start_date && $now_date < $end_date) {
107        return true;
108    }
109       
110    return false;
111}
112
113/* ¾¦ÉʰìÍ÷¤Îɽ¼¨ */
114function lfDispProductsList($ids) {
115   
116    global $objQuery;
117    global $objPage;
118
119    // µ¬³Ê̾°ìÍ÷
120    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
121    // µ¬³ÊʬÎà̾°ìÍ÷
122    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
123   
124    $arrProductIds = split('-', $ids);
125    if(!is_array($arrProductIds)) {
126        $arrProductIds[0] = $ids;
127    }
128   
129    // where¶çÀ¸À®
130    $count = 0;
131    $where = "product_id IN (";
132    foreach($arrProductIds as $key =>$val) {
133        if($count > 0) $where .= ",";
134        $where .= "?";
135        $arrval[] = $val;
136        $count++;
137    }
138    $where .= ")";
139
140    // ¾¦ÉʰìÍ÷
141    $arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval);
142
143    for($i = 0; $i < count($arrProducts); $i++) {
144        $objPage = lfMakeSelect($arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
145        // ¹ØÆþÀ©¸Â¿ô¤ò¼èÆÀ
146        $objPage = lfGetSaleLimit($arrProducts);
147    }
148
149    foreach($arrProducts as $key =>$val) {
150        $arrCamp[$val['product_id']] = $val;
151    }
152   
153    $objPage->arrProducts = $arrCamp;
154   
155    return $objPage;
156}
157
158/* µ¬³Ê¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹¤ÎºîÀ® */
159function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
160    global $objPage;
161   
162    $classcat_find1 = false;
163    $classcat_find2 = false;
164    // ºß¸Ë¤¢¤ê¤Î¾¦ÉʤÎ̵ͭ
165    $stock_find = false;
166   
167    // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
168    $arrProductsClass = lfGetProductsClass($product_id);
169   
170    // µ¬³Ê1¥¯¥é¥¹Ì¾¤Î¼èÆÀ
171    $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']];
172    // µ¬³Ê2¥¯¥é¥¹Ì¾¤Î¼èÆÀ
173    $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']];
174   
175    // ¤¹¤Ù¤Æ¤ÎÁȤ߹ç¤ï¤»¿ô
176    $count = count($arrProductsClass);
177   
178    $classcat_id1 = "";
179   
180    $arrSele = array();
181    $arrList = array();
182   
183    $list_id = 0;
184    $arrList[0] = "\tlist". $product_id. "_0 = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤'";
185    $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
186   
187    for ($i = 0; $i < $count; $i++) {
188        // ºß¸Ë¤Î¥Á¥§¥Ã¥¯
189        if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
190            continue;
191        }
192       
193        $stock_find = true;
194       
195        // µ¬³Ê1¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
196        if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
197            $arrList[$list_id].=");\n";
198            $arrVal[$list_id].=");\n";
199            $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
200            $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
201            $list_id++;
202        }
203       
204        // µ¬³Ê2¤Î¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹ÍÑ
205        $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
206       
207        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹É½¼¨ÃÍ
208        if($arrList[$list_id] == "") {
209            $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('ÁªÂò¤·¤Æ¤¯¤À¤µ¤¤', '". $arrClassCatName[$classcat_id2]. "'";
210        } else {
211            $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
212        }
213       
214        // ¥»¥ì¥¯¥È¥Ü¥Ã¥¯¥¹POSTÃÍ
215        if($arrVal[$list_id] == "") {
216            $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
217        } else {
218            $arrVal[$list_id].= ", '".$classcat_id2."'";
219        }
220    }   
221   
222    $arrList[$list_id].=");\n";
223    $arrVal[$list_id].=");\n";
224       
225    // µ¬³Ê1
226    $objPage->arrClassCat1[$product_id] = $arrSele;
227   
228    $lists = "\tlists".$product_id. " = new Array(";
229    $no = 0;
230    foreach($arrList as $val) {
231        $objPage->tpl_javascript.= $val;
232        if ($no != 0) {
233            $lists.= ",list". $product_id. "_". $no;
234        } else {
235            $lists.= "list". $product_id. "_". $no;
236        }
237        $no++;
238    }
239    $objPage->tpl_javascript.= $lists.");\n";
240   
241    $vals = "\tvals".$product_id. " = new Array(";
242    $no = 0;
243    foreach($arrVal as $val) {
244        $objPage->tpl_javascript.= $val;
245        if ($no != 0) {
246            $vals.= ",val". $product_id. "_". $no;
247        } else {
248            $vals.= "val". $product_id. "_". $no;
249        }
250        $no++;
251    }
252    $objPage->tpl_javascript.= $vals.");\n";
253   
254    // ÁªÂò¤µ¤ì¤Æ¤¤¤ëµ¬³Ê2ID
255    $classcategory_id = "classcategory_id". $product_id;
256    $objPage->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); ";
257
258    // µ¬³Ê1¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
259    if($arrProductsClass[0]['classcategory_id1'] != '0') {
260        $classcat_find1 = true;
261    }
262   
263    // µ¬³Ê2¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
264    if($arrProductsClass[0]['classcategory_id2'] != '0') {
265        $classcat_find2 = true;
266    }
267       
268    $objPage->tpl_classcat_find1[$product_id] = $classcat_find1;
269    $objPage->tpl_classcat_find2[$product_id] = $classcat_find2;
270    $objPage->tpl_stock_find[$product_id] = $stock_find;
271       
272    return $objPage;
273}
274
275/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
276function lfGetProductsClass($product_id) {
277    $arrRet = array();
278    if(sfIsInt($product_id)) {
279        // ¾¦Éʵ¬³Ê¼èÆÀ
280        $objQuery = new SC_Query();
281        $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
282        $table = "vw_product_class AS prdcls";
283        $where = "product_id = ?";
284        $objQuery->setorder("rank1 DESC, rank2 DESC");
285        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
286    }
287    return $arrRet;
288}
289
290/* ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯ */
291function lfCheckError($id) {
292    global $objPage;
293   
294    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
295    $objErr = new SC_CheckError();
296   
297    $classcategory_id1 = "classcategory_id". $id. "_1";
298    $classcategory_id2 = "classcategory_id". $id. "_2";
299    $quantity = "quantity". $id;
300    // Ê£¿ô¹àÌÜ¥Á¥§¥Ã¥¯
301    if ($objPage->tpl_classcat_find1[$id]) {
302        $objErr->doFunc(array("µ¬³Ê1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
303    }
304    if ($objPage->tpl_classcat_find2[$id]) {
305        $objErr->doFunc(array("µ¬³Ê2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
306    }
307    $objErr->doFunc(array("¸Ä¿ô", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
308           
309    return $objErr->arrErr;
310}
311
312// ¹ØÆþÀ©¸Â¿ô¤ÎÀßÄê
313function lfGetSaleLimit($product) {
314    global $objPage;
315    //ºß¸Ë¤¬Ìµ¸Â¤Þ¤¿¤Ï¹ØÆþÀ©¸ÂÃͤ¬ÀßÄêÃͤè¤êÂ礭¤¤¾ì¹ç
316    if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) {
317        $objPage->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX;
318    } else {
319        $objPage->tpl_sale_limit[$product['product_id']] = $product['sale_limit'];
320    }
321   
322    return $objPage;
323}
324
325//»ÙʧÊýË¡¤Î¼èÆÀ
326//payment_id    1:Âå¶â°ú´¹¡¡2:¶ä¹Ô¿¶¤ê¹þ¤ß¡¡3:¸½¶â½ñα
327function lfGetPayment() {
328    $objQuery = new SC_Query;
329    $col = "payment_id, rule, payment_method";
330    $from = "dtb_payment";
331    $where = "del_flg = 0";
332    $order = "payment_id";
333    $objQuery->setorder($order);
334    $arrRet = $objQuery->select($col, $from, $where);
335    return $arrRet;
336}
337
338?>
Note: See TracBrowser for help on using the repository browser.