header_html(THEMETITLE);//ヘッダー if(!isset($_SESSION["session_id"])){ html::error("ログインできていないようです。
ログインフォームよりログインしてください。"); } switch($_POST['mode']): case 'theme_add': // 書き込み処理 $add = new theme_add(); $add->add_main(); break; case 'theme_cor': // 編集処理 $cor = new theme_cor(); $cor->cor_main(); break; case 'theme_del_h': // 削除確認 $del = new theme_del(); $del->del_html(); break; case 'theme_del': // 削除処理 $del = new theme_del(); $del->del_main(); break; case 'view': // 個別表示 $view = new theme_view(); $view->no_view(); break; default: // 一覧表示 $view = new theme_view(); $view->view(); break; endswitch; $h->footer_html(); //フッター exit(); //================================================// //■テーマ追加                  // //================================================// class theme_add{ var $id; var $tno; var $tname; //================================================// //□コンストラクタ //================================================// function __construct(){ $this->tname = $_POST['tname']; $this->tno = $_GET['no']; $this->id = $_SESSION["session_id"]; } //================================================// //□追加処理 //================================================// function add_main(){ global $my_url,$th; $th_no = $th['no']; //文字チェック $this->check(); //上限までに戻す if($th['row'] >99){ $th['row'] = 99; } //Mysqlへ接続 $con_id = sql_init::connect(); //整列して読み込み $insert ="SELECT * FROM {$th['colum']} " ."WHERE {$th['id']}='$this->id'" ."ORDER BY {$th['no']}"; //SQL文送信 $sql = mysql_query($insert,$con_id); //配列として受け取る(MYSQL_ASSOCはカラム名で受け取るやつ)$lines[themeName]とかできる $con =0; while($lines = mysql_fetch_array($sql,MYSQL_ASSOC)){ // echo"{$con}個目: {$lines[$th_no]}
"; //件数が超えてないかチェック if($con > $th['row']){ html::error("これ以上増やせません"); } //一致しなければループぬける if($lines[$th_no] !=$con){ break; } $con++; } //No決定 $tno = $con; //登録内容 $insert ="INSERT INTO {$th['colum']}({$th['id']},{$th['no']},{$th['name']})" ."VALUES('$this->id','$tno','$this->tname')"; //データベースへ登録 if(mysql_query($insert,$con_id)){ echo"登録しました。"; }else { html::error("登録できませんでした。"); } //sql接続切る mysql_close($con_id); //管理トップに戻す。 html::back_html($my_url); } //================================================// //□文字チェック //================================================// function check(){ //文字チェック $error = $this->write_check(); if($error != ""){ //書き込み画面へ theme_view::view($error); //フッター html::footer_html(); exit(); } } //================================================// //□check処理部 //================================================// function write_check(){ $error=""; //文字数チェック if(strlen($this->tname) > 40){ $error .="20文字以内にしてください
"; }elseif($this->tname == ""){ $error .="入力されていません
"; } return $error; } } //================================================// //■テーマ編集                  // //================================================// class theme_cor extends theme_add{ //================================================// //□編集処理 //================================================// function cor_main(){ global $my_url,$th; //文字チェック $this->check(); //Mysqlへ接続 $con_id = sql_init::connect(); //登録内容 $insert ="UPDATE {$th['colum']} SET " ."{$th['name']} = '$this->tname' " ."WHERE {$th['id']}='$this->id' AND {$th['no']}='$this->tno'"; //データベースへ登録 if(mysql_query($insert,$con_id)){ echo"変更しました。"; }else { html::error("変更できませんでした。"); } //sql接続切る mysql_close($con_id); //管理トップに戻す。 html::back_html($my_url); } //================================================// //□文字チェック //================================================// function check(){ //文字チェック $error = $this->write_check(); if($error != ""){ //書き込み画面へ theme_view::no_view($error); //フッター html::footer_html(); exit(); } } } //================================================// //■削除・表示部共通部 //================================================// class theme_func{ var $id; var $tno; //================================================// //□コンストラクタ //================================================// function __construct(){ $this->id = $_SESSION["session_id"]; $this->tno = $_GET['no']; } //================================================// //□テーマ使用記事表示 //================================================// function kiji_view($con_id){ global $ki; $ki_day = $ki['day']; $ki_title = $ki['title']; //記事表示 $insert ="SELECT * FROM {$ki['colum']} " ."WHERE {$ki['id']}='$this->id' AND {$ki['tno']}='$this->tno' ORDER BY {$ki['day']} DESC"; //sql実行 $sql = mysql_query($insert,$con_id); //表示 echo""; } //======================================================== //一致するレコード抜き出し //======================================================== function get_line($con_id){ global $th; //一致する行取得 $insert ="SELECT * FROM {$th['colum']} " ."WHERE {$th['id']}='$this->id' AND {$th['no']}='$this->tno'"; //SQL文送信 $sql = mysql_query($insert,$con_id); //配列として受け取る $lines = mysql_fetch_array($sql,MYSQL_ASSOC); return $lines; } } //================================================// //■テーマ編集                  // //================================================// class theme_del extends theme_func{ //================================================// //□削除確認 //================================================// function del_html(){ global $th; $th_name = $th['name']; //Mysqlへ接続 $con_id = sql_init::connect(); if($this->tno == 0){ html::error("基本テーマは削除できません"); } //読み込み $lines = $this->get_line($con_id); //基本テーマ取得 $insert ="SELECT * FROM {$th['colum']} " ."WHERE {$th['id']}='$this->id'" ."ORDER BY {$th['no']} LIMIT 1"; //SQL実行 $sql = mysql_query($insert,$con_id); //配列として受け取る $olines = mysql_fetch_array($sql,MYSQL_ASSOC); //sql接続切る mysql_close($con_id); echo << テーマ名 : {$lines[$th_name]} を削除してもよろしいですか? 削除すると、 {$lines[$th_name]}をテーマにしている記事のテーマが {$olines[$th_name]}に変わります。
EOM; } //================================================// //□削除処理 //================================================// function del_main(){ global $my_url,$th; //Mysqlへ接続 $con_id = sql_init::connect(); //テーマチェンジ $this->theme_change($con_id); //登録内容 $insert ="DELETE FROM {$th['colum']} " ."WHERE {$th['id']}='$this->id' AND {$th['no']}='$this->tno'"; //データベースから削除 if(mysql_query($insert,$con_id)){ echo"削除しました。"; }else { html::error("削除できませんでした。"); } //テーブル整頓 // $insert ="OPTIMIZE TABLE ".$th['columt']; //データベースへ登録 mysql_query($insert,$con_id); //sql接続切る mysql_close($con_id); //管理トップに戻す。 html::back_html($my_url); } //================================================// //□テーマ変更処理 //================================================// function theme_change($con_id){ global $ki; //登録内容 $insert ="UPDATE {$ki['colum']} SET " ."{$ki['tno']} = '0' " ."WHERE {$ki['id']}='$this->id' AND {$ki['tno']}='$this->tno'"; //データベースへ登録 if(mysql_query($insert,$con_id)){ // echo"変更しました。"; }else { //sql接続切る mysql_close($con_id); html::error("テーマ変更できません。"); } } } //================================================// //■表示部 // // view_html // // @param $error // @return void // //================================================// class theme_view extends theme_func{ //================================================// //□一覧表示 //================================================// function view($error=""){ global $th,$ki; $th_no = $th['no']; $th_name = $th['name']; //Mysqlへ接続 $con_id = sql_init::connect(); echo << EOM; //一覧表示 $insert ="SELECT * FROM {$th['colum']} " ."WHERE {$th['id']}='$this->id'"; //sql実行 $sql = mysql_query($insert,$con_id); echo""; //sql接続切る mysql_close($con_id); } //================================================// //□個別表示 //================================================// function no_view($error=""){ global $th; $th_name = $th['name']; //Mysqlへ接続 $con_id = sql_init::connect(); //どのテーマ? $lines = $this->get_line($con_id); echo <<テーマ名 : {$lines[$th_name]} の編集・削除
{$error}
EOM; //記事一覧 $this->kiji_view($con_id); //sql接続切る mysql_close($con_id); } } ?>