Location: PHPKode > projects > Knowledge Box > knowledgebox/setup.php
<?php

  /*
   * Free IT Foundation
   * Free Technology Serving Knowledge
   * http://www.free-it-foundation.org
   * 
   * This file is part of Knowledge Box.
   * 
   * Knowledge Box is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * Knowledge Box 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 more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with Knowledge Box.  If not, see <http://www.gnu.org/licenses/>.
   */


  // module configuration
  $config = array ();
  $config ['mod_name'] = 'Knowledge Box';                                         // name
  $config ['mod_version'] = '1.0.2';                                              // version
  $config ['mod_directory'] = 'knowledgebox';                                     // folder
  $config ['mod_setup_class'] = 'CSetupKnowledgeBoxModule';                       // setup class
  $config ['mod_type'] = 'user';                                                  // module type
  $config ['mod_ui_name'] = 'Knowledge Box';                                      // interface name
  $config ['mod_ui_icon'] = '';                                                   // interface icon
  $config ['mod_description'] = 'Knowledge Bases';                                // description
  $config ['mod_config'] = false;                                                 // configurable

  // show module configuration (framework integration)
  if (@$a == 'setup')
      echo dPshowModuleConfig ($config);

  // access the CRole class
  require_once ('modules/system/roles/roles.class.php');

  // access the knowledge box constants
  require_once ('modules/' . $config ['mod_directory'] . '/require/constants.php');


  /*
   * class
   * CSetupKnowledgeBoxModule
   */
  class CSetupKnowledgeBoxModule
  {

    /*
     * configure ()
     */
    function configure ()
    {
      // void
    }

    /*
     * install ()
     */
    function install ()
    {
      $sql  = "CREATE TABLE `" . KB_TABLE_BASES . "` (" .
              "`id` int(10) unsigned NOT NULL auto_increment," .
              "`name` varchar(64) NOT NULL," .
              " PRIMARY KEY  (`id`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_CONFIGS . "` (" .
              "`base_id` int(10) unsigned NOT NULL," .
              "`property` smallint(5) NOT NULL," .
              "`value` varchar(64) NOT NULL," .
              " PRIMARY KEY  (`base_id`,`property`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_ELEMENTS . "` (" .
              "`id` bigint(20) unsigned NOT NULL auto_increment," .
              "`base_id` int(10) unsigned NOT NULL," .
              "`type` tinyint(1) unsigned NOT NULL," .
              "`resource_id` bigint(20) unsigned NOT NULL," .
              "`width` smallint(5) unsigned NOT NULL," .
              "`rank` bigint(20) unsigned NOT NULL," .
              " PRIMARY KEY  (`id`)," .
              " KEY `base_id` (`base_id`)," .
              " KEY `type` (`type`)," .
              " KEY `resource_id` (`resource_id`)," .
              " KEY `rank` (`rank`)" .
              ") ENGINE=MyISAM";
              
      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_ENTRIES . "` (" .
              "`id` bigint(20) unsigned NOT NULL auto_increment," .
              "`base_id` int(10) unsigned NOT NULL," .
              "`name` varchar(192) NOT NULL," .
              "`visible` tinyint(1) unsigned NOT NULL," .
              " PRIMARY KEY  (`id`)," .
              " KEY `base_id` (`base_id`)," .
              " KEY `visible` (`visible`)" .
              ") ENGINE=MyISAM";
              
      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_FIELDS . "` (" .
              "`id` bigint(20) unsigned NOT NULL auto_increment," .
              "`base_id` int(10) unsigned NOT NULL," .
              "`type` smallint(5) unsigned NOT NULL," .
              "`name` varchar(128) NOT NULL," .
              "`helper` varchar(128) NOT NULL," .
              "`visible` tinyint(1) unsigned NOT NULL," .
              "`mandatory` tinyint(1) unsigned NOT NULL," .
              " `rank` bigint(20) unsigned NOT NULL," .
              " PRIMARY KEY  (`id`)," .
              " KEY `base_id` (`base_id`)," .
              " KEY `type` (`type`)," .
              " KEY `visible` (`visible`)," .
              " KEY `mandatory` (`mandatory`)," .
              " KEY `rank` (`rank`)" .
              ") ENGINE=MyISAM";
              
      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_GROUPS . "` (" .
              "`id` int(10) unsigned NOT NULL auto_increment," .
              "`base_id` int(10) unsigned NOT NULL," .
              "`name` varchar(64) NOT NULL," .
              "`visible` tinyint(1) unsigned NOT NULL," .
              "`width` smallint(5) unsigned NOT NULL," .
              "`rank` int(10) unsigned NOT NULL," .
              " PRIMARY KEY  (`id`)," .
              " KEY `base_id` (`base_id`)," .
              " KEY `visible` (`visible`)," .
              " KEY `rank` (`rank`)" .
              ") ENGINE=MyISAM";
              
      db_exec ($sql); db_error ();

      $sql  = "CREATE TABLE `" . KB_TABLE_KEYWORDS . "` (" .
            "`id` bigint(20) unsigned NOT NULL auto_increment," .
            "`label_id` int(10) unsigned NOT NULL," .
            "`name` varchar(128) NOT NULL," .
            "`rank` bigint(20) unsigned NOT NULL," .
            " PRIMARY KEY  (`id`)," .
            " KEY `label_id` (`label_id`)," .
            " KEY `rank` (`rank`)" .
            ") ENGINE=MyISAM";
      
      db_exec ($sql); db_error ();

      $sql  = "CREATE TABLE `" . KB_TABLE_LABELS . "` (" .
              "`id` int(10) unsigned NOT NULL auto_increment," .
              "`group_id` int(10) unsigned NOT NULL," .
              "`name` varchar(128) NOT NULL," .
              "`visible` tinyint(1) unsigned NOT NULL," .
              "`rank` int(10) unsigned NOT NULL," .
              " PRIMARY KEY  (`id`)," .
              " KEY `group_id` (`group_id`)," .
              " KEY `visible` (`visible`)," .
              " KEY `rank` (`rank`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_RELATIONS . "` (" .
              "`entry_id` bigint(20) unsigned NOT NULL," .
              "`keyword_id` bigint(20) unsigned NOT NULL," .
              " PRIMARY KEY  (`entry_id`,`keyword_id`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_RELATIVES . "` (" .
              "`entry_id` bigint(20) unsigned NOT NULL," .
              "`relative_id` bigint(20) unsigned NOT NULL," .
              " PRIMARY KEY  (`entry_id`,`relative_id`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();
      
      $sql  = "CREATE TABLE `" . KB_TABLE_SUBSTANCES . "` (" .
              "`entry_id` bigint(20) unsigned NOT NULL," .
              "`field_id` bigint(20) unsigned NOT NULL," .
              "`textvalue` longtext NOT NULL," .
              "`binaryvalue` longblob NOT NULL," .
              "`mime` varchar(64) NOT NULL," .
              "`information` varchar(128) NOT NULL," .
              " PRIMARY KEY  (`entry_id`,`field_id`)" .
              ") ENGINE=MyISAM";

      db_exec ($sql); db_error ();

      // administrator role
      $role =& new CRole ();
      $role->role_name = KB_ROLE_ADMINISTRATOR;
      $role->role_description = 'Knowledge Box Administrator';
      $role->store ();

      // contributor role
      $role =& new CRole ();
      $role->role_name = KB_ROLE_CONTRIBUTOR;
      $role->role_description = 'Knowledge Box Contributor';
      $role->store ();

      return null;
    }

    /*
     * remove ()
     */
    function remove ()
    {
      db_exec ("DROP TABLE " . KB_TABLE_BASES);
      db_exec ("DROP TABLE " . KB_TABLE_CONFIGS);
      db_exec ("DROP TABLE " . KB_TABLE_ELEMENTS);
      db_exec ("DROP TABLE " . KB_TABLE_ENTRIES);
      db_exec ("DROP TABLE " . KB_TABLE_FIELDS);
      db_exec ("DROP TABLE " . KB_TABLE_GROUPS);
      db_exec ("DROP TABLE " . KB_TABLE_KEYWORDS);
      db_exec ("DROP TABLE " . KB_TABLE_LABELS);
      db_exec ("DROP TABLE " . KB_TABLE_RELATIONS);
      db_exec ("DROP TABLE " . KB_TABLE_RELATIVES);
      db_exec ("DROP TABLE " . KB_TABLE_SUBSTANCES);

      // get roles
      $role =& new CRole ();
      $roles = $role->getRoles ();

      // remove roles
      foreach ($roles as $role)
      {
        if ($role ['value'] == KB_ROLE_ADMINISTRATOR || $role ['value'] == KB_ROLE_CONTRIBUTOR)
        {
          $obj =& new CRole ();
          $obj->role_id = $role ['id'];
          $obj->delete ();
        }
      }

      return null;
    }

    /*
     * upgrade ()
     */
    function upgrade ($old_version)
    {
      return false;
    }

  }

?>
Return current item: Knowledge Box