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

Revision 8883, 71.2 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    sfprintr($array);
801    if (count($array) > 0) {
802        foreach($array as $key => $val) {
803            $line = ereg_replace("\n", ",$", $line);
804            $line .= "\"".$val."\",";
805        }
806        $line = ereg_replace(",$", "\n", $line);
807    }else{
808        return false;
809    }
810    return $line;
811}
812
813/* ÇÛÎó¤ÎÍ×ÁǤòPDF¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç½ÐÎϤ¹¤ë¡£*/
814function sfGetPDFList($array) {
815    foreach($array as $key => $val) {
816        $line .= "\t".$val;
817    }
818    $line.="\n";
819    return $line;
820}
821
822
823
824/*-----------------------------------------------------------------*/
825/*  check_set_term
826/*  ǯ·îÆü¤ËÊ̤줿2¤Ä¤Î´ü´Ö¤ÎÂÅÅöÀ­¤ò¥Á¥§¥Ã¥¯¤·¡¢À°¹çÀ­¤È´ü´Ö¤òÊÖ¤¹
827/*¡¡°ú¿ô (³«»Ïǯ,³«»Ï·î,³«»ÏÆü,½ªÎ»Ç¯,½ªÎ»·î,½ªÎ»Æü)
828/*¡¡ÌáÃÍ array(£±¡¤£²¡¤£³¡Ë
829/*          £±¡¥³«»Ïǯ·îÆü (YYYY/MM/DD 000000)
830/*          £²¡¥½ªÎ»Ç¯·îÆü (YYYY/MM/DD 235959)
831/*          £³¡¥¥¨¥é¡¼ ( 0 = OK, 1 = NG )
832/*-----------------------------------------------------------------*/
833function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) {
834
835    // ´ü´Ö»ØÄê
836    $error = 0;
837    if ( $start_month || $start_day || $start_year){
838        if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1;
839    } else {
840        $error = 1;
841    }
842    if ( $end_month || $end_day || $end_year){
843        if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2;
844    }
845    if ( ! $error ){
846        $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000";
847        $date2 = $end_year   ."/".sprintf("%02d",$end_month)   ."/".sprintf("%02d",$end_day)   ." 235959";
848        if ($date1 > $date2) $error = 3;
849    } else {
850        $error = 1;
851    }
852    return array($date1, $date2, $error);
853}
854
855// ¥¨¥é¡¼²Õ½ê¤ÎÇØ·Ê¿§¤òÊѹ¹¤¹¤ë¤¿¤á¤Îfunction SC_View¤ÇÆÉ¤ß¹þ¤à
856function sfSetErrorStyle(){
857    return 'style="background-color:'.ERR_COLOR.'"';
858}
859
860/* DB¤ËÅϤ¹¿ôÃͤΥÁ¥§¥Ã¥¯
861 * 10·å°Ê¾å¤Ï¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¥¨¥é¡¼¤òµ¯¤³¤¹¤Î¤Ç¡£
862 */
863function sfCheckNumLength( $value ){
864    if ( ! is_numeric($value)  ){
865        return false;
866    }
867   
868    if ( strlen($value) > 9 ) {
869        return false;
870    }
871   
872    return true;
873}
874
875// °ìÃפ·¤¿ÃͤΥ­¡¼Ì¾¤ò¼èÆÀ
876function sfSearchKey($array, $word, $default) {
877    foreach($array as $key => $val) {
878        if($val == $word) {
879            return $key;
880        }
881    }
882    return $default;
883}
884
885// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ($products_check:true¾¦ÉÊÅÐÏ¿ºÑ¤ß¤Î¤â¤Î¤À¤±¼èÆÀ)
886function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
887    $objQuery = new SC_Query();
888    $where = "del_flg = 0";
889   
890    if($addwhere != "") {
891        $where.= " AND $addwhere";
892    }
893       
894    $objQuery->setoption("ORDER BY rank DESC");
895   
896    if($products_check) {
897        $col = "T1.category_id, category_name, level";
898        $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
899        $where .= " AND product_count > 0";
900    } else {
901        $col = "category_id, category_name, level";
902        $from = "dtb_category";
903    }
904   
905    $arrRet = $objQuery->select($col, $from, $where);
906           
907    $max = count($arrRet);
908    for($cnt = 0; $cnt < $max; $cnt++) {
909        $id = $arrRet[$cnt]['category_id'];
910        $name = $arrRet[$cnt]['category_name'];
911        $arrList[$id] = "";
912        /*
913        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
914            $arrList[$id].= "¡¡";
915        }
916        */
917        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
918            $arrList[$id].= $head;
919        }
920        $arrList[$id].= $name;
921    }
922    return $arrList;
923}
924
925// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ¡Ê¿Æ¥«¥Æ¥´¥ê¤ÎValue:0)
926function sfGetLevelCatList($parent_zero = true) {
927    $objQuery = new SC_Query();
928    $col = "category_id, category_name, level";
929    $where = "del_flg = 0";
930    $objQuery->setoption("ORDER BY rank DESC");
931    $arrRet = $objQuery->select($col, "dtb_category", $where);
932    $max = count($arrRet);
933   
934    for($cnt = 0; $cnt < $max; $cnt++) {
935        if($parent_zero) {
936            if($arrRet[$cnt]['level'] == LEVEL_MAX) {
937                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
938            } else {
939                $arrValue[$cnt] = "";
940            }
941        } else {
942            $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
943        }
944       
945        $arrOutput[$cnt] = "";
946        /*         
947        for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
948            $arrOutput[$cnt].= "¡¡";
949        }
950        */
951        for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
952            $arrOutput[$cnt].= CATEGORY_HEAD;
953        }
954        $arrOutput[$cnt].= $arrRet[$cnt]['category_name'];
955    }
956    return array($arrValue, $arrOutput);
957}
958
959function sfGetErrorColor($val) {
960    if($val != "") {
961        return "background-color:" . ERR_COLOR;
962    }
963    return "";
964}
965
966
967function sfGetEnabled($val) {
968    if( ! $val ) {
969        return " disabled=\"disabled\"";
970    }
971    return "";
972}
973
974function sfGetChecked($param, $value) {
975    if($param == $value) {
976        return "checked=\"checked\"";
977    }
978    return "";
979}
980
981// SELECT¥Ü¥Ã¥¯¥¹Íѥꥹ¥È¤ÎºîÀ®
982function sfGetIDValueList($table, $keyname, $valname) {
983    $objQuery = new SC_Query();
984    $col = "$keyname, $valname";
985    $objQuery->setwhere("del_flg = 0");
986    $objQuery->setorder("rank DESC");
987    $arrList = $objQuery->select($col, $table);
988    $count = count($arrList);
989    for($cnt = 0; $cnt < $count; $cnt++) {
990        $key = $arrList[$cnt][$keyname];
991        $val = $arrList[$cnt][$valname];
992        $arrRet[$key] = $val;
993    }
994    return $arrRet;
995}
996
997function sfTrim($str) {
998    $ret = ereg_replace("^[¡¡ \n\r]*", "", $str);
999    $ret = ereg_replace("[¡¡ \n\r]*$", "", $ret);
1000    return $ret;
1001}
1002
1003/* ½ê°¤¹¤ë¤¹¤Ù¤Æ¤Î³¬ÁؤοÆID¤òÇÛÎó¤ÇÊÖ¤¹ */
1004function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
1005    $arrRet = sfGetParentsArray($table, $pid_name, $id_name, $id);
1006    // ÇÛÎó¤ÎÀèÆ¬1¤Ä¤òºï½ü¤¹¤ë¡£
1007    array_shift($arrRet);
1008    return $arrRet;
1009}
1010
1011
1012/* ¿ÆID¤ÎÇÛÎó¤ò¸µ¤ËÆÃÄê¤Î¥«¥é¥à¤ò¼èÆÀ¤¹¤ë¡£*/
1013function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
1014    $col = $col_name;
1015    $len = count($arrId);
1016    $where = "";
1017   
1018    for($cnt = 0; $cnt < $len; $cnt++) {
1019        if($where == "") {
1020            $where = "$id_name = ?";
1021        } else {
1022            $where.= " OR $id_name = ?";
1023        }
1024    }
1025   
1026    $objQuery->setorder("level");
1027    $arrRet = $objQuery->select($col, $table, $where, $arrId);
1028    return $arrRet;
1029}
1030
1031/* »ÒID¤ÎÇÛÎó¤òÊÖ¤¹ */
1032function sfGetChildsID($table, $pid_name, $id_name, $id) {
1033    $arrRet = sfGetChildrenArray($table, $pid_name, $id_name, $id);
1034    return $arrRet;
1035}
1036
1037/* ¥«¥Æ¥´¥êÊѹ¹»þ¤Î°Üư½èÍý */
1038function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
1039    if ($old_catid == $new_catid) {
1040        return;
1041    }
1042    // µì¥«¥Æ¥´¥ê¤Ç¤Î¥é¥ó¥¯ºï½ü½èÍý
1043    // °Üư¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£     
1044    $where = "$id_name = ?";
1045    $rank = $objQuery->get($table, "rank", $where, array($id));
1046    // ºï½ü¥ì¥³¡¼¥É¤Î¥é¥ó¥¯¤è¤ê¾å¤Î¥ì¥³¡¼¥É¤ò°ì¤Ä²¼¤Ë¤º¤é¤¹¡£
1047    $where = "rank > ? AND $cat_name = ?";
1048    $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1049    $objQuery->exec($sqlup, array($rank, $old_catid));
1050    // ¿·¥«¥Æ¥´¥ê¤Ç¤ÎÅÐÏ¿½èÍý
1051    // ¿·¥«¥Æ¥´¥ê¤ÎºÇÂç¥é¥ó¥¯¤ò¼èÆÀ¤¹¤ë¡£
1052    $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
1053    $where = "$id_name = ?";
1054    $sqlup = "UPDATE $table SET rank = ? WHERE $where";
1055    $objQuery->exec($sqlup, array($max_rank, $id));
1056}
1057
1058/* ÀǶâ·×»» */
1059function sfTax($price, $tax, $tax_rule) {
1060    $real_tax = $tax / 100;
1061    $ret = $price * $real_tax;
1062    switch($tax_rule) {
1063    // »Í¼Î¸ÞÆþ
1064    case 1:
1065        $ret = round($ret);
1066        break;
1067    // ÀÚ¤ê¼Î¤Æ
1068    case 2:
1069        $ret = floor($ret);
1070        break;
1071    // ÀÚ¤ê¾å¤²
1072    case 3:
1073        $ret = ceil($ret);
1074        break;
1075    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1076    default:
1077        $ret = ceil($ret);
1078        break;
1079    }
1080    return $ret;
1081}
1082
1083/* ÀǶâÉÕÍ¿ */
1084function sfPreTax($price, $tax, $tax_rule) {
1085    $real_tax = $tax / 100;
1086    $ret = $price * (1 + $real_tax);
1087    switch($tax_rule) {
1088    // »Í¼Î¸ÞÆþ
1089    case 1:
1090        $ret = round($ret);
1091        break;
1092    // ÀÚ¤ê¼Î¤Æ
1093    case 2:
1094        $ret = floor($ret);
1095        break;
1096    // ÀÚ¤ê¾å¤²
1097    case 3:
1098        $ret = ceil($ret);
1099        break;
1100    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1101    default:
1102        $ret = ceil($ret);
1103        break;
1104    }
1105    return $ret;
1106}
1107
1108/* ¥Ý¥¤¥ó¥ÈÉÕÍ¿ */
1109function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") {
1110    if(sfIsInt($product_id)) {
1111        $objQuery = new SC_Query();
1112        $where = "now() >= cast(start_date as date) AND ";
1113        $where .= "now() < cast(end_date as date) AND ";
1114       
1115        $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )";
1116        //ÅÐÏ¿(¹¹¿·)ÆüÉÕ½ç
1117        $objQuery->setorder('update_date DESC');
1118        //¥­¥ã¥ó¥Ú¡¼¥ó¥Ý¥¤¥ó¥È¤Î¼èÆÀ
1119        $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id));
1120    }
1121    //Ê£¿ô¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¾¦Éʤϡ¢ºÇ¿·¤Î¥­¥ã¥ó¥Ú¡¼¥ó¤«¤é¥Ý¥¤¥ó¥È¤ò¼èÆÀ
1122    if($arrRet[0]['campaign_point_rate'] != "") {
1123        $campaign_point_rate = $arrRet[0]['campaign_point_rate'];
1124        $real_point = $campaign_point_rate / 100;
1125    } else {
1126        $real_point = $point_rate / 100;
1127    }
1128    $ret = $price * $real_point;
1129    switch($rule) {
1130    // »Í¼Î¸ÞÆþ
1131    case 1:
1132        $ret = round($ret);
1133        break;
1134    // ÀÚ¤ê¼Î¤Æ
1135    case 2:
1136        $ret = floor($ret);
1137        break;
1138    // ÀÚ¤ê¾å¤²
1139    case 3:
1140        $ret = ceil($ret);
1141        break;
1142    // ¥Ç¥Õ¥©¥ë¥È:ÀÚ¤ê¾å¤²
1143    default:
1144        $ret = ceil($ret);
1145        break;
1146    }
1147    //¥­¥ã¥ó¥Ú¡¼¥ó¾¦Éʤξì¹ç
1148    if($campaign_point_rate != "") {
1149        $ret = "(".$arrRet[0]['campaign_name']."¥Ý¥¤¥ó¥ÈΨ".$campaign_point_rate."%)".$ret;
1150    }
1151    return $ret;
1152}
1153
1154/* µ¬³ÊʬÎà¤Î·ï¿ô¼èÆÀ */
1155function sfGetClassCatCount() {
1156    $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id ";
1157    $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id ";
1158    $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 ";
1159    $sql.= "group by dtb_class.class_id, dtb_class.name";
1160    $objQuery = new SC_Query();
1161    $arrList = $objQuery->getall($sql);
1162    // ¥­¡¼¤ÈÃͤò¥»¥Ã¥È¤·¤¿ÇÛÎó¤ò¼èÆÀ
1163    $arrRet = sfArrKeyValue($arrList, 'class_id', 'count');
1164   
1165    return $arrRet;
1166}
1167
1168/* µ¬³Ê¤ÎÅÐÏ¿ */
1169function sfInsertProductClass($objQuery, $arrList, $product_id) {
1170    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡£
1171    $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0";
1172    $count = $objQuery->count("dtb_products_class", $where,  array($product_id));
1173   
1174    // ¤¹¤Ç¤Ëµ¬³ÊÅÐÏ¿¤¬¤Ê¤¤¾ì¹ç
1175    if($count == 0) {
1176        // ´û¸µ¬³Ê¤Îºï½ü
1177        $where = "product_id = ?";
1178        $objQuery->delete("dtb_products_class", $where, array($product_id));
1179        $sqlval['product_id'] = $product_id;
1180        $sqlval['classcategory_id1'] = '0';
1181        $sqlval['classcategory_id2'] = '0';
1182        $sqlval['product_code'] = $arrList["product_code"];
1183        $sqlval['stock'] = $arrList["stock"];
1184        $sqlval['stock_unlimited'] = $arrList["stock_unlimited"];
1185        $sqlval['price01'] = $arrList['price01'];
1186        $sqlval['price02'] = $arrList['price02'];
1187        $sqlval['creator_id'] = $_SESSION['member_id'];
1188        $sqlval['create_date'] = "now()";
1189       
1190        if($_SESSION['member_id'] == "") {
1191            $sqlval['creator_id'] = '0';
1192        }
1193       
1194        // INSERT¤Î¼Â¹Ô
1195        $objQuery->insert("dtb_products_class", $sqlval);
1196    }
1197}
1198
1199function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) {
1200    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1201    $objQuery = new SC_Query();
1202    $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2));
1203    return $ret;
1204}
1205
1206/* ʸËö¤Î¡Ö/¡×¤ò¤Ê¤¯¤¹ */
1207function sfTrimURL($url) {
1208    $ret = ereg_replace("[/]+$", "", $url);
1209    return $ret;
1210}
1211
1212/* ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ */
1213function sfGetProductsClass($arrID) {
1214    list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
1215   
1216    if($classcategory_id1 == "") {
1217        $classcategory_id1 = '0';
1218    }
1219    if($classcategory_id2 == "") {
1220        $classcategory_id2 = '0';
1221    }
1222       
1223    // ¾¦Éʵ¬³Ê¼èÆÀ
1224    $objQuery = new SC_Query();
1225    $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";
1226    $table = "vw_product_class AS prdcls";
1227    $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
1228    $objQuery->setorder("rank1 DESC, rank2 DESC");
1229    $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
1230    return $arrRet[0];
1231}
1232
1233/* ½¸·×¾ðÊó¤ò¸µ¤ËºÇ½ª·×»» */
1234function sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo, $objCustomer = "") {
1235    // ¾¦Éʤιç·×¸Ä¿ô
1236    $total_quantity = $objCartSess->getTotalQuantity(true);
1237   
1238    // ÀǶâ¤Î¼èÆÀ
1239    $arrData['tax'] = $objPage->tpl_total_tax;
1240    // ¾®·×¤Î¼èÆÀ
1241    $arrData['subtotal'] = $objPage->tpl_total_pretax; 
1242   
1243    // ¹ç·×Á÷ÎÁ¤Î¼èÆÀ
1244    $arrData['deliv_fee'] = 0;
1245       
1246    // ¾¦Éʤ´¤È¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1247    if (OPTION_PRODUCT_DELIV_FEE == 1) {
1248        $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee();
1249    }
1250   
1251    // ÇÛÁ÷¶È¼Ô¤ÎÁ÷ÎÁ¤¬Í­¸ú¤Î¾ì¹ç
1252    if (OPTION_DELIV_FEE == 1) {
1253        // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1254        $arrData['deliv_fee']+= sfGetDelivFee($arrData['deliv_pref'], $arrData['payment_id']);
1255    }
1256   
1257    // Á÷ÎÁ̵ÎÁ¤Î¹ØÆþ¿ô¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1258    if(DELIV_FREE_AMOUNT > 0) {
1259        if($total_quantity >= DELIV_FREE_AMOUNT) {
1260            $arrData['deliv_fee'] = 0;
1261        }   
1262    }
1263       
1264    // Á÷ÎÁ̵ÎÁ¾ò·ï¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç
1265    if($arrInfo['free_rule'] > 0) {
1266        // ¾®·×¤¬ÌµÎÁ¾ò·ï¤òͤ¨¤Æ¤¤¤ë¾ì¹ç
1267        if($arrData['subtotal'] >= $arrInfo['free_rule']) {
1268            $arrData['deliv_fee'] = 0;
1269        }
1270    }
1271
1272    // ¹ç·×¤Î·×»»
1273    $arrData['total'] = $objPage->tpl_total_pretax; // ¾¦Éʹç·×
1274    $arrData['total']+= $arrData['deliv_fee'];      // Á÷ÎÁ
1275    $arrData['total']+= $arrData['charge'];         // ¼ê¿ôÎÁ
1276    // ¤ª»Ùʧ¤¤¹ç·×
1277    $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
1278    // ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»
1279    $arrData['add_point'] = sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
1280   
1281    if($objCustomer != "") {
1282        // ÃÂÀ¸Æü·î¤Ç¤¢¤Ã¤¿¾ì¹ç
1283        if($objCustomer->isBirthMonth()) {
1284            $arrData['birth_point'] = BIRTH_MONTH_POINT;
1285            $arrData['add_point'] += $arrData['birth_point'];
1286        }
1287    }
1288   
1289    if($arrData['add_point'] < 0) {
1290        $arrData['add_point'] = 0;
1291    }
1292   
1293    return $arrData;
1294}
1295
1296/* ¥«¡¼¥ÈÆâ¾¦Éʤν¸·×½èÍý */
1297function sfTotalCart($objPage, $objCartSess, $arrInfo) {
1298    // µ¬³Ê̾°ìÍ÷
1299    $arrClassName = sfGetIDValueList("dtb_class", "class_id", "name");
1300    // µ¬³ÊʬÎà̾°ìÍ÷
1301    $arrClassCatName = sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
1302   
1303    $objPage->tpl_total_pretax = 0;     // ÈñÍѹç·×(Àǹþ¤ß)
1304    $objPage->tpl_total_tax = 0;        // ¾ÃÈñÀǹç·×
1305    $objPage->tpl_total_point = 0;      // ¥Ý¥¤¥ó¥È¹ç·×
1306   
1307    // ¥«¡¼¥ÈÆâ¾ðÊó¤Î¼èÆÀ
1308    $arrCart = $objCartSess->getCartList();
1309    $max = count($arrCart);
1310    $cnt = 0;
1311
1312    for ($i = 0; $i < $max; $i++) {
1313        // ¾¦Éʵ¬³Ê¾ðÊó¤Î¼èÆÀ   
1314        $arrData = sfGetProductsClass($arrCart[$i]['id']);
1315        $limit = "";
1316        // DB¤Ë¸ºß¤¹¤ë¾¦ÉÊ
1317        if (count($arrData) > 0) {
1318           
1319            // ¹ØÆþÀ©¸Â¿ô¤òµá¤á¤ë¡£         
1320            if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
1321                if($arrData['sale_limit'] < $arrData['stock']) {
1322                    $limit = $arrData['sale_limit'];
1323                } else {
1324                    $limit = $arrData['stock'];
1325                }
1326            } else {
1327                if ($arrData['sale_unlimited'] != '1') {
1328                    $limit = $arrData['sale_limit'];
1329                }
1330                if ($arrData['stock_unlimited'] != '1') {
1331                    $limit = $arrData['stock'];
1332                }
1333            }
1334                       
1335            if($limit != "" && $limit < $arrCart[$i]['quantity']) {
1336                // ¥«¡¼¥ÈÆâ¾¦ÉÊ¿ô¤òÀ©¸Â¤Ë¹ç¤ï¤»¤ë
1337                $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
1338                $quantity = $limit;
1339                $objPage->tpl_message = "¢¨¡Ö" . $arrData['name'] . "¡×¤ÏÈÎÇäÀ©¸Â¤·¤Æ¤ª¤ê¤Þ¤¹¡¢°ìÅ٤ˤ³¤ì°Ê¾å¤Î¹ØÆþ¤Ï¤Ç¤­¤Þ¤»¤ó¡£";
1340            } else {
1341                $quantity = $arrCart[$i]['quantity'];
1342            }
1343           
1344            $objPage->arrProductsClass[$cnt] = $arrData;
1345            $objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
1346            $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
1347            $objPage->arrProductsClass[$cnt]['class_name1'] = $arrClassName[$arrData['class_id1']];
1348            $objPage->arrProductsClass[$cnt]['class_name2'] = $arrClassName[$arrData['class_id2']];
1349            $objPage->arrProductsClass[$cnt]['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']];
1350            $objPage->arrProductsClass[$cnt]['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']];
1351           
1352            // ²Á³Ê¤ÎÅÐÏ¿
1353            if ($arrData['price02'] != "") {
1354                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
1355                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
1356            } else {
1357                $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
1358                $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
1359            }
1360            // ¥Ý¥¤¥ó¥ÈÉÕͿΨ¤ÎÅÐÏ¿
1361            $objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
1362            // ¾¦Éʤ´¤È¤Î¹ç·×¶â³Û
1363            $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
1364            // Á÷ÎÁ¤Î¹ç·×¤ò·×»»¤¹¤ë
1365            $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
1366            $cnt++;
1367        } else {
1368            // DB¤Ë¾¦Éʤ¬¸«¤Ä¤«¤é¤Ê¤¤¾ì¹ç¤Ï¥«¡¼¥È¾¦Éʤκï½ü
1369            $objCartSess->delProductKey('id', $arrCart[$i]['id']);
1370        }
1371    }
1372   
1373    // Á´¾¦Éʹç·×¶â³Û(Àǹþ¤ß)
1374    $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
1375    // Á´¾¦Éʹç·×¾ÃÈñÀÇ
1376    $objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
1377    // Á´¾¦Éʹç·×¥Ý¥¤¥ó¥È
1378    $objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
1379   
1380    return $objPage;   
1381}
1382
1383/* DB¤«¤é¼è¤ê½Ð¤·¤¿ÆüÉÕ¤Îʸ»úÎó¤òÄ´À°¤¹¤ë¡£*/
1384function sfDispDBDate($dbdate, $time = true) {
1385    list($y, $m, $d, $H, $M) = split("[- :]", $dbdate);
1386
1387    if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) {
1388        if ($time) {
1389            $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M);
1390        } else {
1391            $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M);                       
1392        }
1393    } else {
1394        $str = "";
1395    }
1396    return $str;
1397}
1398
1399function sfGetDelivTime($payment_id = "") {
1400    $objQuery = new SC_Query();
1401   
1402    $deliv_id = "";
1403   
1404    if($payment_id != "") {
1405        $where = "del_flg = 0 AND payment_id = ?";
1406        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1407        $deliv_id = $arrRet[0]['deliv_id'];
1408    }
1409   
1410    if($deliv_id != "") {
1411        $objQuery->setorder("time_id");
1412        $where = "deliv_id = ?";
1413        $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
1414    }
1415   
1416    return $arrRet;
1417}
1418
1419
1420// ÅÔÆ»Éܸ©¡¢»Ùʧ¤¤ÊýË¡¤«¤éÇÛÁ÷ÎÁ¶â¤ò¼èÆÀ¤¹¤ë
1421function sfGetDelivFee($pref, $payment_id = "") {
1422    $objQuery = new SC_Query();
1423   
1424    $deliv_id = "";
1425   
1426    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢Âбþ¤·¤¿ÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1427    if($payment_id != "") {
1428        $where = "del_flg = 0 AND payment_id = ?";
1429        $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1430        $deliv_id = $arrRet[0]['deliv_id'];
1431    // »Ùʧ¤¤ÊýË¡¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÀèÆ¬¤ÎÇÛÁ÷¶È¼Ô¤ò¼èÆÀ¤¹¤ë
1432    } else {
1433        $where = "del_flg = 0";
1434        $objQuery->setOrder("rank DESC");
1435        $objQuery->setLimitOffset(1);
1436        $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
1437        $deliv_id = $arrRet[0]['deliv_id'];
1438    }
1439   
1440    // ÇÛÁ÷¶È¼Ô¤«¤éÇÛÁ÷ÎÁ¤ò¼èÆÀ
1441    if($deliv_id != "") {
1442       
1443        // ÅÔÆ»Éܸ©¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢ÅìµþÅÔ¤ÎÈÖ¹æ¤ò»ØÄꤷ¤Æ¤ª¤¯
1444        if($pref == "") {
1445            $pref = 13;
1446        }
1447       
1448        $objQuery = new SC_Query();
1449        $where = "deliv_id = ? AND pref = ?";
1450        $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
1451    }   
1452    return $arrRet[0]['fee'];   
1453}
1454
1455/* »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ */
1456function sfGetPayment() {
1457    $objQuery = new SC_Query();
1458    // ¹ØÆþ¶â³Û¤¬¾ò·ï³Û°Ê²¼¤Î¹àÌܤò¼èÆÀ
1459    $where = "del_flg = 0";
1460    $objQuery->setorder("fix, rank DESC");
1461    $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
1462    return $arrRet;
1463}
1464
1465/* ÇÛÎó¤ò¥­¡¼Ì¾¤´¤È¤ÎÇÛÎó¤ËÊѹ¹¤¹¤ë */
1466function sfSwapArray($array) {
1467    $max = count($array);
1468    for($i = 0; $i < $max; $i++) {
1469        foreach($array[$i] as $key => $val) {
1470            $arrRet[$key][] = $val;
1471        }
1472    }
1473    return $arrRet;
1474}
1475
1476/* ¤«¤±»»¤ò¤¹¤ë¡ÊSmartyÍÑ) */
1477function sfMultiply($num1, $num2) {
1478    return ($num1 * $num2);
1479}
1480
1481/* DB¤ËÅÐÏ¿¤µ¤ì¤¿¥Æ¥ó¥×¥ì¡¼¥È¥á¡¼¥ë¤ÎÁ÷¿® */
1482function sfSendTemplateMail($to, $to_name, $template_id, $objPage) {
1483    global $arrMAILTPLPATH;
1484    $objQuery = new SC_Query();
1485    // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1486    $where = "template_id = ?";
1487    $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
1488    $objPage->tpl_header = $arrRet[0]['header'];
1489    $objPage->tpl_footer = $arrRet[0]['footer'];
1490    $tmp_subject = $arrRet[0]['subject'];
1491   
1492    $objSiteInfo = new SC_SiteInfo();
1493    $arrInfo = $objSiteInfo->data;
1494   
1495    $objMailView = new SC_SiteView();
1496    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1497    $objMailView->assignobj($objPage);
1498    $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]);
1499   
1500    // ¥á¡¼¥ëÁ÷¿®½èÍý
1501    $objSendMail = new GC_SendMail();
1502    $from = $arrInfo['email03'];
1503    $error = $arrInfo['email04'];
1504    $tosubject = $tmp_subject;
1505    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error);
1506    $objSendMail->setTo($to, $to_name);
1507    $objSendMail->sendMail();   // ¥á¡¼¥ëÁ÷¿®
1508}
1509
1510/* ¼õÃí´°Î»¥á¡¼¥ëÁ÷¿® */
1511function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
1512    global $arrMAILTPLPATH;
1513   
1514    $objPage = new LC_Page();
1515    $objSiteInfo = new SC_SiteInfo();
1516    $arrInfo = $objSiteInfo->data;
1517    $objPage->arrInfo = $arrInfo;
1518   
1519    $objQuery = new SC_Query();
1520       
1521    if($subject == "" && $header == "" && $footer == "") {
1522        // ¥á¡¼¥ë¥Æ¥ó¥×¥ì¡¼¥È¾ðÊó¤Î¼èÆÀ
1523        $where = "template_id = ?";
1524        $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array('1'));
1525        $objPage->tpl_header = $arrRet[0]['header'];
1526        $objPage->tpl_footer = $arrRet[0]['footer'];
1527        $tmp_subject = $arrRet[0]['subject'];
1528    } else {
1529        $objPage->tpl_header = $header;
1530        $objPage->tpl_footer = $footer;
1531        $tmp_subject = $subject;
1532    }
1533   
1534    // ¼õÃí¾ðÊó¤Î¼èÆÀ
1535    $where = "order_id = ?";
1536    $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
1537    $arrOrder = $arrRet[0];
1538    $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
1539   
1540    $objPage->Message_tmp = $arrOrder['message'];
1541       
1542    // ¸ÜµÒ¾ðÊó¤Î¼èÆÀ
1543    $customer_id = $arrOrder['customer_id'];
1544    $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
1545    $arrCustomer = $arrRet[0];
1546
1547    $objPage->arrCustomer = $arrCustomer;
1548    $objPage->arrOrder = $arrOrder;
1549
1550    //¤½¤Î¾·èºÑ¾ðÊó
1551    if($arrOrder['memo02'] != "") {
1552        $arrOther = unserialize($arrOrder['memo02']);
1553       
1554        foreach($arrOther as $other_key => $other_val){
1555            if(sfTrim($other_val["value"]) == ""){
1556                $arrOther[$other_key]["value"] = "";
1557            }
1558        }
1559       
1560        $objPage->arrOther = $arrOther;
1561    }
1562
1563    // ÅÔÆ»Éܸ©ÊÑ´¹
1564    global $arrPref;
1565    $objPage->arrOrder['deliv_pref'] = $arrPref[$objPage->arrOrder['deliv_pref']];
1566   
1567    $objPage->arrOrderDetail = $arrOrderDetail;
1568   
1569    $objCustomer = new SC_Customer();
1570    $objPage->tpl_user_point = $objCustomer->getValue('point');
1571   
1572    $objMailView = new SC_SiteView();
1573    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1574    $objMailView->assignobj($objPage);
1575    $body = $objMailView->fetch($arrMAILTPLPATH[$template_id]);
1576   
1577    // ¥á¡¼¥ëÁ÷¿®½èÍý
1578    $objSendMail = new GC_SendMail();
1579    $bcc = $arrInfo['email01'];
1580    $from = $arrInfo['email03'];
1581    $error = $arrInfo['email04'];
1582   
1583    $tosubject = sfMakeSubject($tmp_subject);
1584   
1585    $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1586    $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." ÍÍ");
1587
1588
1589    // Á÷¿®¥Õ¥é¥°:true¤Î¾ì¹ç¤Ï¡¢Á÷¿®¤¹¤ë¡£
1590    if($send) {
1591        if ($objSendMail->sendMail()) {
1592            sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
1593        }
1594    }
1595
1596    return $objSendMail;
1597}
1598
1599// ¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ·¤¿¥á¡¼¥ë¤ÎÁ÷¿®
1600function sfSendTplMail($to, $subject, $tplpath, $objPage) {
1601    $objMailView = new SC_SiteView();
1602    $objSiteInfo = new SC_SiteInfo();
1603    $arrInfo = $objSiteInfo->data;
1604    // ¥á¡¼¥ëËÜʸ¤Î¼èÆÀ
1605    $objPage->tpl_shopname=$arrInfo['shop_name'];
1606    $objPage->tpl_infoemail = $arrInfo['email02'];
1607    $objMailView->assignobj($objPage);
1608    $body = $objMailView->fetch($tplpath);
1609    // ¥á¡¼¥ëÁ÷¿®½èÍý
1610    $objSendMail = new GC_SendMail();
1611    $to = mb_encode_mimeheader($to);
1612    $bcc = $arrInfo['email01'];
1613    $from = $arrInfo['email03'];
1614    $error = $arrInfo['email04'];
1615    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1616    $objSendMail->sendMail();   
1617}
1618
1619// Ä̾ï¤Î¥á¡¼¥ëÁ÷¿®
1620function sfSendMail($to, $subject, $body) {
1621    $objSiteInfo = new SC_SiteInfo();
1622    $arrInfo = $objSiteInfo->data;
1623    // ¥á¡¼¥ëÁ÷¿®½èÍý
1624    $objSendMail = new GC_SendMail();
1625    $bcc = $arrInfo['email01'];
1626    $from = $arrInfo['email03'];
1627    $error = $arrInfo['email04'];
1628    $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
1629    $objSendMail->sendMail();
1630}
1631
1632//·ï̾¤Ë¥Æ¥ó¥×¥ì¡¼¥È¤òÍѤ¤¤ë
1633function sfMakeSubject($subject){
1634   
1635    $objQuery = new SC_Query();
1636    $objMailView = new SC_SiteView();
1637    $objPage = new LC_Page();
1638   
1639    $arrInfo = $objQuery->select("*","dtb_baseinfo");
1640    $arrInfo = $arrInfo[0];
1641    $objPage->tpl_shopname=$arrInfo['shop_name'];
1642    $objPage->tpl_infoemail=$subject;
1643    $objMailView->assignobj($objPage);
1644    $mailtitle = $objMailView->fetch('mail_templates/mail_title.tpl');
1645    $ret = $mailtitle.$subject;
1646    return $ret;
1647}
1648
1649// ¥á¡¼¥ëÇÛ¿®ÍúÎò¤Ø¤ÎÅÐÏ¿
1650function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
1651    $sqlval['subject'] = $subject;
1652    $sqlval['order_id'] = $order_id;
1653    $sqlval['template_id'] = $template_id;
1654    $sqlval['send_date'] = "Now()";
1655    if($_SESSION['member_id'] != "") {
1656        $sqlval['creator_id'] = $_SESSION['member_id'];
1657    } else {
1658        $sqlval['creator_id'] = '0';
1659    }
1660    $sqlval['mail_body'] = $body;
1661   
1662    $objQuery = new SC_Query();
1663    $objQuery->insert("dtb_mail_history", $sqlval);
1664}
1665
1666/* ²ñ°÷¾ðÊó¤ò°ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤Ø */
1667function sfGetCustomerSqlVal($uniqid, $sqlval) {
1668    $objCustomer = new SC_Customer();
1669    // ²ñ°÷¾ðÊóÅÐÏ¿½èÍý
1670    if ($objCustomer->isLoginSuccess()) {
1671        // ÅÐÏ¿¥Ç¡¼¥¿¤ÎºîÀ®
1672        $sqlval['order_temp_id'] = $uniqid;
1673        $sqlval['update_date'] = 'Now()';
1674        $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
1675        $sqlval['order_name01'] = $objCustomer->getValue('name01');
1676        $sqlval['order_name02'] = $objCustomer->getValue('name02');
1677        $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
1678        $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
1679        $sqlval['order_sex'] = $objCustomer->getValue('sex');
1680        $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
1681        $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
1682        $sqlval['order_pref'] = $objCustomer->getValue('pref');
1683        $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
1684        $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
1685        $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
1686        $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
1687        $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
1688        $sqlval['order_email'] = $objCustomer->getValue('email');
1689        $sqlval['order_job'] = $objCustomer->getValue('job');
1690        $sqlval['order_birth'] = $objCustomer->getValue('birth');
1691    }
1692    return $sqlval;
1693}
1694
1695// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤Ø¤Î½ñ¤­¹þ¤ß½èÍý
1696function sfRegistTempOrder($uniqid, $sqlval) {
1697    if($uniqid != "") {
1698        // ´û¸¥Ç¡¼¥¿¤Î¥Á¥§¥Ã¥¯
1699        $objQuery = new SC_Query();
1700        $where = "order_temp_id = ?";
1701        $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
1702        // ´û¸¥Ç¡¼¥¿¤¬¤Ê¤¤¾ì¹ç
1703        if ($cnt == 0) {
1704            // ½é²ó½ñ¤­¹þ¤ß»þ¤Ë²ñ°÷¤ÎÅÐÏ¿ºÑ¤ß¾ðÊó¤ò¼è¤ê¹þ¤à
1705            $sqlval = sfGetCustomerSqlVal($uniqid, $sqlval);
1706            $sqlval['create_date'] = "now()";
1707            $objQuery->insert("dtb_order_temp", $sqlval);
1708        } else {
1709            $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
1710        }
1711    }
1712}
1713
1714/* ²ñ°÷¤Î¥á¥ë¥Þ¥¬ÅÐÏ¿¤¬¤¢¤ë¤«¤É¤¦¤«¤Î¥Á¥§¥Ã¥¯(²¾²ñ°÷¤ò´Þ¤Þ¤Ê¤¤) */
1715function sfCheckCustomerMailMaga($email) {
1716    $col = "T1.email, T1.mail_flag, T2.customer_id";
1717    $from = "dtb_customer_mail AS T1 LEFT JOIN dtb_customer AS T2 ON T1.email = T2.email";
1718    $where = "T1.email = ? AND T2.status = 2";
1719    $objQuery = new SC_Query();
1720    $arrRet = $objQuery->select($col, $from, $where, array($email));
1721    // ²ñ°÷¤Î¥á¡¼¥ë¥¢¥É¥ì¥¹¤¬ÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë
1722    if($arrRet[0]['customer_id'] != "") {
1723        return true;
1724    }
1725    return false;
1726}
1727
1728// ¥«¡¼¥É¤Î½èÍý·ë²Ì¤òÊÖ¤¹
1729function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){
1730
1731    $path = $dir .$file_name;       // cgi¥Õ¥¡¥¤¥ë¤Î¥Õ¥ë¥Ñ¥¹À¸À®
1732    $now_dir = getcwd();            // require¤¬¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¤Î¤Ç¡¢cgi¼Â¹Ô¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Üư¤¹¤ë
1733    chdir($dir);
1734   
1735    // ¥Ñ¥¤¥×ÅϤ·¤Ç¥³¥Þ¥ó¥É¥é¥¤¥ó¤«¤écgiµ¯Æ°
1736    $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info";
1737
1738    $tmpResult = popen($cmd, "r");
1739   
1740    // ·ë²Ì¼èÆÀ
1741    while( ! FEOF ( $tmpResult ) ) {
1742        $result .= FGETS($tmpResult);
1743    }
1744    pclose($tmpResult);             //  ¥Ñ¥¤¥×¤òÊĤ¸¤ë
1745    chdir($now_dir);                //¡¡¸µ¤Ë¤¤¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Ëµ¢¤ë
1746   
1747    // ·ë²Ì¤òÏ¢ÁÛÇÛÎ󤨳ÊǼ
1748    $result = ereg_replace("&$", "", $result);
1749    foreach (explode("&",$result) as $data) {
1750        list($key, $val) = explode("=", $data, 2);
1751        $return[$key] = $val;
1752    }
1753   
1754    return $return;
1755}
1756
1757// ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¾ðÊó¤ò¼èÆÀ¤¹¤ë
1758function sfGetOrderTemp($order_temp_id) {
1759    $objQuery = new SC_Query();
1760    $where = "order_temp_id = ?";
1761    $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
1762    return $arrRet[0];
1763}
1764
1765// ¥«¥Æ¥´¥êID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
1766$g_category_on = false;
1767$g_category_id = "";
1768
1769/* ÁªÂòÃæ¤Î¥«¥Æ¥´¥ê¤ò¼èÆÀ¤¹¤ë */
1770function sfGetCategoryId($product_id, $category_id) {
1771    global $g_category_on;
1772    global $g_category_id;
1773    if(!$g_category_on) {
1774        $g_category_on = true;
1775        if(sfIsInt($category_id) && sfIsRecord("dtb_category","category_id", $category_id)) {
1776            $g_category_id = $category_id;
1777        } else if (sfIsInt($product_id) && sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) {
1778            $objQuery = new SC_Query();
1779            $where = "product_id = ?";
1780            $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id));
1781            $g_category_id = $category_id;
1782        } else {
1783            // ÉÔÀµ¤Ê¾ì¹ç¤Ï¡¢0¤òÊÖ¤¹¡£
1784            $g_category_id = 0;
1785        }
1786    }
1787    return $g_category_id;
1788}
1789
1790// ROOTID¼èÆÀȽÄêÍѤΥ°¥í¡¼¥Ð¥ëÊÑ¿ô(°ìÅÙ¼èÆÀ¤µ¤ì¤Æ¤¤¤¿¤éºÆ¼èÆÀ¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë)
1791$g_root_on = false;
1792$g_root_id = "";
1793
1794/* ÁªÂòÃæ¤Î¥¢¥¤¥Æ¥à¤Î¥ë¡¼¥È¥«¥Æ¥´¥êID¤ò¼èÆÀ¤¹¤ë */
1795function sfGetRootId() {
1796    global $g_root_on;
1797    global $g_root_id;
1798    if(!$g_root_on) {
1799        $g_root_on = true;
1800        $objQuery = new SC_Query();
1801        if($_GET['product_id'] != "" || $_GET['category_id'] != "") {
1802            // ÁªÂòÃæ¤Î¥«¥Æ¥´¥êID¤òȽÄꤹ¤ë
1803            $category_id = sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
1804            // ROOT¥«¥Æ¥´¥êID¤Î¼èÆÀ
1805             $arrRet = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
1806             $root_id = $arrRet[0];
1807        } else {
1808            // ROOT¥«¥Æ¥´¥êID¤ò¤Ê¤·¤ËÀßÄꤹ¤ë
1809            $root_id = "";
1810        }
1811        $g_root_id = $root_id;
1812    }
1813    return $g_root_id;
1814}
1815
1816/* ¥«¥Æ¥´¥ê¤«¤é¾¦Éʤò¸¡º÷¤¹¤ë¾ì¹ç¤ÎWHEREʸ¤ÈÃͤòÊÖ¤¹ */
1817function sfGetCatWhere($category_id) {
1818    // »Ò¥«¥Æ¥´¥êID¤Î¼èÆÀ
1819    $arrRet = sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
1820    $tmp_where = "";
1821    foreach ($arrRet as $val) {
1822        if($tmp_where == "") {
1823            $tmp_where.= " category_id IN ( ? ";
1824        } else {
1825            $tmp_where.= " ,? ";
1826        }
1827        $arrval[] = $val;
1828    }
1829    $tmp_where.= " ) ";
1830    return array($tmp_where, $arrval);
1831}
1832
1833/* ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»¼° */
1834function sfGetAddPoint($totalpoint, $use_point, $arrInfo) {
1835    // ¹ØÆþ¾¦Éʤιç·×¥Ý¥¤¥ó¥È¤«¤éÍøÍѤ·¤¿¥Ý¥¤¥ó¥È¤Î¥Ý¥¤¥ó¥È´¹»»²ÁÃͤò°ú¤¯Êý¼°
1836    $add_point = $totalpoint - intval($use_point * ($arrInfo['point_rate'] / 100));
1837   
1838    if($add_point < 0) {
1839        $add_point = '0';
1840    }
1841    return $add_point;
1842}
1843
1844/* °ì°Õ¤«¤Äͽ¬¤µ¤ì¤Ë¤¯¤¤ID */
1845function sfGetUniqRandomId($head = "") {
1846    // ͽ¬¤µ¤ì¤Ê¤¤¤è¤¦¤Ë¥é¥ó¥À¥àʸ»úÎó¤òÉÕÍ¿¤¹¤ë¡£
1847    $random = gfMakePassword(8);
1848    // Ʊ°ì¥Û¥¹¥ÈÆâ¤Ç°ì°Õ¤ÊID¤òÀ¸À®
1849    $id = uniqid($head);
1850    return ($id . $random);
1851}
1852
1853// ¥«¥Æ¥´¥êÊÌ¥ª¥¹¥¹¥áÉʤμèÆÀ
1854function sfGetBestProducts( $conn, $category_id = 0){
1855    // ´û¤ËÅÐÏ¿¤µ¤ì¤Æ¤¤¤ëÆâÍÆ¤ò¼èÆÀ¤¹¤ë
1856    $sql = "SELECT name, main_image, main_list_image, price01_min, price01_max, price02_min, price02_max, point_rate,
1857             A.product_id, A.comment FROM dtb_best_products as A LEFT JOIN vw_products_allclass AS allcls
1858            USING (product_id) WHERE A.category_id = ? AND A.del_flg = 0 AND status = 1 ORDER BY A.rank";
1859    $arrItems = $conn->getAll($sql, array($category_id));
1860
1861    return $arrItems;
1862}
1863
1864// ÆÃ¼ìÀ©¸æÊ¸»ú¤Î¼êư¥¨¥¹¥±¡¼¥×
1865function sfManualEscape($data) {
1866    // ÇÛÎó¤Ç¤Ê¤¤¾ì¹ç
1867    if(!is_array($data)) {
1868        if (DB_TYPE == "pgsql") {
1869            $ret = pg_escape_string($data);
1870        }else if(DB_TYPE == "mysql"){
1871            $ret = mysql_real_escape_string($data);
1872        }
1873        $ret = ereg_replace("%", "\\%", $ret);
1874        $ret = ereg_replace("_", "\\_", $ret);
1875        return $ret;
1876    }
1877   
1878    // ÇÛÎó¤Î¾ì¹ç
1879    foreach($data as $val) {
1880        if (DB_TYPE == "pgsql") {
1881            $ret = pg_escape_string($val);
1882        }else if(DB_TYPE == "mysql"){
1883            $ret = mysql_real_escape_string($val);
1884        }
1885
1886        $ret = ereg_replace("%", "\\%", $ret);
1887        $ret = ereg_replace("_", "\\_", $ret);
1888        $arrRet[] = $ret;
1889    }
1890
1891    return $arrRet;
1892}
1893
1894// ¼õÃíÈÖ¹æ¡¢ÍøÍѥݥ¤¥ó¥È¡¢²Ã»»¥Ý¥¤¥ó¥È¤«¤éºÇ½ª¥Ý¥¤¥ó¥È¤ò¼èÆÀ
1895function sfGetCustomerPoint($order_id, $use_point, $add_point) {
1896    $objQuery = new SC_Query();
1897    $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
1898    $customer_id = $arrRet[0]['customer_id'];
1899    if($customer_id != "" && $customer_id >= 1) {
1900        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
1901        $point = $arrRet[0]['point'];
1902        $total_point = $arrRet[0]['point'] - $use_point + $add_point;
1903    } else {
1904        $total_point = "";
1905        $point = "";
1906    }
1907    return array($point, $total_point);
1908}
1909
1910/* ¥É¥á¥¤¥ó´Ö¤ÇÍ­¸ú¤Ê¥»¥Ã¥·¥ç¥ó¤Î¥¹¥¿¡¼¥È */
1911function sfDomainSessionStart() {
1912    $ret = session_id();
1913/*
1914    ¥Ø¥Ã¥À¡¼¤òÁ÷¿®¤·¤Æ¤¤¤Æ¤âsession_start()¤¬É¬Íפʥڡ¼¥¸¤¬¤¢¤ë¤Î¤Ç
1915    ¥³¥á¥ó¥È¥¢¥¦¥È¤·¤Æ¤ª¤¯
1916    if($ret == "" && !headers_sent()) {
1917*/
1918    if($ret == "") {
1919        /* ¥»¥Ã¥·¥ç¥ó¥Ñ¥é¥á¡¼¥¿¤Î»ØÄê
1920         ¡¦¥Ö¥é¥¦¥¶¤òÊĤ¸¤ë¤Þ¤ÇÍ­¸ú
1921         ¡¦¤¹¤Ù¤Æ¤Î¥Ñ¥¹¤ÇÍ­¸ú
1922         ¡¦Æ±¤¸¥É¥á¥¤¥ó´Ö¤Ç¶¦Í­ */
1923        session_set_cookie_params (0, "/", DOMAIN_NAME);
1924
1925        if(!ini_get("session.auto_start")){
1926            // ¥»¥Ã¥·¥ç¥ó³«»Ï
1927            session_start();
1928        }
1929    }
1930}
1931
1932/* ʸ»úÎó¤Ë¶¯À©Åª¤Ë²þ¹Ô¤òÆþ¤ì¤ë */
1933function sfPutBR($str, $size) {
1934    $i = 0;
1935    $cnt = 0;
1936    $line = array();
1937    $ret = "";
1938   
1939    while($str[$i] != "") {
1940        $line[$cnt].=$str[$i];
1941        $i++;
1942        if(strlen($line[$cnt]) > $size) {
1943            $line[$cnt].="<br />";
1944            $cnt++;
1945        }
1946    }
1947   
1948    foreach($line as $val) {
1949        $ret.=$val;
1950    }
1951    return $ret;
1952}
1953
1954// Æó²ó°Ê¾å·«¤êÊÖ¤µ¤ì¤Æ¤¤¤ë¥¹¥é¥Ã¥·¥å[/]¤ò°ì¤Ä¤ËÊÑ´¹¤¹¤ë¡£
1955function sfRmDupSlash($istr){
1956    if(ereg("^http://", $istr)) {
1957        $str = substr($istr, 7);
1958        $head = "http://";
1959    } else if(ereg("^https://", $istr)) {
1960        $str = substr($istr, 8);
1961        $head = "https://";
1962    } else {
1963        $str = $istr;
1964    }
1965    $str = ereg_replace("[/]+", "/", $str);
1966    $ret = $head . $str;
1967    return $ret;   
1968}
1969
1970function sfEncodeFile($filepath, $enc_type, $out_dir) {
1971    $ifp = fopen($filepath, "r");
1972   
1973    $basename = basename($filepath);
1974    $outpath = $out_dir . "enc_" . $basename;
1975   
1976    $ofp = fopen($outpath, "w+");
1977   
1978    while(!feof($ifp)) {
1979        $line = fgets($ifp);
1980        $line = mb_convert_encoding($line, $enc_type, "auto");
1981        fwrite($ofp,  $line);
1982    }
1983   
1984    fclose($ofp);
1985    fclose($ifp);
1986   
1987    return  $outpath;
1988}
1989
1990function sfCutString($str, $len, $byte = true, $commadisp = true) {
1991    if($byte) {
1992        if(strlen($str) > ($len + 2)) {
1993            $ret =substr($str, 0, $len);
1994        } else {
1995            $ret = $str;
1996            $commadisp = false;
1997        }
1998    } else {
1999        if(mb_strlen($str) > ($len + 1)) {
2000            $ret = mb_substr($str, 0, $len);
2001        } else {
2002            $ret = $str;
2003            $commadisp = false;
2004        }
2005    }
2006    if($commadisp){
2007        $ret = $ret . "...";
2008    }
2009    return $ret;
2010}
2011
2012// ǯ¡¢·î¡¢Äù¤áÆü¤«¤é¡¢Àè·î¤ÎÄù¤áÆü+1¡¢º£·î¤ÎÄù¤áÆü¤òµá¤á¤ë¡£
2013function sfTermMonth($year, $month, $close_day) {
2014    $end_year = $year;
2015    $end_month = $month;
2016   
2017    // ³«»Ï·î¤¬½ªÎ»·î¤ÈƱ¤¸¤«Èݤ«
2018    $same_month = false;
2019   
2020    // ³ºÅö·î¤ÎËöÆü¤òµá¤á¤ë¡£
2021    $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year));
2022   
2023    // ·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2024    if($end_last_day < $close_day) {
2025        // Äù¤áÆü¤ò·îËöÆü¤Ë¹ç¤ï¤»¤ë
2026        $end_day = $end_last_day;
2027    } else {
2028        $end_day = $close_day;
2029    }
2030   
2031    // Á°·î¤Î¼èÆÀ
2032    $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year));
2033    $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year));
2034    // Á°·î¤ÎËöÆü¤òµá¤á¤ë¡£
2035    $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year));
2036   
2037    // Á°·î¤ÎËöÆü¤¬Äù¤áÆü¤è¤ê¾¯¤Ê¤¤¾ì¹ç
2038    if ($start_last_day < $close_day) {
2039        // ·îËöÆü¤Ë¹ç¤ï¤»¤ë
2040        $tmp_day = $start_last_day;
2041    } else {
2042        $tmp_day = $close_day;
2043    }
2044   
2045    // Àè·î¤ÎËöÆü¤ÎÍâÆü¤ò¼èÆÀ¤¹¤ë
2046    $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2047    $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2048    $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year));
2049   
2050    // ÆüÉդκîÀ®
2051    $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day);
2052    $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day);
2053   
2054    return array($start_date, $end_date);
2055}
2056
2057// PDFÍѤÎRGB¥«¥é¡¼¤òÊÖ¤¹
2058function sfGetPdfRgb($hexrgb) {
2059    $hex = substr($hexrgb, 0, 2);
2060    $r = hexdec($hex) / 255;
2061   
2062    $hex = substr($hexrgb, 2, 2);
2063    $g = hexdec($hex) / 255;
2064   
2065    $hex = substr($hexrgb, 4, 2);
2066    $b = hexdec($hex) / 255;
2067   
2068    return array($r, $g, $b);   
2069}
2070
2071//¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤È¥á¡¼¥ëÇÛ¿®
2072function sfRegistTmpMailData($mail_flag, $email){
2073    $objQuery = new SC_Query();
2074    $objConn = new SC_DBConn();
2075    $objPage = new LC_Page();
2076   
2077    $random_id = sfGetUniqRandomId();
2078    $arrRegistMailMagazine["mail_flag"] = $mail_flag;
2079    $arrRegistMailMagazine["email"] = $email;
2080    $arrRegistMailMagazine["temp_id"] =$random_id;
2081    $arrRegistMailMagazine["end_flag"]='0';
2082    $arrRegistMailMagazine["update_date"] = 'now()';
2083   
2084    //¥á¥ë¥Þ¥¬²¾ÅÐÏ¿Íѥե饰
2085    $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email));
2086    $objConn->query("BEGIN");
2087    switch ($flag){
2088        case '0':
2089        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine);
2090        break;
2091   
2092        case '1':
2093        $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = '" .addslashes($email). "'");
2094        break;
2095    }
2096    $objConn->query("COMMIT");
2097    $subject = sfMakeSubject('¥á¥ë¥Þ¥¬²¾ÅÐÏ¿¤¬´°Î»¤·¤Þ¤·¤¿¡£');
2098    $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id'];
2099    switch ($mail_flag){
2100        case '1':
2101        $objPage->tpl_name = "ÅÐÏ¿";
2102        $objPage->tpl_kindname = "HTML";
2103        break;
2104       
2105        case '2':
2106        $objPage->tpl_name = "ÅÐÏ¿";
2107        $objPage->tpl_kindname = "¥Æ¥­¥¹¥È";
2108        break;
2109       
2110        case '3':
2111        $objPage->tpl_name = "²ò½ü";
2112        break;
2113    }
2114        $objPage->tpl_email = $email;
2115    sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage);
2116}
2117
2118// ºÆµ¢Åª¤Ë¿ÃÊÇÛÎó¤ò¸¡º÷¤·¤Æ°ì¼¡¸µÇÛÎó(Hidden°úÅϤ·ÍÑÇÛÎó)¤ËÊÑ´¹¤¹¤ë¡£
2119function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") {
2120    if(is_array($arrSrc)) {
2121        foreach($arrSrc as $key => $val) {
2122            if($parent_key != "") {
2123                $keyname = $parent_key . "[". $key . "]";
2124            } else {
2125                $keyname = $key;
2126            }
2127            if(is_array($val)) {
2128                $arrDst = sfMakeHiddenArray($val, $arrDst, $keyname);
2129            } else {
2130                $arrDst[$keyname] = $val;
2131            }
2132        }
2133    }
2134    return $arrDst;
2135}
2136
2137// DB¼èÆÀÆü»þ¤ò¥¿¥¤¥à¤ËÊÑ´¹
2138function sfDBDatetoTime($db_date) {
2139    $date = ereg_replace("\..*$","",$db_date);
2140    $time = strtotime($date);
2141    return $time;
2142}
2143
2144// ½ÐÎϤκݤ˥ƥó¥×¥ì¡¼¥È¤òÀÚ¤êÂØ¤¨¤é¤ì¤ë
2145/*
2146    index.php?tpl=test.tpl
2147*/
2148function sfCustomDisplay($objPage) {
2149    $basename = basename($_SERVER["REQUEST_URI"]);
2150
2151    if($basename == "") {
2152        $path = $_SERVER["REQUEST_URI"] . "index.php";
2153    } else {
2154        $path = $_SERVER["REQUEST_URI"];
2155    }   
2156
2157    if($_GET['tpl'] != "") {
2158        $tpl_name = $_GET['tpl'];
2159    } else {
2160        $tpl_name = ereg_replace("^/", "", $path);
2161        $tpl_name = ereg_replace("/", "_", $tpl_name);
2162        $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name);
2163    }
2164
2165    $template_path = TEMPLATE_FTP_DIR . $tpl_name;
2166
2167    if(file_exists($template_path)) {
2168        $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR);
2169        $objView->assignobj($objPage);
2170        $objView->display($tpl_name);
2171    } else {
2172        $objView = new SC_SiteView();
2173        $objView->assignobj($objPage);
2174        $objView->display(SITE_FRAME);
2175    }
2176}
2177
2178//²ñ°÷ÊÔ½¸ÅÐÏ¿½èÍý
2179function sfEditCustomerData($array, $arrRegistColumn) {
2180    $objQuery = new SC_Query();
2181   
2182    foreach ($arrRegistColumn as $data) {
2183        if ($data["column"] != "password") {
2184            if($array[ $data['column'] ] != "") {
2185                $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
2186            } else {
2187                $arrRegist[ $data['column'] ] = NULL;
2188            }
2189        }
2190    }
2191    if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
2192        $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
2193    } else {
2194        $arrRegist["birth"] = NULL;
2195    }
2196
2197    //-- ¥Ñ¥¹¥ï¡¼¥É¤Î¹¹¿·¤¬¤¢¤ë¾ì¹ç¤Ï°Å¹æ²½¡£¡Ê¹¹¿·¤¬¤Ê¤¤¾ì¹ç¤ÏUPDATEʸ¤ò¹½À®¤·¤Ê¤¤¡Ë
2198    if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
2199    $arrRegist["update_date"] = "NOW()";
2200   
2201    $sqlval["create_date"] = "NOW()";
2202    $sqlval["update_date"] = "NOW()";
2203    $sqlval['email'] = $array['email'];
2204    $sqlval['mail_flag'] = $array['mail_flag'];
2205    //-- ÊÔ½¸ÅÐÏ¿¼Â¹Ô
2206    $objQuery->begin();
2207    $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
2208    $objQuery->delete("dtb_customer_mail", "email = ?", array($array['email']));
2209    $objQuery->insert("dtb_customer_mail", $sqlval);
2210    $objQuery->commit();
2211}
2212
2213// PHP¤Îmb_convert_encoding´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2214function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') {
2215    return  mb_convert_encoding($str, $encode);
2216}   
2217
2218// PHP¤Îmktime´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2219function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) {
2220    return  date($format,mktime($hour, $minute, $second, $month, $day, $year));
2221}   
2222
2223// PHP¤Îdate´Ø¿ô¤òSmarty¤Ç¤â»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
2224function sf_date($format, $timestamp = '') {
2225    return  date( $format, $timestamp);
2226}
2227
2228// ¥Á¥§¥Ã¥¯¥Ü¥Ã¥¯¥¹¤Î·¿¤òÊÑ´¹¤¹¤ë
2229function sfChangeCheckBox($data , $tpl = false){
2230    if ($tpl) {
2231        if ($data == 1){
2232            return 'checked';
2233        }else{
2234            return "";
2235        }
2236    }else{
2237        if ($data == "on"){
2238            return 1;
2239        }else{
2240            return 2;
2241        }
2242    }
2243}
2244
2245function sfCategory_Count($objQuery){
2246    $sql = "";
2247   
2248    //¥Æ¡¼¥Ö¥ëÆâÍÆ¤Îºï½ü
2249    $objQuery->query("DELETE FROM dtb_category_count");
2250    $objQuery->query("DELETE FROM dtb_category_total_count");
2251   
2252    //³Æ¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò¿ô¤¨¤Æ³ÊǼ
2253    $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";
2254    $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 ";
2255    $sql .= " ON T1.category_id = T2.category_id  ";
2256    $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";
2257    $sql .= " GROUP BY T1.category_id, T2.category_id ";
2258    $objQuery->query($sql);
2259   
2260    //»Ò¥«¥Æ¥´¥êÆâ¤Î¾¦ÉÊ¿ô¤ò½¸·×¤¹¤ë
2261    $arrCat = $objQuery->getAll("SELECT * FROM dtb_category");
2262   
2263    $sql = "";
2264    foreach($arrCat as $key => $val){
2265       
2266        // »ÒID°ìÍ÷¤ò¼èÆÀ
2267        $arrRet = sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);
2268        $line = sfGetCommaList($arrRet);
2269       
2270        $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";
2271        $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";
2272        $sql .= " WHERE category_id IN (" . $line . ")";
2273               
2274        $objQuery->query($sql, array($val['category_id']));
2275    }
2276}
2277
2278// 2¤Ä¤ÎÇÛÎó¤òÍѤ¤¤ÆÏ¢ÁÛÇÛÎó¤òºîÀ®¤¹¤ë
2279function sfarrCombine($arrKeys, $arrValues) {
2280
2281    if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array();
2282   
2283    $keys = array_values($arrKeys);
2284    $vals = array_values($arrValues);
2285   
2286    $max = max( count( $keys ), count( $vals ) );
2287    $combine_ary = array();
2288    for($i=0; $i<$max; $i++) {
2289        $combine_ary[$keys[$i]] = $vals[$i];
2290    }
2291    if(is_array($combine_ary)) return $combine_ary;
2292   
2293    return false;
2294}
2295
2296/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é»ÒIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2297function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
2298    $objQuery = new SC_Query();
2299    $col = $pid_name . "," . $id_name;
2300    $arrData = $objQuery->select($col, $table);
2301   
2302    $arrPID = array();
2303    $arrPID[] = $id;
2304    $arrChildren = array();
2305    $arrChildren[] = $id;
2306   
2307    $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
2308   
2309    while(count($arrRet) > 0) {
2310        $arrChildren = array_merge($arrChildren, $arrRet);
2311        $arrRet = sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
2312    }
2313   
2314    return $arrChildren;
2315}
2316
2317/* ¿ÆIDľ²¼¤Î»ÒID¤ò¤¹¤Ù¤Æ¼èÆÀ¤¹¤ë */
2318function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
2319    $arrChildren = array();
2320    $max = count($arrData);
2321   
2322    for($i = 0; $i < $max; $i++) {
2323        foreach($arrPID as $val) {
2324            if($arrData[$i][$pid_name] == $val) {
2325                $arrChildren[] = $arrData[$i][$id_name];
2326            }
2327        }
2328    }   
2329    return $arrChildren;
2330}
2331
2332
2333/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤é¿ÆIDÇÛÎó¤ò¼èÆÀ¤¹¤ë */
2334function sfGetParentsArray($table, $pid_name, $id_name, $id) {
2335    $objQuery = new SC_Query();
2336    $col = $pid_name . "," . $id_name;
2337    $arrData = $objQuery->select($col, $table);
2338   
2339    $arrParents = array();
2340    $arrParents[] = $id;
2341    $child = $id;
2342   
2343    $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
2344
2345    while($ret != "") {
2346        $arrParents[] = $ret;
2347        $ret = sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
2348    }
2349   
2350    $arrParents = array_reverse($arrParents);
2351   
2352    return $arrParents;
2353}
2354
2355/* »ÒID½ê°¤¹¤ë¿ÆID¤ò¼èÆÀ¤¹¤ë */
2356function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) {
2357    $max = count($arrData);
2358    $parent = "";
2359    for($i = 0; $i < $max; $i++) {
2360        if($arrData[$i][$id_name] == $child) {
2361            $parent = $arrData[$i][$pid_name];
2362            break;
2363        }
2364    }
2365    return $parent;
2366}
2367
2368/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Î·»Äï¤ò¼èÆÀ¤¹¤ë */
2369function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) {
2370    $max = count($arrData);
2371   
2372    $arrBrothers = array();
2373    foreach($arrPID as $id) {
2374        // ¿ÆID¤ò¸¡º÷¤¹¤ë
2375        for($i = 0; $i < $max; $i++) {
2376            if($arrData[$i][$id_name] == $id) {
2377                $parent = $arrData[$i][$pid_name];
2378                break;
2379            }
2380        }
2381        // ·»ÄïID¤ò¸¡º÷¤¹¤ë
2382        for($i = 0; $i < $max; $i++) {
2383            if($arrData[$i][$pid_name] == $parent) {
2384                $arrBrothers[] = $arrData[$i][$id_name];
2385            }
2386        }                   
2387    }
2388    return $arrBrothers;
2389}
2390
2391/* ³¬Áع½Â¤¤Î¥Æ¡¼¥Ö¥ë¤«¤éÍ¿¤¨¤é¤ì¤¿ID¤Îľ°¤Î»Ò¤ò¼èÆÀ¤¹¤ë */
2392function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) {
2393    $max = count($arrData);
2394   
2395    $arrChildren = array();
2396    // »ÒID¤ò¸¡º÷¤¹¤ë
2397    for($i = 0; $i < $max; $i++) {
2398        if($arrData[$i][$pid_name] == $parent) {
2399            $arrChildren[] = $arrData[$i][$id_name];
2400        }
2401    }                   
2402    return $arrChildren;
2403}
2404
2405
2406// ¥«¥Æ¥´¥ê¥Ä¥ê¡¼¤Î¼èÆÀ
2407function sfGetCatTree($parent_category_id, $count_check = false) {
2408    $objQuery = new SC_Query();
2409    $col = "";
2410    $col .= " cat.category_id,";
2411    $col .= " cat.category_name,";
2412    $col .= " cat.parent_category_id,";
2413    $col .= " cat.level,";
2414    $col .= " cat.rank,";
2415    $col .= " cat.creator_id,";
2416    $col .= " cat.create_date,";
2417    $col .= " cat.update_date,";
2418    $col .= " cat.del_flg, ";
2419    $col .= " ttl.product_count";   
2420    $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
2421    // ÅÐÏ¿¾¦ÉÊ¿ô¤Î¥Á¥§¥Ã¥¯
2422    if($count_check) {
2423        $where = "del_flg = 0 AND product_count > 0";
2424    } else {
2425        $where = "del_flg = 0";
2426    }
2427    $objQuery->setoption("ORDER BY rank DESC");
2428    $arrRet = $objQuery->select($col, $from, $where);
2429   
2430    $arrParentID = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
2431   
2432    foreach($arrRet as $key => $array) {
2433        foreach($arrParentID as $val) {
2434            if($array['category_id'] == $val) {
2435                $arrRet[$key]['display'] = 1;
2436                break;
2437            }
2438        }
2439    }
2440
2441    return $arrRet;
2442}
2443
2444// ¿Æ¥«¥Æ¥´¥ê¡¼¤òÏ¢·ë¤·¤¿Ê¸»úÎó¤ò¼èÆÀ¤¹¤ë
2445function sfGetCatCombName($category_id){
2446    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2447    $objQuery = new SC_Query();
2448    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2449    $ConbName = "";
2450   
2451    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2452    foreach($arrCatID as $key => $val){
2453        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2454        $arrVal = array($val);
2455        $CatName = $objQuery->getOne($sql,$arrVal);
2456        $ConbName .= $CatName . ' | ';
2457    }
2458    // ºÇ¸å¤Î ¡Ã ¤ò¥«¥Ã¥È¤¹¤ë
2459    $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2);
2460   
2461    return $ConbName;
2462}
2463
2464// »ØÄꤷ¤¿¥«¥Æ¥´¥ê¡¼ID¤ÎÂ祫¥Æ¥´¥ê¡¼¤ò¼èÆÀ¤¹¤ë
2465function GetFirstCat($category_id){
2466    // ¾¦Éʤ¬Â°¤¹¤ë¥«¥Æ¥´¥êID¤ò½Ä¤Ë¼èÆÀ
2467    $objQuery = new SC_Query();
2468    $arrRet = array();
2469    $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
2470    $arrRet['id'] = $arrCatID[0];
2471   
2472    // ¥«¥Æ¥´¥ê¡¼Ì¾¾Î¤ò¼èÆÀ¤¹¤ë
2473    $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
2474    $arrVal = array($arrRet['id']);
2475    $arrRet['name'] = $objQuery->getOne($sql,$arrVal);
2476   
2477    return $arrRet;
2478}
2479
2480//MySQLÍѤÎSQLʸ¤ËÊѹ¹¤¹¤ë
2481function sfChangeMySQL($sql){
2482    // ²þ¹Ô¡¢¥¿¥Ö¤ò1¥¹¥Ú¡¼¥¹¤ËÊÑ´¹
2483    $sql = preg_replace("/[\r\n\t]/"," ",$sql);
2484   
2485    $sql = sfChangeView($sql);      // viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2486    $sql = sfChangeILIKE($sql);     // ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2487    $sql = sfChangeRANDOM($sql);    // RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2488
2489    return $sql;
2490}
2491
2492// ÇÛÎó¤ÎÃæ¤Ë¥Ç¡¼¥¿¤¬Â¸ºß¤·¤Æ¤¤¤ë¤«¥Á¥§¥Ã¥¯¤ò¹Ô¤¦(Âçʸ»ú¾®Ê¸»ú¤Î¶èÊ̤ʤ·)
2493function sfInArray($sql){
2494    global $arrView;
2495
2496    foreach($arrView as $key => $val){
2497        if (strcasecmp($sql, $val) == 0){
2498            $changesql = eregi_replace("($key)", "$val", $sql);
2499            sfInArray($changesql);
2500        }
2501    }
2502    return false;
2503}
2504
2505// viewɽ¤ò¥¤¥ó¥é¥¤¥ó¥Ó¥å¡¼¤ËÊÑ´¹¤¹¤ë
2506function sfChangeView($sql){
2507    global $arrView;
2508
2509    $changesql = strtr($sql,$arrView);
2510
2511    return $changesql;
2512}
2513
2514// ILIKE¸¡º÷¤òLIKE¸¡º÷¤ËÊÑ´¹¤¹¤ë
2515function sfChangeILIKE($sql){
2516    $changesql = eregi_replace("(ILIKE )", "LIKE BINARY ", $sql);
2517    return $changesql;
2518}
2519
2520// RANDOM()¤òRAND()¤ËÊÑ´¹¤¹¤ë
2521function sfChangeRANDOM($sql){
2522    $changesql = eregi_replace("( RANDOM)", " RAND", $sql);
2523    return $changesql;
2524}
2525
2526// ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤Î¥Õ¥¡¥¤¥ë¤òºÆµ¢Åª¤Ë¥³¥Ô¡¼
2527function sfCopyDir($src, $des, $mess, $override = false){
2528    if(!is_dir($src)){
2529        return false;
2530    }
2531
2532    $oldmask = umask(0);
2533    $mod= stat($src);
2534   
2535    // ¥Ç¥£¥ì¥¯¥È¥ê¤¬¤Ê¤±¤ì¤ÐºîÀ®¤¹¤ë
2536    if(!file_exists($des)) {
2537        if(!mkdir($des, $mod[2])) {
2538            print("path:" . $des);
2539        }
2540    }
2541   
2542    $fileArray=glob( $src."*" );
2543    foreach( $fileArray as $key => $data_ ){
2544        // CVS´ÉÍý¥Õ¥¡¥¤¥ë¤Ï¥³¥Ô¡¼¤·¤Ê¤¤
2545        if(ereg("/CVS/Entries", $data_)) {
2546            break;
2547        }
2548        if(ereg("/CVS/Repository", $data_)) {
2549            break;
2550        }
2551        if(ereg("/CVS/Root", $data_)) {
2552            break;
2553        }
2554       
2555        mb_ereg("^(.*[\/])(.*)",$data_, $matches);
2556        $data=$matches[2];
2557        if( is_dir( $data_ ) ){
2558            $mess = sfCopyDir( $data_.'/', $des.$data.'/', $mess);
2559        }else{
2560            if(!$override && file_exists($des.$data)) {
2561                $mess.= $des.$data . "¡§¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Þ¤¹\n";
2562            } else {
2563                if(@copy( $data_, $des.$data)) {
2564                    $mess.= $des.$data . "¡§¥³¥Ô¡¼À®¸ù\n";
2565                } else {
2566                    $mess.= $des.$data . "¡§¥³¥Ô¡¼¼ºÇÔ\n";
2567                }
2568            }
2569            $mod=stat($data_ );
2570        }
2571    }
2572    umask($oldmask);
2573    return $mess;
2574}
2575
2576// »ØÄꤷ¤¿¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òÁ´¤Æºï½ü¤¹¤ë
2577function sfDelFile($dir){
2578    $dh = opendir($dir);
2579    // ¥Õ¥©¥ë¥ÀÆâ¤Î¥Õ¥¡¥¤¥ë¤òºï½ü
2580    while($file = readdir($dh)){
2581        if ($file == "." or $file == "..") continue;
2582        $del_file = $dir . "/" . $file;
2583        if(is_file($del_file)){
2584            $ret = unlink($dir . "/" . $file);
2585        }else if (is_dir($del_file)){
2586            $ret = sfDelFile($del_file);
2587        }
2588       
2589        if(!$ret){
2590            return $ret;
2591        }
2592    }
2593    // ¥Õ¥©¥ë¥À¤òºï½ü
2594    return rmdir($dir);
2595   
2596}
2597
2598function sfFlush($output = " ", $sleep = 0){
2599    // ¼Â¹Ô»þ´Ö¤òÀ©¸Â¤·¤Ê¤¤
2600    set_time_limit(0);
2601    // ½ÐÎϤò¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤·¤Ê¤¤(==ÆüËܸ켫ưÊÑ´¹¤â¤·¤Ê¤¤)
2602    ob_end_clean();
2603   
2604    // IE¤Î¤¿¤á¤Ë256¥Ð¥¤¥È¶õʸ»ú½ÐÎÏ
2605    echo str_pad('',256);
2606   
2607    // ½ÐÎϤϥ֥é¥ó¥¯¤À¤±¤Ç¤â¤¤¤¤¤È»×¤¦
2608    echo $output;
2609    // ½ÐÎϤò¥Õ¥é¥Ã¥·¥å¤¹¤ë
2610    flush();
2611   
2612    ob_end_flush();
2613    ob_start();
2614   
2615    // »þ´Ö¤Î¤«¤«¤ë½èÍý
2616    sleep($sleep);
2617}
2618
2619// @version¤Îµ­ºÜ¤¬¤¢¤ë¥Õ¥¡¥¤¥ë¤«¤é¥Ð¡¼¥¸¥ç¥ó¤ò¼èÆÀ¤¹¤ë¡£
2620function sfGetFileVersion($path) {
2621    if(file_exists($path)) {
2622        $src_fp = fopen($path, "rb");
2623        if($src_fp) {
2624            while (!feof($src_fp)) {
2625                $line = fgets($src_fp);
2626                if(ereg("@version", $line)) {
2627                    $arrLine = split(" ", $line);
2628                    $version = $arrLine[5];
2629                }
2630            }
2631            fclose($src_fp);
2632        }
2633    }
2634    return $version;
2635}
2636
2637// »ØÄꤷ¤¿URL¤ËÂФ·¤ÆPOST¤Ç¥Ç¡¼¥¿¤òÁ÷¿®¤¹¤ë
2638function sfSendPostData($url, $arrData, $arrOkCode = array()){
2639    require_once(DATA_PATH . "module/Request.php");
2640   
2641    // Á÷¿®¥¤¥ó¥¹¥¿¥ó¥¹À¸À®
2642    $req = new HTTP_Request($url);
2643    $req->setMethod(HTTP_REQUEST_METHOD_POST);
2644   
2645    // POST¥Ç¡¼¥¿Á÷¿®
2646    $req->addPostDataArray($arrData);
2647   
2648    // ¥¨¥é¡¼¤¬Ìµ¤±¤ì¤Ð¡¢±þÅú¾ðÊó¤ò¼èÆÀ¤¹¤ë
2649    if (!PEAR::isError($req->sendRequest())) {
2650       
2651        // ¥ì¥¹¥Ý¥ó¥¹¥³¡¼¥É¤¬¥¨¥é¡¼È½Äê¤Ê¤é¡¢¶õ¤òÊÖ¤¹
2652        $res_code = $req->getResponseCode();
2653       
2654        if(!in_array($res_code, $arrOkCode)){
2655            $response = "";
2656        }else{
2657            $response = $req->getResponseBody();
2658        }
2659       
2660    } else {
2661        $response = "";
2662    }
2663   
2664    // POST¥Ç¡¼¥¿¥¯¥ê¥¢
2665    $req->clearPostData(); 
2666   
2667    return $response;
2668}
2669
2670/* ¥Ç¥Ð¥Ã¥°ÍÑ ------------------------------------------------------------------------------------------------*/
2671function sfPrintR($obj) {
2672    print("<div style='font-size: 12px;color: #00FF00;'>\n");
2673    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong><br />\n");
2674    print("<pre>\n");
2675    print_r($obj);
2676    print("</pre>\n");
2677    print("<strong>**¥Ç¥Ð¥Ã¥°Ãæ**</strong></div>\n");
2678}
2679
2680?>
Note: See TracBrowser for help on using the repository browser.