| [ Index ] |
PHP Cross Reference of MyBB 1.8.41 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 define("IN_MYBB", 1); 12 define('THIS_SCRIPT', 'modcp.php'); 13 14 $templatelist = "modcp_reports,modcp_reports_report,modcp_reports_selectall,modcp_reports_multipage,modcp_reports_allreport,modcp_reports_allreports,modcp_modlogs_multipage,modcp_announcements_delete,modcp_announcements_edit,modcp_awaitingmoderation"; 15 $templatelist .= ",modcp_reports_allnoreports,modcp_reports_noreports,modcp_banning,modcp_banning_ban,modcp_announcements_announcement_global,modcp_no_announcements_forum,modcp_modqueue_threads_thread,modcp_awaitingthreads,preview"; 16 $templatelist .= ",modcp_banning_nobanned,modcp_modqueue_threads_empty,modcp_modqueue_masscontrols,modcp_modqueue_threads,modcp_modqueue_posts_post,modcp_modqueue_posts_empty,modcp_awaitingposts,modcp_nav_editprofile,modcp_nav_banning"; 17 $templatelist .= ",modcp_nav,modcp_modlogs_noresults,modcp_modlogs_nologs,modcp,modcp_modqueue_posts,modcp_modqueue_attachments_attachment,modcp_modqueue_attachments_empty,modcp_modqueue_attachments,modcp_editprofile_suspensions_info"; 18 $templatelist .= ",modcp_no_announcements_global,modcp_announcements_global,modcp_announcements_forum,modcp_announcements,modcp_editprofile_select_option,modcp_editprofile_select,modcp_finduser_noresults, modcp_nav_forums_posts"; 19 $templatelist .= ",codebuttons,modcp_announcements_new,modcp_modqueue_empty,forumjump_bit,forumjump_special,modcp_warninglogs_warning_revoked,modcp_warninglogs_warning,modcp_ipsearch_result,modcp_nav_modqueue,modcp_banuser_liftlist"; 20 $templatelist .= ",modcp_modlogs,modcp_finduser_user,modcp_finduser,usercp_profile_customfield,usercp_profile_profilefields,modcp_ipsearch_noresults,modcp_ipsearch_results,modcp_ipsearch_misc_info,modcp_nav_announcements,modcp_modqueue_post_link"; 21 $templatelist .= ",modcp_editprofile,modcp_ipsearch,modcp_banuser_addusername,modcp_banuser,modcp_warninglogs_nologs,modcp_banuser_editusername,modcp_lastattachment,modcp_lastpost,modcp_lastthread,modcp_nobanned,modcp_modqueue_thread_link"; 22 $templatelist .= ",modcp_warninglogs,modcp_modlogs_result,modcp_editprofile_signature,forumjump_advanced,modcp_announcements_forum_nomod,modcp_announcements_announcement,usercp_profile_away,modcp_modlogs_user,modcp_editprofile_away"; 23 $templatelist .= ",multipage,multipage_end,multipage_jump_page,multipage_nextpage,multipage_page,multipage_page_current,multipage_page_link_current,multipage_prevpage,multipage_start,modcp_awaitingattachments,modcp_modqueue_attachment_link"; 24 $templatelist .= ",postbit_groupimage,postbit_userstar,postbit_online,postbit_offline,postbit_away,postbit_avatar,postbit_find,postbit_pm,postbit_email,postbit_www,postbit_author_user,announcement_edit,announcement_quickdelete"; 25 $templatelist .= ",modcp_awaitingmoderation_none,modcp_banning_edit,modcp_banuser_bangroups_group,modcp_banuser_lift,modcp_modlogs_result_announcement,modcp_modlogs_result_forum,modcp_modlogs_result_post,modcp_modlogs_result_thread"; 26 $templatelist .= ",modcp_nav_warninglogs,modcp_nav_ipsearch,modcp_nav_users,modcp_announcements_day,modcp_announcements_month_start,modcp_announcements_month_end,modcp_announcements_announcement_expired,modcp_announcements_announcement_active"; 27 $templatelist .= ",modcp_modqueue_link_forum,modcp_modqueue_link_thread,usercp_profile_day,modcp_ipsearch_result_regip,modcp_ipsearch_result_lastip,modcp_ipsearch_result_post,modcp_ipsearch_results_information,usercp_profile_profilefields_text"; 28 $templatelist .= ",usercp_profile_profilefields_select_option,usercp_profile_profilefields_multiselect,usercp_profile_profilefields_select,usercp_profile_profilefields_textarea,usercp_profile_profilefields_radio,postbit"; 29 $templatelist .= ",modcp_banning_remaining,postmodcp_nav_announcements,modcp_nav_reportcenter,modcp_nav_modlogs,modcp_latestfivemodactions,modcp_banuser_bangroups_hidden,modcp_banuser_bangroups,usercp_profile_profilefields_checkbox"; 30 31 require_once "./global.php"; 32 require_once MYBB_ROOT."inc/functions_user.php"; 33 require_once MYBB_ROOT."inc/functions_upload.php"; 34 require_once MYBB_ROOT."inc/functions_modcp.php"; 35 require_once MYBB_ROOT."inc/class_parser.php"; 36 $parser = new postParser; 37 38 // Set up the array of ban times. 39 $bantimes = fetch_ban_times(); 40 41 // Load global language phrases 42 $lang->load("modcp"); 43 $lang->load("announcements"); 44 45 if($mybb->user['uid'] == 0 || $mybb->usergroup['canmodcp'] != 1) 46 { 47 error_no_permission(); 48 } 49 50 if(!$mybb->settings['threadsperpage'] || (int)$mybb->settings['threadsperpage'] < 1) 51 { 52 $mybb->settings['threadsperpage'] = 20; 53 } 54 55 $tflist = $flist = $tflist_queue_threads = $flist_queue_threads = $tflist_queue_posts = $flist_queue_posts = $tflist_queue_attach = 56 $flist_queue_attach = $wflist_reports = $tflist_reports = $flist_reports = $tflist_modlog = $flist_modlog = $errors = ''; 57 // SQL for fetching items only related to forums this user moderates 58 $moderated_forums = array(); 59 $numannouncements = $nummodqueuethreads = $nummodqueueposts = $nummodqueueattach = $numreportedposts = $nummodlogs = 0; 60 if($mybb->usergroup['issupermod'] != 1) 61 { 62 $query = $db->simple_select("moderators", "*", "(id='{$mybb->user['uid']}' AND isgroup = '0') OR (id IN ({$mybb->usergroup['all_usergroups']}) AND isgroup = '1')"); 63 while($forum = $db->fetch_array($query)) 64 { 65 $moderated_forums[] = $forum['fid']; 66 $children = get_child_list($forum['fid']); 67 if(is_array($children)) 68 { 69 $moderated_forums = array_merge($moderated_forums, $children); 70 } 71 } 72 $moderated_forums = array_unique($moderated_forums); 73 74 $numannouncements = $nummodqueuethreads = $nummodqueueposts = $nummodqueueattach = $numreportedposts = $nummodlogs = 0; 75 foreach($moderated_forums as $moderated_forum) 76 { 77 // For Announcements 78 if(is_moderator($moderated_forum, 'canmanageannouncements')) 79 { 80 ++$numannouncements; 81 } 82 83 // For the Mod Queues 84 if(is_moderator($moderated_forum, 'canapproveunapprovethreads')) 85 { 86 $flist_queue_threads .= ",'{$moderated_forum}'"; 87 ++$nummodqueuethreads; 88 } 89 90 if(is_moderator($moderated_forum, 'canapproveunapproveposts')) 91 { 92 $flist_queue_posts .= ",'{$moderated_forum}'"; 93 ++$nummodqueueposts; 94 } 95 96 if(is_moderator($moderated_forum, 'canapproveunapproveattachs')) 97 { 98 $flist_queue_attach .= ",'{$moderated_forum}'"; 99 ++$nummodqueueattach; 100 } 101 102 // For Reported posts 103 if(is_moderator($moderated_forum, 'canmanagereportedposts')) 104 { 105 $flist_reports .= ",'{$moderated_forum}'"; 106 ++$numreportedposts; 107 } 108 109 // For the Mod Log 110 if(is_moderator($moderated_forum, 'canviewmodlog')) 111 { 112 $flist_modlog .= ",'{$moderated_forum}'"; 113 ++$nummodlogs; 114 } 115 116 $flist .= ",'{$moderated_forum}'"; 117 } 118 if($flist_queue_threads) 119 { 120 $tflist_queue_threads = " AND t.fid IN (0{$flist_queue_threads})"; 121 $flist_queue_threads = " AND fid IN (0{$flist_queue_threads})"; 122 } 123 if($flist_queue_posts) 124 { 125 $tflist_queue_posts = " AND t.fid IN (0{$flist_queue_posts})"; 126 $flist_queue_posts = " AND fid IN (0{$flist_queue_posts})"; 127 } 128 if($flist_queue_attach) 129 { 130 $tflist_queue_attach = " AND t.fid IN (0{$flist_queue_attach})"; 131 $flist_queue_attach = " AND fid IN (0{$flist_queue_attach})"; 132 } 133 if($flist_reports) 134 { 135 $wflist_reports = "WHERE r.id3 IN (0{$flist_reports})"; 136 $tflist_reports = " AND r.id3 IN (0{$flist_reports})"; 137 $flist_reports = " AND id3 IN (0{$flist_reports})"; 138 } 139 if($flist_modlog) 140 { 141 $tflist_modlog = " AND t.fid IN (0{$flist_modlog})"; 142 $flist_modlog = " AND fid IN (0{$flist_modlog})"; 143 } 144 if($flist) 145 { 146 $tflist = " AND t.fid IN (0{$flist})"; 147 $flist = " AND fid IN (0{$flist})"; 148 } 149 } 150 151 // Retrieve a list of unviewable forums 152 $unviewableforums = get_unviewable_forums(); 153 $inactiveforums = get_inactive_forums(); 154 $unviewablefids1 = $unviewablefids2 = array(); 155 156 if($unviewableforums) 157 { 158 $flist .= " AND fid NOT IN ({$unviewableforums})"; 159 $tflist .= " AND t.fid NOT IN ({$unviewableforums})"; 160 161 $unviewablefids1 = explode(',', $unviewableforums); 162 } 163 164 if($inactiveforums) 165 { 166 $flist .= " AND fid NOT IN ({$inactiveforums})"; 167 $tflist .= " AND t.fid NOT IN ({$inactiveforums})"; 168 169 $unviewablefids2 = explode(',', $inactiveforums); 170 } 171 172 $unviewableforums = array_merge($unviewablefids1, $unviewablefids2); 173 174 if(!isset($collapsedimg['modcpforums'])) 175 { 176 $collapsedimg['modcpforums'] = ''; 177 } 178 179 if(!isset($collapsed['modcpforums_e'])) 180 { 181 $collapsed['modcpforums_e'] = ''; 182 } 183 184 if(!isset($collapsedimg['modcpusers'])) 185 { 186 $collapsedimg['modcpusers'] = ''; 187 } 188 189 if(!isset($collapsed['modcpusers_e'])) 190 { 191 $collapsed['modcpusers_e'] = ''; 192 } 193 194 // Fetch the Mod CP menu 195 $nav_announcements = $nav_modqueue = $nav_reportcenter = $nav_modlogs = $nav_editprofile = $nav_banning = $nav_warninglogs = $nav_ipsearch = $nav_forums_posts = $modcp_nav_users = ''; 196 if(($numannouncements > 0 || $mybb->usergroup['issupermod'] == 1) && $mybb->usergroup['canmanageannounce'] == 1) 197 { 198 eval("\$nav_announcements = \"".$templates->get("modcp_nav_announcements")."\";"); 199 } 200 201 if(($nummodqueuethreads > 0 || $nummodqueueposts > 0 || $nummodqueueattach > 0 || $mybb->usergroup['issupermod'] == 1) && $mybb->usergroup['canmanagemodqueue'] == 1) 202 { 203 eval("\$nav_modqueue = \"".$templates->get("modcp_nav_modqueue")."\";"); 204 } 205 206 if(($numreportedposts > 0 || $mybb->usergroup['issupermod'] == 1) && $mybb->usergroup['canmanagereportedcontent'] == 1) 207 { 208 eval("\$nav_reportcenter = \"".$templates->get("modcp_nav_reportcenter")."\";"); 209 } 210 211 if(($nummodlogs > 0 || $mybb->usergroup['issupermod'] == 1) && $mybb->usergroup['canviewmodlogs'] == 1) 212 { 213 eval("\$nav_modlogs = \"".$templates->get("modcp_nav_modlogs")."\";"); 214 } 215 216 if($mybb->usergroup['caneditprofiles'] == 1) 217 { 218 eval("\$nav_editprofile = \"".$templates->get("modcp_nav_editprofile")."\";"); 219 } 220 221 if($mybb->usergroup['canbanusers'] == 1) 222 { 223 eval("\$nav_banning = \"".$templates->get("modcp_nav_banning")."\";"); 224 } 225 226 if($mybb->usergroup['canviewwarnlogs'] == 1) 227 { 228 eval("\$nav_warninglogs = \"".$templates->get("modcp_nav_warninglogs")."\";"); 229 } 230 231 if($mybb->usergroup['canuseipsearch'] == 1) 232 { 233 eval("\$nav_ipsearch = \"".$templates->get("modcp_nav_ipsearch")."\";"); 234 } 235 236 $plugins->run_hooks("modcp_nav"); 237 238 if(!empty($nav_announcements) || !empty($nav_modqueue) || !empty($nav_reportcenter) || !empty($nav_modlogs)) 239 { 240 $expaltext = (in_array("modcpforums", $collapse)) ? $lang->expcol_expand : $lang->expcol_collapse; 241 eval("\$modcp_nav_forums_posts = \"".$templates->get("modcp_nav_forums_posts")."\";"); 242 } 243 244 if(!empty($nav_editprofile) || !empty($nav_banning) || !empty($nav_warninglogs) || !empty($nav_ipsearch)) 245 { 246 $expaltext = (in_array("modcpusers", $collapse)) ? $lang->expcol_expand : $lang->expcol_collapse; 247 eval("\$modcp_nav_users = \"".$templates->get("modcp_nav_users")."\";"); 248 } 249 250 eval("\$modcp_nav = \"".$templates->get("modcp_nav")."\";"); 251 252 $plugins->run_hooks("modcp_start"); 253 254 // Make navigation 255 add_breadcrumb($lang->nav_modcp, "modcp.php"); 256 257 $mybb->input['action'] = $mybb->get_input('action'); 258 if($mybb->input['action'] == "do_reports") 259 { 260 if($mybb->usergroup['canmanagereportedcontent'] == 0) 261 { 262 error_no_permission(); 263 } 264 265 if($numreportedposts == 0 && $mybb->usergroup['issupermod'] != 1) 266 { 267 error($lang->you_cannot_view_reported_posts); 268 } 269 270 // Verify incoming POST request 271 verify_post_check($mybb->get_input('my_post_key')); 272 273 $mybb->input['reports'] = $mybb->get_input('reports', MyBB::INPUT_ARRAY); 274 if(empty($mybb->input['reports']) && empty($mybb->cookies['inlinereports'])) 275 { 276 error($lang->error_noselected_reports); 277 } 278 279 $message = $lang->redirect_reportsmarked; 280 281 if(isset($mybb->cookies['inlinereports'])) 282 { 283 if($mybb->cookies['inlinereports'] == '|ALL|') { 284 $message = $lang->redirect_allreportsmarked; 285 $sql = "1=1"; 286 if(isset($mybb->cookies['inlinereports_removed'])) 287 { 288 $inlinereportremovedlist = explode("|", $mybb->cookies['inlinereports_removed']); 289 $reports = array_map("intval", $inlinereportremovedlist); 290 $rids = implode("','", $reports); 291 $sql = "rid NOT IN ('0','{$rids}')"; 292 } 293 } 294 else 295 { 296 $inlinereportlist = explode("|", $mybb->cookies['inlinereports']); 297 $reports = array_map("intval", $inlinereportlist); 298 299 if(!count($reports)) 300 { 301 error($lang->error_noselected_reports); 302 } 303 304 $rids = implode("','", $reports); 305 306 $sql = "rid IN ('0','{$rids}')"; 307 } 308 } 309 else 310 { 311 $mybb->input['reports'] = array_map("intval", $mybb->input['reports']); 312 $rids = implode("','", $mybb->input['reports']); 313 314 $sql = "rid IN ('0','{$rids}')"; 315 } 316 317 $plugins->run_hooks("modcp_do_reports"); 318 319 $db->update_query("reportedcontent", array('reportstatus' => 1), "{$sql}{$flist_reports}"); 320 $cache->update_reportedcontent(); 321 322 my_unsetcookie('inlinereports'); 323 my_unsetcookie('inlinereports_removed'); 324 325 $page = $mybb->get_input('page', MyBB::INPUT_INT); 326 327 redirect("modcp.php?action=reports&page={$page}", $message); 328 } 329 330 if($mybb->input['action'] == "reports") 331 { 332 if($mybb->usergroup['canmanagereportedcontent'] == 0) 333 { 334 error_no_permission(); 335 } 336 337 if($numreportedposts == 0 && $mybb->usergroup['issupermod'] != 1) 338 { 339 error($lang->you_cannot_view_reported_posts); 340 } 341 342 $lang->load('report'); 343 add_breadcrumb($lang->mcp_nav_report_center, "modcp.php?action=reports"); 344 345 $perpage = $mybb->settings['threadsperpage']; 346 if(!$perpage) 347 { 348 $perpage = 20; 349 } 350 351 // Multipage 352 if($mybb->usergroup['cancp'] || $mybb->usergroup['issupermod']) 353 { 354 $query = $db->simple_select("reportedcontent", "COUNT(rid) AS count", "reportstatus ='0'"); 355 $report_count = $db->fetch_field($query, "count"); 356 } 357 else 358 { 359 $query = $db->simple_select('reportedcontent', 'id3', "reportstatus='0' AND (type = 'post' OR type = '')"); 360 361 $report_count = 0; 362 while($fid = $db->fetch_field($query, 'id3')) 363 { 364 if(is_moderator($fid, "canmanagereportedposts")) 365 { 366 ++$report_count; 367 } 368 } 369 unset($fid); 370 } 371 372 $page = $mybb->get_input('page', MyBB::INPUT_INT); 373 374 $postcount = (int)$report_count; 375 $pages = $postcount / $perpage; 376 $pages = ceil($pages); 377 378 if($page > $pages || $page <= 0) 379 { 380 $page = 1; 381 } 382 383 if($page && $page > 0) 384 { 385 $start = ($page-1) * $perpage; 386 } 387 else 388 { 389 $start = 0; 390 $page = 1; 391 } 392 393 $multipage = $reportspages = ''; 394 if($postcount > $perpage) 395 { 396 $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=reports"); 397 eval("\$reportspages = \"".$templates->get("modcp_reports_multipage")."\";"); 398 } 399 400 $plugins->run_hooks("modcp_reports_start"); 401 402 // Reports 403 $reports = $selectall = ''; 404 $inlinecount = 0; 405 406 $query = $db->query(" 407 SELECT r.*, u.username, rr.title 408 FROM ".TABLE_PREFIX."reportedcontent r 409 LEFT JOIN ".TABLE_PREFIX."users u ON (r.uid = u.uid) 410 LEFT JOIN ".TABLE_PREFIX."reportreasons rr ON (r.reasonid = rr.rid) 411 WHERE r.reportstatus = '0'{$tflist_reports} 412 ORDER BY r.reports DESC 413 LIMIT {$start}, {$perpage} 414 "); 415 416 if(!$db->num_rows($query)) 417 { 418 // No unread reports 419 eval("\$reports = \"".$templates->get("modcp_reports_noreports")."\";"); 420 } 421 else 422 { 423 $reportedcontent = $cache->read("reportedcontent"); 424 $reportcache = $usercache = $postcache = array(); 425 426 while($report = $db->fetch_array($query)) 427 { 428 if($report['type'] == 'profile' || $report['type'] == 'reputation') 429 { 430 // Profile UID is in ID 431 if(!isset($usercache[$report['id']])) 432 { 433 $usercache[$report['id']] = $report['id']; 434 } 435 436 // Reputation comment? The offender is the ID2 437 if($report['type'] == 'reputation') 438 { 439 if(!isset($usercache[$report['id2']])) 440 { 441 $usercache[$report['id2']] = $report['id2']; 442 } 443 if(!isset($usercache[$report['id3']])) 444 { 445 // The user who was offended 446 $usercache[$report['id3']] = $report['id3']; 447 } 448 } 449 } 450 else if(!$report['type'] || $report['type'] == 'post') 451 { 452 // This (should) be a post 453 $postcache[$report['id']] = $report['id']; 454 } 455 456 // Lastpost info - is it missing (pre-1.8)? 457 $lastposter = $report['uid']; 458 if(!$report['lastreport']) 459 { 460 // Last reporter is our first reporter 461 $report['lastreport'] = $report['dateline']; 462 } 463 464 if($report['reporters']) 465 { 466 $reporters = my_unserialize($report['reporters']); 467 468 if(is_array($reporters)) 469 { 470 $lastposter = end($reporters); 471 } 472 } 473 474 if(!isset($usercache[$lastposter])) 475 { 476 $usercache[$lastposter] = $lastposter; 477 } 478 479 $report['lastreporter'] = $lastposter; 480 $reportcache[] = $report; 481 } 482 483 // Report Center gets messy 484 // Find information about our users (because we don't log it when they file a report) 485 if(!empty($usercache)) 486 { 487 $sql = implode(',', array_keys($usercache)); 488 $query = $db->simple_select("users", "uid, username", "uid IN ({$sql})"); 489 490 while($user = $db->fetch_array($query)) 491 { 492 $usercache[$user['uid']] = $user; 493 } 494 } 495 496 // Messy * 2 497 // Find out post information for our reported posts 498 if(!empty($postcache)) 499 { 500 $sql = implode(',', array_keys($postcache)); 501 $query = $db->query(" 502 SELECT p.pid, p.uid, p.username, p.tid, t.subject 503 FROM ".TABLE_PREFIX."posts p 504 LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid = t.tid) 505 WHERE p.pid IN ({$sql}) 506 "); 507 508 while($post = $db->fetch_array($query)) 509 { 510 $postcache[$post['pid']] = $post; 511 } 512 } 513 514 $lang->page_selected = $lang->sprintf($lang->page_selected, count($reportcache)); 515 $lang->select_all = $lang->sprintf($lang->select_all, (int)$report_count); 516 $lang->all_selected = $lang->sprintf($lang->all_selected, (int)$report_count); 517 eval("\$selectall = \"".$templates->get("modcp_reports_selectall")."\";"); 518 519 $plugins->run_hooks('modcp_reports_intermediate'); 520 521 // Now that we have all of the information needed, display the reports 522 foreach($reportcache as $report) 523 { 524 $trow = alt_trow(); 525 526 if(!$report['type']) 527 { 528 // Assume a post 529 $report['type'] = 'post'; 530 } 531 532 // Report Information 533 $report_data = array(); 534 535 switch($report['type']) 536 { 537 case 'post': 538 $post = get_post_link($report['id'])."#pid{$report['id']}"; 539 $user = build_profile_link(htmlspecialchars_uni($postcache[$report['id']]['username']), $postcache[$report['id']]['uid']); 540 $report_data['content'] = $lang->sprintf($lang->report_info_post, $post, $user); 541 542 $thread_link = get_thread_link($postcache[$report['id']]['tid']); 543 $thread_subject = htmlspecialchars_uni($parser->parse_badwords($postcache[$report['id']]['subject'])); 544 $report_data['content'] .= $lang->sprintf($lang->report_info_post_thread, $thread_link, $thread_subject); 545 546 break; 547 case 'profile': 548 $user = build_profile_link(htmlspecialchars_uni($usercache[$report['id']]['username']), $usercache[$report['id']]['uid']); 549 $report_data['content'] = $lang->sprintf($lang->report_info_profile, $user); 550 break; 551 case 'reputation': 552 $reputation_link = "reputation.php?uid={$usercache[$report['id3']]['uid']}#rid{$report['id']}"; 553 $bad_user = build_profile_link(htmlspecialchars_uni($usercache[$report['id2']]['username']), $usercache[$report['id2']]['uid']); 554 $report_data['content'] = $lang->sprintf($lang->report_info_reputation, $reputation_link, $bad_user); 555 556 $good_user = build_profile_link(htmlspecialchars_uni($usercache[$report['id3']]['username']), $usercache[$report['id3']]['uid']); 557 $report_data['content'] .= $lang->sprintf($lang->report_info_rep_profile, $good_user); 558 break; 559 } 560 561 // Report reason and comment 562 if($report['reasonid'] > 0) 563 { 564 $reason = htmlspecialchars_uni($lang->parse($report['title'])); 565 566 if(empty($report['reason'])) 567 { 568 eval("\$report_data['comment'] = \"".$templates->get("modcp_reports_report_comment")."\";"); 569 } 570 else 571 { 572 $comment = htmlspecialchars_uni($report['reason']); 573 eval("\$report_data['comment'] = \"".$templates->get("modcp_reports_report_comment_extra")."\";"); 574 } 575 } 576 else 577 { 578 $report_data['comment'] = $lang->na; 579 } 580 581 $report_reports = 1; 582 if($report['reports']) 583 { 584 $report_data['reports'] = my_number_format($report['reports']); 585 } 586 587 if($report['lastreporter']) 588 { 589 if(is_array($usercache[$report['lastreporter']])) 590 { 591 $lastreport_user = build_profile_link(htmlspecialchars_uni($usercache[$report['lastreporter']]['username']), $report['lastreporter']); 592 } 593 elseif($usercache[$report['lastreporter']] > 0) 594 { 595 $lastreport_user = htmlspecialchars_uni($lang->na_deleted); 596 } 597 598 $lastreport_date = my_date('relative', $report['lastreport']); 599 $report_data['lastreporter'] = $lang->sprintf($lang->report_info_lastreporter, $lastreport_date, $lastreport_user); 600 } 601 602 $inlinecheck = ''; 603 if(isset($mybb->cookies['inlinereports']) && my_strpos($mybb->cookies['inlinereports'], "|{$report['rid']}|") !== false) 604 { 605 $inlinecheck = " checked=\"checked\""; 606 ++$inlinecount; 607 } 608 609 $plugins->run_hooks("modcp_reports_report"); 610 eval("\$reports .= \"".$templates->get("modcp_reports_report")."\";"); 611 } 612 } 613 614 $plugins->run_hooks("modcp_reports_end"); 615 616 eval("\$reportedcontent = \"".$templates->get("modcp_reports")."\";"); 617 output_page($reportedcontent); 618 } 619 620 if($mybb->input['action'] == "allreports") 621 { 622 if($mybb->usergroup['canmanagereportedcontent'] == 0) 623 { 624 error_no_permission(); 625 } 626 627 if($numreportedposts == 0 && $mybb->usergroup['issupermod'] != 1) 628 { 629 error($lang->you_cannot_view_reported_posts); 630 } 631 632 $lang->load('report'); 633 634 add_breadcrumb($lang->report_center, "modcp.php?action=reports"); 635 add_breadcrumb($lang->all_reports, "modcp.php?action=allreports"); 636 637 if(!$mybb->settings['threadsperpage']) 638 { 639 $mybb->settings['threadsperpage'] = 20; 640 } 641 642 // Figure out if we need to display multiple pages. 643 $perpage = $mybb->settings['threadsperpage']; 644 if($mybb->get_input('page') != "last") 645 { 646 $page = $mybb->get_input('page', MyBB::INPUT_INT); 647 } 648 649 if($mybb->usergroup['cancp'] || $mybb->usergroup['issupermod']) 650 { 651 $query = $db->simple_select("reportedcontent", "COUNT(rid) AS count"); 652 $report_count = $db->fetch_field($query, "count"); 653 } 654 else 655 { 656 $query = $db->simple_select('reportedcontent', 'id3', "type = 'post' OR type = ''"); 657 658 $report_count = 0; 659 while($fid = $db->fetch_field($query, 'id3')) 660 { 661 if(is_moderator($fid, "canmanagereportedposts")) 662 { 663 ++$report_count; 664 } 665 } 666 unset($fid); 667 } 668 669 if(isset($mybb->input['rid'])) 670 { 671 $mybb->input['rid'] = $mybb->get_input('rid', MyBB::INPUT_INT); 672 $query = $db->simple_select("reportedcontent", "COUNT(rid) AS count", "rid <= '".$mybb->input['rid']."'"); 673 $result = $db->fetch_field($query, "count"); 674 if(($result % $perpage) == 0) 675 { 676 $page = $result / $perpage; 677 } 678 else 679 { 680 $page = (int)$result / $perpage + 1; 681 } 682 } 683 $postcount = (int)$report_count; 684 $pages = $postcount / $perpage; 685 $pages = ceil($pages); 686 687 if($mybb->get_input('page') == "last") 688 { 689 $page = $pages; 690 } 691 692 if($page > $pages || $page <= 0) 693 { 694 $page = 1; 695 } 696 697 if($page) 698 { 699 $start = ($page-1) * $perpage; 700 } 701 else 702 { 703 $start = 0; 704 $page = 1; 705 } 706 $upper = $start+$perpage; 707 708 $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=allreports"); 709 $allreportspages = ''; 710 if($postcount > $perpage) 711 { 712 eval("\$allreportspages = \"".$templates->get("modcp_reports_multipage")."\";"); 713 } 714 715 $plugins->run_hooks("modcp_allreports_start"); 716 717 $query = $db->query(" 718 SELECT r.*, u.username, p.username AS postusername, up.uid AS postuid, t.subject AS threadsubject, prrep.username AS repusername, pr.username AS profileusername, rr.title 719 FROM ".TABLE_PREFIX."reportedcontent r 720 LEFT JOIN ".TABLE_PREFIX."posts p ON (r.id=p.pid) 721 LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid) 722 LEFT JOIN ".TABLE_PREFIX."users u ON (r.uid=u.uid) 723 LEFT JOIN ".TABLE_PREFIX."users up ON (p.uid=up.uid) 724 LEFT JOIN ".TABLE_PREFIX."users pr ON (pr.uid=r.id) 725 LEFT JOIN ".TABLE_PREFIX."users prrep ON (prrep.uid=r.id2) 726 LEFT JOIN ".TABLE_PREFIX."reportreasons rr ON (r.reasonid = rr.rid) 727 {$wflist_reports} 728 ORDER BY r.dateline DESC 729 LIMIT {$start}, {$perpage} 730 "); 731 732 $allreports = ''; 733 if(!$db->num_rows($query)) 734 { 735 eval("\$allreports = \"".$templates->get("modcp_reports_allnoreports")."\";"); 736 } 737 else 738 { 739 while($report = $db->fetch_array($query)) 740 { 741 $trow = alt_trow(); 742 743 if($report['type'] == 'post') 744 { 745 $post = get_post_link($report['id'])."#pid{$report['id']}"; 746 $user = build_profile_link(htmlspecialchars_uni($report['postusername']), $report['postuid']); 747 $report_data['content'] = $lang->sprintf($lang->report_info_post, $post, $user); 748 749 $thread_link = get_thread_link($report['id2']); 750 $thread_subject = htmlspecialchars_uni($parser->parse_badwords($report['threadsubject'])); 751 $report_data['content'] .= $lang->sprintf($lang->report_info_post_thread, $thread_link, $thread_subject); 752 } 753 else if($report['type'] == 'profile') 754 { 755 $user = build_profile_link(htmlspecialchars_uni($report['profileusername']), $report['id']); 756 $report_data['content'] = $lang->sprintf($lang->report_info_profile, $user); 757 } 758 else if($report['type'] == 'reputation') 759 { 760 $user = build_profile_link(htmlspecialchars_uni($report['repusername']), $report['id2']); 761 $reputation_link = "reputation.php?uid={$report['id3']}#rid{$report['id']}"; 762 $report_data['content'] = $lang->sprintf($lang->report_info_reputation, $reputation_link, $user); 763 } 764 765 // Report reason and comment 766 if($report['reasonid'] > 0) 767 { 768 $reason = htmlspecialchars_uni($lang->parse($report['title'])); 769 770 if(empty($report['reason'])) 771 { 772 eval("\$report_data['comment'] = \"".$templates->get("modcp_reports_report_comment")."\";"); 773 } 774 else 775 { 776 $comment = htmlspecialchars_uni($report['reason']); 777 eval("\$report_data['comment'] = \"".$templates->get("modcp_reports_report_comment_extra")."\";"); 778 } 779 } 780 else 781 { 782 $report_data['comment'] = $lang->na; 783 } 784 785 $report['reporterlink'] = get_profile_link($report['uid']); 786 if(!$report['username']) 787 { 788 $report['username'] = $lang->na_deleted; 789 $report['reporterlink'] = $post; 790 } 791 $report['username'] = htmlspecialchars_uni($report['username']); 792 793 $report_data['reports'] = my_number_format($report['reports']); 794 $report_data['time'] = my_date('relative', $report['dateline']); 795 796 $plugins->run_hooks("modcp_allreports_report"); 797 eval("\$allreports .= \"".$templates->get("modcp_reports_allreport")."\";"); 798 } 799 } 800 801 $plugins->run_hooks("modcp_allreports_end"); 802 803 eval("\$allreportedcontent = \"".$templates->get("modcp_reports_allreports")."\";"); 804 output_page($allreportedcontent); 805 } 806 807 if($mybb->input['action'] == "modlogs") 808 { 809 if($mybb->usergroup['canviewmodlogs'] == 0) 810 { 811 error_no_permission(); 812 } 813 814 if($nummodlogs == 0 && $mybb->usergroup['issupermod'] != 1) 815 { 816 error($lang->you_cannot_view_mod_logs); 817 } 818 819 add_breadcrumb($lang->mcp_nav_modlogs, "modcp.php?action=modlogs"); 820 821 $perpage = $mybb->get_input('perpage', MyBB::INPUT_INT); 822 if(!$perpage || $perpage <= 0) 823 { 824 $perpage = $mybb->settings['threadsperpage']; 825 } 826 827 $where = ''; 828 829 // Searching for entries by a particular user 830 if($mybb->get_input('uid', MyBB::INPUT_INT)) 831 { 832 $where .= " AND l.uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'"; 833 } 834 835 // Searching for entries in a specific forum 836 if($mybb->get_input('fid', MyBB::INPUT_INT)) 837 { 838 $where .= " AND t.fid='".$mybb->get_input('fid', MyBB::INPUT_INT)."'"; 839 } 840 841 $mybb->input['sortby'] = $mybb->get_input('sortby'); 842 843 // Order? 844 switch($mybb->input['sortby']) 845 { 846 case "username": 847 $sortby = "u.username"; 848 break; 849 case "forum": 850 $sortby = "f.name"; 851 break; 852 case "thread": 853 $sortby = "t.subject"; 854 break; 855 default: 856 $sortby = "l.dateline"; 857 } 858 $order = $mybb->get_input('order'); 859 if($order != "asc") 860 { 861 $order = "desc"; 862 } 863 864 $plugins->run_hooks("modcp_modlogs_start"); 865 866 $query = $db->query(" 867 SELECT COUNT(l.dateline) AS count 868 FROM ".TABLE_PREFIX."moderatorlog l 869 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid) 870 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid) 871 WHERE 1=1 {$where}{$tflist_modlog} 872 "); 873 $rescount = $db->fetch_field($query, "count"); 874 875 // Figure out if we need to display multiple pages. 876 if($mybb->get_input('page') != "last") 877 { 878 $page = $mybb->get_input('page', MyBB::INPUT_INT); 879 } 880 881 $postcount = (int)$rescount; 882 $pages = $postcount / $perpage; 883 $pages = ceil($pages); 884 885 if($mybb->get_input('page') == "last") 886 { 887 $page = $pages; 888 } 889 890 if($page > $pages || $page <= 0) 891 { 892 $page = 1; 893 } 894 895 if($page) 896 { 897 $start = ($page-1) * $perpage; 898 } 899 else 900 { 901 $start = 0; 902 $page = 1; 903 } 904 905 $page_url = 'modcp.php?action=modlogs&perpage='.$perpage; 906 foreach(array('uid', 'fid') as $field) 907 { 908 $mybb->input[$field] = $mybb->get_input($field, MyBB::INPUT_INT); 909 if(!empty($mybb->input[$field])) 910 { 911 $page_url .= "&{$field}=".$mybb->input[$field]; 912 } 913 } 914 foreach(array('sortby', 'order') as $field) 915 { 916 $mybb->input[$field] = htmlspecialchars_uni($mybb->get_input($field)); 917 if(!empty($mybb->input[$field])) 918 { 919 $page_url .= "&{$field}=".$mybb->input[$field]; 920 } 921 } 922 923 $multipage = multipage($postcount, $perpage, $page, $page_url); 924 $resultspages = ''; 925 if($postcount > $perpage) 926 { 927 eval("\$resultspages = \"".$templates->get("modcp_modlogs_multipage")."\";"); 928 } 929 $query = $db->query(" 930 SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject 931 FROM ".TABLE_PREFIX."moderatorlog l 932 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid) 933 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid) 934 LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid) 935 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid) 936 WHERE 1=1 {$where}{$tflist_modlog} 937 ORDER BY {$sortby} {$order} 938 LIMIT {$start}, {$perpage} 939 "); 940 $results = ''; 941 while($logitem = $db->fetch_array($query)) 942 { 943 $information = ''; 944 $logitem['action'] = htmlspecialchars_uni($logitem['action']); 945 $log_date = my_date('relative', $logitem['dateline']); 946 $trow = alt_trow(); 947 if($logitem['username']) 948 { 949 $logitem['username'] = htmlspecialchars_uni($logitem['username']); 950 $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']); 951 $logitem['profilelink'] = build_profile_link($username, $logitem['uid']); 952 } 953 else 954 { 955 $username = $logitem['profilelink'] = $logitem['username'] = htmlspecialchars_uni($lang->na_deleted); 956 } 957 $logitem['ipaddress'] = my_inet_ntop($db->unescape_binary($logitem['ipaddress'])); 958 959 if($logitem['tsubject']) 960 { 961 $logitem['tsubject'] = htmlspecialchars_uni($parser->parse_badwords($logitem['tsubject'])); 962 $logitem['thread'] = get_thread_link($logitem['tid']); 963 eval("\$information .= \"".$templates->get("modcp_modlogs_result_thread")."\";"); 964 } 965 if($logitem['fname']) 966 { 967 $logitem['forum'] = get_forum_link($logitem['fid']); 968 eval("\$information .= \"".$templates->get("modcp_modlogs_result_forum")."\";"); 969 } 970 if($logitem['psubject']) 971 { 972 $logitem['psubject'] = htmlspecialchars_uni($parser->parse_badwords($logitem['psubject'])); 973 $logitem['post'] = get_post_link($logitem['pid']); 974 eval("\$information .= \"".$templates->get("modcp_modlogs_result_post")."\";"); 975 } 976 977 // Edited a user or managed announcement? 978 if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject']) 979 { 980 $data = my_unserialize($logitem['data']); 981 if(!empty($data['uid'])) 982 { 983 $data['username'] = htmlspecialchars_uni($data['username']); 984 $information = $lang->sprintf($lang->edited_user_info, htmlspecialchars_uni($data['username']), get_profile_link($data['uid'])); 985 } 986 if(!empty($data['aid'])) 987 { 988 $data['subject'] = htmlspecialchars_uni($parser->parse_badwords($data['subject'])); 989 $data['announcement'] = get_announcement_link($data['aid']); 990 eval("\$information .= \"".$templates->get("modcp_modlogs_result_announcement")."\";"); 991 } 992 } 993 994 $plugins->run_hooks("modcp_modlogs_result"); 995 996 eval("\$results .= \"".$templates->get("modcp_modlogs_result")."\";"); 997 } 998 999 if(!$results) 1000 { 1001 eval("\$results = \"".$templates->get("modcp_modlogs_noresults")."\";"); 1002 } 1003 1004 $plugins->run_hooks("modcp_modlogs_filter"); 1005 1006 // Fetch filter options 1007 $sortbysel = array('username' => '', 'forum' => '', 'thread' => '', 'dateline' => ''); 1008 $sortbysel[$mybb->input['sortby']] = "selected=\"selected\""; 1009 $ordersel = array('asc' => '', 'desc' => ''); 1010 $ordersel[$order] = "selected=\"selected\""; 1011 $user_options = ''; 1012 $query = $db->query(" 1013 SELECT DISTINCT l.uid, u.username 1014 FROM ".TABLE_PREFIX."moderatorlog l 1015 LEFT JOIN ".TABLE_PREFIX."users u ON (l.uid=u.uid) 1016 ORDER BY u.username ASC 1017 "); 1018 while($user = $db->fetch_array($query)) 1019 { 1020 // Deleted Users 1021 if(!$user['username']) 1022 { 1023 $user['username'] = $lang->na_deleted; 1024 } 1025 1026 $selected = ''; 1027 if($mybb->get_input('uid', MyBB::INPUT_INT) == $user['uid']) 1028 { 1029 $selected = " selected=\"selected\""; 1030 } 1031 1032 $user['username'] = htmlspecialchars_uni($user['username']); 1033 eval("\$user_options .= \"".$templates->get("modcp_modlogs_user")."\";"); 1034 } 1035 1036 $forum_select = build_forum_jump("", $mybb->get_input('fid', MyBB::INPUT_INT), 1, '', 0, true, '', "fid"); 1037 1038 eval("\$modlogs = \"".$templates->get("modcp_modlogs")."\";"); 1039 output_page($modlogs); 1040 } 1041 1042 if($mybb->input['action'] == "do_delete_announcement") 1043 { 1044 verify_post_check($mybb->get_input('my_post_key')); 1045 1046 if($mybb->usergroup['canmanageannounce'] == 0) 1047 { 1048 error_no_permission(); 1049 } 1050 1051 $aid = $mybb->get_input('aid'); 1052 $query = $db->simple_select("announcements", "aid, subject, fid", "aid='{$aid}'"); 1053 $announcement = $db->fetch_array($query); 1054 1055 if(!$announcement) 1056 { 1057 error($lang->error_invalid_announcement); 1058 } 1059 if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'], "canmanageannouncements")) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums))) 1060 { 1061 error_no_permission(); 1062 } 1063 1064 $plugins->run_hooks("modcp_do_delete_announcement"); 1065 1066 $db->delete_query("announcements", "aid='{$aid}'"); 1067 log_moderator_action(array("aid" => $announcement['aid'], "subject" => $announcement['subject']), $lang->announcement_deleted); 1068 $cache->update_forumsdisplay(); 1069 1070 redirect("modcp.php?action=announcements", $lang->redirect_delete_announcement); 1071 } 1072 1073 if($mybb->input['action'] == "delete_announcement") 1074 { 1075 if($mybb->usergroup['canmanageannounce'] == 0) 1076 { 1077 error_no_permission(); 1078 } 1079 1080 $aid = $mybb->get_input('aid'); 1081 $query = $db->simple_select("announcements", "aid, subject, fid", "aid='{$aid}'"); 1082 1083 $announcement = $db->fetch_array($query); 1084 $announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject'])); 1085 1086 if(!$announcement) 1087 { 1088 error($lang->error_invalid_announcement); 1089 } 1090 1091 if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'], "canmanageannouncements")) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums))) 1092 { 1093 error_no_permission(); 1094 } 1095 1096 $plugins->run_hooks("modcp_delete_announcement"); 1097 1098 eval("\$announcements = \"".$templates->get("modcp_announcements_delete")."\";"); 1099 output_page($announcements); 1100 } 1101 1102 if($mybb->input['action'] == "do_new_announcement") 1103 { 1104 verify_post_check($mybb->get_input('my_post_key')); 1105 1106 if($mybb->usergroup['canmanageannounce'] == 0) 1107 { 1108 error_no_permission(); 1109 } 1110 1111 $announcement_fid = $mybb->get_input('fid', MyBB::INPUT_INT); 1112 if(($mybb->usergroup['issupermod'] != 1 && $announcement_fid == -1) || ($announcement_fid != -1 && !is_moderator($announcement_fid, "canmanageannouncements")) || ($unviewableforums && in_array($announcement_fid, $unviewableforums))) 1113 { 1114 error_no_permission(); 1115 } 1116 1117 $errors = array(); 1118 1119 $mybb->input['title'] = $mybb->get_input('title'); 1120 if(!trim($mybb->input['title'])) 1121 { 1122 $errors[] = $lang->error_missing_title; 1123 } 1124 1125 $mybb->input['message'] = $mybb->get_input('message'); 1126 if(!trim($mybb->input['message'])) 1127 { 1128 $errors[] = $lang->error_missing_message; 1129 } 1130 1131 if(!$announcement_fid) 1132 { 1133 $errors[] = $lang->error_missing_forum; 1134 } 1135 1136 $mybb->input['starttime_time'] = $mybb->get_input('starttime_time'); 1137 $mybb->input['endtime_time'] = $mybb->get_input('endtime_time'); 1138 $startdate = @explode(" ", $mybb->input['starttime_time']); 1139 $startdate = @explode(":", $startdate[0]); 1140 $enddate = @explode(" ", $mybb->input['endtime_time']); 1141 $enddate = @explode(":", $enddate[0]); 1142 1143 if(stristr($mybb->input['starttime_time'], "pm")) 1144 { 1145 $startdate[0] = 12+$startdate[0]; 1146 if($startdate[0] >= 24) 1147 { 1148 $startdate[0] = "00"; 1149 } 1150 } 1151 1152 if(stristr($mybb->input['endtime_time'], "pm")) 1153 { 1154 $enddate[0] = 12+$enddate[0]; 1155 if($enddate[0] >= 24) 1156 { 1157 $enddate[0] = "00"; 1158 } 1159 } 1160 1161 $mybb->input['starttime_month'] = $mybb->get_input('starttime_month'); 1162 $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); 1163 if(!in_array($mybb->input['starttime_month'], $months)) 1164 { 1165 $mybb->input['starttime_month'] = '01'; 1166 } 1167 1168 $localized_time_offset = (float)$mybb->user['timezone']*3600 + $mybb->user['dst']*3600; 1169 1170 $startdate = gmmktime((int)$startdate[0], (int)$startdate[1], 0, $mybb->get_input('starttime_month', MyBB::INPUT_INT), $mybb->get_input('starttime_day', MyBB::INPUT_INT), $mybb->get_input('starttime_year', MyBB::INPUT_INT)) - $localized_time_offset; 1171 if(!checkdate($mybb->get_input('starttime_month', MyBB::INPUT_INT), $mybb->get_input('starttime_day', MyBB::INPUT_INT), $mybb->get_input('starttime_year', MyBB::INPUT_INT)) || $startdate < 0 || $startdate == false) 1172 { 1173 $errors[] = $lang->error_invalid_start_date; 1174 } 1175 1176 if($mybb->get_input('endtime_type', MyBB::INPUT_INT) == 2) 1177 { 1178 $enddate = '0'; 1179 $mybb->input['endtime_month'] = '01'; 1180 } 1181 else 1182 { 1183 $mybb->input['endtime_month'] = $mybb->get_input('endtime_month'); 1184 if(!in_array($mybb->input['endtime_month'], $months)) 1185 { 1186 $mybb->input['endtime_month'] = '01'; 1187 } 1188 $enddate = gmmktime((int)$enddate[0], (int)$enddate[1], 0, $mybb->get_input('endtime_month', MyBB::INPUT_INT), $mybb->get_input('endtime_day', MyBB::INPUT_INT), $mybb->get_input('endtime_year', MyBB::INPUT_INT)) - $localized_time_offset; 1189 if(!checkdate($mybb->get_input('endtime_month', MyBB::INPUT_INT), $mybb->get_input('endtime_day', MyBB::INPUT_INT), $mybb->get_input('endtime_year', MyBB::INPUT_INT)) || $enddate < 0 || $enddate == false) 1190 { 1191 $errors[] = $lang->error_invalid_end_date; 1192 } 1193 1194 if($enddate <= $startdate) 1195 { 1196 $errors[] = $lang->error_end_before_start; 1197 } 1198 } 1199 1200 if($mybb->settings['announcementshtml'] && $mybb->get_input('allowhtml', MyBB::INPUT_INT) == 1) 1201 { 1202 $allowhtml = 1; 1203 } 1204 else 1205 { 1206 $allowhtml = 0; 1207 } 1208 if($mybb->get_input('allowmycode', MyBB::INPUT_INT) == 1) 1209 { 1210 $allowmycode = 1; 1211 } 1212 else 1213 { 1214 $allowmycode = 0; 1215 } 1216 if($mybb->get_input('allowsmilies', MyBB::INPUT_INT) == 1) 1217 { 1218 $allowsmilies = 1; 1219 } 1220 else 1221 { 1222 $allowsmilies = 0; 1223 } 1224 1225 $plugins->run_hooks("modcp_do_new_announcement_start"); 1226 1227 if(!$errors) 1228 { 1229 if(isset($mybb->input['preview'])) 1230 { 1231 $preview = array(); 1232 $mybb->input['action'] = 'new_announcement'; 1233 } 1234 else 1235 { 1236 $insert_announcement = array( 1237 'fid' => $announcement_fid, 1238 'uid' => $mybb->user['uid'], 1239 'subject' => $db->escape_string($mybb->input['title']), 1240 'message' => $db->escape_string($mybb->input['message']), 1241 'startdate' => $startdate, 1242 'enddate' => $enddate, 1243 'allowhtml' => $allowhtml, 1244 'allowmycode' => $allowmycode, 1245 'allowsmilies' => $allowsmilies 1246 ); 1247 $aid = $db->insert_query("announcements", $insert_announcement); 1248 1249 log_moderator_action(array("aid" => $aid, "subject" => $mybb->input['title']), $lang->announcement_added); 1250 1251 $plugins->run_hooks("modcp_do_new_announcement_end"); 1252 1253 $cache->update_forumsdisplay(); 1254 redirect("modcp.php?action=announcements", $lang->redirect_add_announcement); 1255 } 1256 } 1257 else 1258 { 1259 $mybb->input['action'] = 'new_announcement'; 1260 } 1261 } 1262 1263 if($mybb->input['action'] == "new_announcement") 1264 { 1265 if($mybb->usergroup['canmanageannounce'] == 0) 1266 { 1267 error_no_permission(); 1268 } 1269 1270 add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements"); 1271 add_breadcrumb($lang->add_announcement, "modcp.php?action=new_announcements"); 1272 1273 $announcement_fid = $mybb->get_input('fid', MyBB::INPUT_INT); 1274 1275 if(($mybb->usergroup['issupermod'] != 1 && $announcement_fid == -1) || ($announcement_fid != -1 && !is_moderator($announcement_fid, "canmanageannouncements")) || ($unviewableforums && in_array($announcement_fid, $unviewableforums))) 1276 { 1277 error_no_permission(); 1278 } 1279 1280 // Deal with inline errors 1281 if(!empty($errors) || isset($preview)) 1282 { 1283 if(!empty($errors)) 1284 { 1285 $errors = inline_error($errors); 1286 } 1287 else 1288 { 1289 $errors = ''; 1290 } 1291 1292 // Set $announcement to input stuff 1293 $announcement['subject'] = $mybb->input['title']; 1294 $announcement['message'] = $mybb->input['message']; 1295 $announcement['allowhtml'] = $allowhtml; 1296 $announcement['allowmycode'] = $allowmycode; 1297 $announcement['allowsmilies'] = $allowsmilies; 1298 1299 $startmonth = $mybb->input['starttime_month']; 1300 $startdateyear = htmlspecialchars_uni($mybb->input['starttime_year']); 1301 $startday = $mybb->get_input('starttime_day', MyBB::INPUT_INT); 1302 $starttime_time = htmlspecialchars_uni($mybb->input['starttime_time']); 1303 $endmonth = $mybb->input['endtime_month']; 1304 $enddateyear = htmlspecialchars_uni($mybb->input['endtime_year']); 1305 $endday = $mybb->get_input('endtime_day', MyBB::INPUT_INT); 1306 $endtime_time = htmlspecialchars_uni($mybb->input['endtime_time']); 1307 } 1308 else 1309 { 1310 $localized_time = TIME_NOW + (float)$mybb->user['timezone']*3600 + $mybb->user['dst']*3600; 1311 1312 $starttime_time = gmdate($mybb->settings['timeformat'], $localized_time); 1313 $endtime_time = gmdate($mybb->settings['timeformat'], $localized_time); 1314 $startday = $endday = gmdate("j", $localized_time); 1315 $startmonth = $endmonth = gmdate("m", $localized_time); 1316 $startdateyear = gmdate("Y", $localized_time); 1317 1318 $announcement = array( 1319 'subject' => '', 1320 'message' => '', 1321 'allowhtml' => 0, 1322 'allowmycode' => 1, 1323 'allowsmilies' => 1 1324 ); 1325 1326 $enddateyear = $startdateyear+1; 1327 } 1328 1329 // Generate form elements 1330 $startdateday = $enddateday = ''; 1331 for($day = 1; $day <= 31; ++$day) 1332 { 1333 if($startday == $day) 1334 { 1335 $selected = " selected=\"selected\""; 1336 eval("\$startdateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1337 } 1338 else 1339 { 1340 $selected = ''; 1341 eval("\$startdateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1342 } 1343 1344 if($endday == $day) 1345 { 1346 $selected = " selected=\"selected\""; 1347 eval("\$enddateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1348 } 1349 else 1350 { 1351 $selected = ''; 1352 eval("\$enddateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1353 } 1354 } 1355 1356 $startmonthsel = $endmonthsel = array(); 1357 foreach(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12') as $month) 1358 { 1359 $startmonthsel[$month] = ''; 1360 $endmonthsel[$month] = ''; 1361 } 1362 $startmonthsel[$startmonth] = "selected=\"selected\""; 1363 $endmonthsel[$endmonth] = "selected=\"selected\""; 1364 1365 $startdatemonth = $enddatemonth = ''; 1366 1367 eval("\$startdatemonth .= \"".$templates->get("modcp_announcements_month_start")."\";"); 1368 eval("\$enddatemonth .= \"".$templates->get("modcp_announcements_month_end")."\";"); 1369 1370 $title = htmlspecialchars_uni($announcement['subject']); 1371 $message = htmlspecialchars_uni($announcement['message']); 1372 1373 $html_sel = $mycode_sel = $smilies_sel = array('yes' => '', 'no' => ''); 1374 1375 if($mybb->settings['announcementshtml']) 1376 { 1377 if($announcement['allowhtml']) 1378 { 1379 $html_sel['yes'] = ' checked="checked"'; 1380 } 1381 else 1382 { 1383 $html_sel['no'] = ' checked="checked"'; 1384 } 1385 1386 eval("\$allow_html = \"".$templates->get("modcp_announcements_allowhtml")."\";"); 1387 } 1388 else 1389 { 1390 $allow_html = ''; 1391 } 1392 1393 if($announcement['allowmycode']) 1394 { 1395 $mycode_sel['yes'] = ' checked="checked"'; 1396 } 1397 else 1398 { 1399 $mycode_sel['no'] = ' checked="checked"'; 1400 } 1401 1402 if($announcement['allowsmilies']) 1403 { 1404 $smilies_sel['yes'] = ' checked="checked"'; 1405 } 1406 else 1407 { 1408 $smilies_sel['no'] = ' checked="checked"'; 1409 } 1410 1411 $end_type_sel = array('infinite' => '', 'finite' => ''); 1412 if(!isset($mybb->input['endtime_type']) || $mybb->input['endtime_type'] == 2) 1413 { 1414 $end_type_sel['infinite'] = ' checked="checked"'; 1415 } 1416 else 1417 { 1418 $end_type_sel['finite'] = ' checked="checked"'; 1419 } 1420 1421 // MyCode editor 1422 $codebuttons = build_mycode_inserter(); 1423 $smilieinserter = build_clickable_smilies(); 1424 1425 if(isset($preview)) 1426 { 1427 $announcementarray = array( 1428 'aid' => 0, 1429 'fid' => $announcement_fid, 1430 'uid' => $mybb->user['uid'], 1431 'subject' => $mybb->input['title'], 1432 'message' => $mybb->input['message'], 1433 'allowhtml' => $mybb->settings['announcementshtml'] && $mybb->get_input('allowhtml', MyBB::INPUT_INT), 1434 'allowmycode' => $mybb->get_input('allowmycode', MyBB::INPUT_INT), 1435 'allowsmilies' => $mybb->get_input('allowsmilies', MyBB::INPUT_INT), 1436 'dateline' => TIME_NOW, 1437 'userusername' => $mybb->user['username'], 1438 ); 1439 1440 $array = $mybb->user; 1441 foreach($array as $key => $element) 1442 { 1443 $announcementarray[$key] = $element; 1444 } 1445 1446 // Gather usergroup data from the cache 1447 // Field => Array Key 1448 $data_key = array( 1449 'title' => 'grouptitle', 1450 'usertitle' => 'groupusertitle', 1451 'stars' => 'groupstars', 1452 'starimage' => 'groupstarimage', 1453 'image' => 'groupimage', 1454 'namestyle' => 'namestyle', 1455 'usereputationsystem' => 'usereputationsystem' 1456 ); 1457 1458 foreach($data_key as $field => $key) 1459 { 1460 $announcementarray[$key] = $groupscache[$announcementarray['usergroup']][$field]; 1461 } 1462 1463 require_once MYBB_ROOT."inc/functions_post.php"; 1464 $postbit = build_postbit($announcementarray, 3); 1465 eval("\$preview = \"".$templates->get("previewpost")."\";"); 1466 } 1467 else 1468 { 1469 $preview = ''; 1470 } 1471 1472 $plugins->run_hooks("modcp_new_announcement"); 1473 1474 eval("\$announcements = \"".$templates->get("modcp_announcements_new")."\";"); 1475 output_page($announcements); 1476 } 1477 1478 if($mybb->input['action'] == "do_edit_announcement") 1479 { 1480 verify_post_check($mybb->get_input('my_post_key')); 1481 1482 if($mybb->usergroup['canmanageannounce'] == 0) 1483 { 1484 error_no_permission(); 1485 } 1486 1487 // Get the announcement 1488 $aid = $mybb->get_input('aid', MyBB::INPUT_INT); 1489 $query = $db->simple_select("announcements", "*", "aid='{$aid}'"); 1490 $announcement = $db->fetch_array($query); 1491 1492 // Check that it exists 1493 if(!$announcement) 1494 { 1495 error($lang->error_invalid_announcement); 1496 } 1497 1498 // Mod has permissions to edit this announcement 1499 if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'], "canmanageannouncements")) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums))) 1500 { 1501 error_no_permission(); 1502 } 1503 1504 $errors = array(); 1505 1506 // Basic error checking 1507 $mybb->input['title'] = $mybb->get_input('title'); 1508 if(!trim_blank_chrs($mybb->input['title'])) 1509 { 1510 $errors[] = $lang->error_missing_title; 1511 } 1512 1513 $mybb->input['message'] = $mybb->get_input('message'); 1514 if(!trim_blank_chrs($mybb->input['message'])) 1515 { 1516 $errors[] = $lang->error_missing_message; 1517 } 1518 1519 $mybb->input['starttime_time'] = $mybb->get_input('starttime_time'); 1520 $mybb->input['endtime_time'] = $mybb->get_input('endtime_time'); 1521 $startdate = @explode(" ", $mybb->input['starttime_time']); 1522 $startdate = @explode(":", $startdate[0]); 1523 $enddate = @explode(" ", $mybb->input['endtime_time']); 1524 $enddate = @explode(":", $enddate[0]); 1525 1526 if(stristr($mybb->input['starttime_time'], "pm")) 1527 { 1528 $startdate[0] = 12+$startdate[0]; 1529 if($startdate[0] >= 24) 1530 { 1531 $startdate[0] = "00"; 1532 } 1533 } 1534 1535 if(stristr($mybb->input['endtime_time'], "pm")) 1536 { 1537 $enddate[0] = 12+$enddate[0]; 1538 if($enddate[0] >= 24) 1539 { 1540 $enddate[0] = "00"; 1541 } 1542 } 1543 1544 $mybb->input['starttime_month'] = $mybb->get_input('starttime_month'); 1545 $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); 1546 if(!in_array($mybb->input['starttime_month'], $months)) 1547 { 1548 $mybb->input['starttime_month'] = '01'; 1549 } 1550 1551 $localized_time_offset = (float)$mybb->user['timezone']*3600 + $mybb->user['dst']*3600; 1552 1553 $startdate = gmmktime((int)$startdate[0], (int)$startdate[1], 0, $mybb->get_input('starttime_month', MyBB::INPUT_INT), $mybb->get_input('starttime_day', MyBB::INPUT_INT), $mybb->get_input('starttime_year', MyBB::INPUT_INT)) - $localized_time_offset; 1554 if(!checkdate($mybb->get_input('starttime_month', MyBB::INPUT_INT), $mybb->get_input('starttime_day', MyBB::INPUT_INT), $mybb->get_input('starttime_year', MyBB::INPUT_INT)) || $startdate < 0 || $startdate == false) 1555 { 1556 $errors[] = $lang->error_invalid_start_date; 1557 } 1558 1559 if($mybb->get_input('endtime_type', MyBB::INPUT_INT) == "2") 1560 { 1561 $enddate = '0'; 1562 $mybb->input['endtime_month'] = '01'; 1563 } 1564 else 1565 { 1566 $mybb->input['endtime_month'] = $mybb->get_input('endtime_month'); 1567 if(!in_array($mybb->input['endtime_month'], $months)) 1568 { 1569 $mybb->input['endtime_month'] = '01'; 1570 } 1571 $enddate = gmmktime((int)$enddate[0], (int)$enddate[1], 0, $mybb->get_input('endtime_month', MyBB::INPUT_INT), $mybb->get_input('endtime_day', MyBB::INPUT_INT), $mybb->get_input('endtime_year', MyBB::INPUT_INT)) - $localized_time_offset; 1572 if(!checkdate($mybb->get_input('endtime_month', MyBB::INPUT_INT), $mybb->get_input('endtime_day', MyBB::INPUT_INT), $mybb->get_input('endtime_year', MyBB::INPUT_INT)) || $enddate < 0 || $enddate == false) 1573 { 1574 $errors[] = $lang->error_invalid_end_date; 1575 } 1576 elseif($enddate <= $startdate) 1577 { 1578 $errors[] = $lang->error_end_before_start; 1579 } 1580 } 1581 1582 if($mybb->settings['announcementshtml'] && $mybb->get_input('allowhtml', MyBB::INPUT_INT) == 1) 1583 { 1584 $allowhtml = 1; 1585 } 1586 else 1587 { 1588 $allowhtml = 0; 1589 } 1590 if($mybb->get_input('allowmycode', MyBB::INPUT_INT) == 1) 1591 { 1592 $allowmycode = 1; 1593 } 1594 else 1595 { 1596 $allowmycode = 0; 1597 } 1598 if($mybb->get_input('allowsmilies', MyBB::INPUT_INT) == 1) 1599 { 1600 $allowsmilies = 1; 1601 } 1602 else 1603 { 1604 $allowsmilies = 0; 1605 } 1606 1607 $plugins->run_hooks("modcp_do_edit_announcement_start"); 1608 1609 // Proceed to update if no errors 1610 if(!$errors) 1611 { 1612 if(isset($mybb->input['preview'])) 1613 { 1614 $preview = array(); 1615 $mybb->input['action'] = 'edit_announcement'; 1616 } 1617 else 1618 { 1619 $update_announcement = array( 1620 'uid' => $mybb->user['uid'], 1621 'subject' => $db->escape_string($mybb->input['title']), 1622 'message' => $db->escape_string($mybb->input['message']), 1623 'startdate' => $startdate, 1624 'enddate' => $enddate, 1625 'allowhtml' => $allowhtml, 1626 'allowmycode' => $allowmycode, 1627 'allowsmilies' => $allowsmilies 1628 ); 1629 $db->update_query("announcements", $update_announcement, "aid='{$aid}'"); 1630 1631 log_moderator_action(array("aid" => $announcement['aid'], "subject" => $mybb->input['title']), $lang->announcement_edited); 1632 1633 $plugins->run_hooks("modcp_do_edit_announcement_end"); 1634 1635 $cache->update_forumsdisplay(); 1636 redirect("modcp.php?action=announcements", $lang->redirect_edit_announcement); 1637 } 1638 } 1639 else 1640 { 1641 $mybb->input['action'] = 'edit_announcement'; 1642 } 1643 } 1644 1645 if($mybb->input['action'] == "edit_announcement") 1646 { 1647 if($mybb->usergroup['canmanageannounce'] == 0) 1648 { 1649 error_no_permission(); 1650 } 1651 1652 $aid = $mybb->get_input('aid', MyBB::INPUT_INT); 1653 1654 add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements"); 1655 add_breadcrumb($lang->edit_announcement, "modcp.php?action=edit_announcements&aid={$aid}"); 1656 1657 // Get announcement 1658 if(!isset($announcement) || $mybb->request_method != 'post') 1659 { 1660 $query = $db->simple_select("announcements", "*", "aid='{$aid}'"); 1661 $announcement = $db->fetch_array($query); 1662 } 1663 1664 if(!$announcement) 1665 { 1666 error($lang->error_invalid_announcement); 1667 } 1668 if(($mybb->usergroup['issupermod'] != 1 && $announcement['fid'] == -1) || ($announcement['fid'] != -1 && !is_moderator($announcement['fid'], "canmanageannouncements")) || ($unviewableforums && in_array($announcement['fid'], $unviewableforums))) 1669 { 1670 error_no_permission(); 1671 } 1672 1673 if(!$announcement['startdate']) 1674 { 1675 // No start date? Make it now. 1676 $announcement['startdate'] = TIME_NOW; 1677 } 1678 1679 $makeshift_end = false; 1680 if(!$announcement['enddate']) 1681 { 1682 $makeshift_end = true; 1683 $makeshift_time = TIME_NOW; 1684 if($announcement['startdate']) 1685 { 1686 $makeshift_time = $announcement['startdate']; 1687 } 1688 1689 // No end date? Make it a year from now. 1690 $announcement['enddate'] = $makeshift_time + (60 * 60 * 24 * 366); 1691 } 1692 1693 // Deal with inline errors 1694 if(!empty($errors) || isset($preview)) 1695 { 1696 if(!empty($errors)) 1697 { 1698 $errors = inline_error($errors); 1699 } 1700 else 1701 { 1702 $errors = ''; 1703 } 1704 1705 // Set $announcement to input stuff 1706 $announcement['subject'] = $mybb->input['title']; 1707 $announcement['message'] = $mybb->input['message']; 1708 $announcement['allowhtml'] = $allowhtml; 1709 $announcement['allowmycode'] = $allowmycode; 1710 $announcement['allowsmilies'] = $allowsmilies; 1711 1712 $startmonth = $mybb->input['starttime_month']; 1713 $startdateyear = htmlspecialchars_uni($mybb->input['starttime_year']); 1714 $startday = $mybb->get_input('starttime_day', MyBB::INPUT_INT); 1715 $starttime_time = htmlspecialchars_uni($mybb->input['starttime_time']); 1716 $endmonth = $mybb->input['endtime_month']; 1717 $enddateyear = htmlspecialchars_uni($mybb->input['endtime_year']); 1718 $endday = $mybb->get_input('endtime_day', MyBB::INPUT_INT); 1719 $endtime_time = htmlspecialchars_uni($mybb->input['endtime_time']); 1720 1721 $errored = true; 1722 } 1723 else 1724 { 1725 $localized_time_startdate = $announcement['startdate'] + (float)$mybb->user['timezone']*3600 + $mybb->user['dst']*3600; 1726 $localized_time_enddate = $announcement['enddate'] + (float)$mybb->user['timezone']*3600 + $mybb->user['dst']*3600; 1727 1728 $starttime_time = gmdate($mybb->settings['timeformat'], $localized_time_startdate); 1729 $endtime_time = gmdate($mybb->settings['timeformat'], $localized_time_enddate); 1730 1731 $startday = gmdate('j', $localized_time_startdate); 1732 $endday = gmdate('j', $localized_time_enddate); 1733 1734 $startmonth = gmdate('m', $localized_time_startdate); 1735 $endmonth = gmdate('m', $localized_time_enddate); 1736 1737 $startdateyear = gmdate('Y', $localized_time_startdate); 1738 $enddateyear = gmdate('Y', $localized_time_enddate); 1739 1740 $errored = false; 1741 } 1742 1743 // Generate form elements 1744 $startdateday = $enddateday = ''; 1745 for($day = 1; $day <= 31; ++$day) 1746 { 1747 if($startday == $day) 1748 { 1749 $selected = " selected=\"selected\""; 1750 eval("\$startdateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1751 } 1752 else 1753 { 1754 $selected = ''; 1755 eval("\$startdateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1756 } 1757 1758 if($endday == $day) 1759 { 1760 $selected = " selected=\"selected\""; 1761 eval("\$enddateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1762 } 1763 else 1764 { 1765 $selected = ''; 1766 eval("\$enddateday .= \"".$templates->get("modcp_announcements_day")."\";"); 1767 } 1768 } 1769 1770 $startmonthsel = $endmonthsel = array(); 1771 foreach(array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12') as $month) 1772 { 1773 $startmonthsel[$month] = ''; 1774 $endmonthsel[$month] = ''; 1775 } 1776 $startmonthsel[$startmonth] = "selected=\"selected\""; 1777 $endmonthsel[$endmonth] = "selected=\"selected\""; 1778 1779 $startdatemonth = $enddatemonth = ''; 1780 1781 eval("\$startdatemonth .= \"".$templates->get("modcp_announcements_month_start")."\";"); 1782 eval("\$enddatemonth .= \"".$templates->get("modcp_announcements_month_end")."\";"); 1783 1784 $title = htmlspecialchars_uni($announcement['subject']); 1785 $message = htmlspecialchars_uni($announcement['message']); 1786 1787 $html_sel = $mycode_sel = $smilies_sel = array('yes' => '', 'no' => ''); 1788 1789 if($mybb->settings['announcementshtml']) 1790 { 1791 if($announcement['allowhtml']) 1792 { 1793 $html_sel['yes'] = ' checked="checked"'; 1794 } 1795 else 1796 { 1797 $html_sel['no'] = ' checked="checked"'; 1798 } 1799 1800 eval("\$allow_html = \"".$templates->get("modcp_announcements_allowhtml")."\";"); 1801 } 1802 else 1803 { 1804 $allow_html = ''; 1805 } 1806 1807 if($announcement['allowmycode']) 1808 { 1809 $mycode_sel['yes'] = ' checked="checked"'; 1810 } 1811 else 1812 { 1813 $mycode_sel['no'] = ' checked="checked"'; 1814 } 1815 1816 if($announcement['allowsmilies']) 1817 { 1818 $smilies_sel['yes'] = ' checked="checked"'; 1819 } 1820 else 1821 { 1822 $smilies_sel['no'] = ' checked="checked"'; 1823 } 1824 1825 $end_type_sel = array('infinite' => '', 'finite' => ''); 1826 if(($errored && $mybb->get_input('endtime_type', MyBB::INPUT_INT) == 2) || (!$errored && (int)$announcement['enddate'] == 0) || $makeshift_end == true) 1827 { 1828 $end_type_sel['infinite'] = ' checked="checked"'; 1829 } 1830 else 1831 { 1832 $end_type_sel['finite'] = ' checked="checked"'; 1833 } 1834 1835 // MyCode editor 1836 $codebuttons = build_mycode_inserter(); 1837 $smilieinserter = build_clickable_smilies(); 1838 1839 if(isset($preview)) 1840 { 1841 $announcementarray = array( 1842 'aid' => $announcement['aid'], 1843 'fid' => $announcement['fid'], 1844 'uid' => $mybb->user['uid'], 1845 'subject' => $mybb->input['title'], 1846 'message' => $mybb->input['message'], 1847 'allowhtml' => $mybb->settings['announcementshtml'] && $mybb->get_input('allowhtml', MyBB::INPUT_INT), 1848 'allowmycode' => $mybb->get_input('allowmycode', MyBB::INPUT_INT), 1849 'allowsmilies' => $mybb->get_input('allowsmilies', MyBB::INPUT_INT), 1850 'dateline' => TIME_NOW, 1851 'userusername' => $mybb->user['username'], 1852 ); 1853 1854 $array = $mybb->user; 1855 foreach($array as $key => $element) 1856 { 1857 $announcementarray[$key] = $element; 1858 } 1859 1860 // Gather usergroup data from the cache 1861 // Field => Array Key 1862 $data_key = array( 1863 'title' => 'grouptitle', 1864 'usertitle' => 'groupusertitle', 1865 'stars' => 'groupstars', 1866 'starimage' => 'groupstarimage', 1867 'image' => 'groupimage', 1868 'namestyle' => 'namestyle', 1869 'usereputationsystem' => 'usereputationsystem' 1870 ); 1871 1872 foreach($data_key as $field => $key) 1873 { 1874 $announcementarray[$key] = $groupscache[$announcementarray['usergroup']][$field]; 1875 } 1876 1877 require_once MYBB_ROOT."inc/functions_post.php"; 1878 $postbit = build_postbit($announcementarray, 3); 1879 eval("\$preview = \"".$templates->get("previewpost")."\";"); 1880 } 1881 else 1882 { 1883 $preview = ''; 1884 } 1885 1886 $plugins->run_hooks("modcp_edit_announcement"); 1887 1888 eval("\$announcements = \"".$templates->get("modcp_announcements_edit")."\";"); 1889 output_page($announcements); 1890 } 1891 1892 if($mybb->input['action'] == "announcements") 1893 { 1894 if($mybb->usergroup['canmanageannounce'] == 0) 1895 { 1896 error_no_permission(); 1897 } 1898 1899 if($numannouncements == 0 && $mybb->usergroup['issupermod'] != 1) 1900 { 1901 error($lang->you_cannot_manage_announcements); 1902 } 1903 1904 add_breadcrumb($lang->mcp_nav_announcements, "modcp.php?action=announcements"); 1905 1906 // Fetch announcements into their proper arrays 1907 $query = $db->simple_select("announcements", "aid, fid, subject, enddate"); 1908 $announcements = $global_announcements = array(); 1909 while($announcement = $db->fetch_array($query)) 1910 { 1911 if($announcement['fid'] == -1) 1912 { 1913 $global_announcements[$announcement['aid']] = $announcement; 1914 continue; 1915 } 1916 $announcements[$announcement['fid']][$announcement['aid']] = $announcement; 1917 } 1918 1919 $announcements_global = ''; 1920 if($mybb->usergroup['issupermod'] == 1) 1921 { 1922 if($global_announcements && $mybb->usergroup['issupermod'] == 1) 1923 { 1924 // Get the global announcements 1925 foreach($global_announcements as $aid => $announcement) 1926 { 1927 $trow = alt_trow(); 1928 if((isset($announcement['startdate']) && $announcement['startdate'] > TIME_NOW) || (isset($announcement['enddate']) && $announcement['enddate'] < TIME_NOW && $announcement['enddate'] != 0)) 1929 { 1930 eval("\$icon = \"".$templates->get("modcp_announcements_announcement_expired")."\";"); 1931 } 1932 else 1933 { 1934 eval("\$icon = \"".$templates->get("modcp_announcements_announcement_active")."\";"); 1935 } 1936 1937 $subject = htmlspecialchars_uni($parser->parse_badwords($announcement['subject'])); 1938 1939 eval("\$announcements_global .= \"".$templates->get("modcp_announcements_announcement_global")."\";"); 1940 } 1941 } 1942 else 1943 { 1944 // No global announcements 1945 eval("\$announcements_global = \"".$templates->get("modcp_no_announcements_global")."\";"); 1946 } 1947 eval("\$announcements_global = \"".$templates->get("modcp_announcements_global")."\";"); 1948 } 1949 1950 $announcements_forum = ''; 1951 fetch_forum_announcements(); 1952 1953 if(!$announcements_forum) 1954 { 1955 eval("\$announcements_forum = \"".$templates->get("modcp_no_announcements_forum")."\";"); 1956 } 1957 1958 $plugins->run_hooks("modcp_announcements"); 1959 1960 eval("\$announcements = \"".$templates->get("modcp_announcements")."\";"); 1961 output_page($announcements); 1962 } 1963 1964 if($mybb->input['action'] == "do_modqueue") 1965 { 1966 require_once MYBB_ROOT."inc/class_moderation.php"; 1967 $moderation = new Moderation; 1968 1969 // Verify incoming POST request 1970 verify_post_check($mybb->get_input('my_post_key')); 1971 1972 if($mybb->usergroup['canmanagemodqueue'] == 0) 1973 { 1974 error_no_permission(); 1975 } 1976 1977 $plugins->run_hooks("modcp_do_modqueue_start"); 1978 1979 $mybb->input['threads'] = $mybb->get_input('threads', MyBB::INPUT_ARRAY); 1980 $mybb->input['posts'] = $mybb->get_input('posts', MyBB::INPUT_ARRAY); 1981 $mybb->input['attachments'] = $mybb->get_input('attachments', MyBB::INPUT_ARRAY); 1982 if(!empty($mybb->input['threads'])) 1983 { 1984 if($nummodqueuethreads == 0 && $mybb->usergroup['issupermod'] != 1) 1985 { 1986 error($lang->you_cannot_moderate_threads); 1987 } 1988 1989 $threads = array_map("intval", array_keys($mybb->input['threads'])); 1990 $threads_to_approve = $threads_to_delete = array(); 1991 // Fetch threads 1992 $query = $db->simple_select("threads", "tid", "tid IN (".implode(",", $threads)."){$flist_queue_threads}"); 1993 while($thread = $db->fetch_array($query)) 1994 { 1995 if(!isset($mybb->input['threads'][$thread['tid']])) 1996 { 1997 continue; 1998 } 1999 $action = $mybb->input['threads'][$thread['tid']]; 2000 if($action == "approve") 2001 { 2002 $threads_to_approve[] = $thread['tid']; 2003 } 2004 else if($action == "delete") 2005 { 2006 $threads_to_delete[] = $thread['tid']; 2007 } 2008 } 2009 if(!empty($threads_to_approve)) 2010 { 2011 $moderation->approve_threads($threads_to_approve); 2012 log_moderator_action(array('tids' => $threads_to_approve), $lang->multi_approve_threads); 2013 } 2014 if(!empty($threads_to_delete)) 2015 { 2016 if($mybb->settings['soft_delete'] == 1) 2017 { 2018 $moderation->soft_delete_threads($threads_to_delete); 2019 log_moderator_action(array('tids' => $threads_to_delete), $lang->multi_soft_delete_threads); 2020 } 2021 else 2022 { 2023 foreach($threads_to_delete as $tid) 2024 { 2025 $moderation->delete_thread($tid); 2026 } 2027 log_moderator_action(array('tids' => $threads_to_delete), $lang->multi_delete_threads); 2028 } 2029 } 2030 2031 $plugins->run_hooks("modcp_do_modqueue_end"); 2032 2033 redirect("modcp.php?action=modqueue", $lang->redirect_threadsmoderated); 2034 } 2035 else if(!empty($mybb->input['posts'])) 2036 { 2037 if($nummodqueueposts == 0 && $mybb->usergroup['issupermod'] != 1) 2038 { 2039 error($lang->you_cannot_moderate_posts); 2040 } 2041 2042 $posts = array_map("intval", array_keys($mybb->input['posts'])); 2043 // Fetch posts 2044 $posts_to_approve = $posts_to_delete = array(); 2045 $query = $db->simple_select("posts", "pid", "pid IN (".implode(",", $posts)."){$flist_queue_posts}"); 2046 while($post = $db->fetch_array($query)) 2047 { 2048 if(!isset($mybb->input['posts'][$post['pid']])) 2049 { 2050 continue; 2051 } 2052 $action = $mybb->input['posts'][$post['pid']]; 2053 if($action == "approve") 2054 { 2055 $posts_to_approve[] = $post['pid']; 2056 } 2057 else if($action == "delete" && $mybb->settings['soft_delete'] != 1) 2058 { 2059 $moderation->delete_post($post['pid']); 2060 } 2061 else if($action == "delete") 2062 { 2063 $posts_to_delete[] = $post['pid']; 2064 } 2065 } 2066 if(!empty($posts_to_approve)) 2067 { 2068 $moderation->approve_posts($posts_to_approve); 2069 log_moderator_action(array('pids' => $posts_to_approve), $lang->multi_approve_posts); 2070 } 2071 if(!empty($posts_to_delete)) 2072 { 2073 if($mybb->settings['soft_delete'] == 1) 2074 { 2075 $moderation->soft_delete_posts($posts_to_delete); 2076 log_moderator_action(array('pids' => $posts_to_delete), $lang->multi_soft_delete_posts); 2077 } 2078 else 2079 { 2080 log_moderator_action(array('pids' => $posts_to_delete), $lang->multi_delete_posts); 2081 } 2082 } 2083 2084 $plugins->run_hooks("modcp_do_modqueue_end"); 2085 2086 redirect("modcp.php?action=modqueue&type=posts", $lang->redirect_postsmoderated); 2087 } 2088 else if(!empty($mybb->input['attachments'])) 2089 { 2090 if($nummodqueueattach == 0 && $mybb->usergroup['issupermod'] != 1) 2091 { 2092 error($lang->you_cannot_moderate_attachments); 2093 } 2094 2095 $attachments = array_map("intval", array_keys($mybb->input['attachments'])); 2096 $query = $db->query(" 2097 SELECT a.pid, a.aid, t.tid 2098 FROM ".TABLE_PREFIX."attachments a 2099 LEFT JOIN ".TABLE_PREFIX."posts p ON (a.pid=p.pid) 2100 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 2101 WHERE aid IN (".implode(",", $attachments)."){$tflist_queue_attach} 2102 "); 2103 while($attachment = $db->fetch_array($query)) 2104 { 2105 if(!isset($mybb->input['attachments'][$attachment['aid']])) 2106 { 2107 continue; 2108 } 2109 $action = $mybb->input['attachments'][$attachment['aid']]; 2110 if($action == "approve") 2111 { 2112 $db->update_query("attachments", array("visible" => 1), "aid='{$attachment['aid']}'"); 2113 if(isset($attachment['tid'])) 2114 { 2115 update_thread_counters((int)$attachment['tid'], array("attachmentcount" => "+1")); 2116 } 2117 } 2118 else if($action == "delete") 2119 { 2120 remove_attachment($attachment['pid'], '', $attachment['aid']); 2121 if(isset($attachment['tid'])) 2122 { 2123 update_thread_counters((int)$attachment['tid'], array("attachmentcount" => "-1")); 2124 } 2125 } 2126 } 2127 2128 $plugins->run_hooks("modcp_do_modqueue_end"); 2129 2130 redirect("modcp.php?action=modqueue&type=attachments", $lang->redirect_attachmentsmoderated); 2131 } 2132 } 2133 2134 if($mybb->input['action'] == "modqueue") 2135 { 2136 $navsep = ''; 2137 2138 if($mybb->usergroup['canmanagemodqueue'] == 0) 2139 { 2140 error_no_permission(); 2141 } 2142 2143 if($nummodqueuethreads == 0 && $nummodqueueposts == 0 && $nummodqueueattach == 0 && $mybb->usergroup['issupermod'] != 1) 2144 { 2145 error($lang->you_cannot_use_mod_queue); 2146 } 2147 2148 $mybb->input['type'] = $mybb->get_input('type'); 2149 $threadqueue = $postqueue = $attachmentqueue = ''; 2150 if($mybb->input['type'] == "threads" || !$mybb->input['type'] && ($nummodqueuethreads > 0 || $mybb->usergroup['issupermod'] == 1)) 2151 { 2152 if($nummodqueuethreads == 0 && $mybb->usergroup['issupermod'] != 1) 2153 { 2154 error($lang->you_cannot_moderate_threads); 2155 } 2156 2157 $forum_cache = $cache->read("forums"); 2158 2159 $query = $db->simple_select("threads", "COUNT(tid) AS unapprovedthreads", "visible='0' {$flist_queue_threads}"); 2160 $unapproved_threads = $db->fetch_field($query, "unapprovedthreads"); 2161 2162 // Figure out if we need to display multiple pages. 2163 if($mybb->get_input('page') != "last") 2164 { 2165 $page = $mybb->get_input('page', MyBB::INPUT_INT); 2166 } 2167 2168 $perpage = $mybb->settings['threadsperpage']; 2169 $pages = $unapproved_threads / $perpage; 2170 $pages = ceil($pages); 2171 2172 if($mybb->get_input('page') == "last") 2173 { 2174 $page = $pages; 2175 } 2176 2177 if($page > $pages || $page <= 0) 2178 { 2179 $page = 1; 2180 } 2181 2182 if($page) 2183 { 2184 $start = ($page-1) * $perpage; 2185 } 2186 else 2187 { 2188 $start = 0; 2189 $page = 1; 2190 } 2191 2192 $multipage = multipage($unapproved_threads, $perpage, $page, "modcp.php?action=modqueue&type=threads"); 2193 2194 $query = $db->query(" 2195 SELECT t.tid, t.dateline, t.fid, t.subject, t.username AS threadusername, p.message AS postmessage, u.username AS username, t.uid 2196 FROM ".TABLE_PREFIX."threads t 2197 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=t.firstpost) 2198 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid) 2199 WHERE t.visible='0' {$tflist_queue_threads} 2200 ORDER BY t.lastpost DESC 2201 LIMIT {$start}, {$perpage} 2202 "); 2203 $threads = ''; 2204 while($thread = $db->fetch_array($query)) 2205 { 2206 $altbg = alt_trow(); 2207 $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject'])); 2208 $thread['threadlink'] = get_thread_link($thread['tid']); 2209 $forum_link = get_forum_link($thread['fid']); 2210 $forum_name = $forum_cache[$thread['fid']]['name']; 2211 $threaddate = my_date('relative', $thread['dateline']); 2212 2213 if($thread['username'] == "") 2214 { 2215 if($thread['threadusername'] != "") 2216 { 2217 $thread['threadusername'] = htmlspecialchars_uni($thread['threadusername']); 2218 $profile_link = $thread['threadusername']; 2219 } 2220 else 2221 { 2222 $profile_link = $lang->guest; 2223 } 2224 } 2225 else 2226 { 2227 $thread['username'] = htmlspecialchars_uni($thread['username']); 2228 $profile_link = build_profile_link($thread['username'], $thread['uid']); 2229 } 2230 2231 $thread['postmessage'] = nl2br(htmlspecialchars_uni($thread['postmessage'])); 2232 eval("\$forum = \"".$templates->get("modcp_modqueue_link_forum")."\";"); 2233 eval("\$threads .= \"".$templates->get("modcp_modqueue_threads_thread")."\";"); 2234 } 2235 2236 if(!$threads && $mybb->input['type'] == "threads") 2237 { 2238 eval("\$threads = \"".$templates->get("modcp_modqueue_threads_empty")."\";"); 2239 } 2240 2241 if($threads) 2242 { 2243 add_breadcrumb($lang->mcp_nav_modqueue_threads, "modcp.php?action=modqueue&type=threads"); 2244 2245 $plugins->run_hooks("modcp_modqueue_threads_end"); 2246 2247 if($nummodqueueposts > 0 || $mybb->usergroup['issupermod'] == 1) 2248 { 2249 $navsep = " | "; 2250 eval("\$post_link = \"".$templates->get("modcp_modqueue_post_link")."\";"); 2251 } 2252 2253 if($mybb->settings['enableattachments'] == 1 && ($nummodqueueattach > 0 || $mybb->usergroup['issupermod'] == 1)) 2254 { 2255 $navsep = " | "; 2256 eval("\$attachment_link = \"".$templates->get("modcp_modqueue_attachment_link")."\";"); 2257 } 2258 2259 eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";"); 2260 eval("\$threadqueue = \"".$templates->get("modcp_modqueue_threads")."\";"); 2261 output_page($threadqueue); 2262 } 2263 $type = 'threads'; 2264 } 2265 2266 if($mybb->input['type'] == "posts" || (!$mybb->input['type'] && !$threadqueue && ($nummodqueueposts > 0 || $mybb->usergroup['issupermod'] == 1))) 2267 { 2268 if($nummodqueueposts == 0 && $mybb->usergroup['issupermod'] != 1) 2269 { 2270 error($lang->you_cannot_moderate_posts); 2271 } 2272 2273 $forum_cache = $cache->read("forums"); 2274 2275 $query = $db->query(" 2276 SELECT COUNT(pid) AS unapprovedposts 2277 FROM ".TABLE_PREFIX."posts p 2278 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 2279 WHERE p.visible='0' {$tflist_queue_posts} AND t.firstpost != p.pid 2280 "); 2281 $unapproved_posts = $db->fetch_field($query, "unapprovedposts"); 2282 2283 // Figure out if we need to display multiple pages. 2284 if($mybb->get_input('page') != "last") 2285 { 2286 $page = $mybb->get_input('page', MyBB::INPUT_INT); 2287 } 2288 2289 $perpage = $mybb->settings['postsperpage']; 2290 $pages = $unapproved_posts / $perpage; 2291 $pages = ceil($pages); 2292 2293 if($mybb->get_input('page') == "last") 2294 { 2295 $page = $pages; 2296 } 2297 2298 if($page > $pages || $page <= 0) 2299 { 2300 $page = 1; 2301 } 2302 2303 if($page) 2304 { 2305 $start = ($page-1) * $perpage; 2306 } 2307 else 2308 { 2309 $start = 0; 2310 $page = 1; 2311 } 2312 2313 $multipage = multipage($unapproved_posts, $perpage, $page, "modcp.php?action=modqueue&type=posts"); 2314 2315 $query = $db->query(" 2316 SELECT p.pid, p.subject, p.message, p.username AS postusername, t.subject AS threadsubject, t.tid, u.username, p.uid, t.fid, p.dateline 2317 FROM ".TABLE_PREFIX."posts p 2318 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 2319 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 2320 WHERE p.visible='0' {$tflist_queue_posts} AND t.firstpost != p.pid 2321 ORDER BY p.dateline DESC, p.pid DESC 2322 LIMIT {$start}, {$perpage} 2323 "); 2324 $posts = ''; 2325 while($post = $db->fetch_array($query)) 2326 { 2327 $altbg = alt_trow(); 2328 $post['threadsubject'] = htmlspecialchars_uni($parser->parse_badwords($post['threadsubject'])); 2329 $post['subject'] = htmlspecialchars_uni($parser->parse_badwords($post['subject'])); 2330 $post['threadlink'] = get_thread_link($post['tid']); 2331 $post['postlink'] = get_post_link($post['pid'], $post['tid']); 2332 $forum_link = get_forum_link($post['fid']); 2333 $forum_name = $forum_cache[$post['fid']]['name']; 2334 $postdate = my_date('relative', $post['dateline']); 2335 2336 if($post['username'] == "") 2337 { 2338 if($post['postusername'] != "") 2339 { 2340 $post['postusername'] = htmlspecialchars_uni($post['postusername']); 2341 $profile_link = $post['postusername']; 2342 } 2343 else 2344 { 2345 $profile_link = $lang->guest; 2346 } 2347 } 2348 else 2349 { 2350 $post['username'] = htmlspecialchars_uni($post['username']); 2351 $profile_link = build_profile_link($post['username'], $post['uid']); 2352 } 2353 2354 eval("\$thread = \"".$templates->get("modcp_modqueue_link_thread")."\";"); 2355 eval("\$forum = \"".$templates->get("modcp_modqueue_link_forum")."\";"); 2356 $post['message'] = nl2br(htmlspecialchars_uni($post['message'])); 2357 eval("\$posts .= \"".$templates->get("modcp_modqueue_posts_post")."\";"); 2358 } 2359 2360 if(!$posts && $mybb->input['type'] == "posts") 2361 { 2362 eval("\$posts = \"".$templates->get("modcp_modqueue_posts_empty")."\";"); 2363 } 2364 2365 if($posts) 2366 { 2367 add_breadcrumb($lang->mcp_nav_modqueue_posts, "modcp.php?action=modqueue&type=posts"); 2368 2369 $plugins->run_hooks("modcp_modqueue_posts_end"); 2370 2371 if($nummodqueuethreads > 0 || $mybb->usergroup['issupermod'] == 1) 2372 { 2373 $navsep = " | "; 2374 eval("\$thread_link = \"".$templates->get("modcp_modqueue_thread_link")."\";"); 2375 } 2376 2377 if($mybb->settings['enableattachments'] == 1 && ($nummodqueueattach > 0 || $mybb->usergroup['issupermod'] == 1)) 2378 { 2379 $navsep = " | "; 2380 eval("\$attachment_link = \"".$templates->get("modcp_modqueue_attachment_link")."\";"); 2381 } 2382 2383 eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";"); 2384 eval("\$postqueue = \"".$templates->get("modcp_modqueue_posts")."\";"); 2385 output_page($postqueue); 2386 } 2387 } 2388 2389 if($mybb->input['type'] == "attachments" || (!$mybb->input['type'] && !$postqueue && !$threadqueue && $mybb->settings['enableattachments'] == 1 && ($nummodqueueattach > 0 || $mybb->usergroup['issupermod'] == 1))) 2390 { 2391 if($mybb->settings['enableattachments'] == 0) 2392 { 2393 error($lang->attachments_disabled); 2394 } 2395 2396 if($nummodqueueattach == 0 && $mybb->usergroup['issupermod'] != 1) 2397 { 2398 error($lang->you_cannot_moderate_attachments); 2399 } 2400 2401 $query = $db->query(" 2402 SELECT COUNT(aid) AS unapprovedattachments 2403 FROM ".TABLE_PREFIX."attachments a 2404 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid) 2405 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 2406 WHERE a.visible='0'{$tflist_queue_attach} 2407 "); 2408 $unapproved_attachments = $db->fetch_field($query, "unapprovedattachments"); 2409 2410 // Figure out if we need to display multiple pages. 2411 if($mybb->get_input('page') != "last") 2412 { 2413 $page = $mybb->get_input('page', MyBB::INPUT_INT); 2414 } 2415 2416 $perpage = $mybb->settings['postsperpage']; 2417 $pages = $unapproved_attachments / $perpage; 2418 $pages = ceil($pages); 2419 2420 if($mybb->get_input('page') == "last") 2421 { 2422 $page = $pages; 2423 } 2424 2425 if($page > $pages || $page <= 0) 2426 { 2427 $page = 1; 2428 } 2429 2430 if($page) 2431 { 2432 $start = ($page-1) * $perpage; 2433 } 2434 else 2435 { 2436 $start = 0; 2437 $page = 1; 2438 } 2439 2440 $multipage = multipage($unapproved_attachments, $perpage, $page, "modcp.php?action=modqueue&type=attachments"); 2441 2442 $query = $db->query(" 2443 SELECT a.*, p.subject AS postsubject, p.dateline, p.uid, u.username, t.tid, t.subject AS threadsubject 2444 FROM ".TABLE_PREFIX."attachments a 2445 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid) 2446 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 2447 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid) 2448 WHERE a.visible='0'{$tflist_queue_attach} 2449 ORDER BY a.dateuploaded DESC 2450 LIMIT {$start}, {$perpage} 2451 "); 2452 $attachments = ''; 2453 while($attachment = $db->fetch_array($query)) 2454 { 2455 $altbg = alt_trow(); 2456 2457 if(!$attachment['dateuploaded']) 2458 { 2459 $attachment['dateuploaded'] = $attachment['dateline']; 2460 } 2461 2462 $attachdate = my_date('relative', $attachment['dateuploaded']); 2463 2464 $attachment['postsubject'] = htmlspecialchars_uni($parser->parse_badwords($attachment['postsubject'])); 2465 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 2466 $attachment['threadsubject'] = htmlspecialchars_uni($parser->parse_badwords($attachment['threadsubject'])); 2467 $attachment['filesize'] = get_friendly_size($attachment['filesize']); 2468 2469 $link = get_post_link($attachment['pid'], $attachment['tid']) . "#pid{$attachment['pid']}"; 2470 $thread_link = get_thread_link($attachment['tid']); 2471 $attachment['username'] = htmlspecialchars_uni($attachment['username']); 2472 $profile_link = build_profile_link($attachment['username'], $attachment['uid']); 2473 2474 eval("\$attachments .= \"".$templates->get("modcp_modqueue_attachments_attachment")."\";"); 2475 } 2476 2477 if(!$attachments && $mybb->input['type'] == "attachments") 2478 { 2479 eval("\$attachments = \"".$templates->get("modcp_modqueue_attachments_empty")."\";"); 2480 } 2481 2482 if($attachments) 2483 { 2484 add_breadcrumb($lang->mcp_nav_modqueue_attachments, "modcp.php?action=modqueue&type=attachments"); 2485 2486 $plugins->run_hooks("modcp_modqueue_attachments_end"); 2487 2488 if($nummodqueuethreads > 0 || $mybb->usergroup['issupermod'] == 1) 2489 { 2490 eval("\$thread_link = \"".$templates->get("modcp_modqueue_thread_link")."\";"); 2491 $navsep = " | "; 2492 } 2493 2494 if($nummodqueueposts > 0 || $mybb->usergroup['issupermod'] == 1) 2495 { 2496 eval("\$post_link = \"".$templates->get("modcp_modqueue_post_link")."\";"); 2497 $navsep = " | "; 2498 } 2499 2500 eval("\$mass_controls = \"".$templates->get("modcp_modqueue_masscontrols")."\";"); 2501 eval("\$attachmentqueue = \"".$templates->get("modcp_modqueue_attachments")."\";"); 2502 output_page($attachmentqueue); 2503 } 2504 } 2505 2506 // Still nothing? All queues are empty! :-D 2507 if(!$threadqueue && !$postqueue && !$attachmentqueue) 2508 { 2509 add_breadcrumb($lang->mcp_nav_modqueue, "modcp.php?action=modqueue"); 2510 2511 $plugins->run_hooks("modcp_modqueue_end"); 2512 2513 eval("\$queue = \"".$templates->get("modcp_modqueue_empty")."\";"); 2514 output_page($queue); 2515 } 2516 } 2517 2518 if($mybb->input['action'] == "do_editprofile") 2519 { 2520 // Verify incoming POST request 2521 verify_post_check($mybb->get_input('my_post_key')); 2522 2523 if($mybb->usergroup['caneditprofiles'] == 0) 2524 { 2525 error_no_permission(); 2526 } 2527 2528 $user = get_user($mybb->input['uid']); 2529 if(!$user) 2530 { 2531 error($lang->error_nomember); 2532 } 2533 2534 // Check if the current user has permission to edit this user 2535 if(!modcp_can_manage_user($user['uid'])) 2536 { 2537 error_no_permission(); 2538 } 2539 2540 $plugins->run_hooks("modcp_do_editprofile_start"); 2541 2542 if($mybb->get_input('away', MyBB::INPUT_INT) == 1 && $mybb->settings['allowaway'] != 0) 2543 { 2544 $awaydate = TIME_NOW; 2545 if(!empty($mybb->input['awayday'])) 2546 { 2547 // If the user has indicated that they will return on a specific day, but not month or year, assume it is current month and year 2548 if(!$mybb->get_input('awaymonth', MyBB::INPUT_INT)) 2549 { 2550 $mybb->input['awaymonth'] = my_date('n', $awaydate); 2551 } 2552 if(!$mybb->get_input('awayyear', MyBB::INPUT_INT)) 2553 { 2554 $mybb->input['awayyear'] = my_date('Y', $awaydate); 2555 } 2556 2557 $return_month = (int)substr($mybb->get_input('awaymonth'), 0, 2); 2558 $return_day = (int)substr($mybb->get_input('awayday'), 0, 2); 2559 $return_year = min((int)$mybb->get_input('awayyear'), 9999); 2560 2561 // Check if return date is after the away date. 2562 $returntimestamp = gmmktime(0, 0, 0, $return_month, $return_day, $return_year); 2563 $awaytimestamp = gmmktime(0, 0, 0, my_date('n', $awaydate), my_date('j', $awaydate), my_date('Y', $awaydate)); 2564 if($return_year < my_date('Y', $awaydate) || ($returntimestamp < $awaytimestamp && $return_year == my_date('Y', $awaydate))) 2565 { 2566 error($lang->error_modcp_return_date_past); 2567 } 2568 2569 $returndate = "{$return_day}-{$return_month}-{$return_year}"; 2570 } 2571 else 2572 { 2573 $returndate = ""; 2574 } 2575 $away = array( 2576 "away" => 1, 2577 "date" => $awaydate, 2578 "returndate" => $returndate, 2579 "awayreason" => $mybb->get_input('awayreason') 2580 ); 2581 } 2582 else 2583 { 2584 $away = array( 2585 "away" => 0, 2586 "date" => '', 2587 "returndate" => '', 2588 "awayreason" => '' 2589 ); 2590 } 2591 2592 // Set up user handler. 2593 require_once MYBB_ROOT."inc/datahandlers/user.php"; 2594 $userhandler = new UserDataHandler('update'); 2595 2596 // Set the data for the new user. 2597 $updated_user = array( 2598 "uid" => $user['uid'], 2599 "profile_fields" => $mybb->get_input('profile_fields', MyBB::INPUT_ARRAY), 2600 "profile_fields_editable" => true, 2601 "website" => $mybb->get_input('website'), 2602 "signature" => $mybb->get_input('signature'), 2603 "usernotes" => $mybb->get_input('usernotes'), 2604 "away" => $away 2605 ); 2606 2607 $updated_user['birthday'] = array( 2608 "day" => $mybb->get_input('birthday_day', MyBB::INPUT_INT), 2609 "month" => $mybb->get_input('birthday_month', MyBB::INPUT_INT), 2610 "year" => $mybb->get_input('birthday_year', MyBB::INPUT_INT) 2611 ); 2612 2613 if(!empty($mybb->input['usertitle'])) 2614 { 2615 $updated_user['usertitle'] = $mybb->get_input('usertitle'); 2616 } 2617 else if(!empty($mybb->input['reverttitle'])) 2618 { 2619 $updated_user['usertitle'] = ''; 2620 } 2621 2622 if(!empty($mybb->input['remove_avatar'])) 2623 { 2624 $updated_user['avatarurl'] = ''; 2625 } 2626 2627 // Set the data of the user in the datahandler. 2628 $userhandler->set_data($updated_user); 2629 $errors = array(); 2630 2631 // Validate the user and get any errors that might have occurred. 2632 if(!$userhandler->validate_user()) 2633 { 2634 $errors = $userhandler->get_friendly_errors(); 2635 $mybb->input['action'] = "editprofile"; 2636 } 2637 else 2638 { 2639 // Are we removing an avatar from this user? 2640 if(!empty($mybb->input['remove_avatar'])) 2641 { 2642 $extra_user_updates = array( 2643 "avatar" => "", 2644 "avatardimensions" => "", 2645 "avatartype" => "" 2646 ); 2647 remove_avatars($user['uid']); 2648 } 2649 2650 // Moderator "Options" (suspend signature, suspend/moderate posting) 2651 $moderator_options = array( 2652 1 => array( 2653 "action" => "suspendsignature", // The moderator action we're performing 2654 "period" => "action_period", // The time period we've selected from the dropdown box 2655 "time" => "action_time", // The time we've entered 2656 "update_field" => "suspendsignature", // The field in the database to update if true 2657 "update_length" => "suspendsigtime" // The length of suspension field in the database 2658 ), 2659 2 => array( 2660 "action" => "moderateposting", 2661 "period" => "modpost_period", 2662 "time" => "modpost_time", 2663 "update_field" => "moderateposts", 2664 "update_length" => "moderationtime" 2665 ), 2666 3 => array( 2667 "action" => "suspendposting", 2668 "period" => "suspost_period", 2669 "time" => "suspost_time", 2670 "update_field" => "suspendposting", 2671 "update_length" => "suspensiontime" 2672 ) 2673 ); 2674 2675 require_once MYBB_ROOT."inc/functions_warnings.php"; 2676 foreach($moderator_options as $option) 2677 { 2678 ${$option['time']} = $mybb->get_input($option['time'], MyBB::INPUT_INT); 2679 $mybb->input[$option['period']] = $mybb->get_input($option['period']); 2680 if(empty($mybb->input[$option['action']])) 2681 { 2682 if($user[$option['update_field']] == 1) 2683 { 2684 // We're revoking the suspension 2685 $extra_user_updates[$option['update_field']] = 0; 2686 $extra_user_updates[$option['update_length']] = 0; 2687 } 2688 2689 // Skip this option if we haven't selected it 2690 continue; 2691 } 2692 2693 else 2694 { 2695 if($mybb->input[$option['time']] == 0 && $mybb->input[$option['period']] != "never" && $user[$option['update_field']] != 1) 2696 { 2697 // User has selected a type of ban, but not entered a valid time frame 2698 $string = $option['action']."_error"; 2699 $errors[] = $lang->$string; 2700 } 2701 else 2702 { 2703 $suspend_length = fetch_time_length((int)$mybb->input[$option['time']], $mybb->input[$option['period']]); 2704 2705 if($user[$option['update_field']] == 1 && ($mybb->input[$option['time']] || $mybb->input[$option['period']] == "never")) 2706 { 2707 // We already have a suspension, but entered a new time 2708 if($suspend_length == "-1") 2709 { 2710 // Permanent ban on action 2711 $extra_user_updates[$option['update_length']] = 0; 2712 } 2713 elseif($suspend_length && $suspend_length != "-1") 2714 { 2715 // Temporary ban on action 2716 $extra_user_updates[$option['update_length']] = TIME_NOW + $suspend_length; 2717 } 2718 } 2719 elseif(!$user[$option['update_field']]) 2720 { 2721 // New suspension for this user... bad user! 2722 $extra_user_updates[$option['update_field']] = 1; 2723 if($suspend_length == "-1") 2724 { 2725 $extra_user_updates[$option['update_length']] = 0; 2726 } 2727 else 2728 { 2729 $extra_user_updates[$option['update_length']] = TIME_NOW + $suspend_length; 2730 } 2731 } 2732 } 2733 } 2734 } 2735 2736 // Those with javascript turned off will be able to select both - cheeky! 2737 // Check to make sure we're not moderating AND suspending posting 2738 if(isset($extra_user_updates) && !empty($extra_user_updates['moderateposts']) && !empty($extra_user_updates['suspendposting'])) 2739 { 2740 $errors[] = $lang->suspendmoderate_error; 2741 } 2742 2743 if(is_array($errors) && !empty($errors)) 2744 { 2745 $mybb->input['action'] = "editprofile"; 2746 } 2747 else 2748 { 2749 $plugins->run_hooks("modcp_do_editprofile_update"); 2750 2751 // Continue with the update if there is no errors 2752 $user_info = $userhandler->update_user(); 2753 if(!empty($extra_user_updates)) 2754 { 2755 $db->update_query("users", $extra_user_updates, "uid='{$user['uid']}'"); 2756 } 2757 log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->edited_user); 2758 2759 $plugins->run_hooks("modcp_do_editprofile_end"); 2760 2761 redirect("modcp.php?action=finduser", $lang->redirect_user_updated); 2762 } 2763 } 2764 } 2765 2766 if($mybb->input['action'] == "editprofile") 2767 { 2768 if($mybb->usergroup['caneditprofiles'] == 0) 2769 { 2770 error_no_permission(); 2771 } 2772 2773 add_breadcrumb($lang->mcp_nav_editprofile, "modcp.php?action=editprofile"); 2774 2775 $user = get_user($mybb->get_input('uid', MyBB::INPUT_INT)); 2776 if(!$user) 2777 { 2778 error($lang->error_nomember); 2779 } 2780 2781 // Check if the current user has permission to edit this user 2782 if(!modcp_can_manage_user($user['uid'])) 2783 { 2784 error_no_permission(); 2785 } 2786 2787 $userperms = user_permissions($user['uid']); 2788 2789 // Set display group 2790 $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image"); 2791 2792 if(!$user['displaygroup']) 2793 { 2794 $user['displaygroup'] = $user['usergroup']; 2795 } 2796 2797 $display_group = usergroup_displaygroup($user['displaygroup']); 2798 if(is_array($display_group)) 2799 { 2800 $userperms = array_merge($userperms, $display_group); 2801 } 2802 2803 if(!my_validate_url($user['website'])) 2804 { 2805 $user['website'] = ''; 2806 } 2807 2808 if(!$errors) 2809 { 2810 $mybb->input = array_merge($user, $mybb->input); 2811 $birthday = explode('-', $user['birthday']); 2812 if(!isset($birthday[1])) 2813 { 2814 $birthday[1] = ''; 2815 } 2816 if(!isset($birthday[2])) 2817 { 2818 $birthday[2] = ''; 2819 } 2820 list($mybb->input['birthday_day'], $mybb->input['birthday_month'], $mybb->input['birthday_year']) = $birthday; 2821 } 2822 else 2823 { 2824 $errors = inline_error($errors); 2825 } 2826 2827 // Sanitize all input 2828 foreach(array('usertitle', 'website', 'signature', 'birthday_day', 'birthday_month', 'birthday_year') as $field) 2829 { 2830 $mybb->input[$field] = htmlspecialchars_uni($mybb->get_input($field)); 2831 } 2832 2833 // Custom user title 2834 if(!empty($userperms['usertitle'])) 2835 { 2836 $defaulttitle = htmlspecialchars_uni($userperms['usertitle']); 2837 } 2838 else 2839 { 2840 // Go for post count title if a group default isn't set 2841 $usertitles = $cache->read('usertitles'); 2842 2843 foreach($usertitles as $title) 2844 { 2845 if($title['posts'] <= $user['postnum']) 2846 { 2847 $defaulttitle = htmlspecialchars_uni($title['title']); 2848 break; 2849 } 2850 } 2851 } 2852 2853 $user['usertitle'] = htmlspecialchars_uni($user['usertitle']); 2854 2855 if(empty($user['usertitle'])) 2856 { 2857 $lang->current_custom_usertitle = ''; 2858 } 2859 2860 $bdaydaysel = $selected = ''; 2861 for($day = 1; $day <= 31; ++$day) 2862 { 2863 if($mybb->input['birthday_day'] == $day) 2864 { 2865 $selected = "selected=\"selected\""; 2866 } 2867 else 2868 { 2869 $selected = ''; 2870 } 2871 2872 eval("\$bdaydaysel .= \"".$templates->get("usercp_profile_day")."\";"); 2873 } 2874 2875 $bdaymonthsel = array(); 2876 foreach(range(1, 12) as $month) 2877 { 2878 $bdaymonthsel[$month] = ''; 2879 } 2880 $bdaymonthsel[$mybb->input['birthday_month']] = 'selected="selected"'; 2881 2882 $awaysection = ''; 2883 2884 if($mybb->settings['allowaway'] != 0) 2885 { 2886 $awaycheck = array('', ''); 2887 if($errors) 2888 { 2889 if($user['away'] == 1) 2890 { 2891 $awaycheck[1] = "checked=\"checked\""; 2892 } 2893 else 2894 { 2895 $awaycheck[0] = "checked=\"checked\""; 2896 } 2897 $returndate = array(); 2898 $returndate[0] = $mybb->get_input('awayday'); 2899 $returndate[1] = $mybb->get_input('awaymonth'); 2900 $returndate[2] = $mybb->get_input('awayyear', MyBB::INPUT_INT); 2901 $user['awayreason'] = htmlspecialchars_uni($mybb->get_input('awayreason')); 2902 } 2903 else 2904 { 2905 $user['awayreason'] = htmlspecialchars_uni($user['awayreason']); 2906 if($user['away'] == 1) 2907 { 2908 $awaydate = my_date($mybb->settings['dateformat'], $user['awaydate']); 2909 $awaycheck[1] = "checked=\"checked\""; 2910 $awaynotice = $lang->sprintf($lang->away_notice_away, $awaydate); 2911 } 2912 else 2913 { 2914 $awaynotice = $lang->away_notice; 2915 $awaycheck[0] = "checked=\"checked\""; 2916 } 2917 $returndate = explode("-", $user['returndate']); 2918 } 2919 $returndatesel = $selected = ''; 2920 for($day = 1; $day <= 31; ++$day) 2921 { 2922 if($returndate[0] == $day) 2923 { 2924 $selected = "selected=\"selected\""; 2925 } 2926 else 2927 { 2928 $selected = ''; 2929 } 2930 2931 eval("\$returndatesel .= \"".$templates->get("usercp_profile_day")."\";"); 2932 } 2933 2934 $returndatemonthsel = array(); 2935 foreach(range(1, 12) as $month) 2936 { 2937 $returndatemonthsel[$month] = ''; 2938 } 2939 if(isset($returndate[1])) 2940 { 2941 $returndatemonthsel[$returndate[1]] = " selected=\"selected\""; 2942 } 2943 2944 if(!isset($returndate[2])) 2945 { 2946 $returndate[2] = ''; 2947 } 2948 2949 eval("\$awaysection = \"".$templates->get("usercp_profile_away")."\";"); 2950 } 2951 2952 $plugins->run_hooks("modcp_editprofile_start"); 2953 2954 // Fetch profile fields 2955 $user_fields = array(); 2956 $query = $db->simple_select("userfields", "*", "ufid='{$user['uid']}'"); 2957 if($db->num_rows($query) > 0) 2958 { 2959 $user_fields = $db->fetch_array($query); 2960 } 2961 2962 $requiredfields = ''; 2963 $customfields = ''; 2964 $mybb->input['profile_fields'] = $mybb->get_input('profile_fields', MyBB::INPUT_ARRAY); 2965 2966 $pfcache = $cache->read('profilefields'); 2967 2968 if(is_array($pfcache)) 2969 { 2970 foreach($pfcache as $profilefield) 2971 { 2972 $userfield = $code = $select = $val = $options = $expoptions = $useropts = ''; 2973 $seloptions = array(); 2974 $profilefield['type'] = htmlspecialchars_uni($profilefield['type']); 2975 $profilefield['name'] = htmlspecialchars_uni($profilefield['name']); 2976 $profilefield['description'] = htmlspecialchars_uni($profilefield['description']); 2977 $thing = explode("\n", $profilefield['type'], "2"); 2978 $type = $thing[0]; 2979 if(isset($thing[1])) 2980 { 2981 $options = $thing[1]; 2982 } 2983 $field = "fid{$profilefield['fid']}"; 2984 if($errors) 2985 { 2986 if(isset($mybb->input['profile_fields'][$field])) 2987 { 2988 $userfield = $mybb->input['profile_fields'][$field]; 2989 } 2990 } 2991 elseif(isset($user_fields[$field])) 2992 { 2993 $userfield = $user_fields[$field]; 2994 } 2995 if($type == "multiselect") 2996 { 2997 if($errors) 2998 { 2999 $useropts = $userfield; 3000 } 3001 else 3002 { 3003 $useropts = explode("\n", $userfield); 3004 } 3005 if(is_array($useropts)) 3006 { 3007 foreach($useropts as $key => $val) 3008 { 3009 $seloptions[$val] = $val; 3010 } 3011 } 3012 $expoptions = explode("\n", $options); 3013 if(is_array($expoptions)) 3014 { 3015 foreach($expoptions as $key => $val) 3016 { 3017 $val = trim($val); 3018 $val = str_replace("\n", "\\n", $val); 3019 3020 $sel = ""; 3021 if(isset($seloptions[$val]) && $val == $seloptions[$val]) 3022 { 3023 $sel = " selected=\"selected\""; 3024 } 3025 3026 eval("\$select .= \"".$templates->get("usercp_profile_profilefields_select_option")."\";"); 3027 } 3028 if(!$profilefield['length']) 3029 { 3030 $profilefield['length'] = 3; 3031 } 3032 3033 eval("\$code = \"".$templates->get("usercp_profile_profilefields_multiselect")."\";"); 3034 } 3035 } 3036 elseif($type == "select") 3037 { 3038 $expoptions = explode("\n", $options); 3039 if(is_array($expoptions)) 3040 { 3041 foreach($expoptions as $key => $val) 3042 { 3043 $val = trim($val); 3044 $val = str_replace("\n", "\\n", $val); 3045 $sel = ""; 3046 if($val == $userfield) 3047 { 3048 $sel = " selected=\"selected\""; 3049 } 3050 3051 eval("\$select .= \"".$templates->get("usercp_profile_profilefields_select_option")."\";"); 3052 } 3053 if(!$profilefield['length']) 3054 { 3055 $profilefield['length'] = 1; 3056 } 3057 3058 eval("\$code = \"".$templates->get("usercp_profile_profilefields_select")."\";"); 3059 } 3060 } 3061 elseif($type == "radio") 3062 { 3063 $expoptions = explode("\n", $options); 3064 if(is_array($expoptions)) 3065 { 3066 foreach($expoptions as $key => $val) 3067 { 3068 $checked = ""; 3069 if($val == $userfield) 3070 { 3071 $checked = " checked=\"checked\""; 3072 } 3073 3074 eval("\$code .= \"".$templates->get("usercp_profile_profilefields_radio")."\";"); 3075 } 3076 } 3077 } 3078 elseif($type == "checkbox") 3079 { 3080 if($errors) 3081 { 3082 $useropts = $userfield; 3083 } 3084 else 3085 { 3086 $useropts = explode("\n", $userfield); 3087 } 3088 if(is_array($useropts)) 3089 { 3090 foreach($useropts as $key => $val) 3091 { 3092 $seloptions[$val] = $val; 3093 } 3094 } 3095 $expoptions = explode("\n", $options); 3096 if(is_array($expoptions)) 3097 { 3098 foreach($expoptions as $key => $val) 3099 { 3100 $checked = ""; 3101 if(isset($seloptions[$val]) && $val == $seloptions[$val]) 3102 { 3103 $checked = " checked=\"checked\""; 3104 } 3105 3106 eval("\$code .= \"".$templates->get("usercp_profile_profilefields_checkbox")."\";"); 3107 } 3108 } 3109 } 3110 elseif($type == "textarea") 3111 { 3112 $value = htmlspecialchars_uni($userfield); 3113 eval("\$code = \"".$templates->get("usercp_profile_profilefields_textarea")."\";"); 3114 } 3115 else 3116 { 3117 $value = htmlspecialchars_uni($userfield); 3118 $maxlength = ""; 3119 if($profilefield['maxlength'] > 0) 3120 { 3121 $maxlength = " maxlength=\"{$profilefield['maxlength']}\""; 3122 } 3123 3124 eval("\$code = \"".$templates->get("usercp_profile_profilefields_text")."\";"); 3125 } 3126 3127 if($profilefield['required'] == 1) 3128 { 3129 eval("\$requiredfields .= \"".$templates->get("usercp_profile_customfield")."\";"); 3130 } 3131 else 3132 { 3133 eval("\$customfields .= \"".$templates->get("usercp_profile_customfield")."\";"); 3134 } 3135 $altbg = alt_trow(); 3136 } 3137 } 3138 if($customfields) 3139 { 3140 eval("\$customfields = \"".$templates->get("usercp_profile_profilefields")."\";"); 3141 } 3142 3143 $user['username'] = htmlspecialchars_uni($user['username']); 3144 $lang->edit_profile = $lang->sprintf($lang->edit_profile, $user['username']); 3145 $profile_link = build_profile_link(format_name($user['username'], $user['usergroup'], $user['displaygroup']), $user['uid']); 3146 3147 $user['signature'] = htmlspecialchars_uni($user['signature']); 3148 $codebuttons = build_mycode_inserter("signature"); 3149 3150 // Do we mark the suspend signature box? 3151 if($user['suspendsignature'] || ($mybb->get_input('suspendsignature', MyBB::INPUT_INT) && !empty($errors))) 3152 { 3153 $checked = 1; 3154 $checked_item = "checked=\"checked\""; 3155 } 3156 else 3157 { 3158 $checked = 0; 3159 $checked_item = ''; 3160 } 3161 3162 // Do we mark the moderate posts box? 3163 if($user['moderateposts'] || ($mybb->get_input('moderateposting', MyBB::INPUT_INT) && !empty($errors))) 3164 { 3165 $modpost_check = 1; 3166 $modpost_checked = "checked=\"checked\""; 3167 } 3168 else 3169 { 3170 $modpost_check = 0; 3171 $modpost_checked = ''; 3172 } 3173 3174 // Do we mark the suspend posts box? 3175 if($user['suspendposting'] || ($mybb->get_input('suspendposting', MyBB::INPUT_INT) && !empty($errors))) 3176 { 3177 $suspost_check = 1; 3178 $suspost_checked = "checked=\"checked\""; 3179 } 3180 else 3181 { 3182 $suspost_check = 0; 3183 $suspost_checked = ''; 3184 } 3185 3186 $moderator_options = array( 3187 1 => array( 3188 "action" => "suspendsignature", // The input action for this option 3189 "option" => "suspendsignature", // The field in the database that this option relates to 3190 "time" => "action_time", // The time we've entered 3191 "length" => "suspendsigtime", // The length of suspension field in the database 3192 "select_option" => "action" // The name of the select box of this option 3193 ), 3194 2 => array( 3195 "action" => "moderateposting", 3196 "option" => "moderateposts", 3197 "time" => "modpost_time", 3198 "length" => "moderationtime", 3199 "select_option" => "modpost" 3200 ), 3201 3 => array( 3202 "action" => "suspendposting", 3203 "option" => "suspendposting", 3204 "time" => "suspost_time", 3205 "length" => "suspensiontime", 3206 "select_option" => "suspost" 3207 ) 3208 ); 3209 3210 $periods = array( 3211 "hours" => $lang->expire_hours, 3212 "days" => $lang->expire_days, 3213 "weeks" => $lang->expire_weeks, 3214 "months" => $lang->expire_months, 3215 "never" => $lang->expire_permanent 3216 ); 3217 3218 $suspendsignature_info = $moderateposts_info = $suspendposting_info = ''; 3219 $action_options = $modpost_options = $suspost_options = ''; 3220 $modopts = array(); 3221 foreach($moderator_options as $option) 3222 { 3223 ${$option['time']} = $mybb->get_input($option['time'], MyBB::INPUT_INT); 3224 // Display the suspension info, if this user has this option suspended 3225 if($user[$option['option']]) 3226 { 3227 if($user[$option['length']] == 0) 3228 { 3229 // User has a permanent ban 3230 $string = $option['option']."_perm"; 3231 $suspension_info = $lang->$string; 3232 } 3233 else 3234 { 3235 // User has a temporary (or limited) ban 3236 $string = $option['option']."_for"; 3237 $for_date = my_date('relative', $user[$option['length']], '', 2); 3238 $suspension_info = $lang->sprintf($lang->$string, $for_date); 3239 } 3240 3241 switch($option['option']) 3242 { 3243 case "suspendsignature": 3244 eval("\$suspendsignature_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";"); 3245 break; 3246 case "moderateposts": 3247 eval("\$moderateposts_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";"); 3248 break; 3249 case "suspendposting": 3250 eval("\$suspendposting_info = \"".$templates->get("modcp_editprofile_suspensions_info")."\";"); 3251 break; 3252 } 3253 } 3254 3255 // Generate the boxes for this option 3256 $selection_options = ''; 3257 foreach($periods as $key => $value) 3258 { 3259 $string = $option['select_option']."_period"; 3260 if($mybb->get_input($string) == $key) 3261 { 3262 $selected = "selected=\"selected\""; 3263 } 3264 else 3265 { 3266 $selected = ''; 3267 } 3268 3269 eval("\$selection_options .= \"".$templates->get("modcp_editprofile_select_option")."\";"); 3270 } 3271 3272 $select_name = $option['select_option']."_period"; 3273 switch($option['option']) 3274 { 3275 case "suspendsignature": 3276 eval("\$action_options = \"".$templates->get("modcp_editprofile_select")."\";"); 3277 break; 3278 case "moderateposts": 3279 eval("\$modpost_options = \"".$templates->get("modcp_editprofile_select")."\";"); 3280 break; 3281 case "suspendposting": 3282 eval("\$suspost_options = \"".$templates->get("modcp_editprofile_select")."\";"); 3283 break; 3284 } 3285 } 3286 3287 eval("\$suspend_signature = \"".$templates->get("modcp_editprofile_signature")."\";"); 3288 3289 $user['usernotes'] = htmlspecialchars_uni($user['usernotes']); 3290 3291 if(!isset($newtitle)) 3292 { 3293 $newtitle = ''; 3294 } 3295 3296 $birthday_year = $mybb->input['birthday_year']; 3297 $user_website = $mybb->input['website']; 3298 3299 $plugins->run_hooks("modcp_editprofile_end"); 3300 3301 eval("\$edituser = \"".$templates->get("modcp_editprofile")."\";"); 3302 output_page($edituser); 3303 } 3304 3305 if($mybb->input['action'] == "finduser") 3306 { 3307 if($mybb->usergroup['caneditprofiles'] == 0) 3308 { 3309 error_no_permission(); 3310 } 3311 3312 add_breadcrumb($lang->mcp_nav_users, "modcp.php?action=finduser"); 3313 3314 $perpage = $mybb->get_input('perpage', MyBB::INPUT_INT); 3315 if(!$perpage || $perpage <= 0) 3316 { 3317 $perpage = $mybb->settings['threadsperpage']; 3318 } 3319 $where = ''; 3320 3321 if(isset($mybb->input['username'])) 3322 { 3323 switch($db->type) 3324 { 3325 case 'mysql': 3326 case 'mysqli': 3327 $field = 'username'; 3328 break; 3329 default: 3330 $field = 'LOWER(username)'; 3331 break; 3332 } 3333 $where = " AND {$field} LIKE '%".my_strtolower($db->escape_string_like($mybb->get_input('username')))."%'"; 3334 } 3335 3336 // Sort order & direction 3337 switch($mybb->get_input('sortby')) 3338 { 3339 case "lastvisit": 3340 $sortby = "lastvisit"; 3341 break; 3342 case "postnum": 3343 $sortby = "postnum"; 3344 break; 3345 case "username": 3346 $sortby = "username"; 3347 break; 3348 default: 3349 $sortby = "regdate"; 3350 } 3351 $sortbysel = array('lastvisit' => '', 'postnum' => '', 'username' => '', 'regdate' => ''); 3352 $sortbysel[$mybb->get_input('sortby')] = " selected=\"selected\""; 3353 $order = $mybb->get_input('order'); 3354 if($order != "asc") 3355 { 3356 $order = "desc"; 3357 } 3358 $ordersel = array('asc' => '', 'desc' => ''); 3359 $ordersel[$order] = " selected=\"selected\""; 3360 3361 $query = $db->simple_select("users", "COUNT(uid) AS count", "1=1 {$where}"); 3362 $user_count = $db->fetch_field($query, "count"); 3363 3364 // Figure out if we need to display multiple pages. 3365 if($mybb->get_input('page') != "last") 3366 { 3367 $page = $mybb->get_input('page'); 3368 } 3369 3370 $pages = $user_count / $perpage; 3371 $pages = ceil($pages); 3372 3373 if($mybb->get_input('page') == "last") 3374 { 3375 $page = $pages; 3376 } 3377 3378 if($page > $pages || $page <= 0) 3379 { 3380 $page = 1; 3381 } 3382 if($page) 3383 { 3384 $start = ($page-1) * $perpage; 3385 } 3386 else 3387 { 3388 $start = 0; 3389 $page = 1; 3390 } 3391 3392 $page_url = 'modcp.php?action=finduser'; 3393 foreach(array('username', 'sortby', 'order') as $field) 3394 { 3395 if(!empty($mybb->input[$field])) 3396 { 3397 $page_url .= "&{$field}=".$mybb->input[$field]; 3398 } 3399 } 3400 3401 $multipage = multipage($user_count, $perpage, $page, $page_url); 3402 3403 $usergroups_cache = $cache->read("usergroups"); 3404 3405 $plugins->run_hooks("modcp_finduser_start"); 3406 3407 // Fetch out results 3408 $query = $db->simple_select("users", "*", "1=1 {$where}", array("order_by" => $sortby, "order_dir" => $order, "limit" => $perpage, "limit_start" => $start)); 3409 $users = ''; 3410 while($user = $db->fetch_array($query)) 3411 { 3412 $alt_row = alt_trow(); 3413 $user['username'] = htmlspecialchars_uni($user['username']); 3414 $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']); 3415 $user['postnum'] = my_number_format($user['postnum']); 3416 $regdate = my_date('relative', $user['regdate']); 3417 3418 if($user['invisible'] == 1 && $mybb->usergroup['canviewwolinvis'] != 1 && $user['uid'] != $mybb->user['uid']) 3419 { 3420 // We have had at least some active time, hide it instead 3421 $lastdate = $lang->lastvisit_hidden; 3422 } 3423 else if($user['lastvisit']) 3424 { 3425 $lastdate = my_date('relative', $user['lastvisit']); 3426 } 3427 else 3428 { 3429 $lastdate = $lang->lastvisit_never; 3430 } 3431 3432 $usergroup = htmlspecialchars_uni($usergroups_cache[$user['usergroup']]['title']); 3433 eval("\$users .= \"".$templates->get("modcp_finduser_user")."\";"); 3434 } 3435 3436 // No results? 3437 if(!$users) 3438 { 3439 eval("\$users = \"".$templates->get("modcp_finduser_noresults")."\";"); 3440 } 3441 3442 $plugins->run_hooks("modcp_finduser_end"); 3443 3444 $username = htmlspecialchars_uni($mybb->get_input('username')); 3445 eval("\$finduser = \"".$templates->get("modcp_finduser")."\";"); 3446 output_page($finduser); 3447 } 3448 3449 if($mybb->input['action'] == "warninglogs") 3450 { 3451 if($mybb->usergroup['canviewwarnlogs'] == 0) 3452 { 3453 error_no_permission(); 3454 } 3455 3456 add_breadcrumb($lang->mcp_nav_warninglogs, "modcp.php?action=warninglogs"); 3457 3458 // Filter options 3459 $where_sql = ''; 3460 $mybb->input['filter'] = $mybb->get_input('filter', MyBB::INPUT_ARRAY); 3461 $mybb->input['search'] = $mybb->get_input('search', MyBB::INPUT_ARRAY); 3462 if(!empty($mybb->input['filter']['username'])) 3463 { 3464 $search_user = get_user_by_username($mybb->input['filter']['username']); 3465 3466 $mybb->input['filter']['uid'] = (int)$search_user['uid']; 3467 $mybb->input['filter']['username'] = htmlspecialchars_uni($mybb->input['filter']['username']); 3468 } 3469 else 3470 { 3471 $mybb->input['filter']['username'] = ''; 3472 } 3473 if(!empty($mybb->input['filter']['uid'])) 3474 { 3475 $search['uid'] = (int)$mybb->input['filter']['uid']; 3476 $where_sql .= " AND w.uid='{$search['uid']}'"; 3477 if(!isset($mybb->input['search']['username'])) 3478 { 3479 $user = get_user($mybb->input['search']['uid']); 3480 $mybb->input['search']['username'] = htmlspecialchars_uni($user['username']); 3481 } 3482 } 3483 else 3484 { 3485 $mybb->input['filter']['uid'] = ''; 3486 } 3487 if(!empty($mybb->input['filter']['mod_username'])) 3488 { 3489 $mod_user = get_user_by_username($mybb->input['filter']['mod_username']); 3490 3491 $mybb->input['filter']['mod_uid'] = (int)$mod_user['uid']; 3492 $mybb->input['filter']['mod_username'] = htmlspecialchars_uni($mybb->input['filter']['mod_username']); 3493 } 3494 else 3495 { 3496 $mybb->input['filter']['mod_username'] = ''; 3497 } 3498 if(!empty($mybb->input['filter']['mod_uid'])) 3499 { 3500 $search['mod_uid'] = (int)$mybb->input['filter']['mod_uid']; 3501 $where_sql .= " AND w.issuedby='{$search['mod_uid']}'"; 3502 if(!isset($mybb->input['search']['mod_username'])) 3503 { 3504 $mod_user = get_user($mybb->input['search']['uid']); 3505 $mybb->input['search']['mod_username'] = htmlspecialchars_uni($mod_user['username']); 3506 } 3507 } 3508 else 3509 { 3510 $mybb->input['filter']['mod_uid'] = ''; 3511 } 3512 if(!empty($mybb->input['filter']['reason'])) 3513 { 3514 $search['reason'] = $db->escape_string_like($mybb->input['filter']['reason']); 3515 $where_sql .= " AND (w.notes LIKE '%{$search['reason']}%' OR t.title LIKE '%{$search['reason']}%' OR w.title LIKE '%{$search['reason']}%')"; 3516 $mybb->input['filter']['reason'] = htmlspecialchars_uni($mybb->input['filter']['reason']); 3517 } 3518 else 3519 { 3520 $mybb->input['filter']['reason'] = ''; 3521 } 3522 $sortbysel = array('username' => '', 'expires' => '', 'issuedby' => '', 'dateline' => ''); 3523 if(!isset($mybb->input['filter']['sortby'])) 3524 { 3525 $mybb->input['filter']['sortby'] = ''; 3526 } 3527 switch($mybb->input['filter']['sortby']) 3528 { 3529 case "username": 3530 $sortby = "u.username"; 3531 $sortbysel['username'] = ' selected="selected"'; 3532 break; 3533 case "expires": 3534 $sortby = "w.expires"; 3535 $sortbysel['expires'] = ' selected="selected"'; 3536 break; 3537 case "issuedby": 3538 $sortby = "i.username"; 3539 $sortbysel['issuedby'] = ' selected="selected"'; 3540 break; 3541 default: // "dateline" 3542 $sortby = "w.dateline"; 3543 $sortbysel['dateline'] = ' selected="selected"'; 3544 } 3545 if(!isset($mybb->input['filter']['order'])) 3546 { 3547 $mybb->input['filter']['order'] = ''; 3548 } 3549 $order = $mybb->input['filter']['order']; 3550 $ordersel = array('asc' => '', 'desc' => ''); 3551 if($order != "asc") 3552 { 3553 $order = "desc"; 3554 $ordersel['desc'] = ' selected="selected"'; 3555 } 3556 else 3557 { 3558 $ordersel['asc'] = ' selected="selected"'; 3559 } 3560 3561 $plugins->run_hooks("modcp_warninglogs_start"); 3562 3563 // Pagination stuff 3564 $sql = " 3565 SELECT COUNT(wid) as count 3566 FROM 3567 ".TABLE_PREFIX."warnings w 3568 LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid) 3569 WHERE 1=1 3570 {$where_sql} 3571 "; 3572 $query = $db->query($sql); 3573 $total_warnings = $db->fetch_field($query, 'count'); 3574 $page = $mybb->get_input('page', MyBB::INPUT_INT); 3575 if($page <= 0) 3576 { 3577 $page = 1; 3578 } 3579 $per_page = 20; 3580 if(isset($mybb->input['filter']['per_page']) && (int)$mybb->input['filter']['per_page'] > 0) 3581 { 3582 $per_page = (int)$mybb->input['filter']['per_page']; 3583 } 3584 $start = ($page-1) * $per_page; 3585 $pages = ceil($total_warnings / $per_page); 3586 if($page > $pages) 3587 { 3588 $start = 0; 3589 $page = 1; 3590 } 3591 // Build the base URL for pagination links 3592 $url = 'modcp.php?action=warninglogs'; 3593 if(is_array($mybb->input['filter']) && count($mybb->input['filter'])) 3594 { 3595 foreach($mybb->input['filter'] as $field => $value) 3596 { 3597 $value = urlencode($value); 3598 $url .= "&filter[{$field}]={$value}"; 3599 } 3600 } 3601 $multipage = multipage($total_warnings, $per_page, $page, $url); 3602 3603 // The actual query 3604 $sql = " 3605 SELECT 3606 w.wid, w.title as custom_title, w.points, w.dateline, w.issuedby, w.expires, w.expired, w.daterevoked, w.revokedby, 3607 t.title, 3608 u.uid, u.username, u.usergroup, u.displaygroup, 3609 i.uid as mod_uid, i.username as mod_username, i.usergroup as mod_usergroup, i.displaygroup as mod_displaygroup 3610 FROM ".TABLE_PREFIX."warnings w 3611 LEFT JOIN ".TABLE_PREFIX."users u ON (w.uid=u.uid) 3612 LEFT JOIN ".TABLE_PREFIX."warningtypes t ON (w.tid=t.tid) 3613 LEFT JOIN ".TABLE_PREFIX."users i ON (i.uid=w.issuedby) 3614 WHERE 1=1 3615 {$where_sql} 3616 ORDER BY {$sortby} {$order} 3617 LIMIT {$start}, {$per_page} 3618 "; 3619 $query = $db->query($sql); 3620 3621 3622 $warning_list = ''; 3623 while($row = $db->fetch_array($query)) 3624 { 3625 $trow = alt_trow(); 3626 $row['username'] = htmlspecialchars_uni($row['username']); 3627 $username = format_name($row['username'], $row['usergroup'], $row['displaygroup']); 3628 $username_link = build_profile_link($username, $row['uid']); 3629 $row['mod_username'] = htmlspecialchars_uni($row['mod_username']); 3630 $mod_username = format_name($row['mod_username'], $row['mod_usergroup'], $row['mod_displaygroup']); 3631 $mod_username_link = build_profile_link($mod_username, $row['mod_uid']); 3632 $issued_date = my_date('normal', $row['dateline']); 3633 $revoked_text = ''; 3634 if($row['daterevoked'] > 0) 3635 { 3636 $revoked_date = my_date('relative', $row['daterevoked']); 3637 eval("\$revoked_text = \"".$templates->get("modcp_warninglogs_warning_revoked")."\";"); 3638 } 3639 if($row['expires'] > 0) 3640 { 3641 $expire_date = nice_time($row['expires']-TIME_NOW); 3642 } 3643 else 3644 { 3645 $expire_date = $lang->never; 3646 } 3647 $title = $row['title']; 3648 if(empty($row['title'])) 3649 { 3650 $title = $row['custom_title']; 3651 } 3652 $title = htmlspecialchars_uni($title); 3653 if($row['points'] >= 0) 3654 { 3655 $points = '+'.$row['points']; 3656 } 3657 3658 eval("\$warning_list .= \"".$templates->get("modcp_warninglogs_warning")."\";"); 3659 } 3660 3661 if(!$warning_list) 3662 { 3663 eval("\$warning_list = \"".$templates->get("modcp_warninglogs_nologs")."\";"); 3664 } 3665 3666 $plugins->run_hooks("modcp_warninglogs_end"); 3667 3668 $filter_username = $mybb->input['filter']['username']; 3669 $filter_modusername = $mybb->input['filter']['mod_username']; 3670 $filter_reason = $mybb->input['filter']['reason']; 3671 3672 eval("\$warninglogs = \"".$templates->get("modcp_warninglogs")."\";"); 3673 output_page($warninglogs); 3674 } 3675 3676 if($mybb->input['action'] == "ipsearch") 3677 { 3678 if($mybb->usergroup['canuseipsearch'] == 0) 3679 { 3680 error_no_permission(); 3681 } 3682 3683 add_breadcrumb($lang->mcp_nav_ipsearch, "modcp.php?action=ipsearch"); 3684 3685 $ipsearch_results = $ipaddressvalue = ''; 3686 $mybb->input['ipaddress'] = $mybb->get_input('ipaddress'); 3687 if($mybb->input['ipaddress']) 3688 { 3689 if(!is_array($groupscache)) 3690 { 3691 $groupscache = $cache->read("usergroups"); 3692 } 3693 3694 $ipaddressvalue = htmlspecialchars_uni($mybb->input['ipaddress']); 3695 3696 $ip_range = fetch_ip_range($mybb->input['ipaddress']); 3697 3698 $post_results = $user_results = 0; 3699 3700 // Searching post IP addresses 3701 if(isset($mybb->input['search_posts'])) 3702 { 3703 $post_ip_sql = ''; 3704 if($ip_range) 3705 { 3706 if(!is_array($ip_range)) 3707 { 3708 $post_ip_sql = "p.ipaddress=".$db->escape_binary($ip_range); 3709 } 3710 else 3711 { 3712 $post_ip_sql = "p.ipaddress BETWEEN ".$db->escape_binary($ip_range[0])." AND ".$db->escape_binary($ip_range[1]); 3713 } 3714 } 3715 3716 $plugins->run_hooks("modcp_ipsearch_posts_start"); 3717 3718 if($post_ip_sql) 3719 { 3720 $where_sql = ''; 3721 3722 $unviewable_forums = get_unviewable_forums(true); 3723 3724 if($unviewable_forums) 3725 { 3726 $where_sql .= " AND p.fid NOT IN ({$unviewable_forums})"; 3727 } 3728 3729 if($inactiveforums) 3730 { 3731 $where_sql .= " AND p.fid NOT IN ({$inactiveforums})"; 3732 } 3733 3734 // Check group permissions if we can't view threads not started by us 3735 $onlyusfids = array(); 3736 $group_permissions = forum_permissions(); 3737 foreach($group_permissions as $fid => $forumpermissions) 3738 { 3739 if(isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] == 1) 3740 { 3741 $onlyusfids[] = $fid; 3742 } 3743 } 3744 3745 if(!empty($onlyusfids)) 3746 { 3747 $where_sql .= " AND ((t.fid IN(".implode(',', $onlyusfids).") AND t.uid='{$mybb->user['uid']}') OR t.fid NOT IN(".implode(',', $onlyusfids)."))"; 3748 } 3749 3750 // Moderators can view unapproved/deleted posts 3751 if($mybb->usergroup['issupermod'] != 1) 3752 { 3753 $unapprove_forums = array(); 3754 $deleted_forums = array(); 3755 $visible_sql = " AND (p.visible = 1 AND t.visible = 1)"; 3756 $query = $db->simple_select("moderators", "fid, canviewunapprove, canviewdeleted", "(id='{$mybb->user['uid']}' AND isgroup='0') OR (id='{$mybb->user['usergroup']}' AND isgroup='1')"); 3757 while($moderator = $db->fetch_array($query)) 3758 { 3759 if($moderator['canviewunapprove'] == 1) 3760 { 3761 $unapprove_forums[] = $moderator['fid']; 3762 } 3763 3764 if($moderator['canviewdeleted'] == 1) 3765 { 3766 $deleted_forums[] = $moderator['fid']; 3767 } 3768 } 3769 3770 if(!empty($unapprove_forums)) 3771 { 3772 $visible_sql .= " OR (p.visible = 0 AND p.fid IN(".implode(',', $unapprove_forums).")) OR (t.visible = 0 AND t.fid IN(".implode(',', $unapprove_forums)."))"; 3773 } 3774 if(!empty($deleted_forums)) 3775 { 3776 $visible_sql .= " OR (p.visible = -1 AND p.fid IN(".implode(',', $deleted_forums).")) OR (t.visible = -1 AND t.fid IN(".implode(',', $deleted_forums)."))"; 3777 } 3778 } 3779 else 3780 { 3781 // Super moderators (and admins) 3782 $visible_sql = " AND p.visible >= -1"; 3783 } 3784 3785 $query = $db->query(" 3786 SELECT COUNT(p.pid) AS count 3787 FROM ".TABLE_PREFIX."posts p 3788 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid = p.tid) 3789 WHERE {$post_ip_sql}{$where_sql}{$visible_sql} 3790 "); 3791 $post_results = $db->fetch_field($query, "count"); 3792 } 3793 } 3794 3795 // Searching user IP addresses 3796 if(isset($mybb->input['search_users'])) 3797 { 3798 $user_ip_sql = ''; 3799 if($ip_range) 3800 { 3801 if(!is_array($ip_range)) 3802 { 3803 $user_ip_sql = "regip=".$db->escape_binary($ip_range)." OR lastip=".$db->escape_binary($ip_range); 3804 } 3805 else 3806 { 3807 $user_ip_sql = "regip BETWEEN ".$db->escape_binary($ip_range[0])." AND ".$db->escape_binary($ip_range[1])." OR lastip BETWEEN ".$db->escape_binary($ip_range[0])." AND ".$db->escape_binary($ip_range[1]); 3808 } 3809 } 3810 3811 $plugins->run_hooks("modcp_ipsearch_users_start"); 3812 3813 if($user_ip_sql) 3814 { 3815 $query = $db->simple_select('users', 'COUNT(uid) AS count', $user_ip_sql); 3816 3817 $user_results = $db->fetch_field($query, "count"); 3818 } 3819 } 3820 3821 $total_results = $post_results+$user_results; 3822 3823 if(!$total_results) 3824 { 3825 $total_results = 1; 3826 } 3827 3828 // Now we have the result counts, paginate 3829 $perpage = $mybb->get_input('perpage', MyBB::INPUT_INT); 3830 if(!$perpage || $perpage <= 0) 3831 { 3832 $perpage = $mybb->settings['threadsperpage']; 3833 } 3834 3835 // Figure out if we need to display multiple pages. 3836 if($mybb->get_input('page') != "last") 3837 { 3838 $page = $mybb->get_input('page', MyBB::INPUT_INT); 3839 } 3840 3841 $pages = $total_results / $perpage; 3842 $pages = ceil($pages); 3843 3844 if($mybb->get_input('page') == "last") 3845 { 3846 $page = $pages; 3847 } 3848 3849 if($page > $pages || $page <= 0) 3850 { 3851 $page = 1; 3852 } 3853 3854 if($page) 3855 { 3856 $start = ($page-1) * $perpage; 3857 } 3858 else 3859 { 3860 $start = 0; 3861 $page = 1; 3862 } 3863 3864 $page_url = "modcp.php?action=ipsearch&perpage={$perpage}"; 3865 foreach(array('ipaddress', 'search_users', 'search_posts') as $input) 3866 { 3867 if(!empty($mybb->input[$input])) 3868 { 3869 $page_url .= "&{$input}=".urlencode($mybb->input[$input]); 3870 } 3871 } 3872 $multipage = multipage($total_results, $perpage, $page, $page_url); 3873 3874 $post_limit = $perpage; 3875 $results = ''; 3876 if(isset($mybb->input['search_users']) && $user_results && $start <= $user_results) 3877 { 3878 $query = $db->simple_select('users', 'username, uid, regip, lastip', $user_ip_sql, 3879 array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit_start' => $start, 'limit' => $perpage)); 3880 3881 while($ipaddress = $db->fetch_array($query)) 3882 { 3883 $result = false; 3884 $ipaddress['username'] = htmlspecialchars_uni($ipaddress['username']); 3885 $profile_link = build_profile_link($ipaddress['username'], $ipaddress['uid']); 3886 $trow = alt_trow(); 3887 $ip = false; 3888 if(is_array($ip_range)) 3889 { 3890 if(strcmp($ip_range[0], $ipaddress['regip']) <= 0 && strcmp($ip_range[1], $ipaddress['regip']) >= 0) 3891 { 3892 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_regip")."\";"); 3893 $ip = my_inet_ntop($db->unescape_binary($ipaddress['regip'])); 3894 } 3895 elseif(strcmp($ip_range[0], $ipaddress['lastip']) <= 0 && strcmp($ip_range[1], $ipaddress['lastip']) >= 0) 3896 { 3897 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_lastip")."\";"); 3898 $ip = my_inet_ntop($db->unescape_binary($ipaddress['lastip'])); 3899 } 3900 } 3901 elseif($ipaddress['regip'] == $ip_range) 3902 { 3903 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_regip")."\";"); 3904 $ip = my_inet_ntop($db->unescape_binary($ipaddress['regip'])); 3905 } 3906 elseif($ipaddress['lastip'] == $ip_range) 3907 { 3908 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_lastip")."\";"); 3909 $ip = my_inet_ntop($db->unescape_binary($ipaddress['lastip'])); 3910 } 3911 if($ip) 3912 { 3913 eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";"); 3914 $result = true; 3915 } 3916 if($result) 3917 { 3918 --$post_limit; 3919 } 3920 } 3921 } 3922 $post_start = 0; 3923 if($total_results > $user_results && $post_limit) 3924 { 3925 $post_start = $start-$user_results; 3926 if($post_start < 0) 3927 { 3928 $post_start = 0; 3929 } 3930 } 3931 if(isset($mybb->input['search_posts']) && $post_results && (!isset($mybb->input['search_users']) || (isset($mybb->input['search_users']) && $post_limit > 0))) 3932 { 3933 $ipaddresses = $tids = $uids = array(); 3934 3935 $query = $db->query(" 3936 SELECT p.username AS postusername, p.uid, p.subject, p.pid, p.tid, p.ipaddress 3937 FROM ".TABLE_PREFIX."posts p 3938 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid = p.tid) 3939 WHERE {$post_ip_sql}{$where_sql}{$visible_sql} 3940 ORDER BY p.dateline DESC, p.pid DESC 3941 LIMIT {$post_start}, {$post_limit} 3942 "); 3943 while($ipaddress = $db->fetch_array($query)) 3944 { 3945 $tids[$ipaddress['tid']] = $ipaddress['pid']; 3946 $uids[$ipaddress['uid']] = $ipaddress['pid']; 3947 $ipaddresses[$ipaddress['pid']] = $ipaddress; 3948 } 3949 3950 if(!empty($ipaddresses)) 3951 { 3952 $query = $db->simple_select("threads", "subject, tid", "tid IN(".implode(',', array_keys($tids)).")"); 3953 while($thread = $db->fetch_array($query)) 3954 { 3955 $ipaddresses[$tids[$thread['tid']]]['threadsubject'] = $thread['subject']; 3956 } 3957 unset($tids); 3958 3959 $query = $db->simple_select("users", "username, uid", "uid IN(".implode(',', array_keys($uids)).")"); 3960 while($user = $db->fetch_array($query)) 3961 { 3962 $ipaddresses[$uids[$user['uid']]]['username'] = $user['username']; 3963 } 3964 unset($uids); 3965 3966 foreach($ipaddresses as $ipaddress) 3967 { 3968 $ip = my_inet_ntop($db->unescape_binary($ipaddress['ipaddress'])); 3969 if(empty($ipaddress['username'])) 3970 { 3971 $ipaddress['username'] = $ipaddress['postusername']; // Guest username support 3972 } 3973 $ipaddress['username'] = htmlspecialchars_uni($ipaddress['username']); 3974 $trow = alt_trow(); 3975 if(empty($ipaddress['subject'])) 3976 { 3977 $ipaddress['subject'] = "RE: {$ipaddress['threadsubject']}"; 3978 } 3979 3980 $ipaddress['postlink'] = get_post_link($ipaddress['pid'], $ipaddress['tid']); 3981 $ipaddress['subject'] = htmlspecialchars_uni($parser->parse_badwords($ipaddress['subject'])); 3982 $ipaddress['profilelink'] = build_profile_link($ipaddress['username'], $ipaddress['uid']); 3983 3984 eval("\$subject = \"".$templates->get("modcp_ipsearch_result_post")."\";"); 3985 eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";"); 3986 } 3987 } 3988 } 3989 3990 if(!$results) 3991 { 3992 eval("\$results = \"".$templates->get("modcp_ipsearch_noresults")."\";"); 3993 } 3994 3995 if($ipaddressvalue) 3996 { 3997 $lang->ipsearch_results = $lang->sprintf($lang->ipsearch_results, $ipaddressvalue); 3998 } 3999 else 4000 { 4001 $lang->ipsearch_results = $lang->ipsearch; 4002 } 4003 4004 $ipaddress = $ipaddress_url = $misc_info_link = ''; 4005 if(!strstr($mybb->input['ipaddress'], "*") && !strstr($mybb->input['ipaddress'], "/")) 4006 { 4007 $ipaddress = htmlspecialchars_uni($mybb->input['ipaddress']); 4008 $ipaddress_url = urlencode($mybb->input['ipaddress']); 4009 eval("\$misc_info_link = \"".$templates->get("modcp_ipsearch_results_information")."\";"); 4010 } 4011 4012 eval("\$ipsearch_results = \"".$templates->get("modcp_ipsearch_results")."\";"); 4013 } 4014 4015 // Fetch filter options 4016 if(!$mybb->input['ipaddress']) 4017 { 4018 $mybb->input['search_posts'] = 1; 4019 $mybb->input['search_users'] = 1; 4020 } 4021 $usersearchselect = $postsearchselect = ''; 4022 if(isset($mybb->input['search_posts'])) 4023 { 4024 $postsearchselect = "checked=\"checked\""; 4025 } 4026 if(isset($mybb->input['search_users'])) 4027 { 4028 $usersearchselect = "checked=\"checked\""; 4029 } 4030 4031 $plugins->run_hooks("modcp_ipsearch_end"); 4032 4033 eval("\$ipsearch = \"".$templates->get("modcp_ipsearch")."\";"); 4034 output_page($ipsearch); 4035 } 4036 4037 if($mybb->input['action'] == "iplookup") 4038 { 4039 if($mybb->usergroup['canuseipsearch'] == 0) 4040 { 4041 error_no_permission(); 4042 } 4043 4044 $mybb->input['ipaddress'] = $mybb->get_input('ipaddress'); 4045 $lang->ipaddress_misc_info = $lang->sprintf($lang->ipaddress_misc_info, htmlspecialchars_uni($mybb->input['ipaddress'])); 4046 $ipaddress_location = $lang->na; 4047 $ipaddress_host_name = $lang->na; 4048 $modcp_ipsearch_misc_info = ''; 4049 if(!strstr($mybb->input['ipaddress'], "*")) 4050 { 4051 // Return GeoIP information if it is available to us 4052 if(function_exists('geoip_record_by_name')) 4053 { 4054 $ip_record = @geoip_record_by_name($mybb->input['ipaddress']); 4055 if($ip_record) 4056 { 4057 $ipaddress_location = htmlspecialchars_uni(utf8_encode($ip_record['country_name'])); 4058 if($ip_record['city']) 4059 { 4060 $ipaddress_location .= $lang->comma.htmlspecialchars_uni(utf8_encode($ip_record['city'])); 4061 } 4062 } 4063 } 4064 4065 $ipaddress_host_name = htmlspecialchars_uni(@gethostbyaddr($mybb->input['ipaddress'])); 4066 4067 // gethostbyaddr returns the same ip on failure 4068 if($ipaddress_host_name == $mybb->input['ipaddress']) 4069 { 4070 $ipaddress_host_name = $lang->na; 4071 } 4072 } 4073 4074 $plugins->run_hooks("modcp_iplookup_end"); 4075 4076 eval("\$iplookup = \"".$templates->get('modcp_ipsearch_misc_info', 1, 0)."\";"); 4077 echo($iplookup); 4078 exit; 4079 } 4080 4081 if($mybb->input['action'] == "banning") 4082 { 4083 if($mybb->usergroup['canbanusers'] == 0) 4084 { 4085 error_no_permission(); 4086 } 4087 4088 add_breadcrumb($lang->mcp_nav_banning, "modcp.php?action=banning"); 4089 4090 if(!$mybb->settings['threadsperpage']) 4091 { 4092 $mybb->settings['threadsperpage'] = 20; 4093 } 4094 4095 // Figure out if we need to display multiple pages. 4096 $perpage = $mybb->settings['threadsperpage']; 4097 if($mybb->get_input('page') != "last") 4098 { 4099 $page = $mybb->get_input('page', MyBB::INPUT_INT); 4100 } 4101 4102 $query = $db->simple_select("banned", "COUNT(uid) AS count"); 4103 $banned_count = $db->fetch_field($query, "count"); 4104 4105 $postcount = (int)$banned_count; 4106 $pages = $postcount / $perpage; 4107 $pages = ceil($pages); 4108 4109 if($mybb->get_input('page') == "last") 4110 { 4111 $page = $pages; 4112 } 4113 4114 if($page > $pages || $page <= 0) 4115 { 4116 $page = 1; 4117 } 4118 4119 if($page) 4120 { 4121 $start = ($page-1) * $perpage; 4122 } 4123 else 4124 { 4125 $start = 0; 4126 $page = 1; 4127 } 4128 $upper = $start+$perpage; 4129 4130 $multipage = multipage($postcount, $perpage, $page, "modcp.php?action=banning"); 4131 4132 $plugins->run_hooks("modcp_banning_start"); 4133 4134 $query = $db->query(" 4135 SELECT b.*, a.username AS adminuser, u.username 4136 FROM ".TABLE_PREFIX."banned b 4137 LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid) 4138 LEFT JOIN ".TABLE_PREFIX."users a ON (b.admin=a.uid) 4139 ORDER BY dateline DESC 4140 LIMIT {$start}, {$perpage} 4141 "); 4142 4143 // Get the banned users 4144 $bannedusers = ''; 4145 while($banned = $db->fetch_array($query)) 4146 { 4147 $banned['username'] = htmlspecialchars_uni($banned['username']); 4148 $profile_link = build_profile_link($banned['username'], $banned['uid']); 4149 4150 // Only show the edit & lift links if current user created ban, or is super mod/admin 4151 $edit_link = ''; 4152 if($mybb->user['uid'] == $banned['admin'] || !$banned['adminuser'] || $mybb->usergroup['issupermod'] == 1 || $mybb->usergroup['cancp'] == 1) 4153 { 4154 eval("\$edit_link = \"".$templates->get("modcp_banning_edit")."\";"); 4155 } 4156 4157 $admin_profile = build_profile_link(htmlspecialchars_uni($banned['adminuser']), $banned['admin']); 4158 4159 $trow = alt_trow(); 4160 4161 if($banned['reason']) 4162 { 4163 $banned['reason'] = htmlspecialchars_uni($parser->parse_badwords($banned['reason'])); 4164 } 4165 else 4166 { 4167 $banned['reason'] = $lang->na; 4168 } 4169 4170 if($banned['lifted'] == 'perm' || $banned['lifted'] == '' || $banned['bantime'] == 'perm' || $banned['bantime'] == '---') 4171 { 4172 $banlength = $lang->permanent; 4173 $timeremaining = $lang->na; 4174 } 4175 else 4176 { 4177 $banlength = $bantimes[$banned['bantime']]; 4178 $remaining = $banned['lifted']-TIME_NOW; 4179 4180 $timeremaining = nice_time($remaining, array('short' => 1, 'seconds' => false)).""; 4181 4182 $banned_class = ''; 4183 $ban_remaining = "{$timeremaining} {$lang->ban_remaining}"; 4184 4185 if($remaining <= 0) 4186 { 4187 $banned_class = "imminent_banned"; 4188 $ban_remaining = $lang->ban_ending_imminently; 4189 } 4190 if($remaining < 3600) 4191 { 4192 $banned_class = "high_banned"; 4193 } 4194 else if($remaining < 86400) 4195 { 4196 $banned_class = "moderate_banned"; 4197 } 4198 else if($remaining < 604800) 4199 { 4200 $banned_class = "low_banned"; 4201 } 4202 else 4203 { 4204 $banned_class = "normal_banned"; 4205 } 4206 4207 eval('$timeremaining = "'.$templates->get('modcp_banning_remaining').'";'); 4208 } 4209 4210 eval("\$bannedusers .= \"".$templates->get("modcp_banning_ban")."\";"); 4211 } 4212 4213 if(!$bannedusers) 4214 { 4215 eval("\$bannedusers = \"".$templates->get("modcp_banning_nobanned")."\";"); 4216 } 4217 4218 $plugins->run_hooks("modcp_banning"); 4219 4220 eval("\$bannedpage = \"".$templates->get("modcp_banning")."\";"); 4221 output_page($bannedpage); 4222 } 4223 4224 if($mybb->input['action'] == "liftban") 4225 { 4226 // Verify incoming POST request 4227 verify_post_check($mybb->get_input('my_post_key')); 4228 4229 if($mybb->usergroup['canbanusers'] == 0) 4230 { 4231 error_no_permission(); 4232 } 4233 4234 $query = $db->simple_select("banned", "*", "uid='".$mybb->get_input('uid', MyBB::INPUT_INT)."'"); 4235 $ban = $db->fetch_array($query); 4236 4237 if(!$ban) 4238 { 4239 error($lang->error_invalidban); 4240 } 4241 4242 // Permission to edit this ban? 4243 if($mybb->user['uid'] != $ban['admin'] && $mybb->usergroup['issupermod'] != 1 && $mybb->usergroup['cancp'] != 1) 4244 { 4245 error_no_permission(); 4246 } 4247 4248 $plugins->run_hooks("modcp_liftban_start"); 4249 4250 $query = $db->simple_select("users", "username", "uid = '{$ban['uid']}'"); 4251 $username = $db->fetch_field($query, "username"); 4252 4253 $updated_group = array( 4254 'usergroup' => $ban['oldgroup'], 4255 'additionalgroups' => $db->escape_string($ban['oldadditionalgroups']), 4256 'displaygroup' => $ban['olddisplaygroup'] 4257 ); 4258 $db->update_query("users", $updated_group, "uid='{$ban['uid']}'"); 4259 $db->delete_query("banned", "uid='{$ban['uid']}'"); 4260 4261 $cache->update_moderators(); 4262 4263 $cache->update_awaitingactivation(); 4264 4265 log_moderator_action(array("uid" => $ban['uid'], "username" => $username), $lang->lifted_ban); 4266 4267 $plugins->run_hooks("modcp_liftban_end"); 4268 4269 redirect("modcp.php?action=banning", $lang->redirect_banlifted); 4270 } 4271 4272 if($mybb->input['action'] == "do_banuser" && $mybb->request_method == "post") 4273 { 4274 // Verify incoming POST request 4275 verify_post_check($mybb->get_input('my_post_key')); 4276 4277 if($mybb->usergroup['canbanusers'] == 0) 4278 { 4279 error_no_permission(); 4280 } 4281 4282 // Editing an existing ban 4283 $existing_ban = false; 4284 if($mybb->get_input('uid', MyBB::INPUT_INT)) 4285 { 4286 // Get the users info from their uid 4287 $query = $db->query(" 4288 SELECT b.*, u.uid, u.username, u.usergroup, u.additionalgroups, u.displaygroup 4289 FROM ".TABLE_PREFIX."banned b 4290 LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid) 4291 WHERE b.uid='{$mybb->input['uid']}' 4292 "); 4293 $user = $db->fetch_array($query); 4294 4295 if($user) 4296 { 4297 $existing_ban = true; 4298 } 4299 4300 // Permission to edit this ban? 4301 if($existing_ban && $mybb->user['uid'] != $user['admin'] && $mybb->usergroup['issupermod'] != 1 && $mybb->usergroup['cancp'] != 1) 4302 { 4303 error_no_permission(); 4304 } 4305 } 4306 4307 $errors = array(); 4308 4309 // Creating a new ban 4310 if(!$existing_ban) 4311 { 4312 // Get the users info from their Username 4313 $options = array( 4314 'fields' => array('username', 'usergroup', 'additionalgroups', 'displaygroup') 4315 ); 4316 4317 $user = get_user_by_username($mybb->input['username'], $options); 4318 4319 if(!$user) 4320 { 4321 $errors[] = $lang->invalid_username; 4322 } 4323 } 4324 4325 if($user['uid'] == $mybb->user['uid']) 4326 { 4327 $errors[] = $lang->error_cannotbanself; 4328 } 4329 4330 // Have permissions to ban this user? 4331 if(!modcp_can_manage_user($user['uid'])) 4332 { 4333 $errors[] = $lang->error_cannotbanuser; 4334 } 4335 4336 // Check for an incoming reason 4337 if(empty($mybb->input['banreason'])) 4338 { 4339 $errors[] = $lang->error_nobanreason; 4340 } 4341 4342 // Check banned group 4343 $usergroups_cache = $cache->read('usergroups'); 4344 if(isset($usergroups_cache[$mybb->get_input('usergroup', MyBB::INPUT_INT)])) 4345 { 4346 $usergroup = $usergroups_cache[$mybb->get_input('usergroup', MyBB::INPUT_INT)]; 4347 } 4348 4349 if(!isset($usergroup) || empty($usergroup['isbannedgroup'])) 4350 { 4351 $errors[] = $lang->error_nobangroup; 4352 } 4353 4354 // If this is a new ban, we check the user isn't already part of a banned group 4355 if(!$existing_ban && $user['uid']) 4356 { 4357 $query = $db->simple_select("banned", "uid", "uid='{$user['uid']}'", array('limit' => 1)); 4358 if($db->num_rows($query) > 0) 4359 { 4360 $errors[] = $lang->error_useralreadybanned; 4361 } 4362 } 4363 4364 $plugins->run_hooks("modcp_do_banuser_start"); 4365 4366 // Still no errors? Ban the user 4367 if(!$errors) 4368 { 4369 // Ban the user 4370 if($mybb->get_input('liftafter') == '---') 4371 { 4372 $lifted = 0; 4373 } 4374 else 4375 { 4376 if(!isset($user['dateline'])) 4377 { 4378 $user['dateline'] = 0; 4379 } 4380 $lifted = ban_date2timestamp($mybb->get_input('liftafter'), $user['dateline']); 4381 } 4382 4383 $banreason = my_substr($mybb->get_input('banreason'), 0, 255); 4384 4385 if($existing_ban) 4386 { 4387 $update_array = array( 4388 'gid' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 4389 'dateline' => TIME_NOW, 4390 'bantime' => $db->escape_string($mybb->get_input('liftafter')), 4391 'lifted' => $db->escape_string($lifted), 4392 'reason' => $db->escape_string($banreason) 4393 ); 4394 4395 $db->update_query('banned', $update_array, "uid='{$user['uid']}'"); 4396 } 4397 else 4398 { 4399 $insert_array = array( 4400 'uid' => $user['uid'], 4401 'gid' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 4402 'oldgroup' => (int)$user['usergroup'], 4403 'oldadditionalgroups' => $db->escape_string($user['additionalgroups']), 4404 'olddisplaygroup' => (int)$user['displaygroup'], 4405 'admin' => (int)$mybb->user['uid'], 4406 'dateline' => TIME_NOW, 4407 'bantime' => $db->escape_string($mybb->get_input('liftafter')), 4408 'lifted' => $db->escape_string($lifted), 4409 'reason' => $db->escape_string($banreason) 4410 ); 4411 4412 $db->insert_query('banned', $insert_array); 4413 } 4414 4415 // Move the user to the banned group 4416 $update_array = array( 4417 'usergroup' => $mybb->get_input('usergroup', MyBB::INPUT_INT), 4418 'displaygroup' => 0, 4419 'additionalgroups' => '', 4420 ); 4421 $db->update_query('users', $update_array, "uid = {$user['uid']}"); 4422 4423 // Log edit or add ban 4424 if($existing_ban) 4425 { 4426 log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->edited_user_ban); 4427 } 4428 else 4429 { 4430 log_moderator_action(array("uid" => $user['uid'], "username" => $user['username']), $lang->banned_user); 4431 } 4432 4433 $plugins->run_hooks("modcp_do_banuser_end"); 4434 4435 $cache->update_awaitingactivation(); 4436 4437 if($existing_ban) 4438 { 4439 redirect("modcp.php?action=banning", $lang->redirect_banuser_updated); 4440 } 4441 else 4442 { 4443 redirect("modcp.php?action=banning", $lang->redirect_banuser); 4444 } 4445 } 4446 // Otherwise has errors, throw back to ban page 4447 else 4448 { 4449 $mybb->input['action'] = "banuser"; 4450 } 4451 } 4452 4453 if($mybb->input['action'] == "banuser") 4454 { 4455 add_breadcrumb($lang->mcp_nav_banning, "modcp.php?action=banning"); 4456 4457 if($mybb->usergroup['canbanusers'] == 0) 4458 { 4459 error_no_permission(); 4460 } 4461 4462 $mybb->input['uid'] = $mybb->get_input('uid', MyBB::INPUT_INT); 4463 if($mybb->input['uid']) 4464 { 4465 add_breadcrumb($lang->mcp_nav_editing_ban); 4466 } 4467 else 4468 { 4469 add_breadcrumb($lang->mcp_nav_ban_user); 4470 } 4471 4472 $plugins->run_hooks("modcp_banuser_start"); 4473 4474 $banuser_username = ''; 4475 $banreason = ''; 4476 4477 // If incoming user ID, we are editing a ban 4478 if($mybb->input['uid']) 4479 { 4480 $query = $db->query(" 4481 SELECT b.*, u.username, u.uid 4482 FROM ".TABLE_PREFIX."banned b 4483 LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid) 4484 WHERE b.uid='{$mybb->input['uid']}' 4485 "); 4486 $banned = $db->fetch_array($query); 4487 if(!empty($banned['username'])) 4488 { 4489 $username = $banned['username'] = htmlspecialchars_uni($banned['username']); 4490 $banreason = htmlspecialchars_uni($banned['reason']); 4491 $uid = $mybb->input['uid']; 4492 $user = get_user($banned['uid']); 4493 $lang->ban_user = $lang->edit_ban; // Swap over lang variables 4494 eval("\$banuser_username = \"".$templates->get("modcp_banuser_editusername")."\";"); 4495 } 4496 } 4497 4498 // Permission to edit this ban? 4499 if(!empty($banned) && $banned['uid'] && $mybb->user['uid'] != $banned['admin'] && $mybb->usergroup['issupermod'] != 1 && $mybb->usergroup['cancp'] != 1) 4500 { 4501 error_no_permission(); 4502 } 4503 4504 // New ban! 4505 if(!$banuser_username) 4506 { 4507 if($mybb->input['uid']) 4508 { 4509 $user = get_user($mybb->input['uid']); 4510 $user['username'] = htmlspecialchars_uni($user['username']); 4511 $username = $user['username']; 4512 } 4513 else 4514 { 4515 $username = htmlspecialchars_uni($mybb->get_input('username')); 4516 } 4517 eval("\$banuser_username = \"".$templates->get("modcp_banuser_addusername")."\";"); 4518 } 4519 4520 // Coming back to this page from an error? 4521 if($errors) 4522 { 4523 $errors = inline_error($errors); 4524 $banned = array( 4525 "bantime" => $mybb->get_input('liftafter'), 4526 "reason" => $mybb->get_input('reason'), 4527 "gid" => $mybb->get_input('gid', MyBB::INPUT_INT) 4528 ); 4529 $banreason = htmlspecialchars_uni($mybb->get_input('banreason')); 4530 } 4531 4532 // Generate the banned times dropdown 4533 $liftlist = ''; 4534 foreach($bantimes as $time => $title) 4535 { 4536 $selected = ''; 4537 if(isset($banned['bantime']) && $banned['bantime'] == $time) 4538 { 4539 $selected = " selected=\"selected\""; 4540 } 4541 4542 $thattime = ''; 4543 if($time != '---') 4544 { 4545 $dateline = TIME_NOW; 4546 if(isset($banned['dateline'])) 4547 { 4548 $dateline = $banned['dateline']; 4549 } 4550 4551 $thatime = my_date("D, jS M Y @ {$mybb->settings['timeformat']}", ban_date2timestamp($time, $dateline)); 4552 $thattime = " ({$thatime})"; 4553 } 4554 4555 eval("\$liftlist .= \"".$templates->get("modcp_banuser_liftlist")."\";"); 4556 } 4557 4558 $bangroup_option = $bangroups = ''; 4559 $numgroups = $banned_group = 0; 4560 $groupscache = $cache->read("usergroups"); 4561 4562 foreach($groupscache as $key => $group) 4563 { 4564 if($group['isbannedgroup']) 4565 { 4566 $selected = ""; 4567 if(isset($banned['gid']) && $banned['gid'] == $group['gid']) 4568 { 4569 $selected = " selected=\"selected\""; 4570 } 4571 4572 $group['title'] = htmlspecialchars_uni($group['title']); 4573 eval("\$bangroup_option .= \"".$templates->get("modcp_banuser_bangroups_group")."\";"); 4574 $banned_group = $group['gid']; 4575 ++$numgroups; 4576 } 4577 } 4578 4579 if($numgroups == 0) 4580 { 4581 error($lang->no_banned_group); 4582 } 4583 elseif($numgroups > 1) 4584 { 4585 eval("\$bangroups = \"".$templates->get("modcp_banuser_bangroups")."\";"); 4586 } 4587 else 4588 { 4589 eval("\$bangroups = \"".$templates->get("modcp_banuser_bangroups_hidden")."\";"); 4590 } 4591 4592 if(!empty($banned['uid'])) 4593 { 4594 eval("\$lift_link = \"".$templates->get("modcp_banuser_lift")."\";"); 4595 $uid = $banned['uid']; 4596 } 4597 else 4598 { 4599 $lift_link = ''; 4600 $uid = 0; 4601 } 4602 4603 $plugins->run_hooks("modcp_banuser_end"); 4604 4605 eval("\$banuser = \"".$templates->get("modcp_banuser")."\";"); 4606 output_page($banuser); 4607 } 4608 4609 if($mybb->input['action'] == "do_modnotes") 4610 { 4611 // Verify incoming POST request 4612 verify_post_check($mybb->get_input('my_post_key')); 4613 4614 $plugins->run_hooks("modcp_do_modnotes_start"); 4615 4616 // Update Moderator Notes cache 4617 $update_cache = array( 4618 "modmessage" => $mybb->get_input('modnotes') 4619 ); 4620 $cache->update("modnotes", $update_cache); 4621 4622 $plugins->run_hooks("modcp_do_modnotes_end"); 4623 4624 redirect("modcp.php", $lang->redirect_modnotes); 4625 } 4626 4627 if(!$mybb->input['action']) 4628 { 4629 $awaitingattachments = $awaitingposts = $awaitingthreads = $awaitingmoderation = ''; 4630 4631 if($mybb->usergroup['canmanagemodqueue'] == 1) 4632 { 4633 if($mybb->settings['enableattachments'] == 1 && ($nummodqueueattach > 0 || $mybb->usergroup['issupermod'] == 1)) 4634 { 4635 if($nummodqueueposts > 0 || $mybb->usergroup['issupermod'] == 1) 4636 { 4637 $bgcolor = "trow1"; 4638 } 4639 else 4640 { 4641 $bgcolor = "trow2"; 4642 } 4643 4644 $query = $db->query(" 4645 SELECT COUNT(aid) AS unapprovedattachments 4646 FROM ".TABLE_PREFIX."attachments a 4647 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid) 4648 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 4649 WHERE a.visible='0' {$tflist} 4650 "); 4651 $unapproved_attachments = $db->fetch_field($query, "unapprovedattachments"); 4652 4653 if($unapproved_attachments > 0) 4654 { 4655 $query = $db->query(" 4656 SELECT t.tid, p.pid, p.uid, t.username, a.filename, a.dateuploaded 4657 FROM ".TABLE_PREFIX."attachments a 4658 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=a.pid) 4659 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 4660 WHERE a.visible='0' {$tflist} 4661 ORDER BY a.dateuploaded DESC 4662 LIMIT 1 4663 "); 4664 $attachment = $db->fetch_array($query); 4665 $attachment['date'] = my_date('relative', $attachment['dateuploaded']); 4666 $attachment['username'] = htmlspecialchars_uni($attachment['username']); 4667 $attachment['profilelink'] = build_profile_link($attachment['username'], $attachment['uid']); 4668 $attachment['link'] = get_post_link($attachment['pid'], $attachment['tid']); 4669 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 4670 $unapproved_attachments = my_number_format($unapproved_attachments); 4671 4672 eval("\$latest_attachment = \"".$templates->get("modcp_lastattachment")."\";"); 4673 } 4674 else 4675 { 4676 eval("\$latest_attachment = \"".$templates->get("modcp_awaitingmoderation_none")."\";"); 4677 } 4678 4679 eval("\$awaitingattachments = \"".$templates->get("modcp_awaitingattachments")."\";"); 4680 } 4681 4682 if($nummodqueueposts > 0 || $mybb->usergroup['issupermod'] == 1) 4683 { 4684 $query = $db->query(" 4685 SELECT COUNT(pid) AS unapprovedposts 4686 FROM ".TABLE_PREFIX."posts p 4687 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 4688 WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid 4689 "); 4690 $unapproved_posts = $db->fetch_field($query, "unapprovedposts"); 4691 4692 if($unapproved_posts > 0) 4693 { 4694 $query = $db->query(" 4695 SELECT p.pid, p.tid, p.subject, p.uid, p.username, p.dateline 4696 FROM ".TABLE_PREFIX."posts p 4697 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid) 4698 WHERE p.visible='0' {$tflist} AND t.firstpost != p.pid 4699 ORDER BY p.dateline DESC, p.pid DESC 4700 LIMIT 1 4701 "); 4702 $post = $db->fetch_array($query); 4703 $post['date'] = my_date('relative', $post['dateline']); 4704 $post['username'] = htmlspecialchars_uni($post['username']); 4705 $post['profilelink'] = build_profile_link($post['username'], $post['uid']); 4706 $post['link'] = get_post_link($post['pid'], $post['tid']); 4707 $post['subject'] = $post['fullsubject'] = $parser->parse_badwords($post['subject']); 4708 if(my_strlen($post['subject']) > 25) 4709 { 4710 $post['subject'] = my_substr($post['subject'], 0, 25)."..."; 4711 } 4712 $post['subject'] = htmlspecialchars_uni($post['subject']); 4713 $post['fullsubject'] = htmlspecialchars_uni($post['fullsubject']); 4714 $unapproved_posts = my_number_format($unapproved_posts); 4715 4716 eval("\$latest_post = \"".$templates->get("modcp_lastpost")."\";"); 4717 } 4718 else 4719 { 4720 eval("\$latest_post = \"".$templates->get("modcp_awaitingmoderation_none")."\";"); 4721 } 4722 4723 eval("\$awaitingposts = \"".$templates->get("modcp_awaitingposts")."\";"); 4724 } 4725 4726 if($nummodqueuethreads > 0 || $mybb->usergroup['issupermod'] == 1) 4727 { 4728 $query = $db->simple_select("threads", "COUNT(tid) AS unapprovedthreads", "visible='0' {$flist_queue_threads}"); 4729 $unapproved_threads = $db->fetch_field($query, "unapprovedthreads"); 4730 4731 if($unapproved_threads > 0) 4732 { 4733 $query = $db->simple_select("threads", "tid, subject, uid, username, dateline", "visible='0' {$flist_queue_threads}", array('order_by' => 'dateline', 'order_dir' => 'DESC', 'limit' => 1)); 4734 $thread = $db->fetch_array($query); 4735 $thread['date'] = my_date('relative', $thread['dateline']); 4736 $thread['username'] = htmlspecialchars_uni($thread['username']); 4737 $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']); 4738 $thread['link'] = get_thread_link($thread['tid']); 4739 $thread['subject'] = $thread['fullsubject'] = $parser->parse_badwords($thread['subject']); 4740 if(my_strlen($thread['subject']) > 25) 4741 { 4742 $post['subject'] = my_substr($thread['subject'], 0, 25)."..."; 4743 } 4744 $thread['subject'] = htmlspecialchars_uni($thread['subject']); 4745 $thread['fullsubject'] = htmlspecialchars_uni($thread['fullsubject']); 4746 $unapproved_threads = my_number_format($unapproved_threads); 4747 4748 eval("\$latest_thread = \"".$templates->get("modcp_lastthread")."\";"); 4749 } 4750 else 4751 { 4752 eval("\$latest_thread = \"".$templates->get("modcp_awaitingmoderation_none")."\";"); 4753 } 4754 4755 eval("\$awaitingthreads = \"".$templates->get("modcp_awaitingthreads")."\";"); 4756 } 4757 4758 if(!empty($awaitingattachments) || !empty($awaitingposts) || !empty($awaitingthreads)) 4759 { 4760 eval("\$awaitingmoderation = \"".$templates->get("modcp_awaitingmoderation")."\";"); 4761 } 4762 } 4763 4764 $latestfivemodactions = ''; 4765 if(($nummodlogs > 0 || $mybb->usergroup['issupermod'] == 1) && $mybb->usergroup['canviewmodlogs'] == 1) 4766 { 4767 $where = ''; 4768 if($tflist_modlog) 4769 { 4770 $where = "WHERE (t.fid <> 0 {$tflist_modlog}) OR (l.fid <> 0)"; 4771 } 4772 4773 $query = $db->query(" 4774 SELECT l.*, u.username, u.usergroup, u.displaygroup, t.subject AS tsubject, f.name AS fname, p.subject AS psubject 4775 FROM ".TABLE_PREFIX."moderatorlog l 4776 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=l.uid) 4777 LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=l.tid) 4778 LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=l.fid) 4779 LEFT JOIN ".TABLE_PREFIX."posts p ON (p.pid=l.pid) 4780 {$where} 4781 ORDER BY l.dateline DESC 4782 LIMIT 5 4783 "); 4784 4785 $modlogresults = ''; 4786 while($logitem = $db->fetch_array($query)) 4787 { 4788 $information = ''; 4789 $logitem['action'] = htmlspecialchars_uni($logitem['action']); 4790 $log_date = my_date('relative', $logitem['dateline']); 4791 $trow = alt_trow(); 4792 $logitem['username'] = htmlspecialchars_uni($logitem['username']); 4793 $username = format_name($logitem['username'], $logitem['usergroup'], $logitem['displaygroup']); 4794 $logitem['profilelink'] = build_profile_link($username, $logitem['uid']); 4795 $logitem['ipaddress'] = my_inet_ntop($db->unescape_binary($logitem['ipaddress'])); 4796 4797 if($logitem['tsubject']) 4798 { 4799 $logitem['tsubject'] = htmlspecialchars_uni($parser->parse_badwords($logitem['tsubject'])); 4800 $logitem['thread'] = get_thread_link($logitem['tid']); 4801 eval("\$information .= \"".$templates->get("modcp_modlogs_result_thread")."\";"); 4802 } 4803 if($logitem['fname']) 4804 { 4805 $logitem['forum'] = get_forum_link($logitem['fid']); 4806 eval("\$information .= \"".$templates->get("modcp_modlogs_result_forum")."\";"); 4807 } 4808 if($logitem['psubject']) 4809 { 4810 $logitem['psubject'] = htmlspecialchars_uni($parser->parse_badwords($logitem['psubject'])); 4811 $logitem['post'] = get_post_link($logitem['pid']); 4812 eval("\$information .= \"".$templates->get("modcp_modlogs_result_post")."\";"); 4813 } 4814 4815 // Edited a user or managed announcement? 4816 if(!$logitem['tsubject'] || !$logitem['fname'] || !$logitem['psubject']) 4817 { 4818 $data = my_unserialize($logitem['data']); 4819 if(isset($data['uid'])) 4820 { 4821 $information = $lang->sprintf($lang->edited_user_info, htmlspecialchars_uni($data['username']), get_profile_link($data['uid'])); 4822 } 4823 if(isset($data['aid'])) 4824 { 4825 $data['subject'] = htmlspecialchars_uni($parser->parse_badwords($data['subject'])); 4826 $data['announcement'] = get_announcement_link($data['aid']); 4827 eval("\$information .= \"".$templates->get("modcp_modlogs_result_announcement")."\";"); 4828 } 4829 } 4830 4831 $plugins->run_hooks("modcp_modlogs_result"); 4832 4833 eval("\$modlogresults .= \"".$templates->get("modcp_modlogs_result")."\";"); 4834 } 4835 4836 if(!$modlogresults) 4837 { 4838 eval("\$modlogresults = \"".$templates->get("modcp_modlogs_nologs")."\";"); 4839 } 4840 4841 eval("\$latestfivemodactions = \"".$templates->get("modcp_latestfivemodactions")."\";"); 4842 } 4843 4844 $query = $db->query(" 4845 SELECT b.*, a.username AS adminuser, u.username 4846 FROM ".TABLE_PREFIX."banned b 4847 LEFT JOIN ".TABLE_PREFIX."users u ON (b.uid=u.uid) 4848 LEFT JOIN ".TABLE_PREFIX."users a ON (b.admin=a.uid) 4849 WHERE b.bantime != '---' AND b.bantime != 'perm' 4850 ORDER BY lifted ASC 4851 LIMIT 5 4852 "); 4853 4854 $banned_cache = array(); 4855 while($banned = $db->fetch_array($query)) 4856 { 4857 $banned['remaining'] = $banned['lifted']-TIME_NOW; 4858 $banned_cache[$banned['remaining'].$banned['uid']] = $banned; 4859 4860 unset($banned); 4861 } 4862 4863 // Get the banned users 4864 $bannedusers = ''; 4865 foreach($banned_cache as $banned) 4866 { 4867 $banned['username'] = htmlspecialchars_uni($banned['username']); 4868 $profile_link = build_profile_link($banned['username'], $banned['uid']); 4869 4870 // Only show the edit & lift links if current user created ban, or is super mod/admin 4871 $edit_link = ''; 4872 if($mybb->user['uid'] == $banned['admin'] || !$banned['adminuser'] || $mybb->usergroup['issupermod'] == 1 || $mybb->usergroup['cancp'] == 1) 4873 { 4874 eval("\$edit_link = \"".$templates->get("modcp_banning_edit")."\";"); 4875 } 4876 4877 $admin_profile = build_profile_link(htmlspecialchars_uni($banned['adminuser']), $banned['admin']); 4878 4879 $trow = alt_trow(); 4880 4881 if($banned['reason']) 4882 { 4883 $banned['reason'] = htmlspecialchars_uni($parser->parse_badwords($banned['reason'])); 4884 } 4885 else 4886 { 4887 $banned['reason'] = $lang->na; 4888 } 4889 4890 if($banned['lifted'] == 'perm' || $banned['lifted'] == '' || $banned['bantime'] == 'perm' || $banned['bantime'] == '---') 4891 { 4892 $banlength = $lang->permanent; 4893 $timeremaining = $lang->na; 4894 } 4895 else 4896 { 4897 $banlength = $bantimes[$banned['bantime']]; 4898 $remaining = $banned['remaining']; 4899 4900 $timeremaining = nice_time($remaining, array('short' => 1, 'seconds' => false)).""; 4901 4902 $banned_class = ''; 4903 $ban_remaining = "{$timeremaining} {$lang->ban_remaining}"; 4904 4905 if($remaining <= 0) 4906 { 4907 $banned_class = "imminent_banned"; 4908 $ban_remaining = $lang->ban_ending_imminently; 4909 } 4910 else if($remaining < 3600) 4911 { 4912 $banned_class = "high_banned"; 4913 } 4914 else if($remaining < 86400) 4915 { 4916 $banned_class = "moderate_banned"; 4917 } 4918 else if($remaining < 604800) 4919 { 4920 $banned_class = "low_banned"; 4921 } 4922 else 4923 { 4924 $banned_class = "normal_banned"; 4925 } 4926 4927 eval('$timeremaining = "'.$templates->get('modcp_banning_remaining').'";'); 4928 } 4929 4930 eval("\$bannedusers .= \"".$templates->get("modcp_banning_ban")."\";"); 4931 } 4932 4933 if(!$bannedusers) 4934 { 4935 eval("\$bannedusers = \"".$templates->get("modcp_nobanned")."\";"); 4936 } 4937 4938 $modnotes = ''; 4939 $modnotes_cache = $cache->read("modnotes"); 4940 if($modnotes_cache !== false) 4941 { 4942 $modnotes = htmlspecialchars_uni($modnotes_cache['modmessage']); 4943 } 4944 4945 $plugins->run_hooks("modcp_end"); 4946 4947 eval("\$modcp = \"".$templates->get("modcp")."\";"); 4948 output_page($modcp); 4949 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| 2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |