<?
// called from: addcontact.php, updcontact.php3
// description: inserts new CONTACT, ADDRESS and PHONE
//
include("connect.inc");
include("reqlogin.inc");
// get today's date for _added and _updated fields
include("getcurrdate.inc");
// insert new CONTACT
if (!($CalledFromUpdate)) {
$InsContactSQL = "INSERT INTO contact (contact_id, contact_type, first, last, middle, sal, email, bday, website, month_added, day_added, year_added, added_user) VALUES (NULL, '$CNTType', '$FirstName', '$LastName', '$MiddleName', '$Sal', '$Email', '$BirthDate', '$URL', '$MonthNum', '$DayNum', '$YearNum', '$UserID')";
$InsContact = mysql_query($InsContactSQL,$db);
$NewContactID = mysql_insert_id($db);
// create owner information in userxcont
$InsUserXContSQL = "INSERT INTO userxcont (userxcont_id, xuser_id, xcont_id) VALUES (NULL, '$ForUser', '$NewContactID')";
$InsUserXCont = mysql_query($InsUserXContSQL);
}
else {
$NewContactID = $id;
}
// insert new ADDRESS
if ($AddrType01 != "None") {
$InsAddr01 = "INSERT INTO address (address_id, address_type, street01, street02, city, state, zip, fk_contact_id) VALUES (NULL, '$AddrType01', '$Street01', '$Street01A', '$City01', '$State01', '$Zip01', '$NewContactID')";
$InsAddr = mysql_query($InsAddr01,$db);
$NewAddr01 = mysql_insert_id($db);
$GetAddrSQL = "SELECT type_name FROM types WHERE type_id='$AddrType01'";
$GetAddr = mysql_query($GetAddrSQL);
$getaddr = mysql_fetch_array($GetAddr);
$addrname = $getaddr["type_name"];
$GetPhoneSQL = "SELECT type_id FROM types WHERE type_source='Phone' AND type_name='$addrname'";
$GetPhone = mysql_query($GetPhoneSQL);
$getphone = mysql_fetch_array($GetPhone);
$phonetype = $getphone["type_id"];
$InsPhone01 = "INSERT INTO phone (phone_id, phone_type, number, fk_contact_id, fk_address_id) VALUES (NULL, '$phonetype', '$Phone01', '$NewContactID', '$NewAddr01')";
$InsPhone = mysql_query($InsPhone01);
}
if ($AddrType02 != "None") {
$InsAddr02 = "INSERT INTO address (address_id, address_type, street01, street02, city, state, zip, fk_contact_id) VALUES (NULL, '$AddrType02','$Street02','$Street02A','$City02','$State02','$Zip02','$NewContactID')";
$InsAddr = mysql_query($InsAddr02,$db);
$NewAddr02 = mysql_insert_id($db);
$GetAddrSQL = "SELECT type_name FROM types WHERE type_id='$AddrType02'";
$GetAddr = mysql_query($GetAddrSQL);
$getaddr = mysql_fetch_array($GetAddr);
$addrname = $getaddr["type_name"];
$GetPhoneSQL = "SELECT type_id FROM types WHERE type_source='Phone' AND type_name='$addrname'";
$GetPhone = mysql_query($GetPhoneSQL);
$getphone = mysql_fetch_array($GetPhone);
$phonetype = $getphone["type_id"];
$InsPhone02 = "INSERT INTO phone (phone_id, phone_type, number, fk_contact_id, fk_address_id) VALUES (NULL, '$phonetype','$Phone02','$NewContactID','$NewAddr02')";
$InsPhone = mysql_query($InsPhone02);
}
// create phone entries not associated with an address
if ($Phone03 != "None") {
$InsPhone03 = "INSERT INTO phone (phone_id, phone_type, number, fk_contact_id, fk_address_id) VALUES (NULL, '$Phone03','$PhoneNo03','$NewContactID',0)";
$InsPhone = mysql_query($InsPhone03);
}
if ($Phone04 != "None") {
$InsPhone04 = "INSERT INTO phone (phone_id, phone_type, number, fk_contact_id, fk_address_id) VALUES (NULL, '$Phone04','$PhoneNo04','$NewContactID',0)";
$InsPhone = mysql_query($InsPhone04);
}
if ($Information) {
$InsNotesSQL = "INSERT INTO notes (note_id, type, information, fk_key) VALUES (NULL, 'Contact', '$Information', '$NewContactID')";
$InsNotes = mysql_query($InsNotesSQL);
}
$Message = "Contact Updated Successfully";
if (!($CalledFromAddUser)) {
require("contactlist.php");
exit;
}
?>