public function addAction() { $p = $_REQUEST; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $pName = empty($p['name']) ? Tool_Fnc::ajaxMsg('用户名不能为空') : Tool_Fnc::safe_string($p['name']); Tool_Validate::az09($pName) ? '' : Tool_Fnc::ajaxMsg('用户名格式为a-zA-Z_-组成'); $pPasswd = empty($p['passwd']) ? Tool_Fnc::ajaxMsg('密码不能为空') : trim($p['passwd']); $pRepasswd = empty($p['repasswd']) ? Tool_Fnc::ajaxMsg('重复密码不能为空') : trim($p['repasswd']); strlen($pPasswd) < 6 || strlen($pRepasswd) < 6 ? Tool_Fnc::ajaxMsg('密码长度至少为6位') : ''; if ($pPasswd !== $pRepasswd) { Tool_Fnc::ajaxMsg('两次密码不一置'); } $pPrivateKey = Tool_Fnc::newrand(); $pPasswd = Tool_Fnc::markmd5($pPasswd, $pPrivateKey); $tDatas = array('name' => $pName, 'passwd' => $pPasswd, 'private_key' => $pPrivateKey); $tAM = new AdminModel(); if (!$tAM->insert($tDatas)) { Tool_Fnc::ajaxMsg('新增管理员失败'); } Tool_Fnc::ajaxMsg('添加成功', 1); } }
public function add_newsAction() { if (empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { error404(); } $model = new AdminModel(); $nid = post('__nid', 'int'); $name = post('__name'); if ($name) { if ($nid) { $news = $model->getNewsByID($nid); if ($news) { $data['name'] = $name; $model->update('news', $data, "`id` = '{$nid}'"); $response['target_v']['#nid'] = 0; $response['target_v']['#name'] = ''; $response['target_h']['#status'] = Lang::translate('NEWS_ADD_NEWS_EDITED'); } else { $response['target_h']['#status'] = Lang::translate('NEWS_ADD_NEWS_NOT_FOUND'); } } else { $data['uid'] = Request::getParam('user')->id; $data['name'] = $name; $data['time'] = time(); $id = $model->insert('news', $data); if ($id) { $response['target_v']['#nid'] = 0; $response['target_v']['#name'] = ''; $response['target_p']['#news_list'] = '<div id="n_' . $id . '">' . '<a href="' . url('admin', 'lang_news', $id) . '">' . $name . '</a>' . ' (<span class="c_red">' . Lang::translate('NEWS_HIDDEN') . '</span>)'; if (Request::getRole() == 'admin') { $response['target_p']['#news_list'] .= ' - <a onclick="' . ajaxLoad(url('admin', 'act_news'), 'act_news', 'act:approve|id:' . $id) . '">' . Lang::translate('NEWS_APPROVE_0') . '</a>' . ' | <a onclick="' . ajaxLoad(url('admin', 'act_news'), 'act_news', 'act:delete|id:' . $id) . '">' . Lang::translate('NEWS_DELETE') . '</a>'; } $response['target_p']['#news_list'] .= '</div>'; $response['target_h']['#status'] = Lang::translate('NEWS_ADD_NEWS_ADDED'); } else { $response['target_h']['#status'] = Lang::translate('NEWS_ADD_NEWS_NOT_ADDED'); } } } else { $response['target_h']['#status'] = Lang::translate('NEWS_ADD_NEWS_EMPTY_NAME'); } $response['error'] = 0; echo json_encode($response); exit; }