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

Revision 9292, 71.5 KB checked in by naka, 20 years ago (diff)

* empty log message *

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