muti_select() static public method

多选下拉选择菜单 $name 此select 的 name 标签 $array 要制作select 的数 $default 如果要设定默认选择哪个数据 就在此填入默认的数据的值 $self 设置为ture,option的值等于$value $attrArray html标签的熟悉 就是这个select的属性标签 例如 class="x1" $add_help 增加一个值为空的 请选择 项
static public muti_select ( $name, $option, $default = [], $self = null, $attrArray = null, $add_help = true )
Example #1
0
 function add_module()
 {
     //\Swoole\Error::dbd();
     if (empty($_GET['id']) and empty($_POST)) {
         $gets['select'] = 'id,username,realname';
         $tmp = table('user')->gets($gets);
         $user = array();
         foreach ($tmp as $t) {
             $name = !empty($t['realname']) ? $t['realname'] : '';
             $user[$t['id']] = "{$name} [{$t['username']}]";
         }
         $form['name'] = \Swoole\Form::input('name');
         $form['intro'] = \Swoole\Form::text('intro');
         $form['owner_uid'] = \Swoole\Form::select('owner_uid', $user, '', null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%"));
         $form['backup_uids'] = \Swoole\Form::muti_select('backup_uids[]', $user, array(), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false);
         $tmp = table('project')->gets(array("order" => "id desc"));
         $project = array();
         foreach ($tmp as $t) {
             $project[$t['id']] = $t['name'];
         }
         $form['project_id'] = \Swoole\Form::select('project_id', $project, '', null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%"));
         $this->assign('form', $form);
         $this->display();
     } elseif (!empty($_GET['id']) and empty($_POST)) {
         $id = (int) $_GET['id'];
         $module = table("module")->get($id)->get();
         $gets['select'] = '*';
         $tmp = table('user')->gets($gets);
         $user = array();
         foreach ($tmp as $t) {
             $name = !empty($t['realname']) ? $t['realname'] : '';
             $user[$t['id']] = "{$name} [{$t['username']}]";
         }
         $form['id'] = \Swoole\Form::hidden('id', $module['id']);
         $form['name'] = \Swoole\Form::input('name', $module['name']);
         $form['intro'] = \Swoole\Form::text('intro', $module['intro']);
         $form['owner_uid'] = \Swoole\Form::select('owner_uid', $user, $module['owner_uid'], null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%"));
         $form['backup_uids'] = \Swoole\Form::muti_select('backup_uids[]', $user, explode(',', $module['backup_uids']), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false);
         $tmp = table('project')->gets(array("order" => "id desc"));
         $project = array();
         foreach ($tmp as $t) {
             $project[$t['id']] = $t['name'];
         }
         $form['project_id'] = \Swoole\Form::select('project_id', $project, $module['project_id'], null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%"));
         $this->assign('form', $form);
         $this->display();
     } elseif (!empty($_POST) and empty($_POST['id'])) {
         $in['name'] = trim($_POST['name']);
         $in['owner_uid'] = trim($_POST['owner_uid']);
         if (empty($in['owner_uid'])) {
             $in['owner_uid'] = $this->uid;
         }
         $in['project_id'] = trim($_POST['project_id']);
         $backup_uids = '';
         if (!empty($_POST['backup_uids'])) {
             $backup_uids = implode(',', $_POST['backup_uids']);
         }
         $in['backup_uids'] = $backup_uids;
         //            $in['backup_name'] = trim($_POST['backup_name']);
         $in['intro'] = trim($_POST['intro']);
         $c = table('module')->count(array('name' => $in['name']));
         if ($c > 0) {
             \Swoole\JS::js_goto("操作失败,已存在同名模块", "/setting/add_module/");
         } else {
             $id = table('module')->put($in);
             if ($id) {
                 \Swoole\JS::js_goto("操作成功", "/setting/add_module/");
                 \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} add module success {$id} : " . print_r($in, 1));
             } else {
                 \Swoole\JS::js_goto("操作失败", "/setting/add_module/");
                 \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} add module failed:  " . print_r($in, 1));
             }
         }
     } else {
         $id = (int) $_POST['id'];
         $in['name'] = trim($_POST['name']);
         $in['owner_uid'] = trim($_POST['owner_uid']);
         $in['project_id'] = trim($_POST['project_id']);
         $backup_uids = '';
         if (!empty($_POST['backup_uids'])) {
             $backup_uids = implode(',', $_POST['backup_uids']);
         }
         $in['backup_uids'] = $backup_uids;
         $in['intro'] = trim($_POST['intro']);
         $where['name'] = $in['name'];
         $where['where'][] = "id !={$id}";
         $c = table('module')->count($where);
         if ($c > 0) {
             \Swoole\JS::js_goto("操作失败,已存在同名模块", "/setting/module_list/");
         } else {
             $res = table('module')->set($id, $in);
             if ($res) {
                 \Swoole\JS::js_goto("操作成功", "/setting/module_list/");
                 \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} modify module success {$id} : " . print_r($in, 1));
             } else {
                 \Swoole\JS::js_goto("操作失败", "/setting/module_list/");
                 \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} modify module failed:  " . print_r($in, 1));
             }
         }
     }
 }
