<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_duty mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
if ($do == 'list') {
	$type=getGP('type','G');
	if($type==''){
		$type=1;
	}
	if($type!=''){
		$wheresql .= " where dkey='".$type."' and (user like'%".get_realname($_USER->id).",%' or uid='".$_USER->id."')";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."duty ".$wheresql." order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."duty ".$wheresql." ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/duty.php');

}elseif ($do == 'views') {
	$id = getGP('id','G','int');
	$type = getGP('type','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."duty  WHERE id = '".$id."'");
	}
	include_once('template/duty_view.php');
}elseif ($do == 'user_views') {
	$dutyid = getGP('dutyid','G','int');
	$id = getGP('id','G','int');
	$type = getGP('type','G','int');
	if($id!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."duty_user  WHERE id = '".$id."' and dutyid = '".$dutyid."'");
	}
	include_once('template/user_views.php');
}elseif ($do == 'log') {
	if($_POST['view']!=''){
			$did = check_str(getGP('did','P'));
			$duid = check_str(getGP('duid','P'));
			$progress = check_str(getGP('progress','P'));
			$appendix = check_str(getGP('appendix','P'));
			$note = check_str(getGP('note','P'));
			$content = getGP('content','P');
			$uid=$_USER->id;
			$date = get_date('Y-m-d H:i:s',PHP_TIME);
			$duty_log = array(
				'dutyid' => $did,
				'content' => $content,
				'progress' => $progress,
				'appendix' => $appendix,
				'note' => $note,
				'date' => $date,
				'uid' => $uid,
				'duid' => $duid
			);
			insert_db('duty_log',$duty_log);
			$id=$db->insert_id();
			$content=serialize($duty_log);
			$title='新建任务进度信息';
			get_logadd($id,$content,$title,33,$_USER->id);
			$formlist='true';
		//show_msg('任务进度信息操作成功！', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'&did='.$did.'');
	}
	$dutyid = getGP('dutyid','G','int');
	if($dutyid==''){
		$dutyid=$did;
	}
	$type = getGP('type','G','int');
	if($dutyid!=''){
		$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."duty_user  WHERE user = '".$_USER->id."' and dutyid = '".$dutyid."'");
	}
	include_once('template/duty_log.php');
	
}
?>