<?php
define('THIS_SCRIPT', 'honor');
require_once 'global.php';
include_once $fsetting['manageurl'].'inc/page.class.php';
$lang = load_lang($lang, 'honor' );
$titlelink = array(
		0=>array('linktitle'=>$lang['title'],'linkurl'=>'honor.php')
);
$honorobj=new userinfo();
head(1,0,0,$titlelink);
$honorobj->userlogin();
LoadMain();
footer();
class userinfo{
	var $username;
	var $usergroupid;
	var $userclass;
	var $userid;
	var $action;
	var $usercurrhonor;
	function userinfo() {
		global $dv,$db,$userid;
		$sql=$db->query("select usergroupid,username,userhonor from {$dv}user where userid={$userid}");
		$result=$db->fetch_array($sql);
		$this->usergroupid=$result['usergroupid'];
		$this->username=$result['username'];
		$this->usercurrhonor=$result['userhonor'];
	}
	function disappearance_days($user_lastlogin) {//失踪天数	
		$disap_pearance=time()+getUserTimeZoneOffset();
		$disap_pearance=dateDiff('D',$user_lastlogin,$disap_pearance);
		return ($disap_pearance);
		exit;
	}
	function honorpiclist() {
		global $piclist,$lang;
		$piclist=array();
		if (is_dir($lang['honor.info2'])) {
			if ($handle = opendir($lang['honor.info2'])) {
				while (($file = readdir($handle)) !== false) {
					if($file=="." or $file==".."){
						continue;
					}
					else{
						$piclist[]=$file;
					}
				}
			}
		}
		closedir($dir_hand);
	}
	function honorlist() {
		global $dv,$db,$hlist;
		$hlist=array();
		$sql=$db->query("select id,honorname,honorpic,honorread from {$dv}honor_list");
		while ($arr=$db->fetch_array($sql)) {
			$hlist[]=$arr;
		}
	}
	function honordel() {
		global $dv,$db,$lang;
		$hid=$_GET['id'];
		if(!is_numeric($hid) or empty($hid)){
			showmsg($lang['honor.info3']);
			exit;
		}
		$db->query("delete from {$dv}honor_list where id={$hid}");
		showmsg($lang['honor.info5']);
		exit;
	}
	function honoruserlist() {
		global $dv,$db,$lang;
		global $page_size,$page,$total,$page_count,$offset,$p,$userlist;
		$userlist=array();
		$total=$db->scalar("select count(userid) from {$dv}user where userhonor!='' order by userid");
		$page_size=20;
		if ($page=="" or $page<1)
			$page=1;
		$page_count=ceil($total/$page_size);
		if ($page>$page_count)
			$page=$page_count;
		$offset=$page;
		if( $offset < 1 ) $offset = 1;
		$sql=$db->query("select username,userhonor from {$dv}user where userhonor!='' order by userid",array('absolutePage'=>$offset, 'pageSize'=>$page_size));
		while ($arr=$db->fetch_array($sql)) {
			$userlist[]=$arr;
		}		
	}
	function usergroup() {
		global $dv,$db,$usergrouplist;
		$usergrouplist=array();
		$sql=$db->query("select usergroupid,title,usertitle from {$dv}usergroups");
		while ($arr=$db->fetch_array($sql)) {
			$usergrouplist[]=$arr;
		}
	}
	function honortitle($h_pic) {
		global $dv,$db;
		$htitle=$db->scalar("select honorname from {$dv}honor_list where honorpic='{$h_pic}'");
		return $htitle;
	}
	function alluserhonor() {//颁发情况
		global $dv,$db,$allhonorlist;
		$allhonorlist=array();
		$sql=$db->query("select id,username,honorname,honorpic,issueuser,reason,honortime from {$dv}honor_user");
		while ($arr=$db->fetch_array($sql)) {
			$allhonorlist[]=$arr;
		}
	}
	function userlogin() {//用户登录;
		global $lang;
		$this->action='common';
	}
}
function LoadMain() {
	global $dv,$db,$lang,$action,$doaction,$honorobj,$piclist,$hlist,$userhonorlist,$usergrouplist,$searchuserlist;
	global $allhonorlist;
	global $page_size,$page,$total,$page_count,$offset,$p,$userlist;
	switch ($doaction) {
		case 'honormanager':
		case '':
			$honorobj->honorpiclist();
			$honorobj->honorlist();
			break;
		case 'del':
			$honorobj->honordel();
			break;
		case 'honorreadlist':
		case '':
			$honorobj->honorlist();
			break;
		case 'honoruser':
			$honorobj->honoruserlist();
			break;
		case 'honorsearch':
			$honorobj->usergroup();
			break;
		case 'honorlog':
			$honorobj->alluserhonor();
			break;

	}
require_once printout('honor');
}
?>