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

Revision 3554, 63.9 KB checked in by naka, 20 years ago (diff)

* empty log message *

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