<?php

	class indexConn extends Conn{
		public function index(){
			$this -> output();
		}
		public function post_list(){
			$this -> output();
		}
		public function post_content(){
			$this -> output();
		}
		public function post_add(){
			$this -> output();
		}
		public function list_other(){
			$this -> output();
		}
		public function post_submit(){
			$content = isset($_POST['content']) ? $_POST['content'] : '';
			if(empty($content))
				alert_2(1,'请输入回帖内容','',3);
			if(empty($_POST['t_id']))
				alert_2(1,'请选择帖子','',3);
			if(empty($_SESSION['user']['user_id']))
				alert_2(1,'请先登陆','',3);
			$pdo = get_pdo();
			$time = time();
			$row = $pdo -> sql('insert into '.DB_PRE."z_bbs_post(content,time,t_id,user_id)values('{$content}','{$time}','{$_POST['t_id']}','{$_SESSION['user']['user_id']}')");
			if(empty($row))
				alert_2(1,'网络繁忙 回帖失败','',3);
			$res = $pdo -> query('select s_id from '.DB_PRE."z_bbs_thread where id='{$_POST['t_id']}' limit 1",'');
			$pdo -> sql('update '.DB_PRE."z_bbs_section set post = post+1 where id='{$res['s_id']}'");
			alert_2(-1,'回帖成功','',3);
		}
		public function thread_submit(){
			$content = isset($_POST['content']) ? $_POST['content'] : '';
			if(empty($_POST['title']))
				alert_2(1,'请输入标题','',3);
			if(empty($content))
				alert_2(1,'请输入回帖内容','',3);
			if(empty($_POST['s_id']))
				alert_2(1,'请选择版块','',3);
			if(empty($_SESSION['user']['user_id']))
				alert_2(1,'请先登陆','',3);
			$pdo = get_pdo();
			$time = time();
			$row = $pdo -> sql('insert into '.DB_PRE."z_bbs_thread(title,content,time,s_id,user_id,f_id)values('{$_POST['title']}','{$content}','{$time}','{$_POST['s_id']}','{$_SESSION['user']['user_id']}','{$_POST['f_id']}')");
			if(empty($row))
				alert_2(1,'网络繁忙 发布失败','',3);
			$id = $pdo -> last_id();
			$pdo -> sql('update '.DB_PRE."z_bbs_section set thread = thread+1,last_time='{$time}',last_id='{$id}' where id='{$_POST['s_id']}'");
			alert_2(0,'发布成功',"bbs.php?h=index&c=post_content&k={$id}",3);
		}
		public function guanzhu(){
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_thread set guanzhu = guanzhu+1 where id='{$_GET['k']}'");
			alert_2(-1,'关注成功',"",3);
		}
		public function pingbi(){
			if(empty($_SESSION['user_id']))
				exit;
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_post set pingbi = '{$_GET['k']}' where id='{$_GET['id']}'");
			alert_2(-1,'操作成功',"",3);
		}
		public function post_update(){
			$this -> output();
		}

		public function thread_update_submit(){
			$content = isset($_POST['content']) ? $_POST['content'] : '';
			if(empty($_POST['title']))
				alert_2(1,'请输入标题','',3);
			if(empty($content))
				alert_2(1,'请输入帖子内容','',3);
			if(empty($_POST['t_id']))
				alert_2(1,'请选择帖子','',3);
			if(empty($_POST['s_id']))
				alert_2(1,'请选择版块','',3);
			if(empty($_SESSION['user_id']))
				alert_2(1,'请先登陆','',3);
			$pdo = get_pdo();
			$db_pre = DB_PRE;
			$sql = <<<SQL
update {$db_pre}z_bbs_thread 
	set
		title = '{$_POST['title']}', 
		content = '{$content}', 
		s_id = '{$_POST['s_id']}', 
		f_id = '{$_POST['f_id']}'
	where id='{$_POST['t_id']}'
SQL;

			$row = $pdo -> sql($sql);
			if($row===false)
				alert_2(1,'网络繁忙 修改失败','',3);
			alert_2(0,'修改成功',"bbs.php?h=index&c=post_content&k={$_POST['t_id']}",3);
		
		}
		public function post_update2(){
			$this -> output();
		}
		public function post_update_submit(){
			$content = isset($_POST['content']) ? $_POST['content'] : '';
			if(empty($content))
				alert_2(1,'请输入回帖内容','',3);
			if(empty($_POST['id']))
				alert_2(1,'请选择帖子','',3);
			if(empty($_SESSION['user_id']))
				alert_2(1,'请先登陆','',3);
			$pdo = get_pdo();
			$db_pre = DB_PRE;
			$sql = <<<SQL
update {$db_pre}z_bbs_post 
	set
		content = '{$content}'
	where id='{$_POST['id']}'
SQL;

			$row = $pdo -> sql($sql);
			if($row===false)
				alert_2(1,'网络繁忙 修改失败','',3);
			alert_2(0,'修改成功',"{$_POST['url']}",3);
		}





		public function run(){
			if(!isset($_SESSION)){
				session_start();
			}
		}

	}
?>