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

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