Some basic admin implemented
authorDan
Tue, 13 Nov 2007 19:39:50 -0500
changeset 6 3f66ec435f08
parent 5 6eea55374f5b
child 7 37387f84fe25
Some basic admin implemented
decir/admincp/admin_base.php
decir/admincp/admin_forums.php
decir/admincp/admin_index.php
decir/constants.php
decir/edit.php
decir/forum_index.php
decir/functions.php
decir/install.php
decir/install.sql
decir/posting.php
decir/viewforum.php
decir/viewtopic.php
plugins/Decir.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decir/admincp/admin_base.php	Tue Nov 13 19:39:50 2007 -0500
@@ -0,0 +1,105 @@
+<?php
+/*
+ * Decir
+ * Version 0.1
+ * Copyright (C) 2007 Dan Fuhry
+ * admin_base.php - lowlevel loader for the Decir admin panel
+ *
+ * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ */
+ 
+$decir_menu = array();
+
+// Only load the actual admin modules if they're needed
+function page_Special_DecirAdmin_preloader()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  global $decir_menu;
+  require( DECIR_ROOT . '/admincp/admin_index.php' );
+  require( DECIR_ROOT . '/admincp/admin_forums.php' );
+  
+  $decir_menu['Special|Administration'] = 'Main administration panel';
+}
+
+$plugins->attachHook('base_classes_initted', '
+    $paths->add_page(Array(
+      \'name\'=>\'Decir Administration Panel\',
+      \'urlname\'=>\'DecirAdmin\',
+      \'namespace\'=>\'Special\',
+      \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
+      ));
+  ');
+
+function page_Special_DecirAdmin()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  
+  if ( $session->user_level < USER_LEVEL_ADMIN )
+    die_friendly('Access denied', '<p>This page is restricted access.</p>');
+  
+  if ( $session->auth_level < USER_LEVEL_ADMIN )
+    redirect(makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true), '', '', 0);
+  
+  $session->theme = 'admin';
+  $session->style = 'default';
+  $template = false;
+  unset($GLOBALS['template']);
+  unset($template);
+  $GLOBALS['template'] = new template();
+  $template =& $GLOBALS['template'];
+  
+  $template->header();
+  ?>
+  Add or remove forums, control user permissions, and check forum statistics.
+  <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin-top: 10px;">
+    <tr>
+      <td style="padding-right: 20px; width: 200px;" valign="top">
+        <h4 style="margin: 0 0 10px 0;">Decir configuration</h4>
+        <ul>
+          <?php
+            global $decir_menu;
+            foreach ( $decir_menu as $page_id => $link_text )
+            {
+              if ( strpos($page_id, '|') )
+              {
+                $namesp  = substr($page_id, 0, strpos($page_id, '|'));
+                $page_id = substr($page_id, strpos($page_id, '|') + 1);                
+              }
+              else
+              {
+                $namesp = 'Admin';
+              }
+              $link_text = htmlspecialchars($link_text);
+              if ( $namesp == 'Admin' )
+              {
+                $url = makeUrlNS('Special', 'DecirAdmin', 'module=' . $paths->nslist[$namesp] . $page_id, true);
+              }
+              else
+              {
+                $url = makeUrlNS($namesp, $page_id);
+              }
+              echo '<li><a href="' . $url . "\">$link_text</a></li>";
+            }
+          ?>
+        </ul>
+      </td>
+      <td valign="top">
+        <?php
+          $module = ( isset($_GET['module']) ) ? $_GET['module'] : $paths->nslist['Admin'] . 'DecirIndex';
+          list($page_id, $namespace) = RenderMan::strToPageID($module);
+          $page = new PageProcessor($page_id, $namespace);
+          $page->send();
+        ?>
+      </td>
+    </tr>
+  </table>
+  <?php
+  
+  $template->footer();
+}
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decir/admincp/admin_forums.php	Tue Nov 13 19:39:50 2007 -0500
@@ -0,0 +1,429 @@
+<?php
+/*
+ * Decir
+ * Version 0.1
+ * Copyright (C) 2007 Dan Fuhry
+ * admin_forums.php - forum creation and management frontend
+ *
+ * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ */
+
+$decir_menu['DecirForums'] = 'Manage forums';
+require( DECIR_ROOT . '/constants.php' );
+
+function page_Admin_DecirForums()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
+  {
+    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>';
+    return;
+  }
+  
+  $show_main_menu = true;
+  
+  if ( isset($_POST['act']) )
+  {
+    switch ( $_POST['act'] )
+    {
+      case "create":
+      case "create_finish":
+        
+        // Do we have any categories yet?
+        $q = $db->sql_query('SELECT forum_id, forum_name FROM ' . table_prefix . 'decir_forums WHERE forum_type = ' . FORUM_CATEGORY . ';');
+        if ( !$q )
+          $db->_die('Decir admin_forums.php retrieving category count');
+        $need_category = ( $db->numrows() < 1 );
+        $cats = array();
+        if ( !$need_category )
+        {
+          while ( list($cat_id, $cat_name) = $db->fetchrow_num() )
+          {
+            $cats[ $cat_id ] = $cat_name;
+          }
+        }
+        
+        $db->free_result();
+        
+        if ( $_POST['act'] == 'create_finish' )
+        {
+          $errors = array();
+          $forum_type = intval($_POST['forum_type']);
+          if ( $forum_type != FORUM_FORUM && $forum_type != FORUM_CATEGORY )
+            $errors[] = 'Invalid forum type. <tt>X.X</tt>';
+          $forum_name = trim($_POST['forum_name']);
+          if ( empty($forum_name) )
+            $errors[] = 'Please enter a name for this forum.';
+          $forum_desc = '';
+          $forum_parent = 0;
+          if ( $forum_type == FORUM_FORUM )
+          {
+            $forum_desc = trim($_POST['forum_desc']);
+            if ( empty($forum_desc) )
+              $errors[] = 'Please enter a description for this forum.';
+            $forum_parent = intval($_POST['forum_parent']);
+            if ( !isset($cats[$forum_parent]) )
+              $errors[] = 'Invalid parent category';
+          }
+          if ( count($errors) > 0 )
+          {
+            // Errors encountered - bounce form back to the user
+            $show_main_menu = false;
+            $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE);
+            $form->forum_name = $forum_name;
+            $form->forum_desc = $forum_desc;
+            $form->forum_type = $forum_type;
+            $form->need_category = $need_category;
+            $form->category_list = $cats;
+            echo $form->html();
+            break;
+          }
+          // All checks passed. Create forum.
+          $forum_name_db = $db->escape($forum_name);
+          $forum_desc_db = $db->escape($forum_desc);
+          $sql = 'INSERT INTO ' . table_prefix . "decir_forums(forum_name, forum_desc, forum_type, parent, num_topics, num_posts) VALUES\n"
+                 . "  ( '$forum_name_db', '$forum_desc_db', $forum_type, $forum_parent, 0, 0 );";
+          if ( $db->sql_query($sql) )
+          {
+            $forum_name = htmlspecialchars($forum_name);
+            $type = ( $forum_type == FORUM_FORUM ) ? 'forum' : 'category';
+            echo "<div class=\"info-box\">The {$type} \"{$forum_name}\" has been created successfully.</div>";
+          }
+          break;
+        }
+        // Create a smartform
+        $show_main_menu = false;
+        $form = new Decir_Admin_SmartForm_Forum(DECIR_ADMIN_MODE_CREATE);
+        $form->need_category = $need_category;
+        $form->category_list = $cats;
+        echo $form->html();
+        break;
+    }
+  }
+  
+  if ( $show_main_menu )
+  {
+    // Display the main forum admin interface
+    $form_url = makeUrlNS('Special', 'DecirAdmin', "module={$paths->nslist['Admin']}DecirForums", true);
+    echo "<form action=\"$form_url\" method=\"post\" enctype=\"multipart/form-data\">";
+    echo '<div class="tblholder">
+            <table border="0" cellspacing="1" cellpadding="4">
+              <tr>
+                <th colspan="4">Forum administration</th>
+              </tr>';
+    // Select and display all forums
+    $q = $db->sql_unbuffered_query('SELECT forum_id, forum_name, forum_type FROM ' . table_prefix . 'decir_forums ORDER BY ( forum_type = ' . FORUM_CATEGORY . ' ) DESC, forum_order;');
+    
+    if ( !$q )
+      $db->_die('Decir admin_forums.php selecting main forum datum');
+    
+    if ( $row = $db->fetchrow() )
+    {
+      do
+      {
+      }
+      while ( $row = $db->fetchrow() );
+    }
+    else
+    {
+      echo '<td colspan="4" class="row3">There are no forums on this board.</td>';
+    }
+    
+    // Create forum button
+    echo '    <tr>
+                <th class="subhead">
+                  <button name="act" value="create">Create new forum</button>
+                </th>
+              </tr>';
+    
+    echo '  </table>
+          </div>';
+    echo "</form>";
+  }
+}
+
+/**
+ * Smart form for creating and editing Decir forums.
+ * @package Decir
+ * @subpackage Administration
+ * @copyright 2007 Dan Fuhry
+ * @license GPL
+ */
+
+class Decir_Admin_SmartForm_Forum
+{
+  
+  /**
+   * Whether we are creating or editing a forum.
+   * @var int
+   */
+  
+  var $form_mode;
+  
+  /**
+   * The name of the forum - only used in edit mode.
+   * @var string
+   */
+  
+  var $forum_name = '';
+  
+  /**
+   * The description of the forum - only used in edit mode.
+   * @var string
+   */
+  
+  var $forum_desc = '';
+  
+  /**
+   * The type of entry this is (forum or category)
+   * @var int
+   */
+  
+  var $forum_type = -1;
+  
+  /**
+   * Track if we need to make the user create a category as opposed to a forum.
+   * @var bool
+   */
+  
+  var $need_category = false;
+  
+  /**
+   * The list of categories on the site.
+   * @var array
+   */
+  
+  var $category_list = array();
+  
+  /**
+   * Instance ID for javascripting
+   * @var string
+   */
+  
+  var $instance_id;
+  
+  /**
+   * Constructor
+   * @param int Form type - should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT
+   */
+  
+  function __construct($form_mode)
+  {
+    global $db, $session, $paths, $template, $plugins; // Common objects
+    $form_mode = intval($form_mode);
+    if ( $form_mode != DECIR_ADMIN_MODE_CREATE && $form_mode != DECIR_ADMIN_MODE_EDIT )
+      die('Syntax error: $form_mode to Decir_Admin_SmartForm_Forum::__construct should be DECIR_ADMIN_MODE_CREATE or DECIR_ADMIN_MODE_EDIT.');
+    
+    $this->form_mode = $form_mode;
+    $this->instance_id = $session->dss_rand();
+  }
+  
+  /**
+   * PHP4 compatibility constructor.
+   * @see Decir_Admin_SmartForm_Forum::__construct
+   */
+  
+  function Decir_Admin_SmartForm_Forum($form_type)
+  {
+    $this->__construct($form_type);
+  }
+  
+  /**
+   * Render the form into HTML.
+   * @return string
+   */
+  
+  function html()
+  {
+    global $db, $session, $paths, $template, $plugins; // Common objects
+    $f_f = FORUM_FORUM;
+    $f_c = FORUM_CATEGORY;
+    $tpl_code = <<<EOF
+        <!-- Start forum creation/edit smartform {INSTANCE_ID} -->
+        
+        <script type="text/javascript">
+        
+          function set_form_type_category_{INSTANCE_ID}()
+          {
+            document.getElementById('type_category_{INSTANCE_ID}').style.display = 'block';
+            document.getElementById('type_forum_{INSTANCE_ID}').style.display = 'none';
+          }
+          
+          function set_form_type_forum_{INSTANCE_ID}()
+          {
+            document.getElementById('type_category_{INSTANCE_ID}').style.display = 'none';
+            document.getElementById('type_forum_{INSTANCE_ID}').style.display = 'block';
+          }
+          var set_form_type_auto_{INSTANCE_ID} = function()
+          {
+            if ( document.getElementById('radio_forum_{INSTANCE_ID}').checked )
+            {
+              set_form_type_forum_{INSTANCE_ID}();
+            }
+            else if ( document.getElementById('radio_category_{INSTANCE_ID}').checked )
+            {
+              set_form_type_category_{INSTANCE_ID}();
+            }
+          }
+          
+          addOnloadHook(set_form_type_auto_{INSTANCE_ID});
+        
+        </script>
+        
+        <form action="{FORM_ACTION}" name="decir_forum_smartform_{INSTANCE_ID}" method="post" enctype="multipart/form-data">
+        
+        <div class="tblholder">
+          <table border="0" cellspacing="1" cellpadding="4">
+            <tr>
+              <th colspan="2">
+                <!-- BEGIN mode_is_create -->
+                Create new forum
+                <!-- BEGINELSE mode_is_create -->
+                Edit forum {FORUM_NAME}
+                <!-- END mode_is_create -->
+              </th>
+            </tr>
+            <!-- BEGIN mode_is_create -->
+            <tr>
+              <td class="row2" style="width: 50%;">
+                Forum type:
+              </td>
+              <td class="row1" style="width: 50%;">
+                <label>
+                  <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
+                </label>
+                <label>
+                  <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
+                </label>
+              </td>
+            </tr>
+            <!-- END mode_is_create -->
+            <tr>
+              <td class="row2" style="width: 50%;">
+                Forum description:
+              </td>
+              <td class="row1" style="width: 50%;">
+              <input type="text" name="forum_name" size="40" value="{FORUM_NAME}" />
+              </td>
+            </tr>
+          </table>
+        </div>
+        
+        <!-- BEGIN show_opts_category -->
+        <div class="tblholder" id="type_category_{INSTANCE_ID}"<!-- BEGIN mode_is_create --> style="display: none;" <!-- END mode_is_create -->>
+          <table border="0" cellspacing="1" cellpadding="4">
+            <tr>
+              <th colspan="2">
+                Category options
+              </th>
+            </tr>
+            <tr>
+              <td class="row2" style="width: 50%;">
+                Stub
+              </td>
+              <td class="row1" style="width: 50%;">
+                Stub
+              </td>
+            </tr>
+            <tr>
+              <th class="subhead" colspan="2">
+                <button name="act" value="create_finish"><b>Create category</b></button>
+                <button name="act" value="noop" style="font-weight: normal;">Cancel</button>
+              </th>
+            </tr>
+          </table>
+        </div>
+        <!-- END show_opts_category -->
+        
+        <!-- BEGIN show_opts_forum -->
+        <div id="type_forum_{INSTANCE_ID}">
+          
+          <!-- BEGIN need_category -->
+          
+          <div class="error-box">
+            There aren't any categories on this site yet. You need to create at least one category before you can create a forum.
+          </div>
+          
+          <!-- BEGINELSE need_category -->
+          
+          <div class="tblholder">
+            <table border="0" cellspacing="1" cellpadding="4">
+              <tr>
+                <th colspan="2">
+                  Forum options
+                </th>
+              </tr>
+              <tr>
+                <td class="row2" style="width: 50%;">
+                  Forum description:
+                </td>
+                <td class="row1" style="width: 50%;">
+                  <input type="text" name="forum_desc" size="40" value="{FORUM_DESC}" />
+                </td>
+              </tr>
+              <tr>
+                <td class="row2">
+                  Create in category:
+                </td>
+                <td class="row1">
+                  <select name="forum_parent">
+                    {CATEGORY_LIST}</select>
+                </td>
+              </tr>
+              <tr>
+                <th class="subhead" colspan="2">
+                  <button name="act" value="create_finish"><b>Create forum</b></button>
+                  <button name="act" value="noop" style="font-weight: normal;">Cancel</button>
+                </th>
+              </tr>
+            </table>
+          </div>
+          
+          <!-- END need_category -->
+          
+        </div>
+        <!-- END show_opts_forum -->
+        
+        </form>
+        
+        <!-- Finish forum creation/edit smartform {INSTANCE_ID} -->
+EOF;
+    $parser = $template->makeParserText($tpl_code);
+    
+    $category_list = '';
+    foreach ( $this->category_list as $cat_id => $cat_name )
+    {
+      $cat_id = intval($cat_id);
+      $cat_name = htmlspecialchars($cat_name);
+      $category_list .= "<option value=\"$cat_id\">$cat_name</option>\n                    ";
+    }
+    
+    // FIXME: these should really call addslashes and htmlspecialchars
+    
+    $parser->assign_vars(array(
+        'INSTANCE_ID' => $this->instance_id,
+        'FORUM_NAME' => htmlspecialchars($this->forum_name),
+        'FORUM_DESC' => htmlspecialchars($this->forum_desc),
+        'FORM_ACTION' => makeUrlNS('Special', 'DecirAdmin', 'module=' . $paths->nslist['Admin'] . 'DecirForums', true),
+        'TYPE_FORUM' => FORUM_FORUM,
+        'TYPE_CATEGORY' => FORUM_CATEGORY,
+        'CATEGORY_LIST' => $category_list
+      ));
+    $parser->assign_bool(array(
+      'mode_is_create' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ),
+      'show_opts_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_CATEGORY ),
+      'show_opts_forum' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE ? true : $this->forum_type == FORUM_FORUM ),
+      'type_is_forum' => ( $this->forum_type != FORUM_CATEGORY ),
+      'need_category' => ( $this->form_mode == DECIR_ADMIN_MODE_CREATE && $this->need_category )
+    ));
+    
+    return $parser->run();
+  }
+  
+}
+
+?>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/decir/admincp/admin_index.php	Tue Nov 13 19:39:50 2007 -0500
@@ -0,0 +1,95 @@
+<?php
+/*
+ * Decir
+ * Version 0.1
+ * Copyright (C) 2007 Dan Fuhry
+ * admin_base.php - lowlevel loader for the Decir admin panel
+ *
+ * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ */
+
+$decir_menu['DecirIndex'] = 'Administration home';
+
+function page_Admin_DecirIndex()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
+  {
+    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>';
+    return;
+  }
+  
+  //
+  // Obtain forum statistics
+  //
+  
+  // Number of users
+  $q = $db->sql_query('SELECT COUNT(user_id)-1 AS num_users FROM ' . table_prefix . 'users;');
+  if ( !$q )
+    $db->_die();
+  
+  $row = $db->fetchrow();
+  $db->free_result();
+  $num_users = $row['num_users'];
+  
+  // Number of posts
+  $q = $db->sql_query('SELECT COUNT(post_id) AS num_posts FROM ' . table_prefix . 'decir_posts;');
+  if ( !$q )
+    $db->_die();
+  
+  $row = $db->fetchrow();
+  $db->free_result();
+  $num_posts = $row['num_posts'];
+  
+  // Board start date
+  $date = intval( getConfig('decir_install_date') );
+  if ( !$date )
+  {
+    $date = time();
+    setConfig('decir_install_date', $date);
+  }
+  $start_date = date('F d, Y h:i a', $date);
+  
+  // Average posts per day
+  $board_age_days = round( ( time() / ( 60*60*24 ) ) - ( $date / ( 60*60*24 ) ) );
+  if ( $board_age_days < 1 )
+  {
+    $avg_posts = $num_posts;
+  }
+  else
+  {
+    $avg_posts = $num_posts / $board_age_days;
+  }
+  
+  echo '<h3>Administration home</h3>';
+  echo '<p>Thank you for choosing Decir as your forum solution. From this panel you can control every aspect of your forum\'s behavior and appearance. If you need support
+           for Decir, you can visit the <a href="http://forum.enanocms.org/">Enano support forums</a>.</p>';
+  echo '<h3>Board statistics</h3>';
+  echo "<div class=\"tblholder\">
+          <table border=\"0\" cellspacing=\"1\" cellpadding=\"4\">
+            <tr>
+              <th colspan=\"4\">Board statistics</th>
+            </tr>
+            <tr>
+              <td style=\"width: 25%;\" class=\"row1\"><b>Number of users:</b></td>
+              <td style=\"width: 25%;\" class=\"row2\">{$num_users}</td>
+              
+              <td style=\"width: 25%;\" class=\"row1\"><b>Number of posts:</b></td>
+              <td style=\"width: 25%;\" class=\"row2\">{$num_posts}</td>
+            </tr>
+            <tr>
+              <td style=\"width: 25%;\" class=\"row1\"><b>Board started:</b></td>
+              <td style=\"width: 25%;\" class=\"row2\">{$start_date} ({$board_age_days} days ago)</td>
+              
+              <td style=\"width: 25%;\" class=\"row1\"><b>Average posts per day:</b></td>
+              <td style=\"width: 25%;\" class=\"row2\">{$avg_posts}</td>
+            </tr>
+          </table>
+        </div>";
+}
+
+?>
--- a/decir/constants.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/constants.php	Tue Nov 13 19:39:50 2007 -0500
@@ -22,4 +22,7 @@
 define('TOPIC_STICKY', 4);
 define('TOPIC_ANNOUNCE', 5);
 
