function edit() { if (!empty($_POST['name'])) { $inserts['name'] = $_POST['name']; $inserts['intro'] = $_POST['intro']; $msg['code'] = 0; if (empty($_POST['id'])) { $res = table("project")->put($inserts); $msg['message'] = $res ? "添加成功,ID: " . $res : "添加失败"; } else { $res = table("project")->set(intval($_POST['id']), $inserts); $msg['message'] = $res ? "修改成功" : "修改失败"; } $this->assign('msg', $msg); } if (empty($_GET)) { $form['name'] = \Swoole\Form::input('name'); $form['intro'] = \Swoole\Form::input('intro'); $this->assign('form', $form); } else { $id = (int) $_GET['id']; $res = table("project")->get($id)->get(); $form['name'] = \Swoole\Form::input('name', $res['name']); $form['intro'] = \Swoole\Form::input('intro', $res['intro']); $form['id'] = \Swoole\Form::hidden('id', $res['id']); } $this->assign('form', $form); $this->display(); }
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)); } } } }
function category_list() { $gets = array(); $id = trim(get_post('id')); if ($id !== '') { $id = (int) $id; $gets['where'][] = "id={$id}"; $_GET['id'] = $id; } else { $id = null; } $name = trim(get_post('name')); if ($name !== '') { $name = trim($name); $gets['where'][] = "name like '%{$name}%'"; $_GET['name'] = $name; } else { $name = null; } $project_id = trim(get_post('project_id')); if ($project_id !== '') { $project_id = (int) $project_id; $gets['where'][] = "project_id = {$project_id}"; $_GET['project_id'] = $project_id; } else { $project_id = null; } $projects = table('project')->gets(array('select' => 'id, name', 'order' => 'id desc')); $projects = array_rebuild($projects, 'id', 'name'); // 搜索表单 $form['id'] = \Swoole\Form::input('id', htmlspecialchars($id), array('id' => 'id', 'placeholder' => 'ID')); $form['name'] = \Swoole\Form::input('name', htmlspecialchars($name), array('id' => 'name', 'placeholder' => '分类名称')); $form['project_id'] = \Swoole\Form::select('project_id', $projects, htmlspecialchars($project_id), null, array('class' => 'select2', 'style' => 'width:100%')); $gets['order'] = 'id desc'; $gets['page'] = !empty($_GET['page']) ? (int) $_GET['page'] : 1; $gets['pagesize'] = 20; $gets['where'][] = 'status = 1'; $data = table('tiny_url_category')->gets($gets, $pager); foreach ($data as $k => $v) { $data[$k]['project_name'] = !empty($projects[$v['project_id']]) ? $projects[$v['project_id']] : null; } $this->assign('form', $form); $this->assign('data', $data); $this->assign('pager', array('render' => $pager->render())); $this->display(); }
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/'); } } }