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

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