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

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