<?php
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Form;
use Dcat\Admin\Grid\Filter;
use Dcat\Admin\Show;
use Dcat\Admin\Layout\Navbar;
use Illuminate\Support\Facades\DB;

/**
 * Dcat-admin - admin builder based on Laravel.
 * @author jqh <https://github.com/jqhph>
 *
 * Bootstraper for Admin.
 *
 * Here you can remove builtin form field:
 *
 * extend custom field:
 * Dcat\Admin\Form::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Column::extend('php', PHPEditor::class);
 * Dcat\Admin\Grid\Filter::extend('php', PHPEditor::class);
 *
 * Or require js and css assets:
 * Admin::css('/packages/prettydocs/css/styles.css');
 * Admin::js('/packages/prettydocs/js/main.js');
 *
 */

$user = Admin::user();

if (!empty($user)) {
    $db = DB::connection('sqlsrv');
    $md=$db->select("SELECT KHDM,KHMC FROM KEHU WHERE KHDM = '{$user->username}' 
    UNION ALL 
    SELECT KHDM,KHMC FROM KEHU WHERE SX5_ID IN (SELECT SX5_ID FROM KEHU WHERE KHDM = '{$user->username}') 
    AND SX5_ID NOT IN ('000', 'C000') AND KHMC NOT LIKE '%停%' AND KHDM<>'{$user->username}'");

    if ($user->username<>'admin' && empty($user->sddm)) {
        $user->sddm = $user->username; // 修改指定字段值
        $user->save(); // 保存修改
    }
    if ($user->username<>'admin') {
        Admin::navbar(function (Navbar $navbar) use($md,$user){
            $navbar->right(view('select',['md'=>$md,'sddm'=>$user->sddm]));
        });
    }
}

