1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | /** |
---|
25 | * 各種ユーティリティクラス. |
---|
26 | * |
---|
27 | * 主に static 参照するユーティリティ系の関数群 |
---|
28 | * |
---|
29 | * :XXX: 内部でインスタンスを生成している関数は, Helper クラスへ移動するべき... |
---|
30 | * |
---|
31 | * @package Util |
---|
32 | * @author LOCKON CO.,LTD. |
---|
33 | * @version $Id:SC_Utils.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
34 | */ |
---|
35 | class SC_Utils { |
---|
36 | |
---|
37 | /** |
---|
38 | * サイト管理情報から値を取得する。 |
---|
39 | * データが存在する場合、必ず1以上の数値が設定されている。 |
---|
40 | * 0を返した場合は、呼び出し元で対応すること。 |
---|
41 | * |
---|
42 | * @param $control_id 管理ID |
---|
43 | * @param $dsn DataSource |
---|
44 | * @return $control_flg フラグ |
---|
45 | */ |
---|
46 | function sfGetSiteControlFlg($control_id, $dsn = "") { |
---|
47 | |
---|
48 | // データソース |
---|
49 | if($dsn == "") { |
---|
50 | if(defined('DEFAULT_DSN')) { |
---|
51 | $dsn = DEFAULT_DSN; |
---|
52 | } else { |
---|
53 | return; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | // クエリ生成 |
---|
58 | $target_column = "control_flg"; |
---|
59 | $table_name = "dtb_site_control"; |
---|
60 | $where = "control_id = ?"; |
---|
61 | $arrval = array($control_id); |
---|
62 | $control_flg = 0; |
---|
63 | |
---|
64 | // クエリ発行 |
---|
65 | $objQuery = new SC_Query($dsn, true, true); |
---|
66 | $arrSiteControl = $objQuery->select($target_column, $table_name, $where, $arrval); |
---|
67 | |
---|
68 | // データが存在すればフラグを取得する |
---|
69 | if (count($arrSiteControl) > 0) { |
---|
70 | $control_flg = $arrSiteControl[0]["control_flg"]; |
---|
71 | } |
---|
72 | |
---|
73 | return $control_flg; |
---|
74 | } |
---|
75 | |
---|
76 | // インストール初期処理 |
---|
77 | function sfInitInstall() { |
---|
78 | // インストール済みが定義されていない。 |
---|
79 | if (!defined('ECCUBE_INSTALL')) { |
---|
80 | header("Location: ./install/" . DIR_INDEX_URL); // TODO 絶対URL にする |
---|
81 | exit; |
---|
82 | } |
---|
83 | $path = HTML_PATH . "install/index.php"; |
---|
84 | if(file_exists($path)) { |
---|
85 | SC_Utils::sfErrorHeader(">> /install/index.phpは、インストール完了後にファイルを削除してください。"); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | // 装飾付きエラーメッセージの表示 |
---|
90 | function sfErrorHeader($mess, $print = false) { |
---|
91 | global $GLOBAL_ERR; |
---|
92 | $GLOBAL_ERR.="<div style='color: #F00; font-weight: bold; font-size: 12px;" |
---|
93 | . "background-color: #FEB; text-align: center; padding: 5px;'>"; |
---|
94 | $GLOBAL_ERR.= $mess; |
---|
95 | $GLOBAL_ERR.= "</div>"; |
---|
96 | if($print) { |
---|
97 | print($GLOBAL_ERR); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | /* エラーページの表示 */ |
---|
102 | function sfDispError($type) { |
---|
103 | |
---|
104 | require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_DispError_Ex.php"); |
---|
105 | |
---|
106 | $objPage = new LC_Page_Error_DispError_Ex(); |
---|
107 | register_shutdown_function(array($objPage, "destroy")); |
---|
108 | $objPage->init(); |
---|
109 | $objPage->type = $type; |
---|
110 | $objPage->process(); |
---|
111 | exit; |
---|
112 | } |
---|
113 | |
---|
114 | /* サイトエラーページの表示 */ |
---|
115 | function sfDispSiteError($type, $objSiteSess = "", $return_top = false, $err_msg = "") { |
---|
116 | global $objCampaignSess; |
---|
117 | |
---|
118 | require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_Ex.php"); |
---|
119 | |
---|
120 | $objPage = new LC_Page_Error_Ex(); |
---|
121 | register_shutdown_function(array($objPage, "destroy")); |
---|
122 | $objPage->init(); |
---|
123 | $objPage->type = $type; |
---|
124 | $objPage->objSiteSess = $objSiteSess; |
---|
125 | $objPage->return_top = $return_top; |
---|
126 | $objPage->err_msg = $err_msg; |
---|
127 | $objPage->is_mobile = (defined('MOBILE_SITE')) ? true : false; |
---|
128 | $objPage->process(); |
---|
129 | exit; |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * 例外エラーページの表示 |
---|
134 | * |
---|
135 | * @param string $debugMsg デバッグ用のメッセージ |
---|
136 | * @return void |
---|
137 | */ |
---|
138 | function sfDispException($debugMsg = null) { |
---|
139 | require_once(CLASS_EX_PATH . "page_extends/error/LC_Page_Error_SystemError_Ex.php"); |
---|
140 | |
---|
141 | $objPage = new LC_Page_Error_SystemError_Ex(); |
---|
142 | register_shutdown_function(array($objPage, "destroy")); |
---|
143 | $objPage->init(); |
---|
144 | if (!is_null($debugMsg)) { |
---|
145 | $objPage->addDebugMsg($debugMsg); |
---|
146 | } |
---|
147 | if (function_exists("debug_backtrace")) { |
---|
148 | $objPage->backtrace = debug_backtrace(); |
---|
149 | } |
---|
150 | GC_Utils_Ex::gfPrintLog($objPage->sfGetErrMsg()); |
---|
151 | $objPage->process(); |
---|
152 | |
---|
153 | exit(); |
---|
154 | } |
---|
155 | |
---|
156 | /* 認証の可否判定 */ |
---|
157 | function sfIsSuccess($objSess, $disp_error = true) { |
---|
158 | $ret = $objSess->IsSuccess(); |
---|
159 | if($ret != SUCCESS) { |
---|
160 | if($disp_error) { |
---|
161 | // エラーページの表示 |
---|
162 | SC_Utils::sfDispError($ret); |
---|
163 | } |
---|
164 | return false; |
---|
165 | } |
---|
166 | // リファラーチェック(CSRFの暫定的な対策) |
---|
167 | // 「リファラ無」 の場合はスルー |
---|
168 | // 「リファラ有」 かつ 「管理画面からの遷移でない」 場合にエラー画面を表示する |
---|
169 | if ( empty($_SERVER['HTTP_REFERER']) ) { |
---|
170 | // TODO 警告表示させる? |
---|
171 | // sfErrorHeader('>> referrerが無効になっています。'); |
---|
172 | } else { |
---|
173 | $domain = SC_Utils::sfIsHTTPS() ? SSL_URL : SITE_URL; |
---|
174 | $pattern = sprintf('|^%s.*|', $domain); |
---|
175 | $referer = $_SERVER['HTTP_REFERER']; |
---|
176 | |
---|
177 | // 管理画面から以外の遷移の場合はエラー画面を表示 |
---|
178 | if (!preg_match($pattern, $referer)) { |
---|
179 | if ($disp_error) SC_Utils::sfDispError(INVALID_MOVE_ERRORR); |
---|
180 | return false; |
---|
181 | } |
---|
182 | } |
---|
183 | return true; |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * 文字列をアスタリスクへ変換する. |
---|
188 | * |
---|
189 | * @param string $passlen 変換する文字列 |
---|
190 | * @return string アスタリスクへ変換した文字列 |
---|
191 | */ |
---|
192 | function lfPassLen($passlen){ |
---|
193 | $ret = ""; |
---|
194 | for ($i=0;$i<$passlen;true){ |
---|
195 | $ret.="*"; |
---|
196 | $i++; |
---|
197 | } |
---|
198 | return $ret; |
---|
199 | } |
---|
200 | |
---|
201 | /** |
---|
202 | * HTTPSかどうかを判定 |
---|
203 | * |
---|
204 | * @return bool |
---|
205 | */ |
---|
206 | function sfIsHTTPS () { |
---|
207 | // HTTPS時には$_SERVER['HTTPS']には空でない値が入る |
---|
208 | // $_SERVER['HTTPS'] != 'off' はIIS用 |
---|
209 | if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { |
---|
210 | return true; |
---|
211 | } else { |
---|
212 | return false; |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | /** |
---|
217 | * 正規の遷移がされているかを判定 |
---|
218 | * 前画面でuniqidを埋め込んでおく必要がある |
---|
219 | * @param obj SC_Session, SC_SiteSession |
---|
220 | * @return bool |
---|
221 | */ |
---|
222 | function sfIsValidTransition($objSess) { |
---|
223 | // 前画面からPOSTされるuniqidが正しいものかどうかをチェック |
---|
224 | $uniqid = $objSess->getUniqId(); |
---|
225 | if ( !empty($_POST['uniqid']) && ($_POST['uniqid'] === $uniqid) ) { |
---|
226 | return true; |
---|
227 | } else { |
---|
228 | return false; |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | /* 前のページで正しく登録が行われたか判定 */ |
---|
233 | function sfIsPrePage(&$objSiteSess) { |
---|
234 | $ret = $objSiteSess->isPrePage(); |
---|
235 | if($ret != true) { |
---|
236 | // エラーページの表示 |
---|
237 | SC_Utils::sfDispSiteError(PAGE_ERROR, $objSiteSess); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | function sfCheckNormalAccess(&$objSiteSess, &$objCartSess) { |
---|
242 | // ユーザユニークIDの取得 |
---|
243 | $uniqid = $objSiteSess->getUniqId(); |
---|
244 | // 購入ボタンを押した時のカート内容がコピーされていない場合のみコピーする。 |
---|
245 | $objCartSess->saveCurrentCart($uniqid); |
---|
246 | // POSTのユニークIDとセッションのユニークIDを比較(ユニークIDがPOSTされていない場合はスルー) |
---|
247 | $ret = $objSiteSess->checkUniqId(); |
---|
248 | if($ret != true) { |
---|
249 | // エラーページの表示 |
---|
250 | SC_Utils_Ex::sfDispSiteError(CANCEL_PURCHASE, $objSiteSess); |
---|
251 | } |
---|
252 | |
---|
253 | // カート内が空でないか || 購入ボタンを押してから変化がないか |
---|
254 | $quantity = $objCartSess->getTotalQuantity(); |
---|
255 | $ret = $objCartSess->checkChangeCart(); |
---|
256 | if($ret == true || !($quantity > 0)) { |
---|
257 | // カート情報表示に強制移動する |
---|
258 | // FIXME false を返して, Page クラスで遷移させるべき... |
---|
259 | if (defined("MOBILE_SITE")) { |
---|
260 | header("Location: ". MOBILE_URL_CART_TOP |
---|
261 | . "?" . session_name() . "=" . session_id()); |
---|
262 | } else { |
---|
263 | header("Location: ".URL_CART_TOP); |
---|
264 | } |
---|
265 | exit; |
---|
266 | } |
---|
267 | return $uniqid; |
---|
268 | } |
---|
269 | |
---|
270 | /* DB用日付文字列取得 */ |
---|
271 | function sfGetTimestamp($year, $month, $day, $last = false) { |
---|
272 | if($year != "" && $month != "" && $day != "") { |
---|
273 | if($last) { |
---|
274 | $time = "23:59:59"; |
---|
275 | } else { |
---|
276 | $time = "00:00:00"; |
---|
277 | } |
---|
278 | $date = $year."-".$month."-".$day." ".$time; |
---|
279 | } else { |
---|
280 | $date = ""; |
---|
281 | } |
---|
282 | return $date; |
---|
283 | } |
---|
284 | |
---|
285 | /** |
---|
286 | * INT型の数値チェック |
---|
287 | * ・FIXME: マイナス値の扱いが不明確 |
---|
288 | * ・XXX: INT_LENには収まるが、INT型の範囲を超えるケースに対応できないのでは? |
---|
289 | * |
---|
290 | * @param mixed $value |
---|
291 | * @return bool |
---|
292 | */ |
---|
293 | // |
---|
294 | function sfIsInt($value) { |
---|
295 | if (strlen($value) >= 1 && strlen($value) <= INT_LEN && is_numeric($value)) { |
---|
296 | return true; |
---|
297 | } |
---|
298 | return false; |
---|
299 | } |
---|
300 | |
---|
301 | /* |
---|
302 | * 桁が0で埋められているかを判定する |
---|
303 | * |
---|
304 | * @param string $value 検査対象 |
---|
305 | * @return boolean 0で埋められている |
---|
306 | */ |
---|
307 | function sfIsZeroFilling($value) { |
---|
308 | if (strlen($value) > 1 && $value{0} === '0') |
---|
309 | return true; |
---|
310 | return false; |
---|
311 | } |
---|
312 | |
---|
313 | function sfCSVDownload($data, $prefix = ""){ |
---|
314 | |
---|
315 | if($prefix == "") { |
---|
316 | $dir_name = SC_Utils::sfUpDirName(); |
---|
317 | $file_name = $dir_name . date("ymdHis") .".csv"; |
---|
318 | } else { |
---|
319 | $file_name = $prefix . date("ymdHis") .".csv"; |
---|
320 | } |
---|
321 | |
---|
322 | /* HTTPヘッダの出力 */ |
---|
323 | Header("Content-disposition: attachment; filename=${file_name}"); |
---|
324 | Header("Content-type: application/octet-stream; name=${file_name}"); |
---|
325 | Header("Cache-Control: "); |
---|
326 | Header("Pragma: "); |
---|
327 | |
---|
328 | if (mb_internal_encoding() == CHAR_CODE){ |
---|
329 | $data = mb_convert_encoding($data,'SJIS-Win',CHAR_CODE); |
---|
330 | } |
---|
331 | |
---|
332 | /* データを出力 */ |
---|
333 | echo $data; |
---|
334 | } |
---|
335 | |
---|
336 | /* 1階層上のディレクトリ名を取得する */ |
---|
337 | function sfUpDirName() { |
---|
338 | $path = $_SERVER['PHP_SELF']; |
---|
339 | $arrVal = split("/", $path); |
---|
340 | $cnt = count($arrVal); |
---|
341 | return $arrVal[($cnt - 2)]; |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | |
---|
346 | |
---|
347 | /** |
---|
348 | * 現在のサイトを更新(ただしポストは行わない) |
---|
349 | * |
---|
350 | * @deprecated LC_Page::reload() を使用して下さい. |
---|
351 | */ |
---|
352 | function sfReload($get = "") { |
---|
353 | if ($_SERVER["SERVER_PORT"] == "443" ){ |
---|
354 | $url = ereg_replace(URL_DIR . "$", "", SSL_URL); |
---|
355 | } else { |
---|
356 | $url = ereg_replace(URL_DIR . "$", "", SITE_URL); |
---|
357 | } |
---|
358 | |
---|
359 | if($get != "") { |
---|
360 | header("Location: ". $url . $_SERVER['PHP_SELF'] . "?" . $get); |
---|
361 | } else { |
---|
362 | header("Location: ". $url . $_SERVER['PHP_SELF']); |
---|
363 | } |
---|
364 | exit; |
---|
365 | } |
---|
366 | |
---|
367 | // チェックボックスの値をマージ |
---|
368 | function sfMergeCBValue($keyname, $max) { |
---|
369 | $conv = ""; |
---|
370 | $cnt = 1; |
---|
371 | for($cnt = 1; $cnt <= $max; $cnt++) { |
---|
372 | if ($_POST[$keyname . $cnt] == "1") { |
---|
373 | $conv.= "1"; |
---|
374 | } else { |
---|
375 | $conv.= "0"; |
---|
376 | } |
---|
377 | } |
---|
378 | return $conv; |
---|
379 | } |
---|
380 | |
---|
381 | // html_checkboxesの値をマージして2進数形式に変更する。 |
---|
382 | function sfMergeCheckBoxes($array, $max) { |
---|
383 | $ret = ""; |
---|
384 | if(is_array($array)) { |
---|
385 | foreach($array as $val) { |
---|
386 | $arrTmp[$val] = "1"; |
---|
387 | } |
---|
388 | } |
---|
389 | for($i = 1; $i <= $max; $i++) { |
---|
390 | if(isset($arrTmp[$i]) && $arrTmp[$i] == "1") { |
---|
391 | $ret.= "1"; |
---|
392 | } else { |
---|
393 | $ret.= "0"; |
---|
394 | } |
---|
395 | } |
---|
396 | return $ret; |
---|
397 | } |
---|
398 | |
---|
399 | |
---|
400 | // html_checkboxesの値をマージして「-」でつなげる。 |
---|
401 | function sfMergeParamCheckBoxes($array) { |
---|
402 | $ret = ''; |
---|
403 | if(is_array($array)) { |
---|
404 | foreach($array as $val) { |
---|
405 | if($ret != "") { |
---|
406 | $ret.= "-$val"; |
---|
407 | } else { |
---|
408 | $ret = $val; |
---|
409 | } |
---|
410 | } |
---|
411 | } else { |
---|
412 | $ret = $array; |
---|
413 | } |
---|
414 | return $ret; |
---|
415 | } |
---|
416 | |
---|
417 | // html_checkboxesの値をマージしてSQL検索用に変更する。 |
---|
418 | function sfSearchCheckBoxes($array) { |
---|
419 | $max = 0; |
---|
420 | $ret = ""; |
---|
421 | foreach($array as $val) { |
---|
422 | $arrTmp[$val] = "1"; |
---|
423 | if($val > $max) { |
---|
424 | $max = $val; |
---|
425 | } |
---|
426 | } |
---|
427 | for($i = 1; $i <= $max; $i++) { |
---|
428 | if($arrTmp[$i] == "1") { |
---|
429 | $ret.= "1"; |
---|
430 | } else { |
---|
431 | $ret.= "_"; |
---|
432 | } |
---|
433 | } |
---|
434 | |
---|
435 | if($ret != "") { |
---|
436 | $ret.= "%"; |
---|
437 | } |
---|
438 | return $ret; |
---|
439 | } |
---|
440 | |
---|
441 | // 2進数形式の値をhtml_checkboxes対応の値に切り替える |
---|
442 | function sfSplitCheckBoxes($val) { |
---|
443 | $arrRet = array(); |
---|
444 | $len = strlen($val); |
---|
445 | for($i = 0; $i < $len; $i++) { |
---|
446 | if(substr($val, $i, 1) == "1") { |
---|
447 | $arrRet[] = ($i + 1); |
---|
448 | } |
---|
449 | } |
---|
450 | return $arrRet; |
---|
451 | } |
---|
452 | |
---|
453 | // チェックボックスの値をマージ |
---|
454 | function sfMergeCBSearchValue($keyname, $max) { |
---|
455 | $conv = ""; |
---|
456 | $cnt = 1; |
---|
457 | for($cnt = 1; $cnt <= $max; $cnt++) { |
---|
458 | if ($_POST[$keyname . $cnt] == "1") { |
---|
459 | $conv.= "1"; |
---|
460 | } else { |
---|
461 | $conv.= "_"; |
---|
462 | } |
---|
463 | } |
---|
464 | return $conv; |
---|
465 | } |
---|
466 | |
---|
467 | // チェックボックスの値を分解 |
---|
468 | function sfSplitCBValue($val, $keyname = "") { |
---|
469 | $arr = array(); |
---|
470 | $len = strlen($val); |
---|
471 | $no = 1; |
---|
472 | for ($cnt = 0; $cnt < $len; $cnt++) { |
---|
473 | if($keyname != "") { |
---|
474 | $arr[$keyname . $no] = substr($val, $cnt, 1); |
---|
475 | } else { |
---|
476 | $arr[] = substr($val, $cnt, 1); |
---|
477 | } |
---|
478 | $no++; |
---|
479 | } |
---|
480 | return $arr; |
---|
481 | } |
---|
482 | |
---|
483 | // キーと値をセットした配列を取得 |
---|
484 | function sfArrKeyValue($arrList, $keyname, $valname, $len_max = "", $keysize = "") { |
---|
485 | $arrRet = array(); |
---|
486 | $max = count($arrList); |
---|
487 | |
---|
488 | if($len_max != "" && $max > $len_max) { |
---|
489 | $max = $len_max; |
---|
490 | } |
---|
491 | |
---|
492 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
493 | if($keysize != "") { |
---|
494 | $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize); |
---|
495 | } else { |
---|
496 | $key = $arrList[$cnt][$keyname]; |
---|
497 | } |
---|
498 | $val = $arrList[$cnt][$valname]; |
---|
499 | |
---|
500 | if(!isset($arrRet[$key])) { |
---|
501 | $arrRet[$key] = $val; |
---|
502 | } |
---|
503 | |
---|
504 | } |
---|
505 | return $arrRet; |
---|
506 | } |
---|
507 | |
---|
508 | // キーと値をセットした配列を取得(値が複数の場合) |
---|
509 | function sfArrKeyValues($arrList, $keyname, $valname, $len_max = "", $keysize = "", $connect = "") { |
---|
510 | |
---|
511 | $max = count($arrList); |
---|
512 | |
---|
513 | if($len_max != "" && $max > $len_max) { |
---|
514 | $max = $len_max; |
---|
515 | } |
---|
516 | |
---|
517 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
518 | if($keysize != "") { |
---|
519 | $key = SC_Utils::sfCutString($arrList[$cnt][$keyname], $keysize); |
---|
520 | } else { |
---|
521 | $key = $arrList[$cnt][$keyname]; |
---|
522 | } |
---|
523 | $val = $arrList[$cnt][$valname]; |
---|
524 | |
---|
525 | if($connect != "") { |
---|
526 | $arrRet[$key].= "$val".$connect; |
---|
527 | } else { |
---|
528 | $arrRet[$key][] = $val; |
---|
529 | } |
---|
530 | } |
---|
531 | return $arrRet; |
---|
532 | } |
---|
533 | |
---|
534 | // 配列の値をカンマ区切りで返す。 |
---|
535 | function sfGetCommaList($array, $space=true, $arrPop = array()) { |
---|
536 | if (count($array) > 0) { |
---|
537 | $line = ""; |
---|
538 | foreach($array as $val) { |
---|
539 | if (!in_array($val, $arrPop)) { |
---|
540 | if ($space) { |
---|
541 | $line .= $val . ", "; |
---|
542 | } else { |
---|
543 | $line .= $val . ","; |
---|
544 | } |
---|
545 | } |
---|
546 | } |
---|
547 | if ($space) { |
---|
548 | $line = ereg_replace(", $", "", $line); |
---|
549 | } else { |
---|
550 | $line = ereg_replace(",$", "", $line); |
---|
551 | } |
---|
552 | return $line; |
---|
553 | } else { |
---|
554 | return false; |
---|
555 | } |
---|
556 | |
---|
557 | } |
---|
558 | |
---|
559 | /* 配列の要素をCSVフォーマットで出力する。*/ |
---|
560 | function sfGetCSVList($array) { |
---|
561 | $line = ""; |
---|
562 | if (count($array) > 0) { |
---|
563 | foreach($array as $key => $val) { |
---|
564 | $val = mb_convert_encoding($val, CHAR_CODE, CHAR_CODE); |
---|
565 | $line .= "\"".$val."\","; |
---|
566 | } |
---|
567 | $line = ereg_replace(",$", "\r\n", $line); |
---|
568 | }else{ |
---|
569 | return false; |
---|
570 | } |
---|
571 | return $line; |
---|
572 | } |
---|
573 | |
---|
574 | /* 配列の要素をPDFフォーマットで出力する。*/ |
---|
575 | function sfGetPDFList($array) { |
---|
576 | foreach($array as $key => $val) { |
---|
577 | $line .= "\t".$val; |
---|
578 | } |
---|
579 | $line.="\n"; |
---|
580 | return $line; |
---|
581 | } |
---|
582 | |
---|
583 | |
---|
584 | |
---|
585 | /*-----------------------------------------------------------------*/ |
---|
586 | /* check_set_term |
---|
587 | /* 年月日に別れた2つの期間の妥当性をチェックし、整合性と期間を返す |
---|
588 | /* 引数 (開始年,開始月,開始日,終了年,終了月,終了日) |
---|
589 | /* 戻値 array(1,2,3) |
---|
590 | /* 1.開始年月日 (YYYY/MM/DD 000000) |
---|
591 | /* 2.終了年月日 (YYYY/MM/DD 235959) |
---|
592 | /* 3.エラー ( 0 = OK, 1 = NG ) |
---|
593 | /*-----------------------------------------------------------------*/ |
---|
594 | function sfCheckSetTerm ( $start_year, $start_month, $start_day, $end_year, $end_month, $end_day ) { |
---|
595 | |
---|
596 | // 期間指定 |
---|
597 | $error = 0; |
---|
598 | if ( $start_month || $start_day || $start_year){ |
---|
599 | if ( ! checkdate($start_month, $start_day , $start_year) ) $error = 1; |
---|
600 | } else { |
---|
601 | $error = 1; |
---|
602 | } |
---|
603 | if ( $end_month || $end_day || $end_year){ |
---|
604 | if ( ! checkdate($end_month ,$end_day ,$end_year) ) $error = 2; |
---|
605 | } |
---|
606 | if ( ! $error ){ |
---|
607 | $date1 = $start_year ."/".sprintf("%02d",$start_month) ."/".sprintf("%02d",$start_day) ." 000000"; |
---|
608 | $date2 = $end_year ."/".sprintf("%02d",$end_month) ."/".sprintf("%02d",$end_day) ." 235959"; |
---|
609 | if ($date1 > $date2) $error = 3; |
---|
610 | } else { |
---|
611 | $error = 1; |
---|
612 | } |
---|
613 | return array($date1, $date2, $error); |
---|
614 | } |
---|
615 | |
---|
616 | // エラー箇所の背景色を変更するためのfunction SC_Viewで読み込む |
---|
617 | function sfSetErrorStyle(){ |
---|
618 | return 'style="background-color:'.ERR_COLOR.'"'; |
---|
619 | } |
---|
620 | |
---|
621 | /* DBに渡す数値のチェック |
---|
622 | * 10桁以上はオーバーフローエラーを起こすので。 |
---|
623 | */ |
---|
624 | function sfCheckNumLength( $value ){ |
---|
625 | if ( ! is_numeric($value) ){ |
---|
626 | return false; |
---|
627 | } |
---|
628 | |
---|
629 | if ( strlen($value) > 9 ) { |
---|
630 | return false; |
---|
631 | } |
---|
632 | |
---|
633 | return true; |
---|
634 | } |
---|
635 | |
---|
636 | // 一致した値のキー名を取得 |
---|
637 | function sfSearchKey($array, $word, $default) { |
---|
638 | foreach($array as $key => $val) { |
---|
639 | if($val == $word) { |
---|
640 | return $key; |
---|
641 | } |
---|
642 | } |
---|
643 | return $default; |
---|
644 | } |
---|
645 | |
---|
646 | function sfGetErrorColor($val) { |
---|
647 | if($val != "") { |
---|
648 | return "background-color:" . ERR_COLOR; |
---|
649 | } |
---|
650 | return ""; |
---|
651 | } |
---|
652 | |
---|
653 | function sfGetEnabled($val) { |
---|
654 | if( ! $val ) { |
---|
655 | return " disabled=\"disabled\""; |
---|
656 | } |
---|
657 | return ""; |
---|
658 | } |
---|
659 | |
---|
660 | function sfGetChecked($param, $value) { |
---|
661 | if($param == $value) { |
---|
662 | return "checked=\"checked\""; |
---|
663 | } |
---|
664 | return ""; |
---|
665 | } |
---|
666 | |
---|
667 | function sfTrim($str) { |
---|
668 | $ret = mb_ereg_replace("^[ \n\r]*", "", $str); |
---|
669 | $ret = mb_ereg_replace("[ \n\r]*$", "", $ret); |
---|
670 | return $ret; |
---|
671 | } |
---|
672 | |
---|
673 | /** |
---|
674 | * 税金額を返す |
---|
675 | * |
---|
676 | * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfTax() を使用する |
---|
677 | * |
---|
678 | * @param integer $price 計算対象の金額 |
---|
679 | * @param integer $tax 税率(%単位) |
---|
680 | * XXX integer のみか不明 |
---|
681 | * @param integer $tax_rule 端数処理 |
---|
682 | * @return integer 税金額 |
---|
683 | */ |
---|
684 | function sfTax($price, $tax, $tax_rule) { |
---|
685 | $real_tax = $tax / 100; |
---|
686 | $ret = $price * $real_tax; |
---|
687 | switch($tax_rule) { |
---|
688 | // 四捨五入 |
---|
689 | case 1: |
---|
690 | $ret = round($ret); |
---|
691 | break; |
---|
692 | // 切り捨て |
---|
693 | case 2: |
---|
694 | $ret = floor($ret); |
---|
695 | break; |
---|
696 | // 切り上げ |
---|
697 | case 3: |
---|
698 | $ret = ceil($ret); |
---|
699 | break; |
---|
700 | // デフォルト:切り上げ |
---|
701 | default: |
---|
702 | $ret = ceil($ret); |
---|
703 | break; |
---|
704 | } |
---|
705 | return $ret; |
---|
706 | } |
---|
707 | |
---|
708 | /** |
---|
709 | * 税金付与した金額を返す |
---|
710 | * |
---|
711 | * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfTax() を使用する |
---|
712 | * |
---|
713 | * @param integer $price 計算対象の金額 |
---|
714 | * @param integer $tax 税率(%単位) |
---|
715 | * XXX integer のみか不明 |
---|
716 | * @param integer $tax_rule 端数処理 |
---|
717 | * @return integer 税金付与した金額 |
---|
718 | */ |
---|
719 | function sfPreTax($price, $tax, $tax_rule) { |
---|
720 | return $price + SC_Utils_Ex::sfTax($price, $tax, $tax_rule); |
---|
721 | } |
---|
722 | |
---|
723 | // 桁数を指定して四捨五入 |
---|
724 | function sfRound($value, $pow = 0){ |
---|
725 | $adjust = pow(10 ,$pow-1); |
---|
726 | |
---|
727 | // 整数且つ0出なければ桁数指定を行う |
---|
728 | if(SC_Utils::sfIsInt($adjust) and $pow > 1){ |
---|
729 | $ret = (round($value * $adjust)/$adjust); |
---|
730 | } |
---|
731 | |
---|
732 | $ret = round($ret); |
---|
733 | |
---|
734 | return $ret; |
---|
735 | } |
---|
736 | |
---|
737 | /* ポイント付与 */ |
---|
738 | function sfPrePoint($price, $point_rate, $rule = POINT_RULE, $product_id = "") { |
---|
739 | if(SC_Utils::sfIsInt($product_id)) { |
---|
740 | $objQuery = new SC_Query(); |
---|
741 | $where = "now() >= cast(start_date as date) AND "; |
---|
742 | $where .= "now() < cast(end_date as date) AND "; |
---|
743 | |
---|
744 | $where .= "del_flg = 0 AND campaign_id IN (SELECT campaign_id FROM dtb_campaign_detail where product_id = ? )"; |
---|
745 | //登録(更新)日付順 |
---|
746 | $objQuery->setorder('update_date DESC'); |
---|
747 | //キャンペーンポイントの取得 |
---|
748 | $arrRet = $objQuery->select("campaign_name, campaign_point_rate", "dtb_campaign", $where, array($product_id)); |
---|
749 | } |
---|
750 | //複数のキャンペーンに登録されている商品は、最新のキャンペーンからポイントを取得 |
---|
751 | if(isset($arrRet[0]['campaign_point_rate']) |
---|
752 | && $arrRet[0]['campaign_point_rate'] != "") { |
---|
753 | |
---|
754 | $campaign_point_rate = $arrRet[0]['campaign_point_rate']; |
---|
755 | $real_point = $campaign_point_rate / 100; |
---|
756 | } else { |
---|
757 | $real_point = $point_rate / 100; |
---|
758 | } |
---|
759 | $ret = $price * $real_point; |
---|
760 | switch($rule) { |
---|
761 | // 四捨五入 |
---|
762 | case 1: |
---|
763 | $ret = round($ret); |
---|
764 | break; |
---|
765 | // 切り捨て |
---|
766 | case 2: |
---|
767 | $ret = floor($ret); |
---|
768 | break; |
---|
769 | // 切り上げ |
---|
770 | case 3: |
---|
771 | $ret = ceil($ret); |
---|
772 | break; |
---|
773 | // デフォルト:切り上げ |
---|
774 | default: |
---|
775 | $ret = ceil($ret); |
---|
776 | break; |
---|
777 | } |
---|
778 | //キャンペーン商品の場合 |
---|
779 | if(isset($campaign_point_rate) && $campaign_point_rate != "") { |
---|
780 | $ret = "(".$arrRet[0]['campaign_name']."ポイント率".$campaign_point_rate."%)".$ret; |
---|
781 | } |
---|
782 | return $ret; |
---|
783 | } |
---|
784 | |
---|
785 | /* 規格分類の件数取得 */ |
---|
786 | function sfGetClassCatCount() { |
---|
787 | $sql = "select count(dtb_class.class_id) as count, dtb_class.class_id "; |
---|
788 | $sql.= "from dtb_class inner join dtb_classcategory on dtb_class.class_id = dtb_classcategory.class_id "; |
---|
789 | $sql.= "where dtb_class.del_flg = 0 AND dtb_classcategory.del_flg = 0 "; |
---|
790 | $sql.= "group by dtb_class.class_id, dtb_class.name"; |
---|
791 | $objQuery = new SC_Query(); |
---|
792 | $arrList = $objQuery->getall($sql); |
---|
793 | // キーと値をセットした配列を取得 |
---|
794 | $arrRet = SC_Utils::sfArrKeyValue($arrList, 'class_id', 'count'); |
---|
795 | |
---|
796 | return $arrRet; |
---|
797 | } |
---|
798 | |
---|
799 | /* 規格の登録 */ |
---|
800 | function sfInsertProductClass($objQuery, $arrList, $product_id , $product_class_id = "") { |
---|
801 | // すでに規格登録があるかどうかをチェックする。 |
---|
802 | $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; |
---|
803 | $count = $objQuery->count("dtb_products_class", $where, array($product_id)); |
---|
804 | |
---|
805 | // すでに規格登録がない場合 |
---|
806 | if($count == 0) { |
---|
807 | // 既存規格の削除 |
---|
808 | $where = "product_id = ?"; |
---|
809 | $objQuery->delete("dtb_products_class", $where, array($product_id)); |
---|
810 | |
---|
811 | // 配列の添字を定義 |
---|
812 | $checkArray = array("product_code", "stock", "stock_unlimited", "price01", "price02"); |
---|
813 | $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); |
---|
814 | |
---|
815 | $sqlval['product_id'] = $product_id; |
---|
816 | if(strlen($product_class_id ) > 0 ){ |
---|
817 | $sqlval['product_class_id'] = $product_class_id; |
---|
818 | } |
---|
819 | $sqlval['classcategory_id1'] = '0'; |
---|
820 | $sqlval['classcategory_id2'] = '0'; |
---|
821 | $sqlval['product_code'] = $arrList["product_code"]; |
---|
822 | $sqlval['stock'] = $arrList["stock"]; |
---|
823 | $sqlval['stock_unlimited'] = ($arrList["stock_unlimited"]) ? '1' : '0'; |
---|
824 | $sqlval['price01'] = $arrList['price01']; |
---|
825 | $sqlval['price02'] = $arrList['price02']; |
---|
826 | $sqlval['creator_id'] = $_SESSION['member_id']; |
---|
827 | $sqlval['create_date'] = "now()"; |
---|
828 | |
---|
829 | if($_SESSION['member_id'] == "") { |
---|
830 | $sqlval['creator_id'] = '0'; |
---|
831 | } |
---|
832 | |
---|
833 | // INSERTの実行 |
---|
834 | $objQuery->insert("dtb_products_class", $sqlval); |
---|
835 | } |
---|
836 | } |
---|
837 | |
---|
838 | function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) { |
---|
839 | $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; |
---|
840 | $objQuery = new SC_Query(); |
---|
841 | $ret = $objQuery->get("dtb_products_class", "product_class_id", $where, Array($product_id, $classcategory_id1, $classcategory_id2)); |
---|
842 | return $ret; |
---|
843 | } |
---|
844 | |
---|
845 | /* 文末の「/」をなくす */ |
---|
846 | function sfTrimURL($url) { |
---|
847 | $ret = ereg_replace("[/]+$", "", $url); |
---|
848 | return $ret; |
---|
849 | } |
---|
850 | |
---|
851 | /* DBから取り出した日付の文字列を調整する。*/ |
---|
852 | function sfDispDBDate($dbdate, $time = true) { |
---|
853 | list($y, $m, $d, $H, $M) = split("[- :]", $dbdate); |
---|
854 | |
---|
855 | if(strlen($y) > 0 && strlen($m) > 0 && strlen($d) > 0) { |
---|
856 | if ($time) { |
---|
857 | $str = sprintf("%04d/%02d/%02d %02d:%02d", $y, $m, $d, $H, $M); |
---|
858 | } else { |
---|
859 | $str = sprintf("%04d/%02d/%02d", $y, $m, $d, $H, $M); |
---|
860 | } |
---|
861 | } else { |
---|
862 | $str = ""; |
---|
863 | } |
---|
864 | return $str; |
---|
865 | } |
---|
866 | |
---|
867 | /* 配列をキー名ごとの配列に変更する */ |
---|
868 | function sfSwapArray($array, $isColumnName = true) { |
---|
869 | $arrRet = array(); |
---|
870 | $max = count($array); |
---|
871 | for($i = 0; $i < $max; $i++) { |
---|
872 | $j = 0; |
---|
873 | foreach($array[$i] as $key => $val) { |
---|
874 | if ($isColumnName) { |
---|
875 | $arrRet[$key][] = $val; |
---|
876 | } else { |
---|
877 | $arrRet[$j][] = $val; |
---|
878 | } |
---|
879 | $j++; |
---|
880 | } |
---|
881 | } |
---|
882 | return $arrRet; |
---|
883 | } |
---|
884 | |
---|
885 | /** |
---|
886 | * 連想配列から新たな配列を生成して返す. |
---|
887 | * |
---|
888 | * $requires が指定された場合, $requires に含まれるキーの値のみを返す. |
---|
889 | * |
---|
890 | * @param array 連想配列 |
---|
891 | * @param array 必須キーの配列 |
---|
892 | * @return array 連想配列の値のみの配列 |
---|
893 | */ |
---|
894 | function getHash2Array($hash, $requires = array()) { |
---|
895 | $array = array(); |
---|
896 | $i = 0; |
---|
897 | foreach ($hash as $key => $val) { |
---|
898 | if (!empty($requires)) { |
---|
899 | if (in_array($key, $requires)) { |
---|
900 | $array[$i] = $val; |
---|
901 | $i++; |
---|
902 | } |
---|
903 | } else { |
---|
904 | $array[$i] = $val; |
---|
905 | $i++; |
---|
906 | } |
---|
907 | } |
---|
908 | return $array; |
---|
909 | } |
---|
910 | |
---|
911 | /* かけ算をする(Smarty用) */ |
---|
912 | function sfMultiply($num1, $num2) { |
---|
913 | return ($num1 * $num2); |
---|
914 | } |
---|
915 | |
---|
916 | // カードの処理結果を返す |
---|
917 | function sfGetAuthonlyResult($dir, $file_name, $name01, $name02, $card_no, $card_exp, $amount, $order_id, $jpo_info = "10"){ |
---|
918 | |
---|
919 | $path = $dir .$file_name; // cgiファイルのフルパス生成 |
---|
920 | $now_dir = getcwd(); // requireがうまくいかないので、cgi実行ディレクトリに移動する |
---|
921 | chdir($dir); |
---|
922 | |
---|
923 | // パイプ渡しでコマンドラインからcgi起動 |
---|
924 | $cmd = "$path card_no=$card_no name01=$name01 name02=$name02 card_exp=$card_exp amount=$amount order_id=$order_id jpo_info=$jpo_info"; |
---|
925 | |
---|
926 | $tmpResult = popen($cmd, "r"); |
---|
927 | |
---|
928 | // 結果取得 |
---|
929 | while( ! FEOF ( $tmpResult ) ) { |
---|
930 | $result .= FGETS($tmpResult); |
---|
931 | } |
---|
932 | pclose($tmpResult); // パイプを閉じる |
---|
933 | chdir($now_dir); // 元にいたディレクトリに帰る |
---|
934 | |
---|
935 | // 結果を連想配列へ格納 |
---|
936 | $result = ereg_replace("&$", "", $result); |
---|
937 | foreach (explode("&",$result) as $data) { |
---|
938 | list($key, $val) = explode("=", $data, 2); |
---|
939 | $return[$key] = $val; |
---|
940 | } |
---|
941 | |
---|
942 | return $return; |
---|
943 | } |
---|
944 | |
---|
945 | /** |
---|
946 | * 加算ポイントの計算 |
---|
947 | * |
---|
948 | * ・店舗基本情報に基づいた計算は SC_Helper_DB::sfGetAddPoint() を使用する |
---|
949 | * |
---|
950 | * @param integer $totalpoint |
---|
951 | * @param integer $use_point |
---|
952 | * @param integer $point_rate |
---|
953 | * @return integer 加算ポイント |
---|
954 | */ |
---|
955 | function sfGetAddPoint($totalpoint, $use_point, $point_rate) { |
---|
956 | // 購入商品の合計ポイントから利用したポイントのポイント換算価値を引く方式 |
---|
957 | $add_point = $totalpoint - intval($use_point * ($point_rate / 100)); |
---|
958 | |
---|
959 | if($add_point < 0) { |
---|
960 | $add_point = '0'; |
---|
961 | } |
---|
962 | return $add_point; |
---|
963 | } |
---|
964 | |
---|
965 | /* 一意かつ予測されにくいID */ |
---|
966 | function sfGetUniqRandomId($head = "") { |
---|
967 | // 予測されないようにランダム文字列を付与する。 |
---|
968 | $random = GC_Utils_Ex::gfMakePassword(8); |
---|
969 | // 同一ホスト内で一意なIDを生成 |
---|
970 | $id = uniqid($head); |
---|
971 | return ($id . $random); |
---|
972 | } |
---|
973 | |
---|
974 | // 特殊制御文字の手動エスケープ |
---|
975 | function sfManualEscape($data) { |
---|
976 | // 配列でない場合 |
---|
977 | if(!is_array($data)) { |
---|
978 | if (DB_TYPE == "pgsql") { |
---|
979 | $ret = pg_escape_string($data); |
---|
980 | }else if(DB_TYPE == "mysql"){ |
---|
981 | $ret = mysql_real_escape_string($data); |
---|
982 | } |
---|
983 | $ret = ereg_replace("%", "\\%", $ret); |
---|
984 | $ret = ereg_replace("_", "\\_", $ret); |
---|
985 | return $ret; |
---|
986 | } |
---|
987 | |
---|
988 | // 配列の場合 |
---|
989 | foreach($data as $val) { |
---|
990 | if (DB_TYPE == "pgsql") { |
---|
991 | $ret = pg_escape_string($val); |
---|
992 | }else if(DB_TYPE == "mysql"){ |
---|
993 | $ret = mysql_real_escape_string($val); |
---|
994 | } |
---|
995 | |
---|
996 | $ret = ereg_replace("%", "\\%", $ret); |
---|
997 | $ret = ereg_replace("_", "\\_", $ret); |
---|
998 | $arrRet[] = $ret; |
---|
999 | } |
---|
1000 | |
---|
1001 | return $arrRet; |
---|
1002 | } |
---|
1003 | |
---|
1004 | /** |
---|
1005 | * ドメイン間で有効なセッションのスタート |
---|
1006 | * 共有SSL対応のための修正により、この関数は廃止します。 |
---|
1007 | * セッションはrequire.phpを読み込んだ際に開始されます。 |
---|
1008 | */ |
---|
1009 | function sfDomainSessionStart() { |
---|
1010 | /** |
---|
1011 | * 2.1.1ベータからはSC_SessionFactory_UseCookie::initSession()で処理するため、 |
---|
1012 | * ここでは何も処理しない |
---|
1013 | */ |
---|
1014 | if (defined('SESSION_KEEP_METHOD')) { |
---|
1015 | return; |
---|
1016 | } |
---|
1017 | |
---|
1018 | if (session_id() === "") { |
---|
1019 | |
---|
1020 | session_set_cookie_params(0, "/", DOMAIN_NAME); |
---|
1021 | |
---|
1022 | if (!ini_get("session.auto_start")) { |
---|
1023 | // セッション開始 |
---|
1024 | session_start(); |
---|
1025 | } |
---|
1026 | } |
---|
1027 | } |
---|
1028 | |
---|
1029 | /* 文字列に強制的に改行を入れる */ |
---|
1030 | function sfPutBR($str, $size) { |
---|
1031 | $i = 0; |
---|
1032 | $cnt = 0; |
---|
1033 | $line = array(); |
---|
1034 | $ret = ""; |
---|
1035 | |
---|
1036 | while($str[$i] != "") { |
---|
1037 | $line[$cnt].=$str[$i]; |
---|
1038 | $i++; |
---|
1039 | if(strlen($line[$cnt]) > $size) { |
---|
1040 | $line[$cnt].="<br />"; |
---|
1041 | $cnt++; |
---|
1042 | } |
---|
1043 | } |
---|
1044 | |
---|
1045 | foreach($line as $val) { |
---|
1046 | $ret.=$val; |
---|
1047 | } |
---|
1048 | return $ret; |
---|
1049 | } |
---|
1050 | |
---|
1051 | // 二回以上繰り返されているスラッシュ[/]を一つに変換する。 |
---|
1052 | function sfRmDupSlash($istr){ |
---|
1053 | if(ereg("^http://", $istr)) { |
---|
1054 | $str = substr($istr, 7); |
---|
1055 | $head = "http://"; |
---|
1056 | } else if(ereg("^https://", $istr)) { |
---|
1057 | $str = substr($istr, 8); |
---|
1058 | $head = "https://"; |
---|
1059 | } else { |
---|
1060 | $str = $istr; |
---|
1061 | } |
---|
1062 | $str = ereg_replace("[/]+", "/", $str); |
---|
1063 | $ret = $head . $str; |
---|
1064 | return $ret; |
---|
1065 | } |
---|
1066 | |
---|
1067 | /** |
---|
1068 | * テキストファイルの文字エンコーディングを変換する. |
---|
1069 | * |
---|
1070 | * $filepath に存在するテキストファイルの文字エンコーディングを変換する. |
---|
1071 | * 変換前の文字エンコーディングは, mb_detect_order で設定した順序で自動検出する. |
---|
1072 | * 変換後は, 変換前のファイル名に「enc_」というプレフィクスを付与し, |
---|
1073 | * $out_dir で指定したディレクトリへ出力する |
---|
1074 | * |
---|
1075 | * TODO $filepath のファイルがバイナリだった場合の扱い |
---|
1076 | * TODO fwrite などでのエラーハンドリング |
---|
1077 | * |
---|
1078 | * @access public |
---|
1079 | * @param string $filepath 変換するテキストファイルのパス |
---|
1080 | * @param string $enc_type 変換後のファイルエンコーディングの種類を表す文字列 |
---|
1081 | * @param string $out_dir 変換後のファイルを出力するディレクトリを表す文字列 |
---|
1082 | * @return string 変換後のテキストファイルのパス |
---|
1083 | */ |
---|
1084 | function sfEncodeFile($filepath, $enc_type, $out_dir) { |
---|
1085 | $ifp = fopen($filepath, "r"); |
---|
1086 | |
---|
1087 | // 正常にファイルオープンした場合 |
---|
1088 | if ($ifp !== false) { |
---|
1089 | |
---|
1090 | $basename = basename($filepath); |
---|
1091 | $outpath = $out_dir . "enc_" . $basename; |
---|
1092 | |
---|
1093 | $ofp = fopen($outpath, "w+"); |
---|
1094 | |
---|
1095 | while(!feof($ifp)) { |
---|
1096 | $line = fgets($ifp); |
---|
1097 | $line = mb_convert_encoding($line, $enc_type, "auto"); |
---|
1098 | fwrite($ofp, $line); |
---|
1099 | } |
---|
1100 | |
---|
1101 | fclose($ofp); |
---|
1102 | fclose($ifp); |
---|
1103 | } |
---|
1104 | // ファイルが開けなかった場合はエラーページを表示 |
---|
1105 | else { |
---|
1106 | SC_Utils::sfDispError(''); |
---|
1107 | exit; |
---|
1108 | } |
---|
1109 | return $outpath; |
---|
1110 | } |
---|
1111 | |
---|
1112 | function sfCutString($str, $len, $byte = true, $commadisp = true) { |
---|
1113 | if($byte) { |
---|
1114 | if(strlen($str) > ($len + 2)) { |
---|
1115 | $ret =substr($str, 0, $len); |
---|
1116 | $cut = substr($str, $len); |
---|
1117 | } else { |
---|
1118 | $ret = $str; |
---|
1119 | $commadisp = false; |
---|
1120 | } |
---|
1121 | } else { |
---|
1122 | if(mb_strlen($str) > ($len + 1)) { |
---|
1123 | $ret = mb_substr($str, 0, $len); |
---|
1124 | $cut = mb_substr($str, $len); |
---|
1125 | } else { |
---|
1126 | $ret = $str; |
---|
1127 | $commadisp = false; |
---|
1128 | } |
---|
1129 | } |
---|
1130 | |
---|
1131 | // 絵文字タグの途中で分断されないようにする。 |
---|
1132 | if (isset($cut)) { |
---|
1133 | // 分割位置より前の最後の [ 以降を取得する。 |
---|
1134 | $head = strrchr($ret, '['); |
---|
1135 | |
---|
1136 | // 分割位置より後の最初の ] 以前を取得する。 |
---|
1137 | $tail_pos = strpos($cut, ']'); |
---|
1138 | if ($tail_pos !== false) { |
---|
1139 | $tail = substr($cut, 0, $tail_pos + 1); |
---|
1140 | } |
---|
1141 | |
---|
1142 | // 分割位置より前に [、後に ] が見つかった場合は、[ から ] までを |
---|
1143 | // 接続して絵文字タグ1個分になるかどうかをチェックする。 |
---|
1144 | if ($head !== false && $tail_pos !== false) { |
---|
1145 | $subject = $head . $tail; |
---|
1146 | if (preg_match('/^\[emoji:e?\d+\]$/', $subject)) { |
---|
1147 | // 絵文字タグが見つかったので削除する。 |
---|
1148 | $ret = substr($ret, 0, -strlen($head)); |
---|
1149 | } |
---|
1150 | } |
---|
1151 | } |
---|
1152 | |
---|
1153 | if($commadisp){ |
---|
1154 | $ret = $ret . "..."; |
---|
1155 | } |
---|
1156 | return $ret; |
---|
1157 | } |
---|
1158 | |
---|
1159 | // 年、月、締め日から、先月の締め日+1、今月の締め日を求める。 |
---|
1160 | function sfTermMonth($year, $month, $close_day) { |
---|
1161 | $end_year = $year; |
---|
1162 | $end_month = $month; |
---|
1163 | |
---|
1164 | // 開始月が終了月と同じか否か |
---|
1165 | $same_month = false; |
---|
1166 | |
---|
1167 | // 該当月の末日を求める。 |
---|
1168 | $end_last_day = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); |
---|
1169 | |
---|
1170 | // 月の末日が締め日より少ない場合 |
---|
1171 | if($end_last_day < $close_day) { |
---|
1172 | // 締め日を月末日に合わせる |
---|
1173 | $end_day = $end_last_day; |
---|
1174 | } else { |
---|
1175 | $end_day = $close_day; |
---|
1176 | } |
---|
1177 | |
---|
1178 | // 前月の取得 |
---|
1179 | $tmp_year = date("Y", mktime(0, 0, 0, $month, 0, $year)); |
---|
1180 | $tmp_month = date("m", mktime(0, 0, 0, $month, 0, $year)); |
---|
1181 | // 前月の末日を求める。 |
---|
1182 | $start_last_day = date("d", mktime(0, 0, 0, $month, 0, $year)); |
---|
1183 | |
---|
1184 | // 前月の末日が締め日より少ない場合 |
---|
1185 | if ($start_last_day < $close_day) { |
---|
1186 | // 月末日に合わせる |
---|
1187 | $tmp_day = $start_last_day; |
---|
1188 | } else { |
---|
1189 | $tmp_day = $close_day; |
---|
1190 | } |
---|
1191 | |
---|
1192 | // 先月の末日の翌日を取得する |
---|
1193 | $start_year = date("Y", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
1194 | $start_month = date("m", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
1195 | $start_day = date("d", mktime(0, 0, 0, $tmp_month, $tmp_day + 1, $tmp_year)); |
---|
1196 | |
---|
1197 | // 日付の作成 |
---|
1198 | $start_date = sprintf("%d/%d/%d 00:00:00", $start_year, $start_month, $start_day); |
---|
1199 | $end_date = sprintf("%d/%d/%d 23:59:59", $end_year, $end_month, $end_day); |
---|
1200 | |
---|
1201 | return array($start_date, $end_date); |
---|
1202 | } |
---|
1203 | |
---|
1204 | // PDF用のRGBカラーを返す |
---|
1205 | function sfGetPdfRgb($hexrgb) { |
---|
1206 | $hex = substr($hexrgb, 0, 2); |
---|
1207 | $r = hexdec($hex) / 255; |
---|
1208 | |
---|
1209 | $hex = substr($hexrgb, 2, 2); |
---|
1210 | $g = hexdec($hex) / 255; |
---|
1211 | |
---|
1212 | $hex = substr($hexrgb, 4, 2); |
---|
1213 | $b = hexdec($hex) / 255; |
---|
1214 | |
---|
1215 | return array($r, $g, $b); |
---|
1216 | } |
---|
1217 | |
---|
1218 | //メルマガ仮登録とメール配信 |
---|
1219 | /* |
---|
1220 | * FIXME |
---|
1221 | */ |
---|
1222 | function sfRegistTmpMailData($mail_flag, $email){ |
---|
1223 | $objQuery = new SC_Query(); |
---|
1224 | $objConn = new SC_DBConn(); |
---|
1225 | $objPage = new LC_Page(); |
---|
1226 | |
---|
1227 | $random_id = sfGetUniqRandomId(); |
---|
1228 | $arrRegistMailMagazine["mail_flag"] = $mail_flag; |
---|
1229 | $arrRegistMailMagazine["email"] = $email; |
---|
1230 | $arrRegistMailMagazine["temp_id"] =$random_id; |
---|
1231 | $arrRegistMailMagazine["end_flag"]='0'; |
---|
1232 | $arrRegistMailMagazine["update_date"] = 'now()'; |
---|
1233 | |
---|
1234 | //メルマガ仮登録用フラグ |
---|
1235 | $flag = $objQuery->count("dtb_customer_mail_temp", "email=?", array($email)); |
---|
1236 | $objConn->query("BEGIN"); |
---|
1237 | switch ($flag){ |
---|
1238 | case '0': |
---|
1239 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine); |
---|
1240 | break; |
---|
1241 | |
---|
1242 | case '1': |
---|
1243 | $objConn->autoExecute("dtb_customer_mail_temp",$arrRegistMailMagazine, "email = " .SC_Utils::sfQuoteSmart($email)); |
---|
1244 | break; |
---|
1245 | } |
---|
1246 | $objConn->query("COMMIT"); |
---|
1247 | $subject = 'メルマガ仮登録が完了しました'; |
---|
1248 | $objPage->tpl_url = SSL_URL."mailmagazine/regist.php?temp_id=".$arrRegistMailMagazine['temp_id']; |
---|
1249 | switch ($mail_flag){ |
---|
1250 | case '1': |
---|
1251 | $objPage->tpl_name = "登録"; |
---|
1252 | $objPage->tpl_kindname = "HTML"; |
---|
1253 | break; |
---|
1254 | |
---|
1255 | case '2': |
---|
1256 | $objPage->tpl_name = "登録"; |
---|
1257 | $objPage->tpl_kindname = "テキスト"; |
---|
1258 | break; |
---|
1259 | |
---|
1260 | case '3': |
---|
1261 | $objPage->tpl_name = "解除"; |
---|
1262 | break; |
---|
1263 | } |
---|
1264 | $objPage->tpl_email = $email; |
---|
1265 | sfSendTplMail($email, $subject, 'mail_templates/mailmagazine_temp.tpl', $objPage); |
---|
1266 | } |
---|
1267 | |
---|
1268 | // 再帰的に多段配列を検索して一次元配列(Hidden引渡し用配列)に変換する。 |
---|
1269 | function sfMakeHiddenArray($arrSrc, $arrDst = array(), $parent_key = "") { |
---|
1270 | if(is_array($arrSrc)) { |
---|
1271 | foreach($arrSrc as $key => $val) { |
---|
1272 | if($parent_key != "") { |
---|
1273 | $keyname = $parent_key . "[". $key . "]"; |
---|
1274 | } else { |
---|
1275 | $keyname = $key; |
---|
1276 | } |
---|
1277 | if(is_array($val)) { |
---|
1278 | $arrDst = SC_Utils::sfMakeHiddenArray($val, $arrDst, $keyname); |
---|
1279 | } else { |
---|
1280 | $arrDst[$keyname] = $val; |
---|
1281 | } |
---|
1282 | } |
---|
1283 | } |
---|
1284 | return $arrDst; |
---|
1285 | } |
---|
1286 | |
---|
1287 | // DB取得日時をタイムに変換 |
---|
1288 | function sfDBDatetoTime($db_date) { |
---|
1289 | $date = ereg_replace("\..*$","",$db_date); |
---|
1290 | $time = strtotime($date); |
---|
1291 | return $time; |
---|
1292 | } |
---|
1293 | |
---|
1294 | /** |
---|
1295 | * テンプレートを切り替えて出力する |
---|
1296 | * |
---|
1297 | * @deprecated 2008/04/02以降使用不可 |
---|
1298 | */ |
---|
1299 | function sfCustomDisplay(&$objPage, $is_mobile = false) { |
---|
1300 | $basename = basename($_SERVER["REQUEST_URI"]); |
---|
1301 | |
---|
1302 | if($basename == "") { |
---|
1303 | $path = $_SERVER["REQUEST_URI"] . DIR_INDEX_URL; |
---|
1304 | } else { |
---|
1305 | $path = $_SERVER["REQUEST_URI"]; |
---|
1306 | } |
---|
1307 | |
---|
1308 | if(isset($_GET['tpl']) && $_GET['tpl'] != "") { |
---|
1309 | $tpl_name = $_GET['tpl']; |
---|
1310 | } else { |
---|
1311 | $tpl_name = ereg_replace("^/", "", $path); |
---|
1312 | $tpl_name = ereg_replace("/", "_", $tpl_name); |
---|
1313 | $tpl_name = ereg_replace("(\.php$|\.html$)", ".tpl", $tpl_name); |
---|
1314 | } |
---|
1315 | |
---|
1316 | $template_path = TEMPLATE_FTP_DIR . $tpl_name; |
---|
1317 | echo $template_path; |
---|
1318 | if($is_mobile === true) { |
---|
1319 | $objView = new SC_MobileView(); |
---|
1320 | $objView->assignobj($objPage); |
---|
1321 | $objView->display(SITE_FRAME); |
---|
1322 | } else if(file_exists($template_path)) { |
---|
1323 | $objView = new SC_UserView(TEMPLATE_FTP_DIR, COMPILE_FTP_DIR); |
---|
1324 | $objView->assignobj($objPage); |
---|
1325 | $objView->display($tpl_name); |
---|
1326 | } else { |
---|
1327 | $objView = new SC_SiteView(); |
---|
1328 | $objView->assignobj($objPage); |
---|
1329 | $objView->display(SITE_FRAME); |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | // PHPのmb_convert_encoding関数をSmartyでも使えるようにする |
---|
1334 | function sf_mb_convert_encoding($str, $encode = 'CHAR_CODE') { |
---|
1335 | return mb_convert_encoding($str, $encode); |
---|
1336 | } |
---|
1337 | |
---|
1338 | // PHPのmktime関数をSmartyでも使えるようにする |
---|
1339 | function sf_mktime($format, $hour=0, $minute=0, $second=0, $month=1, $day=1, $year=1999) { |
---|
1340 | return date($format,mktime($hour, $minute, $second, $month, $day, $year)); |
---|
1341 | } |
---|
1342 | |
---|
1343 | // PHPのdate関数をSmartyでも使えるようにする |
---|
1344 | function sf_date($format, $timestamp = '') { |
---|
1345 | return date( $format, $timestamp); |
---|
1346 | } |
---|
1347 | |
---|
1348 | // チェックボックスの型を変換する |
---|
1349 | function sfChangeCheckBox($data , $tpl = false){ |
---|
1350 | if ($tpl) { |
---|
1351 | if ($data == 1){ |
---|
1352 | return 'checked'; |
---|
1353 | }else{ |
---|
1354 | return ""; |
---|
1355 | } |
---|
1356 | }else{ |
---|
1357 | if ($data == "on"){ |
---|
1358 | return 1; |
---|
1359 | }else{ |
---|
1360 | return 2; |
---|
1361 | } |
---|
1362 | } |
---|
1363 | } |
---|
1364 | |
---|
1365 | // 2つの配列を用いて連想配列を作成する |
---|
1366 | function sfarrCombine($arrKeys, $arrValues) { |
---|
1367 | |
---|
1368 | if(count($arrKeys) <= 0 and count($arrValues) <= 0) return array(); |
---|
1369 | |
---|
1370 | $keys = array_values($arrKeys); |
---|
1371 | $vals = array_values($arrValues); |
---|
1372 | |
---|
1373 | $max = max( count( $keys ), count( $vals ) ); |
---|
1374 | $combine_ary = array(); |
---|
1375 | for($i=0; $i<$max; $i++) { |
---|
1376 | $combine_ary[$keys[$i]] = $vals[$i]; |
---|
1377 | } |
---|
1378 | if(is_array($combine_ary)) return $combine_ary; |
---|
1379 | |
---|
1380 | return false; |
---|
1381 | } |
---|
1382 | |
---|
1383 | /* 子ID所属する親IDを取得する */ |
---|
1384 | function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) { |
---|
1385 | $max = count($arrData); |
---|
1386 | $parent = ""; |
---|
1387 | for($i = 0; $i < $max; $i++) { |
---|
1388 | if($arrData[$i][$id_name] == $child) { |
---|
1389 | $parent = $arrData[$i][$pid_name]; |
---|
1390 | break; |
---|
1391 | } |
---|
1392 | } |
---|
1393 | return $parent; |
---|
1394 | } |
---|
1395 | |
---|
1396 | /* 階層構造のテーブルから与えられたIDの兄弟を取得する */ |
---|
1397 | function sfGetBrothersArray($arrData, $pid_name, $id_name, $arrPID) { |
---|
1398 | $max = count($arrData); |
---|
1399 | |
---|
1400 | $arrBrothers = array(); |
---|
1401 | foreach($arrPID as $id) { |
---|
1402 | // 親IDを検索する |
---|
1403 | for($i = 0; $i < $max; $i++) { |
---|
1404 | if($arrData[$i][$id_name] == $id) { |
---|
1405 | $parent = $arrData[$i][$pid_name]; |
---|
1406 | break; |
---|
1407 | } |
---|
1408 | } |
---|
1409 | // 兄弟IDを検索する |
---|
1410 | for($i = 0; $i < $max; $i++) { |
---|
1411 | if($arrData[$i][$pid_name] == $parent) { |
---|
1412 | $arrBrothers[] = $arrData[$i][$id_name]; |
---|
1413 | } |
---|
1414 | } |
---|
1415 | } |
---|
1416 | return $arrBrothers; |
---|
1417 | } |
---|
1418 | |
---|
1419 | /* 階層構造のテーブルから与えられたIDの直属の子を取得する */ |
---|
1420 | function sfGetUnderChildrenArray($arrData, $pid_name, $id_name, $parent) { |
---|
1421 | $max = count($arrData); |
---|
1422 | |
---|
1423 | $arrChildren = array(); |
---|
1424 | // 子IDを検索する |
---|
1425 | for($i = 0; $i < $max; $i++) { |
---|
1426 | if($arrData[$i][$pid_name] == $parent) { |
---|
1427 | $arrChildren[] = $arrData[$i][$id_name]; |
---|
1428 | } |
---|
1429 | } |
---|
1430 | return $arrChildren; |
---|
1431 | } |
---|
1432 | |
---|
1433 | // SQLシングルクォート対応 |
---|
1434 | function sfQuoteSmart($in){ |
---|
1435 | |
---|
1436 | if (is_int($in) || is_double($in)) { |
---|
1437 | return $in; |
---|
1438 | } elseif (is_bool($in)) { |
---|
1439 | return $in ? 1 : 0; |
---|
1440 | } elseif (is_null($in)) { |
---|
1441 | return 'NULL'; |
---|
1442 | } else { |
---|
1443 | return "'" . str_replace("'", "''", $in) . "'"; |
---|
1444 | } |
---|
1445 | } |
---|
1446 | |
---|
1447 | // ディレクトリを再帰的に生成する |
---|
1448 | function sfMakeDir($path) { |
---|
1449 | static $count = 0; |
---|
1450 | $count++; // 無限ループ回避 |
---|
1451 | $dir = dirname($path); |
---|
1452 | if(ereg("^[/]$", $dir) || ereg("^[A-Z]:[\\]$", $dir) || $count > 256) { |
---|
1453 | // ルートディレクトリで終了 |
---|
1454 | return; |
---|
1455 | } else { |
---|
1456 | if(is_writable(dirname($dir))) { |
---|
1457 | if(!file_exists($dir)) { |
---|
1458 | mkdir($dir); |
---|
1459 | GC_Utils::gfPrintLog("mkdir $dir"); |
---|
1460 | } |
---|
1461 | } else { |
---|
1462 | SC_Utils::sfMakeDir($dir); |
---|
1463 | if(is_writable(dirname($dir))) { |
---|
1464 | if(!file_exists($dir)) { |
---|
1465 | mkdir($dir); |
---|
1466 | GC_Utils::gfPrintLog("mkdir $dir"); |
---|
1467 | } |
---|
1468 | } |
---|
1469 | } |
---|
1470 | } |
---|
1471 | return; |
---|
1472 | } |
---|
1473 | |
---|
1474 | // ディレクトリ以下のファイルを再帰的にコピー |
---|
1475 | function sfCopyDir($src, $des, $mess = "", $override = false){ |
---|
1476 | if(!is_dir($src)){ |
---|
1477 | return false; |
---|
1478 | } |
---|
1479 | |
---|
1480 | $oldmask = umask(0); |
---|
1481 | $mod= stat($src); |
---|
1482 | |
---|
1483 | // ディレクトリがなければ作成する |
---|
1484 | if(!file_exists($des)) { |
---|
1485 | if(!mkdir($des, $mod[2])) { |
---|
1486 | print("path:" . $des); |
---|
1487 | } |
---|
1488 | } |
---|
1489 | |
---|
1490 | $fileArray=glob( $src."*" ); |
---|
1491 | if (is_array($fileArray)) { |
---|
1492 | foreach( $fileArray as $key => $data_ ){ |
---|
1493 | // CVS管理ファイルはコピーしない |
---|
1494 | if(ereg("/CVS/Entries", $data_)) { |
---|
1495 | break; |
---|
1496 | } |
---|
1497 | if(ereg("/CVS/Repository", $data_)) { |
---|
1498 | break; |
---|
1499 | } |
---|
1500 | if(ereg("/CVS/Root", $data_)) { |
---|
1501 | break; |
---|
1502 | } |
---|
1503 | |
---|
1504 | mb_ereg("^(.*[\/])(.*)",$data_, $matches); |
---|
1505 | $data=$matches[2]; |
---|
1506 | if( is_dir( $data_ ) ){ |
---|
1507 | $mess = SC_Utils::sfCopyDir( $data_.'/', $des.$data.'/', $mess); |
---|
1508 | }else{ |
---|
1509 | if(!$override && file_exists($des.$data)) { |
---|
1510 | $mess.= $des.$data . ":ファイルが存在します\n"; |
---|
1511 | } else { |
---|
1512 | if(@copy( $data_, $des.$data)) { |
---|
1513 | $mess.= $des.$data . ":コピー成功\n"; |
---|
1514 | } else { |
---|
1515 | $mess.= $des.$data . ":コピー失敗\n"; |
---|
1516 | } |
---|
1517 | } |
---|
1518 | $mod=stat($data_ ); |
---|
1519 | } |
---|
1520 | } |
---|
1521 | } |
---|
1522 | umask($oldmask); |
---|
1523 | return $mess; |
---|
1524 | } |
---|
1525 | |
---|
1526 | // 指定したフォルダ内のファイルを全て削除する |
---|
1527 | function sfDelFile($dir){ |
---|
1528 | if(file_exists($dir)) { |
---|
1529 | $dh = opendir($dir); |
---|
1530 | // フォルダ内のファイルを削除 |
---|
1531 | while($file = readdir($dh)){ |
---|
1532 | if ($file == "." or $file == "..") continue; |
---|
1533 | $del_file = $dir . "/" . $file; |
---|
1534 | if(is_file($del_file)){ |
---|
1535 | $ret = unlink($dir . "/" . $file); |
---|
1536 | }else if (is_dir($del_file)){ |
---|
1537 | $ret = SC_Utils::sfDelFile($del_file); |
---|
1538 | } |
---|
1539 | |
---|
1540 | if(!$ret){ |
---|
1541 | return $ret; |
---|
1542 | } |
---|
1543 | } |
---|
1544 | |
---|
1545 | // 閉じる |
---|
1546 | closedir($dh); |
---|
1547 | |
---|
1548 | // フォルダを削除 |
---|
1549 | return rmdir($dir); |
---|
1550 | } |
---|
1551 | } |
---|
1552 | |
---|
1553 | /* |
---|
1554 | * 関数名:sfWriteFile |
---|
1555 | * 引数1 :書き込むデータ |
---|
1556 | * 引数2 :ファイルパス |
---|
1557 | * 引数3 :書き込みタイプ |
---|
1558 | * 引数4 :パーミッション |
---|
1559 | * 戻り値:結果フラグ 成功なら true 失敗なら false |
---|
1560 | * 説明 :ファイル書き出し |
---|
1561 | */ |
---|
1562 | function sfWriteFile($str, $path, $type, $permission = "") { |
---|
1563 | //ファイルを開く |
---|
1564 | if (!($file = fopen ($path, $type))) { |
---|
1565 | return false; |
---|
1566 | } |
---|
1567 | |
---|
1568 | //ファイルロック |
---|
1569 | flock ($file, LOCK_EX); |
---|
1570 | //ファイルの書き込み |
---|
1571 | fputs ($file, $str); |
---|
1572 | //ファイルロックの解除 |
---|
1573 | flock ($file, LOCK_UN); |
---|
1574 | //ファイルを閉じる |
---|
1575 | fclose ($file); |
---|
1576 | // 権限を指定 |
---|
1577 | if($permission != "") { |
---|
1578 | chmod($path, $permission); |
---|
1579 | } |
---|
1580 | |
---|
1581 | return true; |
---|
1582 | } |
---|
1583 | |
---|
1584 | /** |
---|
1585 | * ブラウザに強制的に送出する |
---|
1586 | * |
---|
1587 | * @param boolean|string $output 半角スペース256文字+改行を出力するか。または、送信する文字列を指定。 |
---|
1588 | * @return void |
---|
1589 | */ |
---|
1590 | function sfFlush($output = false, $sleep = 0){ |
---|
1591 | // 出力をバッファリングしない(==日本語自動変換もしない) |
---|
1592 | while (@ob_end_flush()); |
---|
1593 | |
---|
1594 | if ($output === true) { |
---|
1595 | // IEのために半角スペース256文字+改行を出力 |
---|
1596 | //echo str_repeat(' ', 256) . "\n"; |
---|
1597 | echo str_pad('', 256) . "\n"; |
---|
1598 | } else if ($output !== false) { |
---|
1599 | echo $output; |
---|
1600 | } |
---|
1601 | |
---|
1602 | // 出力をフラッシュする |
---|
1603 | flush(); |
---|
1604 | |
---|
1605 | ob_start(); |
---|
1606 | |
---|
1607 | // 時間のかかる処理 |
---|
1608 | sleep($sleep); |
---|
1609 | } |
---|
1610 | |
---|
1611 | // @versionの記載があるファイルからバージョンを取得する。 |
---|
1612 | function sfGetFileVersion($path) { |
---|
1613 | if(file_exists($path)) { |
---|
1614 | $src_fp = fopen($path, "rb"); |
---|
1615 | if($src_fp) { |
---|
1616 | while (!feof($src_fp)) { |
---|
1617 | $line = fgets($src_fp); |
---|
1618 | if(ereg("@version", $line)) { |
---|
1619 | $arrLine = split(" ", $line); |
---|
1620 | $version = $arrLine[5]; |
---|
1621 | } |
---|
1622 | } |
---|
1623 | fclose($src_fp); |
---|
1624 | } |
---|
1625 | } |
---|
1626 | return $version; |
---|
1627 | } |
---|
1628 | |
---|
1629 | // 指定したURLに対してPOSTでデータを送信する |
---|
1630 | function sfSendPostData($url, $arrData, $arrOkCode = array()){ |
---|
1631 | require_once(DATA_PATH . "module/Request.php"); |
---|
1632 | |
---|
1633 | // 送信インスタンス生成 |
---|
1634 | $req = new HTTP_Request($url); |
---|
1635 | |
---|
1636 | $req->addHeader('User-Agent', 'DoCoMo/2.0 P2101V(c100)'); |
---|
1637 | $req->setMethod(HTTP_REQUEST_METHOD_POST); |
---|
1638 | |
---|
1639 | // POSTデータ送信 |
---|
1640 | $req->addPostDataArray($arrData); |
---|
1641 | |
---|
1642 | // エラーが無ければ、応答情報を取得する |
---|
1643 | if (!PEAR::isError($req->sendRequest())) { |
---|
1644 | |
---|
1645 | // レスポンスコードがエラー判定なら、空を返す |
---|
1646 | $res_code = $req->getResponseCode(); |
---|
1647 | |
---|
1648 | if(!in_array($res_code, $arrOkCode)){ |
---|
1649 | $response = ""; |
---|
1650 | }else{ |
---|
1651 | $response = $req->getResponseBody(); |
---|
1652 | } |
---|
1653 | |
---|
1654 | } else { |
---|
1655 | $response = ""; |
---|
1656 | } |
---|
1657 | |
---|
1658 | // POSTデータクリア |
---|
1659 | $req->clearPostData(); |
---|
1660 | |
---|
1661 | return $response; |
---|
1662 | } |
---|
1663 | |
---|
1664 | /** |
---|
1665 | * $array の要素を $arrConvList で指定した方式で mb_convert_kana を適用する. |
---|
1666 | * |
---|
1667 | * @param array $array 変換する文字列の配列 |
---|
1668 | * @param array $arrConvList mb_convert_kana の適用ルール |
---|
1669 | * @return array 変換後の配列 |
---|
1670 | * @see mb_convert_kana |
---|
1671 | */ |
---|
1672 | function mbConvertKanaWithArray($array, $arrConvList) { |
---|
1673 | foreach ($arrConvList as $key => $val) { |
---|
1674 | if(isset($array[$key])) { |
---|
1675 | $array[$key] = mb_convert_kana($array[$key] ,$val); |
---|
1676 | } |
---|
1677 | } |
---|
1678 | return $array; |
---|
1679 | } |
---|
1680 | |
---|
1681 | /** |
---|
1682 | * 配列の添字が未定義の場合は空文字を代入して定義する. |
---|
1683 | * |
---|
1684 | * @param array $array 添字をチェックする配列 |
---|
1685 | * @param array $defineIndexes チェックする添字 |
---|
1686 | * @return array 添字を定義した配列 |
---|
1687 | */ |
---|
1688 | function arrayDefineIndexes($array, $defineIndexes) { |
---|
1689 | foreach ($defineIndexes as $key) { |
---|
1690 | if (!isset($array[$key])) $array[$key] = ""; |
---|
1691 | } |
---|
1692 | return $array; |
---|
1693 | } |
---|
1694 | |
---|
1695 | /** |
---|
1696 | * XML宣言を出力する. |
---|
1697 | * |
---|
1698 | * XML宣言があると問題が発生する UA は出力しない. |
---|
1699 | * |
---|
1700 | * @return string XML宣言の文字列 |
---|
1701 | */ |
---|
1702 | function printXMLDeclaration() { |
---|
1703 | $ua = $_SERVER['HTTP_USER_AGENT']; |
---|
1704 | if (!preg_match("/MSIE/", $ua) || preg_match("/MSIE 7/", $ua)) { |
---|
1705 | print("<?xml version='1.0' encoding='" . CHAR_CODE . "'?>\n"); |
---|
1706 | } |
---|
1707 | } |
---|
1708 | |
---|
1709 | /* |
---|
1710 | * 関数名:sfGetFileList() |
---|
1711 | * 説明 :指定パス配下のディレクトリ取得 |
---|
1712 | * 引数1 :取得するディレクトリパス |
---|
1713 | */ |
---|
1714 | function sfGetFileList($dir) { |
---|
1715 | $arrFileList = array(); |
---|
1716 | $arrDirList = array(); |
---|
1717 | |
---|
1718 | if (is_dir($dir)) { |
---|
1719 | if ($dh = opendir($dir)) { |
---|
1720 | $cnt = 0; |
---|
1721 | // 行末の/を取り除く |
---|
1722 | while (($file = readdir($dh)) !== false) $arrDir[] = $file; |
---|
1723 | $dir = ereg_replace("/$", "", $dir); |
---|
1724 | // アルファベットと数字でソート |
---|
1725 | natcasesort($arrDir); |
---|
1726 | foreach($arrDir as $file) { |
---|
1727 | // ./ と ../を除くファイルのみを取得 |
---|
1728 | if($file != "." && $file != "..") { |
---|
1729 | |
---|
1730 | $path = $dir."/".$file; |
---|
1731 | // SELECT内の見た目を整えるため指定文字数で切る |
---|
1732 | $file_name = SC_Utils::sfCutString($file, FILE_NAME_LEN); |
---|
1733 | $file_size = SC_Utils::sfCutString(SC_Utils::sfGetDirSize($path), FILE_NAME_LEN); |
---|
1734 | $file_time = date("Y/m/d", filemtime($path)); |
---|
1735 | |
---|
1736 | // ディレクトリとファイルで格納配列を変える |
---|
1737 | if(is_dir($path)) { |
---|
1738 | $arrDirList[$cnt]['file_name'] = $file; |
---|
1739 | $arrDirList[$cnt]['file_path'] = $path; |
---|
1740 | $arrDirList[$cnt]['file_size'] = $file_size; |
---|
1741 | $arrDirList[$cnt]['file_time'] = $file_time; |
---|
1742 | $arrDirList[$cnt]['is_dir'] = true; |
---|
1743 | } else { |
---|
1744 | $arrFileList[$cnt]['file_name'] = $file; |
---|
1745 | $arrFileList[$cnt]['file_path'] = $path; |
---|
1746 | $arrFileList[$cnt]['file_size'] = $file_size; |
---|
1747 | $arrFileList[$cnt]['file_time'] = $file_time; |
---|
1748 | $arrFileList[$cnt]['is_dir'] = false; |
---|
1749 | } |
---|
1750 | $cnt++; |
---|
1751 | } |
---|
1752 | } |
---|
1753 | closedir($dh); |
---|
1754 | } |
---|
1755 | } |
---|
1756 | |
---|
1757 | // フォルダを先頭にしてマージ |
---|
1758 | return array_merge($arrDirList, $arrFileList); |
---|
1759 | } |
---|
1760 | |
---|
1761 | /* |
---|
1762 | * 関数名:sfGetDirSize() |
---|
1763 | * 説明 :指定したディレクトリのバイト数を取得 |
---|
1764 | * 引数1 :ディレクトリ |
---|
1765 | */ |
---|
1766 | function sfGetDirSize($dir) { |
---|
1767 | if(file_exists($dir)) { |
---|
1768 | // ディレクトリの場合下層ファイルの総量を取得 |
---|
1769 | if (is_dir($dir)) { |
---|
1770 | $handle = opendir($dir); |
---|
1771 | while ($file = readdir($handle)) { |
---|
1772 | // 行末の/を取り除く |
---|
1773 | $dir = ereg_replace("/$", "", $dir); |
---|
1774 | $path = $dir."/".$file; |
---|
1775 | if ($file != '..' && $file != '.' && !is_dir($path)) { |
---|
1776 | $bytes += filesize($path); |
---|
1777 | } else if (is_dir($path) && $file != '..' && $file != '.') { |
---|
1778 | // 下層ファイルのバイト数を取得する為、再帰的に呼び出す。 |
---|
1779 | $bytes += SC_Utils::sfGetDirSize($path); |
---|
1780 | } |
---|
1781 | } |
---|
1782 | } else { |
---|
1783 | // ファイルの場合 |
---|
1784 | $bytes = filesize($dir); |
---|
1785 | } |
---|
1786 | } |
---|
1787 | // ディレクトリ(ファイル)が存在しない場合は0byteを返す |
---|
1788 | if($bytes == "") $bytes = 0; |
---|
1789 | |
---|
1790 | return $bytes; |
---|
1791 | } |
---|
1792 | |
---|
1793 | /* |
---|
1794 | * 関数名:sfDeleteDir() |
---|
1795 | * 説明 :指定したディレクトリを削除 |
---|
1796 | * 引数1 :削除ファイル |
---|
1797 | */ |
---|
1798 | function sfDeleteDir($dir) { |
---|
1799 | $arrResult = array(); |
---|
1800 | if(file_exists($dir)) { |
---|
1801 | // ディレクトリかチェック |
---|
1802 | if (is_dir($dir)) { |
---|
1803 | if ($handle = opendir("$dir")) { |
---|
1804 | $cnt = 0; |
---|
1805 | while (false !== ($item = readdir($handle))) { |
---|
1806 | if ($item != "." && $item != "..") { |
---|
1807 | if (is_dir("$dir/$item")) { |
---|
1808 | sfDeleteDir("$dir/$item"); |
---|
1809 | } else { |
---|
1810 | $arrResult[$cnt]['result'] = @unlink("$dir/$item"); |
---|
1811 | $arrResult[$cnt]['file_name'] = "$dir/$item"; |
---|
1812 | } |
---|
1813 | } |
---|
1814 | $cnt++; |
---|
1815 | } |
---|
1816 | } |
---|
1817 | closedir($handle); |
---|
1818 | $arrResult[$cnt]['result'] = @rmdir($dir); |
---|
1819 | $arrResult[$cnt]['file_name'] = "$dir/$item"; |
---|
1820 | } else { |
---|
1821 | // ファイル削除 |
---|
1822 | $arrResult[0]['result'] = @unlink("$dir"); |
---|
1823 | $arrResult[0]['file_name'] = "$dir"; |
---|
1824 | } |
---|
1825 | } |
---|
1826 | |
---|
1827 | return $arrResult; |
---|
1828 | } |
---|
1829 | |
---|
1830 | /* |
---|
1831 | * 関数名:sfGetFileTree() |
---|
1832 | * 説明 :ツリー生成用配列取得(javascriptに渡す用) |
---|
1833 | * 引数1 :ディレクトリ |
---|
1834 | * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 |
---|
1835 | */ |
---|
1836 | function sfGetFileTree($dir, $tree_status) { |
---|
1837 | |
---|
1838 | $cnt = 0; |
---|
1839 | $arrTree = array(); |
---|
1840 | $default_rank = count(split('/', $dir)); |
---|
1841 | |
---|
1842 | // 文末の/を取り除く |
---|
1843 | $dir = ereg_replace("/$", "", $dir); |
---|
1844 | // 最上位層を格納(user_data/) |
---|
1845 | if(sfDirChildExists($dir)) { |
---|
1846 | $arrTree[$cnt]['type'] = "_parent"; |
---|
1847 | } else { |
---|
1848 | $arrTree[$cnt]['type'] = "_child"; |
---|
1849 | } |
---|
1850 | $arrTree[$cnt]['path'] = $dir; |
---|
1851 | $arrTree[$cnt]['rank'] = 0; |
---|
1852 | $arrTree[$cnt]['count'] = $cnt; |
---|
1853 | // 初期表示はオープン |
---|
1854 | if($_POST['mode'] != '') { |
---|
1855 | $arrTree[$cnt]['open'] = lfIsFileOpen($dir, $tree_status); |
---|
1856 | } else { |
---|
1857 | $arrTree[$cnt]['open'] = true; |
---|
1858 | } |
---|
1859 | $cnt++; |
---|
1860 | |
---|
1861 | sfGetFileTreeSub($dir, $default_rank, $cnt, $arrTree, $tree_status); |
---|
1862 | |
---|
1863 | return $arrTree; |
---|
1864 | } |
---|
1865 | |
---|
1866 | /* |
---|
1867 | * 関数名:sfGetFileTree() |
---|
1868 | * 説明 :ツリー生成用配列取得(javascriptに渡す用) |
---|
1869 | * 引数1 :ディレクトリ |
---|
1870 | * 引数2 :デフォルトの階層(/区切りで 0,1,2・・・とカウント) |
---|
1871 | * 引数3 :連番 |
---|
1872 | * 引数4 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 |
---|
1873 | */ |
---|
1874 | function sfGetFileTreeSub($dir, $default_rank, &$cnt, &$arrTree, $tree_status) { |
---|
1875 | |
---|
1876 | if(file_exists($dir)) { |
---|
1877 | if ($handle = opendir("$dir")) { |
---|
1878 | while (false !== ($item = readdir($handle))) $arrDir[] = $item; |
---|
1879 | // アルファベットと数字でソート |
---|
1880 | natcasesort($arrDir); |
---|
1881 | foreach($arrDir as $item) { |
---|
1882 | if ($item != "." && $item != "..") { |
---|
1883 | // 文末の/を取り除く |
---|
1884 | $dir = ereg_replace("/$", "", $dir); |
---|
1885 | $path = $dir."/".$item; |
---|
1886 | // ディレクトリのみ取得 |
---|
1887 | if (is_dir($path)) { |
---|
1888 | $arrTree[$cnt]['path'] = $path; |
---|
1889 | if(sfDirChildExists($path)) { |
---|
1890 | $arrTree[$cnt]['type'] = "_parent"; |
---|
1891 | } else { |
---|
1892 | $arrTree[$cnt]['type'] = "_child"; |
---|
1893 | } |
---|
1894 | |
---|
1895 | // 階層を割り出す |
---|
1896 | $arrCnt = split('/', $path); |
---|
1897 | $rank = count($arrCnt); |
---|
1898 | $arrTree[$cnt]['rank'] = $rank - $default_rank + 1; |
---|
1899 | $arrTree[$cnt]['count'] = $cnt; |
---|
1900 | // フォルダが開いているか |
---|
1901 | $arrTree[$cnt]['open'] = lfIsFileOpen($path, $tree_status); |
---|
1902 | $cnt++; |
---|
1903 | // 下層ディレクトリ取得の為、再帰的に呼び出す |
---|
1904 | sfGetFileTreeSub($path, $default_rank, $cnt, $arrTree, $tree_status); |
---|
1905 | } |
---|
1906 | } |
---|
1907 | } |
---|
1908 | } |
---|
1909 | closedir($handle); |
---|
1910 | } |
---|
1911 | } |
---|
1912 | |
---|
1913 | /* |
---|
1914 | * 関数名:sfDirChildExists() |
---|
1915 | * 説明 :指定したディレクトリ配下にファイルがあるか |
---|
1916 | * 引数1 :ディレクトリ |
---|
1917 | */ |
---|
1918 | function sfDirChildExists($dir) { |
---|
1919 | if(file_exists($dir)) { |
---|
1920 | if (is_dir($dir)) { |
---|
1921 | $handle = opendir($dir); |
---|
1922 | while ($file = readdir($handle)) { |
---|
1923 | // 行末の/を取り除く |
---|
1924 | $dir = ereg_replace("/$", "", $dir); |
---|
1925 | $path = $dir."/".$file; |
---|
1926 | if ($file != '..' && $file != '.' && is_dir($path)) { |
---|
1927 | return true; |
---|
1928 | } |
---|
1929 | } |
---|
1930 | } |
---|
1931 | } |
---|
1932 | |
---|
1933 | return false; |
---|
1934 | } |
---|
1935 | |
---|
1936 | /* |
---|
1937 | * 関数名:lfIsFileOpen() |
---|
1938 | * 説明 :指定したファイルが前回開かれた状態にあったかチェック |
---|
1939 | * 引数1 :ディレクトリ |
---|
1940 | * 引数2 :現在のツリーの状態開いているフォルダのパスが | 区切りで格納 |
---|
1941 | */ |
---|
1942 | function lfIsFileOpen($dir, $tree_status) { |
---|
1943 | $arrTreeStatus = split('\|', $tree_status); |
---|
1944 | if(in_array($dir, $arrTreeStatus)) { |
---|
1945 | return true; |
---|
1946 | } |
---|
1947 | |
---|
1948 | return false; |
---|
1949 | } |
---|
1950 | |
---|
1951 | /* |
---|
1952 | * 関数名:sfDownloadFile() |
---|
1953 | * 引数1 :ファイルパス |
---|
1954 | * 説明 :ファイルのダウンロード |
---|
1955 | */ |
---|
1956 | function sfDownloadFile($file) { |
---|
1957 | // ファイルの場合はダウンロードさせる |
---|
1958 | Header("Content-disposition: attachment; filename=".basename($file)); |
---|
1959 | Header("Content-type: application/octet-stream; name=".basename($file)); |
---|
1960 | Header("Cache-Control: "); |
---|
1961 | Header("Pragma: "); |
---|
1962 | echo (sfReadFile($file)); |
---|
1963 | } |
---|
1964 | |
---|
1965 | /* |
---|
1966 | * 関数名:sfCreateFile() |
---|
1967 | * 引数1 :ファイルパス |
---|
1968 | * 引数2 :パーミッション |
---|
1969 | * 説明 :ファイル作成 |
---|
1970 | */ |
---|
1971 | function sfCreateFile($file, $mode = "") { |
---|
1972 | // 行末の/を取り除く |
---|
1973 | if($mode != "") { |
---|
1974 | $ret = @mkdir($file, $mode); |
---|
1975 | } else { |
---|
1976 | $ret = @mkdir($file); |
---|
1977 | } |
---|
1978 | |
---|
1979 | return $ret; |
---|
1980 | } |
---|
1981 | |
---|
1982 | /* |
---|
1983 | * 関数名:sfReadFile() |
---|
1984 | * 引数1 :ファイルパス |
---|
1985 | * 説明 :ファイル読込 |
---|
1986 | */ |
---|
1987 | function sfReadFile($filename) { |
---|
1988 | $str = ""; |
---|
1989 | // バイナリモードでオープン |
---|
1990 | $fp = @fopen($filename, "rb" ); |
---|
1991 | //ファイル内容を全て変数に読み込む |
---|
1992 | if($fp) { |
---|
1993 | $str = @fread($fp, filesize($filename)+1); |
---|
1994 | } |
---|
1995 | @fclose($fp); |
---|
1996 | |
---|
1997 | return $str; |
---|
1998 | } |
---|
1999 | |
---|
2000 | /** |
---|
2001 | * CSV出力用データ取得 |
---|
2002 | * |
---|
2003 | * @return string |
---|
2004 | */ |
---|
2005 | function getCSVData($array, $arrayIndex) { |
---|
2006 | for ($i = 0; $i < count($array); $i++){ |
---|
2007 | // インデックスが設定されている場合 |
---|
2008 | if (is_array($arrayIndex) && 0 < count($arrayIndex)){ |
---|
2009 | for ($j = 0; $j < count($arrayIndex); $j++ ){ |
---|
2010 | if ( $j > 0 ) $return .= ","; |
---|
2011 | $return .= "\""; |
---|
2012 | $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\""; |
---|
2013 | } |
---|
2014 | } else { |
---|
2015 | for ($j = 0; $j < count($array[$i]); $j++ ){ |
---|
2016 | if ( $j > 0 ) $return .= ","; |
---|
2017 | $return .= "\""; |
---|
2018 | $return .= mb_ereg_replace("<","<",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\""; |
---|
2019 | } |
---|
2020 | } |
---|
2021 | $return .= "\n"; |
---|
2022 | } |
---|
2023 | return $return; |
---|
2024 | } |
---|
2025 | |
---|
2026 | /** |
---|
2027 | * 配列をテーブルタグで出力する。 |
---|
2028 | * |
---|
2029 | * @return string |
---|
2030 | */ |
---|
2031 | function getTableTag($array) { |
---|
2032 | $html = "<table>"; |
---|
2033 | $html.= "<tr>"; |
---|
2034 | foreach($array[0] as $key => $val) { |
---|
2035 | $html.="<th>$key</th>"; |
---|
2036 | } |
---|
2037 | $html.= "</tr>"; |
---|
2038 | |
---|
2039 | $cnt = count($array); |
---|
2040 | |
---|
2041 | for($i = 0; $i < $cnt; $i++) { |
---|
2042 | $html.= "<tr>"; |
---|
2043 | foreach($array[$i] as $val) { |
---|
2044 | $html.="<td>$val</td>"; |
---|
2045 | } |
---|
2046 | $html.= "</tr>"; |
---|
2047 | } |
---|
2048 | return $html; |
---|
2049 | } |
---|
2050 | |
---|
2051 | /** |
---|
2052 | * 一覧-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。 |
---|
2053 | * |
---|
2054 | * @param string &$filename ファイル名 |
---|
2055 | * @return string |
---|
2056 | */ |
---|
2057 | function sfNoImageMainList($filename = '') { |
---|
2058 | if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') { |
---|
2059 | $filename .= 'noimage_main_list.jpg'; |
---|
2060 | } |
---|
2061 | return $filename; |
---|
2062 | } |
---|
2063 | |
---|
2064 | /** |
---|
2065 | * 詳細-メイン画像のファイル指定がない場合、専用の画像ファイルに書き換える。 |
---|
2066 | * |
---|
2067 | * @param string &$filename ファイル名 |
---|
2068 | * @return string |
---|
2069 | */ |
---|
2070 | function sfNoImageMain($filename = '') { |
---|
2071 | if (strlen($filename) == 0 || substr($filename, -1, 1) == '/') { |
---|
2072 | $filename .= 'noimage_main.png'; |
---|
2073 | } |
---|
2074 | return $filename; |
---|
2075 | } |
---|
2076 | |
---|
2077 | /* デバッグ用 ------------------------------------------------------------------------------------------------*/ |
---|
2078 | function sfPrintR($obj) { |
---|
2079 | print("<div style='font-size: 12px;color: #00FF00;'>\n"); |
---|
2080 | print("<strong>**デバッグ中**</strong><br />\n"); |
---|
2081 | print("<pre>\n"); |
---|
2082 | //print_r($obj); |
---|
2083 | var_dump($obj); |
---|
2084 | print("</pre>\n"); |
---|
2085 | print("<strong>**デバッグ中**</strong></div>\n"); |
---|
2086 | } |
---|
2087 | |
---|
2088 | /** |
---|
2089 | * ポイント加算するかの判定 |
---|
2090 | * |
---|
2091 | * @param integer $status 対応状況 |
---|
2092 | * @return boolean 加算するか |
---|
2093 | */ |
---|
2094 | function sfIsAddPoint($status) { |
---|
2095 | switch ($status) { |
---|
2096 | case ORDER_NEW: // 新規注文 |
---|
2097 | case ORDER_PAY_WAIT: // 入金待ち |
---|
2098 | case ORDER_PRE_END: // 入金済み |
---|
2099 | case ORDER_CANCEL: // キャンセル |
---|
2100 | case ORDER_BACK_ORDER: // 取り寄せ中 |
---|
2101 | return false; |
---|
2102 | |
---|
2103 | case ORDER_DELIV: // 発送済み |
---|
2104 | return true; |
---|
2105 | |
---|
2106 | default: |
---|
2107 | break; |
---|
2108 | } |
---|
2109 | |
---|
2110 | return false; |
---|
2111 | } |
---|
2112 | |
---|
2113 | /** |
---|
2114 | * ランダムな文字列を取得する |
---|
2115 | * |
---|
2116 | * @param integer $length 文字数 |
---|
2117 | * @return string ランダムな文字列 |
---|
2118 | */ |
---|
2119 | function sfGetRandomString($length = 1) { |
---|
2120 | require_once(dirname(__FILE__) . '/../../module/Text/Password.php'); |
---|
2121 | return Text_Password::create($length); |
---|
2122 | } |
---|
2123 | |
---|
2124 | /** |
---|
2125 | * 現在の URL を取得する |
---|
2126 | * |
---|
2127 | * @return string 現在のURL |
---|
2128 | */ |
---|
2129 | function sfGetUrl() { |
---|
2130 | $url = ''; |
---|
2131 | |
---|
2132 | if (SC_Utils_Ex::sfIsHTTPS()) { |
---|
2133 | $url = "https://"; |
---|
2134 | } else { |
---|
2135 | $url = "http://"; |
---|
2136 | } |
---|
2137 | |
---|
2138 | $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?' . $_SERVER['QUERY_STRING']; |
---|
2139 | |
---|
2140 | return $url; |
---|
2141 | } |
---|
2142 | |
---|
2143 | /** |
---|
2144 | * バックトレースをテキスト形式で出力する |
---|
2145 | * |
---|
2146 | * @return string テキストで表現したバックトレース |
---|
2147 | */ |
---|
2148 | function sfBacktraceToString($arrBacktrace) { |
---|
2149 | $string = ''; |
---|
2150 | |
---|
2151 | foreach ($arrBacktrace as $backtrace) { |
---|
2152 | if (strlen($backtrace['class']) >= 1) { |
---|
2153 | $func = $backtrace['class'] . $backtrace['type'] . $backtrace['function']; |
---|
2154 | } else { |
---|
2155 | $func = $backtrace['function']; |
---|
2156 | } |
---|
2157 | |
---|
2158 | $string .= $backtrace['file'] . " " . $backtrace['line'] . ":" . $func . "\n"; |
---|
2159 | } |
---|
2160 | |
---|
2161 | return $string; |
---|
2162 | } |
---|
2163 | |
---|
2164 | /** |
---|
2165 | * 管理機能かを判定 |
---|
2166 | * |
---|
2167 | * @return bool 管理機能か |
---|
2168 | */ |
---|
2169 | function sfIsAdminFunction() { |
---|
2170 | return defined('ADMIN_FUNCTION') && ADMIN_FUNCTION; |
---|
2171 | } |
---|
2172 | |
---|
2173 | /** |
---|
2174 | * フロント機能かを判定 |
---|
2175 | * |
---|
2176 | * @return bool フロント機能か |
---|
2177 | */ |
---|
2178 | function sfIsFrontFunction() { |
---|
2179 | return SC_Utils_Ex::sfIsPcSite() || SC_Utils_Ex::sfIsMobileSite(); |
---|
2180 | } |
---|
2181 | |
---|
2182 | /** |
---|
2183 | * フロント機能PCサイトかを判定 |
---|
2184 | * |
---|
2185 | * @return bool フロント機能PCサイトか |
---|
2186 | */ |
---|
2187 | function sfIsPcSite() { |
---|
2188 | return defined('FRONT_FUNCTION_PC_SITE') && FRONT_FUNCTION_PC_SITE; |
---|
2189 | } |
---|
2190 | |
---|
2191 | /** |
---|
2192 | * フロント機能モバイル機能かを判定 |
---|
2193 | * |
---|
2194 | * @return bool フロント機能モバイル機能か |
---|
2195 | */ |
---|
2196 | function sfIsMobileSite() { |
---|
2197 | return defined('MOBILE_SITE') && MOBILE_SITE; |
---|
2198 | } |
---|
2199 | |
---|
2200 | /** |
---|
2201 | * インストール機能かを判定 |
---|
2202 | * |
---|
2203 | * @return bool インストール機能か |
---|
2204 | */ |
---|
2205 | function sfIsInstallFunction() { |
---|
2206 | return defined('INSTALL_FUNCTION') && INSTALL_FUNCTION; |
---|
2207 | } |
---|
2208 | |
---|
2209 | // 郵便番号から住所の取得 |
---|
2210 | function sfGetAddress($zipcode) { |
---|
2211 | |
---|
2212 | $conn = new SC_DBconn(ZIP_DSN); |
---|
2213 | |
---|
2214 | $masterData = new SC_DB_MasterData_Ex(); |
---|
2215 | $arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank")); |
---|
2216 | // インデックスと値を反転させる。 |
---|
2217 | $arrREV_PREF = array_flip($arrPref); |
---|
2218 | |
---|
2219 | // 郵便番号検索文作成 |
---|
2220 | $zipcode = mb_convert_kana($zipcode ,"n"); |
---|
2221 | $sqlse = "SELECT state, city, town FROM mtb_zip WHERE zipcode = ?"; |
---|
2222 | |
---|
2223 | $data_list = $conn->getAll($sqlse, array($zipcode)); |
---|
2224 | if (empty($data_list)) return array(); |
---|
2225 | |
---|
2226 | /* |
---|
2227 | 総務省からダウンロードしたデータをそのままインポートすると |
---|
2228 | 以下のような文字列が入っているので 対策する。 |
---|
2229 | ・(1・19丁目) |
---|
2230 | ・以下に掲載がない場合 |
---|
2231 | */ |
---|
2232 | $town = $data_list[0]['town']; |
---|
2233 | $town = ereg_replace("(.*)$","",$town); |
---|
2234 | $town = ereg_replace("以下に掲載がない場合","",$town); |
---|
2235 | $data_list[0]['town'] = $town; |
---|
2236 | $data_list[0]['state'] = $arrREV_PREF[$data_list[0]['state']]; |
---|
2237 | |
---|
2238 | return $data_list; |
---|
2239 | } |
---|
2240 | } |
---|
2241 | ?> |
---|