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

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