Location: PHPKode > projects > Mozart > Mozart-0.0.4/updcontact.php
<?
include("connect.inc");
include("reqlogin.inc");
include("userprefs.inc");
include("getallusers.inc");
?>
<html>
<title>Mozart: Update Contact</title>
<body bgcolor=<? echo $bgcolor ?> text=<? echo $txtcolor ?>>
<?
include("links.inc");

$ContactTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Contact' ORDER BY type_name";
$AddressTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Address' ORDER BY type_name";
$AddrPhoneSQL   = "SELECT * FROM contact, address, phone, userxcont WHERE contact_id=$id AND contact_id = address.fk_contact_id AND contact_id = phone.fk_contact_id AND address_id = phone.fk_address_id AND contact_id = xcont_id"; 
$OtherPhoneSQL  = "SELECT * FROM contact, phone WHERE contact_id=$id and contact_id = phone.fk_contact_id AND phone.fk_address_id = 0";
$PhoneTypeSQL   = "SELECT type_id, type_name FROM types WHERE type_source = 'Phone' ORDER BY type_name";
$NotesSQL       = "SELECT information FROM notes WHERE fk_key = $id AND type = 'Contact'";

$AddrPhone = mysql_query($AddrPhoneSQL); 
if (!($myrow = mysql_fetch_array($AddrPhone))) {
   $ContPhoneSQL = "SELECT * FROM contact, phone, userxcont WHERE contact_id=$id AND contact_id = phone.fk_contact_id";
   $ContPhone    = mysql_query($ContPhoneSQL);
   if (!($myrow = mysql_fetch_array($ContPhone))) {
      $ContAddrSQL = "SELECT * FROM contact, address, userxcont WHERE contact_id=$id AND contact_id = address.fk_contact_id";
      $ContAddr    = mysql_query($ContAddrSQL);
      if (!($myrow = mysql_fetch_array($ContAddr))) {
         $ContactSQL = "SELECT * FROM contact, userxcont WHERE contact_id=$id";
         $Contact    = mysql_query($ContactSQL);
         $myrow      = mysql_fetch_array($Contact);
      }
   }
}
$ContactType = mysql_query($ContactTypeSQL);
$OwnerData = mysql_query($OwnerDataSQL);
$Notes = mysql_query($NotesSQL);
?>
<form action="updatecnt.php" method="post">
<input type=hidden name="id" value="<? echo $myrow["contact_id"]?>"><br>
Contact For: <select name="ForUser">
<?
while ($ownerdata = mysql_fetch_array($OwnerData)) {
	if ($ownerdata["user_id"] == $myrow["xuser_id"]) {
	   $selected = " selected";
           $OldOwner = $myrow["owner"];
	}
	else {
	   $selected = "";
	}
	printf("<option value=%s %s>%s", $ownerdata["user_id"], $selected, $ownerdata["system_id"]);
}
$selected = " selected";
?>
</select>
<br>
<select name="Sal">
<option<? if ($myrow["sal"] == "Mr.") { printf("%s", $selected);}?>>Mr. 
<option<? if ($myrow["sal"] == "Mrs.") { printf("%s", $selected);}?>>Mrs.
<option<? if ($myrow["sal"] == "Ms.") { printf("%s", $selected);}?>>Ms.
</select>
First:<input type="text" name=FirstName value="<? echo $myrow["first"] ?>">
Middle:<input type="text" name=MiddleName value="<? echo $myrow["middle"] ?>">
Last:<input type="text" name=LastName value="<? echo $myrow["last"]?>">
<br>
DOB:<input type="text" name=BirthDate value="<? echo $myrow["bday"]?>">
Email:<input type="text" name=Email value="<? echo $myrow["email"]?>">
URL:<input type="text" name=URL value=<? echo $myrow["website"]?>>
Type:<select name=CNTType>
<?
while ($types = mysql_fetch_array($ContactType)) {
   if ($myrow["contact_type"] == $types["type_id"]) {
	$selected = " selected";
   }
   else {
	$selected = "";
   }
   printf("<option value=%s%s>%s", $types["type_id"], $selected, $types["type_name"]);
} 
?>
</select>
<table border=1 cellspacing=0 cellpadding=0>
<tr>
<?
$x = 0;
do {
   $x = $x + 1;
   $AddressType = mysql_query($AddressTypeSQL);
   ?>
   <br>
   <td>Address Type:</td><td><select name=AddrType[<?echo $x?>]>
   <option>Delete Address
   <?
   while ($addrtype = mysql_fetch_array($AddressType)) {
      if ($myrow["address_type"] == $addrtype["type_id"]) {
	 $selected = " selected";
      }
      else {
         $selected = "";
      }
      printf("<option value=%s%s>%s", $addrtype["type_id"], $selected, $addrtype["type_name"]);
   }
   ?> 
   </select>
   </td></tr>
   </tr>
   <br>
   <tr><td>Street:</td><td><input type="text" name=Street01[<?echo $x?>] value="<? echo $myrow["street01"]?>"></td></tr>
   <tr><td>Suite:</td><td><input type="text" name=Street02[<?echo $x?>] value="<? echo $myrow["street02"]?>"></td></tr>
   <tr><td>City:</td><td><input type="text" name=City[<?echo $x?>] value="<? echo $myrow["city"]?>"></td></tr>
   <tr><td>State:</td><td><input type="text" name=State[<?echo $x?>] value="<? echo $myrow["state"]?>"></td></tr>
   <tr><td>Zip:</td><td><input type="text" name=Zip[<?echo $x?>] value="<? echo $myrow["zip"]?>"></td></tr> 
   <tr><td>Phone:</td><td><input type="text" name=PhoneNo[<?echo $x?>] value="<? echo $myrow["number"]?>"></td></tr>
   <tr><td><input type=hidden name=addrkey[<? echo $x?>] value="<? echo $myrow["address_id"]?>">
   <input type=hidden name=phonekey[<? echo $x?>] value="<? echo $myrow["phone_id"]?>"></td></tr>
   <?
   }
   while ($myrow = mysql_fetch_array($AddrPhone));
