PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full file

  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. // V…

Large files files are truncated, but you can click here to view the full file