<?php

namespace user;

class userlist
{
    /**
     * 用户列表（使用MYUID作为删除排除对象，防止作死自杀）
     * @param $myuid
     * @return string
     */
    public function admin($myuid){
        global $medoo;
        $base = $medoo->select("user_base", "*");
        $basenum=count($base);
        $userinfo='';
        for ($i=0;$i<$basenum;$i++ ){
            $uid=$base[$i]['uid'];
            $info=$medoo->select("user_info", "*",['uid'=>$uid]);
            $userinfo=$userinfo.'<tr><td><input type="checkbox" /></td><td>'.$uid.'</td><td>'.$base[$i]['username'].'</td><td>'.$info[0]['name'].'</td><td class="am-hide-sm-only">'.$base[$i]['callnumber'].'</td><td class="am-hide-sm-only">'.$this->depcha($info[0]['dep']).'</td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><a href="./useredit.html?uid='.$uid.'" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</a>';
            if($info[0]['uid']!=$myuid) {
                $userinfo = $userinfo . '<a href="./usersubmit.cgi?m=delete&uid=' . $uid . '" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</a>';
            }
            $userinfo=$userinfo.'</div></div></td></tr>';
        }
        return $userinfo;
    }

    /**
     * 私有函数：部门ID转部门名称
     * @param $did
     * @return mixed
     */
    private function depcha($did){
        global $DB;
        $depinfo=$DB->getRow("SELECT * FROM oid_dep_info WHERE did=:did LIMIT 1", [':did'=>$did]);
        return $depinfo['name'];
    }
}