[ Index ] |
PHP Cross Reference of MyBB |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id$ 10 */ 11 12 // Disallow direct access to this file for security reasons 13 if(!defined("IN_MYBB")) 14 { 15 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined."); 16 } 17 18 $page->add_breadcrumb_item($lang->forum_announcements, "index.php?module=forum-announcements"); 19 20 if($mybb->input['action'] == "add" || !$mybb->input['action']) 21 { 22 $sub_tabs['forum_announcements'] = array( 23 'title' => $lang->forum_announcements, 24 'link' => "index.php?module=forum-announcements", 25 'description' => $lang->forum_announcements_desc 26 ); 27 28 $sub_tabs['add_announcement'] = array( 29 'title' => $lang->add_announcement, 30 'link' => "index.php?module=forum-announcements&action=add", 31 'description' => $lang->add_announcement_desc 32 ); 33 } 34 else if($mybb->input['action'] == "edit") 35 { 36 $sub_tabs['forum_announcements'] = array( 37 'title' => $lang->forum_announcements, 38 'link' => "index.php?module=forum-announcements", 39 'description' => $lang->forum_announcements_desc 40 ); 41 42 $sub_tabs['update_announcement'] = array( 43 'title' => $lang->update_announcement, 44 'link' => "index.php?module=forum-announcements&action=add", 45 'description' => $lang->update_announcement_desc 46 ); 47 } 48 49 $plugins->run_hooks("admin_forum_announcements_begin"); 50 51 if($mybb->input['action'] == "add") 52 { 53 $plugins->run_hooks("admin_forum_announcements_add"); 54 55 if($mybb->request_method == "post") 56 { 57 if(!trim($mybb->input['title'])) 58 { 59 $errors[] = $lang->error_missing_title; 60 } 61 62 if(!trim($mybb->input['message'])) 63 { 64 $errors[] = $lang->error_missing_message; 65 } 66 67 if(!trim($mybb->input['fid'])) 68 { 69 $errors[] = $lang->error_missing_forum; 70 } 71 72 $startdate = @explode(" ", $mybb->input['starttime_time']); 73 $startdate = @explode(":", $startdate[0]); 74 $enddate = @explode(" ", $mybb->input['endtime_time']); 75 $enddate = @explode(":", $enddate[0]); 76 77 if(stristr($mybb->input['starttime_time'], "pm")) 78 { 79 $startdate[0] = 12+$startdate[0]; 80 if($startdate[0] >= 24) 81 { 82 $startdate[0] = "00"; 83 } 84 } 85 86 if(stristr($mybb->input['endtime_time'], "pm")) 87 { 88 $enddate[0] = 12+$enddate[0]; 89 if($enddate[0] >= 24) 90 { 91 $enddate[0] = "00"; 92 } 93 } 94 95 $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); 96 if(!in_array($mybb->input['starttime_month'], $months)) 97 { 98 $mybb->input['starttime_month'] = 1; 99 } 100 101 $startdate = gmmktime(intval($startdate[0]), intval($startdate[1]), 0, (int)$mybb->input['starttime_month'], intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year'])); 102 if(!checkdate(intval($mybb->input['starttime_month']), intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year'])) || $startdate < 0 || $startdate == false) 103 { 104 $errors[] = $lang->error_invalid_start_date; 105 } 106 107 if($mybb->input['endtime_type'] == "2") 108 { 109 $enddate = '0'; 110 } 111 else 112 { 113 if(!in_array($mybb->input['endtime_month'], $months)) 114 { 115 $mybb->input['endtime_month'] = 1; 116 } 117 $enddate = gmmktime(intval($enddate[0]), intval($enddate[1]), 0, (int)$mybb->input['endtime_month'], intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year'])); 118 if(!checkdate(intval($mybb->input['endtime_month']), intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year'])) || $enddate < 0 || $enddate == false) 119 { 120 $errors[] = $lang->error_invalid_end_date; 121 } 122 if($enddate <= $startdate) 123 { 124 $errors[] = $lang->error_end_before_start; 125 } 126 } 127 128 if(!$errors) 129 { 130 $mybb->input['title'] = utf8_handle_4byte_string($mybb->input['title']); 131 $mybb->input['message'] = utf8_handle_4byte_string($mybb->input['message']); 132 $insert_announcement = array( 133 "fid" => $mybb->input['fid'], 134 "uid" => $mybb->user['uid'], 135 "subject" => $db->escape_string($mybb->input['title']), 136 "message" => $db->escape_string($mybb->input['message']), 137 "startdate" => $startdate, 138 "enddate" => $enddate, 139 "allowhtml" => $db->escape_string($mybb->input['allowhtml']), 140 "allowmycode" => $db->escape_string($mybb->input['allowmycode']), 141 "allowsmilies" => $db->escape_string($mybb->input['allowsmilies']), 142 ); 143 144 $aid = $db->insert_query("announcements", $insert_announcement); 145 146 $plugins->run_hooks("admin_forum_announcements_add_commit"); 147 148 // Log admin action 149 log_admin_action($aid, $mybb->input['title']); 150 $cache->update_forumsdisplay(); 151 152 flash_message($lang->success_added_announcement, 'success'); 153 admin_redirect("index.php?module=forum-announcements"); 154 } 155 else 156 { 157 $mybb->input['action'] = 'add'; 158 } 159 } 160 161 $page->add_breadcrumb_item($lang->add_an_announcement); 162 $page->output_header($lang->add_an_announcement); 163 $page->output_nav_tabs($sub_tabs, "add_announcement"); 164 165 $form = new Form("index.php?module=forum-announcements&action=add", "post"); 166 if($errors) 167 { 168 $page->output_inline_error($errors); 169 } 170 171 $default_options = array( 172 'starttime_time', 173 'starttime_day', 174 'starttime_month', 175 'starttime_year', 176 'endtime_type', 177 'endtime_time', 178 'endtime_day', 179 'endtime_month', 180 'endtime_year', 181 'title', 182 'message', 183 'fid', 184 'allowhtml', 185 'allowmycode', 186 'allowsmilies' 187 ); 188 189 foreach($default_options as $option) 190 { 191 if(!isset($mybb->input[$option])) 192 { 193 $mybb->input[$option] = ''; 194 } 195 } 196 197 if($mybb->input['endtime_type'] == "1") 198 { 199 $endtime_checked[1] = "checked=\"checked\""; 200 $endtime_checked[2] = ""; 201 } 202 else 203 { 204 $endtime_checked[1] = ""; 205 $endtime_checked[2] = "checked=\"checked\""; 206 } 207 208 if(!$mybb->input['starttime_time']) 209 { 210 $start_time = explode("-", gmdate("g-i-a", TIME_NOW)); 211 $mybb->input['starttime_time'] = $start_time[0].":".$start_time[1]." ".$start_time[2]; 212 } 213 214 if(!$mybb->input['endtime_time']) 215 { 216 $end_time = explode("-", gmdate("g-i-a", TIME_NOW)); 217 $mybb->input['endtime_time'] = $end_time[0].":".$end_time[1]." ".$end_time[2]; 218 } 219 220 if($mybb->input['starttime_day']) 221 { 222 $startday = intval($mybb->input['starttime_day']); 223 } 224 else 225 { 226 $startday = gmdate("j", TIME_NOW); 227 } 228 229 if($mybb->input['endtime_day']) 230 { 231 $endday = intval($mybb->input['endtime_day']); 232 } 233 else 234 { 235 $endday = gmdate("j", TIME_NOW); 236 } 237 238 $startdateday = $enddateday = $startdatemonth = $enddatemonth = ''; 239 240 // Days 241 for($i = 1; $i <= 31; ++$i) 242 { 243 if($startday == $i) 244 { 245 $startdateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n"; 246 } 247 else 248 { 249 $startdateday .= "<option value=\"$i\">$i</option>\n"; 250 } 251 252 if($endday == $i) 253 { 254 $enddateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n"; 255 } 256 else 257 { 258 $enddateday .= "<option value=\"$i\">$i</option>\n"; 259 } 260 } 261 262 // Months 263 for($i = 1; $i <= 12; ++$i) 264 { 265 $endmonthsel[$i] = $startmonthsel[$i] = ''; 266 } 267 268 if($mybb->input['starttime_month']) 269 { 270 $startmonth = intval($mybb->input['starttime_month']); 271 $startmonthsel[$startmonth] = "selected=\"selected\""; 272 } 273 else 274 { 275 $startmonth = gmdate("m", TIME_NOW); 276 $startmonthsel[$startmonth] = "selected=\"selected\""; 277 } 278 279 if($mybb->input['endtime_month']) 280 { 281 $endmonth = intval($mybb->input['endtime_month']); 282 $endmonthsel[$endmonth] = "selected=\"selected\""; 283 } 284 else 285 { 286 $endmonth = gmdate("m", TIME_NOW); 287 $endmonthsel[$endmonth] = "selected=\"selected\""; 288 } 289 290 $startdatemonth .= "<option value=\"01\" {$startmonthsel[1]}>{$lang->january}</option>\n"; 291 $enddatemonth .= "<option value=\"01\" {$endmonthsel[1]}>{$lang->january}</option>\n"; 292 $startdatemonth .= "<option value=\"02\" {$startmonthsel[2]}>{$lang->february}</option>\n"; 293 $enddatemonth .= "<option value=\"02\" {$endmonthsel[2]}>{$lang->february}</option>\n"; 294 $startdatemonth .= "<option value=\"03\" {$startmonthsel[3]}>{$lang->march}</option>\n"; 295 $enddatemonth .= "<option value=\"03\" {$endmonthsel[3]}>{$lang->march}</option>\n"; 296 $startdatemonth .= "<option value=\"04\" {$startmonthsel[4]}>{$lang->april}</option>\n"; 297 $enddatemonth .= "<option value=\"04\" {$endmonthsel[4]}>{$lang->april}</option>\n"; 298 $startdatemonth .= "<option value=\"05\" {$startmonthsel[5]}>{$lang->may}</option>\n"; 299 $enddatemonth .= "<option value=\"05\" {$endmonthsel[5]}>{$lang->may}</option>\n"; 300 $startdatemonth .= "<option value=\"06\" {$startmonthsel[6]}>{$lang->june}</option>\n"; 301 $enddatemonth .= "<option value=\"06\" {$endmonthsel[6]}>{$lang->june}</option>\n"; 302 $startdatemonth .= "<option value=\"07\" {$startmonthsel[7]}>{$lang->july}</option>\n"; 303 $enddatemonth .= "<option value=\"07\" {$endmonthsel[7]}>{$lang->july}</option>\n"; 304 $startdatemonth .= "<option value=\"08\" {$startmonthsel[8]}>{$lang->august}</option>\n"; 305 $enddatemonth .= "<option value=\"08\" {$endmonthsel[8]}>{$lang->august}</option>\n"; 306 $startdatemonth .= "<option value=\"09\" {$startmonthsel[9]}>{$lang->september}</option>\n"; 307 $enddatemonth .= "<option value=\"09\" {$endmonthsel[9]}>{$lang->september}</option>\n"; 308 $startdatemonth .= "<option value=\"10\" {$startmonthsel[10]}>{$lang->october}</option>\n"; 309 $enddatemonth .= "<option value=\"10\" {$endmonthsel[10]}>{$lang->october}</option>\n"; 310 $startdatemonth .= "<option value=\"11\" {$startmonthsel[11]}>{$lang->november}</option>\n"; 311 $enddatemonth .= "<option value=\"11\" {$endmonthsel[11]}>{$lang->november}</option>\n"; 312 $startdatemonth .= "<option value=\"12\" {$startmonthsel[12]}>{$lang->december}</option>\n"; 313 $enddatemonth .= "<option value=\"12\" {$endmonthsel[12]}>{$lang->december}</option>\n"; 314 315 if($mybb->input['starttime_year']) 316 { 317 $startdateyear = intval($mybb->input['starttime_year']); 318 } 319 else 320 { 321 $startdateyear = gmdate("Y", TIME_NOW); 322 } 323 324 if($mybb->input['endtime_year']) 325 { 326 $enddateyear = intval($mybb->input['endtime_year']); 327 } 328 else 329 { 330 $enddateyear = gmdate("Y", TIME_NOW) + 1; 331 } 332 333 $form_container = new FormContainer($lang->add_an_announcement); 334 $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title'); 335 $form_container->output_row($lang->start_date." <em>*</em>", $lang->start_date_desc, "<select name=\"starttime_day\">\n{$startdateday}</select>\n \n<select name=\"starttime_month\">\n{$startdatemonth}</select>\n \n<input type=\"text\" name=\"starttime_year\" value=\"{$startdateyear}\" size=\"4\" maxlength=\"4\" />\n - {$lang->time} ".$form->generate_text_box('starttime_time', $mybb->input['starttime_time'], array('id' => 'starttime_time', 'style' => 'width: 50px;'))); 336 337 $actions = "<script type=\"text/javascript\"> 338 function checkAction(id) 339 { 340 var checked = ''; 341 342 $$('.'+id+'s_check').each(function(e) 343 { 344 if(e.checked == true) 345 { 346 checked = e.value; 347 } 348 }); 349 $$('.'+id+'s').each(function(e) 350 { 351 Element.hide(e); 352 }); 353 if($(id+'_'+checked)) 354 { 355 Element.show(id+'_'+checked); 356 } 357 } 358 </script> 359 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 360 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"endtime_type\" value=\"1\" {$endtime_checked[1]} class=\"endtimes_check\" onclick=\"checkAction('endtime');\" style=\"vertical-align: middle;\" /> <strong>{$lang->set_time}</strong></label></dt> 361 <dd style=\"margin-top: 4px;\" id=\"endtime_1\" class=\"endtimes\"> 362 <table cellpadding=\"4\"> 363 <tr> 364 <td><select name=\"endtime_day\">\n{$enddateday}</select>\n \n<select name=\"endtime_month\">\n{$enddatemonth}</select>\n \n<input type=\"text\" name=\"endtime_year\" value=\"{$enddateyear}\" class=\"text_input\" size=\"4\" maxlength=\"4\" />\n - {$lang->time} ".$form->generate_text_box('endtime_time', $mybb->input['endtime_time'], array('id' => 'endtime_time', 'style' => 'width: 50px;'))."</td> 365 </tr> 366 </table> 367 </dd> 368 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"endtime_type\" value=\"2\" {$endtime_checked[2]} class=\"endtimes_check\" onclick=\"checkAction('endtime');\" style=\"vertical-align: middle;\" /> <strong>{$lang->never}</strong></label></dt> 369 </dl> 370 <script type=\"text/javascript\"> 371 checkAction('endtime'); 372 </script>"; 373 $form_container->output_row($lang->end_date." <em>*</em>", $lang->end_date_desc, $actions); 374 375 $form_container->output_row($lang->message." <em>*</em>", "", $form->generate_text_area('message', $mybb->input['message'], array('id' => 'message')), 'message'); 376 377 $form_container->output_row($lang->forums_to_appear_in." <em>*</em>", $lang->forums_to_appear_in_desc, $form->generate_forum_select('fid', $mybb->input['fid'], array('size' => 5, 'main_option' => $lang->all_forums))); 378 379 $form_container->output_row($lang->allow_html." <em>*</em>", "", $form->generate_yes_no_radio('allowhtml', $mybb->input['allowhtml'], array('style' => 'width: 2em;'))); 380 381 $form_container->output_row($lang->allow_mycode." <em>*</em>", "", $form->generate_yes_no_radio('allowmycode', $mybb->input['allowmycode'], array('style' => 'width: 2em;'))); 382 383 $form_container->output_row($lang->allow_smilies." <em>*</em>", "", $form->generate_yes_no_radio('allowsmilies', $mybb->input['allowsmilies'], array('style' => 'width: 2em;'))); 384 385 $form_container->end(); 386 387 $buttons[] = $form->generate_submit_button($lang->save_announcement); 388 $form->output_submit_wrapper($buttons); 389 $form->end(); 390 391 $page->output_footer(); 392 } 393 394 if($mybb->input['action'] == "edit") 395 { 396 $plugins->run_hooks("admin_forum_announcements_edit"); 397 398 if(!trim($mybb->input['aid'])) 399 { 400 flash_message($lang->error_invalid_announcement, 'error'); 401 admin_redirect("index.php?module=forum-announcements"); 402 } 403 404 if($mybb->request_method == "post") 405 { 406 if(!trim($mybb->input['title'])) 407 { 408 $errors[] = $lang->error_missing_title; 409 } 410 411 if(!trim($mybb->input['message'])) 412 { 413 $errors[] = $lang->error_missing_message; 414 } 415 416 if(!trim($mybb->input['fid'])) 417 { 418 $errors[] = $lang->error_missing_forum; 419 } 420 421 $startdate = @explode(" ", $mybb->input['starttime_time']); 422 $startdate = @explode(":", $startdate[0]); 423 $enddate = @explode(" ", $mybb->input['endtime_time']); 424 $enddate = @explode(":", $enddate[0]); 425 426 if(stristr($mybb->input['starttime_time'], "pm")) 427 { 428 $startdate[0] = 12+$startdate[0]; 429 if($startdate[0] >= 24) 430 { 431 $startdate[0] = "00"; 432 } 433 } 434 435 if(stristr($mybb->input['endtime_time'], "pm")) 436 { 437 $enddate[0] = 12+$enddate[0]; 438 if($enddate[0] >= 24) 439 { 440 $enddate[0] = "00"; 441 } 442 } 443 444 $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); 445 if(!in_array($mybb->input['starttime_month'], $months)) 446 { 447 $mybb->input['starttime_month'] = 1; 448 } 449 450 $startdate = gmmktime(intval($startdate[0]), intval($startdate[1]), 0, (int)$mybb->input['starttime_month'], intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year'])); 451 if(!checkdate(intval($mybb->input['starttime_month']), intval($mybb->input['starttime_day']), intval($mybb->input['starttime_year'])) || $startdate < 0 || $startdate == false) 452 { 453 $errors[] = $lang->error_invalid_start_date; 454 } 455 456 if($mybb->input['endtime_type'] == "2") 457 { 458 $enddate = '0'; 459 } 460 else 461 { 462 if(!in_array($mybb->input['endtime_month'], $months)) 463 { 464 $mybb->input['endtime_month'] = 1; 465 } 466 $enddate = gmmktime(intval($enddate[0]), intval($enddate[1]), 0, (int)$mybb->input['endtime_month'], intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year'])); 467 if(!checkdate(intval($mybb->input['endtime_month']), intval($mybb->input['endtime_day']), intval($mybb->input['endtime_year'])) || $enddate < 0 || $enddate == false) 468 { 469 $errors[] = $lang->error_invalid_end_date; 470 } 471 472 if($enddate <= $startdate) 473 { 474 $errors[] = $lang->error_end_before_start; 475 } 476 } 477 478 if(!$errors) 479 { 480 $update_announcement = array( 481 "fid" => $mybb->input['fid'], 482 "subject" => $db->escape_string($mybb->input['title']), 483 "message" => $db->escape_string($mybb->input['message']), 484 "startdate" => $startdate, 485 "enddate" => $enddate, 486 "allowhtml" => $db->escape_string($mybb->input['allowhtml']), 487 "allowmycode" => $db->escape_string($mybb->input['allowmycode']), 488 "allowsmilies" => $db->escape_string($mybb->input['allowsmilies']), 489 ); 490 491 $db->update_query("announcements", $update_announcement, "aid='{$mybb->input['aid']}'"); 492 493 $plugins->run_hooks("admin_forum_announcements_edit_commit"); 494 495 // Log admin action 496 log_admin_action($mybb->input['aid'], $mybb->input['title']); 497 $cache->update_forumsdisplay(); 498 499 flash_message($lang->success_updated_announcement, 'success'); 500 admin_redirect("index.php?module=forum-announcements"); 501 } 502 else 503 { 504 $mybb->input['action'] = 'edit'; 505 } 506 } 507 508 $page->add_breadcrumb_item($lang->update_an_announcement); 509 $page->output_header($lang->update_an_announcement); 510 $page->output_nav_tabs($sub_tabs, "update_announcement"); 511 512 $form = new Form("index.php?module=forum-announcements&action=edit", "post"); 513 echo $form->generate_hidden_field("aid", $mybb->input['aid']); 514 515 if($errors) 516 { 517 $page->output_inline_error($errors); 518 519 // Gather start and end date data 520 $startday = $mybb->input['starttime_day']; 521 $start_time = $mybb->input['starttime_time']; 522 $startmonth = $mybb->input['starttime_month']; 523 $startmonthsel[$startmonth] = 'selected="selected"'; 524 $startdateyear = $mybb->input['starttime_year']; 525 526 if($mybb->input['endtime_type'] == 1) 527 { 528 // Set time 529 $endtime_checked[1] = 'checked="checked"'; 530 $endtime_checked[2] = ''; 531 532 $endday = $mybb->input['endtime_day']; 533 $endtime = $mybb->input['endtime_time']; 534 $endmonth = $mybb->input['endtime_month']; 535 $endmonthsel[$endmonth] = 'selected'; 536 $enddateyear = $mybb->input['endtime_year']; 537 } 538 else 539 { 540 // Never 541 $endtime_checked[1] = ''; 542 $endtime_checked[2] = 'checked="checked"'; 543 544 $endday = $startday; 545 $endmonth = $startmonth; 546 $endmonthsel[$endmonth] = 'selected'; 547 $enddateyear = $startdateyear + 1; 548 } 549 } 550 else 551 { 552 $query = $db->simple_select("announcements", "*", "aid='{$mybb->input['aid']}'"); 553 $announcement = $db->fetch_array($query); 554 555 if(!$announcement) 556 { 557 flash_message($lang->error_invalid_announcement, 'error'); 558 admin_redirect("index.php?module=forum-announcements"); 559 } 560 561 $start_time = explode("-", gmdate("g-i-a", $announcement['startdate'])); 562 $mybb->input['starttime_time'] = $start_time[0].":".$start_time[1]." ".$start_time[2]; 563 564 $startday = gmdate("j", $announcement['startdate']); 565 566 $startmonth = gmdate("m", $announcement['startdate']); 567 $startmonthsel[$startmonth] = "selected=\"selected\""; 568 569 $startdateyear = gmdate("Y", $announcement['startdate']); 570 571 $mybb->input['title'] = $announcement['subject']; 572 $mybb->input['message'] = $announcement['message']; 573 $mybb->input['allowhtml'] = $announcement['allowhtml']; 574 $mybb->input['allowsmilies'] = $announcement['allowsmilies']; 575 $mybb->input['allowmycode'] = $announcement['allowmycode']; 576 $mybb->input['fid'] = $announcement['fid']; 577 578 if($announcement['enddate']) 579 { 580 $endtime_checked[1] = "checked=\"checked\""; 581 $endtime_checked[2] = ""; 582 583 $end_time = explode("-", gmdate("g-i-a", $announcement['enddate'])); 584 $mybb->input['endtime_time'] = $end_time[0].":".$end_time[1]." ".$end_time[2]; 585 586 $endday = gmdate("j", $announcement['enddate']); 587 588 $endmonth = gmdate("m", $announcement['enddate']); 589 $endmonthsel[$endmonth] = "selected"; 590 591 $enddateyear = gmdate("Y", $announcement['enddate']); 592 } 593 else 594 { 595 $endtime_checked[1] = ""; 596 $endtime_checked[2] = "checked=\"checked\""; 597 598 $mybb->input['endtime_time'] = $mybb->input['starttime_time']; 599 $endday = $startday; 600 $endmonth = $startmonth; 601 $enddateyear = $startdateyear+1; 602 } 603 } 604 605 for($i = 1; $i <= 31; ++$i) 606 { 607 if($startday == $i) 608 { 609 $startdateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n"; 610 } 611 else 612 { 613 $startdateday .= "<option value=\"$i\">$i</option>\n"; 614 } 615 616 if($endday == $i) 617 { 618 $enddateday .= "<option value=\"$i\" selected=\"selected\">$i</option>\n"; 619 } 620 else 621 { 622 $enddateday .= "<option value=\"$i\">$i</option>\n"; 623 } 624 } 625 626 $startdatemonth .= "<option value=\"01\" {$startmonthsel['01']}>{$lang->january}</option>\n"; 627 $enddatemonth .= "<option value=\"01\" {$endmonthsel['01']}>{$lang->january}</option>\n"; 628 $startdatemonth .= "<option value=\"02\" {$startmonthsel['02']}>{$lang->february}</option>\n"; 629 $enddatemonth .= "<option value=\"02\" {$endmonthsel['02']}>{$lang->february}</option>\n"; 630 $startdatemonth .= "<option value=\"03\" {$startmonthsel['03']}>{$lang->march}</option>\n"; 631 $enddatemonth .= "<option value=\"03\" {$endmonthsel['03']}>{$lang->march}</option>\n"; 632 $startdatemonth .= "<option value=\"04\" {$startmonthsel['04']}>{$lang->april}</option>\n"; 633 $enddatemonth .= "<option value=\"04\" {$endmonthsel['04']}>{$lang->april}</option>\n"; 634 $startdatemonth .= "<option value=\"05\" {$startmonthsel['05']}>{$lang->may}</option>\n"; 635 $enddatemonth .= "<option value=\"05\" {$endmonthsel['05']}>{$lang->may}</option>\n"; 636 $startdatemonth .= "<option value=\"06\" {$startmonthsel['06']}>{$lang->june}</option>\n"; 637 $enddatemonth .= "<option value=\"06\" {$endmonthsel['06']}>{$lang->june}</option>\n"; 638 $startdatemonth .= "<option value=\"07\" {$startmonthsel['07']}>{$lang->july}</option>\n"; 639 $enddatemonth .= "<option value=\"07\" {$endmonthsel['07']}>{$lang->july}</option>\n"; 640 $startdatemonth .= "<option value=\"08\" {$startmonthsel['08']}>{$lang->august}</option>\n"; 641 $enddatemonth .= "<option value=\"08\" {$endmonthsel['08']}>{$lang->august}</option>\n"; 642 $startdatemonth .= "<option value=\"09\" {$startmonthsel['09']}>{$lang->september}</option>\n"; 643 $enddatemonth .= "<option value=\"09\" {$endmonthsel['09']}>{$lang->september}</option>\n"; 644 $startdatemonth .= "<option value=\"10\" {$startmonthsel['10']}>{$lang->october}</option>\n"; 645 $enddatemonth .= "<option value=\"10\" {$endmonthsel['10']}>{$lang->october}</option>\n"; 646 $startdatemonth .= "<option value=\"11\" {$startmonthsel['11']}>{$lang->november}</option>\n"; 647 $enddatemonth .= "<option value=\"11\" {$endmonthsel['11']}>{$lang->november}</option>\n"; 648 $startdatemonth .= "<option value=\"12\" {$startmonthsel['12']}>{$lang->december}</option>\n"; 649 $enddatemonth .= "<option value=\"12\" {$endmonthsel['12']}>{$lang->december}</option>\n"; 650 651 $form_container = new FormContainer($lang->add_an_announcement); 652 $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('title', $mybb->input['title'], array('id' => 'title')), 'title'); 653 $form_container->output_row($lang->start_date." <em>*</em>", $lang->start_date_desc, "<select name=\"starttime_day\">\n{$startdateday}</select>\n \n<select name=\"starttime_month\">\n{$startdatemonth}</select>\n \n<input type=\"text\" name=\"starttime_year\" value=\"{$startdateyear}\" size=\"4\" maxlength=\"4\" class=\"text_input\" />\n - {$lang->time} ".$form->generate_text_box('starttime_time', $mybb->input['starttime_time'], array('id' => 'starttime_time', 'style' => 'width: 50px;'))); 654 655 $actions = "<script type=\"text/javascript\"> 656 function checkAction(id) 657 { 658 var checked = ''; 659 660 $$('.'+id+'s_check').each(function(e) 661 { 662 if(e.checked == true) 663 { 664 checked = e.value; 665 } 666 }); 667 $$('.'+id+'s').each(function(e) 668 { 669 Element.hide(e); 670 }); 671 if($(id+'_'+checked)) 672 { 673 Element.show(id+'_'+checked); 674 } 675 } 676 </script> 677 <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\"> 678 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"endtime_type\" value=\"1\" {$endtime_checked[1]} class=\"endtimes_check\" onclick=\"checkAction('endtime');\" style=\"vertical-align: middle;\" /> <strong>{$lang->set_time}</strong></label></dt> 679 <dd style=\"margin-top: 4px;\" id=\"endtime_1\" class=\"endtimes\"> 680 <table cellpadding=\"4\"> 681 <tr> 682 <td><select name=\"endtime_day\">\n{$enddateday}</select>\n \n<select name=\"endtime_month\">\n{$enddatemonth}</select>\n \n<input type=\"text\" name=\"endtime_year\" value=\"{$enddateyear}\" size=\"4\" maxlength=\"4\" />\n - {$lang->time} ".$form->generate_text_box('endtime_time', $mybb->input['endtime_time'], array('id' => 'endtime_time', 'style' => 'width: 50px;'))."</td> 683 </tr> 684 </table> 685 </dd> 686 <dt><label style=\"display: block;\"><input type=\"radio\" name=\"endtime_type\" value=\"2\" {$endtime_checked[2]} class=\"endtimes_check\" onclick=\"checkAction('endtime');\" style=\"vertical-align: middle;\" /> <strong>{$lang->never}</strong></label></dt> 687 </dl> 688 <script type=\"text/javascript\"> 689 checkAction('endtime'); 690 </script>"; 691 $form_container->output_row($lang->end_date." <em>*</em>", $lang->end_date_desc, $actions); 692 693 $form_container->output_row($lang->message." <em>*</em>", "", $form->generate_text_area('message', $mybb->input['message'], array('id' => 'message')), 'message'); 694 695 $form_container->output_row($lang->forums_to_appear_in." <em>*</em>", $lang->forums_to_appear_in_desc, $form->generate_forum_select('fid', $mybb->input['fid'], array('size' => 5, 'main_option' => $lang->all_forums))); 696 697 $form_container->output_row($lang->allow_html." <em>*</em>", "", $form->generate_yes_no_radio('allowhtml', $mybb->input['allowhtml'], array('style' => 'width: 2em;'))); 698 699 $form_container->output_row($lang->allow_mycode." <em>*</em>", "", $form->generate_yes_no_radio('allowmycode', $mybb->input['allowmycode'], array('style' => 'width: 2em;'))); 700 701 $form_container->output_row($lang->allow_smilies." <em>*</em>", "", $form->generate_yes_no_radio('allowsmilies', $mybb->input['allowsmilies'], array('style' => 'width: 2em;'))); 702 703 $form_container->end(); 704 705 $buttons[] = $form->generate_submit_button($lang->save_announcement); 706 $form->output_submit_wrapper($buttons); 707 $form->end(); 708 709 $page->output_footer(); 710 } 711 712 if($mybb->input['action'] == "delete") 713 { 714 $plugins->run_hooks("admin_forum_announcements_delete"); 715 716 $query = $db->simple_select("announcements", "*", "aid='{$mybb->input['aid']}'"); 717 $announcement = $db->fetch_array($query); 718 719 // Does the announcement not exist? 720 if(!$announcement['aid']) 721 { 722 flash_message($lang->error_invalid_announcement, 'error'); 723 admin_redirect("index.php?module=forum-announcements"); 724 } 725 726 // User clicked no 727 if($mybb->input['no']) 728 { 729 admin_redirect("index.php?module=forum-announcements"); 730 } 731 732 if($mybb->request_method == "post") 733 { 734 $db->delete_query("announcements", "aid='{$announcement['aid']}'"); 735 736 $plugins->run_hooks("admin_forum_announcements_delete_commit"); 737 738 // Log admin action 739 log_admin_action($announcement['aid'], $announcement['subject']); 740 $cache->update_forumsdisplay(); 741 742 flash_message($lang->success_announcement_deleted, 'success'); 743 admin_redirect("index.php?module=forum-announcements"); 744 } 745 else 746 { 747 $page->output_confirm_action("index.php?module=forum-announcements&action=delete&aid={$announcement['aid']}", $lang->confirm_announcement_deletion); 748 } 749 } 750 751 if(!$mybb->input['action']) 752 { 753 $plugins->run_hooks("admin_forum_announcements_start"); 754 755 $page->add_breadcrumb_item($lang->forum_announcements, "index.php?module=forum-announcements"); 756 757 $page->output_header($lang->forum_announcements); 758 759 $page->output_nav_tabs($sub_tabs, "forum_announcements"); 760 761 // Fetch announcements into their proper arrays 762 $global_announcements = $announcements = array(); 763 $query = $db->simple_select("announcements", "aid, fid, subject, enddate"); 764 while($announcement = $db->fetch_array($query)) 765 { 766 if($announcement['fid'] == -1) 767 { 768 $global_announcements[$announcement['aid']] = $announcement; 769 continue; 770 } 771 $announcements[$announcement['fid']][$announcement['aid']] = $announcement; 772 } 773 774 if(!empty($global_announcements)) 775 { 776 $table = new Table; 777 $table->construct_header($lang->announcement); 778 $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2, "width" => 150)); 779 780 // Get the global announcements 781 foreach($global_announcements as $aid => $announcement) 782 { 783 if($announcement['enddate'] < TIME_NOW && $announcement['enddate'] != 0) 784 { 785 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.gif\" alt=\"(Expired)\" title=\"Expired Announcement\" style=\"vertical-align: middle;\" /> "; 786 } 787 else 788 { 789 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.gif\" alt=\"(Active)\" title=\"Active Announcement\" style=\"vertical-align: middle;\" /> "; 790 } 791 792 $table->construct_cell($icon."<a href=\"index.php?module=forum-announcements&action=edit&aid={$aid}\">".htmlspecialchars_uni($announcement['subject'])."</a>"); 793 $table->construct_cell("<a href=\"index.php?module=forum-announcements&action=edit&aid={$aid}\">{$lang->edit}</a>", array("class" => "align_center", "width" => 75)); 794 $table->construct_cell("<a href=\"index.php?module=forum-announcements&action=delete&aid={$aid}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_announcement_deletion}')\">{$lang->delete}</a>", array("class" => "align_center", "width" => 75)); 795 $table->construct_row(); 796 } 797 $table->output($lang->global_announcements); 798 } 799 800 801 $table = new Table; 802 $table->construct_header($lang->announcement); 803 $table->construct_header($lang->controls, array("class" => "align_center", "colspan" => 2, "width" => 200)); 804 805 fetch_forum_announcements($table); 806 807 if($table->num_rows() == 0) 808 { 809 $table->construct_cell($lang->no_forums, array("colspan" => "3")); 810 $table->construct_row(); 811 } 812 813 $table->output($lang->forum_announcements); 814 815 $page->output_footer(); 816 } 817 818 function fetch_forum_announcements(&$table, $pid=0, $depth=1) 819 { 820 global $mybb, $db, $lang, $announcements, $page; 821 static $forums_by_parent; 822 823 if(!is_array($forums_by_parent)) 824 { 825 $forum_cache = cache_forums(); 826 827 foreach($forum_cache as $forum) 828 { 829 $forums_by_parent[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; 830 } 831 } 832 833 if(!is_array($forums_by_parent[$pid])) 834 { 835 return; 836 } 837 838 foreach($forums_by_parent[$pid] as $children) 839 { 840 foreach($children as $forum) 841 { 842 $forum['name'] = htmlspecialchars_uni($forum['name']); 843 if($forum['active'] == 0) 844 { 845 $forum['name'] = "<em>".$forum['name']."</em>"; 846 } 847 848 if($forum['type'] == "c") 849 { 850 $forum['name'] = "<strong>".$forum['name']."</strong>"; 851 } 852 853 $table->construct_cell("<div style=\"padding-left: ".(40*($depth-1))."px;\">{$forum['name']}</div>"); 854 $table->construct_cell("<a href=\"index.php?module=forum-announcements&action=add&fid={$forum['fid']}\">{$lang->add_announcement}</a>", array("class" => "align_center", "colspan" => 2)); 855 $table->construct_row(); 856 857 if(isset($announcements[$forum['fid']])) 858 { 859 foreach($announcements[$forum['fid']] as $aid => $announcement) 860 { 861 if($announcement['enddate'] < TIME_NOW && $announcement['enddate'] != 0) 862 { 863 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.gif\" alt=\"(Expired)\" title=\"Expired Announcement\" style=\"vertical-align: middle;\" /> "; 864 } 865 else 866 { 867 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.gif\" alt=\"(Active)\" title=\"Active Announcement\" style=\"vertical-align: middle;\" /> "; 868 } 869 870 $table->construct_cell("<div style=\"padding-left: ".(40*$depth)."px;\">{$icon}<a href=\"index.php?module=forum-announcements&action=edit&aid={$aid}\">".htmlspecialchars_uni($announcement['subject'])."</a></div>"); 871 $table->construct_cell("<a href=\"index.php?module=forum-announcements&action=edit&aid={$aid}\">{$lang->edit}</a>", array("class" => "align_center")); 872 $table->construct_cell("<a href=\"index.php?module=forum-announcements&action=delete&aid={$aid}&my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_announcement_deletion}')\">{$lang->delete}</a>", array("class" => "align_center")); 873 $table->construct_row(); 874 } 875 } 876 877 // Build the list for any sub forums of this forum 878 if(isset($forums_by_parent[$forum['fid']])) 879 { 880 fetch_forum_announcements($table, $forum['fid'], $depth+1); 881 } 882 } 883 } 884 } 885 886 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Oct 8 19:19:50 2013 | Cross-referenced by PHPXref 0.7.1 |