1 | <?php
|
---|
2 | /*
|
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
|
---|
4 | *
|
---|
5 | * http://www.lockon.co.jp/
|
---|
6 | */
|
---|
7 | require_once("../../require.php");
|
---|
8 |
|
---|
9 | //---- ページ表示クラス
|
---|
10 | class 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));
|
---|
38 | if(!$cart_flg) {
|
---|
39 | header("location: ". CAMPAIGN_URL . "$dir_name/application.php");
|
---|
40 | }
|
---|
41 |
|
---|
42 | // キャンペーンが開催中かをチェック
|
---|
43 | if(lfCheckActive($dir_name)) {
|
---|
44 | $status = CAMPAIGN_TEMPLATE_ACTIVE;
|
---|
45 | } else {
|
---|
46 | $status = CAMPAIGN_TEMPLATE_END;
|
---|
47 | }
|
---|
48 |
|
---|
49 | if($_GET['init'] != "") {
|
---|
50 | $objPage->tpl_init = 'false';
|
---|
51 | lfDispProductsList($_GET['ids']);
|
---|
52 | } else {
|
---|
53 | $objPage->tpl_init = 'true';
|
---|
54 | }
|
---|
55 |
|
---|
56 | switch($_POST['mode']) {
|
---|
57 |
|
---|
58 | case '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;
|
---|
80 | default :
|
---|
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 | */
|
---|
99 | function 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 | /* 商品一覧の表示 */
|
---|
122 | function 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 | /* 規格セレクトボックスの作成 */
|
---|
167 | function 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 | /* 商品規格情報の取得 */
|
---|
284 | function 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 | /* 入力内容のチェック */
|
---|
299 | function 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 | // 購入制限数の設定
|
---|
321 | function 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:現金書留
|
---|
335 | function 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 | ?> |
---|