#
#
/*
=head1 NAME
CGIToolBox.inc -- CGI汎用ライブラリ
=head1 HISTORY
2003.08.28 v0.1
2003.09.11 v0.2
+ mk_form() 自動フォーム作成関連追加
+ 日付関連追加
2003.09.11 v0.2.1
+ get_param() stripslashes追加
2003.09.24 v0.2.2
+ mk_pager にb_text,n_textオプション追加
2003.12.04 v0.2.3
2004.01.06 v0.2.6
+ read_db() 削除
+ date_calendar()
=head1 SYNOPSIS
# HTML作成
$str = mk_option($ary = array(), $select = '', $spliter = "\n");
$str = mk_radio($name, $ary = array(), $select = '', $num_flag = 0, $spliter = "\n");
$hash = mk_pager($count, $page, $pos, $opt = array());
$tmpl = template($file, $tmpl_var = array());
# HTML作成(フォーム
$conf = mk_form_config($path, $name); # フォーム設定読み
$ary = mk_form($conf, $val = array()); # フォームHTML作成
$param = get_param($conf, $_REQUEST); # 作成フォームからの値をハッシュにする
$err = param_check($conf, $param); # 入力チェック
# ファイル
$scalar = $nextval($path);
$ary = read_db($path);
$hash = file_select($path);
$ary = file_read_hash($path, $reg = array(), $mode = 1)
$hash = file_write($path, $hash);
$hash = file_read_config($path);
# 日付
$ary = date_split('20030101');
$utc = date2utc('20030101');
$bool = date_valid('20030101');
$num = date_wday('20030101');
$day = date_lastday('20030101');
$cal = date_calendar('2004', '01');
# 変換
$str = pricef($num);
$str = escape_tab($str);
$str = unescape_tab($str);
$str = escape_tag($str);
$str = unescape_tag($str);
$str = str2sjis($str, $from = 'SJIS,EUC-JP,JIS');
$str = str2euc($str, $from = 'SJIS,EUC-JP,JIS');
$str = str2jis($str, $from = 'SJIS,EUC-JP,JIS');
# メール送信
$bool = sendmail(
array(
SmtpServer => 'mail.k-digix.co.jp',
From => 'nerikeshi@mac.com',
To => array( '関川' => 'nerikeshi@mac.com'),
Cc => array( 'ネリケシ' => 'nerikeshi@mac.com'),
Subject => '表題',
Body => '内容',
KanjiKode => 'EUC-JP'
)
);
=head1 DESCRIPTION
# フォームファイルの形式
form.conf -----------------------------------------------------------------
[Param]
id ID NotNull size:10 KEY
name 名称 NotNull size:50
flag フラグ NotNull LIST(0:不可,1:可) TYPE:radio DEFAULT:0
select1 選択 NotNull LIST(1,2,3,4)
select2 選択(外部リスト) NotNull
script --------------------------------------------------------------------
### フォーム書き
$conf = mk_form_config('form.conf', 'Param');
$ary = mk_form($conf); # フォームHTML作成
foreach($ary as $a){
print $a['name'] . ':' . $a['element'] . '
'
}
### 作成フォームからの値をハッシュにする
$conf = mk_form_config('form.conf', 'Param');
$param = get_param($conf, $_REQUEST);
$err = param_check($conf, $param);# 入力チェック
if(count($err)) error($err)
=cut
*/
$DumperDep = 0;
$DumperType = array();
# ソート _______________________________________________________________________
// -- ハッシュソート昇順(小さい順
function sort_hash($a, $b, $dep = 0){
global $SortKeys;
$key = $SortKeys[$dep];
if($key == '') return 0;
if ($a[$key] == $b[$key]) return sort_hash($a, $b, $dep + 1);
return ($a[$key] > $b[$key]) ? 1 : -1;
}
// -- ハッシュソート降順(大きい順
function rsort_hash($a, $b, $dep = 0){
global $SortKeys;
$key = $SortKeys[$dep];
if($key == '') return 0;
if ($a[$key] == $b[$key]) return rsort_hash($a, $b, $dep + 1);
return ($a[$key] > $b[$key]) ? -1 : 1;
}
# HTML作成 _____________________________________________________________________
// -- HTML出力
function template($file, $tmpl_var = array(), $opt = array()){
include_once('template.php');
if(! file_exists($file)){
header('Content-Type: text/plain;');
print "TemplateFile [$file] does not exist.";
exit;
}
$tmpl_opt = array(
filename => $file,
die_on_bad_params => 0,
search_path_on_include => 0
);
#dumper(array_merge($tmpl_opt, $opt));
$tmpl =& new Template(array_merge($tmpl_opt, $opt));
$tmpl->AddParam($tmpl_var);
return $tmpl;
}
// -- オプション作成
function mk_option($ary = array(), $select = '', $num_flag = 0, $spliter = "\n"){
$re = array();
foreach($ary as $a){
if(! is_array($a)){
$a = $num_flag ? array(count($re) + 1, $a) : array($a, $a);
}
$selected = $a[0] == $select ? ' SELECTED ' : '';
array_push($re, "