<?
//	Version	: 1.0
//	Author	: code
//	Email	: codehar@code-den.com
//	Website	: http://www.code-den.com
/* All the basic DB queries */
global $db;
$select_dept_list = "SELECT department, serial FROM ".$db->prefix("dir_department")." ORDER BY department";
$select_dept_contacts = "SELECT department, lastname, firstname, title, address, phone, ".$db->prefix("dir_person").".personid
                        FROM ".$db->prefix("dir_department").",".$db->prefix("dir_person").",".$db->prefix("dir_phone")."
                        WHERE ".$db->prefix("dir_department").".serial = '$dept'
                        AND ".$db->prefix("dir_department").".serial = deptid
						AND ".$db->prefix("dir_phone").".personid = ".$db->prefix("dir_person").".personid
                        ORDER BY lastname, firstname";
$select_search = "SELECT department, lastname, firstname, title, address, phone, ".$db->prefix("dir_person").".personid
                        FROM ".$db->prefix("dir_department").", ".$db->prefix("dir_person").", ".$db->prefix("dir_phone")."
                        WHERE ".$db->prefix("dir_department").".serial = ".$db->prefix("dir_person").".deptid
                        AND ".$db->prefix("dir_phone").".personid = ".$db->prefix("dir_person").".personid
                        AND $category LIKE '%$searchstring%'
                        ORDER BY department, lastname, firstname";
$select_edit = "SELECT department, deptid, lastname, firstname, title, address, phone
                    FROM ".$db->prefix("dir_department").", ".$db->prefix("dir_person").", ".$db->prefix("dir_phone")."
                    WHERE ".$db->prefix("dir_department").".serial = ".$db->prefix("dir_person").".deptid
                    AND ".$db->prefix("dir_person").".personid = '$personid'
                    AND ".$db->prefix("dir_phone").".personid = '$personid'";
$insert_person = "INSERT INTO ".$db->prefix("dir_person")." VALUES (NULL, '$lastname', '$firstname', '$title', '$address', '$department')";
$insert_phone = "INSERT INTO ".$db->prefix("dir_phone")." VALUES (NULL, '$personid', '$phone')";
$insert_dept = "INSERT INTO ".$db->prefix("dir_department")." VALUES (NULL, '$department')";
$update_person = "UPDATE ".$db->prefix("dir_person")."
					SET lastname = '$lastname',
					firstname = '$firstname',
					title = '$title',
					address = '$address',					
					deptid = '$department'
					WHERE personid = '$personid'";
$update_phone = "UPDATE ".$db->prefix("dir_phone")." SET phone = '$phone' WHERE personid = '$personid'";
$update_dept = "UPDATE ".$db->prefix("dir_department")." SET department = '$department' WHERE serial = '$serial'";
$delete_person = "DELETE FROM ".$db->prefix("dir_person")." WHERE personid = '$personid'";
$delete_phone = "DELETE FROM ".$db->prefix("dir_phone")." WHERE personid = '$personid'";
$delete_dept = "DELETE FROM ".$db->prefix("dir_department")." WHERE serial = '$serial'";
?>
