Prechádzať zdrojové kódy

Add a missing file sip_profile_copy.php to the dev branch.

Mark Crane 13 rokov pred
commit
076c248fa5

+ 275 - 0
app_config.php

@@ -0,0 +1,275 @@
+<?php
+	//application details
+		$apps[$x]['name'] = 'Contacts';
+		$apps[$x]['uuid'] = '04481e0e-a478-c559-adad-52bd4174574c';
+		$apps[$x]['category'] = 'CRM';
+		$apps[$x]['subcategory'] = '';
+		$apps[$x]['version'] = '';
+		$apps[$x]['license'] = 'Mozilla Public License 1.1';
+		$apps[$x]['contact_url'] = 'http://www.fusionpbx.com';
+		$apps[$x]['description']['en'] = 'Provides a place to store contact information for individuals and organizations.';
+
+	//menu details
+		$apps[$x]['menu'][$y]['title']['en'] = 'Contacts';
+		$apps[$x]['menu'][$y]['uuid'] = 'f14e6ab6-6565-d4e6-cbad-a51d2e3e8ec6';
+		$apps[$x]['menu'][$y]['parent_uuid'] = 'fd29e39c-c936-f5fc-8e2b-611681b266b5';
+		$apps[$x]['menu'][$y]['category'] = 'internal';
+		$apps[$x]['menu'][$y]['path'] = '/app/contacts/contacts.php';
+		//$apps[$x]['menu'][$y]['groups'][] = 'user';
+		$apps[$x]['menu'][$y]['groups'][] = 'admin';
+		$apps[$x]['menu'][$y]['groups'][] = 'superadmin';
+
+	//permission details
+		$apps[$x]['permissions'][0]['name'] = 'contacts_view';
+		$apps[$x]['permissions'][0]['groups'][] = 'superadmin';
+		//$apps[$x]['permissions'][0]['groups'][] = 'user';
+		$apps[$x]['permissions'][0]['groups'][] = 'admin';
+
+		$apps[$x]['permissions'][1]['name'] = 'contacts_add';
+		$apps[$x]['permissions'][1]['groups'][] = 'superadmin';
+		$apps[$x]['permissions'][1]['groups'][] = 'admin';
+
+		$apps[$x]['permissions'][2]['name'] = 'contacts_edit';
+		$apps[$x]['permissions'][2]['groups'][] = 'superadmin';
+		$apps[$x]['permissions'][2]['groups'][] = 'admin';
+		//$apps[$x]['permissions'][2]['groups'][] = 'user';
+
+		$apps[$x]['permissions'][3]['name'] = 'contacts_delete';
+		$apps[$x]['permissions'][3]['groups'][] = 'superadmin';
+		$apps[$x]['permissions'][3]['groups'][] = 'admin';
+
+	//schema details
+		$y = 0; //table array index
+		$z = 0; //field array index
+		$apps[$x]['db'][$y]['table'] = 'v_contacts';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'id';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'contact_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'integer';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'v_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_type';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the type.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_organization';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the organization.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_name_given';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the given name.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_name_family';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the family name.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_nickname';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the nickname.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_title';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the title.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_role';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the role.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_email';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the email address.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_url';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the website address.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_time_zone';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the time zone.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_note';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the notes.';
+		$z++;
+
+		$y = 1; //table array index
+		$apps[$x]['db'][$y]['table'] = 'v_contact_addresses';
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_address_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_contacts';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_type';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the address type.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_street';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the street address.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_extended';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter teh extended address.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_locality';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the city.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_region';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the state or province.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_postal_code';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the postal code.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_country';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the country.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_latitude';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the latitude';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'address_longitude';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the longitude';
+		$z++;
+
+		$y = 2; //table array index
+		$apps[$x]['db'][$y]['table'] = 'v_contact_phones';
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_phone_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_contacts';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'phone_type';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the  telephone type.';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'phone_number';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Enter the telephone number.';
+		$z++;
+
+		$y = 3; //table array index
+		$apps[$x]['db'][$y]['table'] = 'v_contact_notes';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'id';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'contacts_note_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'serial';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'integer';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'INT NOT NULL AUTO_INCREMENT';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_note_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'primary';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_domains';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'domain_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'v_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_id';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'numeric';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = 'Contact ID';
+		$apps[$x]['db'][$y]['fields'][$z]['deprecated'] = 'true';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = 'uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = 'char(36)';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['type'] = 'foreign';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = 'v_contacts';
+		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = 'contact_uuid';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name']['text'] = 'contact_note';
+		$apps[$x]['db'][$y]['fields'][$z]['name']['deprecated'] = 'notes';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'last_mod_date';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = 'last_mod_user';
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = 'text';
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en'] = '';
+		$z++;
+?>

+ 173 - 0
contact_addresses.php

@@ -0,0 +1,173 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+//get variables used to control the order
+	$order_by = $_GET["order_by"];
+	$order = $_GET["order"];
+
+//show the content
+	//echo "<div align='center'>";
+	//echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+	//echo "<tr class='border'>\n";
+	//echo "	<td align=\"center\">\n";
+	//echo "		<br>";
+
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>Addresses</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	//echo "<tr>\n";
+	//echo "<td align='left' colspan='2'>\n";
+	//echo "List of addresses for the contact.<br /><br />\n";
+	//echo "</td>\n";
+	//echo "</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+		$sql = " select count(*) as num_rows from v_contact_addresses ";
+		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= " and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$prep_statement = $db->prepare($sql);
+		if ($prep_statement) {
+		$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['num_rows'] > 0) {
+				$num_rows = $row['num_rows'];
+			}
+			else {
+				$num_rows = '0';
+			}
+		}
+
+	//prepare to page the results
+		$rows_per_page = 10;
+		$param = "";
+		$page = $_GET['page'];
+		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } 
+		list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); 
+		$offset = $rows_per_page * $page; 
+
+	//get the contact list
+		$sql = " select * from v_contact_addresses ";
+		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= " and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$sql .= " limit $rows_per_page offset $offset ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		$result_count = count($result);
+		unset ($prep_statement, $sql);
+
+	$c = 0;
+	$row_style["0"] = "row_style0";
+	$row_style["1"] = "row_style1";
+
+	echo "<div align='center'>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo th_order_by('address_type', 'Type', $order_by, $order);
+	//echo th_order_by('address_street', 'Street Address', $order_by, $order);
+	//echo th_order_by('address_extended', 'Extended Address', $order_by, $order);
+	echo th_order_by('address_locality', 'City', $order_by, $order);
+	echo th_order_by('address_region', 'Region', $order_by, $order);
+	//echo th_order_by('address_postal_code', 'Postal Code', $order_by, $order);
+	echo th_order_by('address_country', 'Country', $order_by, $order);
+	//echo th_order_by('address_latitude', 'Latitude', $order_by, $order);
+	//echo th_order_by('address_longitude', 'Longitude', $order_by, $order);
+	echo "<th>Tools</th>\n";
+	echo "<td align='right' width='42'>\n";
+	echo "	<a href='contact_addresses_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+	echo "</td>\n";
+	echo "<tr>\n";
+
+	if ($result_count > 0) {
+		foreach($result as $row) {
+			$map_query = $row['address_street']." ".$row['address_extended'].", ".$row['address_locality'].", ".$row['address_region'].", ".$row['address_region'].", ".$row['address_postal_code'];
+			echo "<tr >\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_type']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_street']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_extended']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_locality']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_region']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_postal_code']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_country']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_latitude']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_longitude']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>\n";
+			echo "		<a href=\"http://maps.google.com/maps?q=".urlencode($map_query)."&hl=en\" target=\"_blank\">Map</a>&nbsp;\n";
+			echo "	</td>\n";
+			echo "	<td valign='top' align='right'>\n";
+			echo "		<a href='contact_addresses_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_address_uuid']."' alt='edit'>$v_link_label_edit</a>\n";
+			echo "		<a href='contact_addresses_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_address_uuid']."' alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">$v_link_label_delete</a>\n";
+			echo "	</td>\n";
+			echo "</tr>\n";
+			if ($c==0) { $c=1; } else { $c=0; }
+		} //end foreach
+		unset($sql, $result, $row_count);
+	} //end if results
+
+	echo "<tr>\n";
+	echo "<td colspan='11' align='left'>\n";
+	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
+	echo "	<tr>\n";
+	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
+	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
+	echo "		<td width='33.3%' align='right'>\n";
+	echo "			<a href='contact_addresses_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "</div>";
+
+	//echo "</td>";
+	//echo "</tr>";
+	//echo "</table>";
+	//echo "</div>";
+	//echo "<br><br>";
+
+//include the footer
+	//require_once "includes/footer.php";
+?>

