source: branches/dev/data/lib/slib.php @ 12007

Revision 12007, 77.4 KB checked in by kakinaka, 17 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 */
7
8//---¤³¤Î¥Õ¥¡¥¤¥ë¤Î¥Ñ¥¹¤ò»ØÄê
9$INC_PATH = realpath( dirname( __FILE__) );
10require_once( $INC_PATH ."/../conf/conf.php" );
11require_once( $INC_PATH ."/../class/SC_DbConn.php" );
12require_once( $INC_PATH ."/../class/SC_Query.php" );
13require_once( $INC_PATH ."/../class/SC_CampaignSession.php" );
14require_once( $INC_PATH ."/../include/session.inc" );
15
16// Á´¥Ú¡¼¥¸¶¦ÄÌ¥¨¥é¡¼
17$GLOBAL_ERR = "";
18
19// ¥¤¥ó¥¹¥È¡¼¥ë½é´ü½èÍý
20sfInitInstall();
21
22/* ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¡¼¥¸¥ç¥ó½êÆÀ */
23function sfGetDBVersion($dsn = "") {
24    if($dsn == "") {
25        if(defined('DEFAULT_DSN')) {
26            $dsn = DEFAULT_DSN;
27        } else {
28            return;
29        }
30    }
31   
32    $objQuery = new SC_Query($dsn, true, true);
33    list($db_type) = split(":", $dsn);
34    if($db_type == 'mysql') {
35        $val = $objQuery->getOne("select version()");
36        $version = "MySQL " . $val;
37    }   
38    if($db_type == 'pgsql') {
39        $val = $objQuery->getOne("select version()");
40        $arrLine = split(" " , $val);
41        $version = $arrLine[0] . " " . $arrLine[1];
42    }
43    return $version;
44}
45
46/* ¥Æ¡¼¥Ö¥ë¤Î¸ºß¥Á¥§¥Ã¥¯ */
47function sfTabaleExists($table_name, $dsn = "") {
48    if($dsn == "") {
49        if(defined('DEFAULT_DSN')) {
50            $dsn = DEFAULT_DSN;
51        } else {
52            return;
53        }
54    }
55   
56    $objQuery = new SC_Query($dsn, true, true);
57    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
58    if(!$objQuery->isError()) {
59        list($db_type) = split(":", $dsn);
60        // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
61        if ($db_type == "pgsql") {
62            $sql = "SELECT
63                        relname
64                    FROM
65                        pg_class
66                    WHERE
67                        (relkind = 'r' OR relkind = 'v') AND
68                        relname = ?
69                    GROUP BY
70                        relname";
71            $arrRet = $objQuery->getAll($sql, array($table_name));
72            if(count($arrRet) > 0) {
73                return true;
74            }
75        }else if ($db_type == "mysql") {
76            $sql = "SHOW TABLE STATUS LIKE ?";
77            $arrRet = $objQuery->getAll($sql, array($table_name));
78            if(count($arrRet) > 0) {
79                return true;
80            }
81        }
82    }
83    return false;
84}
85
86// ¥«¥é¥à¤Î¸ºß¥Á¥§¥Ã¥¯¤ÈºîÀ®
87function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
88    if($dsn == "") {
89        if(defined('DEFAULT_DSN')) {
90            $dsn = DEFAULT_DSN;
91        } else {
92            return;
93        }
94    }
95
96    // ¥Æ¡¼¥Ö¥ë¤¬Ìµ¤±¤ì¤Ð¥¨¥é¡¼
97    if(!sfTabaleExists($table_name, $dsn)) return false;
98   
99    $objQuery = new SC_Query($dsn, true, true);
100    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
101    if(!$objQuery->isError()) {
102        list($db_type) = split(":", $dsn);
103       
104        // ¥«¥é¥à¥ê¥¹¥È¤ò¼èÆÀ
105        $arrRet = sfGetColumnList($table_name, $objQuery, $db_type);
106        if(count($arrRet) > 0) {
107            if(in_array($col_name, $arrRet)){
108                return true;
109            }
110        }
111    }
112   
113    // ¥«¥é¥à¤òÄɲ乤ë
114    if($add){
115        $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
116        return true;
117    }
118   
119    return false;
120}
121
122// ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß¥Á¥§¥Ã¥¯¤ÈºîÀ®
123function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) {
124    if($dsn == "") {
125        if(defined('DEFAULT_DSN')) {
126            $dsn = DEFAULT_DSN;
127        } else {
128            return;
129        }
130    }
131
132    // ¥Æ¡¼¥Ö¥ë¤¬Ìµ¤±¤ì¤Ð¥¨¥é¡¼
133    if(!sfTabaleExists($table_name, $dsn)) return false;
134   
135    $objQuery = new SC_Query($dsn, true, true);
136    // Àµ¾ï¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç
137    if(!$objQuery->isError()) {
138        list($db_type) = split(":", $dsn);     
139        switch($db_type) {
140        case 'pgsql':
141            // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß³Îǧ
142            $arrRet = $objQuery->getAll("SELECT relname FROM pg_class WHERE relname = ?", array($index_name));
143            break;
144        case 'mysql':
145            // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤Î¸ºß³Îǧ
146            $arrRet = $objQuery->getAll("SHOW INDEX FROM ? WHERE Key_name = ?", array($table_name, $index_name));           
147            break;
148        default:
149            return false;
150        }
151        // ¤¹¤Ç¤Ë¥¤¥ó¥Ç¥Ã¥¯¥¹¤¬Â¸ºß¤¹¤ë¾ì¹ç
152        if(count($arrRet) > 0) {
153            return true;
154        }
155    }
156   
157    // ¥¤¥ó¥Ç¥Ã¥¯¥¹¤òºîÀ®¤¹¤ë
158    if($add){
159        switch($db_type) {
160        case 'pgsql':
161            $objQuery->query("CREATE INDEX ? ON ? (?)", array($index_name, $table_name, $col_name));
162            break;
163        case 'mysql':
164            $objQuery->query("CREATE INDEX ? ON ? (?(?))", array($index_name, $table_name, $col_name, $length));           
165            break;
166        default:
167            return false;
168        }
169        return true;
170    }   
171    return false;
172}
173
174// ¥Ç¡¼¥¿¤Î¸ºß¥Á¥§¥Ã¥¯
175function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
176    if($dsn == "") {
177        if(defined('DEFAULT_DSN')) {
178            $dsn = DEFAULT_DSN;
179        } else {
180            return;
181        }
182    }
183    $objQuery = new SC_Query($dsn, true, true);
184    $count = $objQuery->count($table_name, $where, $arrval);
185
186    if($count > 0) {
187        $ret = true;
188    } else {
189        $ret = false;
190    }
191    // ¥Ç¡¼¥¿¤òÄɲ乤ë
192    if(!$ret && $add) {
193        $objQuery->exec($sql);
194    }
195   
196    return $ret;
197}
198
199/*
200 * ¥µ¥¤¥È´ÉÍý¾ðÊ󤫤éÃͤò¼èÆÀ¤¹¤ë¡£
201 * ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ë¾ì¹ç¡¢É¬¤º1°Ê¾å¤Î¿ôÃͤ¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¡£
202 * 0¤òÊÖ¤·¤¿¾ì¹ç¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤ÇÂбþ¤¹¤ë¤³¤È¡£
203 *
204 * @param $control_id ´ÉÍýID
205 * @param $dsn DataSource
206 * @return $control_flg ¥Õ¥é¥°
207 */
208function sfGetSiteControlFlg($control_id, $dsn = "") {
209
210    // ¥Ç¡¼¥¿¥½¡¼¥¹
211    if($dsn == "") {
212        if(defined('DEFAULT_DSN')) {
213            $dsn = DEFAULT_DSN;
214        } else {
215            return;
216        }
217    }
218
219    // ¥¯¥¨¥êÀ¸À®
220    $target_column = "control_flg";
221    $table_name = "dtb_site_control";
222    $where = "control_id = ?";
223    $arrval = array($control_id);
224    $control_flg = 0;
225
226    // ¥¯¥¨¥êȯ¹Ô
227    $objQuery = new SC_Query($dsn, true, true);
228    $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval);
229
230    // ¥Ç¡¼¥¿¤¬Â¸ºß¤¹¤ì¤Ð¥Õ¥é¥°¤ò¼èÆÀ¤¹¤ë
231    if (count($arrSiteControl) > 0) {
232        $control_flg = $arrSiteControl[0]["control_flg"];
233    }
234   
235    return $control_flg;
236}
237
238// ¥Æ¡¼¥Ö¥ë¤Î¥«¥é¥à°ìÍ÷¤ò¼èÆÀ¤¹¤ë
239function sfGetColumnList($table_name, $objQuery = "", $db_type = DB_TYPE){
240    if($objQuery == "") $objQuery = new SC_Query();
241    $arrRet = array();
242   
243    // postgresql¤Èmysql¤È¤Ç½èÍý¤òʬ¤±¤ë
244    if ($db_type == "pgsql") {
245        $sql = "SELECT a.attname FROM pg_class c, pg_attribute a WHERE c.relname=? AND c.oid=a.attrelid AND a.attnum > 0 ORDER BY a.attnum";
246        $arrColList = $objQuery->getAll($sql, array($table_name));
247        $arrColList = sfswaparray($arrColList);
248        $arrRet = $arrColList["attname"];
249    }else if ($db_type == "mysql") {
250        $sql = "SHOW COLUMNS FROM $table_name";
251        $arrColList = $objQuery->getAll($sql);
252        $arrColList = sfswaparray($arrColList);
253        $arrRet = $arrColList["Field"];
254    }
255    return $arrRet;
256}
257
258// ¥¤¥ó¥¹¥È¡¼¥ë½é´ü½èÍý
259function sfInitInstall() {
260    // ¥¤¥ó¥¹¥È¡¼¥ëºÑ¤ß¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
261    if(!defined('ECCUBE_INSTALL')) {
262        if(!ereg("/install/", $_SERVER['PHP_SELF'])) {
263            header("Location: ./install/");
264        }
265    } else {
266        $path = HTML_PATH . "install/index.php";
267        if(file_exists($path)) {
268            sfErrorHeader(">> /install/index.php¤Ï¡¢¥¤¥ó¥¹¥È¡¼¥ë´°Î»¸å¤Ë¥Õ¥¡¥¤¥ë¤òºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£");
269        }
270       
271        // µì¥Ð¡¼¥¸¥ç¥ó¤Îinstall.inc¤Î¥Á¥§¥Ã¥¯
272        $path = HTML_PATH . "install.inc";
273        if(file_exists($path)) {
274            sfErrorHeader(">> /install.inc¤Ï¥»¥­¥å¥ê¥Æ¥£¡¼¥Û¡¼¥ë¤È¤Ê¤ê¤Þ¤¹¡£ºï½ü¤·¤Æ¤¯¤À¤µ¤¤¡£");
275        }       
276    }
277}
278
279// ¥¢¥Ã¥×¥Ç¡¼¥È¤ÇÀ¸À®¤µ¤ì¤¿PHP¤òÆɤ߽Ф·
280function sfLoadUpdateModule() {
281    // URLÀßÄê¥Ç¥£¥ì¥¯¥È¥ê¤òºï½ü
282    $main_php = ereg_replace(URL_DIR, "", $_SERVER['PHP_SELF']);
283    $extern_php = UPDATE_PATH . $main_php;
284    if(file_exists($extern_php)) {
285        require_once($extern_php);
286    }
287}
288
289function sf_getBasisData() {
290    //DB¤«¤éÀßÄê¾ðÊó¤ò¼èÆÀ
291    $objConn = new SC_DbConn(DEFAULT_DSN);
292    $result = $objConn->getAll("SELECT * FROM dtb_baseinfo");
293    if(is_array($result[0])) {
294        foreach ( $result[0] as $key=>$value ){
295            $CONF["$key"] = $value;
296        }
297    }
298    return $CONF;
299}
300
301// Áõ¾þÉÕ¤­¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Îɽ¼¨
302function sfErrorHeader($mess, $print = false) {
303    global $GLOBAL_ERR;
304    if($GLOBAL_ERR == "") {
305        $GLOBAL_ERR = "<meta http-equiv='Content-Type' content='text/html; charset=" . CHAR_CODE . "'>\n";
306    }
307    $GLOBAL_ERR.= "<table width='100%' border='0' cellspacing='0' cellpadding='0' summary=' '>\n";
308    $GLOBAL_ERR.= "<tr>\n";
309    $GLOBAL_ERR.= "<td bgcolor='#ffeebb' height='25' colspan='2' align='center'>\n";
310    $GLOBAL_ERR.= "<SPAN style='color:red; font-size:12px'><strong>" . $mess . "</strong></span>\n";
311    $GLOBAL_ERR.= "</td>\n";
312    $GLOBAL_ERR.= " </tr>\n";
313    $GLOBAL_ERR.= "</table>\n";
314   
315    if($print) {
316        print($GLOBAL_ERR);
317    }
318}
319
320/* ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨ */
321function sfDispError($type) {
322   
323    class LC_ErrorPage {
324        function LC_ErrorPage() {
325            $this->tpl_mainpage = 'login_error.tpl';
326            $this->tpl_title = '¥¨¥é¡¼';
327        }
328    }
329
330    $objPage = new LC_ErrorPage();
331    $objView = new SC_AdminView();
332   
333    switch ($type) {
334        case LOGIN_ERROR:
335            $objPage->tpl_error="£É£Ä¤Þ¤¿¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
336            break;
337        case ACCESS_ERROR:
338            $objPage->tpl_error="¥í¥°¥¤¥óǧ¾Ú¤ÎÍ­¸ú´ü¸ÂÀÚ¤ì¤Î²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
339            break;
340        case AUTH_ERROR:
341            $objPage->tpl_error="¤³¤Î¥Õ¥¡¥¤¥ë¤Ë¤Ï¥¢¥¯¥»¥¹¸¢¸Â¤¬¤¢¤ê¤Þ¤»¤ó¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
342            break;
343        case PAGE_ERROR:
344            $objPage->tpl_error="ÉÔÀµ¤Ê¥Ú¡¼¥¸°ÜÆ°¤Ç¤¹¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£";
345            break;
346        default:
347            $objPage->tpl_error="¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£<br />¤â¤¦°ìÅÙ¤´³Îǧ¤Î¤¦¤¨¡¢ºÆÅÙ¥í¥°¥¤¥ó¤·¤Æ¤¯¤À¤µ¤¤¡£";
348            break;
349    }
350   
351    $objView->assignobj($objPage);
352    $objView->display(LOGIN_FRAME);
353   
354    exit;
355}
356
357/* ¥µ¥¤¥È¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨ */
358function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "", $is_mobile = false) {
359    global $objCampaignSess;
360   
361    if ($objSiteSess != "") {
362        $objSiteSess->setNowPage('error');
363    }
364   
365    class LC_ErrorPage {
366        function LC_ErrorPage() {
367            $this->tpl_mainpage = 'error.tpl';
368            $this->tpl_css = URL_DIR.'css/layout/error.css';
369            $this->tpl_title = '¥¨¥é¡¼';
370        }
371    }
372   
373    $objPage = new LC_ErrorPage();
374   
375    if($is_mobile === true) {
376        $objView = new SC_MobileView();     
377    } else {
378        $objView = new SC_SiteView();
379    }
380   
381    switch ($type) {
382        case PRODUCT_NOT_FOUND:
383            $objPage->tpl_error="¤´»ØÄê¤Î¥Ú¡¼¥¸¤Ï¤´¤¶¤¤¤Þ¤»¤ó¡£";
384            break;
385        case PAGE_ERROR:
386            $objPage->tpl_error="ÉÔÀµ¤Ê¥Ú¡¼¥¸°ÜÆ°¤Ç¤¹¡£";
387            break;
388        case CART_EMPTY:
389            $objPage->tpl_error="¥«¡¼¥È¤Ë¾¦Éʤ¬¤¬¤¢¤ê¤Þ¤»¤ó¡£";
390            break;
391        case CART_ADD_ERROR:
392            $objPage->tpl_error="¹ØÆþ½èÍýÃæ¤Ï¡¢¥«¡¼¥È¤Ë¾¦ÉʤòÄɲ乤뤳¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
393            break;
394        case CANCEL_PURCHASE:
395            $objPage->tpl_error="¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£°Ê²¼¤ÎÍ×°ø¤¬¹Í¤¨¤é¤ì¤Þ¤¹¡£<br />¡¦¥»¥Ã¥·¥ç¥ó¾ðÊó¤ÎÍ­¸ú´ü¸Â¤¬ÀÚ¤ì¤Æ¤ë¾ì¹ç<br />¡¦¹ØÆþ¼ê³¤­Ãæ¤Ë¿·¤·¤¤¹ØÆþ¼ê³¤­¤ò¼Â¹Ô¤·¤¿¾ì¹ç<br />¡¦¤¹¤Ç¤Ë¹ØÆþ¼ê³¤­¤ò´°Î»¤·¤Æ¤¤¤ë¾ì¹ç";
396            break;
397        case CATEGORY_NOT_FOUND:
398            $objPage->tpl_error="¤´»ØÄê¤Î¥«¥Æ¥´¥ê¤Ï¸ºß¤·¤Þ¤»¤ó¡£";
399            break;
400        case SITE_LOGIN_ERROR:
401            $objPage->tpl_error="¥á¡¼¥ë¥¢¥É¥ì¥¹¤â¤·¤¯¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£";
402            break;
403        case TEMP_LOGIN_ERROR:
404            $objPage->tpl_error="¥á¡¼¥ë¥¢¥É¥ì¥¹¤â¤·¤¯¤Ï¥Ñ¥¹¥ï¡¼¥É¤¬Àµ¤·¤¯¤¢¤ê¤Þ¤»¤ó¡£<br />ËÜÅÐÏ¿¤¬¤ªºÑ¤ß¤Ç¤Ê¤¤¾ì¹ç¤Ï¡¢²¾ÅÐÏ¿¥á¡¼¥ë¤Ëµ­ºÜ¤µ¤ì¤Æ¤¤¤ë<br />URL¤è¤êËÜÅÐÏ¿¤ò¹Ô¤Ã¤Æ¤¯¤À¤µ¤¤¡£";
405            break;
406        case CUSTOMER_ERROR:
407            $objPage->tpl_error="ÉÔÀµ¤Ê¥¢¥¯¥»¥¹¤Ç¤¹¡£";
408            break;
409        case SOLD_OUT:
410            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¤´¹ØÆþ¤ÎľÁ°¤ÇÇä¤êÀڤ줿¾¦Éʤ¬¤¢¤ê¤Þ¤¹¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
411            break;
412        case CART_NOT_FOUND:
413            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¥«¡¼¥ÈÆâ¤Î¾¦ÉʾðÊó¤Î¼èÆÀ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
414            break;
415        case LACK_POINT:
416            $objPage->tpl_error="¿½¤·Ìõ¤´¤¶¤¤¤Þ¤»¤ó¤¬¡¢¥Ý¥¤¥ó¥È¤¬ÉÔ­¤·¤Æ¤ª¤ê¤Þ¤¹¡£¤³¤Î¼ê³¤­¤Ï̵¸ú¤È¤Ê¤ê¤Þ¤·¤¿¡£";
417            break;
418        case FAVORITE_ERROR:
419            $objPage->tpl_error="´û¤Ë¤ªµ¤¤ËÆþ¤ê¤ËÄɲ䵤ì¤Æ¤¤¤ë¾¦ÉʤǤ¹¡£";
420            break;
421        case EXTRACT_ERROR:
422            $objPage->tpl_error="¥Õ¥¡¥¤¥ë¤Î²òÅà¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n»ØÄê¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë½ñ¤­¹þ¤ß¸¢¸Â¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
423            break;
424        case FTP_DOWNLOAD_ERROR:
425            $objPage->tpl_error="¥Õ¥¡¥¤¥ë¤ÎFTP¥À¥¦¥ó¥í¡¼¥É¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
426            break;
427        case FTP_LOGIN_ERROR:
428            $objPage->tpl_error="FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
429            break;
430        case FTP_CONNECT_ERROR:
431            $objPage->tpl_error="FTP¥í¥°¥¤¥ó¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£";
432            break;
433        case CREATE_DB_ERROR:
434            $objPage->tpl_error="DB¤ÎºîÀ®¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\n»ØÄê¤Î¥æ¡¼¥¶¡¼¤Ë¤Ï¡¢DBºîÀ®¤Î¸¢¸Â¤¬Í¿¤¨¤é¤ì¤Æ¤¤¤Ê¤¤²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
435            break;
436        case DB_IMPORT_ERROR:
437            $objPage->tpl_error="¥Ç¡¼¥¿¥Ù¡¼¥¹¹½Â¤¤Î¥¤¥ó¥Ý¡¼¥È¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£\nsql¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤ë²ÄǽÀ­¤¬¤¢¤ê¤Þ¤¹¡£";
438            break;
439        case FILE_NOT_FOUND:
440            $objPage->tpl_error="»ØÄê¤Î¥Ñ¥¹¤Ë¡¢ÀßÄê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤»¤ó¡£";
441            break;
442        case WRITE_FILE_ERROR:
443            $objPage->tpl_error="ÀßÄê¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤á¤Þ¤»¤ó¡£\nÀßÄê¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤ß¸¢¸Â¤òÍ¿¤¨¤Æ¤¯¤À¤µ¤¤¡£";
444            break;
445        case FREE_ERROR_MSG:
446            $objPage->tpl_error=$err_msg;
447            break;
448        default:
449            $objPage->tpl_error="¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤·¤¿¡£";
450            break;
451    }
452   
453    $objPage->return_top = $return_top;
454   
455    $objView->assignobj($objPage);
456   
457    if(is_object($objCampaignSess)) {
458        // ¥Õ¥ì¡¼¥à¤òÁªÂò(¥­¥ã¥ó¥Ú¡¼¥ó¥Ú¡¼¥¸¤«¤éÁ«°Ü¤Ê¤éÊѹ¹)
459        $objCampaignSess->pageView($objView);
460    } else {
461        $objView->display(SITE_FRAME);
462    }   
463    exit;
464}
465
466/* ǧ¾Ú¤Î²ÄÈÝȽÄê */
467function sfIsSuccess($objSess, $disp_error = true) {
468    $ret = $objSess->IsSuccess();
469    if($ret != SUCCESS) {
470        if($disp_error) {
471            // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
472            sfDispError($ret);
473        }
474        return false;
475    }
476    return true;       
477}
478
479/* Á°¤Î¥Ú¡¼¥¸¤ÇÀµ¤·¤¯ÅÐÏ¿¤¬¹Ô¤ï¤ì¤¿¤«È½Äê */
480function sfIsPrePage($objSiteSess, $is_mobile = false) {
481    $ret = $objSiteSess->isPrePage();
482    if($ret != true) {
483        // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
484        sfDispSiteError(PAGE_ERROR, $objSiteSess, false, "", $is_mobile);           
485    }
486}
487
488function sfCheckNormalAccess($objSiteSess, $objCartSess) {
489    // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
490    $uniqid = $objSiteSess->getUniqId();
491    // ¹ØÆþ¥Ü¥¿¥ó¤ò²¡¤·¤¿»þ¤Î¥«¡¼¥ÈÆâÍƤ¬¥³¥Ô¡¼¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Î¤ß¥³¥Ô¡¼¤¹¤ë¡£
492    $objCartSess->saveCurrentCart($uniqid);
493    // POST¤Î¥æ¥Ë¡¼¥¯ID¤È¥»¥Ã¥·¥ç¥ó¤Î¥æ¥Ë¡¼¥¯ID¤òÈæ³Ó(¥æ¥Ë¡¼¥¯ID¤¬POST¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¥¹¥ë¡¼)
494    $ret = $objSiteSess->checkUniqId();
495    if($ret != true) {
496        // ¥¨¥é¡¼¥Ú¡¼¥¸¤Îɽ¼¨
497        sfDispSiteError(CANCEL_PURCHASE, $objSiteSess);
498    }
499   
500    // ¥«¡¼¥ÈÆ⤬¶õ¤Ç¤Ê¤¤¤« || ¹ØÆþ¥Ü¥¿¥ó¤ò²¡¤·¤Æ¤«¤éÊѲ½¤¬¤Ê¤¤¤«
501    $quantity = $objCartSess->getTotalQuantity();
502    $ret = $objCartSess->checkChangeCart();
503    if($ret == true || !($quantity > 0)) {
504        // ¥«¡¼¥È¾ðÊóɽ¼¨¤Ë¶¯À©°ÜÆ°¤¹¤ë
505        header("Location: ".URL_CART_TOP);
506        exit;
507    }
508    return $uniqid;
509}
510
511/* DBÍÑÆüÉÕʸ»úÎó¼èÆÀ */
512function sfGetTimestamp($year, $month, $day, $last = false) {
513    if($year != "" && $month != "" && $day != "") {
514        if($last) {
515            $time = "23:59:59";
516        } else {
517            $time = "00:00:00";
518        }
519        $date = $year."-".$month."-".$day." ".$time;
520    } else {
521        $date = "";
522    }
523    return  $date;
524}
525
526// INT·¿¤Î¿ôÃÍ¥Á¥§¥Ã¥¯
527function sfIsInt($value) {
528    if($value != "" && strlen($value) <= INT_LEN && is_numeric($value)) {
529        return true;
530    }
531    return false;
532}
533
534// INT·¿¤ÎÀ°¿ô¥Á¥§¥Ã¥¯
535function sfIsRealInt($value) {
536    if($value != "" && strlen($value) <= INT_LEN && is_Int($value)) {
537        return true;
538    }
539    return false;
540}
541
542function sfCSVDownload($data, $prefix = ""){
543   
544    if($prefix == "") {
545        $dir_name = sfUpDirName();
546        $file_name = $dir_name . date("ymdHis") .".csv";
547    } else {
548        $file_name = $prefix . date("ymdHis") .".csv";
549    }
550   
551    /* HTTP¥Ø¥Ã¥À¤Î½ÐÎÏ */
552    Header("Content-disposition: attachment; filename=${file_name}");
553    Header("Content-type: application/octet-stream; name=${file_name}");
554    Header("Cache-Control: ");
555    Header("Pragma: ");
556   
557    /* i18n¢· ¤À¤ÈÀµ¾ï¤ËÆ°ºî¤·¤Ê¤¤¤¿¤á¡¢mb¢· ¤ËÊѹ¹
558    if (i18n_discover_encoding($data) == CHAR_CODE){
559        $data = i18n_convert($data,'SJIS',CHAR_CODE);
560    }
561    */
562    if (mb_internal_encoding() == CHAR_CODE){
563        $data = mb_convert_encoding($data,'SJIS',CHAR_CODE);
564    }
565   
566    /* ¥Ç¡¼¥¿¤ò½ÐÎÏ */
567    echo $data;
568}
569
570/* 1³¬Áؾå¤Î¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¼èÆÀ¤¹¤ë */
571function sfUpDirName() {
572    $path = $_SERVER['PHP_SELF'];
573    $arrVal = split("/", $path);
574    $cnt = count($arrVal);
575    return $arrVal[($cnt - 2)];
576}
577
578// ¸½ºß¤Î¥µ¥¤¥È¤ò¹¹¿·¡Ê¤¿¤À¤·¥Ý¥¹¥È¤Ï¹Ô¤ï¤Ê¤¤¡Ë
579function sfReload($get = "") {
580    if ($_SERVER["SERVER_PORT"] == "443" ){
581        $url = ereg_replace(URL_DIR . "$", "", SSL_URL);
582    } else {
583        $url = ereg_replace(URL_DIR . "$", "", SITE_URL);
584    }
585   
586    if($get != "") {
587        header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get);
588    } else {
589        header("Location: ". $url . $_SERVER['PHP_SELF']);
590    }
591    exit;
592}
593
594// ¥é¥ó¥­¥ó¥°¤ò¾å¤²¤ë¡£
595function sfRankUp($table, $colname, $id, $andwhere = "") {
596    $objQuery = new SC_Query();
597    $objQuery->begin();
598    $where = "$colname = ?";
599    if($andwhere != "") {
600        $where.= " AND $andwhere";
601    }
602    // ÂоݹàÌܤΥé¥ó¥¯¤ò¼èÆÀ
603    $rank = $objQuery->get($table, "rank", $where, array($id));
604    // ¥é¥ó¥¯¤ÎºÇÂçÃͤò¼èÆÀ
605    $maxrank = $objQuery->max($table, "rank", $andwhere);
606    // ¥é¥ó¥¯¤¬ºÇÂçÃͤè¤ê¤â¾®¤µ¤¤¾ì¹ç¤Ë¼Â¹Ô¤¹¤ë¡£
607    if($rank < $maxrank) {
608        // ¥é¥ó¥¯¤¬°ì¤Ä¾å¤ÎID¤ò¼èÆÀ¤¹¤ë¡£
609        $where = "rank = ?";
610        if($andwhere != "") {
611            $where.= " AND $andwhere";
612        }
613        $uprank = $rank + 1;
614        $up_id = $objQuery->get($table, $colname, $where, array($uprank));
615        // ¥é¥ó¥¯Æþ¤ìÂؤ¨¤Î¼Â¹Ô
616        $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
617        $objQuery->exec($sqlup, array($rank + 1, $id));
618        $objQuery->exec($sqlup, array($rank, $up_id));
619    }
620    $objQuery->commit();
621}
622
623// ¥é¥ó¥­¥ó¥°¤ò²¼¤²¤ë¡£
624function sfRankDown($table, $colname, $id, $andwhere = "") {
625    $objQuery = new SC_Query();
626    $objQuery->begin();
627    $where = "$colname = ?";
628    if($andwhere != "") {
629        $where.= " AND $andwhere";
630    }
631    // ÂоݹàÌܤΥé¥ó¥¯¤ò¼èÆÀ
632    $rank = $objQuery->get($table, "rank", $where, array($id));
633       
634    // ¥é¥ó¥¯¤¬1(ºÇ¾®ÃÍ)¤è¤ê¤âÂ礭¤¤¾ì¹ç¤Ë¼Â¹Ô¤¹¤ë¡£
635    if($rank > 1) {
636        // ¥é¥ó¥¯¤¬°ì¤Ä²¼¤ÎID¤ò¼èÆÀ¤¹¤ë¡£
637        $where = "rank = ?";
638        if($andwhere != "") {
639            $where.= " AND $andwhere";
640        }
641        $downrank = $rank - 1;
642        $down_id = $objQuery->get($table, $colname, $where, array($downrank));
643        // ¥é¥ó¥¯Æþ¤ìÂؤ¨¤Î¼Â¹Ô
644        $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
645        $objQuery->exec($sqlup, array($rank - 1, $id));
646        $objQuery->exec($sqlup, array($rank, $down_id));
647    }
648    $objQuery->commit();
649}
650
651//----¡¡»ØÄê½ç°Ì¤Ø°ÜÆ°
652function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
653    $objQuery = new SC_Query();
654    $objQuery->begin();
655       
656    // ¼«¿È¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë
657    $rank = $objQuery->get($tableName, "rank", "$keyIdColumn = ?", array($keyId)); 
658    $max = $objQuery->max($tableName, "rank", $where);
659       
660    // ÃͤÎÄ´À°¡ÊµÕ½ç¡Ë
661    if($pos > $max) {
662        $position = 1;
663    } else if($pos < 1) {
664        $position = $max;
665    } else {
666        $position = $max - $pos + 1;
667    }
668   
669    if( $position > $rank ) $term = "rank - 1"; //Æþ¤ìÂؤ¨Àè¤Î½ç°Ì¤¬Æþ¤ì´¹¤¨¸µ¤Î½ç°Ì¤è¤êÂ礭¤¤¾ì¹ç
670    if( $position < $rank ) $term = "rank + 1"; //Æþ¤ìÂؤ¨Àè¤Î½ç°Ì¤¬Æþ¤ì´¹¤¨¸µ¤Î½ç°Ì¤è¤ê¾®¤µ¤¤¾ì¹ç
671
672    //--¡¡»ØÄꤷ¤¿½ç°Ì¤Î¾¦Éʤ«¤é°ÜÆ°¤µ¤»¤ë¾¦ÉʤޤǤÎrank¤ò£±¤Ä¤º¤é¤¹
673    $sql = "UPDATE $tableName SET rank = $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";
674    if($where != "") {
675        $sql.= " AND $where";
676    }
677   
678    if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));
679    if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));
680
681    //-- »ØÄꤷ¤¿½ç°Ì¤Ørank¤ò½ñ¤­´¹¤¨¤ë¡£
682    $sql  = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";
683    if($where != "") {
684        $sql.= " AND $where";
685    }
686   
687    $objQuery->exec( $sql, array( $position, $keyId ) );
688    $objQuery->commit();
689}
690
691// ¥é¥ó¥¯¤ò´Þ¤à¥ì¥³¡¼¥É¤Îºï½ü
692// ¥ì¥³¡¼¥É¤´¤Èºï½ü¤¹¤ë¾ì¹ç¤Ï¡¢$delete¤òtrue¤Ë¤¹¤ë¡£
693function sfDeleteRankRecord($table, $colname, $id, $andwhere = "", $delete = false) {
694    $objQuery = new SC_Query();
695    $objQuery->begin();
696    // ºï½ü¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£     
697    $where = "$colname = ?";
698    if($andwhere != "") {
699        $where.= " AND $andwhere";
700    }
701    $rank = $objQuery->get($table, "rank", $where, array($id));
702
703    if(!$delete) {
704        // ¥é¥ó¥¯¤òºÇ²¼°Ì¤Ë¤¹¤ë¡¢DEL¥Õ¥é¥°ON
705        $sqlup = "UPDATE $table SET rank = 0, del_flg = 1, update_date = Now() ";
706        $sqlup.= "WHERE $colname = ?";
707        // UPDATE¤Î¼Â¹Ô
708        $objQuery->exec($sqlup, array($id));
709    } else {
710        $objQuery->delete($table, "$colname = ?", array($id));
711    }
712   
713    // Äɲå쥳¡¼¥É¤Î¥é¥ó¥¯¤è¤ê¾å¤Î¥ì¥³¡¼¥É¤ò°ì¤Ä¤º¤é¤¹¡£
714    $where = "rank > ?";
715    if($andwhere != "") {
716        $where.= " AND $andwhere";
717    }
718    $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
719    $objQuery->exec($sqlup, array($rank));
720    $objQuery->commit();
721}
722
723// ¥ì¥³¡¼¥É¤Î¸ºß¥Á¥§¥Ã¥¯
724function sfIsRecord($table, $col, $arrval, $addwhere = "") {
725    $objQuery = new SC_Query();
726    $arrCol = split("[, ]", $col);
727       
728    $where = "del_flg = 0";
729   
730    if($addwhere != "") {
731        $where.= " AND $addwhere";
732    }
733       
734    foreach($arrCol as $val) {
735        if($val != "") {
736            if($where == "") {
737                $where = "$val = ?";
738            } else {
739                $where.= " AND $val = ?";
740            }
741        }
742    }
743    $ret = $objQuery->get($table, $col, $where, $arrval);
744   
745    if($ret != "") {
746        return true;
747    }
748    return false;
749}
750
751// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤò¥Þ¡¼¥¸
752function sfMergeCBValue($keyname, $max) {
753    $conv = "";
754    $cnt = 1;
755    for($cnt = 1; $cnt <= $max; $cnt++) {
756        if ($_POST[$keyname . $cnt] == "1") {
757            $conv.= "1";
758        } else {
759            $conv.= "0";
760        }
761    }
762    return $conv;
763}
764
765// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤Æ2¿Ê¿ô·Á¼°¤ËÊѹ¹¤¹¤ë¡£
766function sfMergeCheckBoxes($array, $max) {
767    $ret = "";
768    if(is_array($array)) { 
769        foreach($array as $val) {
770            $arrTmp[$val] = "1";
771        }
772    }
773    for($i = 1; $i <= $max; $i++) {
774        if($arrTmp[$i] == "1") {
775            $ret.= "1";
776        } else {
777            $ret.= "0";
778        }
779    }
780    return $ret;
781}
782
783
784// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤Æ¡Ö-¡×¤Ç¤Ä¤Ê¤²¤ë¡£
785function sfMergeParamCheckBoxes($array) {
786    if(is_array($array)) {
787        foreach($array as $val) {
788            if($ret != "") {
789                $ret.= "-$val";
790            } else {
791                $ret = $val;           
792            }
793        }
794    } else {
795        $ret = $array;
796    }
797    return $ret;
798}
799
800// html_checkboxes¤ÎÃͤò¥Þ¡¼¥¸¤·¤ÆSQL¸¡º÷ÍѤËÊѹ¹¤¹¤ë¡£
801function sfSearchCheckBoxes($array) {
802    $max = 0;
803    $ret = "";
804    foreach($array as $val) {
805        $arrTmp[$val] = "1";
806        if($val > $max) {
807            $max = $val;
808        }
809    }
810    for($i = 1; $i <= $max; $i++) {
811        if($arrTmp[$i] == "1") {
812            $ret.= "1";
813        } else {
814            $ret.= "_";
815        }
816    }
817   
818    if($ret != "") {   
819        $ret.= "%";
820    }
821    return $ret;
822}
823
824// 2¿Ê¿ô·Á¼°¤ÎÃͤòhtml_checkboxesÂбþ¤ÎÃͤËÀÚ¤êÂؤ¨¤ë
825function sfSplitCheckBoxes($val) {
826    $len = strlen($val);
827    for($i = 0; $i < $len; $i++) {
828        if(substr($val, $i, 1) == "1") {
829            $arrRet[] = ($i + 1);
830        }
831    }
832    return $arrRet;
833}
834
835// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤò¥Þ¡¼¥¸
836function sfMergeCBSearchValue($keyname, $max) {
837    $conv = "";
838    $cnt = 1;
839    for($cnt = 1; $cnt <= $max; $cnt++) {
840        if ($_POST[$keyname . $cnt] == "1") {
841            $conv.= "1";
842        } else {
843            $conv.= "_";
844        }
845    }
846    return $conv;
847}
848
849// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤ÎÃͤòʬ²ò
850function sfSplitCBValue($val, $keyname = "") {
851    $len = strlen($val);
852    $no = 1;
853    for ($cnt = 0; $cnt < $len; $cnt++) {
854        if($keyname != "") {
855            $arr[$keyname . $no] = substr($val, $cnt, 1);
856        } else {
857            $arr[] = substr($val, $cnt, 1);
858        }
859        $no++;
860    }
861    return $arr;
862}
863
864// ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ
865function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") {
866   
867    $max = count($arrList);
868   
869    if($len_max != "" && $max > $len_max) {
870        $max = $len_max;
871    }
872   
873    for($cnt = 0; $cnt < $max; $cnt++) {
874        if($keysize != "") {
875            $key = sfCutString($arrList[$cnt][$keyname], $keysize);
876        } else {
877            $key = $arrList[$cnt][$keyname];
878        }
879        $val = $arrList[$cnt][$valname];
880       
881        if(!isset($arrRet[$key])) {
882            $arrRet[$key] = $val;
883        }
884       
885    }
886    return $arrRet;
887}
888
889// ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ(Ãͤ¬Ê£¿ô¤Î¾ì¹ç)
890function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") {
891   
892    $max = count($arrList);
893   
894    if($len_max != "" && $max > $len_max) {
895        $max = $len_max;
896    }
897   
898    for($cnt = 0; $cnt < $max; $cnt++) {
899        if($keysize != "") {
900            $key = sfCutString($arrList[$cnt][$keyname], $keysize);
901        } else {
902            $key = $arrList[$cnt][$keyname];
903        }
904        $val = $arrList[$cnt][$valname];
905       
906        if($connect != "") {
907            $arrRet[$key].= "$val".$connect;
908        } else {
909            $arrRet[$key][] = $val;     
910        }
911    }
912    return $arrRet;
913}
914
915// ÇÛÎó¤ÎÃͤò¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊÖ¤¹¡£
916function sfGetCommaList($array, $space=true) {
917    if (count($array) > 0) {
918        $line = "";
919        foreach($array as $val) {
920            if ($space) {
921                $line .= $val . ", ";
922            }else{
923                $line .= $val . ",";
924            }
925        }
926        if ($space) {
927            $line = ereg_replace(", $", "", $line);
928        }else{
929            $line = ereg_replace(",$", "", $line);
930        }
931        return $line;
932    }else{
933        return false;
934    }
935   
936}
937
938/* ÇÛÎó¤ÎÍ×ÁǤòCSV¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤ¹¤ë¡£*/
939function sfGetCSVList($array) {
940    if (count($array) > 0) {
941        foreach($array as $key => $val) {
942            $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE);
943            $line .= "\"".$val."\",";
944        }
945        $line = ereg_replace(",$", "\n", $line);
946    }else{
947        return false;
948    }
949    return $line;
950}
951
952/* ÇÛÎó¤ÎÍ×ÁǤòPDF¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤ¹¤ë¡£*/
953function sfGetPDFList($array) {
954    foreach($array as $key => $val) {
955        $line .= "\t".$val;
956    }
957    $line.="\n";
958    return $line;
959}
960
961
962
963/*-----------------------------------------------------------------*/
964/*  check_set_term
965/*  ǯ·îÆü¤ËÊ̤줿2¤Ä¤Î´ü´Ö¤ÎÂÅÅöÀ­¤ò¥Á¥§¥Ã¥¯¤·¡¢À°¹çÀ­¤È´ü´Ö¤òÊÖ¤¹
966/*¡¡°ú¿ô (³«»Ïǯ,³«»Ï·î,³«»ÏÆü,½ªÎ»Ç¯,½ªÎ»·î,½ªÎ»Æü)
967/*¡¡ÌáÃÍ array(£±¡¤£²¡¤£³¡Ë
968/*          £±¡¥³«»Ïǯ·îÆü (YYYY/MM/DD 000000)
969/*          £²¡¥½ªÎ»Ç¯·îÆü (YYYY/MM/DD 235959)
970/*          £³¡¥¥¨¥é¡¼ ( 0 = OK, 1 = NG )
971/*-----------------------------------------------------------------*/
972function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) {
973
974    // ´ü´Ö»ØÄê
975    $error = 0;
976    if ( $start_month || $start_day || $start_year){
977        if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1;
978    } else {
979        $error = 1;
980    }
981    if ( $end_month || $end_day || $end_year){
982        if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2;
983    }
984    if ( ! $error ){
985        $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000";
986        $date2 = $end_year   ."/".sprintf("%02d",$end_month)   ."/".sprintf("%02d",$end_day)   ." 235959";
987        if ($date1 > $date2) $error = 3;
988    } else {
989        $error = 1;
990    }
991    return array($date1, $date2, $error);
992}
993
994// ¥¨¥é¡¼²Õ½ê¤ÎÇØ·Ê¿§¤òÊѹ¹¤¹¤ë¤¿¤á¤Îfunction SC_View¤ÇÆɤ߹þ¤à
995function sfSetErrorStyle(){
996    return 'style="background-color:'.ERR_COLOR.'"';
997}
998
999/* DB¤ËÅϤ¹¿ôÃͤΥÁ¥§¥Ã¥¯
1000 * 10·å°Ê¾å¤Ï¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¥¨¥é¡¼¤òµ¯¤³¤¹¤Î¤Ç¡£
1001 */
1002function sfCheckNumLength( $value ){
1003    if ( ! is_numeric($value)  ){
1004        return false;
1005    }
1006   
1007    if ( strlen($value) > 9 ) {
1008        return false;
1009    }
1010   
1011    return true;
1012}
1013
1014// °ìÃפ·¤¿ÃͤΥ­¡¼Ì¾¤ò¼èÆÀ
1015function sfSearchKey($array, $word, $default) {
1016    foreach($array as $key => $val) {
1017        if($val == $word) {
1018            return $key;
1019        }
1020    }
1021    return $default;
1022}
1023
1024// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ($products_check:true¾¦ÉÊÅÐÏ¿ºÑ¤ß¤Î¤â¤Î¤À¤±¼èÆÀ)
1025function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
1026    $objQuery = new SC_Query();
1027    $where = "del_flg = 0";
1028   
1029    if($addwhere != "") {
1030        $where.= " AND $addwhere";
1031    }
1032       
1033    $objQuery->setoption("ORDER BY rank DESC");
1034   
1035    if($products_check) {
1036        $col = "T1.category_id, category_name, level";
1037        $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
1038        $where .= " AND product_count > 0";
1039    } else {
1040        $col = "category_id, category_name, level";
1041        $from = "dtb_category";
1042    }
1043   
1044    $arrRet = $objQuery->select($col, $from, $where);
1045           
1046    $max = count($arrRet);
1047    for($cnt = 0; $cnt < $max; $cnt++) {
1048        $id = $arrRet[$cnt]['category_id'];
1049        $name = $arrRet[$cnt]['category_name'];
1050        $arrList[$id] = "";
1051        /*
1052        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
1053            $arrList[$id].= "¡¡";
1054        }
1055        */
1056        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
1057            $arrList[$id].= $head;
1058        }
1059        $arrList[$id].= $name;
1060    }
1061    return $arrList;
1062}
1063
1064// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ¡Ê¿Æ¥«¥Æ¥´¥ê¤ÎValue:0)
1065function sfGetLevelCatList($parent_zero = true) {
1066    $objQuery = new SC_Query();
1067    $col = "category_id, category_name, level";
1068    $where = "del_flg = 0";
1069    $objQuery->setoption("ORDER BY rank DESC");
1070    $arrRet = $objQuery->select($col, "dtb_category", $where);
1071    $max = count($arrRet);
1072   
1073    for($cnt = 0; $cnt < $max; $cnt++) {
1074        if($parent_zero) {
1075            if($arrRet[$cnt]['level'] == LEVEL_MAX) {
1076                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
1077            } else {
1078                $arrValue[$cnt] = "";
1079            }
1080        } else {
1081            $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
1082        }
1083       
1084        $arrOutput[$cnt] = "";
1085        /*         
1086        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
1087            $arrOutput[$cnt].= "¡¡";
1088        }
1089        */
1090        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
1091            $arrOutput[$cnt].= CATEGORY_HEAD;
1092        }
1093        $arrOutput[$cnt].= $arrRet[$cnt]['category_name'];
1094    }
1095    return array($arrValue, $arrOutput);
1096}
1097
1098function sfGetErrorColor($val) {
1099    if($val != "") {
1100        return "background-color:" . ERR_COLOR;
1101    }
1102    return "";
1103}
1104
1105
1106function sfGetEnabled($val) {
1107    if( ! $val ) {
1108        return " disabled=\"disabled\"";
1109    }
1110    return "";
1111}
1112
1113function sfGetChecked($param, $value) {
1114    if($param == $value) {
1115        return "checked=\"checked\"";
1116    }
1117    return "";
1118}
1119
1120// SELECT¥Ü¥Ã¥¯¥¹Íѥꥹ¥È¤ÎºîÀ®
1121function sfGetIDValueList($table, $keyname, $valname) {
1122    $objQuery = new SC_Query();
1123    $col = "$keyname, $valname";
1124    $objQuery->setwhere("del_flg = 0");
1125    $objQuery->setorder("rank DESC");
1126    $arrList = $objQuery->select($col, $table);
1127    $count = count($arrList);
1128    for($cnt = 0; $cnt < $count; $cnt++) {
1129        $key = $arrList[$cnt][$keyname];
1130        $val = $arrList[$cnt][$valname];
1131        $arrRet[$key] = $val;
1132    }
1133    return $arrRet;
1134}
1135
1136function sfTrim($str) {
1137    $ret = ereg_replace("^[¡¡ \n\r]*", "", $str);
1138    $ret = ereg_replace("[¡¡ \n\r]*$", "", $ret);
1139    return $ret;
1140}
1141
1142/* ½ê°¤¹¤ë¤¹¤Ù¤Æ¤Î³¬ÁؤοÆID¤òÇÛÎó¤ÇÊÖ¤¹ */
1143function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
1144    $arrRet = sfGetParentsArray($table, $pid_name, $id_name, $id);
1145    // ÇÛÎó¤ÎÀèƬ1¤Ä¤òºï½ü¤¹¤ë¡£
1146    array_shift($arrRet);
1147    return $arrRet;
1148}
1149
1150
1151/* ¿ÆID¤ÎÇÛÎó¤ò¸µ¤ËÆÃÄê¤Î¥«¥é¥à¤ò¼èÆÀ¤¹¤ë¡£*/
1152function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
1153    $col = $col_name;
1154    $len = count($arrId);
1155    $where = "";
1156   
1157    for($cnt = 0; $cnt < $len; $cnt++) {
1158        if($where == "") {
1159            $where = "$id_name = ?";
1160        } else {
1161            $where.= " OR $id_name = ?";
1162        }
1163    }
1164   
1165    $objQuery->setorder("level");
1166    $arrRet = $objQuery->select($col, $table, $where, $arrId);
1167    return $arrRet;
1168}
1169
1170/* »ÒID¤ÎÇÛÎó¤òÊÖ¤¹ */
1171function sfGetChildsID($table, $pid_name, $id_name, $id) {
1172    $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id);
1173    return $arrRet;
1174}
1175
1176/* ¥«¥Æ¥´¥êÊѹ¹»þ¤Î°ÜÆ°½èÍý */
1177function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
1178    if ($old_catid == $new_catid) {
1179        return;
1180    }
1181    // µì¥«¥Æ¥´¥ê¤Ç¤Î¥é¥ó¥¯ºï½ü½èÍý
1182    // °ÜÆ°¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£     
1183    $where = "$id_name = ?";
1184    $rank = $objQuery->get($table, "rank", $where, array($id));
1185    // ºï½ü¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤è¤ê¾å¤Î¥ì¥³¡¼¥É¤ò°ì¤Ä²¼¤Ë¤º¤é¤¹¡£
1186    $where = "rank > ? AND $cat_name = ?";
1187    $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1188    $objQuery->exec($sqlup, array($rank, $old_catid));
1189    // ¿·¥«¥Æ¥´¥ê¤Ç¤ÎÅÐÏ¿½èÍý
1190    // ¿·¥«¥Æ¥´¥ê¤ÎºÇÂç¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£
1191    $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
1192    $where = "$id_name = ?";
1193    $sqlup = "UPDATE $table SET rank = ? WHERE $where";
1194    $objQuery->exec($sqlup, array($max_rank, $id));
1195}
1196
1197/* ÀǶâ·×»» */
1198function sfTax($price, $tax, $tax_rule) {
1199    $real_tax = $tax / 100;
1200    $ret = $price * $real_tax;
1201    switch($tax_rule) {
1202    // »Í¼Î¸ÞÆþ
1203    case 1:
1204        $ret = round($ret);
1205        break;
1206    // ÀÚ¤ê¼Î¤Æ
1207    case 2:
1208        $ret = floor($ret);
1209        break;
1210    // ÀÚ¤ê¾å¤²
1211    case 3:
1212        $ret = ceil($ret);
1213        break;
1214    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1215    default:
1216        $ret = ceil($ret);
1217        break;
1218    }
1219    return $ret;
1220}
1221
1222/* ÀǶâÉÕÍ¿ */
1223function sfPreTax($price, $tax, $tax_rule) {
1224    $real_tax = $tax / 100;
1225    $ret = $price * (1 + $real_tax);
1226   
1227    switch($tax_rule) {
1228    // »Í¼Î¸ÞÆþ
1229    case 1:
1230        $ret = round($ret);
1231        break;
1232    // ÀÚ¤ê¼Î¤Æ
1233    case 2:
1234        $ret = floor($ret);
1235        break;
1236    // ÀÚ¤ê¾å¤²
1237    case 3:
1238        $ret = ceil($ret);
1239        break;
1240    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1241    default:
1242        $ret = ceil($ret);
1243        break;
1244    }
1245    return $ret;
1246}
1247
1248// ·å¿ô¤ò»ØÄꤷ¤Æ»Í¼Î¸ÞÆþ
1249function sfRound($value, $pow = 0){
1250    $adjust = pow(10 ,$pow-1);
1251
1252    // À°¿ô³î¤Ä0½Ð¤Ê¤±¤ì¤Ð·å¿ô»ØÄê¤ò¹Ô¤¦
1253    if(sfIsInt($adjust) and $pow > 1){
1254        $ret = (round($value * $adjust)/$adjust);
1255    }
1256   
1257    $ret = round($ret);
1258
1259    return $ret;
1260}
1261
1262/* ¥Ý¥¤¥ó¥ÈÉÕÍ¿ */
1263function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") {
1264    if(sfIsInt($product_id)) {
1265        $objQuery = new SC_Query();
1266        $where = "now() >= cast(start_date as date) AND ";
1267        $where .= "now() < cast(end_date as date) AND ";
1268       
1269        $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )";
1270        //ÅÐÏ¿(¹¹¿·)ÆüÉÕ½ç
1271        $objQuery->setorder('update_date DESC');
1272        //¥­¥ã¥ó¥Ú¡¼¥ó¥Ý¥¤¥ó¥È¤Î¼èÆÀ
1273        $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id));
1274    }
1275    //Ê£¿ô¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¾¦Éʤϡ¢ºÇ¿·¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤«¤é¥Ý¥¤¥ó¥È¤ò¼èÆÀ
1276    if($arrRet[0]['campaign_point_rate'] != "") {
1277        $campaign_point_rate = $arrRet[0]['campaign_point_rate'];
1278        $real_point = $campaign_point_rate / 100;
1279    } else {
1280        $real_point = $point_rate / 100;
1281    }
1282    $ret = $price * $real_point;
1283    switch($rule) {
1284    // »Í¼Î¸ÞÆþ
1285    case 1:
1286        $ret = round($ret);
1287        break;
1288    // ÀÚ¤ê¼Î¤Æ
1289    case 2:
1290        $ret = floor($ret);
1291        break;
1292    // ÀÚ¤ê¾å¤²
1293    case 3:
1294        $ret = ceil($ret);
1295        break;
1296    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1297    default:
1298        $ret = ceil($ret);
1299        break;
1300    }
1301    //¥­¥ã¥ó¥Ú¡¼¥ó¾¦Éʤξì¹ç
1302    if($campaign_point_rate != "") {
1303        $ret = "(".$arrRet[0]['campaign_name']."¥Ý¥¤¥ó¥ÈΨ".$campaign_point_rate."%)".$ret;
1304    }
1305    return $ret;
1306}
1307
1308/* µ¬³ÊʬÎà¤Î·ï¿ô¼èÆÀ */
1309function sfGetClassCatCount() {
1310    $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id ";
1311    $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id ";
1312    $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 ";
1313    $sql.= "group by dtb_class.class_id, dtb_class.name";
1314    $objQuery = new SC_Query();
1315    $arrList = $objQuery->getall($sql);
1316    // ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ
1317    $arrRet = sfArrKeyValue($arrList, 'class_id', 'count');
1318   
1319    return $arrRet;
1320}
1321
1322/* µ¬³Ê¤ÎÅÐÏ¿ */
1323function sfInsertProductClass($objQuery, $arrList, $product_id) {
1324    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£
1325    $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0";
1326    $count = $objQuery->count("dtb_products_class", $where,  array($product_id));
1327   
1328    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤Ê¤¤¾ì¹ç
1329    if($count == 0) {
1330        // ´û¸µ¬³Ê¤Îºï½ü
1331        $where = "product_id = ?";
1332        $objQuery->delete("dtb_products_class", $where, array($product_id));
1333        $sqlval['product_id'] = $product_id;
1334        $sqlval['classcategory_id1'] = '0';
1335        $sqlval['classcategory_id2'] = '0';
1336        $sqlval['product_code'] = $arrList["product_code"];
1337        $sqlval['stock'] = $arrList["stock"];
1338        $sqlval['stock_unlimited'] = $arrList["stock_unlimited"];
1339        $sqlval['price01'] = $arrList['price01'];
1340        $sqlval['price02'] = $arrList['price02'];
1341        $sqlval['creator_id'] = $_SESSION['member_id'];
1342        $sqlval['create_date'] = "now()";
1343       
1344        if($_SESSION['member_id'] == "") {
1345            $sqlval['creator_id'] = '0';
1346        }
1347       
1348        // INSERT¤Î¼Â¹Ô
1349        $objQuery->insert("dtb_products_class", $sqlval);
1350    }
1351}
1352
1353function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) {
1354    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1355    $objQuery = new SC_Query();
1356    $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2));
1357    return $ret;
1358}
1359
1360/* ʸËö¤Î¡Ö/¡×¤ò¤Ê¤¯¤¹ */
1361function sfTrimURL($url) {
1362    $ret = ereg_replace("[/]+$", "", $url);
1363    return $ret;
1364}
1365
1366/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
1367function sfGetProductsClass($arrID) {
1368    list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
1369   
1370    if($classcategory_id1 == "") {
1371        $classcategory_id1 = '0';
1372    }
1373    if($classcategory_id2 == "") {
1374        $classcategory_id2 = '0';
1375    }
1376       
1377    // ¾¦Éʵ¬³Ê¼èÆÀ
1378    $objQuery = new SC_Query();
1379    $col = "product_id, deliv_fee, name, product_code, main_list_image, main_image, price01, price02, point_rate, product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited, sale_limit, sale_unlimited";
1380    $table = "vw_product_class AS prdcls";
1381    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1382    $objQuery->setorder("rank1 DESC, rank2 DESC");
1383    $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
1384    return $arrRet[0];
1385}
1386
1387/* ½¸·×¾ðÊó¤ò¸µ¤ËºÇ½ª·×»» */
1388function sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo, $objCustomer = "") {
1389    // ¾¦Éʤιç·×¸Ä¿ô
1390    $total_quantity = $objCartSess->getTotalQuantity(true);
1391   
1392    // ÀǶâ¤Î¼èÆÀ
1393    $arrData['tax'] = $objPage->tpl_total_tax;
1394    // ¾®·×¤Î¼èÆÀ
1395    $arrData['subtotal'] = $objPage->tpl_total_pretax; 
1396   
1397    // ¹ç·×Á÷ÎÁ¤Î¼èÆÀ
1398    $arrData['deliv_fee'] = 0;
1399       
1400    // ¾¦Éʤ´¤È¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1401    if (OPTION_PRODUCT_DELIV_FEE == 1) {
1402        $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee();
1403    }
1404   
1405    // ÇÛÁ÷¶È¼Ô¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1406    if (OPTION_DELIV_FEE == 1) {
1407        // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1408        $arrData['deliv_fee']+= sfGetDelivFee($arrData['deliv_pref'], $arrData['payment_id']);
1409    }
1410   
1411    // Á÷ÎÁ̵ÎÁ¤Î¹ØÆþ¿ô¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1412    if(DELIV_FREE_AMOUNT > 0) {
1413        if($total_quantity >= DELIV_FREE_AMOUNT) {
1414            $arrData['deliv_fee'] = 0;
1415        }   
1416    }
1417       
1418    // Á÷ÎÁ̵ÎÁ¾ò·ï¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1419    if($arrInfo['free_rule'] > 0) {
1420        // ¾®·×¤¬ÌµÎÁ¾ò·ï¤òĶ¤¨¤Æ¤¤¤ë¾ì¹ç
1421        if($arrData['subtotal'] >= $arrInfo['free_rule']) {
1422            $arrData['deliv_fee'] = 0;
1423        }
1424    }
1425
1426    // ¹ç·×¤Î·×»»
1427    $arrData['total'] = $objPage->tpl_total_pretax; // ¾¦Éʹç·×
1428    $arrData['total']+= $arrData['deliv_fee'];      // Á÷ÎÁ
1429    $arrData['total']+= $arrData['charge'];         // ¼ê¿ôÎÁ
1430    // ¤ª»Ùʧ¤¤¹ç·×
1431    $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
1432    // ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»
1433    $arrData['add_point'] = sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
1434   
1435    if($objCustomer != "") {
1436        // ÃÂÀ¸Æü·î¤Ç¤¢¤Ã¤¿¾ì¹ç
1437        if($objCustomer->isBirthMonth()) {
1438            $arrData['birth_point'] = BIRTH_MONTH_POINT;
1439            $arrData['add_point'] += $arrData['birth_point'];
1440        }
1441    }
1442   
1443    if($arrData['add_point'] < 0) {
1444        $arrData['add_point'] = 0;
1445    }
1446   
1447    return $arrData;
1448}
1449
1450/* ¥«¡¼¥ÈÆ⾦Éʤν¸·×½èÍý */
1451function sfTotalCart($objPage, $objCartSess, $arrInfo) {
1452    // µ¬³Ê̾°ìÍ÷
1453    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
1454    // µ¬³ÊʬÎà̾°ìÍ÷
1455    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
1456   
1457    $objPage->tpl_total_pretax = 0;     // ÈñÍѹç·×(Àǹþ¤ß)
1458    $objPage->tpl_total_tax = 0;        // ¾ÃÈñÀǹç·×
1459    $objPage->tpl_total_point = 0;      // ¥Ý¥¤¥ó¥È¹ç·×
1460   
1461    // ¥«¡¼¥ÈÆâ¾ðÊó¤Î¼èÆÀ
1462    $arrCart = $objCartSess->getCartList();
1463    $max = count($arrCart);
1464    $cnt = 0;
1465
1466    for ($i = 0; $i < $max; $i++) {
1467        // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
1468        $arrData = sfGetProductsClass($arrCart[$i]['id']);
1469        $limit = "";
1470        // DB¤Ë¸ºß¤¹¤ë¾¦ÉÊ
1471        if (count($arrData) > 0) {
1472           
1473            // ¹ØÆþÀ©¸Â¿ô¤òµá¤á¤ë¡£         
1474            if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
1475                if($arrData['sale_limit'] < $arrData['stock']) {
1476                    $limit = $arrData['sale_limit'];
1477                } else {
1478                    $limit = $arrData['stock'];
1479                }
1480            } else {
1481                if ($arrData['sale_unlimited'] != '1') {
1482                    $limit = $arrData['sale_limit'];
1483                }
1484                if ($arrData['stock_unlimited'] != '1') {
1485                    $limit = $arrData['stock'];
1486                }
1487            }
1488                       
1489            if($limit != "" && $limit < $arrCart[$i]['quantity']) {
1490                // ¥«¡¼¥ÈÆ⾦ÉÊ¿ô¤òÀ©¸Â¤Ë¹ç¤ï¤»¤ë
1491                $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
1492                $quantity = $limit;
1493                $objPage->tpl_message = "¢¨¡Ö" . $arrData['name'] . "¡×¤ÏÈÎÇäÀ©¸Â¤·¤Æ¤ª¤ê¤Þ¤¹¡¢°ìÅ٤ˤ³¤ì°Ê¾å¤Î¹ØÆþ¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
1494            } else {
1495                $quantity = $arrCart[$i]['quantity'];
1496            }
1497           
1498            $objPage->arrProductsClass[$cnt] = $arrData;
1499            $objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
1500            $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
1501            $objPage->arrProductsClass[$cnt]['class_name1'] = $arrClassName[$arrData['class_id1']];
1502            $objPage->arrProductsClass[$cnt]['class_name2'] = $arrClassName[$arrData['class_id2']];
1503            $objPage->arrProductsClass[$cnt]['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']];
1504            $objPage->arrProductsClass[$cnt]['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']];
1505           
1506            // ²èÁü¥µ¥¤¥º
1507            list($image_width, $image_height) = getimagesize(IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]));
1508            $objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;
1509            $objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;
1510           
1511            // ²Á³Ê¤ÎÅÐÏ¿
1512            if ($arrData['price02'] != "") {
1513                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
1514                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
1515            } else {
1516                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
1517                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
1518            }
1519            // ¥Ý¥¤¥ó¥ÈÉÕͿΨ¤ÎÅÐÏ¿
1520            $objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
1521            // ¾¦Éʤ´¤È¤Î¹ç·×¶â³Û
1522            $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
1523            // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1524            $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
1525            $cnt++;
1526        } else {
1527            // DB¤Ë¾¦Éʤ¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥«¡¼¥È¾¦Éʤκï½ü
1528            $objCartSess->delProductKey('id', $arrCart[$i]['id']);
1529        }
1530    }
1531   
1532    // Á´¾¦Éʹç·×¶â³Û(Àǹþ¤ß)
1533    $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
1534    // Á´¾¦Éʹç·×¾ÃÈñÀÇ
1535    $objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
1536    // Á´¾¦Éʹç·×¥Ý¥¤¥ó¥È
1537    $objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
1538   
1539    return $objPage;   
1540}
1541
1542/* DB¤«¤é¼è¤ê½Ð¤·¤¿ÆüÉÕ¤Îʸ»úÎó¤òÄ´À°¤¹¤ë¡£*/
1543function sfDispDBDate($dbdate, $time = true) {
1544    list($y, $m, $d, $H, $M) = split("[- :]", $dbdate);
1545
1546    if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) {
1547        if ($time) {
1548            $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M);
1549        } else {
1550            $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M);                       
1551        }
1552    } else {
1553        $str = "";
1554    }
1555    return $str;
1556}
1557
1558function sfGetDelivTime($payment_id = "") {
1559    $objQuery = new SC_Query();
1560   
1561    $deliv_id = "";
1562   
1563    if($payment_id != "") {
1564        $where = "del_flg = 0 AND payment_id = ?";
1565        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1566        $deliv_id = $arrRet[0]['deliv_id'];
1567    }
1568   
1569    if($deliv_id != "") {
1570        $objQuery->setorder("time_id");
1571        $where = "deliv_id = ?";
1572        $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
1573    }
1574   
1575    return $arrRet;
1576}
1577
1578
1579// ÅÔÆ»Éܸ©¡¢»Ùʧ¤¤ÊýË¡¤«¤éÇÛÁ÷ÎÁ¶â¤ò¼èÆÀ¤¹¤ë
1580function sfGetDelivFee($pref, $payment_id = "") {
1581    $objQuery = new SC_Query();
1582   
1583    $deliv_id = "";
1584   
1585    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢Âбþ¤·¤¿ÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1586    if($payment_id != "") {
1587        $where = "del_flg = 0 AND payment_id = ?";
1588        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1589        $deliv_id = $arrRet[0]['deliv_id'];
1590    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÀèƬ¤ÎÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1591    } else {
1592        $where = "del_flg = 0";
1593        $objQuery->setOrder("rank DESC");
1594        $objQuery->setLimitOffset(1);
1595        $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
1596        $deliv_id = $arrRet[0]['deliv_id'];
1597    }
1598   
1599    // ÇÛÁ÷¶È¼Ô¤«¤éÇÛÁ÷ÎÁ¤ò¼èÆÀ
1600    if($deliv_id != "") {
1601       
1602        // ÅÔÆ»Éܸ©¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÅìµþÅÔ¤ÎÈÖ¹æ¤ò»ØÄꤷ¤Æ¤ª¤¯
1603        if($pref == "") {
1604            $pref = 13;
1605        }
1606       
1607        $objQuery = new SC_Query();
1608        $where = "deliv_id = ? AND pref = ?";
1609        $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
1610    }   
1611    return $arrRet[0]['fee'];   
1612}
1613
1614/* »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ */
1615function sfGetPayment() {
1616    $objQuery = new SC_Query();
1617    // ¹ØÆþ¶â³Û¤¬¾ò·ï³Û°Ê²¼¤Î¹àÌܤò¼èÆÀ
1618    $where = "del_flg = 0";
1619    $objQuery->setorder("fix, rank DESC");
1620    $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
1621    return $arrRet;
1622}
1623
1624/* ÇÛÎó¤ò¥­¡¼Ì¾¤´¤È¤ÎÇÛÎó¤ËÊѹ¹¤¹¤ë */
1625function sfSwapArray($array) {
1626    $max = count($array);
1627    for($i = 0; $i < $max; $i++) {
1628        foreach($array[$i] as $key => $val) {
1629            $arrRet[$key][] = $val;
1630        }
1631    }
1632    return $arrRet;
1633}
1634
1635/* ¤«¤±»»¤ò¤¹¤ë¡ÊSmartyÍÑ) */
1636function sfMultiply($num1, $num2) {
1637    return ($num1 * $num2);
1638}
1639
1640/* DB¤ËÅÐÏ¿¤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¥á¡¼¥ë¤ÎÁ÷¿® */
1641function sfSendTemplateMail($to, $to_name, $template_id, $objPage) {
1642    global $arrMAILTPLPATH;
1643    $objQuery = new SC_Query();
1644    // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1645    $where = "template_id = ?";
1646    $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
1647    $objPage->tpl_header = $arrRet[0]['header'];
1648    $objPage->tpl_footer = $arrRet[0]['footer'];
1649    $tmp_subject = $arrRet[0]['subject'];
1650   
1651    $objSiteInfo = new SC_SiteInfo();
1652    $arrInfo = $objSiteInfo->data;
1653   
1654    $objMailView = new SC_SiteView();
1655    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1656    $objMailView->assignobj($objPage);
1657    $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]);
1658   
1659    // ¥á¡¼¥ëÁ÷¿®½èÍý
1660    $objSendMail = new GC_SendMail();
1661    $from = $arrInfo['email03'];
1662    $error = $arrInfo['email04'];
1663    $tosubject = $tmp_subject;
1664    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error);
1665    $objSendMail->setTo($to, $to_name);
1666    $objSendMail->sendMail();   // ¥á¡¼¥ëÁ÷¿®
1667}
1668
1669/* ¼õÃí´°Î»¥á¡¼¥ëÁ÷¿® */
1670function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
1671    global $arrMAILTPLPATH;
1672   
1673    $objPage = new LC_Page();
1674    $objSiteInfo = new SC_SiteInfo();
1675    $arrInfo = $objSiteInfo->data;
1676    $objPage->arrInfo = $arrInfo;
1677   
1678    $objQuery = new SC_Query();
1679       
1680    if($subject == "" && $header == "" && $footer == "") {
1681        // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1682        $where = "template_id = ?";
1683        $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array('1'));
1684        $objPage->tpl_header = $arrRet[0]['header'];
1685        $objPage->tpl_footer = $arrRet[0]['footer'];
1686        $tmp_subject = $arrRet[0]['subject'];
1687    } else {
1688        $objPage->tpl_header = $header;
1689        $objPage->tpl_footer = $footer;
1690        $tmp_subject = $subject;
1691    }
1692   
1693    // ¼õÃí¾ðÊó¤Î¼èÆÀ
1694    $where = "order_id = ?";
1695    $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
1696    $arrOrder = $arrRet[0];
1697    $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
1698   
1699    $objPage->Message_tmp = $arrOrder['message'];
1700       
1701    // ¸ÜµÒ¾ðÊó¤Î¼èÆÀ
1702    $customer_id = $arrOrder['customer_id'];
1703    $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
1704    $arrCustomer = $arrRet[0];
1705
1706    $objPage->arrCustomer = $arrCustomer;
1707    $objPage->arrOrder = $arrOrder;
1708
1709    //¤½¤Î¾·èºÑ¾ðÊó
1710    if($arrOrder['memo02'] != "") {
1711        $arrOther = unserialize($arrOrder['memo02']);
1712       
1713        foreach($arrOther as $other_key => $other_val){
1714            if(sfTrim($other_val["value"]) == ""){
1715                $arrOther[$other_key]["value"] = "";
1716            }
1717        }
1718       
1719        $objPage->arrOther = $arrOther;
1720    }
1721
1722    // ÅÔÆ»Éܸ©ÊÑ´¹
1723    global $arrPref;
1724    $objPage->arrOrder['deliv_pref'] = $arrPref[$objPage->arrOrder['deliv_pref']];
1725   
1726    $objPage->arrOrderDetail = $arrOrderDetail;
1727   
1728    $objCustomer = new SC_Customer();
1729    $objPage->tpl_user_point = $objCustomer->getValue('point');
1730   
1731    $objMailView = new SC_SiteView();
1732    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1733    $objMailView->assignobj($objPage);
1734    $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]);
1735   
1736    // ¥á¡¼¥ëÁ÷¿®½èÍý
1737    $objSendMail = new GC_SendMail();
1738    $bcc = $arrInfo['email01'];
1739    $from = $arrInfo['email03'];
1740    $error = $arrInfo['email04'];
1741   
1742    $tosubject = sfMakeSubject($tmp_subject);
1743   
1744    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1745    $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." ÍÍ");
1746
1747
1748    // Á÷¿®¥Õ¥é¥°:true¤Î¾ì¹ç¤Ï¡¢Á÷¿®¤¹¤ë¡£
1749    if($send) {
1750        if ($objSendMail->sendMail()) {
1751            sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
1752        }
1753    }
1754
1755    return $objSendMail;
1756}
1757
1758// ¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ·¤¿¥á¡¼¥ë¤ÎÁ÷¿®
1759function sfSendTplMail($to, $subject, $tplpath, $objPage) {
1760    $objMailView = new SC_SiteView();
1761    $objSiteInfo = new SC_SiteInfo();
1762    $arrInfo = $objSiteInfo->data;
1763    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1764    $objPage->tpl_shopname=$arrInfo['shop_name'];
1765    $objPage->tpl_infoemail = $arrInfo['email02'];
1766    $objMailView->assignobj($objPage);
1767    $body = $objMailView->fetch($tplpath);
1768    // ¥á¡¼¥ëÁ÷¿®½èÍý
1769    $objSendMail = new GC_SendMail();
1770    $to = mb_encode_mimeheader($to);
1771    $bcc = $arrInfo['email01'];
1772    $from = $arrInfo['email03'];
1773    $error = $arrInfo['email04'];
1774    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1775    $objSendMail->sendMail();   
1776}
1777
1778// Ä̾ï¤Î¥á¡¼¥ëÁ÷¿®
1779function sfSendMail($to, $subject, $body) {
1780    $objSiteInfo = new SC_SiteInfo();
1781    $arrInfo = $objSiteInfo->data;
1782    // ¥á¡¼¥ëÁ÷¿®½èÍý
1783    $objSendMail = new GC_SendMail();
1784    $bcc = $arrInfo['email01'];
1785    $from = $arrInfo['email03'];
1786    $error = $arrInfo['email04'];
1787    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1788    $objSendMail->sendMail();
1789}
1790
1791//·ï̾¤Ë¥Æ¥ó¥×¥ì¡¼¥È¤òÍѤ¤¤ë
1792function sfMakeSubject($subject){
1793   
1794    $objQuery = new SC_Query();
1795    $objMailView = new SC_SiteView();
1796    $objPage = new LC_Page();
1797   
1798    $arrInfo = $objQuery->select("*","dtb_baseinfo");
1799    $arrInfo = $arrInfo[0];
1800    $objPage->tpl_shopname=$arrInfo['shop_name'];
1801    $objPage->tpl_infoemail=$subject;
1802    $objMailView->assignobj($objPage);
1803    $mailtitle = $objMailView->fetch('mail_templates/mail_title.tpl');
1804    $ret = $mailtitle.$subject;
1805    return $ret;
1806}
1807
1808// ¥á¡¼¥ëÇÛ¿®ÍúÎò¤Ø¤ÎÅÐÏ¿
1809function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
1810    $sqlval['subject'] = $subject;
1811    $sqlval['order_id'] = $order_id;
1812    $sqlval['template_id'] = $template_id;
1813    $sqlval['send_date'] = "Now()";
1814    if($_SESSION['member_id'] != "") {
1815        $sqlval['creator_id'] = $_SESSION['member_id'];
1816    } else {
1817        $sqlval['creator_id'] = '0';
1818    }
1819    $sqlval['mail_body'] = $body;
1820   
1821    $objQuery = new SC_Query();
1822    $objQuery->insert("dtb_mail_history", $sqlval);
1823}
1824
1825/* ²ñ°÷¾ðÊó¤ò°ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤Ø */
1826function sfGetCustomerSqlVal($uniqid, $sqlval) {
1827    $objCustomer = new SC_Customer();
1828    // ²ñ°÷¾ðÊóÅÐÏ¿½èÍý
1829    if ($objCustomer->isLoginSuccess()) {
1830        // ÅÐÏ¿¥Ç¡¼¥¿¤ÎºîÀ®
1831        $sqlval['order_temp_id'] = $uniqid;
1832        $sqlval['update_date'] = 'Now()';
1833        $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
1834        $sqlval['order_name01'] = $objCustomer->getValue('name01');
1835        $sqlval['order_name02'] = $objCustomer->getValue('name02');
1836        $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
1837        $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
1838        $sqlval['order_sex'] = $objCustomer->getValue('sex');
1839        $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
1840        $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
1841        $sqlval['order_pref'] = $objCustomer->getValue('pref');
1842        $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
1843        $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
1844        $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
1845        $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
1846        $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
1847        if (defined('MOBILE_SITE')) {
1848            $sqlval['order_email'] = $objCustomer->getValue('email_mobile');
1849        } else {
1850            $sqlval['order_email'] = $objCustomer->getValue('email');
1851        }
1852        $sqlval['order_job'] = $objCustomer->getValue('job');
1853        $sqlval['order_birth'] = $objCustomer->getValue('birth');
1854    }
1855    return $sqlval;
1856}
1857
1858// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Ø¤Î½ñ¤­¹þ¤ß½èÍý
1859function sfRegistTempOrder($uniqid, $sqlval) {
1860    if($uniqid != "") {
1861        // ´û¸¥Ç¡¼¥¿¤Î¥Á¥§¥Ã¥¯
1862        $objQuery = new SC_Query();
1863        $where = "order_temp_id = ?";
1864        $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
1865        // ´û¸¥Ç¡¼¥¿¤¬¤Ê¤¤¾ì¹ç
1866        if ($cnt == 0) {
1867            // ½é²ó½ñ¤­¹þ¤ß»þ¤Ë²ñ°÷¤ÎÅÐÏ¿ºÑ¤ß¾ðÊó¤ò¼è¤ê¹þ¤à
1868            $sqlval = sfGetCustomerSqlVal($uniqid, $sqlval);
1869            $sqlval['create_date'] = "now()";
1870            $objQuery->insert("dtb_order_temp", $sqlval);
1871        } else {
1872            $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
1873        }
1874    }
1875}
1876
1877/* ²ñ°÷¤Î¥á¥ë¥Þ¥¬ÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤Î¥Á¥§¥Ã¥¯(²¾²ñ°÷¤ò´Þ¤Þ¤Ê¤¤) */
1878function sfCheckCustomerMailMaga($email) {
1879    $col = "email, mailmaga_flg, customer_id";
1880    $from = "dtb_customer";
1881    $where = "email = ? AND status = 2";
1882    $objQuery = new SC_Query();
1883    $arrRet = $objQuery->select($col, $from, $where, array($email));
1884    // ²ñ°÷¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë
1885    if($arrRet[0]['customer_id'] != "") {
1886        return true;
1887    }
1888    return false;
1889}
1890
1891// ¥«¡¼¥É¤Î½èÍý·ë²Ì¤òÊÖ¤¹
1892function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){
1893
1894    $path = $dir .$file_name;       // cgi¥Õ¥¡¥¤¥ë¤Î¥Õ¥ë¥Ñ¥¹À¸À®
1895    $now_dir = getcwd();            // require¤¬¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¤Î¤Ç¡¢cgi¼Â¹Ô¥Ç¥£¥ì¥¯¥È¥ê¤Ë°ÜÆ°¤¹¤ë
1896    chdir($dir);
1897   
1898    // ¥Ñ¥¤¥×ÅϤ·¤Ç¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤écgiµ¯Æ°
1899    $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info";
1900
1901    $tmpResult = popen($cmd, "r");
1902   
1903    // ·ë²Ì¼èÆÀ
1904    while( ! FEOF ( $tmpResult ) ) {
1905        $result .= FGETS($tmpResult);
1906    }
1907    pclose($tmpResult);             //  ¥Ñ¥¤¥×¤òÊĤ¸¤ë
1908    chdir($now_dir);                //¡¡¸µ¤Ë¤¤¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Ëµ¢¤ë
1909   
1910    // ·ë²Ì¤òÏ¢ÁÛÇÛÎó¤Ø³ÊǼ
1911    $result = ereg_replace("&$", "", $result);
1912    foreach (explode("&",$result) as $data) {
1913        list($key, $val) = explode("=", $data, 2);
1914        $return[$key] = $val;
1915    }
1916   
1917    return $return;
1918}
1919
1920// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¾ðÊó¤ò¼èÆÀ¤¹¤ë
1921function sfGetOrderTemp($order_temp_id) {
1922    $objQuery = new SC_Query();
1923    $where = "order_temp_id = ?";
1924    $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
1925    return $arrRet[0];
1926}
1927
1928// ¥«¥Æ¥´¥êID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
1929$g_category_on = false;
1930$g_category_id = "";
1931
1932/* ÁªÂòÃæ¤Î¥«¥Æ¥´¥ê¤ò¼èÆÀ¤¹¤ë */
1933function sfGetCategoryId($product_id, $category_id) {
1934    global $g_category_on;
1935    global $g_category_id;
1936    if(!$g_category_on) {
1937        $g_category_on = true;
1938        if(sfIsRealInt($category_id) && sfIsRecord("dtb_category","category_id", $category_id)) {
1939            $g_category_id = $category_id;
1940        } else if (sfIsRealInt($product_id) && sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) {
1941            $objQuery = new SC_Query();
1942            $where = "product_id = ?";
1943            $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id));
1944            $g_category_id = $category_id;
1945        } else {
1946            // ÉÔÀµ¤Ê¾ì¹ç¤Ï¡¢0¤òÊÖ¤¹¡£
1947            $g_category_id = 0;
1948        }
1949    }
1950    return $g_category_id;
1951}
1952
1953// ROOTID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
1954$g_root_on = false;
1955$g_root_id = "";
1956
1957/* ÁªÂòÃæ¤Î¥¢¥¤¥Æ¥à¤Î¥ë¡¼¥È¥«¥Æ¥´¥êID¤ò¼èÆÀ¤¹¤ë */
1958function sfGetRootId() {
1959    global $g_root_on;
1960    global $g_root_id;
1961    if(!$g_root_on) {
1962        $g_root_on = true;
1963        $objQuery = new SC_Query();
1964        if($_GET['product_id'] != "" || $_GET['category_id'] != "") {
1965            // ÁªÂòÃæ¤Î¥«¥Æ¥´¥êID¤òȽÄꤹ¤ë
1966            $category_id = sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
1967            // ROOT¥«¥Æ¥´¥êID¤Î¼èÆÀ
1968             $arrRet = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
1969             $root_id = $arrRet[0];
1970        } else {
1971            // ROOT¥«¥Æ¥´¥êID¤ò¤Ê¤·¤ËÀßÄꤹ¤ë
1972            $root_id = "";
1973        }
1974        $g_root_id = $root_id;
1975    }
1976    return $g_root_id;
1977}
1978
1979/* ¥«¥Æ¥´¥ê¤«¤é¾¦Éʤò¸¡º÷¤¹¤ë¾ì¹ç¤ÎWHEREʸ¤ÈÃͤòÊÖ¤¹ */
1980function sfGetCatWhere($category_id) {
1981    // »Ò¥«¥Æ¥´¥êID¤Î¼èÆÀ
1982    $arrRet = sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
1983    $tmp_where = "";
1984    foreach ($arrRet as $val) {
1985        if($tmp_where == "") {
1986            $tmp_where.= " category_id IN ( ?";
1987        } else {
1988            $tmp_where.= ",? ";
1989        }
1990        $arrval[] = $val;
1991    }
1992    $tmp_where.= " ) ";
1993    return array($tmp_where, $arrval);
1994}
1995
1996/* ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»¼° */
1997function sfGetAddPoint($totalpoint, $use_point, $arrInfo) {
1998    // ¹ØÆþ¾¦Éʤιç·×¥Ý¥¤¥ó¥È¤«¤éÍøÍѤ·¤¿¥Ý¥¤¥ó¥È¤Î¥Ý¥¤¥ó¥È´¹»»²ÁÃͤò°ú¤¯Êý¼°
1999    $add_point = $totalpoint - intval($use_point * ($arrInfo['point_rate'] / 100));
2000   
2001    if($add_point < 0) {
2002        $add_point = '0';
2003    }
2004    return $add_point;
2005}
2006
2007/* °ì°Õ¤«¤Äͽ¬¤µ¤ì¤Ë¤¯¤¤ID */
2008function sfGetUniqRandomId($head = "") {
2009    // ͽ¬¤µ¤ì¤Ê¤¤¤è¤¦¤Ë¥é¥ó¥À¥àʸ»úÎó¤òÉÕÍ¿¤¹¤ë¡£
2010    $random = gfMakePassword(8);
2011    // Ʊ°ì¥Û¥¹¥ÈÆâ¤Ç°ì°Õ¤ÊID¤òÀ¸À®
2012    $id = uniqid($head);
2013    return ($id . $random);
2014}
2015
2016// ¥«¥Æ¥´¥êÊÌ¥ª¥¹¥¹¥áÉʤμèÆÀ
2017function sfGetBestProducts( $conn, $category_id = 0){
2018    // ´û¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ëÆâÍƤò¼èÆÀ¤¹¤ë
2019    $sql = "SELECT name, main_image, main_list_image, price01_min, price01_max, price02_min, price02_max, point_rate,
2020             A.product_id, A.comment FROM dtb_best_products as A LEFT JOIN vw_products_allclass AS allcls
2021            USING (product_id) WHERE A.category_id = ? AND A.del_flg = 0 AND status = 1 ORDER BY A.rank";
2022    $arrItems = $conn->getAll($sql, array($category_id));
2023
2024    return $arrItems;
2025}
2026
2027// ÆüìÀ©¸æʸ»ú¤Î¼êÆ°¥¨¥¹¥±¡¼¥×
2028function sfManualEscape($data) {
2029    // ÇÛÎó¤Ç¤Ê¤¤¾ì¹ç
2030    if(!is_array($data)) {
2031        if (DB_TYPE == "pgsql") {
2032            $ret = pg_escape_string($data);
2033        }else if(DB_TYPE == "mysql"){
2034            $ret = mysql_real_escape_string($data);
2035        }
2036        $ret = ereg_replace("%", "\\%", $ret);
2037        $ret = ereg_replace("_", "\\_", $ret);
2038        return $ret;
2039    }
2040   
2041    // ÇÛÎó¤Î¾ì¹ç
2042    foreach($data as $val) {
2043        if (DB_TYPE == "pgsql") {
2044            $ret = pg_escape_string($val);
2045        }else if(DB_TYPE == "mysql"){
2046            $ret = mysql_real_escape_string($val);
2047        }
2048
2049        $ret = ereg_replace("%", "\\%", $ret);
2050        $ret = ereg_replace("_", "\\_", $ret);
2051        $arrRet[] = $ret;
2052    }
2053
2054    return $arrRet;
2055}
2056
2057// ¼õÃíÈֹ桢ÍøÍѥݥ¤¥ó¥È¡¢²Ã»»¥Ý¥¤¥ó¥È¤«¤éºÇ½ª¥Ý¥¤¥ó¥È¤ò¼èÆÀ
2058function sfGetCustomerPoint($order_id, $use_point, $add_point) {
2059    $objQuery = new SC_Query();
2060    $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
2061    $customer_id = $arrRet[0]['customer_id'];
2062    if($customer_id != "" && $customer_id >= 1) {
2063        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
2064        $point = $arrRet[0]['point'];
2065        $total_point = $arrRet[0]['point'] - $use_point + $add_point;
2066    } else {
2067        $total_point = "";
2068        $point = "";
2069    }
2070    return array($point, $total_point);
2071}
2072
2073/* ¥É¥á¥¤¥ó´Ö¤ÇÍ­¸ú¤Ê¥»¥Ã¥·¥ç¥ó¤Î¥¹¥¿¡¼¥È */
2074function sfDomainSessionStart() {
2075    $ret = session_id();
2076/*
2077    ¥Ø¥Ã¥À¡¼¤òÁ÷¿®¤·¤Æ¤¤¤Æ¤âsession_start()¤¬É¬Íפʥڡ¼¥¸¤¬¤¢¤ë¤Î¤Ç
2078    ¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ¤ª¤¯
2079    if($ret == "" && !headers_sent()) {
2080*/
2081    if($ret == "") {
2082        /* ¥»¥Ã¥·¥ç¥ó¥Ñ¥é¥á¡¼¥¿¤Î»ØÄê
2083         ¡¦¥Ö¥é¥¦¥¶¤òÊĤ¸¤ë¤Þ¤ÇÍ­¸ú
2084         ¡¦¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤ÇÍ­¸ú
2085         ¡¦Æ±¤¸¥É¥á¥¤¥ó´Ö¤Ç¶¦Í­ */
2086        session_set_cookie_params (0, "/", DOMAIN_NAME);
2087
2088        if(!ini_get("session.auto_start")){
2089            // ¥»¥Ã¥·¥ç¥ó³«»Ï
2090            session_start();
2091        }
2092    }
2093}
2094
2095/* ʸ»úÎó¤Ë¶¯À©Åª¤Ë²þ¹Ô¤òÆþ¤ì¤ë */
2096function sfPutBR($str, $size) {
2097    $i = 0;
2098    $cnt = 0;
2099    $line = array();
2100    $ret = "";
2101   
2102    while($str[$i] != "") {
2103        $line[$cnt].=$str[$i];
2104        $i++;
2105        if(strlen($line[$cnt]) > $size) {
2106            $line[$cnt].="<br />";
2107            $cnt++;
2108        }
2109    }
2110   
2111    foreach($line as $val) {
2112        $ret.=$val;
2113    }
2114    return $ret;
2115}
2116
2117// Æó²ó°Ê¾å·«¤êÊÖ¤µ¤ì¤Æ¤¤¤ë¥¹¥é¥Ã¥·¥å[/]¤ò°ì¤Ä¤ËÊÑ´¹¤¹¤ë¡£
2118function sfRmDupSlash($istr){
2119    if(ereg("^http://", $istr)) {
2120        $str = substr($istr, 7);
2121        $head = "http://";
2122    } else if(ereg("^https://", $istr)) {
2123        $str = substr($istr, 8);
2124        $head = "https://";
2125    } else {
2126        $str = $istr;
2127    }
2128    $str = ereg_replace("[/]+", "/", $str);
2129    $ret = $head . $str;
2130    return $ret;   
2131}
2132
2133function sfEncodeFile($filepath, $enc_type, $out_dir) {
2134    $ifp = fopen($filepath, "r");
2135   
2136    $basename = basename($filepath);
2137    $outpath = $out_dir . "enc_" . $basename;
2138   
2139    $ofp = fopen($outpath, "w+");
2140   
2141    while(!feof($ifp)) {
2142        $line = fgets($ifp);
2143        $line = mb_convert_encoding($line, $enc_type, "auto");
2144        fwrite($ofp,  $line);
2145    }
2146   
2147    fclose($ofp);
2148    fclose($ifp);
2149   
2150    return  $outpath;
2151}
2152
2153function sfCutString($str, $len, $byte = true, $commadisp = true) {
2154    if($byte) {
2155        if(strlen($str) > ($len + 2)) {
2156            $ret =substr($str, 0, $len);
2157            $cut = substr($str, $len);
2158        } else {
2159            $ret = $str;
2160            $commadisp = false;
2161        }
2162    } else {
2163        if(mb_strlen($str) > ($len + 1)) {
2164            $ret = mb_substr($str, 0, $len);
2165            $cut = mb_substr($str, $len);
2166        } else {
2167            $ret = $str;
2168            $commadisp = false;
2169        }
2170    }
2171
2172    // ³¨Ê¸»ú¥¿¥°¤ÎÅÓÃæ¤ÇʬÃǤµ¤ì¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£
2173    if (isset($cut)) {
2174        // ʬ³ä°ÌÃÖ¤è¤êÁ°¤ÎºÇ¸å¤Î [ °Ê¹ß¤ò¼èÆÀ¤¹¤ë¡£
2175        $head = strrchr($ret, '[');
2176
2177        // ʬ³ä°ÌÃÖ¤è¤ê¸å¤ÎºÇ½é¤Î ] °ÊÁ°¤ò¼èÆÀ¤¹¤ë¡£
2178        $tail_pos = strpos($cut, ']');
2179        if ($tail_pos !== false) {
2180            $tail = substr($cut, 0, $tail_pos + 1);
2181        }
2182
2183        // ʬ³ä°ÌÃÖ¤è¤êÁ°¤Ë [¡¢¸å¤Ë ] ¤¬¸«¤Ä¤«¤Ã¤¿¾ì¹ç¤Ï¡¢[ ¤«¤é ] ¤Þ¤Ç¤ò
2184        // Àܳ¤·¤Æ³¨Ê¸»ú¥¿¥°1¸Äʬ¤Ë¤Ê¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£
2185        if ($head !== false && $tail_pos !== false) {
2186            $subject = $head . $tail;
2187            if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) {
2188                // ³¨Ê¸»ú¥¿¥°¤¬¸«¤Ä¤«¤Ã¤¿¤Î¤Çºï½ü¤¹¤ë¡£
2189                $ret = substr($ret, 0, -strlen($head));
2190            }
2191        }
2192    }
2193
2194    if($commadisp){
2195        $ret = $ret . "...";
2196    }
2197    return $ret;
2198}
2199
2200// ǯ¡¢·î¡¢Äù¤áÆü¤«¤é¡¢Àè·î¤ÎÄù¤áÆü+1¡¢º£·î¤ÎÄù¤áÆü¤òµá¤á¤ë¡£
2201function sfTermMonth($year, $month, $close_day) {
2202    $end_year = $year;
2203    $end_month = $month;
2204   
2205    // ³«»Ï·î¤¬½ªÎ»·î¤ÈƱ¤¸¤«Èݤ«
2206    $same_month = false;
2207   
2208    // ³ºÅö·î¤ÎËöÆü¤òµá¤á¤ë¡£
2209    $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year));
2210   
2211    // ·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2212    if($end_last_day < $close_day) {
2213        // Äù¤áÆü¤ò·îËöÆü¤Ë¹ç¤ï¤»¤ë
2214        $end_day = $end_last_day;
2215    } else {
2216        $end_day = $close_day;
2217    }
2218   
2219    // Á°·î¤Î¼èÆÀ
2220    $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year));
2221    $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year));
2222    // Á°·î¤ÎËöÆü¤òµá¤á¤ë¡£
2223    $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year));
2224   
2225    // Á°·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2226    if ($start_last_day < $close_day) {
2227        // ·îËöÆü¤Ë¹ç¤ï¤»¤ë
2228        $tmp_day = $start_last_day;
2229    } else {
2230        $tmp_day = $close_day;
2231    }
2232   
2233    // Àè·î¤ÎËöÆü¤ÎÍâÆü¤ò¼èÆÀ¤¹¤ë
2234    $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2235    $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2236    $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2237   
2238    // ÆüÉդκîÀ®
2239    $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day);
2240    $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day);
2241   
2242    return array($start_date, $end_date);
2243}
2244
2245// PDFÍѤÎRGB¥«¥é¡¼¤òÊÖ¤¹
2246function sfGetPdfRgb($hexrgb) {
2247    $hex = substr($hexrgb, 0, 2);
2248    $r = hexdec($hex) / 255;
2249   
2250    $hex = substr($hexrgb, 2, 2);
2251    $g = hexdec($hex) / 255;
2252   
2253    $hex = substr($hexrgb, 4, 2);
2254    $b = hexdec($hex) / 255;
2255   
2256    return array($r, $g, $b);   
2257}
2258
2259//¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤È¥á¡¼¥ëÇÛ¿®
2260function sfRegistTmpMailData($mail_flag, $email){
2261    $objQuery = new SC_Query();
2262    $objConn = new SC_DBConn();
2263    $objPage = new LC_Page();
2264   
2265    $random_id = sfGetUniqRandomId();
2266    $arrRegistMailMagazine["mail_flag"] = $mail_flag;
2267    $arrRegistMailMagazine["email"] = $email;
2268    $arrRegistMailMagazine["temp_id"] =$random_id;
2269    $arrRegistMailMagazine["end_flag"]='0';
2270    $arrRegistMailMagazine["update_date"] = 'now()';
2271   
2272    //¥á¥ë¥Þ¥¬²¾ÅÐÏ¿Íѥե饰
2273    $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email));
2274    $objConn->query("BEGIN");
2275    switch ($flag){
2276        case '0':
2277        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine);
2278        break;
2279   
2280        case '1':
2281        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = '" .addslashes($email). "'");
2282        break;
2283    }
2284    $objConn->query("COMMIT");
2285    $subject = sfMakeSubject('¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤¬´°Î»¤·¤Þ¤·¤¿¡£');
2286    $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id'];
2287    switch ($mail_flag){
2288        case '1':
2289        $objPage->tpl_name = "ÅÐÏ¿";
2290        $objPage->tpl_kindname = "HTML";
2291        break;
2292       
2293        case '2':
2294        $objPage->tpl_name = "ÅÐÏ¿";
2295        $objPage->tpl_kindname = "¥Æ¥­¥¹¥È";
2296        break;
2297       
2298        case '3':
2299        $objPage->tpl_name = "²ò½ü";
2300        break;
2301    }
2302        $objPage->tpl_email = $email;
2303    sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage);
2304}
2305
2306// ºÆµ¢Åª¤Ë¿ÃÊÇÛÎó¤ò¸¡º÷¤·¤Æ°ì¼¡¸µÇÛÎó(Hidden°úÅϤ·ÍÑÇÛÎó)¤ËÊÑ´¹¤¹¤ë¡£
2307function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") {
2308    if(is_array($arrSrc)) {
2309        foreach($arrSrc as $key => $val) {
2310            if($parent_key != "") {
2311                $keyname = $parent_key . "[". $key . "]";
2312            } else {
2313                $keyname = $key;
2314            }
2315            if(is_array($val)) {
2316                $arrDst = sfMakeHiddenArray($val, $arrDst, $keyname);
2317            } else {
2318                $arrDst[$keyname] = $val;
2319            }
2320        }
2321    }
2322    return $arrDst;
2323}
2324
2325// DB¼èÆÀÆü»þ¤ò¥¿¥¤¥à¤ËÊÑ´¹
2326function sfDBDatetoTime($db_date) {
2327    $date = ereg_replace("\..*$","",$db_date);
2328    $time = strtotime($date);
2329    return $time;
2330}
2331
2332// ½ÐÎϤκݤ˥ƥó¥×¥ì¡¼¥È¤òÀÚ¤êÂؤ¨¤é¤ì¤ë
2333/*
2334    index.php?tpl=test.tpl
2335*/
2336function sfCustomDisplay($objPage, $is_mobile = false) {
2337    $basename = basename($_SERVER["REQUEST_URI"]);
2338
2339    if($basename == "") {
2340        $path = $_SERVER["REQUEST_URI"] . "index.php";
2341    } else {
2342        $path = $_SERVER["REQUEST_URI"];
2343    }   
2344
2345    if($_GET['tpl'] != "") {
2346        $tpl_name = $_GET['tpl'];
2347    } else {
2348        $tpl_name = ereg_replace("^/", "", $path);
2349        $tpl_name = ereg_replace("/", "_", $tpl_name);
2350        $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name);
2351    }
2352
2353    $template_path = TEMPLATE_FTP_DIR . $tpl_name;
2354
2355    if($is_mobile === true) {
2356        $objView = new SC_MobileView();         
2357        $objView->assignobj($objPage);
2358        $objView->display(SITE_FRAME);     
2359    } else if(file_exists($template_path)) {
2360        $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR);
2361        $objView->assignobj($objPage);
2362        $objView->display($tpl_name);
2363    } else {
2364        $objView = new SC_SiteView();
2365        $objView->assignobj($objPage);
2366        $objView->display(SITE_FRAME);
2367    }
2368}
2369
2370//²ñ°÷ÊÔ½¸ÅÐÏ¿½èÍý
2371function sfEditCustomerData($array, $arrRegistColumn) {
2372    $objQuery = new SC_Query();
2373   
2374    foreach ($arrRegistColumn as $data) {
2375        if ($data["column"] != "password") {
2376            if($array[ $data['column'] ] != "") {
2377                $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
2378            } else {
2379                $arrRegist[ $data['column'] ] = NULL;
2380            }
2381        }
2382    }
2383    if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
2384        $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
2385    } else {
2386        $arrRegist["birth"] = NULL;
2387    }
2388
2389    //-- ¥Ñ¥¹¥ï¡¼¥É¤Î¹¹¿·¤¬¤¢¤ë¾ì¹ç¤Ï°Å¹æ²½¡£¡Ê¹¹¿·¤¬¤Ê¤¤¾ì¹ç¤ÏUPDATEʸ¤ò¹½À®¤·¤Ê¤¤¡Ë
2390    if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
2391    $arrRegist["update_date"] = "NOW()";
2392   
2393    //-- ÊÔ½¸ÅÐÏ¿¼Â¹Ô
2394    if (defined('MOBILE_SITE')) {
2395        $arrRegist['email_mobile'] = $arrRegist['email'];
2396        unset($arrRegist['email']);
2397    }
2398    $objQuery->begin();
2399    $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
2400    $objQuery->commit();
2401}
2402
2403// PHP¤Îmb_convert_encoding´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2404function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') {
2405    return  mb_convert_encoding($str, $encode);
2406}   
2407
2408// PHP¤Îmktime´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2409function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) {
2410    return  date($format,mktime($hour, $minute, $second, $month, $day, $year));
2411}   
2412
2413// PHP¤Îdate´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2414function sf_date($format, $timestamp = '') {
2415    return  date( $format, $timestamp);
2416}
2417
2418// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤Î·¿¤òÊÑ´¹¤¹¤ë
2419function sfChangeCheckBox($data , $tpl = false){
2420    if ($tpl) {
2421        if ($data == 1){
2422            return 'checked';
2423        }else{
2424            return "";
2425        }
2426    }else{
2427        if ($data == "on"){
2428            return 1;
2429        }else{
2430            return 2;
2431        }
2432    }
2433}
2434
2435function sfCategory_Count($objQuery){
2436    $sql = "";
2437   
2438    //¥Æ¡¼¥Ö¥ëÆâÍƤκï½ü
2439    $objQuery->query("DELETE FROM dtb_category_count");
2440    $objQuery->query("DELETE FROM dtb_category_total_count");
2441   
2442    //³Æ¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò¿ô¤¨¤Æ³ÊǼ
2443    $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";
2444    $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 ";
2445    $sql .= " ON T1.category_id = T2.category_id  ";
2446    $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";
2447    $sql .= " GROUP BY T1.category_id, T2.category_id ";
2448    $objQuery->query($sql);
2449   
2450    //»Ò¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò½¸·×¤¹¤ë
2451    $arrCat = $objQuery->getAll("SELECT * FROM dtb_category");
2452   
2453    $sql = "";
2454    foreach($arrCat as $key => $val){
2455       
2456        // »ÒID°ìÍ÷¤ò¼èÆÀ
2457        $arrRet = sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);
2458        $line = sfGetCommaList($arrRet);
2459       
2460        $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";
2461        $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";
2462        $sql .= " WHERE category_id IN (" . $line . ")";
2463               
2464        $objQuery->query($sql, array($val['category_id']));
2465    }
2466}
2467
2468// 2¤Ä¤ÎÇÛÎó¤òÍѤ¤¤ÆÏ¢ÁÛÇÛÎó¤òºîÀ®¤¹¤ë
2469function sfarrCombine($arrKeys, $arrValues) {
2470
2471    if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array();
2472   
2473    $keys = array_values($arrKeys);
2474    $vals = array_values($arrValues);
2475   
2476    $max = max( count( $keys ), count( $vals ) );
2477    $combine_ary = array();
2478    for($i=0; $i<$max; $i++) {
2479        $combine_ary[$keys[$i]] = $vals[$i];
2480    }
2481    if(is_array($combine_ary)) return $combine_ary;
2482   
2483    return false;
2484}
2485
2486/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é»ÒIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2487function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
2488    $objQuery = new SC_Query();
2489    $col = $pid_name . "," . $id_name;
2490    $arrData = $objQuery->select($col, $table);
2491   
2492    $arrPID = array();
2493    $arrPID[] = $id;
2494    $arrChildren = array();
2495    $arrChildren[] = $id;
2496   
2497    $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
2498   
2499    while(count($arrRet) > 0) {
2500        $arrChildren = array_merge($arrChildren, $arrRet);
2501        $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
2502    }
2503   
2504    return $arrChildren;
2505}
2506
2507/* ¿ÆIDľ²¼¤Î»ÒID¤ò¤¹¤Ù¤Æ¼èÆÀ¤¹¤ë */
2508function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
2509    $arrChildren = array();
2510    $max = count($arrData);
2511   
2512    for($i = 0; $i < $max; $i++) {
2513        foreach($arrPID as $val) {
2514            if($arrData[$i][$pid_name] == $val) {
2515                $arrChildren[] = $arrData[$i][$id_name];
2516            }
2517        }
2518    }   
2519    return $arrChildren;
2520}
2521
2522
2523/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é¿ÆIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2524function sfGetParentsArray($table, $pid_name, $id_name, $id) {
2525    $objQuery = new SC_Query();
2526    $col = $pid_name . "," . $id_name;
2527    $arrData = $objQuery->select($col, $table);
2528   
2529    $arrParents = array();
2530    $arrParents[] = $id;
2531    $child = $id;
2532   
2533    $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
2534
2535    while($ret != "") {
2536        $arrParents[] = $ret;
2537        $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
2538    }
2539   
2540    $arrParents = array_reverse($arrParents);
2541   
2542    return $arrParents;
2543}
2544
2545/* »ÒID½ê°¤¹¤ë¿ÆID¤ò¼èÆÀ¤¹¤ë */
2546function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) {
2547    $max = count($arrData);
2548    $parent = "";
2549    for($i = 0; $i < $max; $i++) {
2550        if($arrData[$i][$id_name] == $child) {
2551            $parent = $arrData[$i][$pid_name];
2552            break;
2553        }
2554    }
2555    return $parent;
2556}
2557
2558/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Î·»Äï¤ò¼èÆÀ¤¹¤ë */
2559function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) {
2560    $max = count($arrData);
2561   
2562    $arrBrothers = array();
2563    foreach($arrPID as $id) {
2564        // ¿ÆID¤ò¸¡º÷¤¹¤ë
2565        for($i = 0; $i < $max; $i++) {
2566            if($arrData[$i][$id_name] == $id) {
2567                $parent = $arrData[$i][$pid_name];
2568                break;
2569            }
2570        }
2571        // ·»ÄïID¤ò¸¡º÷¤¹¤ë
2572        for($i = 0; $i < $max; $i++) {
2573            if($arrData[$i][$pid_name] == $parent) {
2574                $arrBrothers[] = $arrData[$i][$id_name];
2575            }
2576        }                   
2577    }
2578    return $arrBrothers;
2579}
2580
2581/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Îľ°¤Î»Ò¤ò¼èÆÀ¤¹¤ë */
2582function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) {
2583    $max = count($arrData);
2584   
2585    $arrChildren = array();
2586    // »ÒID¤ò¸¡º÷¤¹¤ë
2587    for($i = 0; $i < $max; $i++) {
2588        if($arrData[$i][$pid_name] == $parent) {
2589            $arrChildren[] = $arrData[$i][$id_name];
2590        }
2591    }                   
2592    return $arrChildren;
2593}
2594
2595
2596// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ
2597function sfGetCatTree($parent_category_id, $count_check = false) {
2598    $objQuery = new SC_Query();
2599    $col = "";
2600    $col .= " cat.category_id,";
2601    $col .= " cat.category_name,";
2602    $col .= " cat.parent_category_id,";
2603    $col .= " cat.level,";
2604    $col .= " cat.rank,";
2605    $col .= " cat.creator_id,";
2606    $col .= " cat.create_date,";
2607    $col .= " cat.update_date,";
2608    $col .= " cat.del_flg, ";
2609    $col .= " ttl.product_count";   
2610    $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
2611    // ÅÐÏ¿¾¦ÉÊ¿ô¤Î¥Á¥§¥Ã¥¯
2612    if($count_check) {
2613        $where = "del_flg = 0 AND product_count > 0";
2614    } else {
2615        $where = "del_flg = 0";
2616    }
2617    $objQuery->setoption("ORDER BY rank DESC");
2618    $arrRet = $objQuery->select($col, $from, $where);
2619   
2620    $arrParentID = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
2621   
2622    foreach($arrRet as $key => $array) {
2623        foreach($arrParentID as $val) {
2624            if($array['category_id'] == $val) {
2625                $arrRet[$key]['display'] = 1;
2626                break;
2627            }
2628        }
2629    }
2630
2631    return $arrRet;
2632}
2633
2634// ¿Æ¥«¥Æ¥´¥ê¡¼¤òÏ¢·ë¤·¤¿Ê¸»úÎó¤ò¼èÆÀ¤¹¤ë
2635function sfGetCatCombName($category_id){
2636    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2637    $objQuery = new SC_Query();
2638    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2639    $ConbName = "";
2640   
2641    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2642    foreach($arrCatID as $key => $val){
2643        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2644        $arrVal = array($val);
2645        $CatName = $objQuery->getOne($sql,$arrVal);
2646        $ConbName .= $CatName . ' | ';
2647    }
2648    // ºÇ¸å¤Î ¡Ã ¤ò¥«¥Ã¥È¤¹¤ë
2649    $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2);
2650   
2651    return $ConbName;
2652}
2653
2654// »ØÄꤷ¤¿¥«¥Æ¥´¥ê¡¼ID¤ÎÂ祫¥Æ¥´¥ê¡¼¤ò¼èÆÀ¤¹¤ë
2655function sfGetFirstCat($category_id){
2656    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2657    $objQuery = new SC_Query();
2658    $arrRet = array();
2659    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2660    $arrRet['id'] = $arrCatID[0];
2661   
2662    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2663    $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2664    $arrVal = array($arrRet['id']);
2665    $arrRet['name'] = $objQuery->getOne($sql,$arrVal);
2666   
2667    return $arrRet;
2668}
2669
2670//MySQLÍѤÎSQLʸ¤ËÊѹ¹¤¹¤ë
2671function sfChangeMySQL($sql){
2672    // ²þ¹Ô¡¢¥¿¥Ö¤ò1¥¹¥Ú¡¼¥¹¤ËÊÑ´¹
2673    $sql = preg_replace("/[\r\n\t]/"," ",$sql);
2674   
2675    $sql = sfChangeView($sql);      // viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2676    $sql = sfChangeILIKE($sql);     // ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2677    $sql = sfChangeRANDOM($sql);    // RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2678
2679    return $sql;
2680}
2681
2682// SQL¤ÎÃæ¤Ëview¤¬Â¸ºß¤·¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯¤ò¹Ô¤¦¡£
2683function sfInArray($sql){
2684    global $arrView;
2685
2686    foreach($arrView as $key => $val){
2687        if (strcasecmp($sql, $val) == 0){
2688            $changesql = eregi_replace("($key)", "$val", $sql);
2689            sfInArray($changesql);
2690        }
2691    }
2692    return false;
2693}
2694
2695// SQL¥·¥ó¥°¥ë¥¯¥©¡¼¥ÈÂбþ
2696function sfQuoteSmart($in){
2697   
2698    if (is_int($in) || is_double($in)) {
2699        return $in;
2700    } elseif (is_bool($in)) {
2701        return $in ? 1 : 0;
2702    } elseif (is_null($in)) {
2703        return 'NULL';
2704    } else {
2705        return "'" . str_replace("'", "''", $in) . "'";
2706    }
2707}
2708   
2709// viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2710function sfChangeView($sql){
2711    global $arrView;
2712    global $arrViewWhere;
2713   
2714    $arrViewTmp = $arrView;
2715
2716    // view¤Îwhere¤òÊÑ´¹
2717    foreach($arrViewTmp as $key => $val){
2718        $arrViewTmp[$key] = strtr($arrViewTmp[$key], $arrViewWhere);
2719    }
2720   
2721    // view¤òÊÑ´¹
2722    $changesql = strtr($sql, $arrViewTmp);
2723
2724    return $changesql;
2725}
2726
2727// ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2728function sfChangeILIKE($sql){
2729    $changesql = eregi_replace("(ILIKE )", "LIKE BINARY ", $sql);
2730    return $changesql;
2731}
2732
2733// RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2734function sfChangeRANDOM($sql){
2735    $changesql = eregi_replace("( RANDOM)", " RAND", $sql);
2736    return $changesql;
2737}
2738
2739// view¤Îwhere¤òÃÖ´¹¤¹¤ë
2740function sfViewWhere($target, $where = "", $arrval = array(), $option = ""){
2741    global $arrViewWhere;
2742    $arrWhere = split("[?]", $where);
2743    $where_tmp = " WHERE " . $arrWhere[0];
2744    for($i = 1; $i < count($arrWhere); $i++){
2745        $where_tmp .= sfQuoteSmart($arrval[$i - 1]) . $arrWhere[$i];
2746    }
2747    $arrViewWhere[$target] = $where_tmp . " " . $option;
2748}
2749
2750// ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤Î¥Õ¥¡¥¤¥ë¤òºÆµ¢Åª¤Ë¥³¥Ô¡¼
2751function sfCopyDir($src, $des, $mess, $override = false){
2752    if(!is_dir($src)){
2753        return false;
2754    }
2755
2756    $oldmask = umask(0);
2757    $mod= stat($src);
2758   
2759    // ¥Ç¥£¥ì¥¯¥È¥ê¤¬¤Ê¤±¤ì¤ÐºîÀ®¤¹¤ë
2760    if(!file_exists($des)) {
2761        if(!mkdir($des, $mod[2])) {
2762            print("path:" . $des);
2763        }
2764    }
2765   
2766    $fileArray=glob( $src."*" );
2767    foreach( $fileArray as $key => $data_ ){
2768        // CVS´ÉÍý¥Õ¥¡¥¤¥ë¤Ï¥³¥Ô¡¼¤·¤Ê¤¤
2769        if(ereg("/CVS/Entries", $data_)) {
2770            break;
2771        }
2772        if(ereg("/CVS/Repository", $data_)) {
2773            break;
2774        }
2775        if(ereg("/CVS/Root", $data_)) {
2776            break;
2777        }
2778       
2779        mb_ereg("^(.*[\/])(.*)",$data_, $matches);
2780        $data=$matches[2];
2781        if( is_dir( $data_ ) ){
2782            $mess = sfCopyDir( $data_.'/', $des.$data.'/', $mess);
2783        }else{
2784            if(!$override && file_exists($des.$data)) {
2785                $mess.= $des.$data . "¡§¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤¹\n";
2786            } else {
2787                if(@copy( $data_, $des.$data)) {
2788                    $mess.= $des.$data . "¡§¥³¥Ô¡¼À®¸ù\n";
2789                } else {
2790                    $mess.= $des.$data . "¡§¥³¥Ô¡¼¼ºÇÔ\n";
2791                }
2792            }
2793            $mod=stat($data_ );
2794        }
2795    }
2796    umask($oldmask);
2797    return $mess;
2798}
2799
2800// »ØÄꤷ¤¿¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òÁ´¤Æºï½ü¤¹¤ë
2801function sfDelFile($dir){
2802    $dh = opendir($dir);
2803    // ¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òºï½ü
2804    while($file = readdir($dh)){
2805        if ($file == "." or $file == "..") continue;
2806        $del_file = $dir . "/" . $file;
2807        if(is_file($del_file)){
2808            $ret = unlink($dir . "/" . $file);
2809        }else if (is_dir($del_file)){
2810            $ret = sfDelFile($del_file);
2811        }
2812       
2813        if(!$ret){
2814            return $ret;
2815        }
2816    }
2817    // ¥Õ¥©¥ë¥À¤òºï½ü
2818    return rmdir($dir);
2819   
2820}
2821
2822/*
2823 * ´Ø¿ô̾¡§sfWriteFile
2824 * °ú¿ô1 ¡§½ñ¤­¹þ¤à¥Ç¡¼¥¿
2825 * °ú¿ô2 ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹
2826 * °ú¿ô3 ¡§½ñ¤­¹þ¤ß¥¿¥¤¥×
2827 * °ú¿ô4 ¡§¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó
2828 * Ìá¤êÃÍ¡§·ë²Ì¥Õ¥é¥° À®¸ù¤Ê¤é true ¼ºÇԤʤé false
2829 * ÀâÌÀ¡¡¡§¥Õ¥¡¥¤¥ë½ñ¤­½Ð¤·
2830 */
2831function sfWriteFile($str, $path, $type, $permission = "") {
2832    //¥Õ¥¡¥¤¥ë¤ò³«¤¯
2833    if (!($file = fopen ($path, $type))) {
2834        return false;
2835    }
2836
2837    //¥Õ¥¡¥¤¥ë¥í¥Ã¥¯
2838    flock ($file, LOCK_EX);
2839    //¥Õ¥¡¥¤¥ë¤Î½ñ¤­¹þ¤ß
2840    fputs ($file, $str);
2841    //¥Õ¥¡¥¤¥ë¥í¥Ã¥¯¤Î²ò½ü
2842    flock ($file, LOCK_UN);
2843    //¥Õ¥¡¥¤¥ë¤òÊĤ¸¤ë
2844    fclose ($file);
2845    // ¸¢¸Â¤ò»ØÄê
2846    if($permission != "") {
2847        chmod($path, $permission);
2848    }
2849   
2850    return true;
2851}
2852   
2853function sfFlush($output = " ", $sleep = 0){
2854    // ¼Â¹Ô»þ´Ö¤òÀ©¸Â¤·¤Ê¤¤
2855    set_time_limit(0);
2856    // ½ÐÎϤò¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·¤Ê¤¤(==ÆüËܸ켫ưÊÑ´¹¤â¤·¤Ê¤¤)
2857    ob_end_clean();
2858   
2859    // IE¤Î¤¿¤á¤Ë256¥Ð¥¤¥È¶õʸ»ú½ÐÎÏ
2860    echo str_pad('',256);
2861   
2862    // ½ÐÎϤϥ֥é¥ó¥¯¤À¤±¤Ç¤â¤¤¤¤¤È»×¤¦
2863    echo $output;
2864    // ½ÐÎϤò¥Õ¥é¥Ã¥·¥å¤¹¤ë
2865    flush();
2866   
2867    ob_end_flush();
2868    ob_start();
2869   
2870    // »þ´Ö¤Î¤«¤«¤ë½èÍý
2871    sleep($sleep);
2872}
2873
2874// @version¤Îµ­ºÜ¤¬¤¢¤ë¥Õ¥¡¥¤¥ë¤«¤é¥Ð¡¼¥¸¥ç¥ó¤ò¼èÆÀ¤¹¤ë¡£
2875function sfGetFileVersion($path) {
2876    if(file_exists($path)) {
2877        $src_fp = fopen($path, "rb");
2878        if($src_fp) {
2879            while (!feof($src_fp)) {
2880                $line = fgets($src_fp);
2881                if(ereg("@version", $line)) {
2882                    $arrLine = split(" ", $line);
2883                    $version = $arrLine[5];
2884                }
2885            }
2886            fclose($src_fp);
2887        }
2888    }
2889    return $version;
2890}
2891
2892// »ØÄꤷ¤¿URL¤ËÂФ·¤ÆPOST¤Ç¥Ç¡¼¥¿¤òÁ÷¿®¤¹¤ë
2893function sfSendPostData($url, $arrData, $arrOkCode = array()){
2894    require_once(DATA_PATH . "module/Request.php");
2895   
2896    // Á÷¿®¥¤¥ó¥¹¥¿¥ó¥¹À¸À®
2897    $req = new HTTP_Request($url);
2898   
2899    $req->addHeader('User-Agent', 'DoCoMo/2.0¡¡P2101V(c100)');
2900    $req->setMethod(HTTP_REQUEST_METHOD_POST);
2901   
2902    // POST¥Ç¡¼¥¿Á÷¿®
2903    $req->addPostDataArray($arrData);
2904   
2905    // ¥¨¥é¡¼¤¬Ìµ¤±¤ì¤Ð¡¢±þÅú¾ðÊó¤ò¼èÆÀ¤¹¤ë
2906    if (!PEAR::isError($req->sendRequest())) {
2907       
2908        // ¥ì¥¹¥Ý¥ó¥¹¥³¡¼¥É¤¬¥¨¥é¡¼È½Äê¤Ê¤é¡¢¶õ¤òÊÖ¤¹
2909        $res_code = $req->getResponseCode();
2910       
2911        if(!in_array($res_code, $arrOkCode)){
2912            $response = "";
2913        }else{
2914            $response = $req->getResponseBody();
2915        }
2916       
2917    } else {
2918        $response = "";
2919    }
2920   
2921    // POST¥Ç¡¼¥¿¥¯¥ê¥¢
2922    $req->clearPostData(); 
2923   
2924    return $response;
2925}
2926
2927/* ¥Ç¥Ð¥Ã¥°ÍÑ ------------------------------------------------------------------------------------------------*/
2928function sfPrintR($obj) {
2929    print("<div style='font-size: 12px;color: #00FF00;'>\n");
2930    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong><br />\n");
2931    print("<pre>\n");
2932    print_r($obj);
2933    print("</pre>\n");
2934    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong></div>\n");
2935}
2936
2937?>
Note: See TracBrowser for help on using the repository browser.