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

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