+define('DECIR_ADMIN_MODE_CREATE', 1);
+define('DECIR_ADMIN_MODE_EDIT', 2);
+
 ?>
--- a/decir/edit.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/edit.php	Tue Nov 13 19:39:50 2007 -0500
@@ -164,6 +164,7 @@
 </form>
 <?php
 
+decir_show_footers();
 $template->footer();
 
 ?>
--- a/decir/forum_index.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/forum_index.php	Tue Nov 13 19:39:50 2007 -0500
@@ -48,6 +48,11 @@
     {
       case FORUM_FORUM:
         $color = ( $row['user_level'] >= USER_LEVEL_ADMIN ) ? 'AA0000' : ( ( $row['user_level'] >= USER_LEVEL_MOD ) ? '00AA00' : '0000AA' );
+        $last_post_info = ( $row['last_post_id'] ) ?
+                 '<a href="' . makeUrlNS('DecirTopic', $row['topic_id']) . '#post' . $row['post_id'] . '">' . $row['topic_title'] . '</a><br />
+                 ' . date('d M Y h:i a', $row['timestamp']) . '<br />
+                 by <b><a style="color: #' . $color . '" href="' . makeUrlNS('User', $row['username']) . '">' . $row['username'] . '</a></b>' :
+                 '&lt;No posts&gt;';
         // Forum
         echo '<tr><td class="row3" style="text-align: center;">&lt;icon&gt;</td><td class="row2"><b><a href="' . makeUrlNS('DecirForum', $row['forum_id']) . '">'
              . $row['forum_name'] . '</a></b><br />' . $row['forum_desc'].'</td>
@@ -55,9 +60,7 @@
              <td class="row3" style="text-align: center;">' . $row['num_posts'] . '</td>
              <td class="row1" style="text-align: center;">
                <small>
-                 <a href="' . makeUrlNS('DecirTopic', $row['topic_id']) . '#post' . $row['post_id'] . '">' . $row['topic_title'] . '</a><br />
-                 ' . date('d M Y h:i a', $row['timestamp']) . '<br />
-                 by <b><a style="color: #' . $color . '" href="' . makeUrlNS('User', $row['username']) . '">' . $row['username'] . '</a></b>
+                 ' . $last_post_info . '
                </small>
              </td>
              </tr>';
@@ -82,6 +85,7 @@
 echo '</table>
       </div>';
 
+decir_show_footers();
 $template->footer();
 
 ?>
--- a/decir/functions.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/functions.php	Tue Nov 13 19:39:50 2007 -0500
@@ -396,4 +396,17 @@
   return true;
 }
 
