<?php
	/**************************************************************************\
	* phpGroupWare - Setup                                                     *
	* http://www.phpgroupware.org                                              *
	* --------------------------------------------                             *
	*  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; either version 2 of the License, or (at your  *
	*  option) any later version.                                              *
	\**************************************************************************/

	/* $Id: tables_update.inc.php,v 1.13.2.3 2002/05/14 21:44:20 ceb Exp $ */

	function todo_v0_9_2to0_9_3update_owner($table, $field)
	{
		$GLOBALS['phpgw_setup']->oProc->query("select distinct($field) from $table");
		if ($GLOBALS['phpgw_setup']->oProc->num_rows())
		{
			while ($GLOBALS['phpgw_setup']->oProc->next_record())
			{
				$owner[count($owner)] = $GLOBALS['phpgw_setup']->oProc->f($field);
			}
			if($GLOBALS['phpgw_setup']->alessthanb($GLOBALS['setup_info']['phpgwapi']['currentver'],'0.9.10pre4'))
			{
				$acctstbl = 'accounts';
			}
			else
			{
				$acctstbl = 'phpgw_accounts';
			}
			for($i=0;$i<count($owner);$i++)
			{
				$GLOBALS['phpgw_setup']->oProc->query("SELECT account_id FROM $acctstbl WHERE account_lid='".$owner[$i]."'");
				$GLOBALS['phpgw_setup']->oProc->next_record();
				$GLOBALS['phpgw_setup']->oProc->query("UPDATE $table SET $field=".$GLOBALS['phpgw_setup']->oProc->f("account_id")." WHERE $field='".$owner[$i]."'");
			}
		}
		$GLOBALS['phpgw_setup']->oProc->AlterColumn($table, $field, array('type' => 'int', 'precision' => 4, 'nullable' => false, 'default' => 0));
	}

	$test[] = '0.9.1';
	function todo_upgrade0_9_1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.2';
	function todo_upgrade0_9_2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre1';
	function todo_upgrade0_9_3pre1()
	{
		todo_v0_9_2to0_9_3update_owner('todo','todo_owner');

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre2';
	function todo_upgrade0_9_3pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre3';
	function todo_upgrade0_9_3pre3()
	{
		$GLOBALS['phpgw_setup']->oProc->AddColumn("todo", "todo_id_parent", array("type" => "int", "precision" => 4, "nullable" => false, "default" => "0"));

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre4';
	function todo_upgrade0_9_3pre4()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre5';
	function todo_upgrade0_9_3pre5()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre6';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre6';
	function todo_upgrade0_9_3pre6()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre7';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre7';
	function todo_upgrade0_9_3pre7()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre8';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre8';
	function todo_upgrade0_9_3pre8()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre9';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre9';
	function todo_upgrade0_9_3pre9()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3pre10';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3pre10';
	function todo_upgrade0_9_3pre10()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.3';
	function todo_upgrade0_9_3()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4pre1';
	function todo_upgrade0_9_4pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4pre2';
	function todo_upgrade0_9_4pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4pre3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4pre3';
	function todo_upgrade0_9_4pre3()
	{
		$GLOBALS['phpgw_setup']->oProc->AddColumn("todo", "todo_startdate", array("type" => "int", "precision" => 4));
		$GLOBALS['phpgw_setup']->oProc->RenameColumn("todo", "todo_datedue", "todo_enddate");

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4pre4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4pre4';
	function todo_upgrade0_9_4pre4()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4pre5';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4pre5';
	function todo_upgrade0_9_4pre5()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.4';
	function todo_upgrade0_9_4()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.5pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.5pre1';
	function todo_upgrade0_9_5pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.5pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.5pre2';
	function todo_upgrade0_9_5pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.5';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.5';
	function todo_upgrade0_9_5()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.6';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.6';
	function todo_upgrade0_9_6()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.7pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.7pre1';
	function todo_upgrade0_9_7pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.7pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.7pre2';
	function todo_upgrade0_9_7pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.7pre3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.7pre3';
	function todo_upgrade0_9_7pre3()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.7';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.7';
	function todo_upgrade0_9_7()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.8pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.8pre1';
	function todo_upgrade0_9_8pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.8pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.8pre2';
	function todo_upgrade0_9_8pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.8pre3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.8pre3';
	function todo_upgrade0_9_8pre3()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.8pre4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.8pre4';
	function todo_upgrade0_9_8pre4()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.8pre5';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.8pre5';
	function todo_upgrade0_9_8pre5()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.9pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.9pre1';
	function todo_upgrade0_9_9pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.9';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.9';
	function todo_upgrade0_9_9()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre1';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre1';
	function todo_upgrade0_9_10pre1()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre2';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre2';
	function todo_upgrade0_9_10pre2()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre3';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre3';
	function todo_upgrade0_9_10pre3()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre4';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre4';
	function todo_upgrade0_9_10pre4()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre5';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre5';
	function todo_upgrade0_9_10pre5()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre6';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre6';
	function todo_upgrade0_9_10pre6()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre7';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre7';
	function todo_upgrade0_9_10pre7()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre8';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre8';
	function todo_upgrade0_9_10pre8()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre9';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre9';
	function todo_upgrade0_9_10pre9()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre10';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre10';
	function todo_upgrade0_9_10pre10()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre11';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre11';
	function todo_upgrade0_9_10pre11()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre12';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre12';
	function todo_upgrade0_9_10pre12()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre13';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre13';
	function todo_upgrade0_9_10pre13()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre14';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre14';
	function todo_upgrade0_9_10pre14()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre15';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre15';
	function todo_upgrade0_9_10pre15()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre16';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre16';
	function todo_upgrade0_9_10pre16()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre17';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre17';
	function todo_upgrade0_9_10pre17()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre18';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre18';
	function todo_upgrade0_9_10pre18()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre19';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre19';
	function todo_upgrade0_9_10pre19()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre20';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre20';
	function todo_upgrade0_9_10pre20()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre21';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre21';
	function todo_upgrade0_9_10pre21()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre22';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre22';
	function todo_upgrade0_9_10pre22()
	{
		$GLOBALS['phpgw_setup']->oProc->RenameTable('todo','phpgw_todo');

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre23';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre23';
	function todo_upgrade0_9_10pre23()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre24';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre24';
	function todo_upgrade0_9_10pre24()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre25';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre25';
	function todo_upgrade0_9_10pre25()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre26';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre26';
	function todo_upgrade0_9_10pre26()
	{
		$GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_todo','todo_cat',array('type' => 'int','precision' => 4,'nullable' => True));

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre27';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre27';
	function todo_upgrade0_9_10pre27()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10pre28';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10pre28';
	function todo_upgrade0_9_10pre28()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.10';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.10';
	function todo_upgrade0_9_10()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.001';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11';
	function todo_upgrade0_9_11()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.001';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.001';
	function todo_upgrade0_9_11_001()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.002';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.003';
	function todo_upgrade0_9_11_003()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.004';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.004';
	function todo_upgrade0_9_11_004()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.005';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.005';
	function todo_upgrade0_9_11_005()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.006';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.006';
	function todo_upgrade0_9_11_006()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.007';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.007';
	function todo_upgrade0_9_11_007()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.008';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.008';
	function todo_upgrade0_9_11_008()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.009';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.009';
	function todo_upgrade0_9_11_009()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.010';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.010';
	function todo_upgrade0_9_11_010()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.11.011';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.11.011';
	function todo_upgrade0_9_11_011()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.13.001';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}
	$test[] = '0.9.12';
	function todo_upgrade0_9_12()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.13.001';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}
	$test[] = '0.9.13.001';
	function todo_upgrade0_9_13_001()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.13.002';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.13.002';
	function todo_upgrade0_9_13_002()
	{
		$GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_todo','todo_id_main',array('type' => 'int','precision' => 4,'default' => 0,'nullable' => False));
		$GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_todo','todo_level',array('type' => 'int','precision' => 2,'default' => 0,'nullable' => False));
		$GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_todo','todo_id_parent',array('type' => 'int','precision' => 4,'default' => 0,'nullable' => False));
		$GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_todo','todo_cat',array('type' => 'int','precision' => 4,'default' => 0,'nullable' => False));
		$GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_todo','todo_enddate',array('type' => 'int','precision' => 4,'default' => 0,'nullable' => False));

		$db = $GLOBALS['phpgw_setup']->db;

		$GLOBALS['phpgw_setup']->oProc->query("select todo_id from phpgw_todo where todo_id_main='0'");

		while ($GLOBALS['phpgw_setup']->oProc->next_record())
		{
			$db->query("update phpgw_todo set todo_id_main='" . $GLOBALS['phpgw_setup']->oProc->f('todo_id') . "' "
						. "where todo_id='" . $GLOBALS['phpgw_setup']->oProc->f('todo_id') . "'");

		}

		$GLOBALS['phpgw_setup']->oProc->query("select todo_id_parent from phpgw_todo");

		while ($GLOBALS['phpgw_setup']->oProc->next_record())
		{
			if ($GLOBALS['phpgw_setup']->oProc->f('todo_id_parent') != 0)
			{
				$db->query("update phpgw_todo set todo_id_main='" . $GLOBALS['phpgw_setup']->oProc->f('todo_id_parent') . "',"
							. "todo_level='1' where todo_id_parent='" . $GLOBALS['phpgw_setup']->oProc->f('todo_id_parent') . "'");
			}
		}

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.13.003';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.13.003';
	function todo_upgrade0_9_13_003()
	{
		$GLOBALS['phpgw_setup']->oProc->AddColumn('phpgw_todo','todo_title',array('type' => 'varchar','precision' => 255,'nullable' => False));
		$GLOBALS['phpgw_setup']->oProc->AlterColumn('phpgw_todo','todo_owner',array('type' => 'int','precision' => 4,'default' => 0,'nullable' => False));

		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.13.004';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}

	$test[] = '0.9.13.004';
	function todo_upgrade0_9_13_004()
	{
		$GLOBALS['setup_info']['todo']['currentver'] = '0.9.14';
		return $GLOBALS['setup_info']['todo']['currentver'];
	}
?>
