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

	switch($action)
	{
		case 'manage':
			if(isset($do_submit))
			{
				switch($job)
				{
					case 'settop':
						if($linkobj->linkset(array('istop'=>1),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unsettop':
						if($linkobj->linkset(array('istop'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'pass':
						if($linkobj->linkset(array('status'=>1),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'unpass':
						if($linkobj->linkset(array('status'=>0),$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
					case 'delete':
						if($linkobj->link_delete($id,0))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
						break 2;
				}
			}
			else
			{
				$userid=isset($userid)?intval($userid):0;
				$status=isset($status)?intval($status):-1;
				$starttime=isset($info['starttime'])?strtotime($info['starttime']):'';
				$endtime=isset($info['endtime'])?strtotime($info['endtime']):'';
				$k=isset($k)?htmlspecialchars($k):'';

				$result=$linkobj->linklist($status,$starttime,$endtime,$k);
				include admin_tlp('manage',$mod);
			}
			break;
		case 'add':
			if(isset($do_submit))
			{
				$info['moduleid']=$moduleid;
				$_image=imageupload('image_file',array('png','gif','jpg','jpeg'));

				if($_image)
				{
					$info['image']=$_image;
				}
				if($linkobj->admin_link_add($info))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			include admin_tlp('link_add',$mod);
			break;
		case 'edit':
			$id=intval($id);
			if(isset($do_submit))
			{
				$info['moduleid']=$moduleid;
				$_image=imageupload('image_file',array('png','gif','jpg','jpeg'));

				if($_image)
				{
					$info['image']=$_image;
				}
				if($linkobj->admin_link_edit($info,$id))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			
			$info=$linkobj->getlink($id);
			include admin_tlp('link_edit',$mod);
			break;
		case 'type':
			if(isset($job))
			{
				if($job=='edit')
				{
					if(isset($do_submit))
					{
						$info['moduleid']=$moduleid;
						if($linkobj->type_edit($info,$id))
						{
							admin_success($adminlang['manage_success']);
						}
						else
						{
							admin_error($adminlang['manage_error']);
						}
					}
					else
					{
						$info=$linkobj->typeinfo($id);
						include admin_tlp('type_edit',$mod);
					}
				}
				else if($job=='delete')
				{
					if($linkobj->type_delete($id))
					{
						admin_success($adminlang['manage_success']);
					}
					else
					{
						admin_error($adminlang['manage_error']);
					}
				}
			}
			else
			{
				$result=$linkobj->typelist();
				include admin_tlp('type',$mod);
			}
			break;
		case 'type_add':
			if(isset($do_submit))
			{
				$info['moduleid']=$moduleid;
				if($linkobj->type_add($info))
				{
					admin_success($adminlang['manage_success']);
				}
				else
				{
					admin_error($adminlang['manage_error']);
				}
			}
			include admin_tlp('type_add',$mod);
			break;
	}
?>