source: branches/rel/data/lib/slib.php @ 13402

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