/** * 添加回复 */ public static final function append() { $online = front::online(); if (!$online->user_id) { die('Permission Denied!'); } //需要登录 $time = time(); while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { $post = array('doc_id' => isset($_POST['doc_id']) ? $_POST['doc_id'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '', 'content' => isset($_POST['content']) ? $_POST['content'] : '', 'ip' => get_onlineip(), 'create_date' => date('Y-m-d', $time), 'create_time' => date('H:i:s', $time)); //$post['content'] = htmlentities($content , ENT_COMPAT ,'utf-8') ; //pecho($post); if (!empty($error)) { break; } $doc_remark = new self(); $doc_remark->doc_remark_id = null; $doc_remark->struct($post); $doc_remark->insert('', 'doc_remark_id'); if ($doc_remark->doc_remark_id) { $doc = new doc(); $doc->doc_id = $doc_remark->doc_id; $doc->last_remark = date('Y-m-d H:i:s', $time); $doc->update(); } //print_r ( $doc_remark); header('Location: ?' . $_GET['query']); return; } }
/** * 添加用户 */ public static final function append() { $error = array(); // 数据消毒 $post = array('username' => isset($_POST['username']) ? $_POST['username'] : '', 'password' => isset($_POST['password']) ? $_POST['password'] : '', 'grade' => isset($_POST['grade']) ? $_POST['grade'] : '', 'name' => isset($_POST['name']) ? $_POST['name'] : '', 'gender' => isset($_POST['gender']) ? $_POST['gender'] : '', 'mobile' => isset($_POST['mobile']) ? $_POST['mobile'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '', 'url' => isset($_POST['url']) ? $_POST['url'] : '', 'remark' => isset($_POST['remark']) ? $_POST['remark'] : ''); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据验证 $length = (strlen($post['username']) + mb_strlen($post['username'], 'UTF-8')) / 2; if ($length < 3 || $length > 16 || preg_match('/^[a-zA-Z0-9_\\x{4e00}-\\x{9fa5}]+$/u', $post['username']) === 0 || preg_match('/^[0-9]+$/', $post['username']) === 1 || preg_match('/^_|_$/', $post['username']) === 1) { $error['username'] = '******'; } else { $count = self::selects('COUNT(*)', null, array('username' => $post['username']), null, array('column|table=user' => 'COUNT(*)')); if ($count > 0) { $error['username'] = '******'; } } if (strlen($post['password']) < 4 || strlen($post['password']) > 16 || preg_match('/^[\\x21-\\x9e]+$/', $post['password']) === 0) { $error['password'] = '******'; } if (preg_match('/^[1-3]$/i', $post['grade']) === 0) { $error['grade'] = '请选择级别'; } if (strlen($post['name']) === 0) { $error['name'] = '请填写姓名'; } if (preg_match('/^[1-2]$/i', $post['gender']) === 0) { $error['gender'] = '请选择性别'; } if (strlen($post['mobile']) > 0 && preg_match('/^1[0-9]{10}$/i', $post['mobile']) === 0) { $error['mobile'] = '请正确填写手机号'; } if (strlen($post['email']) > 0 && !filter_var($post['email'], FILTER_VALIDATE_EMAIL)) { $error['email'] = '请正确填写邮箱'; } if (strlen($post['url']) > 0 && !filter_var($post['url'], FILTER_VALIDATE_URL)) { $error['url'] = '请正确填写网址'; } $length = (strlen($post['remark']) + mb_strlen($post['remark'], 'UTF-8')) / 2; if ($length > 100) { $error['remark'] = '备注最多只能填写100个字符'; } if (!empty($error)) { break; } // 数据入库 $user = new self(); $user->user_id = null; $user->struct($post); $user->insert(); header('Location: ?do=browse'); return; } // 页面显示 foreach (array('username', 'mobile', 'email', 'url', 'remark') as $value) { $post[$value] = htmlspecialchars($post[$value]); } self::view(__CLASS__ . '/' . 'form.tpl', compact('post', 'error')); }
/** * 更新某个会员某个时间后所有帐目的小计 * @param INT $uid * @param INT $date * @param STRING $ccy 货币 */ public static final function import() { $item_types = book_item::get_items(); $ccys = book::get_ccy(); $banks = book::get_banks(); $error = array(); $online = front::online(); $time = time(); // 数据消毒 $item_txts = self::selects('item_txt', null, array('user_id' => $online->user_id), array('GROUP BY item_txt'), array(null, 'column|table=book' => 'item_txt')); $opposites = self::selects('opposite', null, array('user_id' => $online->user_id), array('GROUP BY opposite'), array(null, 'column|table=book' => 'opposite')); if (!$item_txts) { $item_txts = array(); } $book_items = self::selects('book_item_id,item,info', '#@__book_item', array('user_id' => $online->user_id), array('ORDER BY book_item_id ASC'), array('book_item_id', 'assoc' => null)); $import_status = ''; // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { $post = array('bank' => isset($_POST['bank']) ? $_POST['bank'] : '', 'book_item_id' => isset($_POST['book_item_id']) ? $_POST['book_item_id'] : ''); // 数据验证 if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } if (empty($post['book_item_id'])) { $error['book_item_id'] = '请指定绑定账户'; } if (empty($post['bank'])) { $error['bank'] = '请指定银行'; } if (empty($_FILES['bankfile']) || empty($_FILES['bankfile']['name'])) { $error['bankfile'] = '请上传文件'; } else { if ($_FILES['bankfile']['error']) { $error['bankfile'] = '文件上传错误:' . $_FILES['bankfile']['error']; } else { $content = file_get_contents($_FILES['bankfile']['tmp_name']); $bank_data = self::get_bank_data($post['bank'], $content); if (!$bank_data) { $error['bankfile'] = '文件格式错误!'; } cache_write('bank_import_' . $post['book_item_id'] . '.php', $bank_data); } } if (!empty($error)) { break; } $ccy = 'CNY'; if ($bank_data) { // 数据入库 $import_count = 0; foreach ($bank_data['data'] as $d) { $p = $d; $p['item'] = ''; $p['item_txt'] = ''; $p['opposite'] = ''; $p['book_item_id'] = $post['book_item_id']; $p['typeid'] = '0'; $p['ccy'] = $ccy; $p['net'] = ''; $p['user_id'] = $online->user_id; $p['update_date'] = date('Y-m-d', $time); $p['update_time'] = date('Y-m-d', $time); $book = new self(); $book->book_id = null; $book->struct($p); $book_id = $book->insert('', 'book_id'); if (!$book_id || $book_id < 1) { $error['bankfile'] = 'add fail'; break; } $import_count++; } if (!$error) { $import_status = '导入成功,共导入' . $import_count . '个/共' . count($bank_data['data']) . '个'; } else { $import_status = '导入失败,共导入' . $import_count . '个/共' . count($bank_data['data']) . '个'; } $import_status .= '<br>' . $bank_data['date_min'] . '~' . $bank_data['date_max']; self::update_statement_net($online->user_id, 0, $ccy); } break; header('Location: ?go=book&do=browse'); return; } if (!$post['create_date']) { $post['create_date'] = date('Y-m-d'); } if (!$post['create_time']) { $post['create_time'] = '12:00:00'; } //date('H:i:s'); //if(!$post['item'])$post['item'] = 3; // 页面显示 foreach (array('item', 'item_txt', 'typeid', 'remark', 'ccy', 'net', 'otype', 'amount') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'import.tpl', compact('post', 'import_status', 'banks', 'error', 'item_txts', 'opposites', 'otype', 'item_types', 'book_items', 'ccys')); }
/** * 添加分类 */ public static final function append() { $error = array(); $online = front::online(); // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据消毒 $post = array('name' => isset($_POST['name']) ? $_POST['name'] : '', 'parent_id' => isset($_POST['parent_id']) ? (int) $_POST['parent_id'] : '0', 'component' => isset($_POST['component']) ? $_POST['component'] : '', 'sort' => isset($_POST['sort']) ? (int) $_POST['sort'] : '0', 'user_id' => $online->user_id); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } // 数据验证 $length = (strlen($post['name']) + mb_strlen($post['name'], 'UTF-8')) / 2; if ($length == 0) { $error['name'] = '分类名不能为空'; } else { $count = self::selects('COUNT(*)', null, array('name' => $post['name'], 'parent_id' => $post['parent_id']), null, array('column|table=channel' => 'COUNT(*)')); if ($count > 0) { $error['name'] = '分类名重复,请换一个分类名'; } if ($post['parent_id']) { $component = self::selects('component', null, array('channel_id' => $post['parent_id']), null, array('column|table=channel' => 'component')); $post['component'] = $component; } else { //顶级分类,可以任意指定 } } if (!empty($error)) { break; } // 数据入库 $channel = new self(); $channel->channel_id = null; $channel->struct($post); $channel->insert(); self::update_path($channel->channel_id); header('Location: ?go=channel&do=browse'); return; } // 页面显示 foreach (array('title', 'copyfrom', 'typeid', 'keyword', 'keyword_auto', 'content') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error')); }
/** * 添加用户 */ public static final function append() { $error = array(); $online = front::online(); $TI = self::get_table(); // 数据消毒 $post = array(); foreach ($TI as $k => $info) { if ($info['Extra'] == 'auto_increment') { continue; } if (isset($_POST[$info['Field']])) { $post[$info['Field']] = $_POST[$info['Field']]; } } if (get_magic_quotes_gpc()) { $post = stripslashes_deep($post); } if ($online->grade > 2) { $error = '无权限'; front::view2('common/error.tpl', compact('error')); return; } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据验证 if ($online->grade > $post['grade']) { $error['grade'] = '等级设置错误'; } $length = (strlen($post['username']) + mb_strlen($post['username'], 'UTF-8')) / 2; if ($length < 3 || $length > 16 || preg_match('/^[a-zA-Z0-9_\\x{4e00}-\\x{9fa5}]+$/u', $post['username']) === 0 || preg_match('/^[0-9]+$/', $post['username']) === 1 || preg_match('/^_|_$/', $post['username']) === 1) { $error['username'] = '******'; } else { $count = self::selects('COUNT(*)', null, array('username' => $post['username']), null, array('column|table=user' => 'COUNT(*)')); if ($count > 0) { $error['username'] = '******'; } } if (strlen($post['password']) < 4 || strlen($post['password']) > 16 || preg_match('/^[\\x21-\\x9e]+$/', $post['password']) === 0) { $error['password'] = '******'; } else { $post['password'] = md5($post['username'] . md5($post['password'])); } if (preg_match('/^[1-3]$/i', $post['grade']) === 0) { $error['grade'] = '请选择级别'; } if (strlen($post['name']) === 0) { $error['name'] = '请填写姓名'; } if (preg_match('/^[1-2]$/i', $post['gender']) === 0) { $error['gender'] = '请选择性别'; } if (strlen($post['mobile']) > 0 && preg_match('/^1[0-9]{10}$/i', $post['mobile']) === 0) { $error['mobile'] = '请正确填写手机号'; } if (strlen($post['email']) > 0 && !filter_var($post['email'], FILTER_VALIDATE_EMAIL)) { $error['email'] = '请正确填写邮箱'; } if (strlen($post['url']) > 0 && !filter_var($post['url'], FILTER_VALIDATE_URL)) { $error['url'] = '请正确填写网址'; } $length = (strlen($post['remark']) + mb_strlen($post['remark'], 'UTF-8')) / 2; if ($length > 100) { $error['remark'] = '备注最多只能填写100个字符'; } if (!empty($error)) { break; } // 数据入库 $user = new self(); $user->user_id = null; $user->struct($post); $user->insert(); header('Location: ?go=user&do=browse'); return; } // 页面显示 foreach (array('username', 'mobile', 'email', 'url', 'remark') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('TI', 'keys', 'post', 'error', 'online', 'notice', 'FromType', 'FromMsg', 'FromName')); }
/** * 添加日志 */ public static final function append() { $error = array(); $online = front::online(); $time = time(); // 数据消毒 $post = array('diary_date' => isset($_POST['diary_date']) ? $_POST['diary_date'] : '', 'title' => isset($_POST['title']) ? $_POST['title'] : '', 'mood' => isset($_POST['mood']) ? $_POST['mood'] : '', 'weather' => isset($_POST['weather']) ? $_POST['weather'] : '', 'content' => isset($_POST['content']) ? $_POST['content'] : '', 'user_id' => $online->user_id, 'create_date' => date('Y-m-d', $time), 'create_time' => date('H:i:s', $time), 'update_date' => date('Y-m-d', $time), 'update_time' => date('H:i:s', $time)); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据验证 if (empty($post['diary_date'])) { //title=content $post['diary_date'] = date('Y-m-d'); } if (empty($post['title'])) { //title=content $post['title'] = substr(strip_tags($post['content']), 0, 15); } else { $post['title'] = strip_tags($post['title']); } if (empty($post['title'])) { $error['title'] = '标题不能为空'; } if (!empty($error)) { break; } // 数据入库 $diary = new self(); $diary->diary_id = null; $diary->struct($post); $diary->insert(); header('Location: ?go=diary&do=browse'); return; } // 页面显示 foreach (array('title', 'url', 'typeid', 'content') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error')); }
/** * 添加网址 */ public static final function append() { $error = array(); $online = front::online(); $time = time(); // 数据消毒 $post = array('title' => isset($_POST['title']) ? $_POST['title'] : '', 'url' => isset($_POST['url']) ? $_POST['url'] : '', 'typeid' => isset($_POST['typeid']) ? $_POST['typeid'] : '', 'content' => isset($_POST['content']) ? $_POST['content'] : '', 'user_id' => $online->user_id, 'create_date' => date('Y-m-d', $time), 'create_time' => date('H:i:s', $time), 'update_date' => date('Y-m-d', $time), 'update_time' => date('H:i:s', $time)); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据验证 $length = (strlen($post['title']) + mb_strlen($post['title'], 'UTF-8')) / 2; if ($length < 3 || $length > 200) { $error['title'] = '网站名至少3个字符,最多200个字符'; } else { $count = self::selects('COUNT(*)', null, array('title' => $post['title']), null, array('column|table=site' => 'COUNT(*)')); if ($count > 0) { $error['title'] = '网站名重复,请检查是否重复记录'; } } $count = self::selects('COUNT(*)', null, array('url' => $post['url']), null, array('column|table=site' => 'COUNT(*)')); if ($count > 0) { $error['url'] = 'URL重复,请检查是否重复记录'; } if ($post['typeid'] === 0) { $error['typeid'] = '请选择分类'; } //$length = (strlen ($post ['content']) + mb_strlen ($post ['content'], 'UTF-8')) /2; //if ($length > 100) { // $error ['content'] = '备注最多只能填写100个字符'; //} if (!empty($error)) { break; } // 数据入库 $site = new self(); $site->site_id = null; $site->struct($post); $site->insert(); header('Location: ?go=site&do=browse'); return; } // 页面显示 foreach (array('title', 'url', 'typeid', 'content') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error')); }
/** * 添加关系 */ public static final function append() { $error = array(); $online = front::online(); $get = array('s_type' => isset($_GET['s_type']) ? $_GET['s_type'] : '', 't_type' => isset($_GET['t_type']) ? $_GET['t_type'] : '', 's_id' => isset($_GET['s_id']) ? (int) $_GET['s_id'] : '0', 't_id' => isset($_GET['t_id']) ? (int) $_GET['t_id'] : '0'); $s_list = null; if ($get['s_type'] == 'channel') { $s_list = channel::get_channel_select(0, 0, $get['s_id'], null, null); } elseif ($get['s_type'] == 'address') { $s_lists = address::selects('address_id as id,name', null, array('user_id' => $online->user_id), array('ORDER BY address_id DESC'), array('id', 'column|table=address' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'book') { $s_lists = book::selects('book_id as id,concat_ws(\',\',create_date,item_txt,remark,ccy,amount,otype) as name', null, array('user_id' => $online->user_id), array('ORDER BY create_date DESC,book_id DESC'), array('id', 'column|table=book' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'diary') { $s_lists = diary::selects('diary_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY diary_id DESC'), array('id', 'column|table=diary' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'doc') { $s_lists = doc::selects('doc_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY doc_id DESC'), array('id', 'column|table=doc' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'site') { $s_lists = site::selects('site_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY site_id DESC'), array('id', 'column|table=site' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'user') { $s_lists = user::selects('user_id as id,username as name', null, array('user_id' => $online->user_id), array('ORDER BY user_id DESC'), array('id', 'column|table=user' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } else { } $t_list = null; if ($get['t_type'] == 'channel') { $t_list = channel::get_channel_select(0, 0, $get['t_id'], null, null); } elseif ($get['t_type'] == 'address') { $t_lists = address::selects('address_id as id,name', null, array('user_id' => $online->user_id), array('ORDER BY address_id DESC'), array('id', 'column|table=address' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'book') { $t_lists = book::selects('book_id as id,concat_ws(\',\',create_date,item_txt,remark,ccy,amount,otype) as name', null, array('user_id' => $online->user_id), array('ORDER BY create_date DESC,book_id DESC'), array('id', 'column|table=book' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'diary') { $t_lists = diary::selects('diary_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY diary_id DESC'), array('id', 'column|table=diary' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'doc') { $t_lists = doc::selects('doc_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY doc_id DESC'), array('id', 'column|table=doc' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'site') { $t_lists = site::selects('site_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY site_id DESC'), array('id', 'column|table=site' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'user') { $t_lists = user::selects('user_id as id,username as name', null, array('user_id' => $online->user_id), array('ORDER BY user_id DESC'), array('id', 'column|table=user' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } else { } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据消毒 $post = array('s_type' => isset($_POST['s_type']) ? $_POST['s_type'] : '', 't_type' => isset($_POST['t_type']) ? $_POST['t_type'] : '', 's_id' => isset($_POST['s_id']) ? (int) $_POST['s_id'] : '0', 't_id' => isset($_POST['t_id']) ? (int) $_POST['t_id'] : '0', 'user_id' => $online->user_id); if (!$post['s_type']) { $error['s_type'] = '请选择源类型'; } if (!$post['t_type']) { $error['t_type'] = '请选择目标类型'; } if (!$post['s_id']) { $error['s_id'] = '请选择源内容'; } if (!$post['t_id']) { $error['t_id'] = '请选目标内容'; } if (!$error['t_id']) { if ($post['s_type'] == $post['t_type'] && $post['s_id'] == $post['t_id']) { $error['t_id'] = '不能和自己关联'; } } if (!$error['t_id']) { $related_id = self::selects('related_id', null, array('user_id' => $online->user_id, 's_id' => $post['s_id'], 's_type' => $post['s_type'], 't_id' => $post['t_id'], 't_type' => $post['t_type']), null, array('column' => 'related_id')); if (!$related_id) { $related_id = self::selects('related_id', null, array('user_id' => $online->user_id, 's_id' => $post['t_id'], 's_type' => $post['t_type'], 't_id' => $post['s_id'], 't_type' => $post['s_type']), null, array('column' => 'related_id')); } if ($related_id) { $error['t_id'] = '目标内容已经关联,请重新选择'; } } if (!empty($error)) { break; } // 数据入库 $related = new self(); $related->related_id = null; $related->struct($post); $related->insert(); $error = '添加成功'; front::view2('error.tpl', compact('error')); return; } $types = array('address' => '地址', 'book' => '账本', 'channel' => '分类', 'diary' => '日志', 'doc' => '文章', 'site' => '网址', 'user' => '用户'); front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'get', 'error', 'types', 's_list', 't_list')); }
/** * 添加日志 */ public static final function append() { $item_types = self::get_items(); $error = array(); $online = front::online(); $time = time(); // 数据消毒 $online = front::online(); // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { $post = array('item' => isset($_POST['item']) ? $_POST['item'] : '', 'info' => isset($_POST['info']) ? $_POST['info'] : '', 'user_id' => $online->user_id); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } if (empty($post['info'])) { //account=content $post['info'] = substr($post['info'], 0, 15); } if (!empty($error)) { break; } // 数据入库 $book = new self(); $book->book_item_id = null; $book->struct($post); $book_item_id = $book->insert('', 'book_item_id'); if ($book_item_id < 1) { $error['create_date'] = 'add fail'; break; } header('Location: ?go=book_item&do=browse'); return; } if (!$post['create_date']) { $post['create_date'] = date('Y-m-d'); } if (!$post['create_time']) { $post['create_time'] = '12:00:00'; } //date('H:i:s'); if (!$post['item']) { $post['item'] = 3; } // 页面显示 foreach (array('item', 'item_txt', 'typeid', 'remark', 'ccy', 'net', 'otype', 'amount') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error', 'item_txts', 'otype', 'item_types')); }
/** * 添加文章 */ public static final function append() { $error = array(); $online = front::online(); $time = time(); // 数据消毒 $post = array('title' => isset($_POST['title']) ? $_POST['title'] : '', 'copyfrom' => isset($_POST['copyfrom']) ? $_POST['copyfrom'] : '', 'typeid' => isset($_POST['typeid']) ? $_POST['typeid'] : '', 'keyword' => isset($_POST['keyword']) ? $_POST['keyword'] : '', 'keyword_auto' => isset($_POST['keyword_auto']) ? $_POST['keyword_auto'] : '', 'content' => isset($_POST['content']) ? $_POST['content'] : '', 'user_id' => $online->user_id, 'hit' => 0, 'create_date' => date('Y-m-d', $time), 'create_time' => date('H:i:s', $time), 'update_date' => date('Y-m-d', $time), 'update_time' => date('H:i:s', $time)); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据验证 $length = (strlen($post['title']) + mb_strlen($post['title'], 'UTF-8')) / 2; if ($length < 3 || $length > 200) { $error['title'] = '文章名至少3个字符,最多200个字符'; } else { $count = self::selects('COUNT(*)', null, array('title' => $post['title']), null, array('column|table=doc' => 'COUNT(*)')); if ($count > 0) { $error['title'] = '文章名重复,请换一个文章名'; } } if ($post['typeid'] === 0) { $error['typeid'] = '请选择文章分类'; } //if (strlen ($post['keyword']) === 0) { // $error ['keyword'] = '请填写姓名'; //} if ($post['keyword_auto'] == 1) { $post['keyword'] = self::get_keywords(strip_tags($post['title'] . $post['content'])); } unset($post['keyword_auto']); //$length = (strlen ($post ['content']) + mb_strlen ($post ['content'], 'UTF-8')) /2; //if ($length > 100) { // $error ['content'] = '备注最多只能填写100个字符'; //} if (!empty($error)) { break; } // 数据入库 $doc = new self(); $doc->doc_id = null; $doc->struct($post); $doc->insert('', 'doc_id'); header('Location: ?go=doc&do=modify&doc_id=' . $doc->doc_id); //header ('Location: ?go=doc&do=browse'); return; } // 页面显示 foreach (array('title', 'copyfrom', 'typeid', 'keyword', 'keyword_auto', 'content') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error')); }