<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_workdate mobile $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
if ($do == 'list') {
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."workdate where uid='".$_USER->id."' order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."workdate where uid='".$_USER->id."' ORDER BY id desc LIMIT 0,50";
	$result = $db->fetch_all($sql);
	include_once('template/workdate.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."workdate  WHERE id = '".$id."'");
	}
	include_once('template/workdate_view.php');
}elseif ($do == 'add') {
	if($_POST['view']!=''){
		$id = getGP('id','P','int');
		if($id!=''){
			$otype=1;
			$workdate = mob_date_post(getGP('workdate','P','array'));
			$startdate = getGP('startdate1','P').":".getGP('startdate2','P')."";
			$contents = check_str(getGP('content','P'));
			$workdate = array(
				'otype' => $otype,
				'workdate' => $workdate,
				'startdate' => $startdate,
				'content' => $contents
			);
			update_db('workdate',$workdate, array('id' => $id));
			$content='';
			$content=serialize($workdate);
			$title='编辑日程信息';
			get_logadd($id,$content,$title,10,$_USER->id);
			
		}else{
			$otype=1;
			$workdate =  mob_date_post(getGP('workdate','P','array'));
			$startdate = getGP('startdate1','P').":".getGP('startdate2','P')."";
			$contents = check_str(getGP('content','P'));
			$date = get_date('Y-m-d H:i:s',PHP_TIME);
			$uid=$_USER->id;
			$workdate = array(
				'otype' => $otype,
				'workdate' => $workdate,
				'startdate' => $startdate,
				'content' => $contents,
				'date' => $date,
				'uid' => $uid
			);
			insert_db('workdate',$workdate);
			$id=$db->insert_id();
			$content=serialize($workdate);
			$title='新建日程信息';
			get_logadd($id,$content,$title,10,$_USER->id);
		}
		$formlist='true';
	}else{
		$id = getGP('id','G','int');
		$type = getGP('type','G','int');
		if($id!=''){
			$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE."workdate  WHERE id = '".$id."'");
			$_title['name']='编辑';
			$workdate=explode('-',$row['workdate']); 
			$y=$workdate[0];
			$m=$workdate[1];
			$d=$workdate[2];
		}else{ 
			$_title['name']='新增';
			$row['sex']='男';
			$y=get_date('Y',PHP_TIME);
			$m=get_date('m',PHP_TIME);
			$d=get_date('d',PHP_TIME);
		}
		
	}
	include_once('template/workdate_add.php');

}
?>