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

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