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

Revision 7587, 70.2 KB checked in by kakinaka, 20 years ago (diff)

* empty log message *

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