<?php
/*
	[Office 515158] (C) 2009-2012 天生创想 Inc.
	$Id: mod_conference 1209087 2012-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='%$name%' ";
		$url .= '&name='.rawurlencode($name);
	}
	//时间
	$venddate = getGP('venddate','G');
	$vstartdate = getGP('vstartdate','G');
	if ($vstartdate!='' && $venddate!='') {
		$wheresql .= " AND (date>='".$vstartdate."' and date<='".$venddate."')";
		$url .= '&vstartdate='.$vstartdate.'&venddate='.$venddate;
	}
	//if(!is_superadmin() && $ischeck=='' && $ui==''){
	//	$wheresql .= " and uid='".$_USER->id."'";
	//}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE.DB_JT."attendance WHERE 1 $wheresql ORDER BY id desc");
    $sql = "SELECT * FROM ".DB_TABLEPRE.DB_JT."attendance WHERE 1 $wheresql ORDER BY id desc LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
	include_once('template/registrationlist.php');

}elseif ($do == 'update') {
	$idarr = getGP('id','P','array');
	foreach ($idarr as $id) {
		$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."attendance 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 == 'views') {
		$id = getGP('id','G','int');
		if($id!=''){
			$row = $db->fetch_one_array("SELECT * FROM ".DB_TABLEPRE.DB_JT."attendance  WHERE id = '$id'");
		}
		include_once('template/attendanceviews.php');
}elseif ($do == 'excel') {
	$datename="attendance_".get_date('YmdHis',PHP_TIME);
	$outputFileName = 'data/excel/'.$datename.'.xls';
		$content = array();
		$archive=array("姓名","考勤时间","时长","状态","备注","位置","日期");
		$content[] = $archive;
		$wheresql = '';
		if ($name = getGP('name','P')) {
			$wheresql .= " AND name='%$name%' ";
		}
		//时间
		$venddate = getGP('venddate','P');
		$vstartdate = getGP('vstartdate','P');
		if ($vstartdate!='' && $venddate!='') {
			$wheresql .= " AND (date>='".$vstartdate."' and date<='".$venddate."')";
		}
		$sql = "SELECT * FROM ".DB_TABLEPRE.DB_JT."attendance WHERE 1 $wheresql ORDER BY id desc";
		$result = $db->query($sql);
		while ($row = $db->fetch_array($result)) {
			$sdate=explode(' ',$row['sdate']);
			$edate=explode(' ',$row['edate']);
			$late='';
			if($row['latedate']!=0){
				$late.= '迟到：'.attendance_date($row['latedate']);
			}
			if($row['ledate']!=0){
				$late.= '<br>早退：'.attendance_date($row['ledate']);
			}
			$type='';
			if($row['latedate']!=0){
				$type.= '<font color=red>迟到</font>';
			}
			if($row['ledate']!=0){
				$type.= '/<font color=red>早退</font>';
			}
			if($row['ledate']==0 && $row['latedate']==0){
				$type.= '正常';
			}
			$archive = array(
				"".$row['name']."",
				"".substr($sdate[1], 0, -3)."至".substr($edate[1], 0, -3)."",
				"".$late."",
				"".$type."",
				"".$row['note']."",
				"".$row['addr']."",
				"".str_replace("-",".",$row[date]).""
			);
			$content[] = $archive;
		}
	$excel = new ExcelWriter($outputFileName);
	if($excel==false) 
		echo $excel->error; 
	foreach($content as $v){
		$excel->writeLine($v);
	}
	$excel->sendfile($outputFileName);
}


?>