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

Revision 10139, 72.0 KB checked in by kakinaka, 20 years ago (diff)

blank

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