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

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