<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class link_updateAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);

		global $conn;
		$link_id=$_POST['link_id'];
		if($link_id){
			$link=new model_Link();
			$link->setSubsection('WHERE link_id='.$link_id);
			$results=$link->doSelectOne();
		}

		$miceSession = new session();

		$user_id=$miceSession->get('userid');
		$orderid=$_POST['orderid'];
		$title=MiceFilterHtml($_POST['title']);
		$url=MiceFilterQuote($_POST['url']);
		$logo=MiceFilterQuote($_POST['logo']);
		$category_id=$_POST['category_id'];
		if($logo==''){
			$logo=0;
		}
		$summary=$_POST['summary'];

		if($title==""){
			$jsstring='Dialog.alert("链接名称不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($url==""){
			$jsstring='Dialog.alert("链接地址不能为空",function(){history.back(-1);});';
			MessageBox($jsstring);
			exit;
		}

		if($results)
		{
			$ins='内容已存在';
			$lid=$results->getLinkId();
			$link->setUserId($user_id);
			$link->setCategoryId($category_id);
			$link->setOrderid($orderid);
			$link->setTitle($title);
			$link->setUrl($url);
			$link->setLogo($logo);
			$link->setSummary($summary);
			$results=$link->doUpdate();
			if($results)
				$exeresult='更新成功';
			else
				$exeresult='更新失败';

		}else{
			$ins='内容已不存在';
			$link=new model_Link();
			$link->setUserId($user_id);
			$link->setCategoryId($category_id);
			$link->setOrderid($orderid);
			$link->setTitle($title);
			$link->setUrl($url);
			$link->setLogo($logo);
			$link->setSummary($summary);
			$results=$link->doInsert();
			if($results){
				$exeresult='插入成功';	
				$lid=$conn->Insert_ID();
			}else
				$exeresult='插入失败';
		}

		

		if($_POST['goon']==1){
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/link/edit";window.event.returnValue = false;},300,100,"继续添加链接");';
			MessageBox($jsstring);
		}else{
			$jsstring='Dialog.alert(\''.$exeresult.'\',function(){window.location.href="'.MICE_URL.'admin.php/link";window.event.returnValue = false;},300,100,"返回链接列表");';
			MessageBox($jsstring);
		}
		exit;
	}
}
?>