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

Revision 6316, 69.1 KB checked in by naka, 20 years ago (diff)

* empty log message *

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