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

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