<?php
include INDEX_ROOT.'admin/head.php';
admin_head('部门处理层');
$m=$_GET['m'];
if($m=='new'){
    if(empty($_POST))sysmsg('POST来的数据不能为空');
    if(empty($_POST['name']))sysmsg('部门名称不能为空');
    if(empty($_POST['order']))sysmsg('负责人组卡序号不能为空');

    $name=$_POST['name'];
    $upid=$_POST['upid'];
    $order=$_POST['order'];

    $account=new \user\account();
    $duid=$account->info_to_eid($order)['uid'];
    if(!$duid){
        alert('负责人组卡序号不存在');
        go("-1");
        die();
    }
    $depmain=new \user\depmain();
    $depmain->reg($name,$duid,$upid);
    alert('添加成功');
    go('/admin/dep.html');
}elseif($m=='edit'){
    if(empty($_POST))sysmsg('POST来的数据不能为空');
    if(empty($_POST['name']))sysmsg('部门名称不能为空');
    $name=$_POST['name'];
    $depmain=new \user\depmain();
    $depmain->update($_GET['id'],$name);
    alert('修改成功');
    go('/admin/dep.html');
}elseif($m=='dep_delete'){
    $did=$_GET['did'];
    (new \user\depmain())->del($did);
    alert('删除成功');
    go('/admin/dep.html');
}else{
    alert('参数错误，请重新输入');
    go('-1');
}

admin_foot();
?>