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

Revision 14950, 78.3 KB checked in by adati, 17 years ago (diff)

CSRF対策:sfIsSuccess()を修正、リファラのチェックをするようにした

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