source: branches/feature-module-update/html/products/review.php @ 15080

Revision 15080, 5.7 KB checked in by nanasess, 17 years ago (diff)

svn properties 設定

  • svn:mime-type - application/x-httpd-php; charset=UTF-8
  • svn:keywords - Id
  • Property svn:keywords set to Id
  • Property svn:mime-type set to application/x-httpd-php; charset=UTF-8
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
9class LC_Page {
10    function LC_Page() {
11        $this->tpl_mainpage = 'products/review.tpl';
12        global $arrRECOMMEND;
13        $this->arrRECOMMEND = $arrRECOMMEND;
14        global $arrSex;
15        $this->arrSex = $arrSex;
16    }
17}
18
19$objPage = new LC_Page();
20$objView = new SC_SiteView();
21$objQuery = new SC_Query();
22
23//---- 登録用カラム配列
24$arrRegistColumn = array(
25                             array(  "column" => "review_id", "convert" => "aKV" ),
26                             array(  "column" => "product_id", "convert" => "aKV" ),
27                             array(  "column" => "reviewer_name", "convert" => "aKV" ),
28                             array(  "column" => "reviewer_url", "convert" => "a"),
29                             array(  "column" => "sex", "convert" => "n" ),
30                             array(  "column" => "email", "convert" => "a" ),
31                             array(  "column" => "recommend_level", "convert" => "n" ),
32                             array(  "column" => "title", "convert" => "aKV" ),
33                             array(  "column" => "comment", "convert" => "aKV" ),
34
35                        );
36switch ($_POST['mode']){
37case 'confirm':
38    $arrForm = lfConvertParam($_POST, $arrRegistColumn);
39    $objPage->arrErr = lfErrorCheck($arrForm);
40    //重複メッセージの判定
41    $flag = $objQuery->count("dtb_review","product_id = ? AND title = ? ", array($arrForm['product_id'], $arrForm['title']));
42
43    if ($flag > 0){
44        $objPage->arrErr['title'] .= "重複したタイトルは登録できません。";
45    }
46       
47    //エラーチェック
48    if($objPage->arrErr == ""){
49        //重複タイトルでない
50        if($flag == 0){
51            //商品名の取得
52            $arrForm['name'] = $objQuery->get("dtb_products", "name", "product_id = ? ", array($arrForm['product_id']));
53            $objPage->arrForm = $arrForm;
54            $objPage->tpl_mainpage = 'products/review_confirm.tpl';
55        }
56    } else {
57        //商品名の取得
58        $arrForm['name'] = $objQuery->get("dtb_products", "name", "product_id = ? ", array($arrForm['product_id']));   
59        $objPage->arrForm = $arrForm;
60    }
61    break;
62
63case 'return':
64    foreach($_POST as $key => $val){
65        $objPage->arrForm[ $key ] = $val;
66    }
67   
68    //商品名の取得
69    $objPage->arrForm['name'] = $objQuery->get("dtb_products", "name", "product_id = ? ", array($objPage->arrForm['product_id']));
70    if(empty($objPage->arrForm['name'])) {
71        sfDispSiteError(PAGE_ERROR);
72    }
73    break;
74
75case 'complete':
76    $arrForm = lfConvertParam($_POST, $arrRegistColumn);
77    $arrErr = lfErrorCheck($arrForm);
78    //重複メッセージの判定
79    $flag = $objQuery->count("dtb_review","product_id = ? AND title = ? ", array($arrForm['product_id'], $arrForm['title']));
80    //エラーチェック
81    if ($arrErr == ""){
82        //重複タイトルでない
83        if($flag == 0) {
84            //登録実行
85            lfRegistRecommendData($arrForm, $arrRegistColumn);
86            //レビュー書き込み完了ページへ
87            header("Location: ./review_complete.php");
88            exit;
89        }
90    } else {
91        if($flag > 0) {
92            sfDispSiteError(PAGE_ERROR);
93        }
94    }
95    break;
96
97default:
98    if(sfIsInt($_GET['product_id'])) {
99        //商品情報の取得
100        $arrForm = $objQuery->select("product_id, name", "dtb_products", "del_flg = 0 AND status = 1 AND product_id=?", array($_GET['product_id']));
101        if(empty($arrForm)) {
102            sfDispSiteError(PAGE_ERROR);
103        }
104        $objPage->arrForm = $arrForm[0];
105    }
106    break;
107
108}
109
110$objView->assignobj($objPage);
111$objView->display($objPage->tpl_mainpage);                 
112
113//-----------------------------------------------------------------------------------------------------------------------------------
114
115
116//エラーチェック
117
118function lfErrorCheck() {
119    $objErr = new SC_CheckError();
120    $objErr->doFunc(array("商品ID", "product_id", INT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));           
121    $objErr->doFunc(array("投稿者名", "reviewer_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
122    $objErr->doFunc(array("URL", "reviewer_url", MTEXT_LEN), array("MAX_LENGTH_CHECK", "URL_CHECK"));
123    $objErr->doFunc(array("おすすめレベル", "recommend_level"), array("SELECT_CHECK"));
124    $objErr->doFunc(array("タイトル", "title", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
125    $objErr->doFunc(array("コメント", "comment", LTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
126   
127    if (REVIEW_ALLOW_URL == false) {
128        // コメント欄へのURLの入力を禁止
129        global $arrReviewDenyURL;
130        $objErr->doFunc(array("URL", "comment", $arrReviewDenyURL), array("PROHIBITED_STR_CHECK"));
131    }
132   
133    return $objErr->arrErr;
134}
135
136//---- 取得文字列の変換
137function lfConvertParam($array, $arrRegistColumn) {
138    /*
139     *  文字列の変換
140     *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
141     *  C :  「全角ひら仮名」を「全角かた仮名」に変換
142     *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
143     *  n :  「全角」数字を「半角(ハンカク)」に変換
144     *  a :  全角英数字を半角英数字に変換する
145     */
146    // カラム名とコンバート情報
147    foreach ($arrRegistColumn as $data) {
148        $arrConvList[ $data["column"] ] = $data["convert"];
149    }
150    // 文字変換
151    foreach ($arrConvList as $key => $val) {
152        // POSTされてきた値のみ変換する。
153        if(strlen(($array[$key])) > 0) {
154            $array[$key] = mb_convert_kana($array[$key] ,$val);
155        }
156    }
157    return $array;
158}
159
160//登録実行
161function lfRegistRecommendData ($array, $arrRegistColumn) {
162    global $objQuery;
163   
164    // 仮登録
165    foreach ($arrRegistColumn as $data) {
166        if (strlen($array[ $data["column"] ]) > 0 ) {
167            $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
168        }
169    }
170    $arrRegist['create_date'] = 'now()';
171    $arrRegist['update_date'] = 'now()';
172    $arrRegist['creator_id'] = '0';
173    //-- 登録実行
174    $objQuery->begin();
175    $objQuery->insert("dtb_review", $arrRegist);
176    $objQuery->commit();
177}
178
179?>
Note: See TracBrowser for help on using the repository browser.