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

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