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

Revision 15315, 78.4 KB checked in by adachi, 17 years ago (diff)

ログインできない問題の修正

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