<?php
	!defined('IN_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'manage':trim($action);
	$moduleid=$moduleobj->getmoduleid($mod);
	$settings=$configobj->getconfig($_SESSION['siteid'],$moduleid);

	$settings['duoshuo_code']=$configobj->getconfigcode($settings['duoshuo_code']);
	$settings['membergrade_count']=formatarray($settings['membergrade_count']);
	switch($action)
	{
		case 'config':		
			if(isset($do_submit))
			{
				$setting['commentpass_membergrade']=implode(',',$setting['commentpass_membergrade']);
				$setting['comment_membergrade']=implode(',',$setting['comment_membergrade']);
				$setting['membergrade_count']=enformatarray($setting['membergrade_count']);

				/// 站外JS
				$setting['duoshuo_code']=$configobj->setconfigcode($setting['duoshuo_code']);

				if($configobj->setconfig($setting,$moduleid))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			$memgrade=$configobj->getmembergrade();
			include admin_tlp('config',$mod);
			break;
		case 'manage':
			if(isset($do_submit))
			{
				switch($job)
				{
					case 'settop':
						if($conobj->baseset(array('istop'=>TIME+3600*max(intval($LA['top_expire']),24)),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unsettop':
						if($conobj->baseset(array('istop'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'settopic':
						if($conobj->baseset(array('istopic'=>TIME+3600*max(intval($LA['top_expire']),24)),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unsettopic':
						if($conobj->baseset(array('istopic'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'setfocus':
						if($conobj->baseset(array('isfocus'=>TIME+3600*max(intval($LA['top_expire']),24)),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unsetfocus':
						if($conobj->baseset(array('isfocus'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'pass':
						if($conobj->baseset(array('status'=>1),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unpass':
						if($conobj->baseset(array('status'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'setshow':
						if($conobj->baseset(array('ishidden'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'sethide':
						if($conobj->baseset(array('ishidden'=>1),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'delete':
						if($conobj->baseset(array('isdeleted'=>1),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'move':
						if(!intval($movetotypeid))
						{
							admin_error($adminlang['manage_error']);
						}

						if($conobj->move(intval($movetotypeid),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
				}
			}
			else
			{
				$typeid=isset($_GET['typeid'])?intval($_GET['typeid']):0;
				$status=isset($status)?intval($status):-1;
				$ishidden=isset($ishidden)?intval($ishidden):-1;
				$userid=isset($userid)?intval($userid):0;
				$starttime=isset($info['starttime'])?strtotime($info['starttime']):'';
				$endtime=isset($info['endtime'])?strtotime($info['endtime']):'';
				$k=isset($k)?htmlspecialchars($k):'';

				$result=$conobj->datalist($moduleid,$status,$ishidden,$userid,$starttime,$endtime,$k,$typeid);
				include admin_tlp('manage',$mod);
			}
			break;
		case 'add':
			if(isset($do_submit))
			{
				if(!$info['typeid'])
				{
					admin_error('请选择所属分类!');
				}
				$info['moduleid']=$moduleid;
				$info['islink']=preg_match('/http([s]?):\/\/(.+)/i',$info['url'])?1:0;
				$typeinfo=$conobj->typeinfo($info['typeid']);
				if($conobj->admin_add($info,$typeinfo['modelid'],($typeinfo['modelid']+1)))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			if(!$typeid)
			{
				$typeid=$conobj->gettypeid($moduleid);
			}
			if(!$typeid)
			{
				admin_error('暂无任何信息分类，请先添加信息分类!',ADMIN_FILE.'?mod='.$mod.'&file='.$mod.'&action=type_add');
			}
			$typeinfo=$conobj->typeinfo($typeid);
			$formlist=$formobj->get($typeinfo['modelid']);
			$moreformlist=$formobj->get(($typeinfo['modelid']+1));
			include admin_tlp('add',$mod);
			break;
		case 'edit':
			$contentid=intval($contentid);
			if(isset($do_submit))
			{
				if(!$info['typeid'])
				{
					admin_error('请选择所属分类!');
				}
				$info['moduleid']=$moduleid;
				$info['islink']=preg_match('/http([s]?):\/\/(.+)/i',$info['url'])?1:0;

				$typeinfo=$conobj->typeinfo($info['typeid']);
				if($conobj->admin_edit($info,$contentid,$typeinfo['modelid'],($typeinfo['modelid']+1)))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			
			$coninfo=$conobj->get($contentid);
			$typeinfo=$conobj->typeinfo($coninfo['typeid']);
			$modelinfo=$modelobj->info(intval($coninfo['modelid']));
			$hash_table=LA_PRE.get_hash_table($modelinfo['tbname'].'_data',$contentid,$modelobj->subformcount2(intval($coninfo['modelid'])));
			$baseinfo=$db->fetch_one("SELECT * FROM `".LA_PRE.$modelinfo['tbname']."` WHERE `".LA_PRE.$modelinfo['tbname']."`.`id`=$contentid");
			$moreinfo=$db->fetch_one("SELECT * FROM `$hash_table` WHERE `$hash_table`.`mid`=$contentid");
			$info=array_merge($coninfo,$baseinfo,$moreinfo);
			$info['istopic']=$info['istopic']>TIME?$info['istopic']:0;
			$info['istop']=$info['istop']>TIME?$info['istop']:0;
			$info['isfocus']=$info['isfocus']>TIME?$info['isfocus']:0;
			$formlist=$formobj->get($typeinfo['modelid'],$info);
			$moreformlist=$formobj->get(($typeinfo['modelid']+1),$info);
			include admin_tlp('edit',$mod);
			break;
		case 'type':
			if(isset($job))
			{
				if($job=='edit')
				{
					if(isset($do_submit))
					{
						$info['moduleid']=$moduleid;
						if($conobj->type_edit($info,$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
					}
					else
					{
						$typelist=$modelobj->modulemodel($mod);

						$info=$conobj->typeinfo($id);
						include admin_tlp('type_edit',$mod);
					}
				}
				else if($job=='delete')
				{
					if($conobj->type_delete($id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$result=$conobj->typelist($moduleid,$typeid);
				include admin_tlp('type',$mod);
			}
			break;
		case 'type_add':
			if(isset($do_submit))
			{
				$info['moduleid']=$moduleid;
				if($conobj->type_add($info))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			$typelist=$modelobj->modulemodel($mod);
			include admin_tlp('type_add',$mod);
			break;
		case 'recycle':
			if(isset($do_submit))
			{
				if($job=='sdelete')
				{
					if($conobj->sdelete($id,0))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
				else if($job=='restore')
				{
					if($conobj->baseset(array('isdeleted'=>0),$id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$userid=isset($userid)?intval($userid):0;
				$starttime=isset($info['starttime'])?strtotime($info['starttime']):'';
				$endtime=isset($info['endtime'])?strtotime($info['endtime']):'';
				$k=isset($k)?htmlspecialchars($k):'';

				$result=$conobj->recyclelist($moduleid,$userid,$starttime,$endtime,$k);
				include admin_tlp('recycle',$mod);
			}
			break;
			
			
		case 'comment':
			if(isset($do_submit))
			{
				if($job=='delete')
				{
					if($conobj->comment_delete($id,0))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
				else if($job=='setpass')
				{
					if($conobj->comment_set(array('status'=>1),$id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
				else if($job=='setunpass')
				{
					if($conobj->comment_set(array('status'=>0),$id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$contentid=isset($contentid)?intval($contentid):0;
				$status=isset($status)?intval($status):-1;
				$userid=isset($userid)?intval($userid):0;
				$starttime=isset($info['starttime'])?strtotime($info['starttime']):'';
				$endtime=isset($info['endtime'])?strtotime($info['endtime']):'';
				$k=isset($k)?htmlspecialchars($k):'';

				$result=$conobj->commentlist($moduleid,$contentid,$status,$userid,$starttime,$endtime,$k);
				include admin_tlp('comment',$mod);
			}
			break;
				case 'liuyan':
			if(isset($do_submit))
			{
				$res=$conobj->liuyan();
				include admin_tlp('liuyan',$mod);
			}
			else
			{
			
				$res=$conobj->liuyan();
				include admin_tlp('liuyan',$mod);
			}
			break;

	}
?>