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

Revision 3650, 63.9 KB checked in by kakinaka, 20 years ago (diff)

blank

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