<?php
define('YUKEY', true);
require(str_replace('sicms','',dirname(__FILE__)) . '/includes/init.php');
check_login();
require(ROOT_PATH . 'includes/lib_manage.php');
$active=!empty($_GET['active']) ? intval($_GET['active']) : 5;
$smarty->assign('act',$act);//因为静态页有用到这个变量

if($act=='ready')
{
$total=manage_count('defects','','',''); //总记录条数
$page_num=20;  //每页显示的记录数
$allpage=ceil($total/$page_num); //总页数
$current_page=!empty($_GET['nowpage']) ? intval($_GET['nowpage']) : 1; //目前页数 
$start_num=$page_num*($current_page-1); //$start_num 起始笔数
$smarty->assign('active',$active);
$smarty->assign('isshow',$isshow);
$smarty->assign('pre',$pre);
$smarty->assign('list_defect',manage_list('defects',$start_num,$page_num,'tbTopical','','',''));
$smarty->assign('all_page',$allpage);
$smarty->assign('all_pages',listpage($allpage));
$smarty->assign('now_page',$current_page);
$smarty->display('defects.dwt');
}
elseif($act=='add')
{
check_rank();
$smarty->assign('active',$active);
$smarty->assign('isshow',$isshow);
$smarty->assign('pre',$pre);
$smarty->assign('one_defect',get_row('si',"*","tbSN",$id,"defects"));
$smarty->display('defects.dwt');
}
elseif($act=='delete')
{
check_rank();
	if($_SESSION['tbRank']>='80')
	{
		del_defect($id);
		$smarty->assign('active',$active);
		$smarty->assign('isshow',$isshow);
		$smarty->assign('pre',$pre);
		$smarty->display('defects.dwt');
	}
	else
	{
		$GLOBALS['err'] ->add($GLOBALS['_LANG']['del_defect']);
		$GLOBALS['err'] ->show();
	}
}
elseif($act=='edit')
{
$smarty->assign('id',$id);
$smarty->assign('active',$active);
$smarty->assign('isshow',$isshow);
$smarty->assign('pre',$pre);
$smarty->assign('one_defect',get_row('si',"*","tbSN",$id,"defects"));
$smarty->display('defects.dwt');
}
elseif($act=='update' || $act=='insert')
{
	$sql='';
	$tbSN=!empty($_POST['tbSN']) ? intval($_POST['tbSN']) : '';
	$tbCategory=!empty($_POST['tbCategory']) ? $_POST['tbCategory'] : '';
	$tbTopical=!empty($_POST['tbTopical']) ? $_POST['tbTopical'] : '';
	$tbDescript=!empty($_POST['tbDescript']) ? $_POST['tbDescript'] : '';
	if($act=='update' && $tbSN!='')
	{
		 $sql="UPDATE " .$GLOBALS['si']->table('defects'). " SET". " tbCategory='$tbCategory',tbTopical='$tbTopical',tbDescript='$tbDescript' WHERE tbSN='$tbSN'";
	}
	if($act=='insert')
	{
		 $sql="INSERT INTO " .$GLOBALS['si']->table('defects'). " (tbCategory,tbTopical,tbDescript) VALUES ('$tbCategory','$tbTopical','$tbDescript')";
	}

		 if($GLOBALS['db']->query($sql))
		 {
		   if($act=='update')ecs_header("Location:defects.php?act=edit&id=$tbSN&isshow=none");
		   if($act=='insert')ecs_header("Location:defects.php?isshow=none");
		 }
		 else
		 {
		 $GLOBALS['err'] ->add($GLOBALS['_LANG']['save_defects']);
		 $GLOBALS['err'] ->show();
		 }
}
?>