ノブログ製作委員会

テーマ管理

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集
<?php
////////////////////////////////////////////////////////
//
// ver 0.4ぐらい
// 12/20 新規追加はできるようになった 0.3
//  21 新規追加を改良               0.4
//       いちおー一覧表示
//
////////////////////////////////////////////////////////



//ファイル読み込み
include("./init.php");

//================================================//
//■メイン                      //
//================================================//

//生成
$h = new html();
$sql = new sql_init();
$add = new theme_add();
$view = new theme_view();

if($_SERVER['REQUEST_METHOD'] == "GET"){
$_POST['mode'] = &$_GET['mode'];
}


$h->header_html(THEMETITLE);//ヘッダー

switch($_POST['mode']):
case 'thama_add': // 書き込み処理
$add->add_main();
break;
default:
$view->view_html();// 一覧表示
break;
endswitch;

$h->footer_html();//フッター

exit();
//================================================//
//■テーマ追加                  //
//================================================//
class theme_add{
var $id;
var $tno;
var $tname;

//================================================//
//□コンストラクタ
//================================================//
function __construct(){
$this->tname = $_POST['tname'];
$this->$tno = 0;
    }
//================================================//
//□追加処理
//================================================//
function add_main(){
global $my_url,$th;
$id = "testrr";

//配列要素を変数に格納
$th =implode("<>", $th);
list($th_colum,$th_id,$th_no, $th_name,$th_row) = split("<>", $th);

//文字チェック
$this->write_check();

//Mysqlへ接続
$con_id = sql_init::connect();

//前の一行を読み込む
$insert ="select * from $th_colum "
."WHERE $th_id='$id'"
."order by $th_no desc LIMIT 1";

//SQL文送信
$sql = mysql_query($insert,$con_id);

//配列として受け取る(MYSQL_ASSOCはカラム名で受け取るやつ)$lines[themeName]とかできる
$lines = mysql_fetch_array($sql,MYSQL_ASSOC);

if($th_row >99){
$th_row =99;
}
if(($lines[$th_no] + 1) > $th_row){
exit("これ以上増やせません");
}

//前のNoを1増やす
$tno= ++$lines[$th_no];

//登録内容
$insert ="insert into $th_colum($th_id,$th_no,$th_name)"
."values('$id','$tno','$this->tname')";

//データベースへ登録
if(mysql_query($insert,$con_id)){
echo"登録しました。";
}else {
echo"登録できませんでした。";
}

//sql接続切る
mysql_close($con_id);
//管理トップに戻す。
html::back_html($my_url);
}
//================================================//
//□文字チェック
//================================================//
function write_check(){
$error="";
//文字数チェック
if(strlen($this->tname) > 40){
$error .="20文字以内にしてください<br/>";
}elseif($this->tname == ""){
$error .="入力されていません<br/>";
}

if($error != ""){
//書き込み画面へ
theme_view::view_html($error);
//フッター
html::footer_html();
exit();
}
}

}
//================================================//
//■表示部
//
// view_html
//
// @param $error
// @return void
//
//================================================//
class theme_view{

//================================================//
//□一覧表示
//================================================//
function view_html($error=""){
global $th;

//配列要素を変数に格納
$th =implode("<>", $th);
list($th_colum,$th_id,$th_no, $th_name) = split("<>", $th);

//Mysqlへ接続
$con_id = sql_init::connect();

echo <<<EOM
<div align="center" >
{$error}
<form action="$PHP_SELF" method="post">
<input type=hidden name="mode" value="thama_add">
<input type=text name=tname size=20 value="" title ="全角20文字以内">
<input type=submit value="追加する">
</form>
</div>
EOM;

//一覧表示
$insert ="select * from {$th_colum} ";

$sql = mysql_query($insert,$con_id);

while($lines = mysql_fetch_array($sql,MYSQL_ASSOC)){
echo"{$lines[$th_name]}<br/>";

}

//sql接続切る
mysql_close($con_id);

}

}


?>

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

目安箱バナー