<?php

namespace user;

class deplist
{
    /**
     * 部门全部显示（适用于/admin/dep.html）
     * @return string
     */
    public function deplist(){
        global $medoo;
        $base = $medoo->select("dep_info", "*");
        $basenum=count($base);
        $userinfo='';
        for ($i=0;$i<$basenum;$i++ ){
            $userinfo=$userinfo.'<tr><td>
                <input type="checkbox" /></td>
                <td>'.$base[$i]['did'].'</td>
                <td>'.$base[$i]['name'].'</td>
                <td>'.$this->orders($base[$i]['orders']).'</td>
                <td>'.$this->depname($base[$i]['upn']).'</td>
                <td>
                <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                <a href="./depedit.html?did='.$base[$i]['did'].'" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</a>
                <a href="./depnew.html?upid='.$base[$i]['did'].'" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 新建下级部门</a>
                ';
            if($base[$i]['upn']!=0){
                $userinfo = $userinfo . '<a href="./depsubmit.cgi?m=dep_delete&did=' . $base[$i]['did'] . '" 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;
    }

    /**
     * 私有函数：部门头头显示
     * @param $uid
     * @return mixed
     */
    private function orders($uid){
        global $medoo;
        $info=$medoo->select("user_info", "*",['uid'=>$uid]);
        return $info[0]['name'];
    }

    private function depname($did){
        global $medoo;
        $info = $medoo->select("dep_info", "*",["did"=>$did]);
        return $info[0]['name'];
    }
}