Location: PHPKode > projects > Mozart > Mozart-0.0.4/updappt.php
<?
// called from: calendar.php
// description: updates entries in APPOINTMENT table
//
include("connect.inc");
include("reqlogin.inc");
include("userprefs.inc");
?>
<html>
<title>Mozart: Update Appointment</title>
<body bgcolor=<? echo $bgcolor ?> text=<? echo $txtcolor ?>>
<?
include("links.inc");
include("getcurrdate.inc");
$error_message = "";
$Information = addslashes($Information);

if (!(checkdate($SelMon, $SelDay, $SelYear)) and ($SelMon)) {
	$error_message = "Invalid Date";
}
elseif ($Insert) {
	$SelTime = "$SelHour" . ":" . "$SelMinute" . ":00";
	$UpdApptSQL = "UPDATE appointment SET owner = '$NewSysID', month = '$SelMon', day = '$SelDay', year = '$SelYear', time = '$SelTime', information = '$Information', month_updated = '$MonthNum', day_updated = '$DayNum', year_updated = '$YearNum', updated_user = '$UserID' WHERE appt_id = '$id'";
	$UpdAppt = mysql_query($UpdApptSQL);

	$errno = mysql_errno($db);
	$error = mysql_error($db);
	if ($errno == 0) {
		$Message = "Appointment Updated Successfully";
	}
	else {
		$Message = "Error $errno: $error";
	}
        include("updapptxproj.inc");
        include("inscontxappt.inc");
	include("calendar.php");
	exit;
}

// read appointment
$GetAppointmentSQL = "SELECT owner, month, day, year, time, information FROM appointment WHERE appt_id = '$id'";
$GetAppointment = mysql_query($GetAppointmentSQL);
$getappt = mysql_fetch_array($GetAppointment);

// read users
include("getallusers.inc");
?>
<form action="updappt.php" method="post">
Change to user:<select name="NewSysID">
<?
while ($ownerdata = mysql_fetch_array($OwnerData)) {
	if ($ownerdata["user_id"] == $getappt["owner"]) {
		$selected = " selected";
                $selected_user = $ownerdata["user_id"]; 
	}
	else {
		$selected = "";
	}
	printf("<option value=%s%s>%s", $ownerdata["user_id"], $selected, $ownerdata["system_id"]);
}
?>
</select>
Month: <select name=SelMon>
<?
$x = 1;
while ($x <= 12) {
	if ($x == $getappt["month"]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf ("<option%s>%s", $selected, $x);
	$x++;
}
?>
</select>
Day: <select name=SelDay>
<?
$x = 1;
while ($x <= 31) {
	if ($x == $getappt["day"]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf ("<option%s>%s", $selected, $x);
	$x++;
}
?>
</select>
Year: <select name=SelYear>
<?
$current_date = getdate();
$curryear = $current_date["year"];
$x = 1;
while ($x <= 10) {
	if ($curryear == $getappt["year"]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf ("<option%s>%s", $selected, $curryear);
	$x++;
	$curryear++;
}
// break time (12:15:00) into $hour and $minute
$x = 1;
for(	$token = strtok($getappt["time"], ":");
	$token != "";
	$token = strtok(":"))
{
	$var[$x] = $token;
	$x++;
}
// now $var[1] should contain the hour
// and $var[2] should contain the minute
?>
</select>
<br>
Time:<select name=SelHour>
<?
$x = 0;
while ($x <= 23) {
	if ($x == $var[1]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf ("<option%s>%s", $selected, $x);
	$x++;
}
?>
</select>
<select name=SelMinute>
<?
$x = 0;
while ($x <= 50) {
	if ($x == $var[2]) {
		$selected = " selected";
	}
	else {
		$selected = "";
	}
	printf ("<option%s>%s", $selected, $x);
	$x = $x + 15;
}
?>
</select>
<br>
Appointment Details:<br><textarea cols=50 rows=10 wrap="hard" name=Information value=$getappt["information"]><? echo $getappt["information"]?></textarea>
<br>
<?
// list contact already associated with appointment
$AssocContSQL = "SELECT contxappt_id, xcont_id FROM contxappt WHERE xappt_id=$id";
$AssocCont    = mysql_query($AssocContSQL);

?>
<table cellspacing=0 cellpadding=0 border=1>
<tr><th>Associated Contacts</th></tr>
<?
while ($assoccont = mysql_fetch_array($AssocCont)) {
// get contact name
   $contactid   = $assoccont["xcont_id"];
   $ContNameSQL = "SElECT last, first FROM contact WHERE contact_id=$contactid";
   $ContName    = mysql_query($ContNameSQL);
   $contname    = mysql_fetch_array($ContName);
   printf("<tr><td><a href=\"display.php?id=%s\">%s, %s</a></td>", $assoccont["xcont_id"], $contname["last"], $contname["first"]);
   printf("<td><a href=\"delcontxappt.php?id=%s\">Disassociate</a></td></tr>", $assoccont["contxappt_id"]);
}
?>
</table>
<?
// get associated project if applicable
$ApptXProjSQL = "SELECT xproj_id FROM apptxproj WHERE xappt_id=$id";
$ApptXProj = mysql_query($ApptXProjSQL);
$apptxproj = mysql_fetch_array($ApptXProj);
$ProjID = $apptxproj["xproj_id"];

// get all projects for user
$ProjDataSQL = "SELECT proj_id, name FROM project, userxproj WHERE proj_id = xproj_id AND xuser_id = '$selected_user' ORDER BY name";
$ProjData    = mysql_query($ProjDataSQL);
print ("Associate with project: <select name=\"ForProject\">");
print ("<option value=0>None");
while ($projdata = mysql_fetch_array($ProjData)) {
   if ($projdata["proj_id"] == $ProjID) {
       $selected = " selected";
   }
   else {
       $selected = "";
   }
       printf("<option value=%s%s>%s", $projdata["proj_id"], $selected, $projdata["name"]);
}
print("</select>");

// get associated contact if applicable
$ContXApptSQL = "SELECT xcont_id FROM contxappt WHERE xappt_id=$id";
$ContXAppt = mysql_query($ContXApptSQL);
$contxappt = mysql_fetch_array($ContXAppt);
$ContID = $contxappt["xcont_id"];

// get all contacts for user
$ContDataSQL = "SELECT contact_id, last, first FROM contact, userxcont WHERE xuser_id = '$selected_user' AND contact_id = xcont_id ORDER BY last, first";
$ContData    = mysql_query($ContDataSQL);
print ("Associate new contact: <select name=\"ForContact\">");
print ("<option value=0>None");
while ($contdata = mysql_fetch_array($ContData)) {
       printf("<option value=%s>%s, %s", $contdata["contact_id"], $contdata["last"], $contdata["first"]);
}
print("</select>");

?>
<br>
<input type=submit name=Insert value="Update Appt">
<input type=reset value="Reset">
<input type=hidden name=id value=<? echo $id ?>>
<input type=hidden name=Mon value=<? echo $Mon ?>>
<input type=hidden name=Day value=<? echo $Day ?>>
<input type=hidden name=Year value=<? echo $Year ?>>
</form>
<?
include("links.inc");
?>
</body>
</html>
Return current item: Mozart