[ Index ]

PHP Cross Reference of MyBB 1.8.38

title

Body

[close]

/admin/modules/forum/ -> announcements.php (source)

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


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref