decir/admincp/admin_forums.php
author Dan
Tue, 13 Nov 2007 23:33:14 -0500
changeset 9 6d9655e02026
parent 7 37387f84fe25
permissions -rw-r--r--
Removed all dragger debugging info and started on the form for forum/category deletion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     1
<?php
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     2
/*
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     3
 * Decir
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     4
 * Version 0.1
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     5
 * Copyright (C) 2007 Dan Fuhry
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     6
 * admin_forums.php - forum creation and management frontend
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     7
 *
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    10
 *
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    13
 */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    14
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    15
$decir_menu['DecirForums'] = 'Manage forums';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    16
require( DECIR_ROOT . '/constants.php' );
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    17
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    18
function page_Admin_DecirForums()
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    19
{
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    20
  global $db, $session, $paths, $template, $plugins; // Common objects
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    21
  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    22
  {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    23
    echo '<h3>Error: Not authenticated</h3><p>It looks like your administration session is invalid or you are not authorized to access this administration page. Please <a href="' . makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true) . '">re-authenticate</a> to continue.</p>';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    24
    return;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    25
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    26
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    27
  $show_main_menu = true;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    28
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    29
  if ( isset($_POST['act']) )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    30
  {
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    31
    $act = ( strpos($_POST['act'], ';') ) ? substr($_POST['act'], 0, strpos($_POST['act'], ';')) : $_POST['act'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    32
    if ( strpos($_POST['act'], ';') )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    33
    {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    34
      $parms = substr($_POST['act'], strpos($_POST['act'], ';') + 1);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    35
      preg_match_all('/([a-z0-9_]+)=([^;]*)/', $parms, $matches);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    36
      $parms = array();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    37
      foreach ( $matches[2] as $id => $parmdata )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    38
      {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    39
        if ( preg_match('/^[0-9]+$/', $parmdata) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    40
          $parmdata = intval($parmdata);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    41
        $parms[ $matches[1][$id] ] = $parmdata;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    42
      }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    43
    }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    44
    switch ( $act )
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    45
    {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    46
      case "create":
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    47
      case "create_finish":
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    48
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    49
        // Do we have any categories yet?
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    50
        $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . 'decir_forums WHERE forum_type = ' . FORUM_CATEGORY . ';');
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    51
        if ( !$q )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    52
          $db->_die('Decir admin_forums.php retrieving category count');
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    53
        $need_category = ( $db->numrows() < 1 );
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    54
        $cats = array();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    55
        if ( !$need_category )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    56
        {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    57
          while ( list($cat_id, $cat_name) = $db->fetchrow_num() )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    58
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    59
            $cats[ $cat_id ] = $cat_name;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    60
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    61
        }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    62
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    63
        $db->free_result();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    64
        
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    65
        if ( $act == 'create_finish' )
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    66
        {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    67
          $errors = array();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    68
          $forum_type = intval($_POST['forum_type']);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    69
          if ( $forum_type != FORUM_FORUM && $forum_type != FORUM_CATEGORY )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    70
            $errors[] = 'Invalid forum type. <tt>X.X</tt>';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    71
          $forum_name = trim($_POST['forum_name']);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    72
          if ( empty($forum_name) )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    73
            $errors[] = 'Please enter a name for this forum.';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    74
          $forum_desc = '';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    75
          $forum_parent = 0;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    76
          if ( $forum_type == FORUM_FORUM )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    77
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    78
            $forum_desc = trim($_POST['forum_desc']);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    79
            if ( empty($forum_desc) )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    80
              $errors[] = 'Please enter a description for this forum.';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    81
            $forum_parent = intval($_POST['forum_parent']);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    82
            if ( !isset($cats[$forum_parent]) )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    83
              $errors[] = 'Invalid parent category';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    84
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    85
          if ( count($errors) > 0 )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    86
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    87
            // Errors encountered - bounce form back to the user
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    88
            $show_main_menu = false;
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
    89
            echo '<div class="error-box">The forum could not be created.<ul><li>' . implode("</li>\n      <li>", $errors) . '</li></ul></div>';
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    90
            $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    91
            $form->forum_name = $forum_name;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    92
            $form->forum_desc = $forum_desc;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    93
            $form->forum_type = $forum_type;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    94
            $form->need_category = $need_category;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    95
            $form->category_list = $cats;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    96
            echo $form->html();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    97
            break;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    98
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
    99
          // All checks passed. Create forum.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   100
          $forum_name_db = $db->escape($forum_name);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   101
          $forum_desc_db = $db->escape($forum_desc);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   102
          $sql = 'INSERT INTO ' . table_prefix . "decir_forums(forum_name, forum_desc, forum_type, parent, num_topics, num_posts) VALUES\n"
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   103
                 . "  ( '$forum_name_db', '$forum_desc_db', $forum_type, $forum_parent, 0, 0 );";
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   104
          if ( $db->sql_query($sql) )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   105
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   106
            $forum_name = htmlspecialchars($forum_name);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   107
            $type = ( $forum_type == FORUM_FORUM ) ? 'forum' : 'category';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   108
            echo "<div class=\"info-box\">The {$type} \"{$forum_name}\" has been created successfully.</div>";
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   109
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   110
          break;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   111
        }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   112
        // Create a smartform
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   113
        $show_main_menu = false;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   114
        $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   115
        $form->need_category = $need_category;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   116
        $form->category_list = $cats;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   117
        echo $form->html();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   118
        break;
9
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   119
      case 'delete':
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   120
      case 'delete_finish':
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   121
        if ( !isset($parms['fid']) || ( isset($parms['fid']) && !is_int($parms['fid']) ) )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   122
        {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   123
          echo '<div class="error-box">Invalid forum ID passed to editor.</div>';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   124
          break;
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   125
        }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   126
        
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   127
        // $fid is safe (validated as an integer).
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   128
        $fid =& $parms['fid'];
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   129
        $q = $db->sql_query('SELECT forum_id, forum_name, forum_type FROM ' . table_prefix . 'decir_forums WHERE forum_id = ' . $fid . ';');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   130
        if ( !$q )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   131
          $db->_die('Decir admin_forums.php selecting forum data for deletion');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   132
        
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   133
        $row = $db->fetchrow();
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   134
        $db->free_result();
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   135
        
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   136
        if ( $row['forum_type'] == FORUM_FORUM )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   137
        {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   138
          // Provide the option of moving the posts in this forum to another forum
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   139
          $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . "decir_forums WHERE forum_id != {$row['forum_id']} AND forum_type = " . FORUM_FORUM . ';');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   140
          if ( !$q )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   141
            $db->_die('Decir admin_forums.php selecting list of possible forums to move topics to');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   142
          $opt_move = '';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   143
          if ( $db->numrows() > 0 )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   144
          {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   145
            $opt_move .= '<p><label><input type="radio" name="with_content" value="move" /> Move to forum:</label><br />
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   146
                             <select name="move_to">';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   147
            while ( $drow = $db->fetchrow() )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   148
            {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   149
              $opt_move .= "<option value=\"{$drow['forum_id']}\">" . htmlspecialchars($drow['forum_name']) . '</option>';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   150
            }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   151
            $opt_move .= "</select></p>";
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   152
          }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   153
        }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   154
        else if ( $row['forum_type'] == FORUM_CATEGORY )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   155
        {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   156
          // Provide the option of moving the posts in this forum to another forum
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   157
          $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . "decir_forums WHERE forum_id != {$row['forum_id']} AND forum_type = " . FORUM_CATEGORY . ';');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   158
          if ( !$q )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   159
            $db->_die('Decir admin_forums.php selecting list of possible categories to move forums to');
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   160
          $opt_move = '';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   161
          if ( $db->numrows() > 0 )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   162
          {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   163
            $opt_move .= '<p><label><input type="radio" name="with_content" value="move" /> Move to category:</label><br />
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   164
                             <select name="move_to">';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   165
            while ( $drow = $db->fetchrow() )
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   166
            {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   167
              $opt_move .= "<option value=\"{$drow['forum_id']}\">" . htmlspecialchars($drow['forum_name']) . '</option>';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   168
            }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   169
            $opt_move .= "</select></p>";
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   170
          }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   171
        }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   172
        else
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   173
        {
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   174
          break;
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   175
        }
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   176
        
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   177
        $forcat = ( $row['forum_type'] == FORUM_FORUM ) ? 'forum' : 'category';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   178
        echo '<div class="tblholder">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   179
                <table border="0" cellspacing="1" cellpadding="4">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   180
                  <tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   181
                    <th>Deleting ' . $forcat . '</th>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   182
                  </tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   183
                  <tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   184
                    <td class="row2">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   185
                      <div style="margin: 0 auto; display: table;">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   186
                      <p><b>You are about to obliterate the '. $forcat .' "' . htmlspecialchars($row['forum_name']) . '".</b><br />
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   187
                         You can either preserve its contents or delete them. Beware that if you are deleting a<br />
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   188
                         ' . $forcat . ' with a large number of posts in it, this process may take some time.</p>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   189
                      </div>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   190
                      <div style="margin: 0 auto; display: table;">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   191
                      <p><label><input type="radio" checked="checked" name="with_content" value="delete" /> Delete contents</p>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   192
                      ' . $opt_move . '
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   193
                      </div>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   194
                    </td>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   195
                  </tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   196
                  <tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   197
                    <td class="row1" style="text-align: center;">
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   198
                      <button name="act" value="delete_finish;fid=' . $row['forum_id'] . '"><span style="font-weight: bold; color: red;">Delete forum</span></button>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   199
                      <button name="act" value="noop" style="font-weight: normal;">Cancel</button>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   200
                    </td>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   201
                  </tr>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   202
                </table>
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   203
              </div>';
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   204
              
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   205
        $show_main_menu = false;
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   206
        
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   207
        break;
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   208
      case 'edit':
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   209
      case 'edit_finish':
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   210
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   211
        if ( !isset($parms['fid']) || ( isset($parms['fid']) && !is_int($parms['fid']) ) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   212
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   213
          echo '<div class="error-box">Invalid forum ID passed to editor.</div>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   214
          break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   215
        }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   216
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   217
        // Fetch category list
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   218
        $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . 'decir_forums WHERE forum_type = ' . FORUM_CATEGORY . ';');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   219
        if ( !$q )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   220
          $db->_die('Decir admin_forums.php retrieving category count');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   221
        $need_category = ( $db->numrows() < 1 );
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   222
        $cats = array();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   223
        if ( !$need_category )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   224
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   225
          while ( list($cat_id, $cat_name) = $db->fetchrow_num() )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   226
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   227
            $cats[ $cat_id ] = $cat_name;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   228
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   229
        }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   230
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   231
        $db->free_result();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   232
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   233
        // $fid is safe (validated as an integer).
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   234
        $fid =& $parms['fid'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   235
        $q = $db->sql_query('SELECT forum_id, forum_name, forum_desc, parent, forum_type FROM ' . table_prefix . 'decir_forums WHERE forum_id = ' . $fid . ';');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   236
        if ( !$q )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   237
          $db->_die('Decir admin_forums.php selecting forum data for edit');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   238
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   239
        $row = $db->fetchrow();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   240
        $db->free_result();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   241
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   242
        if ( $act == 'edit_finish' )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   243
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   244
          $errors = array();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   245
          // Validate and update
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   246
          if ( $row['forum_type'] == FORUM_FORUM )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   247
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   248
            $forum_name = trim($_POST['forum_name']);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   249
            if ( empty($forum_name) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   250
              $errors[] = 'Please enter a name for this forum.';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   251
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   252
            $forum_desc = trim($_POST['forum_desc']);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   253
            if ( empty($forum_desc) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   254
              $errors[] = 'Please enter a description for this forum.';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   255
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   256
            $forum_parent = intval($_POST['forum_parent']);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   257
            if ( !isset($cats[$forum_parent]) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   258
              $errors[] = 'Invalid parent category';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   259
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   260
            $forum_name_db = $db->escape($forum_name);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   261
            $forum_desc_db = $db->escape($forum_desc);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   262
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   263
            $sql = 'UPDATE ' . table_prefix . "decir_forums SET forum_name='$forum_name_db',forum_desc='$forum_desc_db',parent=$forum_parent WHERE forum_id = $fid;";
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   264
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   265
          else if ( $row['forum_type'] == FORUM_CATEGORY )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   266
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   267
            $forum_name = trim($_POST['forum_name']);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   268
            if ( empty($forum_name) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   269
              $errors[] = 'Please enter a name for this forum.';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   270
            $forum_name_db = $db->escape($forum_name);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   271
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   272
            $sql = 'UPDATE ' . table_prefix . "decir_forums SET forum_name='$forum_name_db' WHERE forum_id = $fid;";
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   273
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   274
          else
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   275
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   276
            $db->_die('Mom, I feel sick. Can I lay down for a while? ' . __FILE__ . ':' . __LINE__);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   277
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   278
          if ( count($errors) < 1 )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   279
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   280
            if ( $db->sql_query($sql) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   281
            {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   282
              $show_main_menu = true;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   283
              echo '<div class="info-box">The forum or category was updated.</div>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   284
              break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   285
            }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   286
            else
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   287
            {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   288
              $db->_die('Decir admin_forums.php update forum main SQL query');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   289
            }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   290
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   291
          else
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   292
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   293
            echo '<div class="error-box">The forum was not updated because you entered something invalid.<ul><li>' . implode("</li>\n      <li>", $errors) . '</li></ul></div>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   294
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   295
        }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   296
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   297
        // This is the amazing part. We'll let the smart form do the work for us.
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   298
        $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_EDIT);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   299
        $form->forum_name = $row['forum_name'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   300
        $form->forum_desc = $row['forum_desc'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   301
        $form->forum_type = $row['forum_type'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   302
        $form->forum_parent = $row['parent'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   303
        $form->forum_id = $row['forum_id'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   304
        $form->category_list = $cats;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   305
        echo $form->html();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   306
        
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   307
        $show_main_menu = false;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   308
        break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   309
      case 'save_order':
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   310
        $order = explode(',', $_POST['forum_order']);
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   311
        $i = 0;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   312
        $sql = array();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   313
        foreach ( $order as $forum_id )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   314
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   315
          $i++;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   316
          if ( strval(intval($forum_id)) != $forum_id )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   317
          {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   318
            echo '<p>Hacking attempt</p>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   319
            break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   320
          }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   321
          $sql[] = 'UPDATE ' . table_prefix . "decir_forums SET forum_order = $i WHERE forum_id = $forum_id;";
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   322
        }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   323
        foreach ( $sql as $s )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   324
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   325
          if ( !$db->sql_query($s) )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   326
            $db->_die('Decir admin_forums.php updating forum order');
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   327
        }
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   328
        echo '<div class="info-box">The forum order was updated.</div>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   329
        break;
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   330
    }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   331
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   332
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   333
  if ( $show_main_menu )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   334
  {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   335
    // Display the main forum admin interface
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   336
    $form_url = makeUrlNS('Special', 'DecirAdmin', "module={$paths->nslist['Admin']}DecirForums", true);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   337
    echo "<form action=\"$form_url\" method=\"post\" enctype=\"multipart/form-data\">";
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   338
    echo '<div class="tblholder">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   339
            <table border="0" cellspacing="1" cellpadding="4">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   340
              <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   341
                <th colspan="4">Forum administration</th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   342
              </tr>';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   343
    // Select and display all forums
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   344
    $q = $db->sql_unbuffered_query('SELECT forum_id, forum_name, forum_desc, forum_type, num_topics, num_posts FROM ' . table_prefix . 'decir_forums GROUP BY parent, forum_id ORDER BY forum_order;');
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   345
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   346
    if ( !$q )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   347
      $db->_die('Decir admin_forums.php selecting main forum datum');
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   348
    
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   349
    $order_forums = array();
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   350
    $order_cats = array();
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   351
    if ( $row = $db->fetchrow() )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   352
    {
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   353
      $cat_open = false;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   354
      echo '<tr>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   355
              <th class="subhead">Forum</th>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   356
              <th class="subhead" style="max-width: 50px;">Topics</th>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   357
              <th class="subhead" style="max-width: 50px;">Posts</th>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   358
              <th class="subhead">Admin tasks</th>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   359
            </tr>';
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   360
      do
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   361
      {
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   362
        switch ( $row['forum_type'] )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   363
        {
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   364
          case FORUM_FORUM:
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   365
            // Forum
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   366
            echo '<tr>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   367
                    <td class="row2 decir_forum"><input type="hidden" value="' . $row['forum_id'] . '" />
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   368
                      <b><a href="' . makeUrlNS('DecirForum', $row['forum_id']) . '">'
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   369
                      . $row['forum_name'] . '</a></b><br />' . $row['forum_desc'].'
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   370
                    </td>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   371
                   <td class="row3" style="text-align: center;">' . $row['num_topics'] . '</td>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   372
                   <td class="row3" style="text-align: center;">' . $row['num_posts'] . '</td>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   373
                   <td class="row1" style="text-align: center;">';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   374
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   375
            echo '<button name="act" value="edit;fid=' . $row['forum_id'] . '">Edit</button>&nbsp;';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   376
            echo '<button name="act" value="delete;fid=' . $row['forum_id'] . '">Delete</button>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   377
            
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   378
            echo '</td>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   379
                 </tr>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   380
            $order_forums[] = $row['forum_id'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   381
            break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   382
          case FORUM_CATEGORY:
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   383
            // Category
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   384
            if ( $cat_open )
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   385
              echo '</tbody>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   386
            echo '<tr>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   387
                    <td class="row1 decir_category" colspan="1"><input type="hidden" value="' . $row['forum_id'] . '" />
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   388
                      <h3 style="margin: 0; padding: 0;">' . $row['forum_name'] . '</h3>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   389
                    </td>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   390
                    <td class="row2" colspan="2"></td>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   391
            echo '<td class="row1" style="text-align: center;">';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   392
            echo '<button name="act" value="edit;fid=' . $row['forum_id'] . '">Edit</button>&nbsp;';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   393
            echo '<button name="act" value="delete;fid=' . $row['forum_id'] . '">Delete</button>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   394
            echo '</td>';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   395
            echo '</tr>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   396
                  <tbody id="forum_cat_' . $row['forum_id'] . '">';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   397
            $cat_open = true;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   398
            $order_cats[] = $row['forum_id'];
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   399
            break;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   400
        }
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   401
      }
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   402
      while ( $row = $db->fetchrow($q) );
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   403
    }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   404
    else
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   405
    {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   406
      echo '<td colspan="4" class="row3">There are no forums on this board.</td>';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   407
    }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   408
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   409
    // Create forum button
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   410
    echo '    <tr>
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   411
                <th class="subhead" colspan="4">
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   412
                  <button name="act" value="create">Create new forum</button>
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   413
                  <button name="act" value="save_order">Save forum order</button>
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   414
                </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   415
              </tr>';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   416
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   417
    echo '  </table>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   418
          </div>';
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   419
    $order = /* implode(',', $order_cats) . ';' . */ implode(',', $order_forums);
9
6d9655e02026 Removed all dragger debugging info and started on the form for forum/category deletion
Dan
parents: 7
diff changeset
   420
    echo '<input type="hidden" name="forum_order" id="forum_order" value="' . $order . '" />';
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   421
    echo "</form>";
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   422
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   423
}
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   424
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   425
/**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   426
 * Smart form for creating and editing Decir forums.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   427
 * @package Decir
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   428
 * @subpackage Administration
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   429
 * @copyright 2007 Dan Fuhry
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   430
 * @license GPL
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   431
 */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   432
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   433
class Decir_Admin_SmartForm_Forum
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   434
{
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   435
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   436
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   437
   * Whether we are creating or editing a forum.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   438
   * @var int
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   439
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   440
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   441
  var $form_mode;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   442
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   443
  /**
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   444
   * The unique ID of the forum - only used in edit mode.
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   445
   * @var int
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   446
   */
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   447
  
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   448
  var $forum_id = 0;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   449
  
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   450
  /**
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   451
   * The name of the forum - only used in edit mode or if performing a bounceback from a failed form validation.
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   452
   * @var string
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   453
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   454
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   455
  var $forum_name = '';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   456
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   457
  /**
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   458
   * The description of the forum - only used in edit mode or if performing a bounceback from a failed form validation.
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   459
   * @var string
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   460
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   461
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   462
  var $forum_desc = '';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   463
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   464
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   465
   * The type of entry this is (forum or category)
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   466
   * @var int
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   467
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   468
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   469
  var $forum_type = -1;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   470
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   471
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   472
   * Track if we need to make the user create a category as opposed to a forum.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   473
   * @var bool
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   474
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   475
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   476
  var $need_category = false;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   477
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   478
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   479
   * The list of categories on the site.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   480
   * @var array
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   481
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   482
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   483
  var $category_list = array();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   484
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   485
  /**
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   486
   * The parent category of the forum we're editing.
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   487
   * @var int
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   488
   */
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   489
  
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   490
  var $forum_parent = -1;
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   491
  
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   492
  /**
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   493
   * Instance ID for javascripting
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   494
   * @var string
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   495
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   496
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   497
  var $instance_id;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   498
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   499
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   500
   * Constructor
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   501
   * @param int Form type - should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   502
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   503
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   504
  function __construct($form_mode)
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   505
  {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   506
    global $db, $session, $paths, $template, $plugins; // Common objects
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   507
    $form_mode = intval($form_mode);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   508
    if ( $form_mode != DECIR_ADMIN_MODE_CREATE && $form_mode != DECIR_ADMIN_MODE_EDIT )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   509
      die('Syntax error: $form_mode to Decir_Admin_SmartForm_Forum::__construct should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT.');
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   510
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   511
    $this->form_mode = $form_mode;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   512
    $this->instance_id = $session->dss_rand();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   513
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   514
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   515
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   516
   * PHP4 compatibility constructor.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   517
   * @see Decir_Admin_SmartForm_Forum::__construct
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   518
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   519
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   520
  function Decir_Admin_SmartForm_Forum($form_type)
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   521
  {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   522
    $this->__construct($form_type);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   523
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   524
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   525
  /**
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   526
   * Render the form into HTML.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   527
   * @return string
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   528
   */
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   529
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   530
  function html()
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   531
  {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   532
    global $db, $session, $paths, $template, $plugins; // Common objects
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   533
    $f_f = FORUM_FORUM;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   534
    $f_c = FORUM_CATEGORY;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   535
    $tpl_code = <<<EOF
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   536
        <!-- Start forum creation/edit smartform {INSTANCE_ID} -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   537
        
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   538
        <!-- BEGIN mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   539
        <script type="text/javascript">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   540
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   541
          function set_form_type_category_{INSTANCE_ID}()
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   542
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   543
            document.getElementById('type_category_{INSTANCE_ID}').style.display = 'block';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   544
            document.getElementById('type_forum_{INSTANCE_ID}').style.display = 'none';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   545
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   546
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   547
          function set_form_type_forum_{INSTANCE_ID}()
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   548
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   549
            document.getElementById('type_category_{INSTANCE_ID}').style.display = 'none';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   550
            document.getElementById('type_forum_{INSTANCE_ID}').style.display = 'block';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   551
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   552
          var set_form_type_auto_{INSTANCE_ID} = function()
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   553
          {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   554
            if ( document.getElementById('radio_forum_{INSTANCE_ID}').checked )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   555
            {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   556
              set_form_type_forum_{INSTANCE_ID}();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   557
            }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   558
            else if ( document.getElementById('radio_category_{INSTANCE_ID}').checked )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   559
            {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   560
              set_form_type_category_{INSTANCE_ID}();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   561
            }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   562
          }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   563
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   564
          addOnloadHook(set_form_type_auto_{INSTANCE_ID});
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   565
        </script>
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   566
        <!-- END mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   567
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   568
        <form action="{FORM_ACTION}" name="decir_forum_smartform_{INSTANCE_ID}" method="post" enctype="multipart/form-data">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   569
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   570
        <div class="tblholder">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   571
          <table border="0" cellspacing="1" cellpadding="4">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   572
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   573
              <th colspan="2">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   574
                <!-- BEGIN mode_is_create -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   575
                Create new forum
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   576
                <!-- BEGINELSE mode_is_create -->
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   577
                Editing {FORUM_NAME}
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   578
                <!-- END mode_is_create -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   579
              </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   580
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   581
            <!-- BEGIN mode_is_create -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   582
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   583
              <td class="row2" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   584
                Forum type:
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   585
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   586
              <td class="row1" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   587
                <label>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   588
                  <input id="radio_forum_{INSTANCE_ID}" type="radio" name="forum_type" value="{TYPE_FORUM}" onclick="set_form_type_forum_{INSTANCE_ID}();" <!-- BEGIN type_is_forum -->checked="checked" <!-- END type_is_forum -->/> Forum
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   589
                </label>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   590
                <label>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   591
                  <input id="radio_category_{INSTANCE_ID}" type="radio" name="forum_type" value="{TYPE_CATEGORY}" onclick="set_form_type_category_{INSTANCE_ID}();" <!-- BEGINNOT type_is_forum -->checked="checked" <!-- END type_is_forum -->/> Category
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   592
                </label>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   593
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   594
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   595
            <!-- END mode_is_create -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   596
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   597
              <td class="row2" style="width: 50%;">
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   598
                <!-- BEGINNOT mode_is_create -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   599
                  <!-- BEGINNOT type_is_forum -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   600
                    Category name:
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   601
                  <!-- BEGINELSE type_is_forum -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   602
                    Forum name:
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   603
                  <!-- END type_is_forum -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   604
                <!-- BEGINELSE mode_is_create -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   605
                  Forum name:
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   606
                <!-- END mode_is_create -->                  
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   607
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   608
              <td class="row1" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   609
              <input type="text" name="forum_name" size="40" value="{FORUM_NAME}" />
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   610
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   611
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   612
          </table>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   613
        </div>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   614
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   615
        <!-- BEGIN show_opts_category -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   616
        <div class="tblholder" id="type_category_{INSTANCE_ID}"<!-- BEGIN mode_is_create --> style="display: none;" <!-- END mode_is_create -->>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   617
          <table border="0" cellspacing="1" cellpadding="4">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   618
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   619
              <th colspan="2">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   620
                Category options
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   621
              </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   622
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   623
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   624
              <td class="row2" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   625
                Stub
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   626
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   627
              <td class="row1" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   628
                Stub
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   629
              </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   630
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   631
            <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   632
              <th class="subhead" colspan="2">
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   633
                <!-- BEGIN mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   634
                <button name="act" value="create_finish"><b>Create category</b></button>
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   635
                <!-- BEGINELSE mode_is_create -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   636
                <button name="act" value="edit_finish;fid={FORUM_ID}"><b>Save changes</b></button>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   637
                <!-- END mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   638
                <button name="act" value="noop" style="font-weight: normal;">Cancel</button>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   639
              </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   640
            </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   641
          </table>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   642
        </div>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   643
        <!-- END show_opts_category -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   644
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   645
        <!-- BEGIN show_opts_forum -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   646
        <div id="type_forum_{INSTANCE_ID}">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   647
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   648
          <!-- BEGIN need_category -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   649
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   650
          <div class="error-box">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   651
            There aren't any categories on this site yet. You need to create at least one category before you can create a forum.
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   652
          </div>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   653
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   654
          <!-- BEGINELSE need_category -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   655
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   656
          <div class="tblholder">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   657
            <table border="0" cellspacing="1" cellpadding="4">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   658
              <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   659
                <th colspan="2">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   660
                  Forum options
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   661
                </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   662
              </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   663
              <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   664
                <td class="row2" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   665
                  Forum description:
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   666
                </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   667
                <td class="row1" style="width: 50%;">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   668
                  <input type="text" name="forum_desc" size="40" value="{FORUM_DESC}" />
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   669
                </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   670
              </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   671
              <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   672
                <td class="row2">
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   673
                  <!-- BEGIN mode_is_create -->Create in category:<!-- BEGINELSE mode_is_create -->Parent category:<!-- END mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   674
                </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   675
                <td class="row1">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   676
                  <select name="forum_parent">
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   677
                    {CATEGORY_LIST}</select>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   678
                </td>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   679
              </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   680
              <tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   681
                <th class="subhead" colspan="2">
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   682
                  <!-- BEGIN mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   683
                  <button name="act" value="create_finish"><b>Create forum</b></button>
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   684
                  <!-- BEGINELSE mode_is_create -->
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   685
                  <button name="act" value="edit_finish;fid={FORUM_ID}"><b>Save changes</b></button>
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   686
                  <!-- END mode_is_create -->
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   687
                  <button name="act" value="noop" style="font-weight: normal;">Cancel</button>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   688
                </th>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   689
              </tr>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   690
            </table>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   691
          </div>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   692
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   693
          <!-- END need_category -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   694
          
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   695
        </div>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   696
        <!-- END show_opts_forum -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   697
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   698
        </form>
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   699
        
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   700
        <!-- Finish forum creation/edit smartform {INSTANCE_ID} -->
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   701
EOF;
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   702
    $parser = $template->makeParserText($tpl_code);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   703
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   704
    $category_list = '';
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   705
    foreach ( $this->category_list as $cat_id => $cat_name )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   706
    {
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   707
      $cat_id = intval($cat_id);
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   708
      $cat_name = htmlspecialchars($cat_name);
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   709
      $sel = ( $cat_id == $this->forum_parent ) ? ' selected="selected"' : '';
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   710
      $category_list .= "<option {$sel}value=\"$cat_id\">$cat_name</option>\n                    ";
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   711
    }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   712
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   713
    // FIXME: these should really call addslashes and htmlspecialchars
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   714
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   715
    $parser->assign_vars(array(
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   716
        'INSTANCE_ID' => $this->instance_id,
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   717
        'FORUM_NAME' => htmlspecialchars($this->forum_name),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   718
        'FORUM_DESC' => htmlspecialchars($this->forum_desc),
7
37387f84fe25 Add edit functionality to forum management and implemented a sick drag-and-drop reordering system for forums
Dan
parents: 6
diff changeset
   719
        'FORUM_ID' => $this->forum_id,
6
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   720
        'FORM_ACTION' => makeUrlNS('Special', 'DecirAdmin', 'module=' . $paths->nslist['Admin'] . 'DecirForums', true),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   721
        'TYPE_FORUM' => FORUM_FORUM,
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   722
        'TYPE_CATEGORY' => FORUM_CATEGORY,
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   723
        'CATEGORY_LIST' => $category_list
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   724
      ));
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   725
    $parser->assign_bool(array(
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   726
      'mode_is_create' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   727
      'show_opts_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_CATEGORY ),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   728
      'show_opts_forum' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_FORUM ),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   729
      'type_is_forum' => ( $this->forum_type != FORUM_CATEGORY ),
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   730
      'need_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE && $this->need_category )
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   731
    ));
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   732
    
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   733
    return $parser->run();
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   734
  }
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   735
  
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   736
}
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   737
3f66ec435f08 Some basic admin implemented
Dan
parents:
diff changeset
   738
?>