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

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