[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

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

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


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1