source: branches/feature-module-zeus/html/user_data/include/campaign/default/src/index.php @ 15376

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