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

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