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

Revision 4905, 65.5 KB checked in by kakinaka, 20 years ago (diff)

blank

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