source: temp/trunk/html/admin/mail/htmlmail.php @ 1328

Revision 1328, 10.5 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3require_once("../require.php");
4
5class LC_Page {
6   
7    var $arrForm;
8   
9    var $arrTempProduct;
10    var $subProductNum;
11    var $arrFileName;
12   
13   
14    function LC_Page() {
15        $this->tpl_mainpage = 'mail/htmlmail.tpl';
16        $this->tpl_mainno = 'mail';
17        $this->tpl_subnavi = 'mail/subnavi.tpl';
18        $this->tpl_subno = "template";
19    }
20}
21
22
23class LC_Products{
24   
25    var $conn;
26    var $arrProduct;
27    var $arrProductKey;
28   
29    function LC_Products ($conn=""){
30       
31        $DB_class_name = "SC_DbConn";
32        if ( is_object($conn)){
33            if ( is_a($conn, $DB_class_name)){
34                // $conn¤¬$DB_class_name¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤Ç¤¢¤ë
35                $this->conn = $conn;
36            }
37        } else {
38            if (class_exists($DB_class_name)){
39                //$DB_class_name¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òºîÀ®¤¹¤ë
40                $this->conn = new SC_DbConn();         
41            }
42        }
43    }
44   
45    function setProduct($keyname, $id) {
46       
47        if ( sfCheckNumLength($id) ){
48            $result = $this->getProductData($id);
49        }
50       
51        if ( $result && (in_array($keyname, $this->arrProductKey) ) ){
52   
53            $this->arrProduct["${keyname}"] = $result;
54        }
55    }   
56   
57    function getProductData($id){
58        $conn = $this->conn;
59        // ¾¦ÉʾðÊó¤ò¼èÆÀ¤¹¤ë
60        $sql = "SELECT * FROM dtb_products WHERE product_id = ?";
61        $result = $conn->getAll($sql, array($id));
62        if ( is_array($result) ){
63            $return = $result[0];
64        }
65        return $return;
66    }
67
68    function getProductImageData($id){
69        $conn = $this->conn;
70        // ¾¦ÉʲèÁü¾ðÊó¤ò¼èÆÀ¤¹¤ë
71        $sql = "SELECT main_image FROM dtb_products WHERE product_id = ?";
72        $result = $conn->getAll($sql, array($id));
73        if ( is_array($result) ){
74            $return = $result[0]["main_image"];
75        }
76        return $return;
77    }
78    function setHiddenList($arrPOST) {
79        foreach($this->arrProductKey as $val) {
80            $key = "temp_" . $val;
81            if($arrPOST[$key] != "") {
82                $this->setProduct($val, $arrPOST[$key]);
83            }
84        }
85    }
86}
87
88// ÅÐÏ¿¥«¥é¥à
89$arrRegist = array(
90                      "subject", "charge_image", "mail_method", "header", "main_title", "main_comment", "main_product_id", "sub_title", "sub_comment"
91                    , "sub_product_id01", "sub_product_id02", "sub_product_id03", "sub_product_id04", "sub_product_id05", "sub_product_id06", "sub_product_id07"
92                    , "sub_product_id08", "sub_product_id09", "sub_product_id10", "sub_product_id11", "sub_product_id12"
93                    );
94                   
95// ´û¸¤ÎÅÐÏ¿ºÑ¤ß¾¦Éʤ«¤é²èÁüɽ¼¨¤òɬÍפȤ¹¤ë¹àÌܥꥹ¥È                 
96$arrFileList = array(
97                        "main_product_id", "sub_product_id01", "sub_product_id02", "sub_product_id03", "sub_product_id04", "sub_product_id05"
98                        , "sub_product_id06", "sub_product_id07", "sub_product_id08", "sub_product_id09", "sub_product_id10", "sub_product_id11", "sub_product_id12"
99                    );
100
101$conn = new SC_DBConn();
102$objPage = new LC_Page();
103$objView = new SC_AdminView();
104$objSess = new SC_Session();
105$objQuery = new SC_Query();
106
107// ǧ¾Ú²ÄÈݤÎȽÄê
108sfIsSuccess($objSess);
109
110
111// ²èÁü½èÍý¥¯¥é¥¹ÀßÄê
112$objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
113$objUpFile->addFile("¥á¡¼¥ëôÅö¼Ì¿¿", 'charge_image', array('jpg'),IMAGE_SIZE, true, HTMLMAIL_IMAGE_WIDTH, HTMLMAIL_IMAGE_HEIGHT);
114
115// POSTÃͤΰú·Ñ¤®&ÆþÎÏÃͤÎÊÑ´¹
116$objPage->arrForm = lfConvData($_POST);
117
118// Hidden¤«¤é¤Î¥Ç¡¼¥¿¤ò°ú¤­·Ñ¤°
119$objUpFile->setHiddenFileList($_POST);
120
121switch ($_POST['mode']){
122   
123    //²èÁü¥¢¥Ã¥×¥í¡¼¥É
124    case 'upload_image':
125    // ²èÁüÊݸ½èÍý
126    $objPage->arrErr[$_POST['image_key']] = $objUpFile->makeTempFile($_POST['image_key']);
127    break;
128   
129    //³Îǧ
130    case 'confirm':
131   
132    // ¥¨¥é¡¼¥Á¥§¥Ã¥¯
133    $objPage->arrErr = lfErrorCheck($objPage->arrForm);
134    //¥Õ¥¡¥¤¥ë¸ºß¥Á¥§¥Ã¥¯
135    $objPage->arrErr = array_merge((array)$objPage->arrErr, (array)$objUpFile->checkEXISTS());
136       
137    //¥¨¥é¡¼¤Ê¤·¤Î¾ì¹ç¡¢³Îǧ¥Ú¡¼¥¸¤Ø
138     if (!$objPage->arrErr){
139        //  ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë¾ðÊóÇÛÎó¤òÅϤ¹¡£
140        $objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
141        //ºï½üÍ×µá¤Î¤¢¤Ã¤¿²èÁü¤òɽ¼¨¤·¤Ê¤¤
142        for($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++) {
143            if($_POST['delete_sub'.$i] == "1") {
144                $arrSub['delete'][$i] = "on";
145            }else{
146                $arrSub['delete'][$i] = "";
147            }
148        }
149        $objPage->arrSub = $arrSub;
150        $objPage->tpl_mainpage = 'mail/htmlmail_confirm.tpl';
151     }
152    break;
153   
154    // ³Îǧ¥Ú¡¼¥¸¤«¤é¤ÎÌá¤ê
155    case 'return':
156    break;
157   
158    //¡¡¥Æ¥ó¥×¥ì¡¼¥ÈÅÐÏ¿
159    case 'complete':
160    // ÆþÎÏÃͤÎÊÑ´¹
161    $objPage->arrForm = lfConvData($_POST);
162    $objPage->arrErr = lfErrorCheck($objPage->arrForm); // ÆþÎÏ¥¨¥é¡¼¥Á¥§¥Ã¥¯
163
164    // ¥¢¥Ã¥×¥í¡¼¥É²èÁü¤ò¥»¡¼¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¹Ô
165    $objUpFile->moveTempFile();
166
167    // DBÅÐÏ¿
168    if (is_numeric($objPage->arrForm["template_id"])) { //¡¡ÊÔ½¸»þ
169        lfUpdateData($arrRegist);
170    } else {
171        ifRegistData($arrRegist);
172    }
173    $objPage->tpl_mainpage = 'mail/htmlmail_complete.tpl';
174    break;
175}
176
177// ¸¡º÷·ë²Ì¤«¤é¤ÎÊÔ½¸»þ
178if ($_GET["mode"] == "edit" && is_numeric($_GET["template_id"])) {
179    $objPage->edit_mode = "on";
180    //¥Æ¥ó¥×¥ì¡¼¥È¾ðÊóÆÉ¤ß¹þ¤ß
181    lfSetRegistData($_GET["template_id"]);
182    // DB¥Ç¡¼¥¿¤«¤é²èÁü¥Õ¥¡¥¤¥ë̾¤ÎÆÉ¹þ
183    $objUpFile->setDBFileList($objPage->arrForm);
184
185}
186
187if ($_GET['mode'] != 'edit'){
188//ÅÐÏ¿¾ðÊó¤ÎÆÉ¤ß¹þ¤ß
189$objPage->arrFileName = lfGetProducts();
190}
191
192// HIDDENÍѤËÇÛÎó¤òÅϤ¹¡£
193$objPage->arrHidden = array_merge((array)$objPage->arrHidden, (array)$objUpFile->getHiddenFileList());
194// ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë¾ðÊóÇÛÎó¤òÅϤ¹¡£
195$objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
196
197$objView->assignobj($objPage);
198$objView->display(MAIN_FRAME);
199
200//-------------------------------------------------------------------------------------------------------------------------
201
202/* ¾¦ÉʲèÁü¤ÎÆÉ¤ß¹þ¤ß */
203function lfGetProducts() {
204    global $objQuery;
205   
206    if ($_POST['main_product_id'] != ""){
207    $MainFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($_POST['main_product_id']));
208    $arrFileName[0] = $MainFile[0];
209    }
210    for($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++) {
211        $sub_keyname = "sub_product_id" . sprintf("%02d", $i);
212        if($_POST[$sub_keyname] != "") {
213            $arrSubFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id = ?", array($_POST[$sub_keyname]));
214            $arrFileName[$i] = $arrSubFile[0];
215        }
216    }
217    return $arrFileName;
218}
219
220/* ÅÐÏ¿ºÑ¤ß¥Ç¡¼¥¿ÆÉ¤ß¹þ¤ß */
221function lfSetRegistData($template_id) {
222    global $objQuery;
223    global $objPage;
224    $arrRet = $objQuery->select("*", "dtb_mailmaga_template", "template_id=?", array($template_id));
225    $arrProductid = $arrRet[0];
226    //²èÁü°Ê³°¤Î¾ðÊó¼èÆÀ
227    $objPage->arrForm = $arrRet[0];
228        if ($arrProductid['main_product_id'] != ""){
229            $MainFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($arrProductid['main_product_id']));
230            $arrFileName[0] = $MainFile[0];
231        }
232    for ($i=1; $i<=HTML_TEMPLATE_SUB_MAX; $i++){
233        if ($arrProductid['sub_product_id'.sprintf("%02d", $i)] != ""){
234            $arrSubFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($arrProductid['sub_product_id'.sprintf("%02d", $i)]));
235            $arrFileName[$i] = $arrSubFile[0];
236        }
237    }
238    //²èÁü¤Î¾ðÊó¼èÆÀ
239    $objPage->arrFileName = $arrFileName;
240   
241    return $objPage;
242}
243
244// ÊÔ½¸¥Ç¡¼¥¿¼èÆÀ
245function lfGetEditData($id, $arrIdData) {
246    global $conn;
247
248    // DBÅÐÏ¿¾ðÊó
249    $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ? AND delete = 0";
250    $result = $conn->getAll($sql, array($id));
251
252    //¡¡²èÁü¥Õ¥¡¥¤¥ë̾
253    for ($i = 0; $i < count($arrIdData); $i ++) {
254        $data = "";
255        if (is_numeric($result[0][ $arrIdData[$i] ]) ) {
256            $sql = "SELECT name,product_id,main_image FROM dtb_products WHERE product_id = ?";
257            $data = $conn->getAll($sql, array($result[0][ $arrIdData[$i] ]));
258        }
259        $arrFileName[] = $data[0];
260    }
261   
262    return array($result[0], $arrFileName);
263}
264
265// ³Îǧ¥Ç¡¼¥¿¼èÆÀ
266function lfGetConfirmData($arrPOST, $arrIdData) {
267    global $conn;
268    //¡¡²èÁü¥Õ¥¡¥¤¥ë̾
269    for ($i = 0; $i < count($arrIdData); $i ++) {
270        $data = "";
271        if (is_numeric($arrPOST[ $arrIdData[$i] ]) ) {
272            $sql = "SELECT name,product_id,main_image FROM dtb_products WHERE product_id = ?";
273            $data = $conn->getAll($sql, array($arrPOST[ $arrIdData[$i] ]));
274        }
275        $arrFileName[] = $data[0];
276    }
277    return array($arrPOST, $arrFileName);
278}
279
280// ¥Ç¡¼¥¿¥Ù¡¼¥¹ÅÐÏ¿
281function ifRegistData($arrRegist) {
282    global $conn;
283    global $objUpFile;
284
285    foreach ($arrRegist as $data) {
286        if (strlen($_POST[$data]) > 0) {
287            $arrRegistValue[$data] = $_POST[$data];
288        }
289    }
290    $arrRegistValue["creator_id"] = $_SESSION["member_id"];     // ÅÐÏ¿¼ÔID¡Ê´ÉÍý²èÌÌ¡Ë
291    $uploadfile = $objUpFile->getDBFileList();
292    //ºï½üÍ×µá¤Î¤¢¤Ã¤¿¾¦Éʤòºï½ü¤¹¤ë
293    for ($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++){
294        if ($_POST['delete_sub'.$i] == '1'){
295            $arrRegistValue['sub_product_id'.sprintf("%02d", $i)] = NULL;
296        }
297    }
298    $arrRegistValue = array_merge($arrRegistValue, $uploadfile);
299    $conn->autoExecute("dtb_mailmaga_template", $arrRegistValue);
300}
301
302// ¥Ç¡¼¥¿¹¹¿·
303function lfUpdateData($arrRegist) {
304    global $conn;
305    global $objUpFile;
306
307    foreach ($arrRegist as $data) {
308        if (strlen($_POST[$data]) > 0) {
309            $arrRegistValue[$data] = $_POST[$data];
310        }
311    }
312    $arrRegistValue["creator_id"] = $_SESSION["member_id"];
313    $arrRegistValue["update_date"] = "NOW()";
314    $uploadfile = $objUpFile->getDBFileList();
315    //ºï½üÍ×µá¤Î¤¢¤Ã¤¿¾¦Éʤòºï½ü¤¹¤ë
316    for ($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++){
317        if ($_POST['delete_sub'.$i] == '1'){
318            $arrRegistValue['sub_product_id'.sprintf("%02d", $i)] = NULL;
319        }
320    }
321    $arrRegistValue = array_merge($arrRegistValue, $uploadfile);
322   
323    $conn->autoExecute("dtb_mailmaga_template", $arrRegistValue, "template_id = ". addslashes($_POST["template_id"]));
324}
325
326// ÆþÎÏÃÍÊÑ´¹
327function lfConvData( $data ){
328   
329     // ʸ»úÎó¤ÎÊÑ´¹¡Êmb_convert_kana¤ÎÊÑ´¹¥ª¥×¥·¥ç¥ó¡Ë                         
330    $arrFlag = array(
331                      "header" => "aKV"
332                     ,"subject" => "aKV"
333                     ,"main_title" => "aKV"
334                     ,"main_comment" => "aKV"
335                     ,"main_product_id" => "aKV"
336                     ,"sub_title" => "aKV"
337                     ,"sub_comment" => "aKV"
338                );
339       
340    if ( is_array($data) ){
341        foreach ($arrFlag as $key=>$line) {
342            $data[$key] = mb_convert_kana($data[$key], $line);
343        }
344    }
345
346    return $data;
347}
348
349// ÆþÎÏ¥¨¥é¡¼¥Á¥§¥Ã¥¯
350function lfErrorCheck($array) {
351    $objErr = new SC_CheckError($array);
352   
353    $objErr->doFunc(array("¥á¡¼¥ë·Á¼°", "mail_method"), array("EXIST_CHECK", "ALNUM_CHECK"));
354    $objErr->doFunc(array("Subject", "subject", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
355    $objErr->doFunc(array("¥Ø¥Ã¥À¡¼¥Æ¥­¥¹¥È", 'header', LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK") );
356    $objErr->doFunc(array("¥á¥¤¥ó¾¦ÉÊ¥¿¥¤¥È¥ë", 'main_title', STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK") );
357    $objErr->doFunc(array("¥á¥¤¥ó¾¦ÉÊ¥³¥á¥ó¥È", 'main_comment', LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
358    $objErr->doFunc(array("¥á¥¤¥ó¾¦ÉʲèÁü", "main_product_id"), array("EXIST_CHECK"));
359    $objErr->doFunc(array("¥µ¥Ö¾¦ÉÊ·²¥¿¥¤¥È¥ë", "sub_title", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
360    $objErr->doFunc(array("¥µ¥Ö¾¦ÉÊ·²¥³¥á¥ó¥È", "sub_comment", LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
361   
362    return $objErr->arrErr;
363}
364
365?>
Note: See TracBrowser for help on using the repository browser.