<?php namespace App\Controllers;
helper('util');

class UserManage extends BaseController
{
    /****************************************************
     *       用户管理页面
     /****************************************************/
     public function userManagePage(){
        $data = array();
        $username = $this->request->getGet("username");
        $token = $this->request->getGet("token");
        $page = (int)$this->request->getGet("page");
        if($page == 0){
          $page = 1;
        }
        $perPage = (int)$this->request->getGet("perPage");
        if($perPage == 0){
          $perPage = 20;
        }

        $item = array();
        $item["page"] = $page;
        $item["perPage"] = $perPage; 
        
        if($username == "" || $token == ""){
          $data["userInfo"] = [];
        }else{
          $signModel = new \App\Models\SignModel();
          $userInfo = $signModel->getItemByUsername($username);
          $userManageModel = new \App\Models\UserManageModel();
          $users = $userManageModel->getUsersByPage($item);
          $totalNums = $userManageModel->getTatalUserNum()[0]["total"];
          $orgManageModel = new \App\Models\OrgManageModel();
          $orgSections = $orgManageModel->getAllOrgSection();
          if($userInfo[0]["token"] == $token){
            $data["userInfo"] = $userInfo[0];
            $data["users"] = $users;
            $data["orgSections"] = $orgSections;
            $data["notification"] = [];       
            $data["pageInfo"] = array();
            $data["pageInfo"]["page"] = $page;
            $data["pageInfo"]["perPage"] = $perPage;
            $data["pageInfo"]["total"] = $totalNums;
            //TODO 小红点的逻辑需要加上               
          }else{
            $data["userInfo"] = [];
          }
        }
        $data["uri"] = getUriInfo($this->request);
		    return view('userManage/user_manage',$data);
     }

///////////////////////////////////////////////////  权限管理区域  ////////////////////////////////////////////////////////////////

    /****************************************************
     *       展示权限页面
     /****************************************************/
     public function showRolePage(){
      $data = array();
      $username = $this->request->getGet("username");
      $token = $this->request->getGet("token");
      
      
      if($username == "" || $token == ""){
        $data["userInfo"] = [];
      }else{
        $signModel = new \App\Models\SignModel();
        $userInfo = $signModel->getItemByUsername($username);
        $userManageModel = new \App\Models\UserManageModel();
        if($userInfo[0]["token"] == $token){
          $data["userInfo"] = $userInfo[0];
          $data["notification"] = [];       
          //TODO 小红点的逻辑需要加上               
        }else{
          $data["userInfo"] = [];
        }
      }
      $data["uri"] = getUriInfo($this->request);
      return view('userManage/show_role',$data);
   }
}