<?php
define('YUKEY', true);
require(str_replace('sicms','',dirname(__FILE__)) . '/includes/init.php');
check_login();
require(ROOT_PATH . 'includes/lib_projects.php');
$active=!empty($_GET['active']) ? intval($_GET['active']) : 1;
if($act=='ready')
{
	$total=count_item('','','projects',''); //总记录条数
	$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('pre',$pre);
	$smarty->assign('list_pro',get_projects('','',$start_num,$page_num,'',''));
	$smarty->assign('all_page',$allpage);
	$smarty->assign('all_pages',listpage($allpage));
	$smarty->assign('now_page',$current_page);
	$smarty->display('projects.dwt');
}
elseif($act=='mod_status')
{
	check_rank();
    $id=!empty($_POST['id']) ? $_POST['id'] : '';
	$status=!empty($_POST['status']) ? $_POST['status'] : '';
	$tid=!empty($_POST['tid']) ? $_POST['tid'] : '';
	$sql="UPDATE " .$GLOBALS['prefix']->table('projects'). " SET". " tbStatus='$status' WHERE tbSN='$id'";
		if($GLOBALS['db']->query($sql))
		{
		      $pro=get_row('',"tbSN,tbPONumber,tbStatus","tbSN",$id,"projects");
			  if($pro['tbStatus']=='Cancelled'){
			     $r_status='C'; $p_status='On Going';
			  }elseif($pro['tbStatus']=='On Going'){
   			     $r_status='0'; $p_status='Cancelled';
			  }
		   	  $sql="UPDATE " .$GLOBALS['prefix']->table('reports'). " SET". " tbReport='$r_status' WHERE tbPONumber='". $pro['tbPONumber']. "'";
  $str='<a href="#" onclick="mod_status(\''.$pro['tbSN'].'\',\''.$p_status.'\',\''.$tid.'\');"><font color="red">'.$pro['tbStatus'].'</font></a>';
			  if($GLOBALS['db']->query($sql)) echo json_encode($str);
		}
}
?>