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

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