#!/usr/local/bin/perl # ###################################################################### ### ### ### CGIリンク集管理システム T-Bookmark Ver.1.10 ### [2/4] ユーザ登録 (tbregist.cgi) ### (c) 1996-2000 Takahiro Nishida ### http://www.mytools.net/ ### ### ###################################################################### # require './tblib.pl'; &main; sub main{ &tblib'lock; &init_variables; &open_datafile; &check_input; &check_urlinfo; &add_data; &show_html; &tblib'unlock; } ########## 変数の初期化 sub init_variables{ $basedir = $tblib'basedir; $datafile = "$basedir/tbdata.txt"; $newfile = "$basedir/tbnew.txt"; $tpfile = "$basedir/tb_regist.html"; } ########## 入力のチェック sub check_input{ &tblib'parseform; $utype = $tblib'F{'utype'}; $mode = $tblib'F{'mode'} || "top"; $checked = $tblib'F{'checked'}; } ########## データファイルのオープン sub open_datafile{ &tblib'openfile($datafile, *datas); &tblib'openfile($newfile, *news); &tblib'openfile($tpfile, *tps); &tblib'set_genre; } ########## 入力データの形式チェック sub check_urlinfo{ ($utype) || return; ### 入力の受け取り $uid = $tblib'F{'uid'}; $umail = &tblib'decode($tblib'F{'umail'}); $uname = &tblib'decode($tblib'F{'uname'}); $utitle = &tblib'decode($tblib'F{'utitle'}); $uurl = &tblib'decode($tblib'F{'uurl'}); $ukeys = &tblib'decode($tblib'F{'ukeys'}); $ugcode = &tblib'decode($tblib'F{'gcode'}); $ucom = &tblib'decode($tblib'F{'ucom'}); $udate = &tblib'decode($tblib'F{'udate'}); ### 不正チェック (!$uid) || ($uid =~ /^\d+$/) || ®ist_error("IDが不正です。"); ($umail =~ /^[\w\-\+\.]+\@[\w\-\+\.]+$/) || ®ist_error("メールアドレスが入力されていないかが不正です。"); (!$uurl) || ($uurl =~ /^http:\/\//) || ®ist_error("URLが入力されていないか不正です。"); (!$ugcode) || ($ugcode =~ /^(\w\w:)+$/) || ®ist_error("ジャンルが一つも選択されていないか不正です。"); ### 新規 if($utype eq 'new'){ $udate = "###"; $uid = ""; ($uname && $utitle && $uurl) || ®ist_error("入力がされていない項目があります。★の項目は必須です。$uname, $utitle, $uurl"); } ### 修正、削除 else{ ### 日付を変更する ($udate == 1) && ($udate = "UUU"); ### IDの存在チェック ($uid) || ®ist_error("IDが指定されていません。"); push(@datas, $uid); for($i = 0; $i <= $#datas; $i++){ ($datas[$i] =~ /^$uid/) && last; } ($i == $#datas) && ®ist_error("ID No.$uid は存在しません。"); ### 古いデータと新しいデータをマージ $oldline = $datas[$i]; ($oid, $ogcode, $odate, $ourl, $otitle, $ocom, $okey, $oname, $omail) = split("\t", $oldline); ($omail eq $umail) || ®ist_error("メールアドレスが登録時のものと一致しません。"); ($ugcode) || (($ugcode) = ($ogcode =~ m|^:(.+)|)); ($udate) || ($udate = $odate); ($uurl) || ($uurl = $ourl); ($utitle) || ($utitle = $otitle); ($ucom) || ($ucom = $ocom); ($ukeys) || ($ukeys = $okey); ($uname) || ($uname = $oname); } ($checked && $utype eq 'new') && ($uid = &tblib'make_new_id); $newline = "$utype\t$uid\t:$ugcode\t$udate\t$uurl\t$utitle\t$ucom\t$ukeys\t$uname\t$umail\t$ENV{'REMOTE_HOST'}\t\n"; } ########## ファイルを更新する sub add_data{ ($utype && $checked) || return; ### 同じIDに関する登録があった場合は古いものを消す for $i(0..$#news){ ($news[$i] =~ /\t$uid\t/) && splice(@news, $i, 1); } push(@news, $newline); &tblib'updatefile($newfile, *news); } ########## 表示 sub show_html{ local($htmlbuf, $listbuf); if($utype){ $C{'title'} = $T{$utype}; $listbuf = &html_urlinfo; if($checked){ ### 登録完了 $msg = "【登録完了】 以下のように仮登録されました。この内容は管理者のチェック後に本登録されます。"; $form = "[検索ページへ戻る]"; } else{ ### 申請内容確認 $msg = "【登録確認】 以下のように登録します。内容を確認し「仮登録実行」を押してください。"; $form = &html_registbutton; } } else{ ### 初期画面 $C{'ugcode'} = &tblib'make_genre_form(""); } print "Content-type: text/html\n\n"; $tpfrag = 1; foreach (@tps){ (/^