<?php

	class bbsConn extends Conn{
		public function index(){
			$this -> output();
		}
		public function top_update(){
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_thread set top ='{$_GET['k']}' where id='{$_GET['id']}'");
			alert(1,0,null,'修改成功');
		}
		public function art_delete(){
			$sql = 'delete from '.DB_PRE.'z_bbs_thread where id ';
			if(!empty($_GET['k'])){
				$sql .= "= '{$_GET['k']}'";
			}else{
				if(empty($_POST['all'])){
					alert(0,0,null,'请先选择要删除的文章',1);
				}else{
					sort($_POST['all']);
					$id = implode(',',$_POST['all']);
				$sql .= "in ({$id})";
				}
			}
			$pdo = get_pdo();
			$row = $pdo -> sql($sql);
			alert(1,0,'?h=bbs','删除成功');
		}
		public function s_fenlei(){
			$this->output();
		}
		public function s_fenlei_submit(){
			if(empty($_POST['name'])){
				alert(0,0,null,'分类名称不能为空',1);
			}
			$paixu = empty($_POST['paixu']) ? '0' : min(max(ceil($_POST['paixu']),0),60000);
			$pdo = get_pdo();
			if(!empty($_POST['id'])){
				$sql = 'update '.DB_PRE."z_bbs_section_class set name='{$_POST['name']}',paixu='{$paixu}' where id='{$_POST['id']}'";
				$row = $pdo -> sql($sql);
				if($row === false)
					alert(0,0,null,'修改失败',1);
				else
					alert(1,0,'?h=bbs','修改成功');

			}else{
				$sql = 'insert into '.DB_PRE."z_bbs_section_class(name,paixu)values('{$_POST['name']}','{$paixu}')";
				$row = $pdo -> sql($sql);
				if(empty($row))
					alert(0,0,null,'创建失败',1);
				else
					alert(1,0,'?h=bbs','创建成功');
			}
		}
		public function s_fenlei_d(){
			$pdo = get_pdo();
			$pdo -> sql('delete from '.DB_PRE."z_bbs_section_class where id='{$_GET['k']}'");
			alert(1,0,'?h=bbs','删除成功');
		}
		public function s_fenlei_xianshi(){
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_section_class set xianshi='{$_GET['k']}' where id='{$_GET['id']}'");
			alert(1,0,'?h=bbs','修改成功');
		}




		public function section(){
			$this->output();
		}
		public function section_submit(){
			if(empty($_POST['name'])){
				alert(0,0,null,'分类名称不能为空',1);
			}
			if(empty($_POST['sc_id']))
				alert(0,0,null,'请选择分类',1);
			$paixu = empty($_POST['paixu']) ? '0' : min(max(ceil($_POST['paixu']),0),60000);
			$pdo = get_pdo();
			if(!empty($_POST['id'])){
				$sql = 'update '.DB_PRE."z_bbs_section set name='{$_POST['name']}',paixu='{$paixu}',con='{$_POST['con']}',sc_id='{$_POST['sc_id']}' where id='{$_POST['id']}'";
				$row = $pdo -> sql($sql);
				if($row === false)
					alert(0,0,null,'修改失败',1);
				else
					alert(1,0,'?h=bbs','修改成功');

			}else{
				$sql = 'insert into '.DB_PRE."z_bbs_section(name,paixu,con,sc_id)values('{$_POST['name']}','{$paixu}','{$_POST['con']}','{$_POST['sc_id']}')";
				$row = $pdo -> sql($sql);
				if(empty($row))
					alert(0,0,null,'创建失败',1);
				else
					alert(1,0,'?h=bbs','创建成功');
			}
		}
		public function section_d(){
			$pdo = get_pdo();
			$pdo -> sql('delete from '.DB_PRE."z_bbs_section where id='{$_GET['k']}'");
			alert(1,0,'?h=bbs','删除成功');
		}
		public function s_bankuai_xianshi(){
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_section set xianshi='{$_GET['k']}' where id='{$_GET['id']}'");
			alert(1,0,'?h=bbs','修改成功');
		}




		public function fenlei(){
			$this->output();
		}
		public function fenlei_submit(){
			if(empty($_POST['name'])){
				alert(0,0,null,'分类名称不能为空',1);
			}
			if(empty($_POST['s_id'])){
				alert(0,0,null,'请选择所属版块',1);
			}
			$paixu = empty($_POST['paixu']) ? '0' : min(max(ceil($_POST['paixu']),0),60000);
			$pdo = get_pdo();
			if(!empty($_POST['id'])){
				$sql = 'update '.DB_PRE."z_bbs_post_class set name='{$_POST['name']}',paixu='{$paixu}',s_id='{$_POST['s_id']}' where id='{$_POST['id']}'";
				$row = $pdo -> sql($sql);
				if($row === false)
					alert(0,0,null,'修改失败',1);
				else
					alert(1,0,'?h=bbs','修改成功');

			}else{
				$sql = 'insert into '.DB_PRE."z_bbs_post_class(name,paixu,s_id)values('{$_POST['name']}','{$paixu}','{$_POST['s_id']}')";
				$row = $pdo -> sql($sql);
				if(empty($row))
					alert(0,0,null,'创建失败',1);
				else
					alert(1,0,'?h=bbs','创建成功');
			}
		}
		public function fenlei_d(){
			$pdo = get_pdo();
			$pdo -> sql('delete from '.DB_PRE."z_bbs_post_class where id='{$_GET['k']}'");
			alert(1,0,'?h=bbs','删除成功');
		}


		public function config_submit(){
			$pdo = get_pdo();
			$pdo -> sql('update '.DB_PRE."z_bbs_config set v='{$_POST['t_title']}' where k='hot_key'");
			alert(1,0,'?h=bbs','修改成功');
		}








	}
 

?>