<?php
  /*

      upgrade.0.9.3.inc.php

      Upgrades database to v.0.9.3

      Changelog:
        2005-07-15 arne_sf: Buffers output in array instead of displaying it immediately
        2005-07-15 arne_sf: Initial version, including database schema changes by Stephan Kaufhold
        
      ----

      Copyright (C) 2005  Arne (arne_sf@users.sourceforge.net)

      This program 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 version 2.

      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 more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  */

      
    // Initialize array (important!)
    $qry = array();
    // Create Wrktimer table...
    $output[] = "Creating 'tbl_Wrktimer' ....... ";
    $qry['pgsql'] = "
            CREATE TABLE tbl_wrktimer (
                issue int4 DEFAULT '0' NOT NULL REFERENCES tbl_Issues (id) ON DELETE CASCADE,
                userid int4 DEFAULT '0' NOT NULL REFERENCES tbl_Users (id) ON DELETE CASCADE,
                running bool DEFAULT '0' NOT NULL,
                \"begin\" timestamp NOT NULL,
                \"end\" timestamp NOT NULL,
                CONSTRAINT tbl_wrktimer_pkey PRIMARY KEY (issue,userid)
            );
            ";
    $qry['mysql'] = "
            CREATE TABLE tbl_Wrktimer (
                issue int4 DEFAULT '0' NOT NULL,
                userid int4 DEFAULT '0' NOT NULL,
                running ENUM('f','t') DEFAULT 'f' NOT NULL,
                begin DATETIME DEFAULT 'now()' NOT NULL,
                end DATETIME DEFAULT 'now()' NOT NULL,
                primary key (issue,userid)
            );
            ";
    if ($qry[$db->phptype] != "")
    {
        $res = $db->query($qry[$db->phptype]);
        $output[] = (!PEAR::isError($res) ? "Success!" : $res->getMessage()) . "<BR />\n";
    } else $output[] = "ERROR: DBMS " . $db->phptype . " not yet supported by the upgrade routine!<BR />\n";


    // Setting up work timer preferences
    $output[] = "Setting up work timer preference description ....... ";
    // First update all existing records with default value
    $qry = "
            INSERT INTO tbl_Preference_Descriptions (identifier, type, description,
                overridable) VALUES ('wrk-timer', 'boolean',
                'Turn on usage of Timer', '0');
            ";
    $res = $db->query($qry);
    if (!PEAR::isError($res))
    {
        $output[] = "Success!<BR />\n";
    } else $output[] = $res->getMessage();     // Query failed


    // Setting up work timer preferences
    $output[] = "Setting up work timer preference ....... ";
    // First update all existing records with default value
    $qry = "
            INSERT INTO tbl_Default_Preferences (identifier, value)
                VALUES ('wrk-timer', 'true');
            ";
    $res = $db->query($qry);
    if (!PEAR::isError($res))
    {
        $output[] = "Success!<BR />\n";
    } else $output[] = $res->getMessage();     // Query failed


?>