+ 61 - 0
contact_addresses_delete.php

@@ -0,0 +1,61 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_GET)>0) {
+	$id = check_str($_GET["id"]);
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+if (strlen($id)>0) {
+	$sql = "";
+	$sql .= "delete from v_contact_addresses ";
+	$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+	$sql .= "and contact_address_uuid = '$id' ";
+	
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	unset($sql);
+}
+
+require_once "includes/header.php";
+echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+echo "<div align='center'>\n";
+echo "Delete Complete\n";
+echo "</div>\n";
+require_once "includes/footer.php";
+return;
+
+?>

+ 352 - 0
contact_addresses_edit.php

@@ -0,0 +1,352 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_address_uuid = check_str($_REQUEST["id"]);
+	}
+	else {
+		$action = "add";
+	}
+
+if (strlen($_GET["contact_uuid"]) > 0) {
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+//get http post variables and set them to php variables
+	if (count($_POST)>0) {
+		$address_type = check_str($_POST["address_type"]);
+		$address_street = check_str($_POST["address_street"]);
+		$address_extended = check_str($_POST["address_extended"]);
+		$address_locality = check_str($_POST["address_locality"]);
+		$address_region = check_str($_POST["address_region"]);
+		$address_postal_code = check_str($_POST["address_postal_code"]);
+		$address_country = check_str($_POST["address_country"]);
+		$address_latitude = check_str($_POST["address_latitude"]);
+		$address_longitude = check_str($_POST["address_longitude"]);
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_address_uuid = check_str($_POST["contact_address_uuid"]);
+	}
+
+	//check for all required data
+		//if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
+		//if (strlen($address_type) == 0) { $msg .= "Please provide: Address Type<br>\n"; }
+		//if (strlen($address_street) == 0) { $msg .= "Please provide: Street Address<br>\n"; }
+		//if (strlen($address_extended) == 0) { $msg .= "Please provide: Extended Address<br>\n"; }
+		//if (strlen($address_locality) == 0) { $msg .= "Please provide: City<br>\n"; }
+		//if (strlen($address_region) == 0) { $msg .= "Please provide: State / Province<br>\n"; }
+		//if (strlen($address_postal_code) == 0) { $msg .= "Please provide: Postal Code<br>\n"; }
+		//if (strlen($address_country) == 0) { $msg .= "Please provide: Country<br>\n"; }
+		//if (strlen($address_latitude) == 0) { $msg .= "Please provide: Latitude<br>\n"; }
+		//if (strlen($address_longitude) == 0) { $msg .= "Please provide: Longitude<br>\n"; }
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "includes/header.php";
+			require_once "includes/persistformvar.php";
+			echo "<div align='center'>\n";
+			echo "<table><tr><td>\n";
+			echo $msg."<br />";
+			echo "</td></tr></table>\n";
+			persistformvar($_POST);
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+		if ($action == "add") {
+			$contact_address_uuid = uuid();
+			$sql = "insert into v_contact_addresses ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_address_uuid, ";
+			$sql .= "address_type, ";
+			$sql .= "address_street, ";
+			$sql .= "address_extended, ";
+			$sql .= "address_locality, ";
+			$sql .= "address_region, ";
+			$sql .= "address_postal_code, ";
+			$sql .= "address_country, ";
+			$sql .= "address_latitude, ";
+			$sql .= "address_longitude ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$_SESSION['domain_uuid']."', ";
+			$sql .= "'$contact_uuid', ";
+			$sql .= "'$contact_address_uuid', ";
+			$sql .= "'$address_type', ";
+			$sql .= "'$address_street', ";
+			$sql .= "'$address_extended', ";
+			$sql .= "'$address_locality', ";
+			$sql .= "'$address_region', ";
+			$sql .= "'$address_postal_code', ";
+			$sql .= "'$address_country', ";
+			$sql .= "'$address_latitude', ";
+			$sql .= "'$address_longitude' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Add Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contact_addresses set ";
+			$sql .= "contact_uuid = '$contact_uuid', ";
+			$sql .= "address_type = '$address_type', ";
+			$sql .= "address_street = '$address_street', ";
+			$sql .= "address_extended = '$address_extended', ";
+			$sql .= "address_locality = '$address_locality', ";
+			$sql .= "address_region = '$address_region', ";
+			$sql .= "address_postal_code = '$address_postal_code', ";
+			$sql .= "address_country = '$address_country', ";
+			$sql .= "address_latitude = '$address_latitude', ";
+			$sql .= "address_longitude = '$address_longitude' ";
+			$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."'";
+			$sql .= "and contact_address_uuid = '$contact_address_uuid'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Update Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "update")
+	} //if ($_POST["persistformvar"] != "true") 
+} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+
+//pre-populate the form
+	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+		$contact_address_uuid = $_GET["id"];
+		$sql = "";
+		$sql .= "select * from v_contact_addresses ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_address_uuid = '$contact_address_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$address_type = $row["address_type"];
+			$address_street = $row["address_street"];
+			$address_extended = $row["address_extended"];
+			$address_locality = $row["address_locality"];
+			$address_region = $row["address_region"];
+			$address_postal_code = $row["address_postal_code"];
+			$address_country = $row["address_country"];
+			$address_latitude = $row["address_latitude"];
+			$address_longitude = $row["address_longitude"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "includes/header.php";
+
+//show the content
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"left\">\n";
+	echo "	  <br>";
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<div align='center'>\n";
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
+	echo "<tr>\n";
+	if ($action == "add") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contacts Address Add</b></td>\n";
+	}
+	if ($action == "update") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contacts Address Edit</b></td>\n";
+	}
+	echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='contacts_edit.php?id=$contact_uuid'\" value='Back'></td>\n";
+	echo "</tr>\n";
+	echo "<tr>\n";
+	echo "<td align='left' colspan='2'>\n";
+	echo "Contact address information.<br /><br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Address Type:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='address_type'>\n";
+	echo "	<option value=''></option>\n";
+	if ($address_type == "Home") { 
+		echo "	<option value='Home' SELECTED >home</option>\n";
+	}
+	else {
+		echo "	<option value='Home'>home</option>\n";
+	}
+	if ($address_type == "Work") { 
+		echo "	<option value='Work' SELECTED >work</option>\n";
+	}
+	else {
+		echo "	<option value='Work'>work</option>\n";
+	}
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo "Enter the address type.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Street Address:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_street' maxlength='255' value=\"$address_street\">\n";
+	echo "<br />\n";
+	echo "Enter the street address.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Extended Address:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_extended' maxlength='255' value=\"$address_extended\">\n";
+	echo "<br />\n";
+	echo "Enter the extended address.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	City:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_locality' maxlength='255' value=\"$address_locality\">\n";
+	echo "<br />\n";
+	echo "Enter the city.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Region:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_region' maxlength='255' value=\"$address_region\">\n";
+	echo "<br />\n";
+	echo "Enter the state or province.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Postal Code:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_postal_code' maxlength='255' value=\"$address_postal_code\">\n";
+	echo "<br />\n";
+	echo "Enter the postal code.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Country:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_country' maxlength='255' value=\"$address_country\">\n";
+	echo "<br />\n";
+	echo "Enter the country.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Latitude:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_latitude' maxlength='255' value=\"$address_latitude\">\n";
+	echo "<br />\n";
+	echo "Enter the latitude\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Longitude:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='address_longitude' maxlength='255' value=\"$address_longitude\">\n";
+	echo "<br />\n";
+	echo "Enter the longitude\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "				<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	if ($action == "update") {
+		echo "				<input type='hidden' name='contact_address_uuid' value='$contact_address_uuid'>\n";
+	}
+	echo "				<input type='submit' name='submit' class='btn' value='Save'>\n";
+	echo "		</td>\n";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+	echo "	</td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</div>";
+
+//include the footer
+	require_once "includes/footer.php";
+?>

