source: branches/dev/data/lib/slib.php @ 11728

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