<?
// called from: addappt.php
// description: creates a new entry in the APPOINTMENT table
//
include("connect.inc");
include("reqlogin.inc");
if (!(checkdate($SelMon, $SelDay, $SelYear))) {
$error_message = "Invalid Date";
include("addappt.php");
exit;
}
//get today's date for _added fields
include("getcurrdate.inc");
// set User_ID to $ForUser (who the todo is being created for)
// $UserID = $ForUser;
$SearchSys = $ForUser;
// correct problem input
$Information = addslashes($Information);
$SelTime = "$SelHour" . ":" . "$SelMinute" . ":00";
// insert new contact
$InsAppointmentSQL = "INSERT INTO appointment (appt_id, owner, month, day, year, time, information, month_added, day_added, year_added, added_user) VALUES (NULL, '$ForUser', '$SelMon', '$SelDay', '$SelYear', '$SelTime', '$Information', '$MonthNum', '$DayNum', '$YearNum', '$UserID')";
$InsAppointment = mysql_query($InsAppointmentSQL,$db);
$NewApptID = mysql_insert_id($db);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "Appointment Added Successfully";
}
else {
$Message = "Error $errno: $error";
}
// create entry in user-appt cross-reference table
$InsUserXSQL = "INSERT INTO userxappt (userxappt_id, xuser_id, xappt_id) VALUES (NULL, '$ForUser', '$NewApptID')";
$InsUserX = mysql_query($InsUserXSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "Appointment Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
//if $ForProject, then create entry in appointment-project cross-reference table
if ($ForProject) {
$InsProjXSQL = "INSERT INTO apptxproj (apptxproj_id, xappt_id, xproj_id) VALUES (NULL, '$NewApptID', '$ForProject')";
$InsProjX = mysql_query($InsProjXSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "Appointment Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
}
//if $ForContact, then create entry in contact-appointment cross-reference table
if ($ForContact) {
$InsContXSQL = "INSERT INTO contxappt (contxappt_id, xcont_id, xappt_id) VALUES (NULL, '$ForContact', '$NewApptID')";
$InsContX = mysql_query($InsContXSQL);
$errno = mysql_errno($db);
$error = mysql_error($db);
if ($errno == 0) {
$Message = "Appointment Added Successfully";
}
else {
$Message = "Error $errno: $error";
require("calendar.php");
exit;
}
}
include("calendar.php");
exit;
?>