+ 179 - 0
contact_notes.php

@@ -0,0 +1,179 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+//get variables used to control the order
+	$order_by = $_GET["order_by"];
+	$order = $_GET["order"];
+
+//show the content
+	//echo "<div align='center'>";
+	//echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+	//echo "<tr class='border'>\n";
+	//echo "	<td align=\"center\">\n";
+	//echo "		<br>";
+
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>Notes</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	//echo "<tr>\n";
+	//echo "<td align='left' colspan='2'>\n";
+	//echo "	List of notes for the contact.<br /><br />\n";
+	//echo "</td>\n";
+	//echo "</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+		$sql = " select count(*) as num_rows from v_contact_notes ";
+		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= " and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$prep_statement = $db->prepare($sql);
+		if ($prep_statement) {
+		$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['num_rows'] > 0) {
+				$num_rows = $row['num_rows'];
+			}
+			else {
+				$num_rows = '0';
+			}
+		}
+
+	//prepare to page the results
+		$rows_per_page = 10;
+		$param = "";
+		$page = $_GET['page'];
+		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } 
+		list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); 
+		$offset = $rows_per_page * $page; 
+
+	//get the contact list
+		$sql = "select * from v_contact_notes ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$sql .= " limit $rows_per_page offset $offset ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		if ($prep_statement) {
+			$prep_statement->execute();
+			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			$result_count = count($result);
+			unset ($prep_statement, $sql);
+		}
+
+	$c = 0;
+	$row_style["0"] = "row_style0";
+	$row_style["1"] = "row_style1";
+
+	echo "<div align='center'>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	if ($result_count == 0) {
+		echo "<tr>\n";
+		echo "<th>\n";
+		echo "	&nbsp; \n";
+		echo "</th>\n";
+		echo "<td align='right' width='42'>\n";
+		echo "	<a href='contact_notes_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+		echo "</td>\n";
+		echo "<tr>\n";
+	}
+	else {
+		foreach($result as $row) {
+			$contact_note = $row['contact_note'];
+			//$contact_note = str_replace("\n","<br />",$contact_note);
+
+			echo "<tr>\n";
+			echo "<th>\n";
+			echo "	".$row['last_mod_date']."&nbsp; &nbsp; \n";
+			echo "	".$row['last_mod_user']." &nbsp; &nbsp; \n";
+			echo "</th>\n";
+			//echo "<th>Modified Date ".$row['last_mod_date']."</th>\n";
+			//echo "<th>Modified By ".$row['last_mod_user']."</th>\n";
+			echo "<td align='right' width='42'>\n";
+			echo "	<a href='contact_notes_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+			echo "</td>\n";
+			echo "<tr>\n";
+
+			echo "<tr >\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'><br />".$contact_note."&nbsp;<br /><br /></td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['last_mod_date']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['last_mod_user']."&nbsp;</td>\n";
+			echo "	<td valign='top' align='right'>\n";
+			echo "		<a href='contact_notes_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_note_uuid']."' alt='edit'>$v_link_label_edit</a>\n";
+			echo "		<a href='contact_notes_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_note_uuid']."' alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">$v_link_label_delete</a>\n";
+			echo "	</td>\n";
+			echo "</tr>\n";
+
+			echo "<tr>\n";
+			echo "	<td>&nbsp;</td>\n";
+			echo "<tr>\n";
+
+			if ($c==0) { $c=1; } else { $c=0; }
+		} //end foreach
+		unset($sql, $result, $row_count);
+	} //end if results
+
+	echo "<tr>\n";
+	echo "<td colspan='4' align='left'>\n";
+	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
+	echo "	<tr>\n";
+	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
+	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
+	echo "		<td width='33.3%' align='right'>\n";
+	echo "			<a href='contact_notes_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "</div>";
+
+	//echo "</td>";
+	//echo "</tr>";
+	//echo "</table>";
+	//echo "</div>";
+	//echo "<br><br>";
+
+//include the footer
+	//require_once "includes/footer.php";
+?>

+ 60 - 0
contact_notes_delete.php

