<?php
  /*

      upgrade.0.9.2.inc.php

      Upgrades database to v.0.9.2

      Changelog:
        2005-07-15 arne_sf: Buffers output in array instead of displaying it immediately
        2005-07-15 arne_sf: Added support for MS SQL database backend
        2005-07-09 arne_sf: Made routine aware of DBMS type, implemented pgsql and mysql
        2005-07-02 arne_sf: Initial version
        
      ----

      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.

  */

  
    // Alter tbl_Users, rename user column
    $output[] = "Altering user column in tbl_Users ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_Users RENAME \"user\" TO username";
    $qry['mysql'] = "ALTER TABLE tbl_Users CHANGE user username VARCHAR(20) NOT NULL DEFAULT \"\"";
    $qry['mssql'] = "ALTER TABLE tbl_Users RENAME COLUMN \"user\" TO username";
    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";


    // Alter tbl_UserSites, rename user column
    $output[] = "Altering user column in tbl_UserSites ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_UserSites RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_UserSites CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_UserSites RENAME COLUMN \"user\" TO 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";
    
    
    // Alter tbl_UserDomains, rename user column
    $output[] = "Altering user column in tbl_UserDomains ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_UserDomains RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_UserDomains CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_UserDomains RENAME COLUMN \"user\" TO 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";
    
    
    // Alter tbl_Logs, rename user column
    $output[] = "Altering user column in tbl_Logs ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_Logs RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_Logs CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_Logs RENAME COLUMN \"user\" TO 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";

    
    // Alter tbl_Times, rename user column
    $output[] = "Altering user column in tbl_Times ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_Times RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_Times CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_Times RENAME COLUMN \"user\" TO 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";
    
    
    // Alter tbl_EmailConfirmation, rename user column
    $output[] = "Altering user column in tbl_EmailConfirmation ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_EmailConfirmation RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_EmailConfirmation CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_EmailConfirmation RENAME COLUMN \"user\" TO 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";
    
    
    // Alter tbl_User_Preferences, rename user column
    $output[] = "Altering user column in tbl_User_Preferences ....... ";
    $qry['pgsql'] = "ALTER TABLE tbl_User_Preferences RENAME \"user\" TO userid";
    $qry['mysql'] = "ALTER TABLE tbl_User_Preferences CHANGE user userid INT(4) NOT NULL DEFAULT 0";
    $qry['mssql'] = "ALTER TABLE tbl_User_Preferences RENAME COLUMN \"user\" TO 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"; 

?>
