<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');

get_key("office_communication");
empty($do) && $do = 'list';
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 ($keyword = getGP('keyword','G')) {
		$wheresql .= " AND (b.name LIKE '%$keyword%' OR a.username LIKE '%$keyword%')";
		$url .= '&keyword='.rawurlencode($keyword);
	}
	if ($department = getGP('department','G','int')) {
		$wheresql .= " AND a.departmentid LIKE '%,$department,%'";
		$url .= '&department='.$department;	
	}
	if ($usergroup = getGP('usergroup','G','int')) {
		$wheresql .= " AND a.groupid = $usergroup";
		$url .= '&usergroup='.$usergroup;	
	}
	$num = $db->result("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."user a,".DB_TABLEPRE."user_view b WHERE a.id=b.uid $wheresql and a.jituanid='".$_USER->jituanid."' ");
     $sql = "SELECT * FROM ".DB_TABLEPRE."user a,".DB_TABLEPRE."user_view b WHERE a.id=b.uid $wheresql and a.jituanid='".$_USER->jituanid."'  ORDER BY a.id ASC LIMIT $offset, $pagesize";
	$result = $db->fetch_all($sql);
	include_once('template/user.php');
} 

//读取上级部门
function get_father($fid)
{
    global $db;
	global $_USER;
	$query = $db->query("SELECT name FROM ".DB_TABLEPRE."department where id='".$fid."' and jituanid='".$_USER->jituanid."'  ORDER BY id desc limit 0,1");
	while ($rowuser = $db->fetch_array($query)) {
	$html .= $rowuser[name];
	}
	return $html;
}
//汇总下级部门
function get_father_sum($fid)
{
    global $db;
	global $_USER;
	$query = $db->query("SELECT COUNT(*) AS num FROM ".DB_TABLEPRE."department where father='$fid' and jituanid='".$_USER->jituanid."'");
	while ($rowuser = $db->fetch_array($query)) {
	$html .= $rowuser[num];
	}
	return $html;
}

?>