+/**
+ * Shows the administration link on the foot of the page.
+ */
+
+function decir_show_footers()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  if ( $session->user_level >= USER_LEVEL_ADMIN )
+  {
+    echo '<p style="text-align: center; margin: 20px 0 0 0;"><small><a href="' . makeUrlNS('Special', 'DecirAdmin') . '">Administration control panel</a></small></p>';
+  }
+}
+
 ?>
--- a/decir/install.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/install.php	Tue Nov 13 19:39:50 2007 -0500
@@ -20,6 +20,62 @@
   exit;
 }
 
+function install_decir()
+{
+  global $db, $session, $paths, $template, $plugins; // Common objects
+  if ( $session->auth_level < USER_LEVEL_ADMIN )
+    die('Snotty son of a b**** you are being today...');
+  
+  // Build an array of queries
+  $schema = @file_get_contents( DECIR_ROOT . '/install.sql' );
+  if ( !$schema )
+  {
+    echo '<pre>Decir installation error: can\'t load schema file</pre>';
+    return false;
+  }
+  
+  // Variables
+  $schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema);
+  
+  $schema = explode("\n", $schema);
+  
+  foreach ( $schema as $i => $sql )
+  {
+    $query =& $schema[$i];
+    $t = trim($query);
+    if ( empty($t) || preg_match('/^(\#|--)/i', $t) )
+    {
+      unset($schema[$i]);
+      unset($query);
+    }
+  }
+  
+  $schema = array_values($schema);
+  $schema = implode("\n", $schema);
+  $schema = explode(";\n", $schema);
+  
+  foreach ( $schema as $i => $sql )
+  {
+    $query =& $schema[$i];
+    if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' )
+    {
+      $query .= ';';
+    }
+  }
+  
+  foreach ( $schema as $sql )
+  {
+    $q = $db->sql_query($sql);
+    if ( !$q )
+    {
+      echo '<pre>Decir installation failed: ' . $db->get_error() . '</pre>';
+      return false;
+    }
+  }
+  
+  return true;
+}
+
 if ( $v = getConfig('decir_version') )
 {
   $mode = 'upgrade';
@@ -32,30 +88,46 @@
 
 $page = ( isset($_POST['step']) && in_array($_POST['step'], array('welcome', 'install', 'finish')) ) ? $_POST['step'] : 'welcome';
 
-$template->header();
-
-switch($page)
+if ( $page == 'finish' )
+{
+  require('forum_index.php');
+}
+else
 {
-  case 'welcome':
-    ?>
-    <h3>Welcome to Decir, the Enano bulletin board suite.</h3>
-    <p>Before you can use your forum, we'll need to run a few database queries to get the forum set up.</p>
-    <form action="<?php echo makeUrl($paths->page); ?>" method="post">
-      <input type="hidden" name="step" value="install" />
-      <input type="submit" value="Continue" style="display: block; margin: 0 auto;" />
-    </form>
-    <?php
-    break;
-  case 'install':
-    setConfig('decir_version', ENANO_DECIR_VERSION);
-    ?>
-    <form action="<?php echo makeUrl($paths->page); ?>" method="post">
-      <input type="hidden" name="step" value="finish" />
-      <input type="submit" name="do_install_finish" value="Next &gt;" style="display: block; margin: 0 auto;" />
-    </form>
-    <?php
-    break;
+
+  $template->header();
+  
+  switch($page)
+  {
+    case 'welcome':
+      ?>
+      <h3>Welcome to Decir, the Enano bulletin board suite.</h3>
+      <p>Before you can use your forum, we'll need to run a few database queries to get the forum set up.</p>
+      <form action="<?php echo makeUrl($paths->page); ?>" method="post">
+        <input type="hidden" name="step" value="install" />
+        <input type="submit" value="Continue" style="display: block; margin: 0 auto;" />
+      </form>
+      <?php
+      break;
+    case 'install':
+      $result = install_decir();
+      if ( $result ):
+        setConfig('decir_version', ENANO_DECIR_VERSION);
+        setConfig('decir_install_date', time());
+        ?>
+        <p>Decir has been successfully installed.</p>
+        <form action="<?php echo makeUrl($paths->page); ?>" method="post">
+          <input type="hidden" name="step" value="finish" />
+          <input type="submit" name="do_install_finish" value="Next &gt;" style="display: block; margin: 0 auto;" />
+        </form>
+        <?php
+      else:
+        echo 'ERROR: Decir installation failed.';
+      endif;
+      break;
+  }
+  
+$template->footer();
+  
 }
 
-$template->footer();
-
--- a/decir/install.sql	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/install.sql	Tue Nov 13 19:39:50 2007 -0500
@@ -1,4 +1,4 @@
-CREATE TABLE decir_forums(
+CREATE TABLE {{TABLE_PREFIX}}decir_forums(
   forum_id int(12) unsigned NOT NULL auto_increment,
   forum_type tinyint(2) unsigned NOT NULL DEFAULT 1,
   forum_name varchar(255) NOT NULL,
@@ -13,7 +13,7 @@
   forum_extra text,
   PRIMARY KEY ( forum_id )
 );
-CREATE TABLE decir_topics(
+CREATE TABLE {{TABLE_PREFIX}}decir_topics(
   topic_id int(15) unsigned NOT NULL auto_increment,
   forum_id int(12) unsigned NOT NULL,
   topic_title varchar(255) NOT NULL,
@@ -26,9 +26,11 @@
   topic_deleted tinyint(1) NOT NULL DEFAULT 0,
   topic_deletor int(12) DEFAULT NULL,
   topic_delete_reason varchar(255) DEFAULT NULL,
+  num_views bigint(21) UNSIGNED NOT NULL DEFAULT 0,
+  last_post bigint(18) UNSIGNED NOT NULL,
   PRIMARY KEY ( topic_id )
 );
-CREATE TABLE decir_posts(
+CREATE TABLE {{TABLE_PREFIX}}decir_posts(
   post_id bigint(18) unsigned NOT NULL auto_increment,
   topic_id bigint(15) unsigned NOT NULL,
   poster_id int(12) unsigned NOT NULL,
@@ -41,13 +43,13 @@
   post_deleted tinyint(1) NOT NULL DEFAULT 0,
   PRIMARY KEY ( post_id )
 );
-CREATE TABLE decir_posts_text(
+CREATE TABLE {{TABLE_PREFIX}}decir_posts_text(
   post_id bigint(18) unsigned NOT NULL,
   post_text longtext NOT NULL,
   bbcode_uid varchar(10) NOT NULL,
   PRIMARY KEY ( post_id )
 );
-CREATE TABLE decir_hits(
+CREATE TABLE {{TABLE_PREFIX}}decir_hits(
   hit_id bigint(21) unsigned NOT NULL auto_increment,
   user_id int(12) unsigned NOT NULL DEFAULT 1,
   topic_id bigint(15) unsigned NOT NULL,
--- a/decir/posting.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/posting.php	Tue Nov 13 19:39:50 2007 -0500
@@ -317,6 +317,7 @@
 echo '</table></div>';
 echo '</form>';
 
+decir_show_footers();
 $template->footer();
 
 ?>
--- a/decir/viewforum.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/viewforum.php	Tue Nov 13 19:39:50 2007 -0500
@@ -22,7 +22,8 @@
 if(empty($fid))
 {
   echo '<p>Invalid forum ID</p>';
-  $template->footer();
+  decir_show_footers();
+$template->footer();
   return;
 }
 
@@ -123,6 +124,7 @@
   echo '<p><a href="' . makeUrlNS('Special', 'Forum/New/Topic/' . $fid) . '">Post new topic</a></p>';
 }
 
+decir_show_footers();
 $template->footer();
 
 ?>
--- a/decir/viewtopic.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/decir/viewtopic.php	Tue Nov 13 19:39:50 2007 -0500
@@ -11,7 +11,7 @@
  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
  */
- 
+
 require('common.php');
 require('bbcode.php');
 require('functions_viewtopic.php');
@@ -27,7 +27,8 @@
   {
     $template->header();
     echo '<p>Invalid topic ID</p>';
-    $template->footer();
+    decir_show_footers();
+$template->footer();
     return;
   }
   
@@ -48,7 +49,8 @@
   {
     $template->header();
     echo '<p>Invalid topic ID</p>';
-    $template->footer();
+    decir_show_footers();
+$template->footer();
     return;
   }
 }
@@ -192,6 +194,7 @@
 $q = $db->sql_query('INSERT INTO '.table_prefix."decir_hits(user_id, topic_id, timestamp) VALUES($session->user_id, $tid, $time);");
 $q = $db->sql_query('UPDATE '.table_prefix."decir_topics SET num_views = num_views + 1 WHERE topic_id = $tid;");
 
+decir_show_footers();
 $template->footer();
 
 ?>
--- a/plugins/Decir.php	Wed Oct 24 18:30:03 2007 -0400
+++ b/plugins/Decir.php	Tue Nov 13 19:39:50 2007 -0500
@@ -33,6 +33,8 @@
       ));
   ');
 
+require( DECIR_ROOT . '/admincp/admin_base.php' );
+
 function decir_early_init(&$paths, &$session)
 {
   $paths->addAdminNode('Decir forum configuration', 'General settings', 'DecirGeneral');
@@ -52,6 +54,7 @@
   
   if ( getConfig('decir_version') != ENANO_DECIR_VERSION || isset($_POST['do_install_finish']) )
   {
+    chdir(DECIR_ROOT);
     require(DECIR_ROOT . '/install.php');
     return false;
   }
@@ -84,10 +87,4 @@
   
 }
 
-function page_Admin_DecirGeneral()
-{
-  global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { header('Location: '.makeUrl($paths->nslist['Special'].'Administration'.urlSeparator.'noheaders')); die('Hacking attempt'); }
-  echo 'Hello world!';
-}
-
 ?>