@@ -0,0 +1,60 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_GET)>0) {
+	$id = check_str($_GET["id"]);
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+if (strlen($id)>0) {
+	$sql = "";
+	$sql .= "delete from v_contact_notes ";
+	$sql .= "where domain_uuid = '$domain_uuid' ";
+	$sql .= "and contact_note_uuid = '$id' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	unset($sql);
+}
+
+require_once "includes/header.php";
+echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+echo "<div align='center'>\n";
+echo "Delete Complete\n";
+echo "</div>\n";
+require_once "includes/footer.php";
+return;
+
+?>

+ 210 - 0
contact_notes_edit.php

@@ -0,0 +1,210 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_note_uuid = check_str($_REQUEST["id"]);
+	}
+	else {
+		$action = "add";
+	}
+
+if (strlen($_GET["contact_uuid"]) > 0) {
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+//get http post variables and set them to php variables
+	if (count($_POST)>0) {
+		$contact_note = check_str($_POST["contact_note"]);
+		$last_mod_date = check_str($_POST["last_mod_date"]);
+		$last_mod_user = check_str($_POST["last_mod_user"]);
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_note_uuid = check_str($_POST["contact_note_uuid"]);
+	}
+
+	//check for all required data
+		//if (strlen($contact_note) == 0) { $msg .= "Please provide: Notes<br>\n"; }
+		//if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
+		//if (strlen($last_mod_date) == 0) { $msg .= "Please provide: Last Modified Date<br>\n"; }
+		//if (strlen($last_mod_user) == 0) { $msg .= "Please provide: Last Modified By<br>\n"; }
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "includes/header.php";
+			require_once "includes/persistformvar.php";
+			echo "<div align='center'>\n";
+			echo "<table><tr><td>\n";
+			echo $msg."<br />";
+			echo "</td></tr></table>\n";
+			persistformvar($_POST);
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+		if ($action == "add") {
+			$contact_note_uuid = uuid();
+			$sql = "insert into v_contact_notes ";
+			$sql .= "(";
+			$sql .= "contact_note_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_note, ";
+			$sql .= "domain_uuid, ";
+			$sql .= "last_mod_date, ";
+			$sql .= "last_mod_user ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'$contact_note_uuid', ";
+			$sql .= "'$contact_uuid', ";
+			$sql .= "'$contact_note', ";
+			$sql .= "'$domain_uuid', ";
+			$sql .= "now(), ";
+			$sql .= "'".$_SESSION['username']."' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Add Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contact_notes set ";
+			$sql .= "contact_uuid = '$contact_uuid', ";
+			$sql .= "contact_note = '$contact_note', ";
+			$sql .= "last_mod_date = now(), ";
+			$sql .= "last_mod_user = '".$_SESSION['username']."' ";
+			$sql .= "where domain_uuid = '$domain_uuid' ";
+			$sql .= "and contact_note_uuid = '$contact_note_uuid'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Update Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "update")
+	} //if ($_POST["persistformvar"] != "true") 
+} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+
+//pre-populate the form
+	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+		$contact_note_uuid = $_GET["id"];
+		$sql = "";
+		$sql .= "select * from v_contact_notes ";
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and contact_note_uuid = '$contact_note_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$contact_note = $row["contact_note"];
+			$last_mod_date = $row["last_mod_date"];
+			$last_mod_user = $row["last_mod_user"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "includes/header.php";
+
+//show the content
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
+
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"left\">\n";
+	echo "	  <br>";
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<div align='center'>\n";
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
+	echo "<tr>\n";
+	if ($action == "add") {
+		echo "<td align='left' width='15%' nowrap='nowrap'><b>Add Notes</b></td>\n";
+	}
+	if ($action == "update") {
+		echo "<td align='left' width='15%' nowrap='nowrap'><b>Edit Notes</b></td>\n";
+	}
+	echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='contacts_edit.php?id=$contact_uuid'\" value='Back'></td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Notes:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "  <textarea class='formfld' type='text' rows=\"20\" style=\"width: 100%\" name='contact_note'>$contact_note</textarea>\n";
+	echo "<br />\n";
+	echo "\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "				<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	if ($action == "update") {
+		echo "				<input type='hidden' name='contact_note_uuid' value='$contact_note_uuid'>\n";
+	}
+	echo "				<input type='submit' name='submit' class='btn' value='Save'>\n";
+	echo "		</td>\n";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+	echo "	</td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</div>";
+
+//include the footer
+	require_once "includes/footer.php";
+?>

+ 154 - 0
contact_phones.php

@@ -0,0 +1,154 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+//get variables used to control the order
+	$order_by = $_GET["order_by"];
+	$order = $_GET["order"];
+
+//show the content
+	//echo "<div align='center'>";
+	//echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+	//echo "<tr class='border'>\n";
+	//echo "	<td align=\"center\">\n";
+	//echo "		<br>";
+
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>Phone Numbers</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	//echo "<tr>\n";
+	//echo "<td colspan='2'>\n";
+	//echo "	List of phone numbers for the contact.<br /><br />\n";
+	//echo "</td>\n";
+	//echo "</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+		$sql = " select count(*) as num_rows from v_contact_phones ";
+		$sql .= " where domain_uuid = '$domain_uuid' ";
+		$sql .= " and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$prep_statement = $db->prepare($sql);
+		if ($prep_statement) {
+		$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['num_rows'] > 0) {
+				$num_rows = $row['num_rows'];
+			}
+			else {
+				$num_rows = '0';
+			}
+		}
+
+	//prepare to page the results
+		$rows_per_page = 10;
+		$param = "";
+		$page = $_GET['page'];
+		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } 
+		list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); 
+		$offset = $rows_per_page * $page; 
+
+	//get the contact list
+		$sql = " select * from v_contact_phones ";
+		$sql .= " where domain_uuid = '$domain_uuid' ";
+		$sql .= " and contact_uuid = '$contact_uuid' ";
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$sql .= " limit $rows_per_page offset $offset ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		$result_count = count($result);
+		unset ($prep_statement, $sql);
+
+	$c = 0;
+	$row_style["0"] = "row_style0";
+	$row_style["1"] = "row_style1";
+
+	echo "<div align='center'>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo th_order_by('phone_type', 'Type', $order_by, $order);
+	echo th_order_by('phone_number', 'Numbers', $order_by, $order);
+	echo "<th>Tools</th>\n";
+	echo "<td align='right' width='42'>\n";
+	echo "	<a href='contact_phones_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+	echo "</td>\n";
+	echo "<tr>\n";
+	if ($result_count > 0) {
+		foreach($result as $row) {
+			echo "<tr >\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['phone_type']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".format_phone($row['phone_number'])."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'><a href=\"".PROJECT_PATH."/app/xml_cdr/xml_cdr.php?caller_id_number=".$row['phone_number']."&destination_number=".$row['phone_number']."\">CDR</a>&nbsp;</td>\n";
+			echo "	<td valign='top' align='right'>\n";
+			echo "		<a href='contact_phones_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_phone_uuid']."' alt='edit'>$v_link_label_edit</a>\n";
+			echo "		<a href='contact_phones_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_phone_uuid']."' alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">$v_link_label_delete</a>\n";
+			echo "	</td>\n";
+			echo "</tr>\n";
+			if ($c==0) { $c=1; } else { $c=0; }
+		} //end foreach
+		unset($sql, $result, $row_count);
+	} //end if results
+
+	echo "<tr>\n";
+	echo "<td colspan='4' align='left'>\n";
+	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
+	echo "	<tr>\n";
+	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
+	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
+	echo "		<td width='33.3%' align='right'>\n";
+	echo "			<a href='contact_phones_edit.php?contact_uuid=".$_GET['id']."' alt='add'>$v_link_label_add</a>\n";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "</div>";
+
+	//echo "</td>";
+	//echo "</tr>";
+	//echo "</table>";
+	//echo "</div>";
+	//echo "<br><br>";
+
+//include the footer
+	//require_once "includes/footer.php";
+?>

+ 61 - 0
contact_phones_delete.php

