/application/controllers/admin.php

https://bitbucket.org/vosdbk/wechat_robot_plus · PHP · 873 lines · 663 code · 172 blank · 38 comment · 113 complexity · 26485ed462919ee0f0710c8a7581d855 MD5 · raw file

  1. <?php
  2. /**
  3. * Description of admin
  4. *
  5. * @author terminus
  6. */
  7. class Admin extends TT_Controller {
  8. private $assign;
  9. private $page_config;
  10. public function __construct() {
  11. parent::__construct();
  12. if ('admin' !== $this->ugroup) {
  13. message(lang('notice'), lang('err_nologin'), site_url('login'));
  14. }
  15. $this->load->language('ui/admin');
  16. $this->assign = array(
  17. 'title' => lang('ui_admin'),
  18. );
  19. //读取分页配置
  20. $this->page_config = $this->config->item('page_config');
  21. }
  22. public function index() {
  23. $this->loadview('admin/menus', $this->assign);
  24. }
  25. public function user_index($page = 1) {
  26. //取整并判断页码
  27. $page = intval($page);
  28. if ($page < 1) {
  29. $page = 1;
  30. }
  31. $this->load->model('user_model', 'user');
  32. //分页
  33. $config = array_merge($this->page_config, array(
  34. 'base_url' => site_url('admin/user_index'),
  35. 'total_rows' => $this->user->getUsers(1),
  36. ));
  37. $this->pagination->initialize($config);
  38. $this->assign['pages'] = $this->pagination->create_links();
  39. $this->assign['users'] = $this->user->getUsers(0, $config['per_page'], (($page - 1) * $config['per_page']));
  40. $this->loadview(array('admin/menus', 'admin/user/index'), $this->assign);
  41. }
  42. public function user_add() {
  43. $this->loadview(array('admin/menus', 'admin/user/add'), $this->assign);
  44. }
  45. public function user_doadd() {
  46. $uname = $this->input->post('username');
  47. $password = $this->input->post('password');
  48. $re_password = $this->input->post('re_password');
  49. $role = trim($this->input->post('role'));
  50. if (!chkval('text', $uname, 6, 20)) {
  51. message(lang('notice'), lang('err_username_not_match_rule'), site_url('admin/user_add'));
  52. }
  53. if ($password !== $re_password) {
  54. message(lang('notice'), lang('err_password_repassword_not_match'), site_url('admin/user_add'));
  55. }
  56. if (!chkval('password', $password, 6, 20)) {
  57. message(lang('notice'), lang('err_password_not_match_rule'), site_url('admin/user_add'));
  58. }
  59. $this->load->model('user_model', 'user');
  60. if ($this->user->getUser($uname)) {
  61. message(lang('notice'), lang('err_username_already_used'), site_url('admin/user_add'));
  62. }
  63. switch ($role) {
  64. case '1':
  65. $role = 'admin';
  66. break;
  67. default:
  68. $role = '';
  69. break;
  70. }
  71. if ($this->user->addUser($uname, $password, $role) > 0) {
  72. message(lang('notice'), lang('user_add_success'), site_url('admin/user_index'));
  73. }
  74. message(lang('error'), lang('err_user_add_fail'), site_url('admin/user_add'));
  75. }
  76. public function user_dodel($uid) {
  77. $this->load->model('user_model', 'user');
  78. if (FALSE == $this->user->getUser($uid, 1)) {
  79. message(lang('error'), lang('err_user_not_exist'), site_url('admin/user_index'));
  80. }
  81. if (FALSE == $this->user->delUser($uid)) {
  82. message(lang('error'), lang('err_user_del_fail'), site_url('admin/user_index'));
  83. }
  84. message(lang('notice'), lang('user_del_success'), site_url('admin/user_index'));
  85. }
  86. public function user_edit($uid) {
  87. $this->load->model('user_model', 'user');
  88. $u = $this->user->getUser($uid, 1);
  89. if (FALSE == $u) {
  90. message(lang('error'), lang('err_user_not_exist'), site_url('admin/user_index'));
  91. }
  92. $this->assign['user'] = $u;
  93. $this->loadview(array('admin/menus', 'admin/user/edit'), $this->assign);
  94. }
  95. public function user_doedit() {
  96. $uid = strip_some($this->input->post('uid'));
  97. $password = $this->input->post('password');
  98. $re_password = $this->input->post('re_password');
  99. $role = strip_some($this->input->post('role'));
  100. $this->load->model('user_model', 'user');
  101. if ('' !== $password) {
  102. if ($password !== $re_password) {
  103. message(lang('notice'), lang('err_password_repassword_not_match'), site_url('admin/user_edit/' . $uid));
  104. }
  105. if (!chkval('password', $password, 6, 20)) {
  106. message(lang('notice'), lang('err_password_not_match_rule'), site_url('admin/user_edit/' . $uid));
  107. }
  108. }
  109. switch ($role) {
  110. case '1':
  111. $role = 'admin';
  112. break;
  113. default:
  114. $role = '';
  115. break;
  116. }
  117. if ($this->user->setUser($uid, $password, $role)) {
  118. message(lang('notice'), lang('user_edit_success'), site_url('admin/user_index'));
  119. }
  120. message(lang('error'), lang('err_user_edit_fail'), site_url('admin/user_edit/' . $uid));
  121. }
  122. public function blacklists_index($page = 1) {
  123. //取整并判断页码
  124. $page = intval($page);
  125. if ($page < 1) {
  126. $page = 1;
  127. }
  128. $this->load->model('blacklists_model', 'bl');
  129. //分页
  130. $config = array_merge($this->page_config, array(
  131. 'base_url' => site_url('admin/blacklists_index'),
  132. 'total_rows' => $this->bl->getAll(1),
  133. ));
  134. $this->pagination->initialize($config);
  135. $this->assign['pages'] = $this->pagination->create_links();
  136. $this->assign['blacklists'] = $this->bl->getAll(0, $config['per_page'], (($page - 1) * $config['per_page']));
  137. $this->loadview(array('admin/menus', 'admin/blacklists/index'), $this->assign);
  138. }
  139. public function blacklists_add() {
  140. $this->loadview(array('admin/menus', 'admin/blacklists/add'), $this->assign);
  141. }
  142. public function blacklists_doadd() {
  143. $user_opn_id = strip_some($this->input->post('user_opn_id'));
  144. if (!chkval('text', $user_opn_id, 28, 28)) {
  145. message(lang('notice'), lang('err_user_opn_id_not_match_rule'), site_url('admin/blacklists_add'));
  146. }
  147. $this->load->model('blacklists_model', 'bl');
  148. if ($this->bl->add($user_opn_id) > 0) {
  149. message(lang('notice'), lang('blacklists_add_success'), site_url('admin/blacklists_index'));
  150. }
  151. message(lang('error'), lang('err_blacklists_add_failed'), site_url('admin/blacklists_add'));
  152. }
  153. public function blacklists_dodel($user_opn_id) {
  154. $this->load->model('blacklists_model', 'bl');
  155. if (FALSE == $this->bl->get($user_opn_id)) {
  156. message(lang('error'), lang('err_blacklists_not_exist'), site_url('admin/blacklists_index'));
  157. }
  158. if (FALSE == $this->bl->del($user_opn_id)) {
  159. message(lang('error'), lang('err_blacklists_del_failed'), site_url('admin/blacklists_index'));
  160. }
  161. message(lang('notice'), lang('blacklists_del_success'), site_url('admin/blacklists_index'));
  162. }
  163. public function msgtype_index($page = 1) {
  164. //取整并判断页码
  165. $page = intval($page);
  166. if ($page < 1) {
  167. $page = 1;
  168. }
  169. $this->load->model('msgtype_model', 'mt');
  170. //分页
  171. $config = array_merge($this->page_config, array(
  172. 'base_url' => site_url('admin/msgtype_index'),
  173. 'total_rows' => $this->mt->getMsgtypes(1),
  174. ));
  175. $this->pagination->initialize($config);
  176. $this->assign['pages'] = $this->pagination->create_links();
  177. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, NULL, $config['per_page'], (($page - 1) * $config['per_page']));
  178. $this->loadview(array('admin/menus', 'admin/msgtype/index'), $this->assign);
  179. }
  180. public function msgtype_add() {
  181. $this->loadview(array('admin/menus', 'admin/msgtype/add'), $this->assign);
  182. }
  183. public function msgtype_doadd() {
  184. $type_name = strip_some($this->input->post('type_name'));
  185. $desc = strip_some($this->input->post('description'));
  186. $for_reply = strip_some($this->input->post('for_reply'));
  187. $this->load->model('msgtype_model', 'mt');
  188. if (!chkval('text', $type_name, 1, 10)) {
  189. message(lang('error'), lang('err_msgtype_not_match_rule'), site_url('admin/msgtype_add'));
  190. }
  191. if (($for_reply != 0) && ($for_reply != 1)) {
  192. message(lang('error'), lang('err_invalid_data'), site_url('admin/msgtype_add'));
  193. }
  194. if ($this->mt->getMsgtype($type_name, 0)) {
  195. message(lang('error'), lang('err_msgtype_already_exist'), site_url('admin/msgtype_add'));
  196. }
  197. if ($this->mt->addMsgtype($type_name, $desc, $for_reply) > 0) {
  198. message(lang('notice'), lang('msgtype_add_success'), site_url('admin/msgtype_index'));
  199. }
  200. message(lang('error'), lang('err_msgtype_add_failed'), site_url('admin/msgtype_add'));
  201. }
  202. public function msgtype_dodel($msgtype_id) {
  203. $this->load->model('msgtype_model', 'mt');
  204. if (FALSE == $this->mt->getMsgtype($msgtype_id)) {
  205. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/msgtype_index'));
  206. }
  207. if (FALSE == $this->mt->delMsgtype($msgtype_id)) {
  208. message(lang('error'), lang('err_msgtype_del_failed'), site_url('admin/msgtype_index'));
  209. }
  210. message(lang('notice'), lang('msgtype_del_success'), site_url('admin/msgtype_index'));
  211. }
  212. public function msgtype_edit($msgtype_id) {
  213. $this->load->model('msgtype_model', 'mt');
  214. $m = $this->mt->getMsgtype($msgtype_id);
  215. if (FALSE == $m) {
  216. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/msgtype_index'));
  217. }
  218. $this->assign['msgtype'] = $m;
  219. $this->loadview(array('admin/menus', 'admin/msgtype/edit'), $this->assign);
  220. }
  221. public function msgtype_doedit() {
  222. $id = strip_some($this->input->post('id'));
  223. $type_name = strip_some($this->input->post('type_name'));
  224. $desc = strip_some($this->input->post('description'));
  225. $for_reply = strip_some($this->input->post('for_reply'));
  226. $this->load->model('msgtype_model', 'mt');
  227. if (!$this->mt->getMsgtype($id)) {
  228. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/msgtype_index'));
  229. }
  230. if (!chkval('text', $type_name, 1, 10)) {
  231. message(lang('error'), lang('err_msgtype_not_match_rule'), site_url('admin/msgtype_edit/' . $id));
  232. }
  233. if (($for_reply != 0) && ($for_reply != 1)) {
  234. message(lang('error'), lang('err_invalid_data'), site_url('admin/msgtype_edit/' . $id));
  235. }
  236. if ($this->mt->editMsgtype($id, $type_name, $desc, $for_reply)) {
  237. message(lang('notice'), lang('msgtype_edit_success'), site_url('admin/msgtype_index'));
  238. }
  239. message(lang('error'), lang('err_msgtype_edit_failed'), site_url('admin/msgtype_edit/' . $id));
  240. }
  241. public function keywords_index($page = 1) {
  242. //取整并判断页码
  243. $page = intval($page);
  244. if ($page < 1) {
  245. $page = 1;
  246. }
  247. $this->load->model('keywords_model', 'kw');
  248. //分页
  249. $config = array_merge($this->page_config, array(
  250. 'base_url' => site_url('admin/keywords_index'),
  251. 'total_rows' => $this->kw->getKeywords(1),
  252. ));
  253. $this->pagination->initialize($config);
  254. $this->assign['pages'] = $this->pagination->create_links();
  255. $keywords = $this->kw->getKeywords(0, NULL, $config['per_page'], (($page - 1) * $config['per_page']));
  256. //写入对应类型名
  257. $this->load->model('msgtype_model', 'mt');
  258. foreach ($keywords as $v) {
  259. $v->for_msgtype_name = $this->mt->getMsgtype($v->for_msgtype_id)->type_name;
  260. }
  261. $this->assign['keywords'] = $keywords;
  262. $this->loadview(array('admin/menus', 'admin/keywords/index'), $this->assign);
  263. }
  264. public function keywords_add() {
  265. $this->load->model('msgtype_model', 'mt');
  266. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, NULL);
  267. $this->loadview(array('admin/menus', 'admin/keywords/add'), $this->assign);
  268. }
  269. public function keywords_doadd() {
  270. $for_msgtype_id = strip_some($this->input->post('for_msgtype_id'));
  271. $keyword = strip_some($this->input->post('keyword'));
  272. $desc = strip_some($this->input->post('description'));
  273. $this->load->model('msgtype_model', 'mt');
  274. if (!$this->mt->getMsgtype($for_msgtype_id)) {
  275. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/keywords_add'));
  276. }
  277. if (!mb_strlen($keyword, 'UTF-8') > 100) {
  278. message(lang('error'), lang('err_keyword_not_match_rule'), site_url('admin/keywords_add'));
  279. }
  280. $this->load->model('keywords_model', 'kw');
  281. if ($this->kw->addKeyword($for_msgtype_id, $keyword, $desc) > 0) {
  282. message(lang('notice'), lang('keyword_add_success'), site_url('admin/keywords_index'));
  283. }
  284. message(lang('error'), lang('err_keyword_add_failed'), site_url('admin/keywords_add'));
  285. }
  286. public function keywords_edit($id) {
  287. $this->load->model('keywords_model', 'kw');
  288. $k = $this->kw->getKeyword($id)[0];
  289. if (FALSE == $k) {
  290. message(lang('error'), lang('err_keyword_not_exist'), site_url('admin/keywords_index'));
  291. }
  292. $this->assign['keyword'] = $k;
  293. $this->load->model('msgtype_model', 'mt');
  294. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, NULL);
  295. $this->loadview(array('admin/menus', 'admin/keywords/edit'), $this->assign);
  296. }
  297. public function keywords_doedit() {
  298. $id = strip_some($this->input->post('id'));
  299. $for_msgtype_id = strip_some($this->input->post('for_msgtype_id'));
  300. $keyword = strip_some($this->input->post('keyword'));
  301. $desc = strip_some($this->input->post('description'));
  302. $this->load->model('keywords_model', 'kw');
  303. if (!$this->kw->getKeyword($id)[0]) {
  304. message(lang('error'), lang('err_keyword_not_exist'), site_url('admin/keywords_index'));
  305. }
  306. $this->load->model('msgtype_model', 'mt');
  307. if (!$this->mt->getMsgtype($for_msgtype_id)) {
  308. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/keywords_edit/' . $id));
  309. }
  310. if (!mb_strlen($keyword, 'UTF-8') > 100) {
  311. message(lang('error'), lang('err_keyword_not_match_rule'), site_url('admin/keywords_edit/' . $id));
  312. }
  313. if ($this->kw->editKeyword($id, $keyword, $desc, $for_msgtype_id)) {
  314. message(lang('notice'), lang('keyword_edit_success'), site_url('admin/keywords_index'));
  315. }
  316. message(lang('error'), lang('err_keyword_edit_failed'), site_url('admin/keywords_edit/' . $id));
  317. }
  318. public function keywords_dodel($id) {
  319. $this->load->model('keywords_model', 'kw');
  320. if (FALSE == $this->kw->getKeyword($id, 1)) {
  321. message(lang('error'), lang('err_keyword_not_exist'), site_url('admin/keywords_index'));
  322. }
  323. if (FALSE == $this->kw->delKeyword($id)) {
  324. message(lang('error'), lang('err_keyword_del_failed'), site_url('admin/keywords_index'));
  325. }
  326. message(lang('notice'), lang('keyword_del_success'), site_url('admin/keywords_index'));
  327. }
  328. public function reply_index($page = 1) {
  329. //取整并判断页码
  330. $page = intval($page);
  331. if ($page < 1) {
  332. $page = 1;
  333. }
  334. $this->load->model('reply_model', 'rp');
  335. //分页
  336. $config = array_merge($this->page_config, array(
  337. 'base_url' => site_url('admin/reply_index'),
  338. 'total_rows' => $this->rp->getAll(1),
  339. ));
  340. $this->pagination->initialize($config);
  341. $this->assign['pages'] = $this->pagination->create_links();
  342. $r = $this->rp->getAll(0, $config['per_page'], (($page - 1) * $config['per_page']));
  343. //写入对应关键字名
  344. $this->load->model('keywords_model', 'kw');
  345. //写入对应类型名
  346. $this->load->model('msgtype_model', 'mt');
  347. foreach ($r as $v) {
  348. $v->msgtype_name = $this->mt->getMsgtype($v->reply_msgtype_id)->type_name;
  349. $v->for_keyword = $this->kw->getKeyword($v->for_key_id)[0]->keyword;
  350. }
  351. $this->assign['reply'] = $r;
  352. $this->loadview(array('admin/menus', 'admin/reply/index'), $this->assign);
  353. }
  354. public function reply_add() {
  355. $this->load->model('keywords_model', 'kw');
  356. $this->load->model('msgtype_model', 'mt');
  357. $this->assign['keywords'] = $this->kw->getKeywords();
  358. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, 1);
  359. $this->loadview(array('admin/menus', 'admin/reply/add'), $this->assign);
  360. }
  361. public function reply_doadd() {
  362. //检查关键字
  363. $kid = strip_some($this->input->post('keyword_id'));
  364. $this->load->model('keywords_model', 'kw');
  365. $k = $this->kw->getKeyword($kid)[0];
  366. if (!$k) {
  367. message(lang('error'), lang('err_keyword_not_exist'), site_url('admin/reply_add'));
  368. }
  369. $reply_msgtype_id = strip_some($this->input->post('reply_msgtype_id'));
  370. $this->load->model('msgtype_model', 'mt');
  371. //检查消息类型是否存在及是否可用于回复
  372. $mt = $this->mt->getMsgtype($reply_msgtype_id);
  373. if (!$mt || ($mt->for_reply == 0)) {
  374. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/reply_add'));
  375. }
  376. $content = strip_some($this->input->post('content'));
  377. $pic_url = strip_some($this->input->post('pic_url'));
  378. $link_url = strip_some($this->input->post('link_url'));
  379. $music_url = strip_some($this->input->post('music_url'));
  380. $hqmusic_url = strip_some($this->input->post('hqmusic_url'));
  381. switch ($mt->type_name) {
  382. case 'music':
  383. $title = strip_some($this->input->post('music_title'));
  384. $description = strip_some($this->input->post('music_description'));
  385. break;
  386. case 'news':
  387. $title = strip_some($this->input->post('news_title'));
  388. $description = strip_some($this->input->post('news_description'));
  389. break;
  390. default:
  391. $title = '';
  392. $description = '';
  393. break;
  394. }
  395. $this->load->model('reply_model', 'rp');
  396. if ($this->rp->addReply($kid, $reply_msgtype_id, $content, $title, $description, $pic_url, $link_url, $music_url, $hqmusic_url) > 0) {
  397. message(lang('notice'), lang('reply_add_success'), site_url('admin/reply_index'));
  398. }
  399. message(lang('error'), lang('err_reply_add_failed'), site_url('admin/reply_index'));
  400. }
  401. public function reply_dodel($id) {
  402. $this->load->model('reply_model', 'rp');
  403. if (FALSE == $this->rp->getReply($id)) {
  404. message(lang('error'), lang('err_reply_not_exist'), site_url('admin/reply_index'));
  405. }
  406. if (FALSE == $this->rp->delReply($id)) {
  407. message(lang('error'), lang('err_reply_del_failed'), site_url('admin/reply_index'));
  408. }
  409. message(lang('notice'), lang('reply_del_success'), site_url('admin/reply_index'));
  410. }
  411. public function reply_view($id) {
  412. $this->load->model('reply_model', 'rp');
  413. $r = $this->rp->getReply($id);
  414. if (FALSE == $r) {
  415. message(lang('error'), lang('err_reply_not_exist'), site_url('admin/reply_index'));
  416. }
  417. //写入对应关键字名
  418. $this->load->model('keywords_model', 'kw');
  419. //写入对应类型名
  420. $this->load->model('msgtype_model', 'mt');
  421. $r->msgtype_name = $this->mt->getMsgtype($r->reply_msgtype_id)->type_name;
  422. $r->for_keyword = $this->kw->getKeyword($r->for_key_id)[0]->keyword;
  423. $this->assign['reply'] = $r;
  424. $this->loadview(array('admin/menus', 'admin/reply/view'), $this->assign);
  425. }
  426. public function reply_edit($id) {
  427. $this->load->model('reply_model', 'rp');
  428. $r = $this->rp->getReply($id);
  429. if (FALSE == $r) {
  430. message(lang('error'), lang('err_reply_not_exist'), site_url('admin/reply_index'));
  431. }
  432. //写入对应关键字名
  433. $this->load->model('keywords_model', 'kw');
  434. //写入对应类型名
  435. $this->load->model('msgtype_model', 'mt');
  436. $r->msgtype_name = $this->mt->getMsgtype($r->reply_msgtype_id)->type_name;
  437. $r->for_keyword = $this->kw->getKeyword($r->for_key_id)[0]->keyword;
  438. $this->assign['reply'] = $r;
  439. $this->assign['keywords'] = $this->kw->getKeywords();
  440. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, 1);
  441. $this->loadview(array('admin/menus', 'admin/reply/edit'), $this->assign);
  442. }
  443. public function reply_doedit() {
  444. $id = strip_some($this->input->post('id'));
  445. //检查关键字
  446. $kid = strip_some($this->input->post('keyword_id'));
  447. $this->load->model('keywords_model', 'kw');
  448. $k = $this->kw->getKeyword($kid)[0];
  449. if (!$k) {
  450. message(lang('error'), lang('err_keyword_not_exist'), site_url('admin/reply_edit/' . $id));
  451. }
  452. $reply_msgtype_id = strip_some($this->input->post('reply_msgtype_id'));
  453. $this->load->model('msgtype_model', 'mt');
  454. //检查消息类型是否存在及是否可用于回复
  455. $mt = $this->mt->getMsgtype($reply_msgtype_id);
  456. if (!$mt || ($mt->for_reply == 0)) {
  457. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/reply_edit/' . $id));
  458. }
  459. $content = strip_some($this->input->post('content'));
  460. $pic_url = strip_some($this->input->post('pic_url'));
  461. $link_url = strip_some($this->input->post('link_url'));
  462. $music_url = strip_some($this->input->post('music_url'));
  463. $hqmusic_url = strip_some($this->input->post('hqmusic_url'));
  464. switch ($mt->type_name) {
  465. case 'music':
  466. $title = strip_some($this->input->post('music_title'));
  467. $description = strip_some($this->input->post('music_description'));
  468. break;
  469. case 'news':
  470. $title = strip_some($this->input->post('news_title'));
  471. $description = strip_some($this->input->post('news_description'));
  472. break;
  473. default:
  474. $title = '';
  475. $description = '';
  476. break;
  477. }
  478. $this->load->model('reply_model', 'rp');
  479. if ($this->rp->editReply($id, $kid, $reply_msgtype_id, $content, $title, $description, $pic_url, $link_url, $music_url, $hqmusic_url) > 0) {
  480. message(lang('notice'), lang('reply_edit_success'), site_url('admin/reply_index'));
  481. }
  482. message(lang('error'), lang('err_reply_edit_failed'), site_url('admin/reply_index'));
  483. }
  484. public function commands_index($page = 1) {
  485. //取整并判断页码
  486. $page = intval($page);
  487. if ($page < 1) {
  488. $page = 1;
  489. }
  490. $this->load->model('commands_model', 'cmd');
  491. //分页
  492. $config = array_merge($this->page_config, array(
  493. 'base_url' => site_url('admin/commands_index'),
  494. 'total_rows' => $this->cmd->getAll(1),
  495. ));
  496. $this->pagination->initialize($config);
  497. $this->assign['pages'] = $this->pagination->create_links();
  498. $c = $this->cmd->getAll(0, $config['per_page'], (($page - 1) * $config['per_page']));
  499. //写入对应类型名
  500. //写入父命令
  501. $this->load->model('msgtype_model', 'mt');
  502. foreach ($c as $v) {
  503. $v->reply_msgtype_name = $this->mt->getMsgtype($v->reply_msgtype_id)->type_name;
  504. if ($v->p_cmd_id > 0) {
  505. $v->parent_command = $this->cmd->get($v->p_cmd_id, 1)->command;
  506. }
  507. }
  508. $this->assign['commands'] = $c;
  509. $this->loadview(array('admin/menus', 'admin/commands/index'), $this->assign);
  510. }
  511. public function commands_add() {
  512. $this->load->model('commands_model', 'cmd');
  513. $this->load->model('msgtype_model', 'mt');
  514. $this->assign['commands'] = $this->cmd->getAll(0);
  515. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, 1);
  516. $this->loadview(array('admin/menus', 'admin/commands/add'), $this->assign);
  517. }
  518. public function commands_doadd() {
  519. //检查父命令
  520. $pid = intval(strip_some($this->input->post('parent_command_id')));
  521. $this->load->model('commands_model', 'cmd');
  522. if ($pid > 0) {
  523. $p = $this->cmd->get($pid);
  524. if (!$p) {
  525. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_add'));
  526. }
  527. }
  528. $reply_msgtype_id = strip_some($this->input->post('reply_msgtype_id'));
  529. $this->load->model('msgtype_model', 'mt');
  530. //检查消息类型是否存在及是否可用于回复
  531. $mt = $this->mt->getMsgtype($reply_msgtype_id);
  532. if (!$mt || ($mt->for_reply == 0)) {
  533. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/commands_add'));
  534. }
  535. $command = strip_some($this->input->post('command'));
  536. $data_regex = strip_some($this->input->post('data_regex'));
  537. $is_expire = strip_some($this->input->post('is_expire'));
  538. $is_with_plugin = strip_some($this->input->post('is_with_plugin'));
  539. $plugin_name = strip_some($this->input->post('plugin_name'));
  540. $plugin_function = strip_some($this->input->post('plugin_function'));
  541. $content = strip_some($this->input->post('content'));
  542. $pic_url = strip_some($this->input->post('pic_url'));
  543. $link_url = strip_some($this->input->post('link_url'));
  544. $music_url = strip_some($this->input->post('music_url'));
  545. $hqmusic_url = strip_some($this->input->post('hqmusic_url'));
  546. switch ($mt->type_name) {
  547. case 'music':
  548. $title = strip_some($this->input->post('music_title'));
  549. $description = strip_some($this->input->post('music_description'));
  550. break;
  551. case 'news':
  552. $title = strip_some($this->input->post('news_title'));
  553. $description = strip_some($this->input->post('news_description'));
  554. break;
  555. default:
  556. $title = '';
  557. $description = '';
  558. break;
  559. }
  560. if ($this->cmd->add($command, $pid, $data_regex, $is_expire, $is_with_plugin, $plugin_name, $plugin_function, $reply_msgtype_id, $content, $title, $description, $pic_url, $link_url, $music_url, $hqmusic_url) > 0) {
  561. message(lang('notice'), lang('command_add_success'), site_url('admin/commands_index'));
  562. }
  563. message(lang('error'), lang('err_command_add_failed'), site_url('admin/commands_index'));
  564. }
  565. public function commands_view($id) {
  566. $this->load->model('commands_model', 'cmd');
  567. $c = $this->cmd->get($id);
  568. if (FALSE == $c) {
  569. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_index'));
  570. }
  571. //写入回复类型及判断写入父命令
  572. $this->load->model('msgtype_model', 'mt');
  573. $c->reply_msgtype_name = $this->mt->getMsgtype($c->reply_msgtype_id)->type_name;
  574. if ($c->p_cmd_id > 0) {
  575. $c->parent_command = $this->cmd->get($c->p_cmd_id)->command;
  576. }
  577. $this->assign['command'] = $c;
  578. $this->loadview(array('admin/menus', 'admin/commands/view'), $this->assign);
  579. }
  580. public function commands_edit($id) {
  581. $this->load->model('commands_model', 'cmd');
  582. $c = $this->cmd->get($id);
  583. if (FALSE == $c) {
  584. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_index'));
  585. }
  586. //写入对应类型名,父命令
  587. $this->load->model('msgtype_model', 'mt');
  588. $c->reply_msgtype_name = $this->mt->getMsgtype($c->reply_msgtype_id)->type_name;
  589. if ($c->p_cmd_id > 0) {
  590. $c->parent_command = $this->cmd->get($c->p_cmd_id)->command;
  591. }
  592. $this->assign['command'] = $c;
  593. $this->assign['commands'] = $this->cmd->getAll();
  594. $this->load->model('keywords_model', 'kw');
  595. $this->assign['keywords'] = $this->kw->getKeywords();
  596. $this->assign['msgtype'] = $this->mt->getMsgtypes(0, 1);
  597. $this->loadview(array('admin/menus', 'admin/commands/edit'), $this->assign);
  598. }
  599. public function commands_doedit() {
  600. //检查存在
  601. $id = intval(strip_some($this->input->post('id')));
  602. $this->load->model('commands_model', 'cmd');
  603. if ($id > 0) {
  604. $c = $this->cmd->get($id);
  605. if (!$c) {
  606. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_edit/' . $id));
  607. }
  608. }
  609. //检查父命令
  610. $pid = intval(strip_some($this->input->post('parent_command_id')));
  611. if ($pid > 0) {
  612. $p = $this->cmd->get($pid);
  613. if (!$p) {
  614. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_edit/' . $id));
  615. }
  616. }
  617. $reply_msgtype_id = strip_some($this->input->post('reply_msgtype_id'));
  618. $this->load->model('msgtype_model', 'mt');
  619. //检查消息类型是否存在及是否可用于回复
  620. $mt = $this->mt->getMsgtype($reply_msgtype_id);
  621. if (!$mt || ($mt->for_reply == 0)) {
  622. message(lang('error'), lang('err_msgtype_not_exist'), site_url('admin/commands_edit/' . $id));
  623. }
  624. $command = strip_some($this->input->post('command'));
  625. $data_regex = strip_some($this->input->post('data_regex'));
  626. $is_expire = strip_some($this->input->post('is_expire'));
  627. $is_with_plugin = strip_some($this->input->post('is_with_plugin'));
  628. $plugin_name = strip_some($this->input->post('plugin_name'));
  629. $plugin_function = strip_some($this->input->post('plugin_function'));
  630. $content = strip_some($this->input->post('content'));
  631. $pic_url = strip_some($this->input->post('pic_url'));
  632. $link_url = strip_some($this->input->post('link_url'));
  633. $music_url = strip_some($this->input->post('music_url'));
  634. $hqmusic_url = strip_some($this->input->post('hqmusic_url'));
  635. switch ($mt->type_name) {
  636. case 'music':
  637. $title = strip_some($this->input->post('music_title'));
  638. $description = strip_some($this->input->post('music_description'));
  639. break;
  640. case 'news':
  641. $title = strip_some($this->input->post('news_title'));
  642. $description = strip_some($this->input->post('news_description'));
  643. break;
  644. default:
  645. $title = '';
  646. $description = '';
  647. break;
  648. }
  649. if ($this->cmd->edit($id, $command, $pid, $data_regex, $is_expire, $is_with_plugin, $plugin_name, $plugin_function, $reply_msgtype_id, $content, $title, $description, $pic_url, $link_url, $music_url, $hqmusic_url)) {
  650. message(lang('notice'), lang('command_edit_success'), site_url('admin/commands_index'));
  651. }
  652. message(lang('error'), lang('err_command_edit_failed'), site_url('admin/commands_edit/' . $id));
  653. }
  654. public function commands_dodel($id) {
  655. $this->load->model('commands_model', 'cmd');
  656. if (FALSE == $this->cmd->get($id)) {
  657. message(lang('error'), lang('err_command_not_exist'), site_url('admin/commands_index'));
  658. }
  659. if (FALSE == $this->cmd->del($id)) {
  660. message(lang('error'), lang('err_command_del_failed'), site_url('admin/commands_index'));
  661. }
  662. message(lang('notice'), lang('command_del_success'), site_url('admin/commands_index'));
  663. }
  664. public function ajax() {
  665. $do = $this->input->post('do');
  666. $rd = array(
  667. 'status' => 'false'
  668. );
  669. switch ($do) {
  670. case 'getkeyword':
  671. $this->load->model('keywords_model', 'kw');
  672. $id = strip_some($this->input->post('id'));
  673. $k = $this->kw->getKeyword($id)[0];
  674. if ($k) {
  675. $rd = array(
  676. 'status' => 'success',
  677. 'data' => $k->keyword,
  678. );
  679. }
  680. break;
  681. case 'getcommand':
  682. $this->load->model('commands_model', 'cmd');
  683. $id = strip_some($this->input->post('id'));
  684. $c = $this->cmd->get($id);
  685. if ($c) {
  686. $rd = array(
  687. 'status' => 'success',
  688. 'data' => $c->command,
  689. );
  690. }
  691. break;
  692. default:
  693. $rd = array(
  694. 'status' => 'error',
  695. 'msg' => 'unknown commond'
  696. );
  697. break;
  698. }
  699. echo json_encode($rd);
  700. }
  701. }