source: temp/trunk/data/lib/slib.php @ 9859

Revision 9859, 72.8 KB checked in by kakinaka, 20 years ago (diff)

blank

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