@@ -0,0 +1,61 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_GET)>0) {
+	$id = check_str($_GET["id"]);
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+if (strlen($id)>0) {
+	$sql = "";
+	$sql .= "delete from v_contact_phones ";
+	$sql .= "where domain_uuid = '$domain_uuid' ";
+	$sql .= "and contact_phone_uuid = '$id' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	unset($sql);
+}
+
+require_once "includes/header.php";
+echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+echo "<div align='center'>\n";
+echo "Delete Complete\n";
+echo "</div>\n";
+
+require_once "includes/footer.php";
+return;
+
+?>

+ 320 - 0
contact_phones_edit.php

@@ -0,0 +1,320 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_phone_uuid = check_str($_REQUEST["id"]);
+	}
+	else {
+		$action = "add";
+	}
+
+if (strlen($_GET["contact_uuid"]) > 0) {
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+//get http post variables and set them to php variables
+	if (count($_POST)>0) {
+		$phone_type = check_str($_POST["phone_type"]);
+		$phone_number = check_str($_POST["phone_number"]);
+
+		//remove any phone number formatting
+		$phone_number = preg_replace('{\D}', '', $phone_number);
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_phone_uuid = check_str($_POST["contact_phone_uuid"]);
+	}
+
+	//check for all required data
+		//if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
+		//if (strlen($phone_type) == 0) { $msg .= "Please provide: Telephone Type.<br>\n"; }
+		//if (strlen($phone_number) == 0) { $msg .= "Please provide: Telephone Number<br>\n"; }
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "includes/header.php";
+			require_once "includes/persistformvar.php";
+			echo "<div align='center'>\n";
+			echo "<table><tr><td>\n";
+			echo $msg."<br />";
+			echo "</td></tr></table>\n";
+			persistformvar($_POST);
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+		if ($action == "add") {
+			$contact_phone_uuid = uuid();
+			$sql = "insert into v_contact_phones ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_phone_uuid, ";
+			$sql .= "phone_type, ";
+			$sql .= "phone_number ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'$domain_uuid', ";
+			$sql .= "'$contact_uuid', ";
+			$sql .= "'$contact_phone_uuid', ";
+			$sql .= "'$phone_type', ";
+			$sql .= "'$phone_number' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Add Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contact_phones set ";
+			$sql .= "contact_uuid = '$contact_uuid', ";
+			$sql .= "phone_type = '$phone_type', ";
+			$sql .= "phone_number = '$phone_number' ";
+			$sql .= "where domain_uuid = '$domain_uuid'";
+			$sql .= "and contact_phone_uuid = '$contact_phone_uuid'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts_edit.php?id=$contact_uuid\">\n";
+			echo "<div align='center'>\n";
+			echo "Update Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "update")
+	} //if ($_POST["persistformvar"] != "true") 
+} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+
+//pre-populate the form
+	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+		$contact_phone_uuid = $_GET["id"];
+		$sql = "";
+		$sql .= "select * from v_contact_phones ";
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and contact_phone_uuid = '$contact_phone_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$phone_type = $row["phone_type"];
+			$phone_number = $row["phone_number"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "includes/header.php";
+
+//show the content
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"left\">\n";
+	echo "	  <br>";
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<div align='center'>\n";
+	echo "<table width='100%' align='left' border='0' cellpadding='6' cellspacing='0'>\n";
+	echo "<tr>\n";
+	if ($action == "add") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contacts Phone Add</b></td>\n";
+	}
+	if ($action == "update") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contacts Phone Edit</b></td>\n";
+	}
+	echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='contacts_edit.php?id=$contact_uuid'\" value='Back'></td>\n";
+	echo "</tr>\n";
+	echo "<tr>\n";
+	echo "<td align='left' colspan='2'>\n";
+	echo "Telephone Numbers<br /><br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Telephone Type.:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='phone_type'>\n";
+	echo "	<option value=''></option>\n";
+	if ($phone_type == "home") { 
+		echo "	<option value='home' SELECTED >Home</option>\n";
+	}
+	else {
+		echo "	<option value='home'>Home</option>\n";
+	}
+	if ($phone_type == "work") { 
+		echo "	<option value='work' SELECTED >Work</option>\n";
+	}
+	else {
+		echo "	<option value='work'>Work</option>\n";
+	}
+	if ($phone_type == "pref") { 
+		echo "	<option value='pref' SELECTED >Pref</option>\n";
+	}
+	else {
+		echo "	<option value='pref'>Pref</option>\n";
+	}
+	if ($phone_type == "voice") { 
+		echo "	<option value='voice' SELECTED >Voice</option>\n";
+	}
+	else {
+		echo "	<option value='voice'>Voice</option>\n";
+	}
+	if ($phone_type == "fax") { 
+		echo "	<option value='fax' SELECTED >Fax</option>\n";
+	}
+	else {
+		echo "	<option value='fax'>Fax</option>\n";
+	}
+	if ($phone_type == "msg") { 
+		echo "	<option value='msg' SELECTED >MSG</option>\n";
+	}
+	else {
+		echo "	<option value='msg'>MSG</option>\n";
+	}
+	if ($phone_type == "cell") { 
+		echo "	<option value='cell' SELECTED >Cell</option>\n";
+	}
+	else {
+		echo "	<option value='cell'>Cell</option>\n";
+	}
+	if ($phone_type == "pager") { 
+		echo "	<option value='pager' SELECTED >Pager</option>\n";
+	}
+	else {
+		echo "	<option value='pager'>Pager</option>\n";
+	}
+	if ($phone_type == "bbs") { 
+		echo "	<option value='bbs' SELECTED >BBS</option>\n";
+	}
+	else {
+		echo "	<option value='bbs'>BBS</option>\n";
+	}
+	if ($phone_type == "modem") { 
+		echo "	<option value='modem' SELECTED >Modem</option>\n";
+	}
+	else {
+		echo "	<option value='modem'>Modem</option>\n";
+	}
+	if ($phone_type == "car") { 
+		echo "	<option value='car' SELECTED >Car</option>\n";
+	}
+	else {
+		echo "	<option value='car'>Car</option>\n";
+	}
+	if ($phone_type == "isdn") { 
+		echo "	<option value='isdn' SELECTED >ISDN</option>\n";
+	}
+	else {
+		echo "	<option value='isdn'>ISDN</option>\n";
+	}
+	if ($phone_type == "video") { 
+		echo "	<option value='video' SELECTED >Video</option>\n";
+	}
+	else {
+		echo "	<option value='video'>Video</option>\n";
+	}
+	if ($phone_type == "pcs") { 
+		echo "	<option value='pcs' SELECTED >PCS</option>\n";
+	}
+	else {
+		echo "	<option value='pcs'>PCS</option>\n";
+	}
+	if ($phone_type == "iana-token") { 
+		echo "	<option value='iana-token' SELECTED >iana-token</option>\n";
+	}
+	else {
+		echo "	<option value='iana-token'>iana-token</option>\n";
+	}
+	if ($phone_type == "x-name") { 
+		echo "	<option value='x-name' SELECTED >x-name</option>\n";
+	}
+	else {
+		echo "	<option value='x-name'>x-name</option>\n";
+	}
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo "Enter the  telephone type.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Telephone Number:\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='phone_number' maxlength='255' value=\"$phone_number\">\n";
+	echo "<br />\n";
+	echo "Enter the telephone number.\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "				<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	if ($action == "update") {
+		echo "				<input type='hidden' name='contact_phone_uuid' value='$contact_phone_uuid'>\n";
+	}
+	echo "				<input type='submit' name='submit' class='btn' value='Save'>\n";
+	echo "		</td>\n";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+	echo "	</td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</div>";
+
+//include the footer
+	require_once "includes/footer.php";
+?>

+ 224 - 0
contacts.php

