[ Index ]

PHP Cross Reference of MyBB 1.8.21

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


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