source: branches/dev/html/admin/customer/edit.php @ 11554

Revision 11554, 12.5 KB checked in by kakinaka, 16 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// ǧ¾Ú²ÄÈݤÎȽÄê
10$objSess = new SC_Session();
11sfIsSuccess($objSess);
12
13//---- ¥Ú¡¼¥¸É½¼¨ÍÑ¥¯¥é¥¹
14class LC_Page {
15    var $arrSession;
16    var $tpl_mode;
17    var $list_data;
18
19    var $arrErr;
20    var $arrYear;
21    var $arrMonth;
22    var $arrDay;
23    var $arrPref;
24    var $arrJob;
25    var $arrSex;
26    var $arrReminder;
27    var $count;
28   
29    var $tpl_strnavi;
30               
31    function LC_Page() {
32        $this->tpl_mainpage = 'customer/edit.tpl';
33        $this->tpl_mainno = 'customer';
34        $this->tpl_subnavi = 'customer/subnavi.tpl';
35        $this->tpl_subno = 'index';
36        $this->tpl_pager = DATA_PATH . 'Smarty/templates/admin/pager.tpl';
37        $this->tpl_subtitle = '¸ÜµÒ¥Þ¥¹¥¿';
38       
39        global $arrPref;
40        $this->arrPref = $arrPref;
41        global $arrJob;
42        $this->arrJob = $arrJob;
43        global $arrSex;     
44        $this->arrSex = $arrSex;
45        global $arrReminder;
46        $this->arrReminder = $arrReminder;
47    }
48}
49$objQuery = new SC_Query();
50$objConn = new SC_DBConn();
51$objPage = new LC_Page();
52$objView = new SC_AdminView();
53$objDate = new SC_Date(1901);
54$objPage->arrYear = $objDate->getYear();    //¡¡ÆüÉÕ¥×¥ë¥À¥¦¥óÀßÄê
55$objPage->arrMonth = $objDate->getMonth();
56$objPage->arrDay = $objDate->getDay();
57
58//---- ÅÐÏ¿ÍÑ¥«¥é¥àÇÛÎó
59$arrRegistColumn = array(
60                             array(  "column" => "name01",      "convert" => "aKV" ),
61                             array(  "column" => "name02",      "convert" => "aKV" ),
62                             array(  "column" => "kana01",      "convert" => "CKV" ),
63                             array(  "column" => "kana02",      "convert" => "CKV" ),
64                             array(  "column" => "zip01",       "convert" => "n" ),
65                             array(  "column" => "zip02",       "convert" => "n" ),
66                             array(  "column" => "pref",        "convert" => "n" ),
67                             array(  "column" => "addr01",      "convert" => "aKV" ),
68                             array(  "column" => "addr02",      "convert" => "aKV" ),
69                             array(  "column" => "email",       "convert" => "a" ),
70                             array(  "column" => "tel01",       "convert" => "n" ),
71                             array(  "column" => "tel02",       "convert" => "n" ),
72                             array(  "column" => "tel03",       "convert" => "n" ),
73                             array(  "column" => "fax01",       "convert" => "n" ),
74                             array(  "column" => "fax02",       "convert" => "n" ),
75                             array(  "column" => "fax03",       "convert" => "n" ),
76                             array(  "column" => "sex",         "convert" => "n" ),
77                             array(  "column" => "job",         "convert" => "n" ),
78                             array(  "column" => "birth",       "convert" => "n" ),
79                             array(  "column" => "password",    "convert" => "a" ),
80                             array(  "column" => "reminder",    "convert" => "n" ),
81                             array(  "column" => "reminder_answer", "convert" => "aKV" ),
82                             array(  "column" => "note",        "convert" => "aKV" ),
83                             array(  "column" => "point",       "convert" => "n" ),
84                             array(  "column" => "status",      "convert" => "n" )
85                         );
86
87//---- ÅÐÏ¿½ü³°ÍÑ¥«¥é¥àÇÛÎó
88$arrRejectRegistColumn = array("year", "month", "day");
89
90// ¸¡º÷¾ò·ï¤òÊÝ»ý
91if ($_POST['mode'] == "edit_search") {
92    $arrSearch = $_POST;
93}else{
94    $arrSearch = $_POST['search_data'];
95}
96if(is_array($arrSearch)){
97    foreach($arrSearch as $key => $val){
98        $arrSearchData[$key] = $val;
99    }
100}
101
102$objPage->arrSearchData= $arrSearchData;
103
104//----¡¡¸ÜµÒÊÔ½¸¾ðÊó¼èÆÀ
105if (($_POST["mode"] == "edit" || $_POST["mode"] == "edit_search") && is_numeric($_POST["edit_customer_id"])) {
106
107    //--¡¡¸ÜµÒ¥Ç¡¼¥¿¼èÆÀ
108    $sql = "SELECT A.*, B.mail_flag FROM dtb_customer AS A LEFT OUTER JOIN dtb_customer_mail AS B USING(email)
109             WHERE A.del_flg = 0 AND A.customer_id = ?";
110    $result = $objConn->getAll($sql, array($_POST["edit_customer_id"]));
111    $objPage->list_data = $result[0];
112   
113    $birth = split(" ", $objPage->list_data["birth"]);
114    $birth = split("-",$birth[0]);
115   
116    $objPage->list_data["year"] = $birth[0];
117    $objPage->list_data["month"] = $birth[1];
118    $objPage->list_data["day"] = $birth[2];
119   
120    $objPage->list_data["password"] = DEFAULT_PASSWORD;
121    //DBÅÐÏ¿¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤òÅϤ¹
122    $objPage->tpl_edit_email = $result[0]['email'];
123    //¹ØÆþÍúÎò¾ðÊó¤Î¼èÆÀ
124    $objPage->arrPurchaseHistory = lfPurchaseHistory($_POST['edit_customer_id']);
125    // »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
126    $objPage->arrPayment = sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
127}
128
129//----¡¡¸ÜµÒ¾ðÊóÊÔ½¸
130if ( $_POST["mode"] != "edit" && $_POST["mode"] != "edit_search" && is_numeric($_POST["customer_id"])) {
131
132    //-- POST¥Ç¡¼¥¿¤Î°ú¤­·Ñ¤®
133    $objPage->arrForm = $_POST;
134    $objPage->arrForm['email'] = strtolower($objPage->arrForm['email']);        // email¤Ï¤¹¤Ù¤Æ¾®Ê¸»ú¤Ç½èÍý
135
136    //-- ÆþÎϥǡ¼¥¿¤ÎÊÑ´¹
137    $objPage->arrForm = lfConvertParam($objPage->arrForm, $arrRegistColumn);
138    //-- ÆþÎÏ¥Á¥§¥Ã¥¯
139    $objPage->arrErr = lfErrorCheck($objPage->arrForm);
140
141    //-- ÆþÎÏ¥¨¥é¡¼È¯À¸ or ¥ê¥¿¡¼¥ó»þ
142    if ($objPage->arrErr || $_POST["mode"] == "return") {
143        foreach($objPage->arrForm as $key => $val) {
144            $objPage->list_data[ $key ] = $val;
145        }
146        //¹ØÆþÍúÎò¾ðÊó¤Î¼èÆÀ
147        $objPage->arrPurchaseHistory = lfPurchaseHistory($_POST['customer_id']);
148        // »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
149        $objPage->arrPayment = sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
150       
151    } else {
152        //-- ³Îǧ
153        if ($_POST["mode"] == "confirm") {
154            $objPage->tpl_mainpage = 'customer/edit_confirm.tpl';
155            $passlen = strlen($objPage->arrForm['password']);
156            $objPage->passlen = lfPassLen($passlen);
157           
158        }
159        //--¡¡ÊÔ½¸
160        if($_POST["mode"] == "complete") {
161            $objPage->tpl_mainpage = 'customer/edit_complete.tpl';
162           
163            // ¸½ºß¤Î²ñ°÷¾ðÊó¤ò¼èÆÀ¤¹¤ë
164            $arrCusSts = $objQuery->getOne("SELECT status FROM dtb_customer WHERE customer_id = ?", array($_POST["customer_id"]));
165
166            // ²ñ°÷¾ðÊó¤¬Êѹ¹¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï¥·¡¼¥¯¥ì¥Ã¥È¢ñ¤â¹¹¿·¤¹¤ë¡£
167            if ($arrCusSts != $_POST['status']){
168                $secret = sfGetUniqRandomId("r");
169                $objPage->arrForm['secret_key'] = $secret;
170                array_push($arrRegistColumn, array('column' => 'secret_key', 'convert' => 'n'));
171            }
172            //-- ÊÔ½¸ÅÐÏ¿
173            sfEditCustomerData($objPage->arrForm, $arrRegistColumn);
174        }
175    }
176}
177
178//----¡¡¥Ú¡¼¥¸É½¼¨
179$objView->assignobj($objPage);
180$objView->display(MAIN_FRAME);
181
182
183
184//-------------- function
185
186// ÊÔ½¸ÅÐÏ¿
187function lfRegisDatat($array, $arrRegistColumn) {
188    global $objConn;
189    global $objQuery;
190    foreach ($arrRegistColumn as $data) {
191        if($array[$data["column"]] != "") {
192            $arrRegist[$data["column"]] = $array[$data["column"]];
193        } else {
194            $arrRegist[$data["column"]] = NULL;
195        }
196    }
197    if (strlen($array["year"]) > 0) {
198        $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
199    }
200
201    //-- ¥Ñ¥¹¥ï¡¼¥É¤Î¹¹¿·¤¬¤¢¤ë¾ì¹ç¤Ï°Å¹æ²½¡£¡Ê¹¹¿·¤¬¤Ê¤¤¾ì¹ç¤ÏUPDATEʸ¤ò¹½À®¤·¤Ê¤¤¡Ë
202    if ($array["password"] != DEFAULT_PASSWORD) {
203        $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
204    } else {
205        unset($arrRegist['password']);
206    }
207
208    $arrRegist["update_date"] = "Now()";
209    $arrRegistMail["update_date"] = "Now()";
210    $arrRegistMail["mail_flag"] = $array["mail_flag"];
211    $arrRegistMail['email'] = $array['email'];
212    //-- ÊÔ½¸ÅÐÏ¿¼Â¹Ô
213    $objConn->query("BEGIN");
214    $objQuery->Insert("dtb_customer", $arrRegist, "customer_id = '" .addslashes($array["customer_id"]). "'");
215   
216    //-- ¥á¥ë¥Þ¥¬ÅÐÏ¿
217    $mailmaga = $objQuery->getAll("SELECT * FROM dtb_customer_mail WHERE email = ?", $array["edit_email"]);
218   
219    if(count($mailmaga) > 0 ){
220        $objQuery->Update("dtb_customer_mail", $arrRegistMail, "email = '" .addslashes($array["edit_email"]). "'");
221    }else{
222        $arrRegistMail["create_date"] = "Now()";
223        //$arrRegist["create_date"] = date( "Y/m/d H:i:s", time());
224        $objQuery->Insert("dtb_customer_mail", $arrRegistMail);
225    }
226    $objConn->query("COMMIT");
227}
228
229
230//----¡¡¼èÆÀʸ»úÎó¤ÎÊÑ´¹
231function lfConvertParam($array, $arrRegistColumn) {
232    /*
233     *  ʸ»úÎó¤ÎÊÑ´¹
234     *  K :  ¡ÖȾ³Ñ(ŽÊŽÝŽ¶Ž¸)ÊÒ²¾Ì¾¡×¤ò¡ÖÁ´³ÑÊÒ²¾Ì¾¡×¤ËÊÑ´¹
235     *  C :  ¡ÖÁ´³Ñ¤Ò¤é²¾Ì¾¡×¤ò¡ÖÁ´³Ñ¤«¤¿²¾Ì¾¡×¤ËÊÑ´¹
236     *  V :  ÂùÅÀÉÕ¤­¤Îʸ»ú¤ò°ìʸ»ú¤ËÊÑ´¹¡£"K","H"¤È¶¦¤Ë»ÈÍѤ·¤Þ¤¹ 
237     *  n :  ¡ÖÁ´³Ñ¡×¿ô»ú¤ò¡ÖȾ³Ñ(ŽÊŽÝŽ¶Ž¸)¡×¤ËÊÑ´¹
238     *  a :  Á´³Ñ±Ñ¿ô»ú¤òȾ³Ñ±Ñ¿ô»ú¤ËÊÑ´¹¤¹¤ë
239     */
240    // ¥«¥é¥à̾¤È¥³¥ó¥Ð¡¼¥È¾ðÊó
241    foreach ($arrRegistColumn as $data) {
242        $arrConvList[ $data["column"] ] = $data["convert"];
243    }
244    // ʸ»úÊÑ´¹
245    foreach ($arrConvList as $key => $val) {
246        // POST¤µ¤ì¤Æ¤­¤¿ÃͤΤßÊÑ´¹¤¹¤ë¡£
247        if(strlen(($array[$key])) > 0) {
248            $array[$key] = mb_convert_kana($array[$key] ,$val);
249        }
250    }
251    return $array;
252}
253
254//---- ÆþÎÏ¥¨¥é¡¼¥Á¥§¥Ã¥¯
255function lfErrorCheck($array) {
256
257    global $objConn;
258    $objErr = new SC_CheckError($array);
259
260    $objErr->doFunc(array("²ñ°÷¾õÂÖ", 'status'), array("EXIST_CHECK"));
261    $objErr->doFunc(array("¤ªÌ¾Á°¡ÊÀ«¡Ë", 'name01', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
262    $objErr->doFunc(array("¤ªÌ¾Á°¡Ê̾¡Ë", 'name02', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
263    $objErr->doFunc(array("¥Õ¥ê¥¬¥Ê¡ÊÀ«¡Ë", 'kana01', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
264    $objErr->doFunc(array("¥Õ¥ê¥¬¥Ê¡Ê̾¡Ë", 'kana02', STEXT_LEN), array("EXIST_CHECK", "MAX_LENGTH_CHECK", "KANA_CHECK"));
265    $objErr->doFunc(array("͹ÊØÈÖ¹æ1", "zip01", ZIP01_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
266    $objErr->doFunc(array("͹ÊØÈÖ¹æ2", "zip02", ZIP02_LEN ) ,array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
267    $objErr->doFunc(array("͹ÊØÈÖ¹æ", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
268    $objErr->doFunc(array("ÅÔÆ»Éܸ©", 'pref'), array("SELECT_CHECK","NUM_CHECK"));
269    $objErr->doFunc(array("¤´½»½ê¡Ê1¡Ë", "addr01", MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
270    $objErr->doFunc(array("¤´½»½ê¡Ê2¡Ë", "addr02", MTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
271    $objErr->doFunc(array('¥á¡¼¥ë¥¢¥É¥ì¥¹', "email", MTEXT_LEN) ,array("EXIST_CHECK", "NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
272   
273    //¸½²ñ°÷¤ÎȽÄê ¢ª¡¡¸½²ñ°÷¤â¤·¤¯¤Ï²¾ÅÐÏ¿Ãæ¤Ï¡¢¥á¥¢¥É°ì°Õ¤¬Á°Äó¤Ë¤Ê¤Ã¤Æ¤ë¤Î¤ÇƱ¤¸¥á¥¢¥É¤ÇÅÐÏ¿ÉÔ²Ä
274    if (strlen($array["email"]) > 0) {
275        $sql = "SELECT customer_id FROM dtb_customer WHERE email ILIKE ? escape '#' AND (status = 1 OR status = 2) AND del_flg = 0 AND customer_id <> ?";
276        $checkMail = ereg_replace( "_", "#_", $array["email"]);
277        $result = $objConn->getAll($sql, array($checkMail, $array["customer_id"]));
278        if (count($result) > 0) {
279            $objErr->arrErr["email"] .= "¢¨ ¤¹¤Ç¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¥á¡¼¥ë¥¢¥É¥ì¥¹¤Ç¤¹¡£";
280        }
281    }
282   
283    $objErr->doFunc(array('¥á¡¼¥ë¥¢¥É¥ì¥¹(¥â¥Ð¥¤¥ë)', "email_mobile", MTEXT_LEN) ,array("EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
284    $objErr->doFunc(array("¤ªÅÅÏÃÈÖ¹æ1", 'tel01'), array("EXIST_CHECK"));
285    $objErr->doFunc(array("¤ªÅÅÏÃÈÖ¹æ2", 'tel02'), array("EXIST_CHECK"));
286    $objErr->doFunc(array("¤ªÅÅÏÃÈÖ¹æ3", 'tel03'), array("EXIST_CHECK"));
287    $objErr->doFunc(array("¤ªÅÅÏÃÈÖ¹æ", "tel01", "tel02", "tel03", TEL_LEN) ,array("TEL_CHECK"));
288    $objErr->doFunc(array("FAXÈÖ¹æ", "fax01", "fax02", "fax03", TEL_LEN) ,array("TEL_CHECK"));
289    $objErr->doFunc(array("¤´À­ÊÌ", "sex") ,array("SELECT_CHECK", "NUM_CHECK"));
290    $objErr->doFunc(array("¤´¿¦¶È", "job") ,array("NUM_CHECK"));
291    if ($array["password"] != DEFAULT_PASSWORD) {
292        $objErr->doFunc(array("¥Ñ¥¹¥ï¡¼¥É", 'password', PASSWORD_LEN1, PASSWORD_LEN2), array("EXIST_CHECK", "ALNUM_CHECK", "NUM_RANGE_CHECK"));
293    }
294    $objErr->doFunc(array("¥Ñ¥¹¥ï¡¼¥É¤ò˺¤ì¤¿¤È¤­¤Î¥Ò¥ó¥È ¼ÁÌä", "reminder") ,array("SELECT_CHECK", "NUM_CHECK"));
295    $objErr->doFunc(array("¥Ñ¥¹¥ï¡¼¥É¤ò˺¤ì¤¿¤È¤­¤Î¥Ò¥ó¥È Åú¤¨", "reminder_answer", STEXT_LEN) ,array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
296    $objErr->doFunc(array("¥á¡¼¥ë¥Þ¥¬¥¸¥ó", "mail_flag") ,array("SELECT_CHECK", "NUM_CHECK"));
297    $objErr->doFunc(array("À¸Ç¯·îÆü", "year", "month", "day"), array("CHECK_DATE"));
298    $objErr->doFunc(array("¥á¡¼¥ë¥Þ¥¬¥¸¥ó", 'mail_flag'), array("SELECT_CHECK"));
299    $objErr->doFunc(array("SHOPÍÑ¥á¥â", 'note', LTEXT_LEN), array("MAX_LENGTH_CHECK"));
300    $objErr->doFunc(array("½ê»ý¥Ý¥¤¥ó¥È", "point", TEL_LEN) ,array("MAX_LENGTH_CHECK", "NUM_CHECK"));
301    return $objErr->arrErr;
302   
303}
304
305//¹ØÆþÍúÎò¾ðÊó¤Î¼èÆÀ
306function lfPurchaseHistory($customer_id){
307        global $objQuery;
308        global $objPage;
309       
310        $objPage->tpl_pageno = $_POST['search_pageno'];
311        $objPage->edit_customer_id = $customer_id;
312
313        // ¥Ú¡¼¥¸Á÷¤ê¤Î½èÍý
314        $page_max = SEARCH_PMAX;
315        //¹ØÆþÍúÎò¤Î·ï¿ô¼èÆÀ
316        $objPage->tpl_linemax = $objQuery->count("dtb_order","customer_id=? AND del_flg = 0 ", array($customer_id));
317        $linemax = $objPage->tpl_linemax;
318       
319        // ¥Ú¡¼¥¸Á÷¤ê¤Î¼èÆÀ
320        $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchPage2", NAVI_PMAX);
321        $objPage->arrPagenavi = $objNavi->arrPagenavi;
322        $objPage->arrPagenavi['mode'] = 'edit';
323        $startno = $objNavi->start_row;
324       
325        // ¼èÆÀÈϰϤλØÄê(³«»Ï¹ÔÈֹ桢¹Ô¿ô¤Î¥»¥Ã¥È)
326        $objQuery->setlimitoffset($page_max, $startno);
327        // ɽ¼¨½ç½ø
328        $order = "order_id DESC";
329        $objQuery->setorder($order);
330        //¹ØÆþÍúÎò¾ðÊó¤Î¼èÆÀ
331        $arrPurchaseHistory = $objQuery->select("*", "dtb_order", "customer_id=? AND del_flg = 0 ", array($customer_id));
332       
333        return $arrPurchaseHistory;
334}
335
336//³Îǧ¥Ú¡¼¥¸Íѥѥ¹¥ï¡¼¥Éɽ¼¨ÍÑ
337
338function lfPassLen($passlen){
339    $ret = "";
340    for ($i=0;$i<$passlen;true){
341        $ret.="*";
342        $i++;
343    }
344    return $ret;
345}
346
347
348?>
Note: See TracBrowser for help on using the repository browser.