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

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