[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/config/ -> thread_prefixes.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: thread_prefixes.php 5352 2011-02-15 12:57:18Z 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->thread_prefixes, 'index.php?module=config-thread_prefixes');
  19  
  20  $sub_tabs = array(
  21      "thread_prefixes" => array(
  22          'title' => $lang->thread_prefixes,
  23          'link' => 'index.php?module=config-thread_prefixes',
  24          'description' => $lang->thread_prefixes_desc
  25      ),
  26      "add_prefix" => array(
  27          'title'=> $lang->add_new_thread_prefix,
  28          'link' => 'index.php?module=config-thread_prefixes&amp;action=add_prefix',
  29          'description' => $lang->add_new_thread_prefix_desc
  30      )
  31  );
  32  
  33  $plugins->run_hooks('admin_config_thread_prefixes_begin');
  34  
  35  if($mybb->input['action'] == 'add_prefix')
  36  {
  37      $plugins->run_hooks('admin_config_thread_prefixes_add_prefix');
  38      
  39      if($mybb->request_method == 'post')
  40      {
  41          if(trim($mybb->input['prefix']) == '')
  42          {
  43              $errors[] = $lang->error_missing_prefix;
  44          }
  45          
  46          if(trim($mybb->input['displaystyle']) == '')
  47          {
  48              $errors[] = $lang->error_missing_display_style;
  49          }
  50          
  51          if($mybb->input['forum_type'] == 2)
  52          {
  53              if(count($mybb->input['forum_1_forums']) < 1)
  54              {
  55                  $errors[] = $lang->error_no_forums_selected;
  56              }
  57  
  58              $forum_checked[2] = "checked=\"checked\"";
  59          }
  60          else
  61          {
  62              $forum_checked[1] = "checked=\"checked\"";
  63              $mybb->input['forum_1_forums'] = '';
  64          }
  65          
  66          if($mybb->input['group_type'] == 2)
  67          {
  68              if(count($mybb->input['group_1_groups']) < 1)
  69              {
  70                  $errors[] = $lang->error_no_groups_selected;
  71              }
  72  
  73              $group_checked[2] = "checked=\"checked\"";
  74          }
  75          else
  76          {
  77              $group_checked[1] = "checked=\"checked\"";
  78              $mybb->input['group_1_forums'] = '';
  79          }
  80          
  81          if(!$errors)
  82          {
  83              $new_prefix = array(
  84                  'prefix'        => $db->escape_string($mybb->input['prefix']),
  85                  'displaystyle'    => $db->escape_string($mybb->input['displaystyle'])
  86              );
  87              
  88              if($mybb->input['forum_type'] == 2)
  89              {
  90                  if(is_array($mybb->input['forum_1_forums']))
  91                  {
  92                      $checked = array();
  93                      foreach($mybb->input['forum_1_forums'] as $fid)
  94                      {
  95                          $checked[] = intval($fid);
  96                      }
  97                      
  98                      $new_prefix['forums'] = implode(',', $checked);
  99                  }
 100              }
 101              else
 102              {
 103                  $new_prefix['forums'] = '-1';
 104              }
 105              
 106              if($mybb->input['group_type'] == 2)
 107              {
 108                  if(is_array($mybb->input['group_1_groups']))
 109                  {
 110                      $checked = array();
 111                      foreach($mybb->input['group_1_groups'] as $gid)
 112                      {
 113                          $checked[] = intval($gid);
 114                      }
 115                      
 116                      $new_prefix['groups'] = implode(',', $checked);
 117                  }
 118              }
 119              else
 120              {
 121                  $new_prefix['groups'] = '-1';
 122              }
 123              
 124              $pid = $db->insert_query('threadprefixes', $new_prefix);
 125              
 126              $plugins->run_hooks('admin_config_thread_prefixes_add_prefix_commit');
 127              
 128              // Log admin action
 129              log_admin_action($pid, $mybb->input['prefix']);
 130              $cache->update_threadprefixes();
 131              
 132              flash_message($lang->success_thread_prefix_created, 'success');
 133              admin_redirect('index.php?module=config-thread_prefixes');
 134          }
 135      }
 136      
 137      $page->add_breadcrumb_item($lang->add_new_thread_prefix);
 138      $page->output_header($lang->thread_prefixes." - ".$lang->add_new_thread_prefix);
 139      $page->output_nav_tabs($sub_tabs, 'add_prefix');
 140      
 141      $form = new Form('index.php?module=config-thread_prefixes&amp;action=add_prefix', 'post');
 142      
 143      if($errors)
 144      {
 145          $page->output_inline_error($errors);
 146      }
 147      else
 148      {
 149          $mybb->input['prefix'] = '';
 150          $mybb->input['displaystyle'] = '';
 151          $mybb->input['forum_1_forums'] = '';
 152          $forum_checked[1] = "checked=\"checked\"";
 153          $forum_checked[2] = '';
 154          $mybb->input['group_1_groups'] = '';
 155          $group_checked[1] = "checked=\"checked\"";
 156          $group_checked[2] = '';
 157      }
 158      
 159      $form_container = new FormContainer($lang->prefix_options);
 160      $form_container->output_row($lang->prefix.' <em>*</em>', $lang->prefix_desc, $form->generate_text_box('prefix', $mybb->input['prefix'], array('id' => 'prefix')), 'prefix');
 161      $form_container->output_row($lang->display_style.' <em>*</em>', $lang->display_style_desc, $form->generate_text_box('displaystyle', $mybb->input['displaystyle'], array('id' => 'displaystyle')), 'displaystyle');
 162      
 163      $actions = "<script type=\"text/javascript\">
 164      function checkAction(id)
 165      {
 166          var checked = '';
 167          
 168          $$('.'+id+'s_check').each(function(e)
 169          {
 170              if(e.checked == true)
 171              {
 172                  checked = e.value;
 173              }
 174          });
 175          $$('.'+id+'s').each(function(e)
 176          {
 177              Element.hide(e);
 178          });
 179          if($(id+'_'+checked))
 180          {
 181              Element.show(id+'_'+checked);
 182          }
 183      }    
 184  </script>
 185      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 186      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
 187          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
 188          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
 189              <table cellpadding=\"4\">
 190                  <tr>
 191                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
 192                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
 193                  </tr>
 194              </table>
 195          </dd>
 196      </dl>
 197      <script type=\"text/javascript\">
 198      checkAction('forum');
 199      </script>";
 200      $form_container->output_row($lang->available_in_forums.' <em>*</em>', '', $actions);
 201      
 202      $group_select = "
 203      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
 204      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
 205          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
 206          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
 207              <table cellpadding=\"4\">
 208                  <tr>
 209                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
 210                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
 211                  </tr>
 212              </table>
 213          </dd>
 214      </dl>
 215      <script type=\"text/javascript\">
 216          checkAction('group');
 217      </script>";
 218      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $group_select);
 219      
 220      $form_container->end();
 221      
 222      $buttons[] = $form->generate_submit_button($lang->save_thread_prefix);
 223      
 224      $form->output_submit_wrapper($buttons);
 225      $form->end();
 226      
 227      $page->output_footer();
 228  }
 229  
 230  if($mybb->input['action'] == 'edit_prefix')
 231  {
 232      $plugins->run_hooks('admin_config_thread_prefixes_edit_prefix_start');
 233      
 234      $prefix = build_prefixes($mybb->input['pid']);
 235      if(!$prefix['pid'])
 236      {
 237          flash_message($lang->error_invalid_prefix, 'error');
 238          admin_redirect('index.php?module=config-thread_prefixes');
 239      }
 240      
 241      if($mybb->request_method == 'post')
 242      {
 243          if(trim($mybb->input['prefix']) == '')
 244          {
 245              $errors[] = $lang->error_missing_prefix;
 246          }
 247          
 248          if(trim($mybb->input['displaystyle']) == '')
 249          {
 250              $errors[] = $lang->error_missing_display_style;
 251          }
 252          
 253          if($mybb->input['forum_type'] == 2)
 254          {
 255              if(count($mybb->input['forum_1_forums']) < 1)
 256              {
 257                  $errors[] = $lang->error_no_forums_selected;
 258              }
 259  
 260              $forum_checked[2] = "checked=\"checked\"";
 261          }
 262          else
 263          {
 264              $forum_checked[1] = "checked=\"checked\"";
 265              $mybb->input['forum_1_forums'] = '';
 266          }
 267          
 268          if($mybb->input['group_type'] == 2)
 269          {
 270              if(count($mybb->input['group_1_groups']) < 1)
 271              {
 272                  $errors[] = $lang->error_no_groups_selected;
 273              }
 274  
 275              $group_checked[2] = "checked=\"checked\"";
 276          }
 277          else
 278          {
 279              $group_checked[1] = "checked=\"checked\"";
 280              $mybb->input['group_1_forums'] = '';
 281          }
 282          
 283          if(!$errors)
 284          {
 285              $update_prefix = array(
 286                  'prefix'        => $db->escape_string($mybb->input['prefix']),
 287                  'displaystyle'    => $db->escape_string($mybb->input['displaystyle'])
 288              );
 289              
 290              if($mybb->input['forum_type'] == 2)
 291              {
 292                  if(is_array($mybb->input['forum_1_forums']))
 293                  {
 294                      $checked = array();
 295                      foreach($mybb->input['forum_1_forums'] as $fid)
 296                      {
 297                          $checked[] = intval($fid);
 298                      }
 299                      
 300                      $update_prefix['forums'] = implode(',', $checked);
 301                  }
 302              }
 303              else
 304              {
 305                  $update_prefix['forums'] = '-1';
 306              }
 307              
 308              if($mybb->input['group_type'] == 2)
 309              {
 310                  if(is_array($mybb->input['group_1_groups']))
 311                  {
 312                      $checked = array();
 313                      foreach($mybb->input['group_1_groups'] as $gid)
 314                      {
 315                          $checked[] = intval($gid);
 316                      }
 317                      
 318                      $update_prefix['groups'] = implode(',', $checked);
 319                  }
 320              }
 321              else
 322              {
 323                  $update_prefix['groups'] = '-1';
 324              }
 325              
 326              $db->update_query('threadprefixes', $update_prefix, "pid='{$mybb->input['pid']}'");
 327              
 328              $plugins->run_hooks('admin_config_thread_prefixes_edit_prefix_commit');
 329              
 330              // Log admin action
 331              log_admin_action($mybb->input['pid'], $mybb->input['prefix']);
 332              $cache->update_threadprefixes();
 333              
 334              flash_message($lang->success_thread_prefix_updated, 'success');
 335              admin_redirect('index.php?module=config-thread_prefixes');
 336          }
 337      }
 338      
 339      $page->add_breadcrumb_item($lang->edit_thread_prefix);
 340      $page->output_header($lang->thread_prefixes.' - '.$lang->edit_thread_prefix);
 341  
 342      // Setup the edit prefix tab
 343      unset($sub_tabs);
 344      $sub_tabs['edit_prefix'] = array(
 345          "title" => $lang->edit_prefix,
 346          "link" => "index.php?module=config-thread_prefixes",
 347          "description" => $lang->edit_prefix_desc
 348      );
 349      $page->output_nav_tabs($sub_tabs, "edit_prefix");
 350  
 351      $form = new Form('index.php?module=config-thread_prefixes&amp;action=edit_prefix', 'post');
 352      echo $form->generate_hidden_field('pid', $mybb->input['pid']);
 353      
 354      if($errors)
 355      {
 356          $page->output_inline_error($errors);
 357      }
 358      else
 359      {
 360          $query = $db->simple_select('threadprefixes', '*', "pid = '{$mybb->input['pid']}'");
 361          $threadprefix = $db->fetch_array($query);
 362          
 363          $mybb->input['prefix'] = $threadprefix['prefix'];
 364          $mybb->input['displaystyle'] = $threadprefix['displaystyle'];
 365          $mybb->input['forum_1_forums'] = explode(",", $threadprefix['forums']);
 366  
 367          if(!$threadprefix['forums'] || $threadprefix['forums'] == -1)
 368          {
 369              $forum_checked[1] = "checked=\"checked\"";
 370              $forum_checked[2] = '';
 371          }
 372          else
 373          {
 374              $forum_checked[1] = '';
 375              $forum_checked[2] = "checked=\"checked\"";
 376          }
 377          
 378          $mybb->input['group_1_groups'] = explode(",", $threadprefix['groups']);
 379  
 380          if(!$threadprefix['groups'] || $threadprefix['groups'] == -1)
 381          {
 382              $group_checked[1] = "checked=\"checked\"";
 383              $group_checked[2] = '';
 384          }
 385          else
 386          {
 387              $group_checked[1] = '';
 388              $group_checked[2] = "checked=\"checked\"";
 389          }
 390      }
 391      
 392      $form_container = new FormContainer($lang->prefix_options);
 393      $form_container->output_row($lang->prefix.' <em>*</em>', $lang->prefix_desc, $form->generate_text_box('prefix', $mybb->input['prefix'], array('id' => 'prefix')), 'prefix');
 394      $form_container->output_row($lang->display_style.' <em>*</em>', $lang->display_style_desc, $form->generate_text_box('displaystyle', $mybb->input['displaystyle'], array('id' => 'displaystyle')), 'displaystyle');
 395      
 396      $actions = "<script type=\"text/javascript\">
 397      function checkAction(id)
 398      {
 399          var checked = '';
 400          
 401          $$('.'+id+'s_check').each(function(e)
 402          {
 403              if(e.checked == true)
 404              {
 405                  checked = e.value;
 406              }
 407          });
 408          $$('.'+id+'s').each(function(e)
 409          {
 410              Element.hide(e);
 411          });
 412          if($(id+'_'+checked))
 413          {
 414              Element.show(id+'_'+checked);
 415          }
 416      }    
 417  </script>
 418      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%;\">
 419      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"1\" {$forum_checked[1]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_forums}</strong></label></dt>
 420          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"forum_type\" value=\"2\" {$forum_checked[2]} class=\"forums_check\" onclick=\"checkAction('forum');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_forums}</strong></label></dt>
 421          <dd style=\"margin-top: 4px;\" id=\"forum_2\" class=\"forums\">
 422              <table cellpadding=\"4\">
 423                  <tr>
 424                      <td valign=\"top\"><small>{$lang->forums_colon}</small></td>
 425                      <td>".$form->generate_forum_select('forum_1_forums[]', $mybb->input['forum_1_forums'], array('multiple' => true, 'size' => 5))."</td>
 426                  </tr>
 427              </table>
 428          </dd>
 429      </dl>
 430      <script type=\"text/javascript\">
 431      checkAction('forum');
 432      </script>";
 433      $form_container->output_row($lang->available_in_forums.' <em>*</em>', '', $actions);
 434      
 435      $group_select = "
 436      <dl style=\"margin-top: 0; margin-bottom: 0; width: 100%\">
 437      <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"1\" {$group_checked[1]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->all_groups}</strong></label></dt>
 438          <dt><label style=\"display: block;\"><input type=\"radio\" name=\"group_type\" value=\"2\" {$group_checked[2]} class=\"groups_check\" onclick=\"checkAction('group');\" style=\"vertical-align: middle;\" /> <strong>{$lang->select_groups}</strong></label></dt>
 439          <dd style=\"margin-top: 4px;\" id=\"group_2\" class=\"groups\">
 440              <table cellpadding=\"4\">
 441                  <tr>
 442                      <td valign=\"top\"><small>{$lang->groups_colon}</small></td>
 443                      <td>".$form->generate_group_select('group_1_groups[]', $mybb->input['group_1_groups'], array('multiple' => true, 'size' => 5))."</td>
 444                  </tr>
 445              </table>
 446          </dd>
 447      </dl>
 448      <script type=\"text/javascript\">
 449          checkAction('group');
 450      </script>";
 451      $form_container->output_row($lang->available_to_groups." <em>*</em>", '', $group_select);
 452      
 453      $form_container->end();
 454      
 455      $buttons[] = $form->generate_submit_button($lang->save_thread_prefix);
 456      
 457      $form->output_submit_wrapper($buttons);
 458      $form->end();
 459      
 460      $page->output_footer();
 461  }
 462  
 463  if($mybb->input['action'] == 'delete_prefix')
 464  {
 465      $plugins->run_hooks('admin_config_thread_prefixes_delete_prefix');
 466      
 467      $prefix = build_prefixes($mybb->input['pid']);
 468      if(!$prefix['pid'])
 469      {
 470          flash_message($lang->error_invalid_thread_prefix, 'error');
 471          admin_redirect('index.php?module=config-thread_prefixes');
 472      }
 473      
 474      // User clicked no
 475      if($mybb->input['no'])
 476      {
 477          admin_redirect('index.php?module=config-thread_prefixes');
 478      }
 479      
 480      if($mybb->request_method == 'post')
 481      {
 482          // Remove prefix from existing threads
 483          $update_threads = array('prefix' => 0);
 484          $db->update_query('threads', $update_threads, "prefix='{$prefix['pid']}'");
 485          
 486          // Delete prefix
 487          $db->delete_query('threadprefixes', "pid='{$prefix['pid']}'");
 488          
 489          $plugins->run_hooks('admin_config_thread_prefixes_delete_thread_prefix_commit');
 490          
 491          // Log admin action
 492          log_admin_action($prefix['pid'], $prefix['prefix']);
 493          $cache->update_threadprefixes();
 494          
 495          flash_message($lang->success_thread_prefix_deleted, 'success');
 496          admin_redirect('index.php?module=config-thread_prefixes');
 497      }
 498      else
 499      {
 500          $page->output_confirm_action("index.php?module=config-thread_prefixes&amp;action=delete_prefix&amp;pid={$mybb->input['pid']}", $lang->confirm_thread_prefix_deletion);
 501      }
 502  }
 503  
 504  if(!$mybb->input['action'])
 505  {
 506      $plugins->run_hooks('admin_config_thread_prefixes_start');
 507      
 508      $page->output_header($lang->thread_prefixes);
 509      $page->output_nav_tabs($sub_tabs, 'thread_prefixes');
 510      
 511      $table = new Table;
 512      $table->construct_header($lang->prefix);
 513      $table->construct_header($lang->controls, array('class' => 'align_center', 'colspan' => 2));
 514      
 515      $prefixes = build_prefixes();
 516      if($prefixes)
 517      {
 518          foreach($prefixes as $prefix)
 519          {
 520              $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=edit_prefix&amp;pid={$prefix['pid']}\"><strong>".htmlspecialchars_uni($prefix['prefix'])."</strong></a>");
 521              $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=edit_prefix&amp;pid={$prefix['pid']}\">{$lang->edit}</a>", array('width' => 100, 'class' => "align_center"));
 522              $table->construct_cell("<a href=\"index.php?module=config-thread_prefixes&amp;action=delete_prefix&amp;pid={$prefix['pid']}&amp;my_post_key={$mybb->post_code}\" onclick=\"return AdminCP.deleteConfirmation(this, '{$lang->confirm_thread_prefix_deletion}')\">{$lang->delete}</a>", array('width' => 100, 'class' => 'align_center'));
 523              $table->construct_row();
 524          }
 525      }
 526      
 527      if($table->num_rows() == 0)
 528      {
 529          $table->construct_cell($lang->no_thread_prefixes, array('colspan' => 3));
 530          $table->construct_row();
 531      }
 532      
 533      $table->output($lang->thread_prefixes);
 534      
 535      $page->output_footer();
 536  }
 537  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1