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

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