?>
<tr><td><b>Other</b></td></tr>
<?
$y = $x;
$OtherPhone = mysql_query($OtherPhoneSQL);
while ($myrow = mysql_fetch_array($OtherPhone)) {
  $y = $y + 1;
  $PhoneType = mysql_query($PhoneTypeSQL);
  ?>
  <tr><td>Phone Type:</td><td><select name=AddrType[<?echo $y?>]> 
  <option>Delete Phone
  <?
  while ($phonetype = mysql_fetch_array($PhoneType)) {
	if ($myrow["phone_type"] == $phonetype["type_id"]) {
	   $selected = " selected";
	}
	else {
	   $selected = "";
	}
	printf("<option value=%s%s>%s", $phonetype["type_id"], $selected, $phonetype["type_name"]);
  }
  ?>
  </select>
  </td></tr>
  <br>
  <tr><td>Phone No.:</td><td><input type="text" name=PhoneNo[<?echo $y?>] value="<? echo $myrow["number"]?>"></td></tr>
  <input type=hidden name=phonekey[<? echo $y?>] value="<? echo $myrow["phone_id"]?>"><br>
<?
}
?>
<tr><td>Notes:</td><td><textarea cols=50 rows=10 wrap="hard" name=Information>
<?
while ($notes = mysql_fetch_array($Notes)) {
    echo $notes["information"];
}
?>
</textarea></td></tr>
<tr><td><input type="submit" value="Update"></td></tr>
</table>
<input type=hidden name="addresses" value="<? echo $x?>"><br>
<input type=hidden name="phones" value="<? echo $y?>"><br>
<input type=hidden name="OldOwner" value="<? echo $OldOwner ?>">
</form>
<?
// now display blank forms for adding new info 
$ContactTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Contact' ORDER BY type_name";
$AddressTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Address' ORDER BY type_name";
$SystemIDsSQL   = "SELECT system_id FROM users ORDER BY system_id";
$PhoneTypeSQL = "SELECT type_id, type_name FROM types WHERE type_source = 'Phone' ORDER BY type_name";

$ContactType = mysql_query($ContactTypeSQL);
$AddressType01 = mysql_query($AddressTypeSQL);
$AddressType02 = mysql_query($AddressTypeSQL);
$SystemIDs   = mysql_query($SystemIDsSQL);
$PhoneType01 = mysql_query($PhoneTypeSQL);
$PhoneType02 = mysql_query($PhoneTypeSQL);
?>
<center>
To add new addresses and phone numbers, use the form below.
<br>
To update existing information, use the form above.
</center>
<form action="inscontact.php" method="post">
<br>
<table border=1 cellspacing=0 cellpadding=0>
<tr>
<td></td>
<td>
Address Type:<select name="AddrType01">
<option>None
<?
while ($myrow = mysql_fetch_array($AddressType01)) {
   printf("<option value=%s>%s", $myrow["type_id"], $myrow["type_name"]);
}
?>
</select>
</td>
<td>
Address Type:<select name="AddrType02">
<option>None
<?
while ($myrow = mysql_fetch_array($AddressType02)) {
   printf("<option value=%s>%s", $myrow["type_id"], $myrow["type_name"]);
}
?>
</select>
</td>
<td></td>
<td>Other Phone:<select name="Phone03">
<option>None
<?
while ($myrow = mysql_fetch_array($PhoneType01)) {
   printf("<option value=%s>%s", $myrow["type_id"], $myrow["type_name"]);
}
?>
</select>
</td>
<td>Other Phone:<select name="Phone04">
<option>None
<?
while ($myrow = mysql_fetch_array($PhoneType02)) {
   printf("<option value=%s>%s", $myrow["type_id"], $myrow["type_name"]);
}
?>
</select>
</td>
<tr>
<td>Street:</td><td><input type="text" name="Street01"></td>
<td><input type="text" name="Street02"></td>
<td>Number:</td><td><input type="text" name="PhoneNo03"></td>
<td><input type="text" name="PhoneNo04"></td>
<tr>
<td>Suite:</td><td><input type="text" name="Street01A"></td>
<td><input type="text" name="Street02A"></td>
<tr>
<td>City:</td><td><input type="text" name="City01"></td>
<td><input type="text" name="City02"></td>
<tr>
<td>State:</td><td><input type="text" name="State01"></td>
<td><input type="text" name="State02"></td>
<tr>
<td>Zip:</td><td><input type="text" name="Zip01"></td>
<td><input type="text" name="Zip02"></td>
<tr>
<td>Phone:</td><td><input type="text" name="Phone01"></td>
<td><input type="text" name="Phone02"></td>
</tr>
</table>
<br>
<input type="submit" name=CalledFromUpdate value="Add">
<input type="reset" value="Clear">
<input type=hidden name="id" value="<? echo $id ?>"><br>
</form>
<?
include("links.inc");
?>
</body>
</html>
Return current item: Mozart