<?php
function add_or_edit_article()
{
	global $global,$smarty;
	$art_id = post('art_id');
	$art_title = post('art_title');
	$art_cat_id = post('art_cat_id');
	$art_author = post('art_author');
	$att_url = post('file_path');
	$art_text = post('editor','loose');
	$art_keywords = post('art_keywords');
	$art_description = post('art_description');
	$art_add_time = time();
	if($art_cat_id == '')
	{
		$art_cat_id = 0;
	}
	$art_text = optimize($art_text);
	$art_description = cut_str($art_description,250);
	$obj = new article();
	$obj->set_value('art_title',$art_title);
	$obj->set_value('art_cat_id',$art_cat_id);
	$obj->set_value('art_author',$art_author);
	$obj->set_value('art_text',$art_text);
	$obj->set_value('art_keywords',$art_keywords);
	$obj->set_value('art_description',$art_description);
	$obj->set_value('art_add_time',$art_add_time);
	if($art_id != '')
	{
		$obj->set_where("art_id = $art_id");
		$obj->edit();
		$info_text = '修改文章成功';
	}else{
		$obj->set_value('art_lang',S_LANG);
		$obj->add();
		$info_text = '添加文章成功';
	}
	if(intval(get_varia('single_page_static')))
	{
		$page_id = $art_id;
		if($page_id == '')
		{
			$obj->set_where("art_add_time = $art_add_time");
			$one = $obj->get_one();
			if(count($one))
			{
				$page_id = $one['art_id'];
			}
		}
		if($page_id != '')
		{
			$domain = get_domain();
			$page_url = 'http://' . $domain . S_ROOT . url(array('channel'=>$global['channel'],'id'=>$page_id));
			$html = file_get_contents($page_url);
		}
	}
	$smarty->assign('info_text',$info_text);
	$smarty->assign('link_text','返回列表页');
	$smarty->assign('link_href',url(array('channel'=>$global['channel'],'mod'=>'sheet')));
}
function add_or_edit_cat()
{
	global $global,$smarty;
	$cat_id = post('cat_id');
	$cat_parent_id = post('cat_parent_id');
	$cat_name = post('cat_name');
	$obj = new cat_art();
	$obj->set_value('cat_parent_id',$cat_parent_id);
	$obj->set_value('cat_name',$cat_name);
	if($cat_id != '')
	{
		$obj->set_where("cat_id = $cat_id");
		$obj->edit();
		$info_text = '修改分类成功';
	}else{
		$obj->set_value('cat_lang',S_LANG);
		$obj->add();
		$info_text = '添加分类成功';
	}
	$smarty->assign('info_text',$info_text);
	$smarty->assign('link_text','返回列表页');
	$smarty->assign('link_href',url(array('channel'=>$global['channel'],'mod'=>'cat_list')));
}
function upload()
{
	$dir = post('dir');
	$file = post('file');
	$suffix = strtolower(get_file_name($file,'.'));
	if(strpos('jpg,gif,png,bmp,jpeg,rar,zip,pdf',$suffix) !== false)
	{
		move_uploaded_file($_FILES['file_path']['tmp_name'],$dir.$file);
		set_cookie('file',$dir.$file);
	}
}
//红头船
?>