<#1>
<?php
	// IMPORTANT: Inform the lead developer, if you want to add any steps here.
	//
	// This is the hotfix file for ILIAS 4.1.x DB fixes
	// This file should be used, if bugfixes need DB changes, but the
	// main db update script cannot be used anymore, since it is
	// impossible to merge the changes with the trunk.
	//
	// IMPORTANT: The fixes done here must ALSO BE reflected in the trunk.
	// The trunk needs to work in both cases !!!
	// 1. If the hotfixes have been applied.
	// 2. If the hotfixes have not been applied.
?>
<#2>
<?php

$set = $ilDB->query("SELECT event_id,usr_id,mark,e_comment".
	" FROM event_participants".
	" WHERE mark IS NOT NULL OR e_comment IS NOT NULL");
while($row = $ilDB->fetchAssoc($set))
{
	// move to ut_lp_marks

	$fields = array();
	$fields["mark"] = array("text", $row["mark"]);
	$fields["u_comment"] = array("text", $row["e_comment"]);
	// $fields["status_changed"] = array("timestamp", date("Y-m-d H:i:s"));

	$where = array();
	$where["obj_id"] = array("integer", $row["event_id"]);
	$where["usr_id"] = array("integer", $row["usr_id"]);

	$old = $ilDB->query("SELECT obj_id,usr_id".
		" FROM ut_lp_marks".
		" WHERE obj_id = ".$ilDB->quote($row["event_id"]).
		" AND usr_id = ".$ilDB->quote($row["usr_id"]));
	if($ilDB->numRows($old))
	{
		$ilDB->update("ut_lp_marks", $fields, $where);
	}
	else
	{
		$fields = array_merge($fields, $where);
		$ilDB->insert("ut_lp_marks", $fields);
	}


	// delete old values

	$fields = array();
	$fields["mark"] = array("text", null);
	$fields["e_comment"] = array("text", null);

	$where = array();
	$where["event_id"] = array("integer", $row["event_id"]);
	$where["usr_id"] = array("integer", $row["usr_id"]);

	$ilDB->update("event_participants", $fields, $where);
}
?>

<#3>
<?php
	
	$ilDB->addTableColumn(
		'export_options',
		'pos',
		array(
			'type' 		=> 'integer', 
			'length' 	=> 4,
			'notnull'	=> true,
			'default'	=> 0
		)
	);
?>
<#4>
<?php
$res = $ilDB->query("SELECT question_id, created FROM svy_question");
if ($res->numRows())
{
	while ($row = $ilDB->fetchAssoc($res))
	{
		if (preg_match("/(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})/", $row['created'], $matchescreated))
		{
			$created = mktime((int)$matchescreated[4], (int)$matchescreated[5], (int)$matchescreated[6], (int)$matchescreated[2], (int)$matchescreated[3], (int)$matchescreated[1]);
			$ilDB->manipulateF("UPDATE svy_question SET created = %s WHERE question_id = %s",
				array("text", "integer"),
				array($created, $row['question_id'])
			);
		}
	}
}
?>
<#5>
<?php
$ilDB->manipulate
(
	'UPDATE mail_obj_data SET title = '.$ilDB->quote('z_local', 'text').' '
   .'WHERE title != '.$ilDB->quote('z_local', 'text').' AND m_type = '.$ilDB->quote('local', 'text')
); 
?>

<#6>
<?php
$set = $ilDB->query("SELECT obj_id FROM object_data WHERE type = ".$ilDB->quote("tst", "text"));
while ($r = $ilDB->fetchAssoc($set))
{
	$ilDB->manipulate("UPDATE ut_lp_marks SET ".
		" status_dirty = ".$ilDB->quote(1, "integer").
		" WHERE obj_id = ".$ilDB->quote($r["obj_id"], "integer")
		);
}
?>
<#7>
<?php
	// Dummy step for reading module.xml
?>
<#8>
<?php
if($ilDB->tableColumnExists('svy_svy','mailaddresses'))
{
	$ilDB->addTableColumn("svy_svy", "mailaddresses_tmp", array("type" => "text", "length" => 2000, "notnull" => false, "default" => null));
	$ilDB->manipulate('UPDATE svy_svy SET mailaddresses_tmp = mailaddresses');
	$ilDB->dropTableColumn('svy_svy', 'mailaddresses');
	$ilDB->renameTableColumn("svy_svy", "mailaddresses_tmp", "mailaddresses");
}
?>
<#9>
<?php
if($ilDB->tableColumnExists('svy_svy','mailparticipantdata'))
{
	$ilDB->addTableColumn("svy_svy", "mailparticipantdata_tmp", array("type" => "text", "length" => 4000, "notnull" => false, "default" => null));
	$ilDB->manipulate('UPDATE svy_svy SET mailparticipantdata_tmp = mailparticipantdata');
	$ilDB->dropTableColumn('svy_svy', 'mailparticipantdata');
	$ilDB->renameTableColumn("svy_svy", "mailparticipantdata_tmp", "mailparticipantdata");
}
?>