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

Revision 2956, 63.2 KB checked in by kakinaka, 20 years ago (diff)

blank

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