<?php
/*
	[Office 515158] (C) 2009-2014 天生创想 Inc.
	$Id: mod_blog 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=='1'){
		$wheresql = " where type='1' and  uid='".$_USER->id."'";
	}else{
		$wheresql = " where type='2' and (user='全部人员' or user like'%".get_realname($_USER->id)."%' or uid = ".$_USER->id.")";
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."blog ".$wheresql." order by id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE."blog ".$wheresql." ORDER BY id desc LIMIT 0,100";
	$result = $db->fetch_all($sql);
	include_once('template/blog.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."blog  WHERE id = '".$id."'");
	}
	include_once('template/blog_view.php');
}elseif ($do == 'add') {
	if($_POST['view']!=''){
		$id = getGP('id','P','int');
		$blog=array();
		$blog['title'] = check_str(getGP('title','P'));
		$blog['type'] = trim(getGP('type','P'));
		$blog['date'] = mob_date_post(getGP('workdate','P','array'));
		$blog['content'] = getGP('content','P');
		if($id==''){
			$blog['uid']=$_USER->id;
		}
		$blog['user'] = mob_select_post(getGP('user','P','array'));
		if($id!=''){
			update_db('blog',$blog, array('id' => $id));
			$content='';
			$content=serialize($blog);
			$title='修改工作日志信息';
			get_logadd($id,$content,$title,11,$_USER->id);
		}else{
			insert_db('blog',$blog);
			$id=$db->insert_id();
			$content=serialize($blog);
			$title='新建日志信息';
			get_logadd($id,$content,$title,11,$_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."blog  WHERE id = '".$id."'");
			$_title['name']='编辑';
			$workdate=explode('-',$row['date']); 
			$y=$workdate[0];
			$m=$workdate[1];
			$d=$workdate[2];
		}else{ 
			$row['title']=get_realname($_USER->id).'['.get_depauseridname($_USER->id).']'.' '.get_date('Y-m-d',PHP_TIME).' 工作日志';
			$_title['name']='新增';
			$y=get_date('Y',PHP_TIME);
			$m=get_date('m',PHP_TIME);
			$d=get_date('d',PHP_TIME);
			$row['type']=2;
		}
		
	}
	include_once('template/blog_add.php');

}
?>