<?php
require_once '../../Config.php';
header ( "Content-Type: text/html; charset=utf-8" );
if (intval ( BLL_Admin::isLogin () ) === 0) {
	header ( 'Location:../index.html' );
	die ();
}
new BackUSL_Controller ( $_REQUEST ['action'] );

/**
 * 链接控制器
 *
 * @author Wzb
 *        
 */
class BackUSL_Controller {
	/**
	 * 构造函数
	 *
	 * @param string $action 处理方法名
	 */
	public function __construct($action) {
		if (! method_exists ( $this, $action )) {
			die ( "该方法不存在" );
		}
		switch ($action) {
			case "addsort" : // 新增类别
			case "editsort" : // 修改类别
			case "sortMove" : // 移动类别
			case "delSort" : // 删除类别
			
			case "addLink" : // 新增链接
			case "editLink" : // 修改链接
			case "linkMove" : // 移动链接
			case "deleteLink" : // 删除链接
				break;
			default :
				die ( "该方法错误" );
				break;
		}
		$this->{$action} ();
	}
	
	/**
	 * 添加类别
	 */
	private function addsort() {
		if (BLL_LinkSort::add ( $_POST ) > 0) {
			echo COM_OftenJavaScript::alertGoToUrl ( "新增成功!!!", "LinkSort_List.php" );
		} else {
			echo COM_OftenJavaScript::alertGoBack ( "新增失败!!!" );
		}
	}
	
	/**
	 * 修改类别
	 */
	private function editsort() {
		if (BLL_LinkSort::edit ( $_POST ) > 0) {
			echo COM_OftenJavaScript::alertGoToUrl ( "修改成功!!!", "LinkSort_Edit.php?theId=" . $_POST ['theId'] );
		} else {
			echo COM_OftenJavaScript::alertGoBack ( "修改失败!!!" );
		}
	}
	
	/**
	 * 移动类别
	 */
	private function sortMove() {
		BLL_LinkSort::swapSerial ( $_GET ['idStr'] );
		echo COM_OftenJavaScript::parentRefurbish ();
	}
	
	/**
	 * 删除类别
	 */
	private function delSort() {
		if (BLL_LinkSort::delete ( $_GET ['theId'] )) {
			echo COM_OftenJavaScript::parentAlertRefurbishParent ( "删除成功!!!" );
		} else {
			echo COM_OftenJavaScript::parentAlert ( "删除失败!!!" );
		}
	}
	
	/**
	 * 添加链接
	 */
	private function addLink() {
		if (BLL_Link::add ( $_POST ) > 0) {
			echo COM_OftenJavaScript::alertGoToUrl ( "新增成功!!!", "Link_List.php?theId=" . $_POST ['theId'] );
		} else {
			echo COM_OftenJavaScript::alertGoBack ( "新增失败!!!" );
		}
	}
	
	/**
	 * 修改链接
	 */
	private function editLink() {
		if (BLL_Link::edit ( $_POST ) > 0) {
			echo COM_OftenJavaScript::alertGoToUrl ( "修改成功!!!", "Link_Edit.php?theId=" . $_POST ['theId'] );
		} else {
			echo COM_OftenJavaScript::alertGoBack ( "修改失败!!!" );
		}
	}
	
	/**
	 * 移动链接
	 */
	private function LinkMove() {
		BLL_Link::swapSerial ( $_GET ['idStr'] );
		echo COM_OftenJavaScript::parentRefurbish ();
	}
	
	/**
	 * 删除链接
	 */
	private function deleteLink() {
		$idList = $_GET ['theList'];
		if (BLL_Link::delete ( $idList )) {
			echo COM_OftenJavaScript::parentRefurbish ();
		} else {
			echo COM_OftenJavaScript::parentAlert ( "删除失败!!!" );
		}
	}
}
?>