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

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