@@ -0,0 +1,224 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+require_once "includes/header.php";
+require_once "includes/paging.php";
+
+//get the search criteria
+	$search_all = $_GET["search_all"];
+
+//get variables used to control the order
+	$order_by = $_GET["order_by"];
+	$order = $_GET["order"];
+
+//show the content
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"center\">\n";
+	echo "		<br>";
+
+	echo "<table width=\"100%\" border=\"0\" cellpadding=\"6\" cellspacing=\"0\">\n";
+	echo "	<tr>\n";
+	echo "	<td align=\"left\" valign=\"top\"><strong>Contacts</strong><br>\n";
+	echo "		The contact is a list of individuals and organizations.\n";
+	echo "	</td>\n";
+	echo "	<td align=\"right\" valign=\"top\">\n";
+	echo "		<form method=\"GET\" name=\"frm_search\" action=\"\">\n";
+	echo "			<input class=\"formfld\" type=\"text\" name=\"search_all\" value=\"$search_all\">\n";
+	echo "			<input class=\"btn\" type=\"submit\" name=\"submit\" value=\"Search All\">\n";
+	echo "		</form>\n";
+	echo "	</td>\n";
+	echo "	</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+		$sql = "";
+		$sql .= " select count(*) as num_rows from v_contacts ";
+		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		if (strlen($search_all) > 0) {
+			if (is_numeric($search_all)) {
+				$sql .= "and contact_uuid in (select contact_uuid from v_contact_phones where phone_number like '%".$search_all."%') \n";
+			}
+			else {
+				$sql .= "and contact_uuid in (\n";
+				$sql .= "	select contact_uuid from v_contacts ";
+				$sql .= "	where domain_uuid = '".$_SESSION['domain_uuid']."' \n";
+				$sql .= "	and (\n";
+				$sql .= "	contact_organization like '%".$search_all."%' or \n";
+				$sql .= "	contact_name_given like '%".$search_all."%' or \n";
+				$sql .= "	contact_name_family like '%".$search_all."%' or \n";
+				$sql .= "	contact_nickname like '%".$search_all."%' or \n";
+				$sql .= "	contact_title like '%".$search_all."%' or \n";
+				$sql .= "	contact_role like '%".$search_all."%' or \n";
+				$sql .= "	contact_email like '%".$search_all."%' or \n";
+				$sql .= "	contact_url like '%".$search_all."%' or \n";
+				$sql .= "	contact_time_zone like '%".$search_all."%' or \n";
+				$sql .= "	contact_note like '%".$search_all."%' or \n";
+				$sql .= "	contact_type like '%".$search_all."%'\n";
+				$sql .= "	)\n";
+				$sql .= ")\n";
+			}
+		}
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$prep_statement = $db->prepare($sql);
+		if ($prep_statement) {
+		$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['num_rows'] > 0) {
+				$num_rows = $row['num_rows'];
+			}
+			else {
+				$num_rows = '0';
+			}
+		}
+
+	//prepare to page the results
+		$rows_per_page = 30;
+		$param = "";
+		$page = $_GET['page'];
+		if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } 
+		list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); 
+		$offset = $rows_per_page * $page; 
+
+	//get the  list
+		$sql = " select * from v_contacts ";
+		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		if (strlen($search_all) > 0) {
+			if (is_numeric($search_all)) {
+				$sql .= "and contact_uuid in (select contact_uuid from v_contact_phones where phone_number like '%".$search_all."%') \n";
+			}
+			else {
+				$sql .= "and contact_uuid in (\n";
+				$sql .= "	select contact_uuid from v_contacts where domain_uuid = '".$_SESSION['domain_uuid']."' \n";
+				$sql .= "	and (\n";
+				$sql .= "	contact_organization like '%".$search_all."%' or \n";
+				$sql .= "	contact_name_given like '%".$search_all."%' or \n";
+				$sql .= "	contact_name_family like '%".$search_all."%' or \n";
+				$sql .= "	contact_nickname like '%".$search_all."%' or \n";
+				$sql .= "	contact_title like '%".$search_all."%' or \n";
+				$sql .= "	contact_role like '%".$search_all."%' or \n";
+				$sql .= "	contact_email like '%".$search_all."%' or \n";
+				$sql .= "	contact_url like '%".$search_all."%' or \n";
+				$sql .= "	contact_time_zone like '%".$search_all."%' or \n";
+				$sql .= "	contact_note like '%".$search_all."%' or \n";
+				$sql .= "	contact_type like '%".$search_all."%'\n";
+				$sql .= "	)\n";
+				$sql .= ")\n";
+			}
+		}
+		if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+		$sql .= " limit $rows_per_page offset $offset ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		$result_count = count($result);
+		unset ($prep_statement, $sql);
+
+	$c = 0;
+	$row_style["0"] = "row_style0";
+	$row_style["1"] = "row_style1";
+
+	echo "<div align='center'>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo th_order_by('contact_type', 'Type', $order_by, $order);
+	echo th_order_by('contact_organization', 'Organization', $order_by, $order);
+	echo th_order_by('contact_name_given', 'First Name', $order_by, $order);
+	echo th_order_by('contact_name_family', 'Last Name', $order_by, $order);
+	echo th_order_by('contact_nickname', 'Nickname', $order_by, $order);
+	echo th_order_by('contact_title', 'Title', $order_by, $order);
+	echo th_order_by('contact_role', 'Role', $order_by, $order);
+	//echo th_order_by('contact_email', 'Email', $order_by, $order);
+	//echo th_order_by('contact_url', 'URL', $order_by, $order);
+	//echo th_order_by('contact_time_zone', 'Time Zone', $order_by, $order);
+	//echo th_order_by('contact_note', 'Notes', $order_by, $order);
+	echo "<td align='right' width='42'>\n";
+	echo "	<a href='contacts_edit.php' alt='add'>$v_link_label_add</a>\n";
+	echo "</td>\n";
+	echo "<tr>\n";
+
+	if ($result_count > 0) {
+		foreach($result as $row) {
+			echo "<tr >\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".ucwords($row['contact_type'])."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_organization']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_name_given']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_name_family']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_nickname']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_title']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_role']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_email']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_url']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_time_zone']."&nbsp;</td>\n";
+			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_note']."&nbsp;</td>\n";
+			echo "	<td valign='top' align='right'>\n";
+			echo "		<a href='contacts_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."' alt='edit'>$v_link_label_edit</a>\n";
+			echo "		<a href='contacts_delete.php?id=".$row['contact_uuid']."' alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">$v_link_label_delete</a>\n";
+			echo "	</td>\n";
+			echo "</tr>\n";
+			if ($c==0) { $c=1; } else { $c=0; }
+		} //end foreach
+		unset($sql, $result, $row_count);
+	} //end if results
+
+	echo "<tr>\n";
+	echo "<td colspan='15' align='left'>\n";
+	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
+	echo "	<tr>\n";
+	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
+	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
+	echo "		<td width='33.3%' align='right'>\n";
+	echo "			<a href='contacts_edit.php' alt='add'>$v_link_label_add</a>\n";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "</div>";
+	echo "<br><br>";
+	echo "<br><br>";
+
+	echo "</td>";
+	echo "</tr>";
+	echo "</table>";
+	echo "</div>";
+	echo "<br><br>";
+
+//include the footer
+	require_once "includes/footer.php";
+?>

+ 86 - 0
contacts_delete.php

@@ -0,0 +1,86 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_GET)>0) {
+	$id = check_str($_GET["id"]);
+}
+
+if (strlen($id)>0) {
+	//delete a contact
+		$sql = "delete from v_contacts ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$id' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($prep_statement, $sql);
+
+	//delete addresses
+		$sql = "delete from v_contact_addresses ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$id' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($prep_statement, $sql);
+
+	//delete phones
+		$sql = "";
+		$sql .= "delete from v_contact_phones ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$id' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($prep_statement, $sql);
+
+	//delete notes
+		$sql = "";
+		$sql .= "delete from v_contact_notes ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$id' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($prep_statement, $sql);
+}
+
+//redirect the browser
+	require_once "includes/header.php";
+	echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts.php\">\n";
+	echo "<div align='center'>\n";
+	echo "Delete Complete\n";
+	echo "</div>\n";
+	require_once "includes/footer.php";
+	return;
+
+?>

+ 481 - 0
contacts_edit.php

