source: branches/beta/data/lib/slib.php @ 15002

Revision 15002, 78.2 KB checked in by kakinaka, 17 years ago (diff)

カラム一覧取得時、不正データは取得しないように修正

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