source: branches/feature-module-update/html/admin/mail/htmlmail.php @ 15532

Revision 15532, 11.1 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type 修正

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/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   
11    var $arrForm;
12   
13    var $arrTempProduct;
14    var $subProductNum;
15    var $arrFileName;
16   
17   
18    function LC_Page() {
19        $this->tpl_mainpage = 'mail/htmlmail.tpl';
20        $this->tpl_mainno = 'mail';
21        $this->tpl_subnavi = 'mail/subnavi.tpl';
22        $this->tpl_subno = "template";
23    }
24}
25
26
27class LC_Products{
28   
29    var $conn;
30    var $arrProduct;
31    var $arrProductKey;
32   
33    function LC_Products ($conn=""){
34       
35        $DB_class_name = "SC_DbConn";
36        if ( is_object($conn)){
37            if ( is_a($conn, $DB_class_name)){
38                // $connが$DB_class_nameのインスタンスである
39                $this->conn = $conn;
40            }
41        } else {
42            if (class_exists($DB_class_name)){
43                //$DB_class_nameのインスタンスを作成する
44                $this->conn = new SC_DbConn();         
45            }
46        }
47    }
48   
49    function setProduct($keyname, $id) {
50       
51        if ( sfCheckNumLength($id) ){
52            $result = $this->getProductData($id);
53        }
54       
55        if ( $result && (in_array($keyname, $this->arrProductKey) ) ){
56   
57            $this->arrProduct["${keyname}"] = $result;
58        }
59    }   
60   
61    function getProductData($id){
62        $conn = $this->conn;
63        // 商品情報を取得する
64        $sql = "SELECT * FROM dtb_products WHERE product_id = ?";
65        $result = $conn->getAll($sql, array($id));
66        if ( is_array($result) ){
67            $return = $result[0];
68        }
69        return $return;
70    }
71
72    function getProductImageData($id){
73        $conn = $this->conn;
74        // 商品画像情報を取得する
75        $sql = "SELECT main_image FROM dtb_products WHERE product_id = ?";
76        $result = $conn->getAll($sql, array($id));
77        if ( is_array($result) ){
78            $return = $result[0]["main_image"];
79        }
80        return $return;
81    }
82    function setHiddenList($arrPOST) {
83        foreach($this->arrProductKey as $val) {
84            $key = "temp_" . $val;
85            if($arrPOST[$key] != "") {
86                $this->setProduct($val, $arrPOST[$key]);
87            }
88        }
89    }
90}
91
92// 登録カラム
93$arrRegist = array(
94                      "subject", "charge_image", "mail_method", "header", "main_title", "main_comment", "main_product_id", "sub_title", "sub_comment"
95                    , "sub_product_id01", "sub_product_id02", "sub_product_id03", "sub_product_id04", "sub_product_id05", "sub_product_id06", "sub_product_id07"
96                    , "sub_product_id08", "sub_product_id09", "sub_product_id10", "sub_product_id11", "sub_product_id12"
97                    );
98                   
99// 既存の登録済み商品から画像表示を必要とする項目リスト                   
100$arrFileList = array(
101                        "main_product_id", "sub_product_id01", "sub_product_id02", "sub_product_id03", "sub_product_id04", "sub_product_id05"
102                        , "sub_product_id06", "sub_product_id07", "sub_product_id08", "sub_product_id09", "sub_product_id10", "sub_product_id11", "sub_product_id12"
103                    );
104
105$conn = new SC_DBConn();
106$objPage = new LC_Page();
107$objView = new SC_AdminView();
108$objSess = new SC_Session();
109$objQuery = new SC_Query();
110
111// 認証可否の判定
112sfIsSuccess($objSess);
113
114
115// 画像処理クラス設定
116$objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
117$objUpFile->addFile("メール担当写真", 'charge_image', array('jpg'),IMAGE_SIZE, true, HTMLMAIL_IMAGE_WIDTH, HTMLMAIL_IMAGE_HEIGHT);
118
119// POST値の引継ぎ&入力値の変換
120$objPage->arrForm = lfConvData($_POST);
121
122// Hiddenからのデータを引き継ぐ
123$objUpFile->setHiddenFileList($_POST);
124
125switch ($_POST['mode']){
126   
127    //画像アップロード
128    case 'upload_image':
129    // 画像保存処理
130    $objPage->arrErr[$_POST['image_key']] = $objUpFile->makeTempFile($_POST['image_key']);
131    break;
132   
133    //確認
134    case 'confirm':
135   
136    // エラーチェック
137    $objPage->arrErr = lfErrorCheck($objPage->arrForm);
138    //ファイル存在チェック
139    $objPage->arrErr = array_merge((array)$objPage->arrErr, (array)$objUpFile->checkEXISTS());
140       
141    //エラーなしの場合、確認ページへ
142     if (!$objPage->arrErr){
143        //  アップロードファイル情報配列を渡す。
144        $objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
145        //削除要求のあった画像を表示しない
146        for($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++) {
147            if($_POST['delete_sub'.$i] == "1") {
148                $arrSub['delete'][$i] = "on";
149            }else{
150                $arrSub['delete'][$i] = "";
151            }
152        }
153        $objPage->arrSub = $arrSub;
154        $objPage->tpl_mainpage = 'mail/htmlmail_confirm.tpl';
155     }
156    break;
157   
158    // 確認ページからの戻り
159    case 'return':
160    break;
161   
162    // テンプレート登録
163    case 'complete':
164    // 入力値の変換
165    $objPage->arrForm = lfConvData($_POST);
166    $objPage->arrErr = lfErrorCheck($objPage->arrForm); // 入力エラーチェック
167
168    // アップロード画像をセーブディレクトリに移行
169    $objUpFile->moveTempFile();
170
171    // DB登録
172    if (is_numeric($objPage->arrForm["template_id"])) { // 編集時
173        lfUpdateData($arrRegist);
174    } else {
175        ifRegistData($arrRegist);
176    }
177    $objPage->tpl_mainpage = 'mail/htmlmail_complete.tpl';
178    break;
179}
180
181// 検索結果からの編集時
182if ($_GET["mode"] == "edit" && is_numeric($_GET["template_id"])) {
183    $objPage->edit_mode = "on";
184    //テンプレート情報読み込み
185    lfSetRegistData($_GET["template_id"]);
186    // DBデータから画像ファイル名の読込
187    $objUpFile->setDBFileList($objPage->arrForm);
188
189}
190
191if ($_GET['mode'] != 'edit'){
192//登録情報の読み込み
193$objPage->arrFileName = lfGetProducts();
194}
195
196// HIDDEN用に配列を渡す。
197$objPage->arrHidden = array_merge((array)$objPage->arrHidden, (array)$objUpFile->getHiddenFileList());
198// アップロードファイル情報配列を渡す。
199$objPage->arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
200
201$objView->assignobj($objPage);
202$objView->display(MAIN_FRAME);
203
204//-------------------------------------------------------------------------------------------------------------------------
205
206/* 商品画像の読み込み */
207function lfGetProducts() {
208    global $objQuery;
209   
210    if ($_POST['main_product_id'] != ""){
211    $MainFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($_POST['main_product_id']));
212    $arrFileName[0] = $MainFile[0];
213    }
214    for($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++) {
215        $sub_keyname = "sub_product_id" . sprintf("%02d", $i);
216        if($_POST[$sub_keyname] != "") {
217            $arrSubFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id = ?", array($_POST[$sub_keyname]));
218            $arrFileName[$i] = $arrSubFile[0];
219        }
220    }
221    return $arrFileName;
222}
223
224/* 登録済みデータ読み込み */
225function lfSetRegistData($template_id) {
226    global $objQuery;
227    global $objPage;
228    $arrRet = $objQuery->select("*", "dtb_mailmaga_template", "template_id=?", array($template_id));
229    $arrProductid = $arrRet[0];
230    //画像以外の情報取得
231    $objPage->arrForm = $arrRet[0];
232        if ($arrProductid['main_product_id'] != ""){
233            $MainFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($arrProductid['main_product_id']));
234            $arrFileName[0] = $MainFile[0];
235        }
236    for ($i=1; $i<=HTML_TEMPLATE_SUB_MAX; $i++){
237        if ($arrProductid['sub_product_id'.sprintf("%02d", $i)] != ""){
238            $arrSubFile = $objQuery->select("main_image, name, product_id", "dtb_products", "product_id=?", array($arrProductid['sub_product_id'.sprintf("%02d", $i)]));
239            $arrFileName[$i] = $arrSubFile[0];
240        }
241    }
242    //画像の情報取得
243    $objPage->arrFileName = $arrFileName;
244   
245    return $objPage;
246}
247
248// 編集データ取得
249function lfGetEditData($id, $arrIdData) {
250    global $conn;
251
252    // DB登録情報
253    $sql = "SELECT * FROM dtb_mailmaga_template WHERE template_id = ? AND del_flg = 0";
254    $result = $conn->getAll($sql, array($id));
255
256    // 画像ファイル名
257    for ($i = 0; $i < count($arrIdData); $i ++) {
258        $data = "";
259        if (is_numeric($result[0][ $arrIdData[$i] ]) ) {
260            $sql = "SELECT name,product_id,main_image FROM dtb_products WHERE product_id = ?";
261            $data = $conn->getAll($sql, array($result[0][ $arrIdData[$i] ]));
262        }
263        $arrFileName[] = $data[0];
264    }
265   
266    return array($result[0], $arrFileName);
267}
268
269// 確認データ取得
270function lfGetConfirmData($arrPOST, $arrIdData) {
271    global $conn;
272    // 画像ファイル名
273    for ($i = 0; $i < count($arrIdData); $i ++) {
274        $data = "";
275        if (is_numeric($arrPOST[ $arrIdData[$i] ]) ) {
276            $sql = "SELECT name,product_id,main_image FROM dtb_products WHERE product_id = ?";
277            $data = $conn->getAll($sql, array($arrPOST[ $arrIdData[$i] ]));
278        }
279        $arrFileName[] = $data[0];
280    }
281    return array($arrPOST, $arrFileName);
282}
283
284// データベース登録
285function ifRegistData($arrRegist) {
286    global $conn;
287    global $objUpFile;
288
289    foreach ($arrRegist as $data) {
290        if (strlen($_POST[$data]) > 0) {
291            $arrRegistValue[$data] = $_POST[$data];
292        }
293    }
294    $arrRegistValue["creator_id"] = $_SESSION["member_id"];     // 登録者ID(管理画面)
295    $uploadfile = $objUpFile->getDBFileList();
296    //削除要求のあった商品を削除する
297    for ($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++){
298        if ($_POST['delete_sub'.$i] == '1'){
299            $arrRegistValue['sub_product_id'.sprintf("%02d", $i)] = NULL;
300        }
301    }
302    $arrRegistValue = array_merge($arrRegistValue, $uploadfile);
303    $conn->autoExecute("dtb_mailmaga_template", $arrRegistValue);
304}
305
306// データ更新
307function lfUpdateData($arrRegist) {
308    global $conn;
309    global $objUpFile;
310
311    foreach ($arrRegist as $data) {
312        if (strlen($_POST[$data]) > 0) {
313            $arrRegistValue[$data] = $_POST[$data];
314        }
315    }
316    $arrRegistValue["creator_id"] = $_SESSION["member_id"];
317    $arrRegistValue["update_date"] = "NOW()";
318    $uploadfile = $objUpFile->getDBFileList();
319    //削除要求のあった商品を削除する
320    for ($i = 1; $i <= HTML_TEMPLATE_SUB_MAX; $i++){
321        if ($_POST['delete_sub'.$i] == '1'){
322            $arrRegistValue['sub_product_id'.sprintf("%02d", $i)] = NULL;
323        }
324    }
325    $arrRegistValue = array_merge($arrRegistValue, $uploadfile);
326   
327    $conn->autoExecute("dtb_mailmaga_template", $arrRegistValue, "template_id = ". addslashes($_POST["template_id"]));
328}
329
330// 入力値変換
331function lfConvData( $data ){
332   
333     // 文字列の変換(mb_convert_kanaの変換オプション)                         
334    $arrFlag = array(
335                      "header" => "aKV"
336                     ,"subject" => "aKV"
337                     ,"main_title" => "aKV"
338                     ,"main_comment" => "aKV"
339                     ,"main_product_id" => "aKV"
340                     ,"sub_title" => "aKV"
341                     ,"sub_comment" => "aKV"
342                );
343       
344    if ( is_array($data) ){
345        foreach ($arrFlag as $key=>$line) {
346            $data[$key] = mb_convert_kana($data[$key], $line);
347        }
348    }
349
350    return $data;
351}
352
353// 入力エラーチェック
354function lfErrorCheck($array) {
355    $objErr = new SC_CheckError($array);
356   
357    $objErr->doFunc(array("メール形式", "mail_method"), array("EXIST_CHECK", "ALNUM_CHECK"));
358    $objErr->doFunc(array("Subject", "subject", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
359    $objErr->doFunc(array("ヘッダーテキスト", 'header', LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK") );
360    $objErr->doFunc(array("メイン商品タイトル", 'main_title', STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK") );
361    $objErr->doFunc(array("メイン商品コメント", 'main_comment', LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
362    $objErr->doFunc(array("メイン商品画像", "main_product_id"), array("EXIST_CHECK"));
363    $objErr->doFunc(array("サブ商品群タイトル", "sub_title", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
364    $objErr->doFunc(array("サブ商品群コメント", "sub_comment", LTEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
365   
366    return $objErr->arrErr;
367}
368
369?>
Note: See TracBrowser for help on using the repository browser.