<?
//v1.1 www.exoops.info 2006/03 
//	Version	: 1.0
//	Author	: code
//	Email	: codehar@code-den.com
//	Website	: http://www.code-den.com
/* Edit & Delete entry functions */
if ( @file_exists(XOOPS_ROOT_PATH."/modules/directory/language/".$bcoosConfig['language'].'/language.php') ) {
	include_once(XOOPS_ROOT_PATH."/modules/directory/language/".$bcoosConfig['language'].'/language.php');
	} else {
		include_once(XOOPS_ROOT_PATH."/modules/directory/language/english/language.php");
	}
	
function edit_contact_list($action,$personid) {
		include ('dbkey.php');
		include('queries.php');
		$result_edit = $db->query($select_edit);
		$a_row = mysql_fetch_array($result_edit);
		print "<td valign=\"top\">";
		OpenTable();
		print "<table width=\"100%\" border=\"0\">
			<form action=\"$adm_path/edit.php?action=edit\" method=\"post\">
			<tr><td colspan=\"4\" class=Highlight><b>";
			echo _CODE_DIR_EDIT_ENTRY;
			print "</b></td></tr>
			<tr><td>";
			echo _CODE_DIR_FIRSTNAME;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"firstname\" value=\"$a_row[firstname]\" size=\"15\"></td>
			<td>";
			echo _CODE_DIR_LASTNAME;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"lastname\" value=\"$a_row[lastname]\" size=\"15\"></td></tr>
			<tr><td>";
			echo _TITLE;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"title\" value=\"$a_row[title]\" size=\"20\"></td>
			<td>";
			echo _CODE_DIR_PHONE;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"phone\" value=\"$a_row[phone]\" size=\"12\"></td></tr>
			<td>";
			echo _CODE_DIR_ADDRESS;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"address\" value=\"$a_row[address]\" size=\"20\"></td></tr>
			<tr><td>";
			echo _CODE_DIR_DEPARTMENT;
			print ":</td>
			<td><select class=\"select\" name=\"department\">";
		$dept_select = $a_row[deptid];
		/* List departments in DB and build SELECT array */
		$result_list = $db->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>";
 CloseTable();
		print "</td>";
}
function edit_contact_upd($action,$lastname,$firstname,$title,$phone,$address,$department,$personid,$update_person,$update_phone) {
	
		include ('dbkey.php');
		include('queries.php');
		$db->query($update_person);
		$db->query($update_phone);
		print "<td valign=\"top\">";
		OpenTable();
		print "<table width=\"100%\" border=\"0\">
			<tr><td class=Highlight valign=\"top\" colspan=\"4\">
			<b>";
			echo _CODE_DIR_SUCCESS_UPD_ENTRY;
			print "</b></td></tr>
			<tr><td class=TinyText valign=\"top\"><b>";
			echo _NAME;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_DEPARTMENT;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _TITLE;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_PHONE;
			print "</b></td>
      <td class=TinyText valign=\"top\"><b>";
	  echo _CODE_DIR_ADDRESS;
	  print "Address</b></td></tr>
			<tr><td>$lastname, $firstname</td>";
		/* Match department serial to department name */
		$result_list = $db->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>
			<td>$address</td>			
			</tr></table>";
			CloseTable();
			print "</td>";
}
function edit_contact_del($action,$personid,$select_edit) {
		include ('dbkey.php');
		include('queries.php');
		$result_edit = $db->query($select_edit);
		$a_row = mysql_fetch_array($result_edit);
		print "<td valign=\"top\">";
		OpenTable();
		print "<table width=\"100%\" border=\"0\">
			<tr><td class=Highlight valign=\"top\" colspan=\"4\">
			<b>";
			echo _CODE_DIR_QUEST_DELETE;
			print "</b></td></tr>
			<tr><td class=TinyText valign=\"top\"><b>";
			echo _NAME;
			print"</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_DEPARTMENT;
			print"</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _TITLE;
			print "Title</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_PHONE;
			print "</b></td>
      <td class=TinyText valign=\"top\"><b>";
	  echo _CODE_DIR_ADDRESS;
	  print "</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 */
		$result_list = $db->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>
			<td>$a_row[address]</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>";
			CloseTable();
			print "</td>";
}
function deleted_entry($personid,$delete_person,$delete_phone) {
		include ('dbkey.php');
		include('queries.php');
		$db->query($delete_person);
		$db->query($delete_phone);
	    print "<td class=Highlight><center><b>";
		echo _CODE_DIR_SUCCESS_DEL_CONTACT;
		print "</b></center></td>";
}
/* Add entry functions */
function add_contact_form() {
		include ('dbkey.php');
		include('queries.php');
		print "<td valign=\"top\">";
		OpenTable();
        print "<table width=\"100%\" border=\"0\">
			<form action=\"$adm_path/add.php?action=add\" method=\"post\">
			<tr><td colspan=\"4\" class=Highlight><b>";
			echo _CODE_DIR_ADD_NEW_ENTRY;
			print "</b></td></tr>
			<tr><td>";
			echo _CODE_DIR_FIRSTNAME;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"firstname\" size=\"15\"></td>
			<td>";
			echo _CODE_DIR_LASTNAME;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"lastname\" size=\"15\"></td></tr>
			<tr><td>";
			echo _TITLE;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"title\" size=\"20\"></td>
			<td>";
			echo _CODE_DIR_PHONE;
			print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"phone\" size=\"12\"></td></tr>
             <tr><td>";
	  echo _CODE_DIR_ADDRESS;
	  print ":</td>
			<td><input type=\"text\" class=\"text\" name=\"address\" size=\"50\"></td></tr>
			<tr><td>";
			echo _CODE_DIR_DEPARTMENT;
			print ":</td>
			<td><select class=\"select\" name=\"department\">";
		/* List departments in DB and build SELECT */
		$result_list = $db->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>";
			CloseTable();
			print "</td>";
}
function add_contact($lastname,$firstname,$title,$phone,$address,$department,$insert_person,$insert_phone) {
		include ('dbkey.php');
		include('queries.php');
		$db->query($insert_person);
		$result_person = $db->query("SELECT personid
										FROM ".$db->prefix("dir_person")."
										WHERE lastname = '$lastname'
										AND firstname = '$firstname'");
		$a_row = mysql_fetch_array($result_person);
		$personid = $a_row[personid];
		$db->query("INSERT INTO ".$db->prefix("dir_phone")." VALUES (NULL, '$personid', '$phone')");
		print "<td valign=\"top\">";
		OpenTable();
		print "<table width=\"100%\" border=\"0\">
			<tr><td class=Highlight valign=\"top\" colspan=\"4\">
			<b>";
			echo _CODE_DIR_SUCCESS_ADD_ENTRY;
			print "</b></td></tr>
			<tr><td class=TinyText valign=\"top\"><b>";
			echo _NAME;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_DEPARTMENT;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _TITLE;
			print "</b></td>
			<td class=TinyText valign=\"top\"><b>";
			echo _CODE_DIR_PHONE;
			print "</b></td>
      <td class=TinyText valign=\"top\"><b>";
	  echo _CODE_DIR_ADDRESS;
	  print "</b></td></tr>
			<tr><td>$lastname, $firstname</td>";
		/* Match department serial to department name */
		$result_list = $db->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>
			<td>$address</td>
			</tr></table>";
		CloseTable();
		print "</td>";
}
function add_dept($action,$department) {
		include ('dbkey.php');
		include('queries.php');
		$db->query($insert_dept);
		print "<td class=Highlight><b>";
		echo _CODE_DIR_SUCCESS_DEPT_ENTRY;
		print ": $department</b></td>";
    
}
function edit_dept($action,$serial) {
		include ('dbkey.php');
		include('queries.php');
	echo "<td valign=\"top\"><p>";
	echo _CODE_DIR_MODIFY_DEPT_TXT;
	print ":</p>
		<form action=\"$adm_path/dept.php?action=upd&serial=$serial\" method=\"post\">";
	/* Match department serial to department name */
	$result_list = $db->query($select_dept_list);
	while ( $a_row = mysql_fetch_array( $result_list ))
		{
			if ( $a_row[serial] == $serial ) {
				echo "<input type=\"text\" class=\"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 or delete\" border=\"0\">
			</a></form></td>";
    
}
function upd_dept($action,$serial,$department) {
		include ('dbkey.php');
		include('queries.php');
		$result_update = $db->query("UPDATE department SET department = '$department' WHERE serial = '$serial'");
		print "<td class=Highlight><b>";
		echo _CODE_DIR_SUCCESS_UPD_DEPT;
		print ": $department</b></td>";
    
}
function del_dept($action,$serial) {
		include ('dbkey.php');
		include('queries.php');
		$db->query($delete_dept);
		print "<td class=Highlight><b>";
		echo _CODE_DIR_SUCCESS_DEL_DEPT;
		print ".</b></td>";
    
}
?>
