Location: PHPKode > scripts > Prioritexter > P_CreateTable.php
<?php
class P_CreateTable {

  function createTables() {
    global $db;

    Debug::debug("creating tables");

    $q[] = "CREATE TABLE ". DB_PROJECT_NICKNAME ."_prioritizer_task ("
       . "task_id mediumint(9) NOT NULL auto_increment,"
       . "name varchar(255) NOT NULL default 'Unnamed task',"
       . "notes tinytext,"
       . "priority tinyint(4) NOT NULL default '5',"
       . "created bigint(20) default NULL,"
       . "due bigint(20) default NULL,"
       . "adjustment int(11) NOT NULL default '0',"
       . "type enum('task','project','dream') NOT NULL default 'task',"
       . "active tinyint(1) NOT NULL default '1',"
       . "finished bigint(20) default NULL,"
       . "PRIMARY KEY(task_id)"
       . ") TYPE=MyISAM";
       
    $q[] = "CREATE TABLE ". DB_PROJECT_NICKNAME ."_prioritizer_task_category ("
       . " task_category_id int(11) NOT NULL auto_increment,"
       . " task_id int(11) default NULL,"
       . " category_id int(11) default NULL,"
       . " PRIMARY KEY(task_category_id),"
       . " KEY task_id (task_id,category_id)"
       . " ) TYPE=MyISAM";

    $q[] = "CREATE TABLE ". DB_PROJECT_NICKNAME ."_prioritizer_category ("
       . "category_id int(11) NOT NULL auto_increment,"
       . "category_name tinytext,"
       . "PRIMARY KEY(category_id)"
       . ") TYPE=MyISAM";

    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (1, 'Misc')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (2, 'Office')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (3, 'Home')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (4, 'Call')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (5, 'Errand')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_category VALUES (6, 'Social')";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_task VALUES (1, 'Welcome to "
       . "Prioritizer Beta! Please delete this message after reading it. "
       . "The icons at the right of each item will tell you what they "
       . "represent if you move the mouse pointer onto them.', '', 1, "
       . "1106064000, 1421424000, 0, 'task', 1, NULL)";
    $q[] = "INSERT INTO ". DB_PROJECT_NICKNAME
       . "_prioritizer_task_category VALUES (1, 1, 1)";

    foreach($q as $query_str) 
      $result = $db->query($query_str);
  }

  function createIfDontExist() {
    global $db;

    Debug::debug("testing tables");
    if (!$db->testTable("task")) P_CreateTable::createTables();
  }

}
?>
Return current item: Prioritexter