Example #2
0
 function add()
 {
     //不是超级用户不能查看修改用户
     if ($this->userinfo['usertype'] != 0) {
         return "access deny";
     }
     //\Swoole::$php->db->debug = true;
     if (empty($_GET) and empty($_POST)) {
         $tmp = table('project')->gets(array("order" => "id desc"));
         $project = array();
         foreach ($tmp as $t) {
             $project[$t['id']] = $t['name'];
         }
         $form['project_id'] = \Swoole\Form::muti_select('project_id[]', $project, array(), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false);
         $form['uid'] = \Swoole\Form::input('uid');
         $form['mobile'] = \Swoole\Form::input('mobile');
         $form['realname'] = \Swoole\Form::input('realname');
         $form['username'] = \Swoole\Form::input('username');
         $form['usertype'] = \Swoole\Form::select('usertype', $this->config['usertype'], null, null, array('class' => 'select2'));
         $this->assign('form', $form);
         $this->display();
     } elseif (!empty($_GET['id']) and empty($_POST)) {
         $id = (int) $_GET['id'];
         $user = table('user')->get($id)->get();
         $tmp = table('project')->gets(array("order" => "id desc"));
         $project = array();
         foreach ($tmp as $t) {
             $project[$t['id']] = $t['name'];
         }
         $form['project_id'] = \Swoole\Form::muti_select('project_id[]', $project, explode(',', $user['project_id']), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false);
         $form['uid'] = \Swoole\Form::input('uid', $user['uid']);
         $form['mobile'] = \Swoole\Form::input('mobile', $user['mobile']);
         $form['realname'] = \Swoole\Form::input('realname', $user['realname']);
         $form['username'] = \Swoole\Form::input('username', $user['username']);
         $form['usertype'] = \Swoole\Form::select('usertype', $this->config['usertype'], null, null, array('class' => 'select2'));
         $form['id'] = \Swoole\Form::hidden('id', $user['id']);
         $this->assign('form', $form);
         $this->display();
     } elseif (!empty($_POST['id'])) {
         $id = (int) $_POST['id'];
         $inserts['realname'] = $_POST['realname'];
         $inserts['username'] = $_POST['username'];
         $inserts['uid'] = (int) $_POST['uid'];
         $inserts['project_id'] = implode(',', $_POST['project_id']);
         $inserts['mobile'] = $_POST['mobile'];
         $res = table("user")->set($id, $inserts);
         if ($res) {
             \Swoole\JS::js_goto("修改成功", '/user/ulist/');
         } else {
             \Swoole\JS::js_goto("修改失败", '/user/ulist/');
         }
     } else {
         $inserts['realname'] = $_POST['realname'];
         $inserts['username'] = trim($_POST['username']);
         $inserts['uid'] = isset($_POST['uid']) ? (int) $_POST['uid'] : 0;
         $inserts['project_id'] = isset($_POST['project_id']) ? implode(',', $_POST['project_id']) : '';
         $inserts['mobile'] = $_POST['mobile'];
         //默认密码
         $inserts['password'] = Swoole\Auth::mkpasswd($inserts['username'], '123456');
         $res = table("user")->put($inserts);
         if ($res) {
             \Swoole\JS::js_goto("添加成功", '/user/ulist//');
         } else {
             \Swoole\JS::js_goto("添加失败", '/user/ulist/');
         }
     }
 }