<?
// called from: addtodo.php
// description: inserts new entry to TODO table
//
include("connect.inc");
include("reqlogin.inc");
// if invalid date, return to addtoto
if (!(checkdate($SelMon, $SelDay, $SelYear))) {
$error_message = "Invalid Date";
include("addtodo.php");
exit;
}
// get current date for _added fields
include("getcurrdate.inc");
// set User_ID to $ForUser (who the todo is being created for)
$UserID = $ForUser;
$SearchSys = $ForUser;
// add slashes to info field for database compatibility
$Information = addslashes($Information);
// insert new to do
$InsToDoSQL = "INSERT INTO todo (todo_id, owner, month, day, year, priority, information, complete, month_added, day_added, year_added, added_user) VALUES (NULL, '$UserID', '$SelMon', '$SelDay', '$SelYear', '$Priority', '$Information', ' ', '$MonthNum', '$DayNum', '$YearNum', '$UserID')";
$InsToDo = mysql_query($InsToDoSQL,$db);
$NewToDoID = mysql_insert_id($db);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "To Do Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
// create entry in user-todo cross-reference table
$InsUserXSQL = "INSERT INTO userxtodo (userxtodo_id, xuser_id, xtodo_id) VALUES (NULL, '$UserID', '$NewToDoID')";
$InsUserX = mysql_query($InsUserXSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "To Do Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
//if $ForProject, then create entry in todo-project cross-reference table
if ($ForProject) {
$InsProjXSQL = "INSERT INTO todoxproj (todoxproj_id, xtodo_id, xproj_id) VALUES (NULL, '$NewToDoID', '$ForProject')";
$InsProjX = mysql_query($InsProjXSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "To Do Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
}
require("calendar.php");
exit;
?>