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

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