<?php
/*
	[Office 515158] (C) 2009-2012 天生创想 Inc.
	$Id: mod_attendance_config 1209087 2017-01-08 08:58:28Z baiwei.jiang $
*/
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
empty($do) && $do = 'list';
get_key("registration_");
if ($do == 'list') {
	//列表信息 
	$wheresql = '';
	$page = max(1, getGP('page','G','int'));
	$pagesize = $_CONFIG->config_data('pagenum');
	$offset = ($page - 1) * $pagesize;
	$url = 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'';
	if ($name = getGP('name','G')) {
		$wheresql .= " AND name like'%$name%' ";
		$url .= '&name='.rawurlencode($name);
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE.DB_JT."attendance_config WHERE 1 $wheresql ORDER BY id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE.DB_JT."attendance_config WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
	include_once('template/attendance_config.php');

}elseif ($do == 'update') {
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
		$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."attendance_config WHERE id = '$id' ");
	}
	$content=serialize($idarr);
	$title='删除考勤配置内容';
	get_logadd($id,$content,$title,7,$_USER->id);
	show_msg('考勤配置信息删除成功！', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');

}elseif ($do == 'add') {
	if(getGP('view','P')!=''){
		$id = getGP('id','P','int');
		if($id!=''){
			$name = check_str(getGP('name','P'));
			$user = ','.check_str(getGP('userid','P')).',';
			$sdate = getGP('sdate','P');
			$edate = getGP('edate','P');
			$getlocation = getGP('getlocation','P');
			$type = 2;
			$attendance_config = array(
				'name' => $name,
				'user' => $user,
				'sdate' => $sdate,
				'getlocation' => $getlocation,
				'edate' => $edate
			);
			update_db(DB_JT.'attendance_config',$attendance_config, array('id' => $id));
			$content='';
			$content=serialize($attendance_config);
			$title='编辑考勤配置信息';
			get_logadd($id,$content,$title,7,$_USER->id);
			
		}else{
			$name = check_str(getGP('name','P'));
			$user =  ','.check_str(getGP('userid','P')).',';
			$sdate = getGP('sdate','P');
			$edate = getGP('edate','P');
			$type = 2;
			$getlocation = getGP('getlocation','P');
			$date = get_date('Y-m-d H:i:s',PHP_TIME);
			$attendance_config = array(
				'name' => $name,
				'user' => $user,
				'sdate' => $sdate,
				'edate' => $edate,
				'getlocation' => $getlocation,
				'type' => $type,
				'date' => $date
			);
			insert_db(DB_JT.'attendance_config',$attendance_config);
			$id=$db->insert_id();
			$content='';
			$content=serialize($attendance_config);
			$title='新增考勤配置信息';
			get_logadd($id,$content,$title,7,$_USER->id);
		}
		show_msg('考勤配置信息操作成功！', 'admin.php?ac='.$ac.'&fileurl='.$fileurl.'');
	}else{
		$id = getGP('id','G','int');
		if($id!=''){
			$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE.DB_JT."attendance_config  WHERE id = '$id'");
			$_title['name']='编辑';
		}else{ 
			$row['user']='0';
			$_title['name']='发布';
		}
		include_once('template/attendance_configadd.php');
		
	}
}
?>