$value)
{
if ($value == "")
{
unset ($a[$key]); //get rid of the empty ones
}
}
$agenda = array_values($a); //new agenda array starting with key 0
$num = count($agenda); //number of agenda's
include ("config.inc.php"); //connect to mysql database
if (IsSet ($_POST[date_new]))
{
$date_new = $_POST[date_new];
}
for ($i = 1; $i < count($date_new) + 1; $i++) //loop trough the array of timeslots
{
if ($date_new[$i] != "") //something is filled in
{
if (!get_magic_quotes_gpc())
{
$date_new[$i] = addslashes($date_new[$i]); //add slashes if needed
}
for ($k = 0; $k < $num; $k++) //check in every agenda if record exists
{
$query = "SELECT id FROM $table_agenda_events WHERE adate = '$save_date' AND agenda = '$agenda[$k]' AND timeslot = '$i'";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
//print $query."
" ;
if ($numRows > 0)
{
$result = mysql_query("UPDATE $table_agenda_events SET descr = '$date_new[$i]' WHERE adate = '$save_date' AND timeslot = '$i' AND agenda = '$agenda[$k]'");
if (mysql_errno() != 0)
{
echo mysql_errno() . ": " . mysql_error() . "
";
}
}
else
{ //we have to insert a new one
// print "INSERT INTO agenda (id , adate , timeslot, descr, agenda) VALUES('', '$save_date', '$i', '$date_new[$i]', '$agenda[$k]')" ; //we have a record, update it
$result = mysql_query("INSERT INTO $table_agenda_events (id , adate , timeslot, descr, agenda) VALUES('', '$save_date', '$i', '$date_new[$i]', '$agenda[$k]')");
if (mysql_errno() != 0)
{
echo mysql_errno() . ": " . mysql_error() . "
";
}
}
}
}
else //empty slot , see if have to delete
{
if ($num == 1) //only delete when we have 1 agenda
{
mysql_query("DELETE FROM $table_agenda_events WHERE adate = '$save_date' AND agenda = '$agenda[0]' AND timeslot = '$i'");
}
}
}
Header("Location: agenda.php?date=$date&a=$_GET[a]");
?>