Location: PHPKode > projects > O - OpenSource GroupWare > osgw/contacts/edit_contact.php
<?php
/**************************************************************************
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   @Authors:	Ryan Thompson(hide@address.com)
***************************************************************************/
include("./data.php");
$service['add_header'] = TRUE;
include("../config.inc.php");
include($here. "/class.contacts.php");
$ct = new contacts;

$user_id = $user->user_id;
if(isset($_POST['save_contact']))
{
	$ct->edit($_POST);
	echo $db->db_error;


}
echo $layout->page_header;

echo $layout->service_header($ct->msg('service_name'), $ct->nav_buttons(), $ct->msg('edit_contact'));

$sql = "SELECT * FROM o_contacts WHERE address_id='$_GET[id]' AND user_id='$user_id'";
$db->query($sql);
$db->fetch_results();

echo "<form name=\"contact\" method=\"post\">";
echo "<table align=\"center\" cellspacing=\"0\">";
echo "<tr>";

echo "<td class=\"input_header\">Title:</td>";
echo "<td>\n";
$title = array("Mr.", "Mrs.", "Ms.", "Miss", "Dr.", "Prof.");
echo "<select name=\"title\">";
$i = 0;
while($i < count($title))
{
	echo "<option value=\"$title[$i]\"";
	if($db->record['title'] == $title[$i])
	{
		echo " selected=\"selected\"";
	}
	
	echo ">$title[$i]</option>";
	
	$i++;
}
echo "</select>";
echo "</td></tr>";
echo "<tr><td class=\"input_header\">First name:</td><td><input type=\"text\" size=\"40\" name=\"firstname\" value=\"". $db->record['firstname'] ."\"></td></tr>\n";
echo "<tr><td class=\"input_header\">Last name:</td><td><input type=\"text\" size=\"40\" name=\"lastname\" value=\"". $db->record['lastname'] ."\"></td></tr>\n";
echo "<tr><td class=\"input_header\">Birthday</td><td>";

$bday = explode('-',$db->record['birthday']);

echo "<select name=\"birthday_day\">\n";
echo "<option value=\"$bday[2]\">$bday[2]</option>";
echo "<option value=''>---</option>";
$i = 1;

while($i<=31)
{
	if(strlen($i) == 1)
	{
		$i = '0'.$i;
	}
	echo "<option value=\"$i\">$i</option>\n";
	$i++;
}

echo "</select>\n\n";
echo "<select name=\"birthday_month\">\n";

//Not a very good way to do this but I have to strip the zero.
$m = $bday[1] + 1;
$m--;
echo "<option value=\"$bday[1]\">". $med_months[$m] ."</option>";
echo "<option value=''>---</option>";
$i = 1;

while($i<=count($med_months))
{

	if(strlen($i) == 1)
	{
		$d = '0'.$i;
	} else {
		$d = $i;
	}
	echo "<option value=\"$d\">". $med_months[$i] ."</option>\n";
$i++;
}

echo "</select>\n\n";
echo "<select name=\"birthday_year\">";
echo "<option value=\"$bday[0]\">$bday[0]</option>";
echo "<option value=''>-----</option>";
$i = 1900;
while($i <= date("Y"))
{
	echo "<option value=\"$i\">$i</option>\n";
	$i++;
}

echo "</select>\n\n";


echo "</td></tr>\n";
echo "<tr><td class=\"input_header\">Phone Number:</td>\n";
echo "<td><input type=\"text\" size=\"20\" name=\"phone\" value=\"". rtrim($db->record['phone']) ."\">\n";
echo "</td></tr>\n";
echo "<tr><td class=\"input_header\">Fax Number:</td>\n";
echo "<td><input type=\"text\" size=\"20\" name=\"fax\" value=\"". rtrim($db->record['fax']) ."\"></td></tr>\n";
echo "<tr><td class=\"input_header\">Cell Phone:</td>\n";
echo "<td><input type=\"text\" size=\"20\" name=\"cell\" value=\"". rtrim($db->record['cell']) ."\"></td></tr>\n";
echo "<tr><td class=\"input_header\">Email Address:</td><td><input type=\"text\" size=\"40\" name=\"email_address\" value=\"". $db->record['email'] ."\"></td></tr>";
echo "<tr><td class=\"input_header\">Address:</td><td><input type=\"text\" size=\"40\" name=\"address\" value=\"". $db->record['address1'] ."\"></td></tr>";
echo "<tr><td class=\"input_header\">Address 2:</td><td><input type=\"text\" size=\"40\" name=\"address2\" value=\"". $db->record['address2'] ."\"></td></tr>";
echo "<tr><td class=\"input_header\">City:</td><td><input type=\"text\" size=\"40\" name=\"city\" value=\"". $db->record['city'] ."\"></td></tr>";
echo "<tr><td class=\"input_header\">Province/State:</td><td><input type=\"text\" size=\"40\" name=\"province\" value=\"". $db->record['province'] ."\"></td></tr>";
$pc = $db->record['postal_code'];
$dept = $db->record['department'];
$company = $db->record['company'];
$website = $db->record['website'];
echo "<tr><td class=\"input_header\">Country:</td>";

$sql = "SELECT o_countries.* FROM o_countries 
	LEFT JOIN o_contacts ON o_countries.c_id=o_contacts.country 
	WHERE o_contacts.address_id='". $_GET['id'] ."'";
$db->query($sql);
$db->fetch_results();
echo "<td><select name=\"country\">\n";
echo "<option value=\"". $db->record['c_id'] ."\">". $db->record['country'] ."</option>\n";
echo "<option value=\"-----------------\">-----------------</option>\n";
	$sql = "SELECT * FROM o_countries";
	$db->query($sql,__FILE__,__LINE__);
	while($db->fetch_results())
	{
	
		echo "<option value=\"". $db->record['c_id'] ."\">". $db->record['country'] ."</option>\n";
	}

echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td class=\"input_header\">Postal Code:</td><td><input type=\"text\" size=\"7\" name=\"postal_code\" value=\"$pc\"></td></tr>";
echo "<tr><td class=\"input_header\">Website:</td>\n<td><input type=\"text\" size=\"40\" name=\"website\" value=\"$website\"></td></tr>\n";
echo "<tr><td class=\"input_header\">\n";
echo "Company:\n";
echo "</td><td>\n";
echo "<input type=\"text\" name=\"company\" size=\"40\" value=\"$company\">\n";
echo "</td></tr>\n";
echo "<tr><td class=\"input_header\">\n";
echo "Department:\n";
echo "</td><td>\n";
echo "<input type=\"text\" name=\"department\" size=\"40\" value=\"$dept\">\n";
echo "</td></tr>\n";


$link = $_SERVER['PHP_SELF'];
$add = "onSubmit=\"alert(forms['contact'].firstname.value;if(forms['contact'].firstname.value == ''){ alert('You must supply at least a first name')}\"";
?>
<tr><td>
<input type="submit" name="save_contact" value="Save Contact" class="button1">
</form>
</td><td>

<input type="submit" name="cancel_edit" value="Cancel" onClick="window.location='add_contact.php'" class="button1">
</td>
</tr>
</table>



<?php

echo "&nbsp;&nbsp;\n";

echo $layout->create_footer();

?>
Return current item: O - OpenSource GroupWare