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

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