<?php
require_once('inc/logincheck.php');
CommTool::checkIncludeByAdminPhp();
if('modify' == $action)
{
  if(strstr($useremail, '@') && strstr($useremail, '.'))
  { 
    if(!eregi("^([_a-z0-9]+([._a-z0-9-]+)*)@([a-z0-9]{2,}(.[a-z0-9-]{2,})*.[a-z]{2,3})$", $useremail))
    { 
      promptMessage("javascript:history.go(-1)", $promptUserCorrectFormatEmail, $configJumpTime);
      exit;
    } 
  }
  else
  {
    promptMessage("javascript:history.go(-1)", $promptUserEmptyEmail, $configJumpTime);
    exit;
  } 
  $usermodifyip = getIP();        
  if(!empty($userpassword))
  {
    if(5 > strlen($userpassword) || 15 < strlen($userpassword))
    {
      promptMessage("javascript:history.go(-1)", $promptEditCorrectAdminPasswordFormat, $configJumpTime);
      exit;
    }
    if($userpassword != $userpasswordcheck)
    {
      promptMessage("javascript:history.go(-1)", $promptAdminTheTwoPasswordNotAgree, $configJumpTime);
      exit;
    }
    
    $userpassword = CommTool::encryptMd5($userpassword, $configEncryptTimes);
    $strSql = "update {$configTableHead}user set userpassword='{$userpassword}', nickname='{$nickname}', usersex='{$usersex}', 
         usertel='{$usertel}', useremail='{$useremail}', userqq='{$userqq}', usermsn='{$usermsn}', userali='{$userali}', remark='{$remark}', usermodifytime='{$nowTime}', usermodifyip='{$usermodifyip}' where id={$id};";
  }
  else
  {
    $strSql = "update {$configTableHead}user set  nickname='{$nickname}', usersex='{$usersex}', 
         usertel='{$usertel}', useremail='{$useremail}', userqq='{$userqq}', usermsn='{$usermsn}', userali='{$userali}', remark='{$remark}', usermodifytime='{$nowTime}', usermodifyip='{$usermodifyip}' where id={$id};";
  }
  
  if($dbInstance->query($strSql))
  {
    promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=user&menu=user_action", $promptEditDataSuccess, $configJumpTime);
    exit;    
  }
  else
  {
    promptMessage("javascript:history.go(-1)", $promptEditDataFail, $configJumpTime);
    exit;    
  }
}
else if('delete' == $action)
{
  if(empty($id) || ereg("/^d+$/", $id))
  {
    promptMessage("javascript:history.go(-1)", $promptDeleteEmptyId, $configJumpTime);
    exit;
  }
  else
  {
    if(is_array($id))
    {
      foreach($id as $key=>$value)
      {
        $sql = "delete from {$configTableHead}user where id='{$value}'";
        if(!$flag = $dbInstance->query($sql))
        {
          promptMessage("javascript:history.go(-1)", $prompBatchDeleteFail, $configJumpTime);
          exit;
        }  
      }
      promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=user&menu=user_action", $prompBatchDeleteSuccess, $configJumpTime);
      exit;    
    }
    else
    {
      $sql = "delete from {$configTableHead}user where id='{$id}'";
      if($dbInstance->query($sql))
      {
        promptMessage("index.php?lang={$kuWebsiteEditVersionLanguage}&path=user&menu=user_action", $promptDeleteDataSuccess, $configJumpTime);
        exit;
      }
      else
      {
        promptMessage("javascript:history.go(-1)", $promptDeleteDataFail, $configJumpTime);
        exit;
      }
    }  
  }  
}
$sql = "select count(*) as amount from {$configTableHead}user";  
$result = $dbInstance->query($sql);
$row = $dbInstance->fetchArray($result);
$totalNumber = $row['amount'];                                                                  //总记录数
$maxNum = $adminPagingPageNumber;                                                                //每页显示的记录数 
!empty($page) ? ($page = intval($page)) : $page =1;
$actionDisplayNumber = $adminPagingActionsDisplayNumber;                                         //活动显示页数 
$type = $adminPagingType;                                                                       //分页样式0-5 
$isAlwaysShowFirstOrLast = $adminPagingIsAlwaysShowFirstOrLast;                                  //是否绍终显示第一页和最后一页
$startNum = ($page - 1) * $maxNum;                                                              //记录查询起始
$sql = "select * from {$configTableHead}user order by id desc limit $startNum, $maxNum";     
                                                        
$result = $dbInstance->query($sql);
while($arr = $dbInstance->fetchArray($result)) 
{
  $userList[] = $arr;
}
include_once template('user_manage.html');
?>