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

Revision 6548, 68.7 KB checked in by naka, 20 years ago (diff)

* empty log message *

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