<?
/* Edit & Delete entry functions */
function edit_contact_list($action,$personid) {
include ('dbkey.php');
include('queries.php');
$link_edit = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Cannot connect to db");
mysql_select_db($dbname,$link_edit)
or die("Could not find db");
$result_edit = mysql_query($select_edit);
$a_row = mysql_fetch_array($result_edit);
print "<td valign=\"top\"><table width=\"100%\" border=\"0\">
<form action=\"$adm_path/edit.php?action=edit\" method=\"post\">
<tr><td colspan=\"4\" class=Highlight><b>Edit entry</b></td></tr>
<tr><td>First Name:</td>
<td><input type=\"text\" name=\"firstname\" value=\"$a_row[firstname]\" size=\"15\"></td>
<td>Last Name:</td>
<td><input type=\"text\" name=\"lastname\" value=\"$a_row[lastname]\" size=\"15\"></td></tr>
<tr><td>Title:</td>
<td><input type=\"text\" name=\"title\" value=\"$a_row[title]\" size=\"20\"></td>
<td>Phone:</td>
<td><input type=\"text\" name=\"phone\" value=\"$a_row[phone]\" size=\"12\"></td></tr>
<tr><td>Department:</td>
<td><select name=\"department\">";
$dept_select = $a_row[deptid];
/* List departments in DB and build SELECT array */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $a_row = mysql_fetch_array( $result_list ))
{
if ( $a_row[serial] == $dept_select ) {
print "<option value=\"$a_row[serial]\" selected>$a_row[department]</option>\n";
} else {
print "<option value=\"$a_row[serial]\">$a_row[department]</option>\n";
}
}
print "</select></td>
<td><input type=\"hidden\" name=\"personid\" value=\"$personid\">
<input type=\"image\" src=\"$img_path/button_upd.gif\" border=\"0\" alt=\"Update contact!\"></td></form>
<form action=\"$adm_path/edit.php?action=delete&personid=$personid\" method=\"post\"><td>
<input type=\"image\" src=\"$img_path/button_del.gif\" border=\"0\" alt=\"Delete contact!\"></td>
</form></tr></table></td>";
}
function edit_contact_upd($action,$lastname,$firstname,$title,$phone,$department,$personid,$update_person,$update_phone) {
include ('dbkey.php');
include('queries.php');
$link_update = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_update)
or die("Could not select the database");
mysql_query($update_person);
mysql_query($update_phone);
print "<td valign=\"top\"><table width=\"100%\" border=\"0\">
<tr><td class=Highlight valign=\"top\" colspan=\"4\">
<b>Successfully updated entry</b></td></tr>
<tr><td class=TinyText valign=\"top\"><b>Name</b></td>
<td class=TinyText valign=\"top\"><b>Department</b></td>
<td class=TinyText valign=\"top\"><b>Title</b></td>
<td class=TinyText valign=\"top\"><b>Phone</b></td></tr>
<tr><td>$lastname, $firstname</td>";
/* Match department serial to department name */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $a_row = mysql_fetch_array( $result_list ))
{
if ( $a_row[serial] == $department ) {
print "<td>$a_row[department]</td>";
}
}
print "<td>$title</td>
<td>$phone</td>
</tr></table></td>";
}
function edit_contact_del($action,$personid,$select_edit) {
include ('dbkey.php');
include('queries.php');
$link_edit = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Cannot connect to db");
mysql_select_db($dbname,$link_edit)
or die("Could not find db");
$result_edit = mysql_query($select_edit);
$a_row = mysql_fetch_array($result_edit);
print "<td valign=\"top\"><table width=\"100%\" border=\"0\">
<tr><td class=Highlight valign=\"top\" colspan=\"4\">
<b>Delete this entry?</b></td></tr>
<tr><td class=TinyText valign=\"top\"><b>Name</b></td>
<td class=TinyText valign=\"top\"><b>Department</b></td>
<td class=TinyText valign=\"top\"><b>Title</b></td>
<td class=TinyText valign=\"top\"><b>Phone</b></td></tr>
<tr><td>$a_row[lastname], $a_row[firstname]</td>";
$dept_select = $a_row[deptid];
/* List departments in DB and build SELECT array */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $b_row = mysql_fetch_array( $result_list ))
{
if ( $b_row[serial] == $dept_select ) {
print "<td>$b_row[department]</td>";
}
}
print "<td>$a_row[title]</td>
<td>$a_row[phone]</td>
</tr><tr><form action=\"$adm_path/delete.php\" method=\"post\">
<td colspan=\"4\"><input type=\"hidden\" name=\"personid\" value=\"$personid\">
<input type=\"image\" src=\"$img_path/button_del.gif\" border=\"0\" alt=\"Delete contact!\">
<a href=\"$adm_path/index.php\"><img src=\"$img_path/button_cancel.gif\" alt=\"Click to cancel delete\" border=\"0\"></a></td>
</form></tr></table></td>";
}
function deleted_entry($personid,$delete_person,$delete_phone) {
include ('dbkey.php');
include('queries.php');
$link_update = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_update)
or die("Could not select the database");
mysql_query($delete_person);
mysql_query($delete_phone);
print "<td class=Highlight><center><b>Contact successfully deleted.</b></center></td>";
}
/* Add entry functions */
function add_contact_form() {
include ('dbkey.php');
include('queries.php');
print "<td valign=\"top\"><table width=\"100%\" border=\"0\">
<form action=\"$adm_path/add.php?action=add\" method=\"post\">
<tr><td colspan=\"4\" class=Highlight><b>Add new entry</b></td></tr>
<tr><td>First Name:</td>
<td><input type=\"text\" name=\"firstname\" size=\"15\"></td>
<td>Last Name:</td>
<td><input type=\"text\" name=\"lastname\" size=\"15\"></td></tr>
<tr><td>Title:</td>
<td><input type=\"text\" name=\"title\" size=\"20\"></td>
<td>Phone:</td>
<td><input type=\"text\" name=\"phone\" size=\"12\"></td></tr>
<tr><td>Department:</td>
<td><select name=\"department\">";
/* List departments in DB and build SELECT */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $a_row = mysql_fetch_array( $result_list ))
{
print "<option value=\"$a_row[serial]\">$a_row[department]</option>\n";
}
print "</select></td><td colspan=\"2\">
<input type=\"image\" src=\"$img_path/button_add.gif\" border=\"0\" alt=\"Add contact!\">
</td></tr></form></table></td>";
}
function add_contact($lastname,$firstname,$title,$phone,$department,$insert_person,$insert_phone) {
include ('dbkey.php');
include('queries.php');
$link_insert = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_insert)
or die("Could not select the database");
mysql_query($insert_person);
$result_person = mysql_query("SELECT personid
FROM person
WHERE lastname = '$lastname'
AND firstname = '$firstname'");
$a_row = mysql_fetch_array($result_person);
$personid = $a_row[personid];
mysql_query("INSERT INTO phone VALUES (NULL, '$personid', '$phone')");
print "<td valign=\"top\"><table width=\"100%\" border=\"0\">
<tr><td class=Highlight valign=\"top\" colspan=\"4\">
<b>Successfully added entry</b></td></tr>
<tr><td class=TinyText valign=\"top\"><b>Name</b></td>
<td class=TinyText valign=\"top\"><b>Department</b></td>
<td class=TinyText valign=\"top\"><b>Title</b></td>
<td class=TinyText valign=\"top\"><b>Phone</b></td></tr>
<tr><td>$lastname, $firstname</td>";
/* Match department serial to department name */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $a_row = mysql_fetch_array( $result_list ))
{
if ( $a_row[serial] == $department ) {
print "<td>$a_row[department]</td>";
}
}
print "<td>$title</td>
<td>$phone</td>
</tr></table></td>";
}
function add_dept($action,$department) {
include ('dbkey.php');
include('queries.php');
$link_insert = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_insert)
or die("Could not select the database");
mysql_query($insert_dept);
print "<td class=Highlight><b>Successfully added department: $department</b></td>";
}
function edit_dept($action,$serial) {
include ('dbkey.php');
include('queries.php');
echo "<td valign=\"top\"><p>Modify the following department:</p>
<form action=\"$adm_path/dept.php?action=upd&serial=$serial\" method=\"post\">";
/* Match department serial to department name */
$link_list = mysql_connect($dbhost,$dbuser,$dbpass)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_list)
or die("Could not select the database");
$result_list = mysql_query($select_dept_list);
while ( $a_row = mysql_fetch_array( $result_list ))
{
if ( $a_row[serial] == $serial ) {
echo "<input type=\"text\" name=\"deptartment\" value=\"$a_row[department]\" size=\"15\"><br>";
}
}
echo "<input type=\"image\" src=\"$img_path/button_upd.gif\" border=\"0\" alt=\"Modify department!\">
<a href=\"$adm_path/dept.php?action=del&serial=$serial\"><img src=\"$img_path/button_del.gif\" border=\"0\"></a>
<a href=\"$adm_path/index.php\"><img src=\"$img_path/button_cancel.gif\" alt=\"Click to cancel delete\" border=\"0\">
</a></form></td>";
}
function upd_dept($action,$serial,$department) {
include ('dbkey.php');
include('queries.php');
$link_update = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_update)
or die("Could not select the database");
$result_update = mysql_query("UPDATE department SET department = '$department' WHERE serial = '$serial'");
print "<td class=Highlight><b>Successfully updated department: $department</b></td>";
}
function del_dept($action,$serial) {
include ('dbkey.php');
include('queries.php');
$link_delete = mysql_connect($dbhost,$dbadmin,$dbadmpwd)
or die("Could not connect to the database");
mysql_select_db($dbname,$link_delete)
or die("Could not select the database");
mysql_query($delete_dept);
print "<td class=Highlight><b>Successfully deleted department.</b></td>";
}
?>