PageRenderTime 70ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/modcp.php

https://bitbucket.org/KamranMackey/mybb
PHP | 3485 lines | 3105 code | 285 blank | 95 comment | 411 complexity | 18af37e26dd3e0b23276447ac16e8228 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * MyBB 1.6
  4. * Copyright 2010 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://mybb.com
  7. * License: http://mybb.com/about/license
  8. *
  9. * $Id$
  10. */
  11. define("IN_MYBB", 1);
  12. define('THIS_SCRIPT', 'modcp.php');
  13. $templatelist = "modcp_reports,modcp_reports_report,modcp_reports_multipage,modcp_reports_allreport";
  14. $templatelist .= ",modcp_reports_allnoreports,modcp_reports_noreports,modcp_banning,modcp_banning_ban";
  15. $templatelist .= ",modcp_banning_multipage,modcp_banning_nobanned,modcp_banning_auser,modcp_banning_error";
  16. $templatelist .= ",modcp_banning_edit,modcp_banning_banned_user,modcp_nav,modcp_modlogs_noresults,modcp";
  17. $templatelist .= ",modcp_no_announcements_global,modcp_announcements_global,modcp_announcements_forum,modcp_announcements";
  18. $templatelist .= ",codebuttons,smilieinsert,modcp_announcements_new,modcp_modqueue_empty,forumjump_bit,forumjump_special";
  19. $templatelist .= ",modcp_modlogs,modcp_finduser_user,modcp_finduser,usercp_profile_customfield,usercp_profile_profilefields";
  20. $templatelist .= ",modcp_editprofile,modcp_ipsearch,modcp_banuser_addusername,modcp_banuser,modcp_warninglogs_nologs";
  21. $templatelist .= ",modcp_warninglogs,modcp_modlogs_result,modcp_editprofile_signature_info,modcp_editprofile_signature_options,modcp_editprofile_signature";
  22. require_once "./global.php";
  23. require_once MYBB_ROOT."inc/functions_user.php";
  24. require_once MYBB_ROOT."inc/functions_upload.php";
  25. require_once MYBB_ROOT."inc/functions_modcp.php";
  26. require_once MYBB_ROOT."inc/class_parser.php";
  27. $parser = new postParser;
  28. // Set up the array of ban times.
  29. $bantimes = fetch_ban_times();
  30. // Load global language phrases
  31. $lang->load("modcp");
  32. if($mybb->user['uid'] == 0 || $mybb->usergroup['canmodcp'] != 1)
  33. {
  34. error_no_permission();
  35. }
  36. $errors = '';
  37. // SQL for fetching items only related to forums this user moderates
  38. $moderated_forums = array();
  39. if($mybb->usergroup['issupermod'] != 1)
  40. {
  41. $query = $db->simple_select("moderators", "*", "(id='{$mybb->user['uid']}' AND isgroup = '0') OR (id='{$mybb->user['usergroup']}' AND isgroup = '1')");
  42. while($forum = $db->fetch_array($query))
  43. {
  44. $flist .= ",'{$forum['fid']}'";
  45. $children = get_child_list($forum['fid']);
  46. if(!empty($children))
  47. {
  48. $flist .= ",'".implode("','", $children)."'";
  49. }
  50. $moderated_forums[] = $forum['fid'];
  51. }
  52. if($flist)
  53. {
  54. $tflist = " AND t.fid IN (0{$flist})";
  55. $flist = " AND fid IN (0{$flist})";
  56. }
  57. }
  58. else
  59. {
  60. $flist = $tflist = '';
  61. }
  62. // Retrieve a list of unviewable forums
  63. $unviewableforums = get_unviewable_forums();
  64. if($unviewableforums && !is_super_admin($mybb->user['uid']))
  65. {
  66. $flist .= " AND fid NOT IN ({$unviewableforums})";
  67. $tflist .= " AND t.fid NOT IN ({$unviewableforums})";
  68. $unviewableforums = str_replace("'", '', $unviewableforums);
  69. $unviewableforums = explode(',', $unviewableforums);
  70. }
  71. // Fetch the Mod CP menu
  72. eval("\$modcp_nav = \"".$templates->get("modcp_nav")."\";");
  73. $plugins->run_hooks("modcp_start");
  74. // Make navigation
  75. add_breadcrumb($lang->nav_modcp, "modcp.php");
  76. if($mybb->input['action'] == "do_reports")
  77. {
  78. // Verify incoming POST request
  79. verify_post_check($mybb->input['my_post_key']);
  80. if(!is_array($mybb->input['reports']))
  81. {
  82. error($lang->error_noselected_reports);
  83. }
  84. $sql = '1=1';
  85. if(!$mybb->input['allbox'])
  86. {
  87. $mybb->input['reports'] = array_map("intval", $mybb->input['reports']);
  88. $rids = implode($mybb->input['reports'], "','");
  89. $rids = "'0','{$rids}'";
  90. $sql = "rid IN ({$rids})";
  91. }
  92. $plugins->run_hooks("modcp_do_reports");
  93. $db->update_query("reportedposts", array('reportstatus' => 1), "{$sql}{$flist}");
  94. $cache->update_reportedposts();
  95. $page = intval($mybb->input['page']);
  96. redirect("modcp.php?action=reports&page={$page}", $lang->redirect_reportsmarked);
  97. }
  98. if($mybb->input['action'] == "reports")
  99. {
  100. add_breadcrumb($lang->mcp_nav_reported_posts, "modcp.php?action=reports");
  101. if(!$mybb->settings['threadsperpage'])
  102. {
  103. $mybb->settings['threadsperpage'] = 20;
  104. }
  105. // Figure out if we need to display multiple pages.
  106. $perpage = $mybb->settings['threadsperpage'];
  107. if($mybb->input['page'] != "last")
  108. {
  109. $page = intval($mybb->input['page']);
  110. }
  111. $query = $db->simple_select("reportedposts", "COUNT(rid) AS count", "reportstatus ='0'");
  112. $report_count = $db->fetch_field($query, "count");
  113. $mybb->input['rid'] = intval($mybb->input['rid']);
  114. if($mybb->input['rid'])
  115. {
  116. $query = $db->simple_select("reportedposts", "COUNT(rid) AS count", "rid <= '".$mybb->input['rid']."'");
  117. $result = $db->fetch_field($query, "count");
  118. if(($result % $perpage) == 0)
  119. {
  120. $page = $result / $perpage;
  121. }
  122. else
  123. {
  124. $page = intval($result / $perpage) + 1;
  125. }
  126. }
  127. $postcount = intval($report_count);
  128. $pages = $postcount / $perpage;
  129. $pages = ceil($pages);
  130. if($mybb->input['page'] == "last")
  131. {
  132. $page = $pages;
  133. }
  134. if($page > $pages || $page <= 0)
  135. {
  136. $page = 1;
  137. }
  138. if($page && $page > 0)
  139. {
  140. $start = ($page-1) * $perpage;
  141. }
  142. else
  143. {
  144. $start = 0;
  145. $page = 1;
  146. }
  147. $upper = $start+$perpage;
  148. $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=reports");
  149. if($postcount > $perpage)
  150. {
  151. eval("\$reportspages = \"".$templates->get("modcp_reports_multipage")."\";");
  152. }
  153. $query = $db->simple_select("forums", "fid, name");
  154. while($forum = $db->fetch_array($query))
  155. {
  156. $forums[$forum['fid']] = $forum['name'];
  157. }
  158. $plugins->run_hooks("modcp_reports_start");
  159. $reports = '';
  160. $query = $db->query("
  161. SELECT r.*, u.username, up.username AS postusername, up.uid AS postuid, t.subject AS threadsubject
  162. FROM ".TABLE_PREFIX."reportedposts r
  163. LEFT JOIN ".TABLE_PREFIX."posts p ON (r.pid=p.pid)
  164. LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
  165. LEFT JOIN ".TABLE_PREFIX."users u ON (r.uid=u.uid)
  166. LEFT JOIN ".TABLE_PREFIX."users up ON (p.uid=up.uid)
  167. WHERE r.reportstatus='0'
  168. ORDER BY r.dateline DESC
  169. LIMIT {$start}, {$perpage}
  170. ");
  171. if(!$db->num_rows($query))
  172. {
  173. eval("\$reports = \"".$templates->get("modcp_reports_noreports")."\";");
  174. }
  175. else
  176. {
  177. while($report = $db->fetch_array($query))
  178. {
  179. $trow = alt_trow();
  180. if(is_moderator($report['fid']))
  181. {
  182. $trow = 'trow_shaded';
  183. }
  184. $report['postlink'] = get_post_link($report['pid'], $report['tid']);
  185. $report['threadlink'] = get_thread_link($report['tid']);
  186. $report['posterlink'] = get_profile_link($report['postuid']);
  187. $report['reporterlink'] = get_profile_link($report['uid']);
  188. $reportdate = my_date($mybb->settings['dateformat'], $report['dateline']);
  189. $reporttime = my_date($mybb->settings['timeformat'], $report['dateline']);
  190. $report['threadsubject'] = htmlspecialchars_uni($parser->parse_badwords($report['threadsubject']));
  191. eval("\$reports .= \"".$templates->get("modcp_reports_report")."\";");
  192. }
  193. }
  194. $plugins->run_hooks("modcp_reports_end");
  195. eval("\$reportedposts = \"".$templates->get("modcp_reports")."\";");
  196. output_page($reportedposts);
  197. }
  198. if($mybb->input['action'] == "allreports")
  199. {
  200. add_breadcrumb($lang->mcp_nav_all_reported_posts, "modcp.php?action=allreports");
  201. if(!$mybb->settings['threadsperpage'])
  202. {
  203. $mybb->settings['threadsperpage'] = 20;
  204. }
  205. // Figure out if we need to display multiple pages.
  206. $perpage = $mybb->settings['threadsperpage'];
  207. if($mybb->input['page'] != "last")
  208. {
  209. $page = intval($mybb->input['page']);
  210. }
  211. $query = $db->simple_select("reportedposts", "COUNT(rid) AS count");
  212. $warnings = $db->fetch_field($query, "count");
  213. if($mybb->input['rid'])
  214. {
  215. $mybb->input['rid'] = intval($mybb->input['rid']);
  216. $query = $db->simple_select("reportedposts", "COUNT(rid) AS count", "rid <= '".$mybb->input['rid']."'");
  217. $result = $db->fetch_field($query, "count");
  218. if(($result % $perpage) == 0)
  219. {
  220. $page = $result / $perpage;
  221. }
  222. else
  223. {
  224. $page = intval($result / $perpage) + 1;
  225. }
  226. }
  227. $postcount = intval($warnings);
  228. $pages = $postcount / $perpage;
  229. $pages = ceil($pages);
  230. if($mybb->input['page'] == "last")
  231. {
  232. $page = $pages;
  233. }
  234. if($page > $pages || $page <= 0)
  235. {
  236. $page = 1;
  237. }
  238. if($page)
  239. {
  240. $start = ($page-1) * $perpage;
  241. }
  242. else
  243. {
  244. $start = 0;
  245. $page = 1;
  246. }
  247. $upper = $start+$perpage;
  248. $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=allreports");
  249. if($postcount > $perpage)
  250. {
  251. eval("\$allreportspages = \"".$templates->get("modcp_reports_multipage")."\";");
  252. }
  253. $plugins->run_hooks("modcp_allreports_start");
  254. $query = $db->query("
  255. SELECT r.*, u.username, up.username AS postusername, up.uid AS postuid, t.subject AS threadsubject
  256. FROM ".TABLE_PREFIX."reportedposts r
  257. LEFT JOIN ".TABLE_PREFIX."posts p ON (r.pid=p.pid)
  258. LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
  259. LEFT JOIN ".TABLE_PREFIX."users u ON (r.uid=u.uid)
  260. LEFT JOIN ".TABLE_PREFIX."users up ON (p.uid=up.uid)
  261. ORDER BY r.dateline DESC
  262. LIMIT {$start}, {$perpage}
  263. ");
  264. $allreports = '';
  265. if(!$db->num_rows($query))
  266. {
  267. eval("\$allreports = \"".$templates->get("modcp_reports_allnoreports")."\";");
  268. }
  269. else
  270. {
  271. while($report = $db->fetch_array($query))
  272. {
  273. $trow = alt_trow();
  274. $report['threadsubject'] = $lang->na;
  275. $report['threadlink'] = get_thread_link($report['tid']);
  276. $report['posterlink'] = get_profile_link($report['postuid']);
  277. $report['postlink'] = get_post_link($report['pid'], $report['tid']);
  278. $report['postusername'] = build_profile_link($report['postusername'], $report['postuid']);
  279. $report['reporterlink'] = get_profile_link($report['uid']);
  280. $reportdate = my_date($mybb->settings['dateformat'], $report['dateline']);
  281. $reporttime = my_date($mybb->settings['timeformat'], $report['dateline']);
  282. if($report['reportstatus'] == 0)
  283. {
  284. $trow = "trow_shaded";
  285. }
  286. if($report['threadsubject'])
  287. {
  288. $report['threadsubject'] = htmlspecialchars_uni($parser->parse_badwords($report['threadsubject']));
  289. $report['threadsubject'] = "<a href=\"".get_thread_link($report['tid'])."\" target=\"_blank\">{$report['threadsubject']}</a>";
  290. }
  291. eval("\$allreports .= \"".$templates->get("modcp_reports_allreport")."\";");
  292. }
  293. }
  294. $plugins->run_hooks("modcp_allreports_end");
  295. eval("\$allreportedposts = \"".$templates->get("modcp_reports_allreports")."\";");
  296. output_page($allreportedposts);
  297. }
  298. if($mybb->input['action'] == "modlogs")
  299. {
  300. add_breadcrumb($lang->mcp_nav_modlogs, "modcp.php?action=modlogs");
  301. $perpage = intval($mybb->input['perpage']);
  302. if(!$perpage || $perpage <= 0)
  303. {
  304. $perpage = $mybb->settings['threadsperpage'];
  305. }
  306. $where = '';
  307. // Searching for entries by a particular user
  308. if($mybb->input['uid'])
  309. {
  310. $where .= " AND l.uid='".intval($mybb->input['uid'])."'";
  311. }
  312. // Searching for entries in a specific forum
  313. if($mybb->input['fid'])
  314. {
  315. $where .= " AND t.fid='".intval($mybb->input['fid'])."'";
  316. }
  317. // Order?
  318. switch($mybb->input['sortby'])
  319. {
  320. case "username":
  321. $sortby = "u.username";
  322. break;
  323. case "forum":
  324. $sortby = "f.name";
  325. break;
  326. case "thread":
  327. $sortby = "t.subject";
  328. break;
  329. default:
  330. $sortby = "l.dateline";
  331. }
  332. $order = $mybb->input['order'];
  333. if($order != "asc")
  334. {
  335. $order = "desc";
  336. }
  337. $plugins->run_hooks("modcp_modlogs_start");
  338. $query = $db->query("
  339. SELECT COUNT(l.dateline) AS count
  340. FROM ".TABLE_PREFIX."moderatorlog l
  341. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
  342. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
  343. WHERE 1=1 {$where}{$tflist}
  344. ");
  345. $rescount = $db->fetch_field($query, "count");
  346. // Figure out if we need to display multiple pages.
  347. if($mybb->input['page'] != "last")
  348. {
  349. $page = intval($mybb->input['page']);
  350. }
  351. $postcount = intval($rescount);
  352. $pages = $postcount / $perpage;
  353. $pages = ceil($pages);
  354. if($mybb->input['page'] == "last")
  355. {
  356. $page = $pages;
  357. }
  358. if($page > $pages || $page <= 0)
  359. {
  360. $page = 1;
  361. }
  362. if($page)
  363. {
  364. $start = ($page-1) * $perpage;
  365. }
  366. else
  367. {
  368. $start = 0;
  369. $page = 1;
  370. }
  371. $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=modlogs&amp;perpage=$perpage&amp;uid={$mybb->input['uid']}&amp;fid={$mybb->input['fid']}&amp;sortby={$mybb->input['sortby']}&amp;order={$mybb->input['order']}");
  372. if($postcount > $perpage)
  373. {
  374. eval("\$resultspages = \"".$templates->get("modcp_modlogs_multipage")."\";");
  375. }
  376. $query = $db->query("
  377. SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject
  378. FROM ".TABLE_PREFIX."moderatorlog l
  379. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
  380. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
  381. LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid)
  382. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid)
  383. WHERE 1=1 {$where}{$tflist}
  384. ORDER BY {$sortby} {$order}
  385. LIMIT {$start}, {$perpage}
  386. ");
  387. while($logitem = $db->fetch_array($query))
  388. {
  389. $information = '';
  390. $logitem['action'] = htmlspecialchars_uni($logitem['action']);
  391. $log_date = my_date($mybb->settings['dateformat'], $logitem['dateline']);
  392. $log_time = my_date($mybb->settings['timeformat'], $logitem['dateline']);
  393. $trow = alt_trow();
  394. $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']);
  395. $logitem['profilelink'] = build_profile_link($username, $logitem['uid']);
  396. if($logitem['tsubject'])
  397. {
  398. $information = "<strong>{$lang->thread}</strong> <a href=\"".get_thread_link($logitem['tid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['tsubject'])."</a><br />";
  399. }
  400. if($logitem['fname'])
  401. {
  402. $information .= "<strong>{$lang->forum}</strong> <a href=\"".get_forum_link($logitem['fid'])."\" target=\"_blank\">{$logitem['fname']}</a><br />";
  403. }
  404. if($logitem['psubject'])
  405. {
  406. $information .= "<strong>{$lang->post}</strong> <a href=\"".get_post_link($logitem['pid'])."#pid{$logitem['pid']}\">".htmlspecialchars_uni($logitem['psubject'])."</a>";
  407. }
  408. // Edited a user?
  409. if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject'])
  410. {
  411. $data = unserialize($logitem['data']);
  412. if($data['uid'])
  413. {
  414. $information = $lang->sprintf($lang->edited_user_info, htmlspecialchars_uni($data['username']), get_profile_link($data['uid']));
  415. }
  416. }
  417. eval("\$results .= \"".$templates->get("modcp_modlogs_result")."\";");
  418. }
  419. if(!$results)
  420. {
  421. eval("\$results = \"".$templates->get("modcp_modlogs_noresults")."\";");
  422. }
  423. $plugins->run_hooks("modcp_modlogs_filter");
  424. // Fetch filter options
  425. $sortbysel[$mybb->input['sortby']] = "selected=\"selected\"";
  426. $ordersel[$mybb->input['order']] = "selected=\"selected\"";
  427. $query = $db->query("
  428. SELECT DISTINCT l.uid, u.username
  429. FROM ".TABLE_PREFIX."moderatorlog l
  430. LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid)
  431. ORDER BY u.username ASC
  432. ");
  433. while($user = $db->fetch_array($query))
  434. {
  435. // Deleted Users
  436. if(!$user['username'])
  437. {
  438. $user['username'] = $lang->na_deleted;
  439. }
  440. $selected = '';
  441. if($mybb->input['uid'] == $user['uid'])
  442. {
  443. $selected = " selected=\"selected\"";
  444. }
  445. $user_options .= "<option value=\"{$user['uid']}\"{$selected}>".htmlspecialchars_uni($user['username'])."</option>\n";
  446. }
  447. $forum_select = build_forum_jump("", $mybb->input['fid'], 1, '', 0, true, '', "fid");
  448. eval("\$modlogs = \"".$templates->get("modcp_modlogs")."\";");
  449. output_page($modlogs);
  450. }
  451. if($mybb->input['action'] == "do_delete_announcement")
  452. {
  453. verify_post_check($mybb->input['my_post_key']);
  454. $aid = intval($mybb->input['aid']);
  455. $query = $db->simple_select("announcements", "aid, subject, fid", "aid='{$aid}'");
  456. $announcement = $db->fetch_array($query);
  457. if(!$announcement['aid'])
  458. {
  459. error($lang->error_invalid_announcement);
  460. }
  461. if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'])) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  462. {
  463. error_no_permission();
  464. }
  465. $plugins->run_hooks("modcp_do_delete_announcement");
  466. $db->delete_query("announcements", "aid='{$aid}'");
  467. $cache->update_forumsdisplay();
  468. redirect("modcp.php?action=announcements", $lang->redirect_delete_announcement);
  469. }
  470. if($mybb->input['action'] == "delete_announcement")
  471. {
  472. $aid = intval($mybb->input['aid']);
  473. $query = $db->simple_select("announcements", "aid, subject, fid", "aid='{$aid}'");
  474. $announcement = $db->fetch_array($query);
  475. $announcement['subject'] = htmlspecialchars_uni($announcement['subject']);
  476. if(!$announcement['aid'])
  477. {
  478. error($lang->error_invalid_announcement);
  479. }
  480. if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'])) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  481. {
  482. error_no_permission();
  483. }
  484. $plugins->run_hooks("modcp_delete_announcement");
  485. eval("\$announcements = \"".$templates->get("modcp_announcements_delete")."\";");
  486. output_page($announcements);
  487. }
  488. if($mybb->input['action'] == "do_new_announcement")
  489. {
  490. verify_post_check($mybb->input['my_post_key']);
  491. $announcement_fid = intval($mybb->input['fid']);
  492. if(($mybb->usergroup['issupermod'] != 1 && $announcement_fid == -1) || ($announcement_fid != -1 && !is_moderator($announcement_fid)) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  493. {
  494. error_no_permission();
  495. }
  496. if(!trim($mybb->input['title']))
  497. {
  498. $errors[] = $lang->error_missing_title;
  499. }
  500. if(!trim($mybb->input['message']))
  501. {
  502. $errors[] = $lang->error_missing_message;
  503. }
  504. if(!trim($mybb->input['fid']))
  505. {
  506. $errors[] = $lang->error_missing_forum;
  507. }
  508. $startdate = @explode(" ", $mybb->input['starttime_time']);
  509. $startdate = @explode(":", $startdate[0]);
  510. $enddate = @explode(" ", $mybb->input['endtime_time']);
  511. $enddate = @explode(":", $enddate[0]);
  512. if(stristr($mybb->input['starttime_time'], "pm"))
  513. {
  514. $startdate[0] = 12+$startdate[0];
  515. if($startdate[0] >= 24)
  516. {
  517. $startdate[0] = "00";
  518. }
  519. }
  520. if(stristr($mybb->input['endtime_time'], "pm"))
  521. {
  522. $enddate[0] = 12+$enddate[0];
  523. if($enddate[0] >= 24)
  524. {
  525. $enddate[0] = "00";
  526. }
  527. }
  528. $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  529. if(!in_array($mybb->input['starttime_month'], $months))
  530. {
  531. $mybb->input['starttime_month'] = 1;
  532. }
  533. $startdate = gmmktime(intval($startdate[0]), intval($startdate[1]), 0, (int)$mybb->input['starttime_month'], intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year']));
  534. if($startdate < 0 || $startdate == false)
  535. {
  536. $errors[] = $lang->error_invalid_start_date;
  537. }
  538. if($mybb->input['endtime_type'] == "2")
  539. {
  540. $enddate = '0';
  541. }
  542. else
  543. {
  544. if(!in_array($mybb->input['endtime_month'], $months))
  545. {
  546. $mybb->input['endtime_month'] = 1;
  547. }
  548. $enddate = gmmktime(intval($enddate[0]), intval($enddate[1]), 0, (int)$mybb->input['endtime_month'], intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year']));
  549. if($enddate < 0 || $enddate == false)
  550. {
  551. $errors[] = $lang->error_invalid_end_date;
  552. }
  553. elseif($enddate < $startdate)
  554. {
  555. $errors[] = $lang->error_end_before_start;
  556. }
  557. }
  558. $plugins->run_hooks("modcp_do_new_announcement_start");
  559. if(!$errors)
  560. {
  561. $insert_announcement = array(
  562. 'fid' => $announcement_fid,
  563. 'uid' => $mybb->user['uid'],
  564. 'subject' => $db->escape_string($mybb->input['title']),
  565. 'message' => $db->escape_string($mybb->input['message']),
  566. 'startdate' => $startdate,
  567. 'enddate' => $enddate,
  568. 'allowhtml' => $db->escape_string($mybb->input['allowhtml']),
  569. 'allowmycode' => $db->escape_string($mybb->input['allowmycode']),
  570. 'allowsmilies' => $db->escape_string($mybb->input['allowsmilies']),
  571. );
  572. $aid = $db->insert_query("announcements", $insert_announcement);
  573. $plugins->run_hooks("modcp_do_new_announcement_end");
  574. $cache->update_forumsdisplay();
  575. redirect("modcp.php?action=announcements", $lang->redirect_add_announcement);
  576. }
  577. else
  578. {
  579. $mybb->input['action'] = 'new_announcement';
  580. }
  581. }
  582. if($mybb->input['action'] == "new_announcement")
  583. {
  584. add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements");
  585. add_breadcrumb($lang->add_announcement, "modcp.php?action=new_announcements");
  586. $announcement_fid = intval($mybb->input['fid']);
  587. if(($mybb->usergroup['issupermod'] != 1 && $announcement_fid == -1) || ($announcement_fid != -1 && !is_moderator($announcement_fid)) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  588. {
  589. error_no_permission();
  590. }
  591. // Deal with inline errors
  592. if(is_array($errors))
  593. {
  594. $errors = inline_error($errors);
  595. // Set $announcement to input stuff
  596. $announcement['subject'] = $mybb->input['title'];
  597. $announcement['message'] = $mybb->input['message'];
  598. $announcement['allowhtml'] = $mybb->input['allowhtml'];
  599. $announcement['allowmycode'] = $mybb->input['allowmycode'];
  600. $announcement['allowsmilies'] = $mybb->input['allowsmilies'];
  601. $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  602. if(!in_array($mybb->input['starttime_month'], $months))
  603. {
  604. $mybb->input['starttime_month'] = 1;
  605. }
  606. if(!in_array($mybb->input['endtime_month'], $months))
  607. {
  608. $mybb->input['endtime_month'] = 1;
  609. }
  610. $startmonth = $mybb->input['starttime_month'];
  611. $startdateyear = htmlspecialchars_uni($mybb->input['starttime_year']);
  612. $startday = intval($mybb->input['starttime_day']);
  613. $starttime_time = htmlspecialchars($mybb->input['starttime_time']);
  614. $endmonth = $mybb->input['endtime_month'];
  615. $enddateyear = htmlspecialchars_uni($mybb->input['endtime_year']);
  616. $endday = intval($mybb->input['endtime_day']);
  617. $endtime_time = htmlspecialchars($mybb->input['endtime_time']);
  618. }
  619. else
  620. {
  621. // Note: dates are in GMT timezone
  622. $starttime_time = gmdate("g:i a", TIME_NOW);
  623. $endtime_time = gmdate("g:i a", TIME_NOW);
  624. $startday = $endday = gmdate("j", TIME_NOW);
  625. $startmonth = $endmonth = gmdate("m", TIME_NOW);
  626. $startdateyear = gmdate("Y", TIME_NOW);
  627. $enddateyear = $startdateyear+1;
  628. }
  629. // Generate form elements
  630. for($i = 1; $i <= 31; ++$i)
  631. {
  632. if($startday == $i)
  633. {
  634. $startdateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  635. }
  636. else
  637. {
  638. $startdateday .= "<option value=\"$i\">$i</option>\n";
  639. }
  640. if($endday == $i)
  641. {
  642. $enddateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  643. }
  644. else
  645. {
  646. $enddateday .= "<option value=\"$i\">$i</option>\n";
  647. }
  648. }
  649. $startmonthsel = $endmonthsel = array();
  650. $startmonthsel[$startmonth] = "selected=\"selected\"";
  651. $endmonthsel[$endmonth] = "selected=\"selected\"";
  652. $startdatemonth .= "<option value=\"01\" {$startmonthsel['01']}>{$lang->january}</option>\n";
  653. $enddatemonth .= "<option value=\"01\" {$endmonthsel['01']}>{$lang->january}</option>\n";
  654. $startdatemonth .= "<option value=\"02\" {$startmonthsel['02']}>{$lang->february}</option>\n";
  655. $enddatemonth .= "<option value=\"02\" {$endmonthsel['02']}>{$lang->february}</option>\n";
  656. $startdatemonth .= "<option value=\"03\" {$startmonthsel['03']}>{$lang->march}</option>\n";
  657. $enddatemonth .= "<option value=\"03\" {$endmonthsel['03']}>{$lang->march}</option>\n";
  658. $startdatemonth .= "<option value=\"04\" {$startmonthsel['04']}>{$lang->april}</option>\n";
  659. $enddatemonth .= "<option value=\"04\" {$endmonthsel['04']}>{$lang->april}</option>\n";
  660. $startdatemonth .= "<option value=\"05\" {$startmonthsel['05']}>{$lang->may}</option>\n";
  661. $enddatemonth .= "<option value=\"05\" {$endmonthsel['05']}>{$lang->may}</option>\n";
  662. $startdatemonth .= "<option value=\"06\" {$startmonthsel['06']}>{$lang->june}</option>\n";
  663. $enddatemonth .= "<option value=\"06\" {$endmonthsel['06']}>{$lang->june}</option>\n";
  664. $startdatemonth .= "<option value=\"07\" {$startmonthsel['07']}>{$lang->july}</option>\n";
  665. $enddatemonth .= "<option value=\"07\" {$endmonthsel['07']}>{$lang->july}</option>\n";
  666. $startdatemonth .= "<option value=\"08\" {$startmonthsel['08']}>{$lang->august}</option>\n";
  667. $enddatemonth .= "<option value=\"08\" {$endmonthsel['08']}>{$lang->august}</option>\n";
  668. $startdatemonth .= "<option value=\"09\" {$startmonthsel['09']}>{$lang->september}</option>\n";
  669. $enddatemonth .= "<option value=\"09\" {$endmonthsel['09']}>{$lang->september}</option>\n";
  670. $startdatemonth .= "<option value=\"10\" {$startmonthsel['10']}>{$lang->october}</option>\n";
  671. $enddatemonth .= "<option value=\"10\" {$endmonthsel['10']}>{$lang->october}</option>\n";
  672. $startdatemonth .= "<option value=\"11\" {$startmonthsel['11']}>{$lang->november}</option>\n";
  673. $enddatemonth .= "<option value=\"11\" {$endmonthsel['11']}>{$lang->november}</option>\n";
  674. $startdatemonth .= "<option value=\"12\" {$startmonthsel['12']}>{$lang->december}</option>\n";
  675. $enddatemonth .= "<option value=\"12\" {$endmonthsel['12']}>{$lang->december}</option>\n";
  676. $title = htmlspecialchars_uni($announcement['subject']);
  677. $message = htmlspecialchars_uni($announcement['message']);
  678. $html_sel = $mycode_sel = $smilies_sel = array();
  679. if($mybb->input['allowhtml'] || !isset($mybb->input['allowhtml']))
  680. {
  681. $html_sel['yes'] = ' checked="checked"';
  682. }
  683. else
  684. {
  685. $html_sel['no'] = ' checked="checked"';
  686. }
  687. if($mybb->input['allowmycode'] || !isset($mybb->input['allowmycode']))
  688. {
  689. $mycode_sel['yes'] = ' checked="checked"';
  690. }
  691. else
  692. {
  693. $mycode_sel['no'] = ' checked="checked"';
  694. }
  695. if($mybb->input['allowsmilies'] || !isset($mybb->input['allowsmilies']))
  696. {
  697. $smilies_sel['yes'] = ' checked="checked"';
  698. }
  699. else
  700. {
  701. $smilies_sel['no'] = ' checked="checked"';
  702. }
  703. if($mybb->input['endtime_type'] == 2 || !isset($mybb->input['endtime_type']))
  704. {
  705. $end_type_sel['infinite'] = ' checked="checked"';
  706. }
  707. else
  708. {
  709. $end_type_sel['finite'] = ' checked="checked"';
  710. }
  711. // MyCode editor
  712. $codebuttons = build_mycode_inserter();
  713. $smilieinserter = build_clickable_smilies();
  714. $plugins->run_hooks("modcp_new_announcement");
  715. eval("\$announcements = \"".$templates->get("modcp_announcements_new")."\";");
  716. output_page($announcements);
  717. }
  718. if($mybb->input['action'] == "do_edit_announcement")
  719. {
  720. verify_post_check($mybb->input['my_post_key']);
  721. // Get the announcement
  722. $aid = intval($mybb->input['aid']);
  723. $query = $db->simple_select("announcements", "aid, subject, fid", "aid='{$aid}'");
  724. $announcement = $db->fetch_array($query);
  725. // Check that it exists
  726. if(!$announcement['aid'])
  727. {
  728. error($lang->error_invalid_announcement);
  729. }
  730. // Mod has permissions to edit this announcement
  731. if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'])) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  732. {
  733. error_no_permission();
  734. }
  735. // Basic error checking
  736. if(!trim($mybb->input['title']))
  737. {
  738. $errors[] = $lang->error_missing_title;
  739. }
  740. if(!trim($mybb->input['message']))
  741. {
  742. $errors[] = $lang->error_missing_message;
  743. }
  744. if(!trim($mybb->input['fid']))
  745. {
  746. $errors[] = $lang->error_missing_forum;
  747. }
  748. $startdate = @explode(" ", $mybb->input['starttime_time']);
  749. $startdate = @explode(":", $startdate[0]);
  750. $enddate = @explode(" ", $mybb->input['endtime_time']);
  751. $enddate = @explode(":", $enddate[0]);
  752. if(stristr($mybb->input['starttime_time'], "pm"))
  753. {
  754. $startdate[0] = 12+$startdate[0];
  755. if($startdate[0] >= 24)
  756. {
  757. $startdate[0] = "00";
  758. }
  759. }
  760. if(stristr($mybb->input['endtime_time'], "pm"))
  761. {
  762. $enddate[0] = 12+$enddate[0];
  763. if($enddate[0] >= 24)
  764. {
  765. $enddate[0] = "00";
  766. }
  767. }
  768. $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  769. if(!in_array($mybb->input['starttime_month'], $months))
  770. {
  771. $mybb->input['starttime_month'] = 1;
  772. }
  773. $startdate = gmmktime(intval($startdate[0]), intval($startdate[1]), 0, (int)$mybb->input['starttime_month'], intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year']));
  774. if($startdate < 0 || $startdate == false)
  775. {
  776. $errors[] = $lang->error_invalid_start_date;
  777. }
  778. if($mybb->input['endtime_type'] == "2")
  779. {
  780. $enddate = '0';
  781. }
  782. else
  783. {
  784. if(!in_array($mybb->input['endtime_month'], $months))
  785. {
  786. $mybb->input['endtime_month'] = 1;
  787. }
  788. $enddate = gmmktime(intval($enddate[0]), intval($enddate[1]), 0, (int)$mybb->input['endtime_month'], intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year']));
  789. if($enddate < 0 || $enddate == false)
  790. {
  791. $errors[] = $lang->error_invalid_end_date;
  792. }
  793. elseif($enddate < $startdate)
  794. {
  795. $errors[] = $lang->error_end_before_start;
  796. }
  797. }
  798. $plugins->run_hooks("modcp_do_edit_announcement_start");
  799. // Proceed to update if no errors
  800. if(!$errors)
  801. {
  802. $update_announcement = array(
  803. 'uid' => $mybb->user['uid'],
  804. 'subject' => $db->escape_string($mybb->input['title']),
  805. 'message' => $db->escape_string($mybb->input['message']),
  806. 'startdate' => $startdate,
  807. 'enddate' => $enddate,
  808. 'allowhtml' => $db->escape_string($mybb->input['allowhtml']),
  809. 'allowmycode' => $db->escape_string($mybb->input['allowmycode']),
  810. 'allowsmilies' => $db->escape_string($mybb->input['allowsmilies']),
  811. );
  812. $db->update_query("announcements", $update_announcement, "aid='{$aid}'");
  813. $plugins->run_hooks("modcp_do_edit_announcement_end");
  814. $cache->update_forumsdisplay();
  815. redirect("modcp.php?action=announcements", $lang->redirect_edit_announcement);
  816. }
  817. else
  818. {
  819. $mybb->input['action'] = 'edit_announcement';
  820. }
  821. }
  822. if($mybb->input['action'] == "edit_announcement")
  823. {
  824. $announcement_fid = intval($mybb->input['fid']);
  825. $aid = intval($mybb->input['aid']);
  826. add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements");
  827. add_breadcrumb($lang->edit_announcement, "modcp.php?action=edit_announcements&amp;aid={$aid}");
  828. // Get announcement
  829. $query = $db->simple_select("announcements", "*", "aid='{$aid}'");
  830. $announcement = $db->fetch_array($query);
  831. if(!$announcement['fid'])
  832. {
  833. error($lang->error_invalid_announcement);
  834. }
  835. if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'])) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums)))
  836. {
  837. error_no_permission();
  838. }
  839. if(!$announcement['startdate'])
  840. {
  841. // No start date? Make it now.
  842. $announcement['startdate'] = TIME_NOW;
  843. }
  844. $makeshift_end = false;
  845. if(!$announcement['enddate'])
  846. {
  847. $makeshift_end = true;
  848. $makeshift_time = TIME_NOW;
  849. if($announcement['startdate'])
  850. {
  851. $makeshift_time = $announcement['startdate'];
  852. }
  853. // No end date? Make it a year from now.
  854. $announcement['enddate'] = $makeshift_time + (60 * 60 * 24 * 366);
  855. }
  856. // Deal with inline errors
  857. if(is_array($errors))
  858. {
  859. $errors = inline_error($errors);
  860. // Set $announcement to input stuff
  861. $announcement['subject'] = $mybb->input['title'];
  862. $announcement['message'] = $mybb->input['message'];
  863. $announcement['allowhtml'] = $mybb->input['allowhtml'];
  864. $announcement['allowmycode'] = $mybb->input['allowmycode'];
  865. $announcement['allowsmilies'] = $mybb->input['allowsmilies'];
  866. $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
  867. if(!in_array($mybb->input['starttime_month'], $months))
  868. {
  869. $mybb->input['starttime_month'] = 1;
  870. }
  871. if(!in_array($mybb->input['endtime_month'], $months))
  872. {
  873. $mybb->input['endtime_month'] = 1;
  874. }
  875. $startmonth = $mybb->input['starttime_month'];
  876. $startdateyear = htmlspecialchars_uni($mybb->input['starttime_year']);
  877. $startday = intval($mybb->input['starttime_day']);
  878. $starttime_time = htmlspecialchars($mybb->input['starttime_time']);
  879. $endmonth = $mybb->input['endtime_month'];
  880. $enddateyear = htmlspecialchars_uni($mybb->input['endtime_year']);
  881. $endday = intval($mybb->input['endtime_day']);
  882. $endtime_time = htmlspecialchars($mybb->input['endtime_time']);
  883. $errored = true;
  884. }
  885. else
  886. {
  887. // Note: dates are in GMT timezone
  888. $starttime_time = gmdate('g:i a', $announcement['startdate']);
  889. $endtime_time = gmdate('g:i a', $announcement['enddate']);
  890. $startday = gmdate('j', $announcement['startdate']);
  891. $endday = gmdate('j', $announcement['enddate']);
  892. $startmonth = gmdate('m', $announcement['startdate']);
  893. $endmonth = gmdate('m', $announcement['enddate']);
  894. $startdateyear = gmdate('Y', $announcement['startdate']);
  895. $enddateyear = gmdate('Y', $announcement['enddate']);
  896. $errored = false;
  897. }
  898. // Generate form elements
  899. for($i = 1; $i <= 31; ++$i)
  900. {
  901. if($startday == $i)
  902. {
  903. $startdateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  904. }
  905. else
  906. {
  907. $startdateday .= "<option value=\"$i\">$i</option>\n";
  908. }
  909. if($endday == $i)
  910. {
  911. $enddateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  912. }
  913. else
  914. {
  915. $enddateday .= "<option value=\"$i\">$i</option>\n";
  916. }
  917. }
  918. $startmonthsel = $endmonthsel = array();
  919. $startmonthsel[$startmonth] = "selected=\"selected\"";
  920. $endmonthsel[$endmonth] = "selected=\"selected\"";
  921. $startdatemonth .= "<option value=\"01\" {$startmonthsel['01']}>{$lang->january}</option>\n";
  922. $enddatemonth .= "<option value=\"01\" {$endmonthsel['01']}>{$lang->january}</option>\n";
  923. $startdatemonth .= "<option value=\"02\" {$startmonthsel['02']}>{$lang->february}</option>\n";
  924. $enddatemonth .= "<option value=\"02\" {$endmonthsel['02']}>{$lang->february}</option>\n";
  925. $startdatemonth .= "<option value=\"03\" {$startmonthsel['03']}>{$lang->march}</option>\n";
  926. $enddatemonth .= "<option value=\"03\" {$endmonthsel['03']}>{$lang->march}</option>\n";
  927. $startdatemonth .= "<option value=\"04\" {$startmonthsel['04']}>{$lang->april}</option>\n";
  928. $enddatemonth .= "<option value=\"04\" {$endmonthsel['04']}>{$lang->april}</option>\n";
  929. $startdatemonth .= "<option value=\"05\" {$startmonthsel['05']}>{$lang->may}</option>\n";
  930. $enddatemonth .= "<option value=\"05\" {$endmonthsel['05']}>{$lang->may}</option>\n";
  931. $startdatemonth .= "<option value=\"06\" {$startmonthsel['06']}>{$lang->june}</option>\n";
  932. $enddatemonth .= "<option value=\"06\" {$endmonthsel['06']}>{$lang->june}</option>\n";
  933. $startdatemonth .= "<option value=\"07\" {$startmonthsel['07']}>{$lang->july}</option>\n";
  934. $enddatemonth .= "<option value=\"07\" {$endmonthsel['07']}>{$lang->july}</option>\n";
  935. $startdatemonth .= "<option value=\"08\" {$startmonthsel['08']}>{$lang->august}</option>\n";
  936. $enddatemonth .= "<option value=\"08\" {$endmonthsel['08']}>{$lang->august}</option>\n";
  937. $startdatemonth .= "<option value=\"09\" {$startmonthsel['09']}>{$lang->september}</option>\n";
  938. $enddatemonth .= "<option value=\"09\" {$endmonthsel['09']}>{$lang->september}</option>\n";
  939. $startdatemonth .= "<option value=\"10\" {$startmonthsel['10']}>{$lang->october}</option>\n";
  940. $enddatemonth .= "<option value=\"10\" {$endmonthsel['10']}>{$lang->october}</option>\n";
  941. $startdatemonth .= "<option value=\"11\" {$startmonthsel['11']}>{$lang->november}</option>\n";
  942. $enddatemonth .= "<option value=\"11\" {$endmonthsel['11']}>{$lang->november}</option>\n";
  943. $startdatemonth .= "<option value=\"12\" {$startmonthsel['12']}>{$lang->december}</option>\n";
  944. $enddatemonth .= "<option value=\"12\" {$endmonthsel['12']}>{$lang->december}</option>\n";
  945. $title = htmlspecialchars_uni($announcement['subject']);
  946. $message = htmlspecialchars_uni($announcement['message']);
  947. $html_sel = $mycode_sel = $smilies_sel = array();
  948. if($announcement['allowhtml'])
  949. {
  950. $html_sel['yes'] = ' checked="checked"';
  951. }
  952. else
  953. {
  954. $html_sel['no'] = ' checked="checked"';
  955. }
  956. if($announcement['allowmycode'])
  957. {
  958. $mycode_sel['yes'] = ' checked="checked"';
  959. }
  960. else
  961. {
  962. $mycode_sel['no'] = ' checked="checked"';
  963. }
  964. if($announcement['allowsmilies'])
  965. {
  966. $smilies_sel['yes'] = ' checked="checked"';
  967. }
  968. else
  969. {
  970. $smilies_sel['no'] = ' checked="checked"';
  971. }
  972. if(($errored && $mybb->input['endtime_type'] == 2) || (!$errored && intval($announcement['enddate']) == 0) || $makeshift_end == true)
  973. {
  974. $end_type_sel['infinite'] = ' checked="checked"';
  975. }
  976. else
  977. {
  978. $end_type_sel['finite'] = ' checked="checked"';
  979. }
  980. // MyCode editor
  981. $codebuttons = build_mycode_inserter();
  982. $smilieinserter = build_clickable_smilies();
  983. $plugins->run_hooks("modcp_edit_announcement");
  984. eval("\$announcements = \"".$templates->get("modcp_announcements_edit")."\";");
  985. output_page($announcements);
  986. }
  987. if($mybb->input['action'] == "announcements")
  988. {
  989. add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements");
  990. // Fetch announcements into their proper arrays
  991. $query = $db->simple_select("announcements", "aid, fid, subject, enddate");
  992. while($announcement = $db->fetch_array($query))
  993. {
  994. if($announcement['fid'] == -1)
  995. {
  996. $global_announcements[$announcement['aid']] = $announcement;
  997. continue;
  998. }
  999. $announcements[$announcement['fid']][$announcement['aid']] = $announcement;
  1000. }
  1001. if($mybb->usergroup['issupermod'] == 1)
  1002. {
  1003. if($global_announcements && $mybb->usergroup['issupermod'] == 1)
  1004. {
  1005. // Get the global announcements
  1006. foreach($global_announcements as $aid => $announcement)
  1007. {
  1008. $trow = alt_trow();
  1009. if($announcement['startdate'] > TIME_NOW || ($announcement['enddate'] < TIME_NOW && $announcement['enddate'] != 0))
  1010. {
  1011. $icon = "<img src=\"{$theme['imgdir']}/minioff.gif\" alt=\"({$lang->expired})\" title=\"{$lang->expired_announcement}\" style=\"vertical-align: middle;\" /> ";
  1012. }
  1013. else
  1014. {
  1015. $icon = "<img src=\"{$theme['imgdir']}/minion.gif\" alt=\"({$lang->active})\" title=\"{$lang->active_announcement}\" style=\"vertical-align: middle;\" /> ";
  1016. }
  1017. $subject = htmlspecialchars_uni($announcement['subject']);
  1018. eval("\$announcements_global .= \"".$templates->get("modcp_announcements_announcement_global")."\";");
  1019. }
  1020. }
  1021. else
  1022. {
  1023. // No global announcements
  1024. eval("\$announcements_global = \"".$templates->get("modcp_no_announcements_global")."\";");
  1025. }
  1026. eval("\$announcements_global = \"".$templates->get("modcp_announcements_global")."\";");
  1027. }
  1028. else
  1029. {
  1030. // Moderator is not super, so don't show global annnouncemnets
  1031. $announcements_global = '';
  1032. }
  1033. fetch_forum_announcements();
  1034. if(!$announcements_forum)
  1035. {
  1036. eval("\$announcements_forum = \"".$templates->get("modcp_no_announcements_forum")."\";");
  1037. }
  1038. $plugins->run_hooks("modcp_announcements");
  1039. eval("\$announcements = \"".$templates->get("modcp_announcements")."\";");
  1040. output_page($announcements);
  1041. }
  1042. if($mybb->input['action'] == "do_modqueue")
  1043. {
  1044. require_once MYBB_ROOT."inc/class_moderation.php";
  1045. $moderation = new Moderation;
  1046. // Verify incoming POST request
  1047. verify_post_check($mybb->input['my_post_key']);
  1048. $plugins->run_hooks("modcp_do_modqueue_start");
  1049. if(is_array($mybb->input['threads']))
  1050. {
  1051. // Fetch threads
  1052. $query = $db->simple_select("threads", "tid", "tid IN (".implode(",", array_map("intval", array_keys($mybb->input['threads'])))."){$flist}");
  1053. while($thread = $db->fetch_array($query))
  1054. {
  1055. $action = $mybb->input['threads'][$thread['tid']];
  1056. if($action == "approve")
  1057. {
  1058. $threads_to_approve[] = $thread['tid'];
  1059. }
  1060. else if($action == "delete")
  1061. {
  1062. $threads_to_delete[] = $thread['tid'];
  1063. }
  1064. }
  1065. if(!empty($threads_to_approve))
  1066. {
  1067. $moderation->approve_threads($threads_to_approve);
  1068. log_moderator_action(array('tids' => $threads_to_approve), $lang->multi_approve_threads);
  1069. }
  1070. if(!empty($threads_to_delete))
  1071. {
  1072. foreach($threads_to_delete as $tid)
  1073. {
  1074. $moderation->delete_thread($tid);
  1075. }
  1076. log_moderator_action(array('tids' => $threads_to_delete), $lang->multi_delete_threads);
  1077. }
  1078. $plugins->run_hooks("modcp_do_modqueue_end");
  1079. redirect("modcp.php?action=modqueue", $lang->redirect_threadsmoderated);
  1080. }
  1081. else if(is_array($mybb->input['posts']))
  1082. {
  1083. // Fetch posts
  1084. $query = $db->simple_select("posts", "pid", "pid IN (".implode(",", array_map("intval", array_keys($mybb->input['posts'])))."){$flist}");
  1085. while($post = $db->fetch_array($query))
  1086. {
  1087. $action = $mybb->input['posts'][$post['pid']];
  1088. if($action == "approve")
  1089. {
  1090. $posts_to_approve[] = $post['pid'];
  1091. }
  1092. else if($action == "delete")
  1093. {
  1094. $moderation->delete_post($post['pid']);
  1095. }
  1096. }
  1097. if(is_array($posts_to_approve))
  1098. {
  1099. $moderation->approve_posts($posts_to_approve);
  1100. }
  1101. log_moderator_action(array('pids' => $posts_to_approve), $lang->multi_approve_posts);
  1102. $plugins->run_hooks("modcp_do_modqueue_end");
  1103. redirect("modcp.php?action=modqueue&type=posts", $lang->redirect_postsmoderated);
  1104. }
  1105. else if(is_array($mybb->input['attachments']))
  1106. {
  1107. $query = $db->query("
  1108. SELECT a.pid, a.aid
  1109. FROM ".TABLE_PREFIX."attachments a
  1110. LEFT JOIN ".TABLE_PREFIX."posts p ON (a.pid=p.pid)
  1111. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  1112. WHERE aid IN (".implode(",", array_map("intval", array_keys($mybb->input['attachments'])))."){$tflist}
  1113. ");
  1114. while($attachment = $db->fetch_array($query))
  1115. {
  1116. $action = $mybb->input['attachments'][$attachment['aid']];
  1117. if($action == "approve")
  1118. {
  1119. $db->update_query("attachments", array("visible" => 1), "aid='{$attachment['aid']}'");
  1120. }
  1121. else if($action == "delete")
  1122. {
  1123. remove_attachment($attachment['pid'], '', $attachment['aid']);
  1124. }
  1125. }
  1126. $plugins->run_hooks("modcp_do_modqueue_end");
  1127. redirect("modcp.php?action=modqueue&type=attachments", $lang->redirect_attachmentsmoderated);
  1128. }
  1129. }
  1130. if($mybb->input['action'] == "modqueue")
  1131. {
  1132. if($mybb->input['type'] == "threads" || !$mybb->input['type'])
  1133. {
  1134. $forum_cache = $cache->read("forums");
  1135. $query = $db->simple_select("threads", "COUNT(tid) AS unapprovedthreads", "visible=0 {$flist}");
  1136. $unapproved_threads = $db->fetch_field($query, "unapprovedthreads");
  1137. // Figure out if we need to display multiple pages.
  1138. if($mybb->input['page'] != "last")
  1139. {
  1140. $page = intval($mybb->input['page']);
  1141. }
  1142. $perpage = $mybb->settings['threadsperpage'];
  1143. $pages = $unapproved_threads / $perpage;
  1144. $pages = ceil($pages);
  1145. if($mybb->input['page'] == "last")
  1146. {
  1147. $page = $pages;
  1148. }
  1149. if($page > $pages || $page <= 0)
  1150. {
  1151. $page = 1;
  1152. }
  1153. if($page)
  1154. {
  1155. $start = ($page-1) * $perpage;
  1156. }
  1157. else
  1158. {
  1159. $start = 0;
  1160. $page = 1;
  1161. }
  1162. $multipage = multipage($pages, $perpage, $page, "modcp.php?action=modqueue&amp;type=threads");
  1163. $query = $db->query("
  1164. SELECT t.tid, t.dateline, t.fid, t.subject, p.message AS postmessage, u.username AS username, t.uid
  1165. FROM ".TABLE_PREFIX."threads t
  1166. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=t.firstpost)
  1167. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
  1168. WHERE t.visible='0' {$tflist}
  1169. ORDER BY t.lastpost DESC
  1170. LIMIT {$start}, {$perpage}
  1171. ");
  1172. while($thread = $db->fetch_array($query))
  1173. {
  1174. $altbg = alt_trow();
  1175. $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  1176. $thread['threadlink'] = get_thread_link($thread['tid']);
  1177. $thread['forumlink'] = get_forum_link($thread['fid']);
  1178. $forum_name = $forum_cache[$thread['fid']]['name'];
  1179. $threaddate = my_date($mybb->settings['dateformat'], $thread['dateline']);
  1180. $threadtime = my_date($mybb->settings['timeformat'], $thread['dateline']);
  1181. $profile_link = build_profile_link($thread['username'], $thread['uid']);
  1182. $thread['postmessage'] = nl2br(htmlspecialchars_uni($thread['postmessage']));
  1183. $forum = "<strong>{$lang->meta_forum} <a href=\"{$thread['forumlink']}\">{$forum_name}</a></strong>";
  1184. eval("\$threads .= \"".$templates->get("modcp_modqueue_threads_thread")."\";");
  1185. }
  1186. if(!$threads && $mybb->input['type'] == "threads")
  1187. {
  1188. eval("\$threads = \"".$templates->get("modcp_modqueue_threads_empty")."\";");
  1189. }
  1190. if($threads)
  1191. {
  1192. add_breadcrumb($lang->mcp_nav_modqueue_threads, "modcp.php?action=modqueue&amp;type=threads");
  1193. $plugins->run_hooks("modcp_modqueue_threads_end");
  1194. eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";");
  1195. eval("\$threadqueue = \"".$templates->get("modcp_modqueue_threads")."\";");
  1196. output_page($threadqueue);
  1197. }
  1198. $type = 'threads';
  1199. }
  1200. if($mybb->input['type'] == "posts" || (!$mybb->input['type'] && !$threadqueue))
  1201. {
  1202. $forum_cache = $cache->read("forums");
  1203. $query = $db->query("
  1204. SELECT COUNT(pid) AS unapprovedposts
  1205. FROM ".TABLE_PREFIX."posts p
  1206. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  1207. WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid
  1208. ");
  1209. $unapproved_posts = $db->fetch_field($query, "unapprovedposts");
  1210. // Figure out if we need to display multiple pages.
  1211. if($mybb->input['page'] != "last")
  1212. {
  1213. $page = intval($mybb->input['page']);
  1214. }
  1215. $perpage = $mybb->settings['postsperpage'];
  1216. $pages = $unapproved_posts / $perpage;
  1217. $pages = ceil($pages);
  1218. if($mybb->input['page'] == "last")
  1219. {
  1220. $page = $pages;
  1221. }
  1222. if($page > $pages || $page <= 0)
  1223. {
  1224. $page = 1;
  1225. }
  1226. if($page)
  1227. {
  1228. $start = ($page-1) * $perpage;
  1229. }
  1230. else
  1231. {
  1232. $start = 0;
  1233. $page = 1;
  1234. }
  1235. $multipage = multipage($pages, $perpage, $page, "modcp.php?action=modqueue&amp;type=posts");
  1236. $query = $db->query("
  1237. SELECT p.pid, p.subject, p.message, t.subject AS threadsubject, t.tid, u.username, p.uid, t.fid, p.dateline
  1238. FROM ".TABLE_PREFIX."posts p
  1239. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  1240. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
  1241. WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid
  1242. ORDER BY p.dateline DESC
  1243. LIMIT {$start}, {$perpage}
  1244. ");
  1245. while($post = $db->fetch_array($query))
  1246. {
  1247. $altbg = alt_trow();
  1248. $post['threadsubject'] = htmlspecialchars_uni($parser->parse_badwords($post['threadsubject']));
  1249. $post['threadlink'] = get_thread_link($post['tid']);
  1250. $post['forumlink'] = get_forum_link($post['fid']);
  1251. $post['postlink'] = get_post_link($post['pid'], $post['tid']);
  1252. $forum_name = $forum_cache[$post['fid']]['name'];
  1253. $postdate = my_date($mybb->settings['dateformat'], $post['dateline']);
  1254. $posttime = my_date($mybb->settings['timeformat'], $post['dateline']);
  1255. $profile_link = build_profile_link($post['username'], $post['uid']);
  1256. $thread = "<strong>{$lang->meta_thread} <a href=\"{$post['threadlink']}\">{$post['threadsubject']}</a></strong>";
  1257. $forum = "<strong>{$lang->meta_forum} <a href=\"{$post['forumlink']}\">{$forum_name}</a></strong><br />";
  1258. $post['message'] = nl2br(htmlspecialchars_uni($post['message']));
  1259. eval("\$posts .= \"".$templates->get("modcp_modqueue_posts_post")."\";");
  1260. }
  1261. if(!$posts && $mybb->input['type'] == "posts")
  1262. {
  1263. eval("\$posts = \"".$templates->get("modcp_modqueue_posts_empty")."\";");
  1264. }
  1265. if($posts)
  1266. {
  1267. add_breadcrumb($lang->mcp_nav_modqueue_posts, "modcp.php?action=modqueue&amp;type=posts");
  1268. $plugins->run_hooks("modcp_modqueue_posts_end");
  1269. eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";");
  1270. eval("\$postqueue = \"".$templates->get("modcp_modqueue_posts")."\";");
  1271. output_page($postqueue);
  1272. }
  1273. }
  1274. if($mybb->input['type'] == "attachments" || (!$mybb->input['type'] && !$postqueue && !$threadqueue))
  1275. {
  1276. $query = $db->query("
  1277. SELECT COUNT(aid) AS unapprovedattachments
  1278. FROM ".TABLE_PREFIX."attachments a
  1279. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
  1280. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  1281. WHERE a.visible='0' {$tflist}
  1282. ");
  1283. $unapproved_attachments = $db->fetch_field($query, "unapprovedattachments");
  1284. // Figure out if we need to display multiple pages.
  1285. if($mybb->input['page'] != "last")
  1286. {
  1287. $page = intval($mybb->input['page']);
  1288. }
  1289. $perpage = $mybb->settings['postsperpage'];
  1290. $pages = $unapproved_attachments / $perpage;
  1291. $pages = ceil($pages);
  1292. if($mybb->input['page'] == "last")
  1293. {
  1294. $page = $pages;
  1295. }
  1296. if($page > $pages || $page <= 0)
  1297. {
  1298. $page = 1;
  1299. }
  1300. if($page)
  1301. {
  1302. $start = ($page-1) * $perpage;
  1303. }
  1304. else
  1305. {
  1306. $start = 0;
  1307. $page = 1;
  1308. }
  1309. $multipage = multipage($pages, $perpage, $page, "modcp.php?action=modqueue&amp;type=attachments");
  1310. $query = $db->query("
  1311. SELECT a.*, p.subject AS postsubject, p.dateline, p.uid, u.username, t.tid, t.subject AS threadsubject
  1312. FROM ".TABLE_PREFIX."attachments a
  1313. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
  1314. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  1315. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
  1316. WHERE a.visible='0'
  1317. ORDER BY a.dateuploaded DESC
  1318. LIMIT {$start}, {$perpage}
  1319. ");
  1320. while($attachment = $db->fetch_array($query))
  1321. {
  1322. $altbg = alt_trow();
  1323. if(!$attachment['dateuploaded'])
  1324. {
  1325. $attachment['dateuploaded'] = $attachment['dateline'];
  1326. }
  1327. $attachdate = my_date($mybb->settings['dateformat'], $attachment['dateuploaded']);
  1328. $attachtime = my_date($mybb->settings['timeformat'], $attachment['dateuploaded']);
  1329. $attachment['postsubject'] = htmlspecialchars_uni($attachment['postsubject']);
  1330. $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
  1331. $attachment['threadsubject'] = htmlspecialchars_uni($attachment['threadsubject']);
  1332. $attachment['filesize'] = get_friendly_size($attachment['filesize']);
  1333. $link = get_post_link($attachment['pid'], $attachment['tid']) . "#pid{$attachment['pid']}";
  1334. $thread_link = get_thread_link($attachment['tid']);
  1335. $profile_link = build_profile_link($attachment['username'], $attachment['uid']);
  1336. eval("\$attachments .= \"".$templates->get("modcp_modqueue_attachments_attachment")."\";");
  1337. }
  1338. if(!$attachments && $mybb->input['type'] == "attachments")
  1339. {
  1340. eval("\$attachments = \"".$templates->get("modcp_modqueue_attachments_empty")."\";");
  1341. }
  1342. if($attachments)
  1343. {
  1344. add_breadcrumb($lang->mcp_nav_modqueue_attachments, "modcp.php?action=modqueue&amp;type=attachments");
  1345. $plugins->run_hooks("modcp_modqueue_attachments_end");
  1346. eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";");
  1347. eval("\$attachmentqueue = \"".$templates->get("modcp_modqueue_attachments")."\";");
  1348. output_page($attachmentqueue);
  1349. }
  1350. }
  1351. // Still nothing? All queues are empty! :-D
  1352. if(!$threadqueue && !$postqueue && !$attachmentqueue)
  1353. {
  1354. add_breadcrumb($lang->mcp_nav_modqueue, "modcp.php?action=modqueue");
  1355. $plugins->run_hooks("modcp_modqueue_end");
  1356. eval("\$queue = \"".$templates->get("modcp_modqueue_empty")."\";");
  1357. output_page($queue);
  1358. }
  1359. }
  1360. if($mybb->input['action'] == "do_editprofile")
  1361. {
  1362. // Verify incoming POST request
  1363. verify_post_check($mybb->input['my_post_key']);
  1364. $user = get_user($mybb->input['uid']);
  1365. if(!$user['uid'])
  1366. {
  1367. error($lang->invalid_user);
  1368. }
  1369. // Check if the current user has permission to edit this user
  1370. if(!modcp_can_manage_user($user['uid']))
  1371. {
  1372. error_no_permission();
  1373. }
  1374. $plugins->run_hooks("modcp_do_editprofile_start");
  1375. // Set up user handler.
  1376. require_once MYBB_ROOT."inc/datahandlers/user.php";
  1377. $userhandler = new UserDataHandler('update');
  1378. // Set the data for the new user.
  1379. $updated_user = array(
  1380. "uid" => $mybb->input['uid'],
  1381. "profile_fields" => $mybb->input['profile_fields'],
  1382. "profile_fields_editable" => true,
  1383. "website" => $mybb->input['website'],
  1384. "icq" => $mybb->input['icq'],
  1385. "aim" => $mybb->input['aim'],
  1386. "yahoo" => $mybb->input['yahoo'],
  1387. "msn" => $mybb->input['msn'],
  1388. "signature" => $mybb->input['signature'],
  1389. "usernotes" => $mybb->input['usernotes']
  1390. );
  1391. $updated_user['birthday'] = array(
  1392. "day" => $mybb->input['birthday_day'],
  1393. "month" => $mybb->input['birthday_month'],
  1394. "year" => $mybb->input['birthday_year']
  1395. );
  1396. if($mybb->input['usertitle'] != '')
  1397. {
  1398. $updated_user['usertitle'] = $mybb->input['usertitle'];
  1399. }
  1400. else if($mybb->input['reverttitle'])
  1401. {
  1402. $updated_user['usertitle'] = '';
  1403. }
  1404. if($mybb->input['remove_avatar'])
  1405. {
  1406. $updated_user['avatarurl'] = '';
  1407. }
  1408. // Set the data of the user in the datahandler.
  1409. $userhandler->set_data($updated_user);
  1410. $errors = '';
  1411. // Validate the user and get any errors that might have occurred.
  1412. if(!$userhandler->validate_user())
  1413. {
  1414. $errors = $userhandler->get_friendly_errors();
  1415. $mybb->input['action'] = "editprofile";
  1416. }
  1417. else
  1418. {
  1419. // Are we removing an avatar from this user?
  1420. if($mybb->input['remove_avatar'])
  1421. {
  1422. $extra_user_updates = array(
  1423. "avatar" => "",
  1424. "avatardimensions" => "",
  1425. "avatartype" => ""
  1426. );
  1427. remove_avatars($user['uid']);
  1428. }
  1429. // Moderator "Options" (suspend signature, suspend/moderate posting)
  1430. $moderator_options = array(
  1431. 1 => array(
  1432. "action" => "suspendsignature", // The moderator action we're performing
  1433. "period" => "action_period", // The time period we've selected from the dropdown box
  1434. "time" => "action_time", // The time we've entered
  1435. "update_field" => "suspendsignature", // The field in the database to update if true
  1436. "update_length" => "suspendsigtime" // The length of suspension field in the database
  1437. ),
  1438. 2 => array(
  1439. "action" => "moderateposting",
  1440. "period" => "modpost_period",
  1441. "time" => "modpost_time",
  1442. "update_field" => "moderateposts",
  1443. "update_length" => "moderationtime"
  1444. ),
  1445. 3 => array(
  1446. "action" => "suspendposting",
  1447. "period" => "suspost_period",
  1448. "time" => "suspost_time",
  1449. "update_field" => "suspendposting",
  1450. "update_length" => "suspensiontime"
  1451. )
  1452. );
  1453. require_once MYBB_ROOT."inc/functions_warnings.php";
  1454. foreach($moderator_options as $option)
  1455. {
  1456. if(!$mybb->input[$option['action']])
  1457. {
  1458. if($user[$option['update_field']] == 1)
  1459. {
  1460. // We're revoking the suspension
  1461. $extra_user_updates[$option['update_field']] = 0;
  1462. $extra_user_updates[$option['update_length']] = 0;
  1463. }
  1464. // Skip this option if we haven't selected it
  1465. continue;
  1466. }
  1467. if($mybb->input[$option['action']])
  1468. {
  1469. if(intval($mybb->input[$option['time']]) == 0 && $mybb->input[$option['period']] != "never" && $user[$option['update_field']] != 1)
  1470. {
  1471. // User has selected a type of ban, but not entered a valid time frame
  1472. $string = $option['action']."_error";
  1473. $errors[] = $lang->$string;
  1474. }
  1475. if(!is_array($errors))
  1476. {
  1477. $suspend_length = fetch_time_length(intval($mybb->input[$option['time']]), $mybb->input[$option['period']]);
  1478. if($user[$option['update_field']] == 1 && ($mybb->input[$option['time']] || $mybb->input[$option['period']] == "never"))
  1479. {
  1480. // We already have a suspension, but entered a new time
  1481. if($suspend_length == "-1")
  1482. {
  1483. // Permanent ban on action
  1484. $extra_user_updates[$option['update_length']] = 0;
  1485. }
  1486. elseif($suspend_length && $suspend_length != "-1")
  1487. {
  1488. // Temporary ban on action
  1489. $extra_user_updates[$option['update_length']] = TIME_NOW + $suspend_length;
  1490. }
  1491. }
  1492. elseif(!$user[$option['update_field']])
  1493. {
  1494. // New suspension for this user... bad user!
  1495. $extra_user_updates[$option['update_field']] = 1;
  1496. if($suspend_length == "-1")
  1497. {
  1498. $extra_user_updates[$option['update_length']] = 0;
  1499. }
  1500. else
  1501. {
  1502. $extra_user_updates[$option['update_length']] = TIME_NOW + $suspend_length;
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. // Those with javascript turned off will be able to select both - cheeky!
  1509. // Check to make sure we're not moderating AND suspending posting
  1510. if($extra_user_updates['moderateposts'] && $extra_user_updates['suspendposting'])
  1511. {
  1512. $errors[] = $lang->suspendmoderate_error;
  1513. }
  1514. if(is_array($errors))
  1515. {
  1516. $mybb->input['action'] = "editprofile";
  1517. }
  1518. else
  1519. {
  1520. $plugins->run_hooks("modcp_do_editprofile_update");
  1521. // Continue with the update if there is no errors
  1522. $user_info = $userhandler->update_user();
  1523. $db->update_query("users", $extra_user_updates, "uid='{$user['uid']}'");
  1524. log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->edited_user);
  1525. $plugins->run_hooks("modcp_do_editprofile_end");
  1526. redirect("modcp.php?action=finduser", $lang->redirect_user_updated);
  1527. }
  1528. }
  1529. }
  1530. if($mybb->input['action'] == "editprofile")
  1531. {
  1532. add_breadcrumb($lang->mcp_nav_editprofile, "modcp.php?action=editprofile");
  1533. $user = get_user($mybb->input['uid']);
  1534. if(!$user['uid'])
  1535. {
  1536. error($lang->invalid_user);
  1537. }
  1538. // Check if the current user has permission to edit this user
  1539. if(!modcp_can_manage_user($user['uid']))
  1540. {
  1541. error_no_permission();
  1542. }
  1543. if($user['website'] == "" || $user['website'] == "http://")
  1544. {
  1545. $user['website'] = "http://";
  1546. }
  1547. if($user['icq'] != "0")
  1548. {
  1549. $user['icq'] = intval($user['icq']);
  1550. }
  1551. if($user['icq'] == 0)
  1552. {
  1553. $user['icq'] = "";
  1554. }
  1555. if(!$errors)
  1556. {
  1557. $mybb->input = array_merge($user, $mybb->input);
  1558. list($mybb->input['birthday_day'], $mybb->input['birthday_month'], $mybb->input['birthday_year']) = explode("-", $user['birthday']);
  1559. }
  1560. else
  1561. {
  1562. $errors = inline_error($errors);
  1563. }
  1564. // Sanitize all input
  1565. foreach(array('usertitle', 'website', 'icq', 'aim', 'yahoo', 'msn', 'signature', 'birthday_day', 'birthday_month', 'birthday_year') as $field)
  1566. {
  1567. $mybb->input[$field] = htmlspecialchars_uni($mybb->input[$field]);
  1568. }
  1569. if($user['usertitle'] == "")
  1570. {
  1571. $query = $db->simple_select("usertitles", "*", "posts <='".$user['postnum']."'", array('order_by' => 'posts', 'order_dir' => 'DESC', 'limit' => 1));
  1572. $utitle = $db->fetch_array($query);
  1573. $defaulttitle = $utitle['title'];
  1574. }
  1575. else
  1576. {
  1577. if(!$user['displaygroup'])
  1578. {
  1579. $user['displaygroup'] = $user['usergroup'];
  1580. }
  1581. $displaygroupfields = array(
  1582. "usertitle"
  1583. );
  1584. $display_group = usergroup_displaygroup($user['displaygroup']);
  1585. $defaulttitle = $display_group['usertitle'];
  1586. }
  1587. if(empty($user['usertitle']))
  1588. {
  1589. $lang->current_custom_usertitle = '';
  1590. }
  1591. $bdaysel = '';
  1592. for($i = 1; $i <= 31; ++$i)
  1593. {
  1594. if($mybb->input['birthday_day'] == $i)
  1595. {
  1596. $bdaydaysel .= "<option value=\"$i\" selected=\"selected\">$i</option>\n";
  1597. }
  1598. else
  1599. {
  1600. $bdaydaysel .= "<option value=\"$i\">$i</option>\n";
  1601. }
  1602. }
  1603. $bdaymonthsel[$mybb->input['birthday_month']] = 'selected="selected"';
  1604. $plugins->run_hooks("modcp_editprofile_start");
  1605. // Fetch profile fields
  1606. $query = $db->simple_select("userfields", "*", "ufid='{$user['uid']}'");
  1607. $user_fields = $db->fetch_array($query);
  1608. $requiredfields = '';
  1609. $customfields = '';
  1610. $query = $db->simple_select("profilefields", "*", "", array('order_by' => 'disporder'));
  1611. while($profilefield = $db->fetch_array($query))
  1612. {
  1613. $profilefield['type'] = htmlspecialchars_uni($profilefield['type']);
  1614. $profilefield['description'] = htmlspecialchars_uni($profilefield['description']);
  1615. $thing = explode("\n", $profilefield['type'], "2");
  1616. $type = $thing[0];
  1617. $options = $thing[1];
  1618. $field = "fid{$profilefield['fid']}";
  1619. $select = '';
  1620. if($errors)
  1621. {
  1622. $userfield = $mybb->input['profile_fields'][$field];
  1623. }
  1624. else
  1625. {
  1626. $userfield = $user_fields[$field];
  1627. }
  1628. if($type == "multiselect")
  1629. {
  1630. if($errors)
  1631. {
  1632. $useropts = $userfield;
  1633. }
  1634. else
  1635. {
  1636. $useropts = explode("\n", $userfield);
  1637. }
  1638. if(is_array($useropts))
  1639. {
  1640. foreach($useropts as $key => $val)
  1641. {
  1642. $seloptions[$val] = $val;
  1643. }
  1644. }
  1645. $expoptions = explode("\n", $options);
  1646. if(is_array($expoptions))
  1647. {
  1648. foreach($expoptions as $key => $val)
  1649. {
  1650. $val = trim($val);
  1651. $val = str_replace("\n", "\\n", $val);
  1652. $sel = "";
  1653. if($val == $seloptions[$val])
  1654. {
  1655. $sel = " selected=\"selected\"";
  1656. }
  1657. $select .= "<option value=\"$val\"$sel>$val</option>\n";
  1658. }
  1659. if(!$profilefield['length'])
  1660. {
  1661. $profilefield['length'] = 3;
  1662. }
  1663. $code = "<select name=\"profile_fields[$field][]\" size=\"{$profilefield['length']}\" multiple=\"multiple\">$select</select>";
  1664. }
  1665. }
  1666. elseif($type == "select")
  1667. {
  1668. $expoptions = explode("\n", $options);
  1669. if(is_array($expoptions))
  1670. {
  1671. foreach($expoptions as $key => $val)
  1672. {
  1673. $val = trim($val);
  1674. $val = str_replace("\n", "\\n", $val);
  1675. $sel = "";
  1676. if($val == $userfield)
  1677. {
  1678. $sel = " selected=\"selected\"";
  1679. }
  1680. $select .= "<option value=\"$val\"$sel>$val</option>";
  1681. }
  1682. if(!$profilefield['length'])
  1683. {
  1684. $profilefield['length'] = 1;
  1685. }
  1686. $code = "<select name=\"profile_fields[$field]\" size=\"{$profilefield['length']}\">$select</select>";
  1687. }
  1688. }
  1689. elseif($type == "radio")
  1690. {
  1691. $expoptions = explode("\n", $options);
  1692. if(is_array($expoptions))
  1693. {
  1694. foreach($expoptions as $key => $val)
  1695. {
  1696. $checked = "";
  1697. if($val == $userfield)
  1698. {
  1699. $checked = " checked=\"checked\"";
  1700. }
  1701. $code .= "<input type=\"radio\" class=\"radio\" name=\"profile_fields[$field]\" value=\"$val\"$checked /> <span class=\"smalltext\">$val</span><br />";
  1702. }
  1703. }
  1704. }
  1705. elseif($type == "checkbox")
  1706. {
  1707. if($errors)
  1708. {
  1709. $useropts = $userfield;
  1710. }
  1711. else
  1712. {
  1713. $useropts = explode("\n", $userfield);
  1714. }
  1715. if(is_array($useropts))
  1716. {
  1717. foreach($useropts as $key => $val)
  1718. {
  1719. $seloptions[$val] = $val;
  1720. }
  1721. }
  1722. $expoptions = explode("\n", $options);
  1723. if(is_array($expoptions))
  1724. {
  1725. foreach($expoptions as $key => $val)
  1726. {
  1727. $checked = "";
  1728. if($val == $seloptions[$val])
  1729. {
  1730. $checked = " checked=\"checked\"";
  1731. }
  1732. $code .= "<input type=\"checkbox\" class=\"checkbox\" name=\"profile_fields[$field][]\" value=\"$val\"$checked /> <span class=\"smalltext\">$val</span><br />";
  1733. }
  1734. }
  1735. }
  1736. elseif($type == "textarea")
  1737. {
  1738. $value = htmlspecialchars_uni($userfield);
  1739. $code = "<textarea name=\"profile_fields[$field]\" rows=\"6\" cols=\"30\" style=\"width: 95%\">$value</textarea>";
  1740. }
  1741. else
  1742. {
  1743. $value = htmlspecialchars_uni($userfield);
  1744. $maxlength = "";
  1745. if($profilefield['maxlength'] > 0)
  1746. {
  1747. $maxlength = " maxlength=\"{$profilefield['maxlength']}\"";
  1748. }
  1749. $code = "<input type=\"text\" name=\"profile_fields[$field]\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"$value\" />";
  1750. }
  1751. if($profilefield['required'] == 1)
  1752. {
  1753. eval("\$requiredfields .= \"".$templates->get("usercp_profile_customfield")."\";");
  1754. }
  1755. else
  1756. {
  1757. eval("\$customfields .= \"".$templates->get("usercp_profile_customfield")."\";");
  1758. }
  1759. $altbg = alt_trow();
  1760. $code = "";
  1761. $select = "";
  1762. $val = "";
  1763. $options = "";
  1764. $expoptions = "";
  1765. $useropts = "";
  1766. $seloptions = "";
  1767. }
  1768. if($customfields)
  1769. {
  1770. eval("\$customfields = \"".$templates->get("usercp_profile_profilefields")."\";");
  1771. }
  1772. $lang->edit_profile = $lang->sprintf($lang->edit_profile, $user['username']);
  1773. $profile_link = build_profile_link(format_name($user['username'], $user['usergroup'], $user['displaygroup']), $user['uid']);
  1774. $codebuttons = build_mycode_inserter("signature");
  1775. // Do we mark the suspend signature box?
  1776. if($user['suspendsignature'] || ($mybb->input['suspendsignature'] && !empty($errors)))
  1777. {
  1778. $checked = 1;
  1779. $checked_item = "checked=\"checked\"";
  1780. }
  1781. else
  1782. {
  1783. $checked = 0;
  1784. }
  1785. // Do we mark the moderate posts box?
  1786. if($user['moderateposts'] || ($mybb->input['moderateposting'] && !empty($errors)))
  1787. {
  1788. $modpost_check = 1;
  1789. $modpost_checked = "checked=\"checked\"";
  1790. }
  1791. else
  1792. {
  1793. $modpost_check = 0;
  1794. }
  1795. // Do we mark the suspend posts box?
  1796. if($user['suspendposting'] || ($mybb->input['suspendposting'] && !empty($errors)))
  1797. {
  1798. $suspost_check = 1;
  1799. $suspost_checked = "checked=\"checked\"";
  1800. }
  1801. else
  1802. {
  1803. $suspost_check = 0;
  1804. }
  1805. $moderator_options = array(
  1806. 1 => array(
  1807. "action" => "suspendsignature", // The input action for this option
  1808. "option" => "suspendsignature", // The field in the database that this option relates to
  1809. "length" => "suspendsigtime", // The length of suspension field in the database
  1810. "select_option" => "action" // The name of the select box of this option
  1811. ),
  1812. 2 => array(
  1813. "action" => "moderateposting",
  1814. "option" => "moderateposts",
  1815. "length" => "moderationtime",
  1816. "select_option" => "modpost"
  1817. ),
  1818. 3 => array(
  1819. "action" => "suspendposting",
  1820. "option" => "suspendposting",
  1821. "length" => "suspensiontime",
  1822. "select_option" => "suspost"
  1823. )
  1824. );
  1825. $periods = array(
  1826. "hours" => $lang->expire_hours,
  1827. "days" => $lang->expire_days,
  1828. "weeks" => $lang->expire_weeks,
  1829. "months" => $lang->expire_months,
  1830. "never" => $lang->expire_permanent
  1831. );
  1832. foreach($moderator_options as $option)
  1833. {
  1834. // Display the suspension info, if this user has this option suspended
  1835. if($user[$option['option']])
  1836. {
  1837. if($user[$option['length']] == 0)
  1838. {
  1839. // User has a permanent ban
  1840. $string = $option['option']."_perm";
  1841. $suspension_info = $lang->$string;
  1842. }
  1843. else
  1844. {
  1845. // User has a temporary (or limited) ban
  1846. $string = $option['option']."_for";
  1847. $for_date = my_date($mybb->settings['dateformat'], $user[$option['length']]);
  1848. $for_time = my_date($mybb->settings['timeformat'], $user[$option['length']]);
  1849. $suspension_info = $lang->sprintf($lang->$string, $for_date, $for_time);
  1850. }
  1851. switch($option['option'])
  1852. {
  1853. case "suspendsignature":
  1854. eval("\$suspendsignature_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";");
  1855. break;
  1856. case "moderateposts":
  1857. eval("\$moderateposts_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";");
  1858. break;
  1859. case "suspendposting":
  1860. eval("\$suspendposting_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";");
  1861. break;
  1862. }
  1863. }
  1864. // Generate the boxes for this option
  1865. $selection_options = '';
  1866. foreach($periods as $key => $value)
  1867. {
  1868. $string = $option['select_option']."_period";
  1869. if($mybb->input[$string] == $key)
  1870. {
  1871. $selected = "selected=\"selected\"";
  1872. }
  1873. else
  1874. {
  1875. $selected = '';
  1876. }
  1877. eval("\$selection_options .= \"".$templates->get("modcp_editprofile_select_option")."\";");
  1878. }
  1879. $select_name = $option['select_option']."_period";
  1880. switch($option['option'])
  1881. {
  1882. case "suspendsignature":
  1883. eval("\$action_options = \"".$templates->get("modcp_editprofile_select")."\";");
  1884. break;
  1885. case "moderateposts":
  1886. eval("\$modpost_options = \"".$templates->get("modcp_editprofile_select")."\";");
  1887. break;
  1888. case "suspendposting":
  1889. eval("\$suspost_options = \"".$templates->get("modcp_editprofile_select")."\";");
  1890. break;
  1891. }
  1892. }
  1893. eval("\$suspend_signature = \"".$templates->get("modcp_editprofile_signature")."\";");
  1894. $plugins->run_hooks("modcp_editprofile_end");
  1895. eval("\$edituser = \"".$templates->get("modcp_editprofile")."\";");
  1896. output_page($edituser);
  1897. }
  1898. if($mybb->input['action'] == "finduser")
  1899. {
  1900. add_breadcrumb($lang->mcp_nav_users, "modcp.php?action=finduser");
  1901. $perpage = intval($mybb->input['perpage']);
  1902. if(!$perpage || $perpage <= 0)
  1903. {
  1904. $perpage = $mybb->settings['threadsperpage'];
  1905. }
  1906. $where = '';
  1907. if($mybb->input['username'])
  1908. {
  1909. $where = " AND LOWER(username) LIKE '%".my_strtolower($db->escape_string_like($mybb->input['username']))."%'";
  1910. }
  1911. // Sort order & direction
  1912. switch($mybb->input['sortby'])
  1913. {
  1914. case "lastvisit":
  1915. $sortby = "lastvisit";
  1916. break;
  1917. case "postnum":
  1918. $sortby = "postnum";
  1919. break;
  1920. case "username":
  1921. $sortby = "username";
  1922. break;
  1923. default:
  1924. $sortby = "regdate";
  1925. }
  1926. $order = $mybb->input['order'];
  1927. if($order != "asc")
  1928. {
  1929. $order = "desc";
  1930. }
  1931. $query = $db->simple_select("users", "COUNT(uid) AS count", "1=1 {$where}");
  1932. $user_count = $db->fetch_field($query, "count");
  1933. // Figure out if we need to display multiple pages.
  1934. if($mybb->input['page'] != "last")
  1935. {
  1936. $page = intval($mybb->input['page']);
  1937. }
  1938. $pages = $user_count / $perpage;
  1939. $pages = ceil($pages);
  1940. if($mybb->input['page'] == "last")
  1941. {
  1942. $page = $pages;
  1943. }
  1944. if($page > $pages || $page <= 0)
  1945. {
  1946. $page = 1;
  1947. }
  1948. if($page)
  1949. {
  1950. $start = ($page-1) * $perpage;
  1951. }
  1952. else
  1953. {
  1954. $start = 0;
  1955. $page = 1;
  1956. }
  1957. $page_url = 'modcp.php?action=finduser';
  1958. foreach(array('username', 'sortby', 'order') as $field)
  1959. {
  1960. if($mybb->input[$field])
  1961. {
  1962. $page_url .= "&amp;{$field}=".htmlspecialchars_uni($mybb->input[$field]);
  1963. $mybb->input[$field] = htmlspecialchars_uni($mybb->input[$field]);
  1964. }
  1965. }
  1966. $multipage = multipage($user_count, $perpage, $page, $page_url);
  1967. $usergroups_cache = $cache->read("usergroups");
  1968. $plugins->run_hooks("modcp_finduser_start");
  1969. // Fetch out results
  1970. $query = $db->simple_select("users", "*", "1=1 {$where}", array("order_by" => $sortby, "order_dir" => $order, "limit" => $perpage, "limit_start" => $start));
  1971. while($user = $db->fetch_array($query))
  1972. {
  1973. $alt_row = alt_trow();
  1974. $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
  1975. $user['postnum'] = my_number_format($user['postnum']);
  1976. $regdate = my_date($mybb->settings['dateformat'], $user['regdate']);
  1977. $regtime = my_date($mybb->settings['timeformat'], $user['regdate']);
  1978. $lastdate = my_date($mybb->settings['dateformat'], $user['lastvisit']);
  1979. $lasttime = my_date($mybb->settings['timeformat'], $user['lastvisit']);
  1980. $usergroup = $usergroups_cache[$user['usergroup']]['title'];
  1981. eval("\$users .= \"".$templates->get("modcp_finduser_user")."\";");
  1982. }
  1983. // No results?
  1984. if(!$users)
  1985. {
  1986. eval("\$users = \"".$templates->get("modcp_finduser_noresults")."\";");
  1987. }
  1988. $plugins->run_hooks("modcp_finduser_end");
  1989. eval("\$finduser = \"".$templates->get("modcp_finduser")."\";");
  1990. output_page($finduser);
  1991. }
  1992. if($mybb->input['action'] == "warninglogs")
  1993. {
  1994. add_breadcrumb($lang->mcp_nav_warninglogs, "modcp.php?action=warninglogs");
  1995. // Filter options
  1996. $where_sql = '';
  1997. if($mybb->input['filter']['username'])
  1998. {
  1999. $search['username'] = $db->escape_string($mybb->input['filter']['username']);
  2000. $query = $db->simple_select("users", "uid", "username='{$search['username']}'");
  2001. $mybb->input['filter']['uid'] = $db->fetch_field($query, "uid");
  2002. $mybb->input['filter']['username'] = htmlspecialchars_uni($mybb->input['filter']['username']);
  2003. }
  2004. if($mybb->input['filter']['uid'])
  2005. {
  2006. $search['uid'] = intval($mybb->input['filter']['uid']);
  2007. $where_sql .= " AND w.uid='{$search['uid']}'";
  2008. if(!isset($mybb->input['search']['username']))
  2009. {
  2010. $user = get_user($mybb->input['search']['uid']);
  2011. $mybb->input['search']['username'] = htmlspecialchars_uni($user['username']);
  2012. }
  2013. }
  2014. if($mybb->input['filter']['mod_username'])
  2015. {
  2016. $search['mod_username'] = $db->escape_string($mybb->input['filter']['mod_username']);
  2017. $query = $db->simple_select("users", "uid", "username='{$search['mod_username']}'");
  2018. $mybb->input['filter']['mod_uid'] = $db->fetch_field($query, "uid");
  2019. $mybb->input['filter']['mod_username'] = htmlspecialchars_uni($mybb->input['filter']['mod_username']);
  2020. }
  2021. if($mybb->input['filter']['mod_uid'])
  2022. {
  2023. $search['mod_uid'] = intval($mybb->input['filter']['mod_uid']);
  2024. $where_sql .= " AND w.issuedby='{$search['mod_uid']}'";
  2025. if(!isset($mybb->input['search']['mod_username']))
  2026. {
  2027. $mod_user = get_user($mybb->input['search']['uid']);
  2028. $mybb->input['search']['mod_username'] = htmlspecialchars_uni($mod_user['username']);
  2029. }
  2030. }
  2031. if($mybb->input['filter']['reason'])
  2032. {
  2033. $search['reason'] = $db->escape_string($mybb->input['filter']['reason']);
  2034. $where_sql .= " AND (w.notes LIKE '%{$search['reason']}%' OR t.title LIKE '%{$search['reason']}%' OR w.title LIKE '%{$search['reason']}%')";
  2035. $mybb->input['filter']['reason'] = htmlspecialchars_uni($mybb->input['filter']['reason']);
  2036. }
  2037. $sortbysel = array();
  2038. switch($mybb->input['filter']['sortby'])
  2039. {
  2040. case "username":
  2041. $sortby = "u.username";
  2042. $sortbysel['username'] = ' selected="selected"';
  2043. break;
  2044. case "expires":
  2045. $sortby = "w.expires";
  2046. $sortbysel['expires'] = ' selected="selected"';
  2047. break;
  2048. case "issuedby":
  2049. $sortby = "i.username";
  2050. $sortbysel['issuedby'] = ' selected="selected"';
  2051. break;
  2052. default: // "dateline"
  2053. $sortby = "w.dateline";
  2054. $sortbysel['dateline'] = ' selected="selected"';
  2055. }
  2056. $order = $mybb->input['filter']['order'];
  2057. $ordersel = array();
  2058. if($order != "asc")
  2059. {
  2060. $order = "desc";
  2061. $ordersel['desc'] = ' selected="selected"';
  2062. }
  2063. else
  2064. {
  2065. $ordersel['asc'] = ' selected="selected"';
  2066. }
  2067. $plugins->run_hooks("modcp_warninglogs_start");
  2068. // Pagination stuff
  2069. $sql = "
  2070. SELECT COUNT(wid) as count
  2071. FROM
  2072. ".TABLE_PREFIX."warnings w
  2073. LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
  2074. WHERE 1=1
  2075. {$where_sql}
  2076. ";
  2077. $query = $db->query($sql);
  2078. $total_warnings = $db->fetch_field($query, 'count');
  2079. $page = 1;
  2080. if(isset($mybb->input['page']) && intval($mybb->input['page']) > 0)
  2081. {
  2082. $page = intval($mybb->input['page']);
  2083. }
  2084. $per_page = 20;
  2085. if(isset($mybb->input['filter']['per_page']) && intval($mybb->input['filter']['per_page']) > 0)
  2086. {
  2087. $per_page = intval($mybb->input['filter']['per_page']);
  2088. }
  2089. $start = ($page-1) * $per_page;
  2090. // Build the base URL for pagination links
  2091. $url = 'modcp.php?action=warninglogs';
  2092. if(is_array($mybb->input['filter']) && count($mybb->input['filter']))
  2093. {
  2094. foreach($mybb->input['filter'] as $field => $value)
  2095. {
  2096. $value = urlencode($value);
  2097. $url .= "&amp;filter[{$field}]={$value}";
  2098. }
  2099. }
  2100. $multipage = multipage($total_warnings, $per_page, $page, $url);
  2101. // The actual query
  2102. $sql = "
  2103. SELECT
  2104. w.wid, w.title as custom_title, w.points, w.dateline, w.issuedby, w.expires, w.expired, w.daterevoked, w.revokedby,
  2105. t.title,
  2106. u.uid, u.username, u.usergroup, u.displaygroup,
  2107. i.uid as mod_uid, i.username as mod_username, i.usergroup as mod_usergroup, i.displaygroup as mod_displaygroup
  2108. FROM ".TABLE_PREFIX."warnings w
  2109. LEFT JOIN ".TABLE_PREFIX."users u ON (w.uid=u.uid)
  2110. LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid)
  2111. LEFT JOIN ".TABLE_PREFIX."users i ON (i.uid=w.issuedby)
  2112. WHERE 1=1
  2113. {$where_sql}
  2114. ORDER BY {$sortby} {$order}
  2115. LIMIT {$start}, {$per_page}
  2116. ";
  2117. $query = $db->query($sql);
  2118. $warning_list = '';
  2119. while($row = $db->fetch_array($query))
  2120. {
  2121. $trow = alt_trow();
  2122. $username = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
  2123. $username_link = build_profile_link($username, $row['uid']);
  2124. $mod_username = format_name($row['mod_username'], $row['mod_usergroup'], $row['mod_displaygroup']);
  2125. $mod_username_link = build_profile_link($mod_username, $row['mod_uid']);
  2126. $issued_date = my_date($mybb->settings['dateformat'], $row['dateline']).' '.my_date($mybb->settings['timeformat'], $row['dateline']);
  2127. $revoked_text = '';
  2128. if($row['daterevoked'] > 0)
  2129. {
  2130. $revoked_date = my_date($mybb->settings['dateformat'], $row['daterevoked']).' '.my_date($mybb->settings['timeformat'], $row['daterevoked']);
  2131. eval("\$revoked_text = \"".$templates->get("modcp_warninglogs_warning_revoked")."\";");
  2132. }
  2133. if($row['expires'] > 0)
  2134. {
  2135. $expire_date = my_date($mybb->settings['dateformat'], $row['expires']).' '.my_date($mybb->settings['timeformat'], $row['expires']);
  2136. }
  2137. else
  2138. {
  2139. $expire_date = $lang->never;
  2140. }
  2141. $title = $row['title'];
  2142. if(empty($row['title']))
  2143. {
  2144. $title = $row['custom_title'];
  2145. }
  2146. $title = htmlspecialchars_uni($title);
  2147. if($row['points'] >= 0)
  2148. {
  2149. $points = '+'.$row['points'];
  2150. }
  2151. eval("\$warning_list .= \"".$templates->get("modcp_warninglogs_warning")."\";");
  2152. }
  2153. if(!$warning_list)
  2154. {
  2155. eval("\$warning_list = \"".$templates->get("modcp_warninglogs_nologs")."\";");
  2156. }
  2157. $plugins->run_hooks("modcp_warninglogs_end");
  2158. eval("\$warninglogs = \"".$templates->get("modcp_warninglogs")."\";");
  2159. output_page($warninglogs);
  2160. }
  2161. if($mybb->input['action'] == "ipsearch")
  2162. {
  2163. add_breadcrumb($lang->mcp_nav_ipsearch, "modcp.php?action=ipsearch");
  2164. if($mybb->input['ipaddress'])
  2165. {
  2166. if(!is_array($groupscache))
  2167. {
  2168. $groupscache = $cache->read("usergroups");
  2169. }
  2170. $ipaddressvalue = htmlspecialchars_uni($mybb->input['ipaddress']);
  2171. // Searching post IP addresses
  2172. if($mybb->input['search_posts'])
  2173. {
  2174. // IPv6 IP
  2175. if(strpos($mybb->input['ipaddress'], ":") !== false)
  2176. {
  2177. $post_ip_sql = "ipaddress LIKE '".$db->escape_string(str_replace("*", "%", $mybb->input['ipaddress']))."'";
  2178. }
  2179. else
  2180. {
  2181. $ip_range = fetch_longipv4_range($mybb->input['ipaddress']);
  2182. if($ip_range)
  2183. {
  2184. if(!is_array($ip_range))
  2185. {
  2186. $post_ip_sql = "longipaddress='{$ip_range}'";
  2187. }
  2188. else
  2189. {
  2190. $post_ip_sql = "longipaddress > '{$ip_range[0]}' AND longipaddress < '{$ip_range[1]}'";
  2191. }
  2192. }
  2193. }
  2194. $plugins->run_hooks("modcp_ipsearch_posts_start");
  2195. if($post_ip_sql)
  2196. {
  2197. $query = $db->query("
  2198. SELECT COUNT(pid) AS count
  2199. FROM ".TABLE_PREFIX."posts
  2200. WHERE {$post_ip_sql}
  2201. ");
  2202. $post_results = $db->fetch_field($query, "count");
  2203. }
  2204. }
  2205. // Searching user IP addresses
  2206. if($mybb->input['search_users'])
  2207. {
  2208. // IPv6 IP
  2209. if(strpos($mybb->input['ipaddress'], ":") !== false)
  2210. {
  2211. $user_ip_sql = "regip LIKE '".$db->escape_string(str_replace("*", "%", $mybb->input['ipaddress']))."' OR lastip LIKE '".$db->escape_string(str_replace("*", "%", $mybb->input['ipaddress']))."'";
  2212. }
  2213. else
  2214. {
  2215. $ip_range = fetch_longipv4_range($mybb->input['ipaddress']);
  2216. if($ip_range)
  2217. {
  2218. if(!is_array($ip_range))
  2219. {
  2220. $user_ip_sql = "longregip='{$ip_range}' OR longlastip='{$ip_range}'";
  2221. }
  2222. else
  2223. {
  2224. $user_ip_sql = "(longregip > '{$ip_range[0]}' AND longregip < '{$ip_range[1]}') OR (longlastip > '{$ip_range[0]}' AND longlastip < '{$ip_range[1]}')";
  2225. }
  2226. }
  2227. }
  2228. $plugins->run_hooks("modcp_ipsearch_users_start");
  2229. if($user_ip_sql)
  2230. {
  2231. $query = $db->query("
  2232. SELECT COUNT(uid) AS count
  2233. FROM ".TABLE_PREFIX."users
  2234. WHERE {$user_ip_sql}
  2235. ");
  2236. $user_results = $db->fetch_field($query, "count");
  2237. }
  2238. }
  2239. $total_results = $post_results+$user_results;
  2240. if(!$total_results)
  2241. {
  2242. $total_results = 1;
  2243. }
  2244. // Now we have the result counts, paginate
  2245. $perpage = intval($mybb->input['perpage']);
  2246. if(!$perpage || $perpage <= 0)
  2247. {
  2248. $perpage = $mybb->settings['threadsperpage'];
  2249. }
  2250. // Figure out if we need to display multiple pages.
  2251. if($mybb->input['page'] != "last")
  2252. {
  2253. $page = intval($mybb->input['page']);
  2254. }
  2255. $pages = $total_results / $perpage;
  2256. $pages = ceil($pages);
  2257. if($mybb->input['page'] == "last")
  2258. {
  2259. $page = $pages;
  2260. }
  2261. if($page > $pages || $page <= 0)
  2262. {
  2263. $page = 1;
  2264. }
  2265. if($page)
  2266. {
  2267. $start = ($page-1) * $perpage;
  2268. }
  2269. else
  2270. {
  2271. $start = 0;
  2272. $page = 1;
  2273. }
  2274. $page_url = "modcp.php?action=ipsearch&amp;perpage={$perpage}";
  2275. foreach(array('ipaddress', 'search_users', 'search_posts') as $input)
  2276. {
  2277. if(!$mybb->input[$input]) continue;
  2278. $page_url .= "&amp;{$input}=".htmlspecialchars_uni($mybb->input[$input]);
  2279. }
  2280. $multipage = multipage($total_results, $perpage, $page, $page_url);
  2281. $post_limit = $perpage;
  2282. if($mybb->input['search_users'] && $user_results && $start <= $user_results)
  2283. {
  2284. $query = $db->query("
  2285. SELECT username, uid, regip, lastip
  2286. FROM ".TABLE_PREFIX."users
  2287. WHERE {$user_ip_sql}
  2288. ORDER BY regdate DESC
  2289. LIMIT {$start}, {$perpage}
  2290. ");
  2291. while($ipaddress = $db->fetch_array($query))
  2292. {
  2293. $result = false;
  2294. $profile_link = build_profile_link($ipaddress['username'], $ipaddress['uid']);
  2295. $trow = alt_trow();
  2296. $regexp_ip = str_replace("\*", "(.*)", preg_quote($mybb->input['ipaddress'], "#"));
  2297. // Reg IP matches
  2298. if(preg_match("#{$regexp_ip}#i", $ipaddress['regip']))
  2299. {
  2300. $ip = $ipaddress['regip'];
  2301. $subject = "<strong>{$lang->ipresult_regip}</strong> {$profile_link}";
  2302. eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";");
  2303. $result = true;
  2304. }
  2305. // Last known IP matches
  2306. if(preg_match("#{$regexp_ip}#i", $ipaddress['lastip']))
  2307. {
  2308. $ip = $ipaddress['lastip'];
  2309. $subject = "<strong>{$lang->ipresult_lastip}</strong> {$profile_link}";
  2310. eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";");
  2311. $result = true;
  2312. }
  2313. if($result)
  2314. {
  2315. --$post_limit;
  2316. }
  2317. }
  2318. }
  2319. $post_start = 0;
  2320. if($total_results > $user_results && $post_limit)
  2321. {
  2322. $post_start = $start-$user_results;
  2323. if($post_start < 0)
  2324. {
  2325. $post_start = 0;
  2326. }
  2327. }
  2328. if($mybb->input['search_posts'] && $post_results && (!$mybb->input['search_users'] || ($mybb->input['search_users'] && $post_limit > 0)))
  2329. {
  2330. $ipaddresses = $tids = $uids = array();
  2331. $query = $db->query("
  2332. SELECT username AS postusername, uid, subject, pid, tid, ipaddress
  2333. FROM ".TABLE_PREFIX."posts
  2334. WHERE {$post_ip_sql}
  2335. ORDER BY dateline DESC
  2336. LIMIT {$post_start}, {$post_limit}
  2337. ");
  2338. while($ipaddress = $db->fetch_array($query))
  2339. {
  2340. $tids[$ipaddress['tid']] = $ipaddress['pid'];
  2341. $uids[$ipaddress['uid']] = $ipaddress['pid'];
  2342. $ipaddresses[$ipaddress['pid']] = $ipaddress;
  2343. }
  2344. if(!empty($ipaddresses))
  2345. {
  2346. $query = $db->simple_select("threads", "subject, tid", "tid IN(".implode(',', array_keys($tids)).")");
  2347. while($thread = $db->fetch_array($query))
  2348. {
  2349. $ipaddresses[$tids[$thread['tid']]]['threadsubject'] = $thread['subject'];
  2350. }
  2351. unset($tids);
  2352. $query = $db->simple_select("users", "username, uid", "uid IN(".implode(',', array_keys($uids)).")");
  2353. while($user = $db->fetch_array($query))
  2354. {
  2355. $ipaddresses[$uids[$user['uid']]]['username'] = $user['username'];
  2356. }
  2357. unset($uids);
  2358. foreach($ipaddresses as $ipaddress)
  2359. {
  2360. $ip = $ipaddress['ipaddress'];
  2361. if(!$ipaddress['username']) $ipaddress['username'] = $ipaddress['postusername']; // Guest username support
  2362. $trow = alt_trow();
  2363. if(!$ipaddress['subject'])
  2364. {
  2365. $ipaddress['subject'] = "RE: {$ipaddress['threadsubject']}";
  2366. }
  2367. $subject = "<strong>{$lang->ipresult_post}</strong> <a href=\"".get_post_link($ipaddress['pid'], $ipaddress['tid'])."\">".htmlspecialchars_uni($ipaddress['subject'])."</a> {$lang->by} ".build_profile_link($ipaddress['username'], $ipaddress['uid']);
  2368. eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";");
  2369. }
  2370. }
  2371. }
  2372. if(!$results)
  2373. {
  2374. eval("\$results = \"".$templates->get("modcp_ipsearch_noresults")."\";");
  2375. }
  2376. if($ipaddressvalue)
  2377. {
  2378. $lang->ipsearch_results = $lang->sprintf($lang->ipsearch_results, $ipaddressvalue);
  2379. }
  2380. else
  2381. {
  2382. $lang->ipsearch_results = $lang->ipsearch;
  2383. }
  2384. if(!strstr($mybb->input['ipaddress'], "*") && !strstr($mybb->input['ipaddress'], ":"))
  2385. {
  2386. $misc_info_link = "<div class=\"float_right\">(<a href=\"modcp.php?action=iplookup&ipaddress=".htmlspecialchars_uni($mybb->input['ipaddress'])."\" onclick=\"MyBB.popupWindow('{$mybb->settings['bburl']}/modcp.php?action=iplookup&ipaddress=".urlencode($mybb->input['ipaddress'])."', 'iplookup', 500, 250); return false;\">{$lang->info_on_ip}</a>)</div>";
  2387. }
  2388. eval("\$ipsearch_results = \"".$templates->get("modcp_ipsearch_results")."\";");
  2389. }
  2390. // Fetch filter options
  2391. if(!$mybb->input['ipaddress'])
  2392. {
  2393. $mybb->input['search_posts'] = 1;
  2394. $mybb->input['search_users'] = 1;
  2395. }
  2396. if($mybb->input['search_posts'])
  2397. {
  2398. $postsearchselect = "checked=\"checked\"";
  2399. }
  2400. if($mybb->input['search_users'])
  2401. {
  2402. $usersearchselect = "checked=\"checked\"";
  2403. }
  2404. $plugins->run_hooks("modcp_ipsearch_end");
  2405. eval("\$ipsearch = \"".$templates->get("modcp_ipsearch")."\";");
  2406. output_page($ipsearch);
  2407. }
  2408. if($mybb->input['action'] == "iplookup")
  2409. {
  2410. $lang->ipaddress_misc_info = $lang->sprintf($lang->ipaddress_misc_info, htmlspecialchars_uni($mybb->input['ipaddress']));
  2411. $ipaddress_location = $lang->na;
  2412. $ipaddress_host_name = $lang->na;
  2413. $modcp_ipsearch_misc_info = '';
  2414. if(!strstr($mybb->input['ipaddress'], "*") && !strstr($mybb->input['ipaddress'], ":"))
  2415. {
  2416. // Return GeoIP information if it is available to us
  2417. if(function_exists('geoip_record_by_name'))
  2418. {
  2419. $ip_record = @geoip_record_by_name($mybb->input['ipaddress']);
  2420. if($ip_record)
  2421. {
  2422. $ipaddress_location = htmlspecialchars_uni($ip_record['country_name']);
  2423. if($ip_record['city'])
  2424. {
  2425. $ipaddress_location .= $lang->comma.htmlspecialchars_uni($ip_record['city']);
  2426. }
  2427. }
  2428. }
  2429. $ipaddress_host_name = htmlspecialchars_uni(@gethostbyaddr($mybb->input['ipaddress']));
  2430. // gethostbyaddr returns the same ip on failure
  2431. if($ipaddress_host_name == $mybb->input['ipaddress'])
  2432. {
  2433. $ipaddress_host_name = $lang->na;
  2434. }
  2435. }
  2436. $plugins->run_hooks("modcp_iplookup_end");
  2437. eval("\$iplookup = \"".$templates->get('modcp_ipsearch_misc_info')."\";");
  2438. output_page($iplookup);
  2439. }
  2440. if($mybb->input['action'] == "banning")
  2441. {
  2442. add_breadcrumb($lang->mcp_nav_banning, "modcp.php?action=banning");
  2443. if(!$mybb->settings['threadsperpage'])
  2444. {
  2445. $mybb->settings['threadsperpage'] = 20;
  2446. }
  2447. // Figure out if we need to display multiple pages.
  2448. $perpage = $mybb->settings['threadsperpage'];
  2449. if($mybb->input['page'] != "last")
  2450. {
  2451. $page = intval($mybb->input['page']);
  2452. }
  2453. $query = $db->simple_select("banned", "COUNT(uid) AS count");
  2454. $banned_count = $db->fetch_field($query, "count");
  2455. $postcount = intval($banned_count);
  2456. $pages = $postcount / $perpage;
  2457. $pages = ceil($pages);
  2458. if($mybb->input['page'] == "last")
  2459. {
  2460. $page = $pages;
  2461. }
  2462. if($page > $pages || $page <= 0)
  2463. {
  2464. $page = 1;
  2465. }
  2466. if($page)
  2467. {
  2468. $start = ($page-1) * $perpage;
  2469. }
  2470. else
  2471. {
  2472. $start = 0;
  2473. $page = 1;
  2474. }
  2475. $upper = $start+$perpage;
  2476. $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=banning");
  2477. if($postcount > $perpage)
  2478. {
  2479. eval("\$allbannedpages = \"".$templates->get("modcp_banning_multipage")."\";");
  2480. }
  2481. $plugins->run_hooks("modcp_banning_start");
  2482. $query = $db->query("
  2483. SELECT b.*, a.username AS adminuser, u.username
  2484. FROM ".TABLE_PREFIX."banned b
  2485. LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid)
  2486. LEFT JOIN ".TABLE_PREFIX."users a ON (b.admin=a.uid)
  2487. ORDER BY lifted ASC
  2488. LIMIT {$start}, {$perpage}
  2489. ");
  2490. // Get the banned users
  2491. while($banned = $db->fetch_array($query))
  2492. {
  2493. $profile_link = build_profile_link($banned['username'], $banned['uid']);
  2494. // Only show the edit & lift links if current user created ban, or is super mod/admin
  2495. $edit_link = '';
  2496. if($mybb->user['uid'] == $banned['admin'] || !$banned['adminuser'] || $mybb->usergroup['issupermod'] == 1 || $mybb->usergroup['cancp'] == 1)
  2497. {
  2498. $edit_link = "<br /><span class=\"smalltext\"><a href=\"modcp.php?action=banuser&amp;uid={$banned['uid']}\">{$lang->edit_ban}</a> | <a href=\"modcp.php?action=liftban&amp;uid={$banned['uid']}&amp;my_post_key={$mybb->post_code}\">{$lang->lift_ban}</a></span>";
  2499. }
  2500. $admin_profile = build_profile_link($banned['adminuser'], $banned['admin']);
  2501. $trow = alt_trow();
  2502. if($banned['reason'])
  2503. {
  2504. $banned['reason'] = htmlspecialchars_uni($parser->parse_badwords($banned['reason']));
  2505. }
  2506. else
  2507. {
  2508. $banned['reason'] = $lang->na;
  2509. }
  2510. if($banned['lifted'] == 'perm' || $banned['lifted'] == '' || $banned['bantime'] == 'perm' || $banned['bantime'] == '---')
  2511. {
  2512. $banlength = $lang->permanent;
  2513. $timeremaining = $lang->na;
  2514. }
  2515. else
  2516. {
  2517. $banlength = $bantimes[$banned['bantime']];
  2518. $remaining = $banned['lifted']-TIME_NOW;
  2519. $timeremaining = nice_time($remaining, array('short' => 1, 'seconds' => false))."";
  2520. if($remaining < 3600)
  2521. {
  2522. $timeremaining = "<span style=\"color: red;\">({$timeremaining} {$lang->ban_remaining})</span>";
  2523. }
  2524. else if($remaining < 86400)
  2525. {
  2526. $timeremaining = "<span style=\"color: maroon;\">({$timeremaining} {$lang->ban_remaining})</span>";
  2527. }
  2528. else if($remaining < 604800)
  2529. {
  2530. $timeremaining = "<span style=\"color: green;\">({$timeremaining} {$lang->ban_remaining})</span>";
  2531. }
  2532. else
  2533. {
  2534. $timeremaining = "({$timeremaining} {$lang->ban_remaining})";
  2535. }
  2536. }
  2537. eval("\$bannedusers .= \"".$templates->get("modcp_banning_ban")."\";");
  2538. }
  2539. if(!$bannedusers)
  2540. {
  2541. eval("\$bannedusers = \"".$templates->get("modcp_banning_nobanned")."\";");
  2542. }
  2543. $plugins->run_hooks("modcp_banning");
  2544. eval("\$bannedpage = \"".$templates->get("modcp_banning")."\";");
  2545. output_page($bannedpage);
  2546. }
  2547. if($mybb->input['action'] == "liftban")
  2548. {
  2549. // Verify incoming POST request
  2550. verify_post_check($mybb->input['my_post_key']);
  2551. $query = $db->simple_select("banned", "*", "uid='".intval($mybb->input['uid'])."'");
  2552. $ban = $db->fetch_array($query);
  2553. if(!$ban['uid'])
  2554. {
  2555. error($lang->error_invalidban);
  2556. }
  2557. // Permission to edit this ban?
  2558. if($mybb->user['uid'] != $ban['admin'] && $mybb->usergroup['issupermod'] != 1 && $mybb->usergroup['cancp'] != 1)
  2559. {
  2560. error_no_permission();
  2561. }
  2562. $plugins->run_hooks("modcp_liftban_start");
  2563. $query = $db->simple_select("users", "username", "uid = '{$ban['uid']}'");
  2564. $username = $db->fetch_field($query, "username");
  2565. $updated_group = array(
  2566. 'usergroup' => $ban['oldgroup'],
  2567. 'additionalgroups' => $ban['oldadditionalgroups'],
  2568. 'displaygroup' => $ban['olddisplaygroup']
  2569. );
  2570. $db->update_query("users", $updated_group, "uid='{$ban['uid']}'");
  2571. $db->delete_query("banned", "uid='{$ban['uid']}'");
  2572. $cache->update_banned();
  2573. $cache->update_moderators();
  2574. log_moderator_action(array("uid" => $ban['uid'], "username" => $username), $lang->lifted_ban);
  2575. $plugins->run_hooks("modcp_liftban_end");
  2576. redirect("modcp.php?action=banning", $lang->redirect_banlifted);
  2577. }
  2578. if($mybb->input['action'] == "do_banuser" && $mybb->request_method == "post")
  2579. {
  2580. // Verify incoming POST request
  2581. verify_post_check($mybb->input['my_post_key']);
  2582. // Editing an existing ban
  2583. if($mybb->input['uid'])
  2584. {
  2585. // Get the users info from their uid
  2586. $query = $db->query("
  2587. SELECT b.*, u.uid, u.usergroup, u.additionalgroups, u.displaygroup
  2588. FROM ".TABLE_PREFIX."banned b
  2589. LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid)
  2590. WHERE b.uid='{$mybb->input['uid']}'
  2591. ");
  2592. $user = $db->fetch_array($query);
  2593. if(!$user['uid'])
  2594. {
  2595. error($lang->error_invalidban);
  2596. }
  2597. // Permission to edit this ban?
  2598. if($mybb->user['uid'] != $user['admin'] && $mybb->usergroup['issupermod'] != 1 && $mybb->usergroup['cancp'] != 1)
  2599. {
  2600. error_no_permission();
  2601. }
  2602. }
  2603. // Creating a new ban
  2604. else
  2605. {
  2606. // Get the users info from their Username
  2607. $query = $db->simple_select("users", "uid, username, usergroup, additionalgroups, displaygroup", "username = '".$db->escape_string($mybb->input['username'])."'", array('limit' => 1));
  2608. $user = $db->fetch_array($query);
  2609. if(!$user['uid'])
  2610. {
  2611. $errors[] = $lang->invalid_username;
  2612. }
  2613. }
  2614. if($user['uid'] == $mybb->user['uid'])
  2615. {
  2616. $errors[] = $lang->error_cannotbanself;
  2617. }
  2618. // Have permissions to ban this user?
  2619. if(!modcp_can_manage_user($user['uid']))
  2620. {
  2621. $errors[] = $lang->error_cannotbanuser;
  2622. }
  2623. // Check for an incoming reason
  2624. if(!$mybb->input['banreason'])
  2625. {
  2626. $errors[] = $lang->error_nobanreason;
  2627. }
  2628. // Check banned group
  2629. $query = $db->simple_select("usergroups", "gid", "isbannedgroup=1 AND gid='".intval($mybb->input['usergroup'])."'");
  2630. if(!$db->fetch_field($query, "gid"))
  2631. {
  2632. $errors[] = $lang->error_nobangroup;
  2633. }
  2634. // If this is a new ban, we check the user isn't already part of a banned group
  2635. if(!$mybb->input['uid'] && $user['uid'])
  2636. {
  2637. $query = $db->simple_select("banned", "uid", "uid='{$user['uid']}'");
  2638. if($db->fetch_field($query, "uid"))
  2639. {
  2640. $errors[] = $lang->error_useralreadybanned;
  2641. }
  2642. }
  2643. $plugins->run_hooks("modcp_do_banuser_start");
  2644. // Still no errors? Ban the user
  2645. if(!$errors)
  2646. {
  2647. // Ban the user
  2648. if($mybb->input['liftafter'] == '---')
  2649. {
  2650. $lifted = 0;
  2651. }
  2652. else
  2653. {
  2654. $lifted = ban_date2timestamp($mybb->input['liftafter'], $user['dateline']);
  2655. }
  2656. if($mybb->input['uid'])
  2657. {
  2658. $update_array = array(
  2659. 'gid' => intval($mybb->input['usergroup']),
  2660. 'admin' => intval($mybb->user['uid']),
  2661. 'dateline' => TIME_NOW,
  2662. 'bantime' => $db->escape_string($mybb->input['liftafter']),
  2663. 'lifted' => $db->escape_string($lifted),
  2664. 'reason' => $db->escape_string($mybb->input['banreason'])
  2665. );
  2666. $db->update_query('banned', $update_array, "uid='{$user['uid']}'");
  2667. }
  2668. else
  2669. {
  2670. $insert_array = array(
  2671. 'uid' => $user['uid'],
  2672. 'gid' => intval($mybb->input['usergroup']),
  2673. 'oldgroup' => $user['usergroup'],
  2674. 'oldadditionalgroups' => $user['additionalgroups'],
  2675. 'olddisplaygroup' => $user['displaygroup'],
  2676. 'admin' => intval($mybb->user['uid']),
  2677. 'dateline' => TIME_NOW,
  2678. 'bantime' => $db->escape_string($mybb->input['liftafter']),
  2679. 'lifted' => $db->escape_string($lifted),
  2680. 'reason' => $db->escape_string($mybb->input['banreason'])
  2681. );
  2682. $db->insert_query('banned', $insert_array);
  2683. }
  2684. // Move the user to the banned group
  2685. $update_array = array(
  2686. 'usergroup' => intval($mybb->input['usergroup']),
  2687. 'displaygroup' => 0,
  2688. 'additionalgroups' => '',
  2689. );
  2690. $db->update_query('users', $update_array, "uid = {$user['uid']}");
  2691. $cache->update_banned();
  2692. log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->banned_user);
  2693. $plugins->run_hooks("modcp_do_banuser_end");
  2694. if($mybb->input['uid'])
  2695. {
  2696. redirect("modcp.php?action=banning", $lang->redirect_banuser_updated);
  2697. }
  2698. else
  2699. {
  2700. redirect("modcp.php?action=banning", $lang->redirect_banuser);
  2701. }
  2702. }
  2703. // Otherwise has errors, throw back to ban page
  2704. else
  2705. {
  2706. $mybb->input['action'] = "banuser";
  2707. }
  2708. }
  2709. if($mybb->input['action'] == "banuser")
  2710. {
  2711. add_breadcrumb($lang->mcp_nav_banning, "modcp.php?action=banning");
  2712. if($mybb->input['uid'])
  2713. {
  2714. add_breadcrumb($lang->mcp_nav_ban_user);
  2715. }
  2716. else
  2717. {
  2718. add_breadcrumb($lang->mcp_nav_editing_ban);
  2719. }
  2720. $plugins->run_hooks("modcp_banuser_start");
  2721. // If incoming user ID, we are editing a ban
  2722. if($mybb->input['uid'])
  2723. {
  2724. $query = $db->query("
  2725. SELECT b.*, u.username, u.uid
  2726. FROM ".TABLE_PREFIX."banned b
  2727. LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid)
  2728. WHERE b.uid='{$mybb->input['uid']}'
  2729. ");
  2730. $banned = $db->fetch_array($query);
  2731. if($banned['username'])
  2732. {
  2733. $username = htmlspecialchars_uni($banned['username']);
  2734. $banreason = htmlspecialchars_uni($banned['reason']);
  2735. $uid = $mybb->input['uid'];
  2736. $user = get_user($banned['uid']);
  2737. $lang->ban_user = $lang->edit_ban; // Swap over lang variables
  2738. eval("\$banuser_username = \"".$templates->get("modcp_banuser_editusername")."\";");
  2739. }
  2740. }
  2741. // New ban!
  2742. if(!$banuser_username)
  2743. {
  2744. if($mybb->input['uid'])
  2745. {
  2746. $user = get_user($mybb->input['uid']);
  2747. $username = $user['username'];
  2748. }
  2749. else
  2750. {
  2751. $username = htmlspecialchars_uni($mybb->input['username']);
  2752. }
  2753. eval("\$banuser_username = \"".$templates->get("modcp_banuser_addusername")."\";");
  2754. }
  2755. // Coming back to this page from an error?
  2756. if($errors)
  2757. {
  2758. $errors = inline_error($errors);
  2759. $banned = array(
  2760. "bantime" => $mybb->input['liftafter'],
  2761. "reason" => $mybb->input['reason'],
  2762. "gid" => $mybb->input['gid']
  2763. );
  2764. $banreason = htmlspecialchars_uni($mybb->input['banreason']);
  2765. }
  2766. // Generate the banned times dropdown
  2767. foreach($bantimes as $time => $title)
  2768. {
  2769. $liftlist .= "<option value=\"{$time}\"";
  2770. if($banned['bantime'] == $time)
  2771. {
  2772. $liftlist .= " selected=\"selected\"";
  2773. }
  2774. $thatime = my_date("D, jS M Y @ g:ia", ban_date2timestamp($time, $banned['dateline']));
  2775. if($time == '---')
  2776. {
  2777. $liftlist .= ">{$title}</option>\n";
  2778. }
  2779. else
  2780. {
  2781. $liftlist .= ">{$title} ({$thatime})</option>\n";
  2782. }
  2783. }
  2784. $bangroups = '';
  2785. $query = $db->simple_select("usergroups", "gid, title", "isbannedgroup=1");
  2786. while($item = $db->fetch_array($query))
  2787. {
  2788. $selected = "";
  2789. if($banned['gid'] == $item['gid'])
  2790. {
  2791. $selected = " selected=\"selected\"";
  2792. }
  2793. $bangroups .= "<option value=\"{$item['gid']}\"{$selected}>".htmlspecialchars_uni($item['title'])."</option>\n";
  2794. }
  2795. $lift_link = "<div class=\"float_right\"><a href=\"modcp.php?action=liftban&amp;uid={$user['uid']}&amp;my_post_key={$mybb->post_code}\">{$lang->lift_ban}</a></div>";
  2796. $plugins->run_hooks("modcp_banuser_end");
  2797. eval("\$banuser = \"".$templates->get("modcp_banuser")."\";");
  2798. output_page($banuser);
  2799. }
  2800. if($mybb->input['action'] == "do_modnotes")
  2801. {
  2802. // Verify incoming POST request
  2803. verify_post_check($mybb->input['my_post_key']);
  2804. $plugins->run_hooks("modcp_do_modnotes_start");
  2805. // Update Moderator Notes cache
  2806. $update_cache = array(
  2807. "modmessage" => $mybb->input['modnotes']
  2808. );
  2809. $cache->update("modnotes", $update_cache);
  2810. $plugins->run_hooks("modcp_do_modnotes_end");
  2811. redirect("modcp.php", $lang->redirect_modnotes);
  2812. }
  2813. if(!$mybb->input['action'])
  2814. {
  2815. $query = $db->query("
  2816. SELECT COUNT(aid) AS unapprovedattachments
  2817. FROM ".TABLE_PREFIX."attachments a
  2818. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
  2819. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  2820. WHERE a.visible='0' {$tflist}
  2821. ");
  2822. $unapproved_attachments = $db->fetch_field($query, "unapprovedattachments");
  2823. if($unapproved_attachments > 0)
  2824. {
  2825. $query = $db->query("
  2826. SELECT t.tid, p.pid, p.uid, t.username, a.filename, a.dateuploaded
  2827. FROM ".TABLE_PREFIX."attachments a
  2828. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid)
  2829. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  2830. WHERE a.visible='0' {$tflist}
  2831. ORDER BY a.dateuploaded DESC
  2832. LIMIT 1
  2833. ");
  2834. $attachment = $db->fetch_array($query);
  2835. $attachment['date'] = my_date($mybb->settings['dateformat'], $attachment['dateuploaded']);
  2836. $attachment['time'] = my_date($mybb->settings['timeformat'], $attachment['dateuploaded']);
  2837. $attachment['profilelink'] = build_profile_link($attachment['username'], $attachment['uid']);
  2838. $attachment['link'] = get_post_link($attachment['pid'], $attachment['tid']);
  2839. $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
  2840. eval("\$latest_attachment = \"".$templates->get("modcp_lastattachment")."\";");
  2841. }
  2842. else
  2843. {
  2844. $latest_attachment = "<span style=\"text-align: center;\">{$lang->lastpost_never}</span>";
  2845. }
  2846. $query = $db->query("
  2847. SELECT COUNT(pid) AS unapprovedposts
  2848. FROM ".TABLE_PREFIX."posts p
  2849. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  2850. WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid
  2851. ");
  2852. $unapproved_posts = $db->fetch_field($query, "unapprovedposts");
  2853. if($unapproved_posts > 0)
  2854. {
  2855. $query = $db->query("
  2856. SELECT p.pid, p.tid, p.subject, p.uid, p.username, p.dateline
  2857. FROM ".TABLE_PREFIX."posts p
  2858. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  2859. WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid
  2860. ORDER BY p.dateline DESC
  2861. LIMIT 1
  2862. ");
  2863. $post = $db->fetch_array($query);
  2864. $post['date'] = my_date($mybb->settings['dateformat'], $post['dateline']);
  2865. $post['time'] = my_date($mybb->settings['timeformat'], $post['dateline']);
  2866. $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
  2867. $post['link'] = get_post_link($post['pid'], $post['tid']);
  2868. $post['subject'] = $post['fullsubject'] = $parser->parse_badwords($post['subject']);
  2869. if(my_strlen($post['subject']) > 25)
  2870. {
  2871. $post['subject'] = my_substr($post['subject'], 0, 25)."...";
  2872. }
  2873. $post['subject'] = htmlspecialchars_uni($post['subject']);
  2874. $post['fullsubject'] = htmlspecialchars_uni($post['fullsubject']);
  2875. eval("\$latest_post = \"".$templates->get("modcp_lastpost")."\";");
  2876. }
  2877. else
  2878. {
  2879. $latest_post = "<span style=\"text-align: center;\">{$lang->lastpost_never}</span>";
  2880. }
  2881. $query = $db->simple_select("threads", "COUNT(tid) AS unapprovedthreads", "visible=0 {$flist}");
  2882. $unapproved_threads = $db->fetch_field($query, "unapprovedthreads");
  2883. if($unapproved_threads > 0)
  2884. {
  2885. $query = $db->simple_select("threads", "tid, subject, uid, username, dateline", "visible=0 {$flist}", array('order_by' => 'dateline', 'order_dir' => 'DESC', 'limit' => 1));
  2886. $thread = $db->fetch_array($query);
  2887. $thread['date'] = my_date($mybb->settings['dateformat'], $thread['dateline']);
  2888. $thread['time'] = my_date($mybb->settings['timeformat'], $thread['dateline']);
  2889. $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']);
  2890. $thread['link'] = get_thread_link($thread['tid']);
  2891. $thread['subject'] = $thread['fullsubject'] = $parser->parse_badwords($thread['subject']);
  2892. if(my_strlen($thread['subject']) > 25)
  2893. {
  2894. $post['subject'] = my_substr($thread['subject'], 0, 25)."...";
  2895. }
  2896. $thread['subject'] = htmlspecialchars_uni($thread['subject']);
  2897. $thread['fullsubject'] = htmlspecialchars_uni($thread['fullsubject']);
  2898. eval("\$latest_thread = \"".$templates->get("modcp_lastthread")."\";");
  2899. }
  2900. else
  2901. {
  2902. $latest_thread = "<span style=\"text-align: center;\">{$lang->lastpost_never}</span>";
  2903. }
  2904. $where = '';
  2905. if($tflist)
  2906. {
  2907. $where = "WHERE (t.fid <> 0 {$tflist}) OR (!l.fid)";
  2908. }
  2909. $query = $db->query("
  2910. SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject
  2911. FROM ".TABLE_PREFIX."moderatorlog l
  2912. LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid)
  2913. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid)
  2914. LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid)
  2915. LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid)
  2916. {$where}
  2917. ORDER BY l.dateline DESC
  2918. LIMIT 5
  2919. ");
  2920. while($logitem = $db->fetch_array($query))
  2921. {
  2922. $information = '';
  2923. $logitem['action'] = htmlspecialchars_uni($logitem['action']);
  2924. $log_date = my_date($mybb->settings['dateformat'], $logitem['dateline']);
  2925. $log_time = my_date($mybb->settings['timeformat'], $logitem['dateline']);
  2926. $trow = alt_trow();
  2927. $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']);
  2928. $logitem['profilelink'] = build_profile_link($username, $logitem['uid']);
  2929. if($logitem['tsubject'])
  2930. {
  2931. $information = "<strong>{$lang->thread}</strong> <a href=\"".get_thread_link($logitem['tid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['tsubject'])."</a><br />";
  2932. }
  2933. if($logitem['fname'])
  2934. {
  2935. $information .= "<strong>{$lang->forum}</strong> <a href=\"".get_forum_link($logitem['fid'])."\" target=\"_blank\">".htmlspecialchars_uni($logitem['fname'])."</a><br />";
  2936. }
  2937. if($logitem['psubject'])
  2938. {
  2939. $information .= "<strong>{$lang->post}</strong> <a href=\"".get_post_link($logitem['pid'])."#pid{$logitem['pid']}\">".htmlspecialchars_uni($logitem['psubject'])."</a>";
  2940. }
  2941. // Edited a user?
  2942. if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject'])
  2943. {
  2944. $data = unserialize($logitem['data']);
  2945. if($data['uid'])
  2946. {
  2947. $information = $lang->sprintf($lang->edited_user_info, htmlspecialchars_uni($data['username']), get_profile_link($data['uid']));
  2948. }
  2949. }
  2950. eval("\$modlogresults .= \"".$templates->get("modcp_modlogs_result")."\";");
  2951. }
  2952. if(!$modlogresults)
  2953. {
  2954. eval("\$modlogresults = \"".$templates->get("modcp_modlogs_noresults")."\";");
  2955. }
  2956. $query = $db->query("
  2957. SELECT b.*, a.username AS adminuser, u.username, (b.lifted-".TIME_NOW.") AS remaining
  2958. FROM ".TABLE_PREFIX."banned b
  2959. LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid)
  2960. LEFT JOIN ".TABLE_PREFIX."users a ON (b.admin=a.uid)
  2961. WHERE b.bantime != '---' AND b.bantime != 'perm'
  2962. ORDER BY remaining ASC
  2963. LIMIT 5
  2964. ");
  2965. // Get the banned users
  2966. while($banned = $db->fetch_array($query))
  2967. {
  2968. $profile_link = build_profile_link($banned['username'], $banned['uid']);
  2969. // Only show the edit & lift links if current user created ban, or is super mod/admin
  2970. $edit_link = '';
  2971. if($mybb->user['uid'] == $banned['admin'] || !$banned['adminuser'] || $mybb->usergroup['issupermod'] == 1 || $mybb->usergroup['cancp'] == 1)
  2972. {
  2973. $edit_link = "<br /><span class=\"smalltext\"><a href=\"modcp.php?action=banuser&amp;uid={$banned['uid']}\">{$lang->edit_ban}</a> | <a href=\"modcp.php?action=liftban&amp;uid={$banned['uid']}&amp;my_post_key={$mybb->post_code}\">{$lang->lift_ban}</a></span>";
  2974. }
  2975. $admin_profile = build_profile_link($banned['adminuser'], $banned['admin']);
  2976. $trow = alt_trow();
  2977. if($banned['reason'])
  2978. {
  2979. $banned['reason'] = htmlspecialchars_uni($parser->parse_badwords($banned['reason']));
  2980. }
  2981. else
  2982. {
  2983. $banned['reason'] = $lang->na;
  2984. }
  2985. if($banned['lifted'] == 'perm' || $banned['lifted'] == '' || $banned['bantime'] == 'perm' || $banned['bantime'] == '---')
  2986. {
  2987. $banlength = $lang->permanent;
  2988. $timeremaining = $lang->na;
  2989. }
  2990. else
  2991. {
  2992. $banlength = $bantimes[$banned['bantime']];
  2993. $remaining = $banned['remaining'];
  2994. $timeremaining = nice_time($remaining, array('short' => 1, 'seconds' => false))."";
  2995. if($remaining <= 0)
  2996. {
  2997. $timeremaining = "<span style=\"color: red;\">({$lang->ban_ending_imminently})</span>";
  2998. }
  2999. else if($remaining < 3600)
  3000. {
  3001. $timeremaining = "<span style=\"color: red;\">({$timeremaining} {$lang->ban_remaining})</span>";
  3002. }
  3003. else if($remaining < 86400)
  3004. {
  3005. $timeremaining = "<span style=\"color: maroon;\">({$timeremaining} {$lang->ban_remaining})</span>";
  3006. }
  3007. else if($remaining < 604800)
  3008. {
  3009. $timeremaining = "<span style=\"color: green;\">({$timeremaining} {$lang->ban_remaining})</span>";
  3010. }
  3011. else
  3012. {
  3013. $timeremaining = "({$timeremaining} {$lang->ban_remaining})";
  3014. }
  3015. }
  3016. eval("\$bannedusers .= \"".$templates->get("modcp_banning_ban")."\";");
  3017. }
  3018. if(!$bannedusers)
  3019. {
  3020. eval("\$bannedusers = \"".$templates->get("modcp_banning_nobanned")."\";");
  3021. }
  3022. $modnotes = $cache->read("modnotes");
  3023. $modnotes = htmlspecialchars_uni($modnotes['modmessage']);
  3024. $plugins->run_hooks("modcp_end");
  3025. eval("\$modcp = \"".$templates->get("modcp")."\";");
  3026. output_page($modcp);
  3027. }
  3028. ?>