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

Revision 7691, 70.9 KB checked in by kakinaka, 20 years ago (diff)

blank

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