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

Revision 6248, 68.5 KB checked in by naka, 20 years ago (diff)

* empty log message *

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