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

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