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

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