@@ -0,0 +1,481 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+require_once "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_uuid = check_str($_REQUEST["id"]);
+	}
+	else {
+		$action = "add";
+	}
+
+//get http post variables and set them to php variables
+	if (count($_POST)>0) {
+		$contact_type = check_str($_POST["contact_type"]);
+		$contact_organization = check_str($_POST["contact_organization"]);
+		$contact_name_given = check_str($_POST["contact_name_given"]);
+		$contact_name_family = check_str($_POST["contact_name_family"]);
+		$contact_nickname = check_str($_POST["contact_nickname"]);
+		$contact_title = check_str($_POST["contact_title"]);
+		$contact_role = check_str($_POST["contact_role"]);
+		$contact_email = check_str($_POST["contact_email"]);
+		$contact_url = check_str($_POST["contact_url"]);
+		$contact_time_zone = check_str($_POST["contact_time_zone"]);
+		$contact_note = check_str($_POST["contact_note"]);
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_uuid = check_str($_POST["contact_uuid"]);
+	}
+
+	//check for all required data
+		//if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid<br>\n"; }
+		//if (strlen($contact_type) == 0) { $msg .= "Please provide: Type<br>\n"; }
+		//if (strlen($contact_organization) == 0) { $msg .= "Please provide: Organization<br>\n"; }
+		//if (strlen($contact_name_given) == 0) { $msg .= "Please provide: First Name<br>\n"; }
+		//if (strlen($contact_name_family) == 0) { $msg .= "Please provide: Last Name<br>\n"; }
+		//if (strlen($contact_nickname) == 0) { $msg .= "Please provide: Nickname<br>\n"; }
+		//if (strlen($contact_title) == 0) { $msg .= "Please provide: Title<br>\n"; }
+		//if (strlen($contact_role) == 0) { $msg .= "Please provide: Role<br>\n"; }
+		//if (strlen($) == 0) { $msg .= "Please provide: Contact Information<br>\n"; }
+		//if (strlen($contact_email) == 0) { $msg .= "Please provide: Email<br>\n"; }
+		//if (strlen($contact_url) == 0) { $msg .= "Please provide: URL<br>\n"; }
+		//if (strlen($) == 0) { $msg .= "Please provide: Additional Information<br>\n"; }
+		//if (strlen($contact_time_zone) == 0) { $msg .= "Please provide: Time Zone<br>\n"; }
+		//if (strlen($contact_note) == 0) { $msg .= "Please provide: Notes<br>\n"; }
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "includes/header.php";
+			require_once "includes/persistformvar.php";
+			echo "<div align='center'>\n";
+			echo "<table><tr><td>\n";
+			echo $msg."<br />";
+			echo "</td></tr></table>\n";
+			persistformvar($_POST);
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+		if ($action == "add") {
+			$contact_uuid = uuid();
+			$sql = "insert into v_contacts ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_type, ";
+			$sql .= "contact_organization, ";
+			$sql .= "contact_name_given, ";
+			$sql .= "contact_name_family, ";
+			$sql .= "contact_nickname, ";
+			$sql .= "contact_title, ";
+			$sql .= "contact_role, ";
+			$sql .= "contact_email, ";
+			$sql .= "contact_url, ";
+			$sql .= "contact_time_zone, ";
+			$sql .= "contact_note ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$_SESSION['domain_uuid']."', ";
+			$sql .= "'$contact_uuid', ";
+			$sql .= "'$contact_type', ";
+			$sql .= "'$contact_organization', ";
+			$sql .= "'$contact_name_given', ";
+			$sql .= "'$contact_name_family', ";
+			$sql .= "'$contact_nickname', ";
+			$sql .= "'$contact_title', ";
+			$sql .= "'$contact_role', ";
+			$sql .= "'$contact_email', ";
+			$sql .= "'$contact_url', ";
+			$sql .= "'$contact_time_zone', ";
+			$sql .= "'$contact_note' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts.php\">\n";
+			echo "<div align='center'>\n";
+			echo "Add Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contacts set ";
+			$sql .= "contact_type = '$contact_type', ";
+			$sql .= "contact_organization = '$contact_organization', ";
+			$sql .= "contact_name_given = '$contact_name_given', ";
+			$sql .= "contact_name_family = '$contact_name_family', ";
+			$sql .= "contact_nickname = '$contact_nickname', ";
+			$sql .= "contact_title = '$contact_title', ";
+			$sql .= "contact_role = '$contact_role', ";
+			$sql .= "contact_email = '$contact_email', ";
+			$sql .= "contact_url = '$contact_url', ";
+			$sql .= "contact_time_zone = '$contact_time_zone', ";
+			$sql .= "contact_note = '$contact_note' ";
+			$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+			$sql .= "and contact_uuid = '$contact_uuid' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			require_once "includes/header.php";
+			echo "<meta http-equiv=\"refresh\" content=\"2;url=contacts.php\">\n";
+			echo "<div align='center'>\n";
+			echo "Update Complete\n";
+			echo "</div>\n";
+			require_once "includes/footer.php";
+			return;
+		} //if ($action == "update")
+	} //if ($_POST["persistformvar"] != "true") 
+} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
+
+//pre-populate the form
+	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+		$contact_uuid = $_GET["id"];
+		$sql = "";
+		$sql .= "select * from v_contacts ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$contact_type = $row["contact_type"];
+			$contact_organization = $row["contact_organization"];
+			$contact_name_given = $row["contact_name_given"];
+			$contact_name_family = $row["contact_name_family"];
+			$contact_nickname = $row["contact_nickname"];
+			$contact_title = $row["contact_title"];
+			$contact_role = $row["contact_role"];
+			$contact_email = $row["contact_email"];
+			$contact_url = $row["contact_url"];
+			$contact_time_zone = $row["contact_time_zone"];
+			$contact_note = $row["contact_note"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "includes/header.php";
+
+//show the content
+	echo "<div align='center'>";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
+	echo "<tr class='border'>\n";
+	echo "	<td align=\"left\">\n";
+	echo "		<br>";
+
+	echo "<div align='center'>\n";
+	echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
+	echo "<tr>\n";
+	if ($action == "add") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contact Add</b></td>\n";
+	}
+	if ($action == "update") {
+		echo "<td align='left' width='30%' nowrap='nowrap'><b>Contact Edit</b></td>\n";
+	}
+	echo "<td width='70%' align='right'>\n";
+	echo "	<input type='button' class='btn' name='' alt='qr code' onclick=\"window.location='contacts_vcard.php?id=$contact_uuid&type=image'\" value='QR Code'>\n";
+	echo "	<input type='button' class='btn' name='' alt='vcard' onclick=\"window.location='contacts_vcard.php?id=$contact_uuid&type=download'\" value='vCard'>\n";
+	if ($action == "update" && is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/invoices')) {
+		echo "	<input type='button' class='btn' name='' alt='invoice' onclick=\"window.location='".PROJECT_PATH."/app/invoices/v_invoices.php?id=$contact_uuid'\" value='Invoices'>\n";
+	}
+	echo "	<input type='button' class='btn' name='' alt='back' onclick=\"window.location='contacts.php?".$_GET["query_string"]."'\" value='Back'>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "<tr>\n";
+	echo "<td align=\"left\" colspan='2'>\n";
+	echo "The contact is a list of individuals and organizations.<br /><br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	echo "<table border='0' cellpadding='3' cellspacing='3' width='100%'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+
+		echo "<form method='post' name='frm' action=''>\n";
+		echo "<table border='0' width='100%'>\n";
+		echo "<tr>\n";
+		echo "	<td><strong>User Information</strong></td>\n";
+		echo "	<td>&nbsp;</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Type:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<select class='formfld' style='width:85%;' name='contact_type'>\n";
+		echo "	<option value=''></option>\n";
+		if ($contact_type == "customer") { 
+			echo "	<option value='customer' selected='selected' >Customer</option>\n";
+		}
+		else {
+			echo "	<option value='customer'>Customer</option>\n";
+		}
+		if ($contact_type == "contractor") { 
+			echo "	<option value='contractor' selected='selected' >Contractor</option>\n";
+		}
+		else {
+			echo "	<option value='contractor'>Contractor</option>\n";
+		}
+		if ($contact_type == "friend") { 
+			echo "	<option value='friend' selected='selected' >Friend</option>\n";
+		}
+		else {
+			echo "	<option value='friend'>Friend</option>\n";
+		}
+		if ($contact_type == "lead") { 
+			echo "	<option value='lead' selected='selected' >Lead</option>\n";
+		}
+		else {
+			echo "	<option value='lead'>Lead</option>\n";
+		}
+		if ($contact_type == "member") { 
+			echo "	<option value='member' selected='selected' >Member</option>\n";
+		}
+		else {
+			echo "	<option value='member'>Member</option>\n";
+		}
+		if ($contact_type == "family") { 
+			echo "	<option value='family' selected='selected' >Family</option>\n";
+		}
+		else {
+			echo "	<option value='family'>Family</option>\n";
+		}
+		if ($contact_type == "subscriber") { 
+			echo "	<option value='subscriber' selected='selected' >Subscriber</option>\n";
+		}
+		else {
+			echo "	<option value='subscriber'>Subscriber</option>\n";
+		}
+		if ($contact_type == "supplier") { 
+			echo "	<option value='supplier' selected='selected' >Supplier</option>\n";
+		}
+		else {
+			echo "	<option value='supplier'>Supplier</option>\n";
+		}
+		if ($contact_type == "provider") { 
+			echo "	<option value='provider' selected='selected' >Provider</option>\n";
+		}
+		else {
+			echo "	<option value='provider'>Provider</option>\n";
+		}
+		if ($contact_type == "user") { 
+			echo "	<option value='user' selected='selected' >User</option>\n";
+		}
+		else {
+			echo "	<option value='user'>User</option>\n";
+		}
+		if ($contact_type == "volunteer") { 
+			echo "	<option value='volunteer' selected='selected' >Volunteer</option>\n";
+		}
+		else {
+			echo "	<option value='volunteer'>Volunteer</option>\n";
+		}
+		echo "	</select>\n";
+		echo "<br />\n";
+		echo "Select the contact type.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Organization:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_organization' maxlength='255' value=\"$contact_organization\">\n";
+		echo "<br />\n";
+		echo "Enter the organization.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	First Name:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_name_given' maxlength='255' value=\"$contact_name_given\">\n";
+		echo "<br />\n";
+		echo "Enter the given name.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Last Name:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_name_family' maxlength='255' value=\"$contact_name_family\">\n";
+		echo "<br />\n";
+		echo "Enter the family name.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Nickname:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_nickname' maxlength='255' value=\"$contact_nickname\">\n";
+		echo "<br />\n";
+		echo "Enter the nickname.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Title:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_title' maxlength='255' value=\"$contact_title\">\n";
+		echo "<br />\n";
+		echo "Enter the title.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Role:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_role' maxlength='255' value=\"$contact_role\">\n";
+		echo "<br />\n";
+		echo "Enter the role.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		//echo "<tr>\n";
+		//echo "<td><strong>Contact Information</strong></td>\n";
+		//echo "<td>&nbsp;</td>\n";
+		//echo "<tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Email:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_email' maxlength='255' value=\"$contact_email\">\n";
+		echo "<br />\n";
+		echo "Enter the email address.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	URL:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "  <input class='formfld' style='width:85%;' type='text' name='contact_url' maxlength='255' value='$contact_url'>\n";
+		echo "<br />\n";
+		echo "Enter the website address.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		//echo "<tr>\n";
+		//echo "<td><strong>Additional Information</strong></td>\n";
+		//echo "<td>&nbsp;</td>\n";
+		//echo "<tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Time Zone:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' style='width:85%;' type='text' name='contact_time_zone' maxlength='255' value=\"$contact_time_zone\">\n";
+		echo "<br />\n";
+		echo "Enter the time zone.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+		echo "	Notes:\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "  <input class='formfld' style='width:85%;' type='text' name='contact_note' maxlength='255' value='$contact_note'>\n";
+		echo "<br />\n";
+		echo "Enter the notes.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+		echo "	<tr>\n";
+		echo "		<td colspan='2' align='right'>\n";
+		if ($action == "update") {
+			echo "				<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+		}
+		echo "				<input type='submit' name='submit' class='btn' value='Save'>\n";
+		echo "		</td>\n";
+		echo "	</tr>";
+		echo "</table>";
+		echo "</form>";
+
+	echo "</td>\n";
+	echo "<td width='50%' class='' valign='top' align='center'>\n";
+		//echo "	<img src='contacts_vcard.php?id=$contact_uuid&type=image' width='90%'><br /><br />\n";
+		if ($action == "update") {
+			require "contact_phones.php";
+			require "contact_addresses.php";
+			require "contact_notes.php";
+			//echo "<br/><br/>\n";
+		}
+
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	if ($action == "update") {
+		echo "<br/>\n";
+		
+	}
+
+	echo "	</td>";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</div>";
+
+//include the footer
+	require_once "includes/footer.php";
+?>

+ 202 - 0
contacts_vcard.php

@@ -0,0 +1,202 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+require_once "includes/require.php";
+require_once "includes/checkauth.php";
+if (permission_exists('contacts_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+if (count($_GET)>0) {
+	//create the vcard object
+		require_once "includes/class_vcard.php";
+		$vcard = new vcard();
+
+	//get the contact id
+		$contact_uuid = $_GET["id"];
+
+	//get the contact's information
+		$sql = "";
+		$sql .= "select * from v_contacts ";
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$contact_type = $row["contact_type"];
+			$contact_organization = $row["contact_organization"];
+			$contact_name_given = $row["contact_name_given"];
+			$contact_name_family = $row["contact_name_family"];
+			$contact_nickname = $row["contact_nickname"];
+			$contact_title = $row["contact_title"];
+			$contact_role = $row["contact_role"];
+			$contact_email = $row["contact_email"];
+			$contact_url = $row["contact_url"];
+			$contact_time_zone = $row["contact_time_zone"];
+			$contact_note = $row["contact_note"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+
+		$vcard->data['company'] = $contact_organization;
+		$vcard->data['first_name'] = $contact_name_given;
+		$vcard->data['last_name'] = $contact_name_family;
+		$vcard->data['contact_email1'] = $contact_email;
+		$vcard->data['contact_url'] = $contact_url;
+
+		if ($_GET['type'] == "image" || $_GET['type'] == "html") {
+			//don't add this to the QR code at this time
+		}
+		else {
+			$vcard->data['display_name'] = $contact_name_given." ".$contact_name_family;
+			$vcard->data['contact_nickname'] = $contact_nickname;
+			$vcard->data['contact_title'] = $contact_title;
+			$vcard->data['contact_role'] = $contact_role;
+			$vcard->data['timezone'] = $contact_time_zone;
+			$vcard->data['contact_note'] = $contact_note;
+		}
+
+	//get the contact's telephone numbers
+		$sql = "";
+		$sql .= "select * from v_contact_phones ";
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$phone_type = $row["phone_type"];
+			$phone_number = $row["phone_number"];
+			$vcard->data[$phone_type.'_tel'] = $phone_number;
+		}
+		unset ($prep_statement);
+
+	//get the contact's addresses
+		if ($_GET['type'] == "image" || $_GET['type'] == "html") {
+			//don't add this to the QR code at this time
+		}
+		else {
+			$sql = "";
+			$sql .= "select * from v_contact_addresses ";
+			$sql .= "where domain_uuid = '$domain_uuid' ";
+			$sql .= "and contact_uuid = '$contact_uuid' ";
+			$prep_statement = $db->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			foreach ($result as &$row) {
+				$address_type = $row["address_type"];
+				$address_street = $row["address_street"];
+				$address_extended = $row["address_extended"];
+				$address_locality = $row["address_locality"];
+				$address_region = $row["address_region"];
+				$address_postal_code = $row["address_postal_code"];
+				$address_country = $row["address_country"];
+				$address_latitude = $row["address_latitude"];
+				$address_longitude = $row["address_longitude"];
+				$address_type = strtolower(trim($address_type));
+
+				$vcard->data[$address_type.'_address'] = $address_street;
+				$vcard->data[$address_type.'_extended_address'] = $address_extended;
+				$vcard->data[$address_type.'_city'] = $address_locality;
+				$vcard->data[$address_type.'_state'] = $address_region;
+				$vcard->data[$address_type.'_postal_code'] = $address_postal_code;
+				$vcard->data[$address_type.'_country'] = $address_country;
+			}
+			unset ($prep_statement);
+		}
+
+	//download the vcard
+		if ($_GET['type'] == "download") {
+			$vcard->download();
+		}
+
+	//show the vcard in an text qr code
+		if ($_GET['type'] == "text") {
+			$vcard->build();
+			$content = $vcard->card;
+			echo $content;
+		}
+
+	//show the vcard in an image qr code
+		if ($_GET['type'] == "image" || $_GET['type'] == "html") {
+			$vcard->build();
+			$content = $vcard->card;
+
+			//include
+				require_once "includes/qr/qrcode.php";
+
+			//error correction level
+				//QR_ERROR_CORRECT_LEVEL_L : $e = 0;
+				//QR_ERROR_CORRECT_LEVEL_M : $e = 1;
+				//QR_ERROR_CORRECT_LEVEL_Q : $e = 2;
+				//QR_ERROR_CORRECT_LEVEL_H : $e = 3;
+
+			//get the qr object
+				$qr = QRCode::getMinimumQRCode($content, QR_ERROR_CORRECT_LEVEL_L);
+		}
+
+	//show the vcard as an png image
+		if ($_GET['type'] == "image") {
+			header("Content-type: image/png");
+			$im = $qr->createImage(5, 10);
+			imagepng($im);
+			imagedestroy($im);
+		}
+
+	//show the vcard in an html qr code
+		if ($_GET['type'] == "html") {
+			$qr->make();
+			$qr->printHTML();
+		}
+}
+
+/*
+//additional un accounted fields
+additional_name
+name_prefix
+name_suffix
+department
+work_po_box
+home_po_box
+home_extended_address
+home_address
+home_city
+home_state
+home_postal_code
+home_country
+pager_tel
+contact_email2
+photo
+birthday
+sort_string
+*/
+
+?>

+ 50 - 0
root.php

@@ -0,0 +1,50 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+
+// make sure the PATH_SEPARATOR is defined
+	if (!defined("PATH_SEPARATOR")) {
+		if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); }
+	}
+
+// make sure the document_root is set
+	$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
+	//echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."<br />\n";
+	//echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."<br />\n";
+	//echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."<br />\n";
+
+// if the project directory exists then add it to the include path otherwise add the document root to the include path
+	if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' );
+	}
+	else {
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] );
+	}
+
+?>