Browse Source

Contacts: Ability to add unlimited Emails and URLs. Ability to specify a primary Email, Address, URL, and Number. Ability to select or define a custom label for Emails, Addresses, URLs, and Numbers (similar to Google Contacts).

Nate Jones 10 years ago
parent
commit
d7435d8e3d

+ 135 - 18
app_config.php

@@ -193,14 +193,14 @@
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
 		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the category.";
 		$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-us'] = "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-us'] = "Enter the website address.";
-		$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-us'] = "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-us'] = "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-us'] = "Enter the time zone.";
@@ -244,13 +244,17 @@
 		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "contact_uuid";
 		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
 		$z++;
-		//$apps[$x]['db'][$y]['fields'][$z]['name'] = "address_name";
-		//$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
-		//$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the address name.";
-		//$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-us'] = "Enter the address type.";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Used for vCard format.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "address_label";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Custom label for an address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "address_primary";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Designate a primary address.";
 		$z++;
 		$apps[$x]['db'][$y]['fields'][$z]['name'] = "address_street";
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
@@ -258,7 +262,7 @@
 		$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-us'] = "Enter teh extended address.";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the extended address.";
 		$z++;
 		$apps[$x]['db'][$y]['fields'][$z]['name'] = "address_locality";
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
@@ -316,13 +320,33 @@
 		$apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "contact_uuid";
 		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
 		$z++;
-		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_type";
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_type_voice";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Number is used for voice calls.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_type_fax";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Number is used for fax calls.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_type_video";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Number is used for video calls.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_type_text";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Number is used for text messages.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_label";
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
-		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the phone type.";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Custom label for the number";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_primary";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Designate a primary number.";
 		$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-us'] = "Enter the phone number.";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the number.";
 		$z++;
 		$apps[$x]['db'][$y]['fields'][$z]['name'] = "phone_extension";
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
@@ -436,7 +460,7 @@
 		$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";
-		$z++;	
+		$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";
@@ -480,4 +504,97 @@
 		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
 		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "";
 
+		$y = 7; //table array index
+		$apps[$x]['db'][$y]['table'] = "v_contact_emails";
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "contact_email_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-us'] = "";
+		$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-us'] = "";
+		$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-us'] = "";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "email_label";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Custom label for the email address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "email_primary";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Designate a primary address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "email_address";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the email address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "email_description";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the email description.";
+		$z++;
+
+		$y = 8; //table array index
+		$apps[$x]['db'][$y]['table'] = "v_contact_urls";
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "contact_url_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-us'] = "";
+		$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-us'] = "";
+		$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-us'] = "";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "url_type";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Defines the purpose or protocol for the URL.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "url_label";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Custom label for the url.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "url_primary";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Designate a primary address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "url_address";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "The actual URL address.";
+		$z++;
+		$apps[$x]['db'][$y]['fields'][$z]['name'] = "url_description";
+		$apps[$x]['db'][$y]['fields'][$z]['type'] = "text";
+		$apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "Enter the URL description.";
+		$z++;
+
+
 ?>

+ 187 - 0
app_defaults.php

@@ -0,0 +1,187 @@
+<?php
+
+if ($domains_processed == 1) {
+
+	require_once "resources/classes/schema.php";
+
+	//populate new phone_label values, phone_type_* values
+	$obj = new schema;
+	$obj->db = $db;
+	$obj->db_type = $db_type;
+	$obj->schema();
+	$field_exists = $obj->column_exists($db_name, 'v_contact_phones', 'phone_type');	//check if field exists
+	if ($field_exists) {
+		//add multi-lingual support
+		require_once "app/contacts/app_languages.php";
+		foreach($text as $key => $value) {
+			$text[$key] = $value[$_SESSION['domain']['language']['code']];
+		}
+
+		// populate phone_type_* values
+		$sql = "update v_contact_phones set phone_type_voice = '1' ";
+		$sql .= "where phone_type = 'home' ";
+		$sql .= "or phone_type = 'work' ";
+		$sql .= "or phone_type = 'voice' ";
+		$sql .= "or phone_type = 'voicemail' ";
+		$sql .= "or phone_type = 'cell' ";
+		$sql .= "or phone_type = 'pcs' ";
+		$db->exec(check_sql($sql));
+		unset($sql);
+		$sql = "update v_contact_phones set phone_type_fax = '1' where phone_type = 'fax'";
+		$db->exec(check_sql($sql));
+		unset($sql);
+		$sql = "update v_contact_phones set phone_type_video = '1' where phone_type = 'video'";
+		$db->exec(check_sql($sql));
+		unset($sql);
+		$sql = "update v_contact_phones set phone_type_text = '1' where phone_type = 'cell' or phone_type = 'pager'";
+		$db->exec(check_sql($sql));
+		unset($sql);
+
+		// migrate phone_type values to phone_label, correct case and make multilingual where appropriate
+		$default_phone_types = array('home','work','pref','voice','fax','msg','cell','pager','modem','car','isdn','video','pcs');
+		$default_phone_labels = array($text['option-home'],$text['option-work'],'Pref','Voice',$text['option-fax'],$text['option-voicemail'],$text['option-mobile'],$text['option-pager'],'Modem','Car','ISDN','Video','PCS');
+		foreach ($default_phone_types as $index => $old) {
+			$new = $default_phone_labels[$index];
+			$sql = "update v_contact_phones set phone_label = '".$new."' where phone_type = '".$old."'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+		}
+
+		// empty phone_type field to prevent confusion in the future
+		$sql = "update v_contact_phones set phone_type = null";
+		$db->exec(check_sql($sql));
+		unset($sql);
+	}
+	unset($obj);
+
+	//populate primary email from deprecated field in v_contact table
+	$obj = new schema;
+	$obj->db = $db;
+	$obj->db_type = $db_type;
+	$obj->schema();
+	$field_exists = $obj->column_exists($db_name, 'v_contacts', 'contact_email');	//check if field exists
+	if ($field_exists) {
+		// get email records
+		$sql = "select * from v_contacts where contact_email is not null and contact_email != ''";
+		$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);
+		if ($result_count > 0) {
+			foreach($result as $row) {
+				$sql = "insert into v_contact_emails ";
+				$sql .= "(";
+				$sql .= "domain_uuid, ";
+				$sql .= "contact_uuid, ";
+				$sql .= "contact_email_uuid, ";
+				$sql .= "email_primary, ";
+				$sql .= "email_address";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$row['domain_uuid']."', ";
+				$sql .= "'".$row['contact_uuid']."', ";
+				$sql .= "'".uuid()."', ";
+				$sql .= "1, ";
+				$sql .= "'".$row['contact_email']."' ";
+				$sql .= ")";
+				$db->exec(check_sql($sql));
+				unset($sql);
+
+				//verify and remove value from old field
+				$sql2 = "select email_address from v_contact_emails ";
+				$sql2 .= "where domain_uuid = '".$row['domain_uuid']."' ";
+				$sql2 .= "and contact_uuid = '".$row['contact_uuid']."' ";
+				$sql2 .= "and email_address = '".$row['contact_email']."' ";
+				$prep_statement2 = $db->prepare(check_sql($sql2));
+				$prep_statement2->execute();
+				$result2 = $prep_statement2->fetchAll(PDO::FETCH_NAMED);
+				$result_count2 = count($result2);
+				if ($result_count2 > 0) {
+					$sql3 = "update v_contacts set contact_email = '' ";
+					$sql3 .= "where domain_uuid = '".$row['domain_uuid']."' ";
+					$sql3 .= "and contact_uuid = '".$row['contact_uuid']."' ";
+					$prep_statement3 = $db->prepare(check_sql($sql3));
+					$prep_statement3->execute();
+					unset($sql3, $prep_statement3);
+				}
+				unset($sql2, $result2, $prep_statement2);
+			}
+		}
+	}
+	unset($obj);
+
+	//populate primary url from deprecated field in v_contact table
+	$obj = new schema;
+	$obj->db = $db;
+	$obj->db_type = $db_type;
+	$obj->schema();
+	$field_exists = $obj->column_exists($db_name, 'v_contacts', 'contact_url');	//check if field exists
+	if ($field_exists) {
+		// get email records
+		$sql = "select * from v_contacts where contact_url is not null and contact_url != ''";
+		$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);
+		if ($result_count > 0) {
+			foreach($result as $row) {
+				$sql = "insert into v_contact_urls ";
+				$sql .= "(";
+				$sql .= "domain_uuid, ";
+				$sql .= "contact_uuid, ";
+				$sql .= "contact_url_uuid, ";
+				$sql .= "url_primary, ";
+				$sql .= "url_address";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$row['domain_uuid']."', ";
+				$sql .= "'".$row['contact_uuid']."', ";
+				$sql .= "'".uuid()."', ";
+				$sql .= "1, ";
+				$sql .= "'".$row['contact_url']."' ";
+				$sql .= ")";
+				$db->exec(check_sql($sql));
+				unset($sql);
+
+				//verify and remove value from old field
+				$sql2 = "select url_address from v_contact_urls ";
+				$sql2 .= "where domain_uuid = '".$row['domain_uuid']."' ";
+				$sql2 .= "and contact_uuid = '".$row['contact_uuid']."' ";
+				$sql2 .= "and url_address = '".$row['contact_url']."' ";
+				$prep_statement2 = $db->prepare(check_sql($sql2));
+				$prep_statement2->execute();
+				$result2 = $prep_statement2->fetchAll(PDO::FETCH_NAMED);
+				$result_count2 = count($result2);
+				if ($result_count2 > 0) {
+					$sql3 = "update v_contacts set contact_url = '' ";
+					$sql3 .= "where domain_uuid = '".$row['domain_uuid']."' ";
+					$sql3 .= "and contact_uuid = '".$row['contact_uuid']."' ";
+					$prep_statement3 = $db->prepare(check_sql($sql3));
+					$prep_statement3->execute();
+					unset($sql3, $prep_statement3);
+				}
+				unset($sql2, $result2, $prep_statement2);
+			}
+		}
+	}
+	unset($obj);
+
+	//set [name]_primary fields to 0 where null
+	$name_tables = array('phones','addresses','emails','urls');
+	$name_fields = array('phone','address','email','url');
+	foreach ($name_tables as $name_index => $name_table) {
+		$sql = "update v_contact_".$name_table." set ".$name_fields[$name_index]."_primary = 0 ";
+		$sql .= "where ".$name_fields[$name_index]."_primary is null ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($sql, $prep_statement);
+	}
+	unset($name_tables, $name_fields);
+
+}
+
+?>

+ 270 - 34
app_languages.php

@@ -136,7 +136,7 @@
 		$text['label-contact_subcategory']['es-cl'] = "Subcategoría";
 		$text['label-contact_subcategory']['pt-pt'] = "Subcategoria";
 		$text['label-contact_subcategory']['fr-fr'] = "Sous-Catégorie";
-                
+
 		$text['description-contact_subcategory']['en-us'] = "Enter the subcategory.";
 		$text['description-contact_subcategory']['es-cl'] = "Ingrese la categoría.";
 		$text['description-contact_subcategory']['pt-pt'] = "Introduza a subcategoria";
@@ -303,41 +303,51 @@
 		$text['button-certificate']['fr-fr'] = "Certificat";
 
 	// contact phones
-		$text['title-contact_phones-add']['en-us'] = "Contact Phone Add";
+		$text['title-contact_phones-add']['en-us'] = "Contact Number Add";
 		$text['title-contact_phones-add']['es-cl'] = "Agregar Número de Contacto";
 		$text['title-contact_phones-add']['pt-pt'] = "Adicionar contacto telefónico";
 		$text['title-contact_phones-add']['fr-fr'] = "Ajouter un téléphone au Contact";
 
-		$text['header-contact_phones-add']['en-us'] = "Contact Phone Add";
+		$text['header-contact_phones-add']['en-us'] = "Contact Number Add";
 		$text['header-contact_phones-add']['es-cl'] = "Agregar Número de Contacto";
 		$text['header-contact_phones-add']['pt-pt'] = "Adicionar contacto telefónico";
 		$text['header-contact_phones-add']['fr-fr'] = "Ajouter un téléphone au Contact";
 
-		$text['title-contact_phones-edit']['en-us'] = "Contact Phone Edit";
+		$text['title-contact_phones-edit']['en-us'] = "Contact Number Edit";
 		$text['title-contact_phones-edit']['es-cl'] = "Editar Número de Contacto";
 		$text['title-contact_phones-edit']['pt-pt'] = "Editar contacto telefónico";
 		$text['title-contact_phones-edit']['fr-fr'] = "Editer le téléphone du Contact";
 
-		$text['header-contact_phones-edit']['en-us'] = "Contact Phone Edit";
+		$text['header-contact_phones-edit']['en-us'] = "Contact Number Edit";
 		$text['header-contact_phones-edit']['es-cl'] = "Editar Número de Contacto";
 		$text['header-contact_phones-edit']['pt-pt'] = "Editar contacto telefónico";
 		$text['header-contact_phones-edit']['fr-fr'] = "Editer le téléphone du Contact";
 
-		$text['label-phone_numbers']['en-us'] = "Phone Numbers";
-		$text['label-phone_numbers']['es-cl'] = "Números telefónicos";
-		$text['label-phone_numbers']['pt-pt'] = "Números de telefone";
-		$text['label-phone_numbers']['fr-fr'] = "Numéros de téléphone";
+		$text['label-phone_numbers']['en-us'] = "Numbers";
+		$text['label-phone_numbers']['es-cl'] = "Números";
+		$text['label-phone_numbers']['pt-pt'] = "Números";
+		$text['label-phone_numbers']['fr-fr'] = "Numéros";
 
 		$text['label-phone_type']['en-us'] = "Type";
 		$text['label-phone_type']['es-cl'] = "Tipo";
 		$text['label-phone_type']['pt-pt'] = "Tipo";
 		$text['label-phone_type']['fr-fr'] = "Type";
 
-		$text['description-phone_type']['en-us'] = "Select the phone type.";
+		$text['description-phone_type']['en-us'] = "Define the number type or purpose.";
 		$text['description-phone_type']['es-cl'] = "Seleccione el tipo de teléfono.";
 		$text['description-phone_type']['pt-pt'] = "Seleccionar tipo de telefone";
 		$text['description-phone_type']['fr-fr'] = "";
 
+		$text['label-phone_label']['en-us'] = "Label";
+		$text['label-phone_label']['es-cl'] = "Etiqueta";
+		$text['label-phone_label']['pt-pt'] = "Etiqueta";
+		$text['label-phone_label']['fr-fr'] = "Etiquette";
+
+		$text['description-phone_label']['en-us'] = "Select or enter a custom label.";
+		$text['description-phone_label']['es-cl'] = "Seleccione o introduzca una etiqueta personalizada.";
+		$text['description-phone_label']['pt-pt'] = "Selecione ou digite um rótulo personalizado.";
+		$text['description-phone_label']['fr-fr'] = "Sélectionnez ou entrez une étiquette personnalisée.";
+
 		$text['label-phone_number']['en-us'] = "Number";
 		$text['label-phone_number']['es-cl'] = "Número";
 		$text['label-phone_number']['pt-pt'] = "Número";
@@ -378,6 +388,61 @@
 		$text['label-phone_call']['pt-pt'] = "Chamada";
 		$text['label-phone_call']['fr-fr'] = "Appel";
 
+		$text['label-voice']['en-us'] = "Voice";
+		$text['label-voice']['es-cl'] = "Voz";
+		$text['label-voice']['pt-pt'] = "Voz";
+		$text['label-voice']['fr-fr'] = "Voix";
+
+		$text['label-fax']['en-us'] = "Fax";
+		$text['label-fax']['es-cl'] = "Facsímil";
+		$text['label-fax']['pt-pt'] = "Fax";
+		$text['label-fax']['fr-fr'] = "Télécopie";
+
+		$text['label-video']['en-us'] = "Video";
+		$text['label-video']['es-cl'] = "Vídeo";
+		$text['label-video']['pt-pt'] = "Vídeo";
+		$text['label-video']['fr-fr'] = "Vidéo";
+
+		$text['label-text']['en-us'] = "Text";
+		$text['label-text']['es-cl'] = "Texto";
+		$text['label-text']['pt-pt'] = "Texto";
+		$text['label-text']['fr-fr'] = "Texte";
+
+		$text['option-mobile']['en-us'] = "Mobile";
+		$text['option-mobile']['es-cl'] = "Celular";
+		$text['option-mobile']['pt-pt'] = "Celular";
+		$text['option-mobile']['fr-fr'] = "Cellulaire";
+
+		$text['option-main']['en-us'] = "Main";
+		$text['option-main']['es-cl'] = "Principal";
+		$text['option-main']['pt-pt'] = "Principal";
+		$text['option-main']['fr-fr'] = "Principal";
+
+		$text['option-fax']['en-us'] = "Fax";
+		$text['option-fax']['es-cl'] = "Facsímil";
+		$text['option-fax']['pt-pt'] = "Fax";
+		$text['option-fax']['fr-fr'] = "Télécopie";
+
+		$text['option-pager']['en-us'] = "Pager";
+		$text['option-pager']['es-cl'] = "Buscapersonas";
+		$text['option-pager']['pt-pt'] = "Pager";
+		$text['option-pager']['fr-fr'] = "Pager";
+
+		$text['option-voicemail']['en-us'] = "Voicemail";
+		$text['option-voicemail']['es-cl'] = "Correo de Voz";
+		$text['option-voicemail']['pt-pt'] = "Voicemail";
+		$text['option-voicemail']['fr-fr'] = "Messagerie Vocale";
+
+		$text['option-text']['en-us'] = "Text";
+		$text['option-text']['es-cl'] = "Texto";
+		$text['option-text']['pt-pt'] = "Texto";
+		$text['option-text']['fr-fr'] = "Texte";
+
+		$text['option-other']['en-us'] = "Other";
+		$text['option-other']['es-cl'] = "Otro";
+		$text['option-other']['pt-pt'] = "Outro";
+		$text['option-other']['fr-fr'] = "Autre";
+
 	// contact addresses
 		$text['title-contact_addresses-add']['en-us'] = "Contact Address Add";
 		$text['title-contact_addresses-add']['es-cl'] = "Agregar Dirección de Contacto";
@@ -419,30 +484,30 @@
 		$text['label-address_type']['pt-pt'] = "Tipo";
 		$text['label-address_type']['fr-fr'] = "Type";
 
-		$text['description-address_type']['en-us'] = "Enter the address type.";
-		$text['description-address_type']['es-cl'] = "Ingrese el tipo de dirección.";
-		$text['description-address_type']['pt-pt'] = "Introduza o tipo de endereço";
-		$text['description-address_type']['fr-fr'] = "";
+		$text['description-address_type']['en-us'] = "Define the address type (used for vCard generation).";
+		$text['description-address_type']['es-cl'] = "Definir el tipo de dirección (utilizado para la generación de vCard).";
+		$text['description-address_type']['pt-pt'] = "Defina o tipo de endereço (usado para geração de vCard).";
+		$text['description-address_type']['fr-fr'] = "Définir le type d'adresse (utilisé pour la production vCard).";
 
-		$text['label-address_street']['en-us'] = "Street Address";
-		$text['label-address_street']['es-cl'] = "Calle";
-		$text['label-address_street']['pt-pt'] = "Rua";
-		$text['label-address_street']['fr-fr'] = "Rue";
+		$text['label-address_label']['en-us'] = "Label";
+		$text['label-address_label']['es-cl'] = "Etiqueta";
+		$text['label-address_label']['pt-pt'] = "Etiqueta";
+		$text['label-address_label']['fr-fr'] = "Etiquette";
 
-		$text['description-address_street']['en-us'] = "Enter the street address.";
-		$text['description-address_street']['es-cl'] = "Ingrese la calle.";
-		$text['description-address_street']['pt-pt'] = "Introduza o endereço da rua";
-		$text['description-address_street']['fr-fr'] = "";
+		$text['description-address_label']['en-us'] = "Select or enter a custom label.";
+		$text['description-address_label']['es-cl'] = "Seleccione o introduzca una etiqueta personalizada.";
+		$text['description-address_label']['pt-pt'] = "Selecione ou digite um rótulo personalizado.";
+		$text['description-address_label']['fr-fr'] = "Sélectionnez ou entrez une étiquette personnalisée.";
 
-		$text['label-address_extended']['en-us'] = "Extended Address";
-		$text['label-address_extended']['es-cl'] = "Dirección Extendida";
-		$text['label-address_extended']['pt-pt'] = "Mais informações";
-		$text['label-address_extended']['fr-fr'] = "Autres infos";
+		$text['label-address_address']['en-us'] = "Address";
+		$text['label-address_address']['es-cl'] = "Calle";
+		$text['label-address_address']['pt-pt'] = "Rua";
+		$text['label-address_address']['fr-fr'] = "Rue";
 
-		$text['description-address_extended']['en-us'] = "Enter the extended address.";
-		$text['description-address_extended']['es-cl'] = "Ingrese la dirección extendida.";
-		$text['description-address_extended']['pt-pt'] = "Introduza mais informações relativamente ao endereço.";
-		$text['description-address_extended']['fr-fr'] = "";
+		$text['description-address_address']['en-us'] = "Enter the address.";
+		$text['description-address_address']['es-cl'] = "Ingrese la calle.";
+		$text['description-address_address']['pt-pt'] = "Introduza o endereço da rua";
+		$text['description-address_address']['fr-fr'] = "Saisissez l'adresse.";
 
 		$text['label-address_locality']['en-us'] = "City";
 		$text['label-address_locality']['es-cl'] = "Ciudad";
@@ -529,6 +594,56 @@
 		$text['option-work']['pt-pt'] = "Local de Trabalho";
 		$text['option-work']['fr-fr'] = "En Milieu de Travail";
 
+		$text['option-dom']['en-us'] = "Domestic";
+		$text['option-dom']['es-cl'] = "Doméstico";
+		$text['option-dom']['pt-pt'] = "Doméstico";
+		$text['option-dom']['fr-fr'] = "Domestique";
+
+		$text['option-intl']['en-us'] = "International";
+		$text['option-intl']['es-cl'] = "Internacional";
+		$text['option-intl']['pt-pt'] = "Internacional";
+		$text['option-intl']['fr-fr'] = "international";
+
+		$text['option-postal']['en-us'] = "Postal";
+		$text['option-postal']['es-cl'] = "Postal";
+		$text['option-postal']['pt-pt'] = "Postal";
+		$text['option-postal']['fr-fr'] = "Postal";
+
+		$text['option-parcel']['en-us'] = "Parcel";
+		$text['option-parcel']['es-cl'] = "Parcela";
+		$text['option-parcel']['pt-pt'] = "Parcela";
+		$text['option-parcel']['fr-fr'] = "Parcelle";
+
+		$text['option-pref']['en-us'] = "Preferred";
+		$text['option-pref']['es-cl'] = "Preferido";
+		$text['option-pref']['pt-pt'] = "Preferido";
+		$text['option-pref']['fr-fr'] = "Préféré";
+
+		$text['option-mailing']['en-us'] = "Mailing";
+		$text['option-mailing']['es-cl'] = "Mailing";
+		$text['option-mailing']['pt-pt'] = "Mailing";
+		$text['option-mailing']['fr-fr'] = "Postale";
+
+		$text['option-physical']['en-us'] = "Physical";
+		$text['option-physical']['es-cl'] = "Físico";
+		$text['option-physical']['pt-pt'] = "Físico";
+		$text['option-physical']['fr-fr'] = "Physique";
+
+		$text['option-shipping']['en-us'] = "Shipping";
+		$text['option-shipping']['es-cl'] = "Envío";
+		$text['option-shipping']['pt-pt'] = "Remessa";
+		$text['option-shipping']['fr-fr'] = "Livraison";
+
+		$text['option-billing']['en-us'] = "Billing";
+		$text['option-billing']['es-cl'] = "Facturación";
+		$text['option-billing']['pt-pt'] = "Faturamento";
+		$text['option-billing']['fr-fr'] = "Facturation";
+
+		$text['label-google_map']['en-us'] = "Open with Google Maps";
+		$text['label-google_map']['es-cl'] = "Abrir con Google Maps";
+		$text['label-google_map']['pt-pt'] = "Abrir com o Google Maps";
+		$text['label-google_map']['fr-fr'] = "Ouvrir avec Google Maps";
+
 	// contact extensions
 		$text['label-contact_extensions']['en-us'] = "Extensions";
 		$text['label-contact_extensions']['es-cl'] = "Extensións";
@@ -550,6 +665,93 @@
 		$text['label-description']['pt-pt'] = "Descrição";
 		$text['label-description']['fr-fr'] = "Description";
 
+	// contact emails
+		$text['header-contact_email-add']['en-us'] = "Contact Email Add";
+		$text['header-contact_email-add']['es-cl'] = "Correo electrónico de contacto Agregar";
+		$text['header-contact_email-add']['pt-pt'] = "Contato e-mail Adicionar";
+		$text['header-contact_email-add']['fr-fr'] = "Contactez-mail Ajouter";
+
+		$text['description-contact_email-add']['en-us'] = "Contact email address information.";
+		$text['description-contact_email-add']['es-cl'] = "Contactar con información de la dirección de correo electrónico.";
+		$text['description-contact_email-add']['pt-pt'] = "As informações de contato endereço de email.";
+		$text['description-contact_email-add']['fr-fr'] = "Coordonnées de l'adresse e-mail.";
+
+		$text['header-contact_email-edit']['en-us'] = "Contact Email Edit";
+		$text['header-contact_email-edit']['es-cl'] = "Correo electrónico de contacto Editar";
+		$text['header-contact_email-edit']['pt-pt'] = "Email de Contato Editar";
+		$text['header-contact_email-edit']['fr-fr'] = "Contact Courriel Modifier";
+
+		$text['description-contact_email-edit']['en-us'] = "Contact email address information.";
+		$text['description-contact_email-edit']['es-cl'] = "Contactar con información de la dirección de correo electrónico.";
+		$text['description-contact_email-edit']['pt-pt'] = "As informações de contato endereço de email.";
+		$text['description-contact_email-edit']['fr-fr'] = "Coordonnées de l'adresse e-mail.";
+
+		$text['label-emails']['en-us'] = "Emails";
+		$text['label-emails']['es-cl'] = "Extensións";
+		$text['label-emails']['pt-pt'] = "Extensões";
+		$text['label-emails']['fr-fr'] = "Extensions";
+
+		$text['label-email_label']['en-us'] = "Label";
+		$text['label-email_label']['es-cl'] = "Etiqueta";
+		$text['label-email_label']['pt-pt'] = "Etiqueta";
+		$text['label-email_label']['fr-fr'] = "Etiquette";
+
+		$text['label-email_address']['en-us'] = "Address";
+		$text['label-email_address']['es-cl'] = "Calle";
+		$text['label-email_address']['pt-pt'] = "Rua";
+		$text['label-email_address']['fr-fr'] = "Rue";
+
+		$text['label-email_description']['en-us'] = "Description";
+		$text['label-email_description']['es-cl'] = "Descripción";
+		$text['label-email_description']['pt-pt'] = "Descrição";
+		$text['label-email_description']['fr-fr'] = "Description";
+
+	// contact urls
+		$text['header-contact_url-add']['en-us'] = "Contact URL Add";
+		$text['header-contact_url-add']['es-cl'] = "Correo electrónico de contacto Agregar";
+		$text['header-contact_url-add']['pt-pt'] = "Contato e-mail Adicionar";
+		$text['header-contact_url-add']['fr-fr'] = "Contactez-mail Ajouter";
+
+		$text['description-contact_url-add']['en-us'] = "Contact url address information.";
+		$text['description-contact_url-add']['es-cl'] = "Contactar con información de la dirección de correo electrónico.";
+		$text['description-contact_url-add']['pt-pt'] = "As informações de contato endereço de url.";
+		$text['description-contact_url-add']['fr-fr'] = "Coordonnées de l'adresse e-mail.";
+
+		$text['header-contact_url-edit']['en-us'] = "Contact URL Edit";
+		$text['header-contact_url-edit']['es-cl'] = "Correo electrónico de contacto Editar";
+		$text['header-contact_url-edit']['pt-pt'] = "URL de Contato Editar";
+		$text['header-contact_url-edit']['fr-fr'] = "Contact Courriel Modifier";
+
+		$text['description-contact_url-edit']['en-us'] = "Contact url address information.";
+		$text['description-contact_url-edit']['es-cl'] = "Contactar con información de la dirección de correo electrónico.";
+		$text['description-contact_url-edit']['pt-pt'] = "As informações de contato endereço de url.";
+		$text['description-contact_url-edit']['fr-fr'] = "Coordonnées de l'adresse e-mail.";
+
+		$text['label-urls']['en-us'] = "URLs";
+		$text['label-urls']['es-cl'] = "Extensións";
+		$text['label-urls']['pt-pt'] = "Extensões";
+		$text['label-urls']['fr-fr'] = "Extensions";
+
+		$text['label-url_label']['en-us'] = "Label";
+		$text['label-url_label']['es-cl'] = "Etiqueta";
+		$text['label-url_label']['pt-pt'] = "Etiqueta";
+		$text['label-url_label']['fr-fr'] = "Etiquette";
+
+		$text['label-url_address']['en-us'] = "Address";
+		$text['label-url_address']['es-cl'] = "Calle";
+		$text['label-url_address']['pt-pt'] = "Rua";
+		$text['label-url_address']['fr-fr'] = "Rue";
+
+		$text['label-url_description']['en-us'] = "Description";
+		$text['label-url_description']['es-cl'] = "Descripción";
+		$text['label-url_description']['pt-pt'] = "Descrição";
+		$text['label-url_description']['fr-fr'] = "Description";
+
+		$text['option-personal']['en-us'] = "Personal";
+		$text['option-personal']['es-cl'] = "Personal";
+		$text['option-personal']['pt-pt'] = "Pessoal";
+		$text['option-personal']['fr-fr'] = "Personnel";
+
 	// contact notes
 		$text['title-contact_notes-add']['en-us'] = "Contact Note Add";
 		$text['title-contact_notes-add']['es-cl'] = "Agregar Nota de Contacto";
@@ -561,7 +763,7 @@
 		$text['header-contact_notes-add']['pt-pt'] = "Adicionar nota de contacto";
 		$text['header-contact_notes-add']['fr-fr'] = "Ajouter une note au contact";
 
-		$text['description-contact_notes-add']['en-us'] = "";
+		$text['description-contact_notes-add']['en-us'] = "Enter the desired note below.";
 		$text['description-contact_notes-add']['es-cl'] = "Ingrese una nota de contacto.";
 		$text['description-contact_notes-add']['pt-pt'] = "";
 		$text['description-contact_notes-add']['fr-fr'] = "";
@@ -576,11 +778,10 @@
 		$text['header-contact_notes-edit']['pt-pt'] = "Editar notas de contacto";
 		$text['header-contact_notes-edit']['fr-fr'] = "Editer la note du contact";
 
-		$text['description-contact_notes-edit']['en-us'] = ".";
+		$text['description-contact_notes-edit']['en-us'] = "Enter the desired note below.";
 		$text['description-contact_notes-edit']['es-cl'] = "Modifique la nota de contacto";
 		$text['description-contact_notes-edit']['pt-pt'] = "";
-		$text['description-contact_notes-edit']['fr-fr'] = ".";
-
+		$text['description-contact_notes-edit']['fr-fr'] = "";
 
 		$text['label-contact_notes']['en-us'] = "Notes";
 		$text['label-contact_notes']['es-cl'] = "Notas";
@@ -597,6 +798,16 @@
 		$text['description-contact_note']['pt-pt'] = "";
 		$text['description-contact_note']['fr-fr'] = "";
 
+		$text['label-note_content']['en-us'] = "Content";
+		$text['label-note_content']['es-cl'] = "";
+		$text['label-note_content']['pt-pt'] = "";
+		$text['label-note_content']['fr-fr'] = "";
+
+		$text['label-note_user']['en-us'] = "User";
+		$text['label-note_user']['es-cl'] = "";
+		$text['label-note_user']['pt-pt'] = "";
+		$text['label-note_user']['fr-fr'] = "";
+
 	// contact import
 		$text['title-contacts_import']['en-us'] = "Import Contacts";
 		$text['title-contacts_import']['es-cl'] = "Importar Contactos";
@@ -649,6 +860,31 @@
 		$text['message-results']['fr-fr'] = "Les contacts suivants ont été téléchargés correctement à partir di fichier CSV:";
 
 	// general labels
+		$text['label-primary']['en-us'] = "Primary";
+		$text['label-primary']['es-cl'] = "Primário";
+		$text['label-primary']['pt-pt'] = "Primário";
+		$text['label-primary']['fr-fr'] = "Primaire";
+
+		$text['description-phone_primary']['en-us'] = "Set as the primary Number for this contact.";
+		$text['description-phone_primary']['es-cl'] = "Establecer como el número primario para este contacto.";
+		$text['description-phone_primary']['pt-pt'] = "Definir como o principal número para este contato.";
+		$text['description-phone_primary']['fr-fr'] = "Définir comme primaire numéro pour ce contact.";
+
+		$text['description-address_primary']['en-us'] = "Set as the primary Address for this contact.";
+		$text['description-address_primary']['es-cl'] = "Establecer como dirección principal para este contacto.";
+		$text['description-address_primary']['pt-pt'] = "Definir como o principal endereço para este contato.";
+		$text['description-address_primary']['fr-fr'] = "Définir comme adresse principale pour ce contact.";
+
+		$text['description-email_primary']['en-us'] = "Set as the primary Email for this contact.";
+		$text['description-email_primary']['es-cl'] = "Establecer como el correo electrónico principal para este contacto.";
+		$text['description-email_primary']['pt-pt'] = "Definir como o principal e-mail para este contato.";
+		$text['description-email_primary']['fr-fr'] = "Définir comme primaire par mail pour ce contact.";
+
+		$text['description-url_primary']['en-us'] = "Set as the primary URL for this contact.";
+		$text['description-url_primary']['es-cl'] = "Establecer como la URL principal de este contacto.";
+		$text['description-url_primary']['pt-pt'] = "Definir como a URL principal para este contato.";
+		$text['description-url_primary']['fr-fr'] = "Définir comme l'URL principale de ce contact.";
+
 		$text['button-add']['en-us'] = "Add";
 		$text['button-add']['es-cl'] = "Agregar";
 		$text['button-add']['pt-pt'] = "Adicionar";

+ 1 - 3
contact_address_delete.php

@@ -46,11 +46,9 @@ if (count($_GET)>0) {
 }
 
 if (strlen($id)>0) {
-	$sql = "";
-	$sql .= "delete from v_contact_addresses ";
+	$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);

+ 136 - 100
contact_address_edit.php

@@ -57,6 +57,8 @@ if (strlen($_GET["contact_uuid"]) > 0) {
 	if (count($_POST)>0) {
 		//$address_name = check_str($_POST["address_name"]);
 		$address_type = check_str($_POST["address_type"]);
+		$address_label = check_str($_POST["address_label"]);
+		$address_label_custom = check_str($_POST["address_label_custom"]);
 		$address_street = check_str($_POST["address_street"]);
 		$address_extended = check_str($_POST["address_extended"]);
 		$address_locality = check_str($_POST["address_locality"]);
@@ -65,7 +67,11 @@ if (strlen($_GET["contact_uuid"]) > 0) {
 		$address_country = check_str($_POST["address_country"]);
 		$address_latitude = check_str($_POST["address_latitude"]);
 		$address_longitude = check_str($_POST["address_longitude"]);
+		$address_primary = check_str($_POST["address_primary"]);
 		$address_description = check_str($_POST["address_description"]);
+
+		//use custom label if set
+		$address_label = ($address_label_custom != '') ? $address_label_custom : $address_label;
 	}
 
 if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
@@ -76,15 +82,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	}
 
 	//check for all required data
-		//if (strlen($address_type) == 0) { $msg .= $text['message-required'].$text['label-address_type']."<br>\n"; }
-		//if (strlen($address_street) == 0) { $msg .= $text['message-required'].$text['label-address_street']."<br>\n"; }
-		//if (strlen($address_extended) == 0) { $msg .= $text['message-required'].$text['label-address_extended']."<br>\n"; }
-		//if (strlen($address_locality) == 0) { $msg .= $text['message-required'].$text['label-address_locality']."<br>\n"; }
-		//if (strlen($address_region) == 0) { $msg .= $text['message-required'].$text['label-address_region']."<br>\n"; }
-		//if (strlen($address_postal_code) == 0) { $msg .= $text['message-required'].$text['label-address_postal_code']."<br>\n"; }
-		//if (strlen($address_country) == 0) { $msg .= $text['message-required'].$text['label-address_country']."<br>\n"; }
-		//if (strlen($address_latitude) == 0) { $msg .= $text['message-required'].$text['label-address_latitude']."<br>\n"; }
-		//if (strlen($address_longitude) == 0) { $msg .= $text['message-required'].$text['label-address_longitude']."<br>\n"; }
 		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
 			require_once "resources/header.php";
 			require_once "resources/persist_form_var.php";
@@ -100,6 +97,16 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	//add or update the database
 	if ($_POST["persistformvar"] != "true") {
+
+		//if primary, unmark other primary numbers
+		if ($address_primary) {
+			$sql = "update v_contact_addresses set address_primary = 0 ";
+			$sql .= "where domain_uuid = '".$domain_uuid."' ";
+			$sql .= "and contact_uuid = '".$contact_uuid."' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+		}
+
 		if ($action == "add") {
 			$contact_address_uuid = uuid();
 			$sql = "insert into v_contact_addresses ";
@@ -107,8 +114,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "domain_uuid, ";
 			$sql .= "contact_uuid, ";
 			$sql .= "contact_address_uuid, ";
-			//$sql .= "address_name, ";
 			$sql .= "address_type, ";
+			$sql .= "address_label, ";
 			$sql .= "address_street, ";
 			$sql .= "address_extended, ";
 			$sql .= "address_locality, ";
@@ -117,24 +124,26 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "address_country, ";
 			$sql .= "address_latitude, ";
 			$sql .= "address_longitude, ";
+			$sql .= "address_primary, ";
 			$sql .= "address_description ";
 			$sql .= ")";
 			$sql .= "values ";
 			$sql .= "(";
 			$sql .= "'".$_SESSION['domain_uuid']."', ";
-			$sql .= "'$contact_uuid', ";
-			$sql .= "'$contact_address_uuid', ";
-			//$sql .= "'$address_name', ";
-			$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 .= "'$address_description' ";
+			$sql .= "'".$contact_uuid."', ";
+			$sql .= "'".$contact_address_uuid."', ";
+			$sql .= "'".$address_type."', ";
+			$sql .= "'".$address_label."', ";
+			$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 .= (($address_primary) ? 1 : 0).", ";
+			$sql .= "'".$address_description."' ";
 			$sql .= ")";
 			$db->exec(check_sql($sql));
 			unset($sql);
@@ -146,20 +155,21 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		if ($action == "update") {
 			$sql = "update v_contact_addresses set ";
-			$sql .= "contact_uuid = '$contact_uuid', ";
-			//$sql .= "address_name = '$address_name', ";
-			$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 .= "address_description = '$address_description' ";
+			$sql .= "contact_uuid = '".$contact_uuid."', ";
+			$sql .= "address_type = '".$address_type."', ";
+			$sql .= "address_label = '".$address_label."', ";
+			$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 .= "address_primary = ".(($address_primary) ? 1 : 0).", ";
+			$sql .= "address_description = '".$address_description."' ";
 			$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
-			$sql .= "and contact_address_uuid = '$contact_address_uuid'";
+			$sql .= "and contact_address_uuid = '".$contact_address_uuid."'";
 			$db->exec(check_sql($sql));
 			unset($sql);
 
@@ -182,6 +192,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		foreach ($result as &$row) {
 			//$address_name = $row["address_name"];
 			$address_type = $row["address_type"];
+			$address_label = $row["address_label"];
 			$address_street = $row["address_street"];
 			$address_extended = $row["address_extended"];
 			$address_locality = $row["address_locality"];
@@ -190,6 +201,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$address_country = $row["address_country"];
 			$address_latitude = $row["address_latitude"];
 			$address_longitude = $row["address_longitude"];
+			$address_primary = $row["address_primary"];
 			$address_description = $row["address_description"];
 			break; //limit to 1 row
 		}
@@ -205,18 +217,22 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		$document['title'] = $text['title-contact_addresses-add'];
 	}
 
-//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>";
+//javascript to toggle input/select boxes
+	echo "<script type='text/javascript'>";
+	echo "	function toggle_custom(field) {";
+	echo "		$('#'+field).toggle();";
+	echo "		document.getElementById(field).selectedIndex = 0;";
+	echo "		document.getElementById(field+'_custom').value = '';";
+	echo "		$('#'+field+'_custom').toggle();";
+	echo "		if ($('#'+field+'_custom').is(':visible')) { $('#'+field+'_custom').focus(); } else { $('#'+field).focus(); }";
+	echo "	}";
+	echo "</script>";
 
+//show the content
 	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 "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td align='left' width='30%' nowrap='nowrap'><b>";
+	echo "<td align='left' valign='top' nowrap='nowrap'><b>";
 	if ($action == "update") {
 		echo $text['header-contact_addresses-edit'];
 	}
@@ -224,13 +240,13 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		echo $text['header-contact_addresses-add'];
 	}
 	echo "</b></td>\n";
-	echo "<td width='70%' align='right'>";
+	echo "<td align='right' valign='top'>";
 	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=$contact_uuid'\" value='".$text['button-back']."'>";
 	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "</td>\n";
 	echo "</tr>\n";
-	echo "<tr>\n";
-	echo "<td align='left' colspan='2'>\n";
+	echo "</table>\n";
+
 	if ($action == "update") {
 		echo $text['description-contact_addresses-edit'];
 	}
@@ -238,75 +254,85 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		echo $text['description-contact_addresses-add'];
 	}
 	echo "<br /><br />\n";
-	echo "</td>\n";
-	echo "</tr>\n";
 
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_type'].":\n";
+	echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-address_label']."\n";
 	echo "</td>\n";
-	echo "<td class='vtable' align='left'>\n";
-	if (is_array($_SESSION["contact"]["address_type"])) {
-		sort($_SESSION["contact"]["address_type"]);
-		echo "	<select class='formfld' style='width:85%;' name='address_type'>\n";
-		echo "	<option value=''></option>\n";
-		foreach($_SESSION["contact"]["address_type"] as $row) {
-			if ($row == $address_type) {
-				echo "	<option value='".$row."' selected='selected'>".$row."</option>\n";
-			}
-			else {
-				echo "	<option value='".$row."'>".$row."</option>\n";
-			}
+	echo "<td width='70%' class='vtable' align='left'>\n";
+	if (is_array($_SESSION["contact"]["address_label"])) {
+		sort($_SESSION["contact"]["address_label"]);
+		foreach($_SESSION["contact"]["address_label"] as $row) {
+			$address_label_options[] = "<option value='".$row."' ".(($row == $address_label) ? "selected='selected'" : null).">".$row."</option>";
 		}
-		echo "	</select>\n";
+		$address_label_found = (in_array($address_label, $_SESSION["contact"]["address_label"])) ? true : false;
 	}
 	else {
-		echo "	<select class='formfld' name='address_type'>\n";
-		echo "	<option value=''></option>\n";
-		if (strtolower($address_type) == "home") {
-			echo "	<option value='home' selected='selected'>".$text['option-home']."</option>\n";
-		}
-		else {
-			echo "	<option value='home'>".$text['option-home']."</option>\n";
-		}
-		if (strtolower($address_type) == "work") {
-			echo "	<option value='work' selected='selected'>".$text['option-work']."</option>\n";
+		$selected[$address_label] = "selected";
+		$default_labels[] = $text['option-work'];
+		$default_labels[] = $text['option-home'];
+		$default_labels[] = $text['option-mailing'];
+		$default_labels[] = $text['option-physical'];
+		$default_labels[] = $text['option-shipping'];
+		$default_labels[] = $text['option-billing'];
+		$default_labels[] = $text['option-other'];
+		foreach ($default_labels as $default_label) {
+			$address_label_options[] = "<option value='".$default_label."' ".$selected[$default_label].">".$default_label."</option>";
 		}
-		else {
-			echo "	<option value='work'>".$text['option-work']."</option>\n";
-		}
-		echo "	</select>\n";
+		$address_label_found = (in_array($address_label, $default_labels)) ? true : false;
 	}
+	echo "	<select class='formfld' ".((!$address_label_found && $address_label != '') ? "style='display: none;'" : null)." name='address_label' id='address_label' onchange=\"getElementById('address_label_custom').value='';\">\n";
+	echo "		<option value=''></option>\n";
+	echo 		(is_array($address_label_options)) ? implode("\n", $address_label_options) : null;
+	echo "	</select>\n";
+	echo "	<input type='text' class='formfld' ".(($address_label_found || $address_label == '') ? "style='display: none;'" : null)." name='address_label_custom' id='address_label_custom' value=\"".((!$address_label_found) ? htmlentities($address_label) : null)."\">\n";
+	echo "	<input type='button' id='btn_toggle_label' class='btn' alt='".$text['button-back']."' value='&#9665;' onclick=\"toggle_custom('address_label');\">\n";
 	echo "<br />\n";
-	echo $text['description-address_type']."\n";
+	echo $text['description-address_label']."\n";
 	echo "</td>\n";
 	echo "</tr>\n";
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_street'].":\n";
+	echo "	".$text['label-address_type']."\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 "	<select class='formfld' name='address_type' id='address_type'>\n";
+	echo "		<option value=''></option>\n";
+	$vcard_address_types = array(
+		'work' => $text['option-work'],
+		'home' => $text['option-home'],
+		'dom' => $text['option-dom'],
+		'intl' => $text['option-intl'],
+		'postal' => $text['option-postal'],
+		'parcel' => $text['option-parcel'],
+		'pref' => $text['option-pref']
+		);
+	foreach ($vcard_address_types as $vcard_address_type_value => $vcard_address_type_label) {
+		echo "	<option value='".$vcard_address_type_value."' ".(($address_type == $vcard_address_type_value) ? "selected" : null).">".$vcard_address_type_label."</option>\n";
+	}
+	echo "	</select>\n";
 	echo "<br />\n";
-	echo $text['description-address_street']."\n";
+	echo $text['description-address_type']."\n";
 	echo "</td>\n";
 	echo "</tr>\n";
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_extended'].":\n";
+	echo "	".$text['label-address_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\" style='margin-bottom: 3px;'><br>\n";
 	echo "	<input class='formfld' type='text' name='address_extended' maxlength='255' value=\"$address_extended\">\n";
 	echo "<br />\n";
-	echo $text['description-address_extended']."\n";
+	echo $text['description-address_address']."\n";
 	echo "</td>\n";
 	echo "</tr>\n";
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_locality'].":\n";
+	echo "	".$text['label-address_locality']."\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";
@@ -317,7 +343,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_region'].":\n";
+	echo "	".$text['label-address_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";
@@ -328,7 +354,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_postal_code'].":\n";
+	echo "	".$text['label-address_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";
@@ -339,7 +365,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_country'].":\n";
+	echo "	".$text['label-address_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";
@@ -350,7 +376,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_latitude'].":\n";
+	echo "	".$text['label-address_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";
@@ -361,7 +387,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_longitude'].":\n";
+	echo "	".$text['label-address_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";
@@ -372,7 +398,21 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-address_description'].":\n";
+	echo "	".$text['label-primary']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='address_primary' id='address_primary'>\n";
+	echo "		<option value='0'>".$text['option-false']."</option>\n";
+	echo "		<option value='1' ".(($address_primary) ? "selected" : null).">".$text['option-true']."</option>\n";
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo $text['description-address_primary']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-address_description']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' align='left'>\n";
 	echo "	<input class='formfld' type='text' name='address_description' maxlength='255' value=\"$address_description\">\n";
@@ -383,21 +423,17 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "	<tr>\n";
 	echo "		<td colspan='2' align='right'>\n";
-	echo "				<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	echo "			<br>\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='hidden' name='contact_address_uuid' value='$contact_address_uuid'>\n";
 	}
-	echo "				<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "			<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "		</td>\n";
 	echo "	</tr>";
 	echo "</table>";
 	echo "</form>";
 
-	echo "	</td>";
-	echo "	</tr>";
-	echo "</table>";
-	echo "</div>";
-
 //include the footer
 	require_once "resources/footer.php";
 ?>

+ 45 - 55
contact_addresses.php

@@ -38,8 +38,8 @@ else {
 require_once "resources/paging.php";
 
 //get variables used to control the order
-	$order_by = $_GET["order_by"];
-	$order = $_GET["order"];
+// 	$order_by = $_GET["order_by"];
+// 	$order = $_GET["order"];
 
 //show the content
 
@@ -51,36 +51,37 @@ require_once "resources/paging.php";
 	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';
-			}
-		}
+// 		$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;
+// 		$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 ";
+		$sql = "select * from v_contact_addresses ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$sql .= "order by address_primary desc, address_label asc ";
+// 		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);
@@ -95,17 +96,12 @@ require_once "resources/paging.php";
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 
 	echo "<tr>\n";
-	echo th_order_by('address_type', $text['label-address_type'], $order_by, $order);
-	//echo th_order_by('address_street', $text['label-address_street'], $order_by, $order);
-	//echo th_order_by('address_extended', $text['label-address_extended'], $order_by, $order);
-	echo th_order_by('address_locality', $text['label-address_locality'], $order_by, $order);
-	echo th_order_by('address_region', $text['label-address_region'], $order_by, $order);
-	//echo th_order_by('address_postal_code', $text['label-address_postal_code'], $order_by, $order);
-	echo th_order_by('address_country', $text['label-address_country'], $order_by, $order);
-	//echo th_order_by('address_latitude', $text['label-address_latitude'], $order_by, $order);
-	//echo th_order_by('address_longitude', $text['label-address_longitude'], $order_by, $order);
-	echo "<th>".$text['label-address_tools']."</th>\n";
-	echo th_order_by('address_description', $text['label-address_description'], $order_by, $order);
+	echo "<th>".$text['label-address_label']."</th>\n";
+	echo "<th>".$text['label-address_address']."</th>\n";
+	echo "<th>".$text['label-address_locality'].", ".$text['label-address_region']."</th>\n";
+	echo "<th style='text-align: center;'>".$text['label-address_country']."</th>\n";
+	echo "<th>&nbsp;</th>\n";
+	echo "<th>".$text['label-address_description']."</th>\n";
 	echo "<td class='list_control_icons'>";
 	echo 	"<a href='contact_address_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
 	echo "</td>\n";
@@ -115,19 +111,13 @@ require_once "resources/paging.php";
 		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'];
 			$tr_link = "href='contact_address_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_address_uuid']."'";
-			echo "<tr ".$tr_link.">\n";
-			//echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_name']."&nbsp;</td>\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>".ucwords($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]." tr_link_void'>\n";
-			echo "		<a href=\"http://maps.google.com/maps?q=".urlencode($map_query)."&hl=en\" target=\"_blank\">Map</a>&nbsp;\n";
+			echo "<tr ".$tr_link." ".(($row['address_primary']) ? "style='font-weight: bold;'" : null).">\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['address_label']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."' style='width: 25%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['address_street']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".$row['address_locality'].(($row['address_region'] != '') ? ", ".$row['address_region'] : null)."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."' style='text-align: center;'>".$row['address_country']."&nbsp;</td>\n";
+			echo "	<td valign='middle' class='".$row_style[$c]." tr_link_void' style='padding: 0px;'>\n";
+			echo "		<a href=\"http://maps.google.com/maps?q=".urlencode($map_query)."&hl=en\" target=\"_blank\"><img src='icon_gmaps.png' style='width: 21px; height: 21px; alt='".$text['label-google_map']."' title='".$text['label-google_map']."'></a>\n";
 			echo "	</td>\n";
 			echo "	<td valign='top' class='row_stylebg'>".$row['address_description']."&nbsp;</td>\n";
 			echo "	<td class='list_control_icons'>";
@@ -141,11 +131,11 @@ require_once "resources/paging.php";
 	} //end if results
 
 	echo "<tr>\n";
-	echo "<td colspan='11' align='left'>\n";
+	echo "<td colspan='7' 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%' nowrap>&nbsp;</td>\n";
+//	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
 	echo "		<td class='list_control_icons'>";
 	echo 			"<a href='contact_address_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
 	echo "		</td>\n";

+ 24 - 7
contact_delete.php

@@ -45,25 +45,35 @@ if (count($_GET)>0) {
 }
 
 if (strlen($id)>0) {
-	//delete a contact
-		$sql = "delete from v_contacts ";
+	//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 addresses
-		$sql = "delete from v_contact_addresses ";
+	//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 phones
+	//delete emails
 		$sql = "";
-		$sql .= "delete from v_contact_phones ";
+		$sql .= "delete from v_contact_emails ";
+		$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 urls
+		$sql = "";
+		$sql .= "delete from v_contact_urls ";
 		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
 		$sql .= "and contact_uuid = '$id' ";
 		$prep_statement = $db->prepare(check_sql($sql));
@@ -80,7 +90,6 @@ if (strlen($id)>0) {
 		unset($prep_statement, $sql);
 
 	//delete settings
-                
 		$sql = "";
 		$sql = "delete from v_contact_settings ";
 		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
@@ -88,6 +97,14 @@ if (strlen($id)>0) {
 		$prep_statement = $db->prepare(check_sql($sql));
 		$prep_statement->execute();
 		unset($prep_statement, $sql);
+
+	//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);
 }
 
 

+ 22 - 56
contact_edit.php

@@ -74,8 +74,6 @@ else {
 		$contact_title = check_str($_POST["contact_title"]);
 		$contact_category = check_str($_POST["contact_category"]);
 		$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"]);
 	}
@@ -95,8 +93,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		//if (strlen($contact_nickname) == 0) { $msg .= $text['message-required'].$text['label-contact_nickname']."<br>\n"; }
 		//if (strlen($contact_title) == 0) { $msg .= $text['message-required'].$text['label-contact_title']."<br>\n"; }
 		//if (strlen($contact_role) == 0) { $msg .= $text['message-required'].$text['label-contact_role']."<br>\n"; }
-		//if (strlen($contact_email) == 0) { $msg .= $text['message-required'].$text['label-contact_email']."<br>\n"; }
-		//if (strlen($contact_url) == 0) { $msg .= $text['message-required'].$text['label-contact_url']."<br>\n"; }
 		//if (strlen($contact_time_zone) == 0) { $msg .= $text['message-required'].$text['label-contact_time_zone']."<br>\n"; }
 		//if (strlen($contact_note) == 0) { $msg .= $text['message-required'].$text['label-contact_note']."<br>\n"; }
 		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
@@ -129,8 +125,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "contact_title, ";
 			$sql .= "contact_category, ";
 			$sql .= "contact_role, ";
-			$sql .= "contact_email, ";
-			$sql .= "contact_url, ";
 			$sql .= "contact_time_zone, ";
 			$sql .= "contact_note ";
 			$sql .= ") ";
@@ -146,8 +140,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "'".$contact_title."', ";
 			$sql .= "'".$contact_category."', ";
 			$sql .= "'".$contact_role."', ";
-			$sql .= "'".$contact_email."', ";
-			$sql .= "'".$contact_url."', ";
 			$sql .= "'".$contact_time_zone."', ";
 			$sql .= "'".$contact_note."' ";
 			$sql .= ")";
@@ -210,8 +202,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "contact_title = '".$contact_title."', ";
 			$sql .= "contact_category = '".$contact_category."', ";
 			$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 = '".$domain_uuid."' ";
@@ -237,7 +227,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
 
 //pre-populate the form
-	if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
+	if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
 		$contact_uuid = $_GET["id"];
 		$sql = "select * from v_contacts ";
 		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
@@ -254,11 +244,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$contact_title = $row["contact_title"];
 			$contact_category = $row["contact_category"];
 			$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);
 	}
@@ -326,17 +313,17 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	echo "<form method='post' name='frm' action=''>\n";
 	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td align='left' width='30%' nowrap='nowrap'><b>";
+	echo "<td valign='top' align='left' width='30%' nowrap='nowrap'><b>";
 	switch ($action) {
 		case "add" : 	echo $text['header-contact-add'];	break;
 		case "update" :	echo $text['header-contact-edit'];	break;
 	}
 	echo "</b></td>\n";
-	echo "<td width='70%' align='right'>\n";
+	echo "<td valign='top' width='70%' align='right'>\n";
 	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contacts.php?".$_GET["query_string"]."'\" value='".$text['button-back']."'>\n";
 	if ($action == "update") {
 		echo "	<input type='button' class='btn' name='' alt='".$text['button-qr_code']."' onclick=\"$('#qr_code_container').fadeIn(400);\" value='".$text['button-qr_code']."'>\n";
-		echo "	<input type='button' class='btn' name='' alt='".$text['button-vcard']."' onclick=\"window.location='contacts_vcard.php?id=$contact_uuid&type=download'\" value='".$text['button-vcard']."'>\n";
+		echo "	<input type='button' class='btn' name='' alt='".$text['button-vcard']."' onclick=\"window.location='contacts_vcard.php?id=".$contact_uuid."&type=download'\" value='".$text['button-vcard']."'>\n";
 	}
 	if ($action == "update" && is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/invoices')) {
 		echo "	<input type='button' class='btn' name='' alt='".$text['button-invoices']."' onclick=\"window.location='".PROJECT_PATH."/app/invoices/invoices.php?id=$contact_uuid'\" value='".$text['button-invoices']."'>\n";
@@ -358,19 +345,18 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	echo "</tr>\n";
 	echo "</table>\n";
 
-	echo "<table border='0' cellpadding='3' cellspacing='3' width='100%'>\n";
+	echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
 	echo "<tr>\n";
 	echo "<td width='40%' valign='top' align='left' nowrap='nowrap'>\n";
 
 		echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
 		echo "<tr>\n";
 		echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_type'].":\n";
+		echo "	".$text['label-contact_type']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
-
-		if (is_array($_SESSION["contact"]["role"])) {
-			sort($_SESSION["contact"]["role"]);
+		if (is_array($_SESSION["contact"]["type"])) {
+			sort($_SESSION["contact"]["type"]);
 			echo "	<select class='formfld' name='contact_type'>\n";
 			echo "	<option value=''></option>\n";
 			foreach($_SESSION["contact"]["type"] as $row) {
@@ -462,7 +448,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_organization'].":\n";
+		echo "	".$text['label-contact_organization']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<input class='formfld' type='text' name='contact_organization' maxlength='255' value=\"$contact_organization\">\n";
@@ -473,7 +459,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_name_given'].":\n";
+		echo "	".$text['label-contact_name_given']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<input class='formfld' type='text' name='contact_name_given' maxlength='255' value=\"$contact_name_given\">\n";
@@ -484,7 +470,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_name_family'].":\n";
+		echo "	".$text['label-contact_name_family']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<input class='formfld' type='text' name='contact_name_family' maxlength='255' value=\"$contact_name_family\">\n";
@@ -495,7 +481,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_nickname'].":\n";
+		echo "	".$text['label-contact_nickname']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<input class='formfld' type='text' name='contact_nickname' maxlength='255' value=\"$contact_nickname\">\n";
@@ -506,7 +492,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_title'].":\n";
+		echo "	".$text['label-contact_title']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		if (is_array($_SESSION["contact"]["title"])) {
@@ -533,7 +519,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_category'].":\n";
+		echo "	".$text['label-contact_category']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		if (is_array($_SESSION["contact"]["category"])) {
@@ -560,7 +546,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_role'].":\n";
+		echo "	".$text['label-contact_role']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		if (is_array($_SESSION["contact"]["role"])) {
@@ -587,29 +573,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_email'].":\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<input class='formfld' type='text' name='contact_email' maxlength='255' value=\"$contact_email\">\n";
-		echo "<br />\n";
-		echo $text['description-contact_email']."\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_url'].":\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "  <input class='formfld' type='text' name='contact_url' maxlength='255' value='$contact_url'>\n";
-		echo "<br />\n";
-		echo $text['description-contact_url']."\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_time_zone'].":\n";
+		echo "	".$text['label-contact_time_zone']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<input class='formfld' type='text' name='contact_time_zone' maxlength='255' value=\"$contact_time_zone\">\n";
@@ -638,7 +602,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		$contact_shared_disabled = ($_SESSION['groups'][0]['domain_uuid'] != $_SESSION['domain_uuid']) ? "disabled='disabled'" : null;
 		echo "<tr>\n";
 		echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-shared'].":\n";
+		echo "	".$text['label-shared']."\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
 		echo "	<select class='formfld' ".(($contact_shared_disabled == '') ? "name='contact_shared'" : null)." id='contact_shared' ".((permission_exists('contact_group_view')) ? "onchange=\"$('#div_groups').slideToggle('400');\"" : null)." ".$contact_shared_disabled.">\n";
@@ -737,10 +701,10 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
 		echo "<tr>\n";
 		echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	".$text['label-contact_note'].":\n";
+		echo "	".$text['label-contact_note']."\n";
 		echo "</td>\n";
 		echo "<td width='70%' class='vtable' align='left'>\n";
-		echo "  <input class='formfld' type='text' name='contact_note' maxlength='255' value='$contact_note'>\n";
+		echo "  <textarea class='formfld' style='width: 100%; height: 80px;' name='contact_note'>".$contact_note."</textarea>\n";
 		echo "<br />\n";
 		echo $text['description-contact_note']."\n";
 		echo "</td>\n";
@@ -759,11 +723,13 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	echo "</td>\n";
 
 	if ($action == "update") {
-		echo "<td>&nbsp;&nbsp;</td>";
+		echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
 		echo "<td width='60%' class='' valign='top' align='center'>\n";
 			//echo "	<img src='contacts_vcard.php?id=$contact_uuid&type=image' width='90%'><br /><br />\n";
 			require "contact_phones.php";
 			require "contact_addresses.php";
+			require "contact_emails.php";
+			require "contact_urls.php";
 			require "contact_extensions.php";
 			require "contact_notes.php";
 			require "contact_settings.php";

+ 61 - 0
contact_email_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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//add multi-lingual support
+	require_once "app_languages.php";
+	foreach($text as $key => $value) {
+		$text[$key] = $value[$_SESSION['domain']['language']['code']];
+	}
+
+if (count($_GET)>0) {
+	$id = check_str($_GET["id"]);
+	$contact_uuid = check_str($_GET["contact_uuid"]);
+}
+
+if (strlen($id)>0) {
+	$sql = "delete from v_contact_emails ";
+	$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+	$sql .= "and contact_email_uuid = '".$id."' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	unset($sql);
+}
+
+$_SESSION["message"] = $text['message-delete'];
+header("Location: contact_edit.php?id=".$contact_uuid);
+return;
+
+?>

+ 301 - 0
contact_email_edit.php

@@ -0,0 +1,301 @@
+<?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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//add multi-lingual support
+	require_once "app_languages.php";
+	foreach($text as $key => $value) {
+		$text[$key] = $value[$_SESSION['domain']['language']['code']];
+	}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_email_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) {
+		$email_label = check_str($_POST["email_label"]);
+		$email_label_custom = check_str($_POST["email_label_custom"]);
+		$email_address = check_str($_POST["email_address"]);
+		$email_primary = check_str($_POST["email_primary"]);
+		$email_description = check_str($_POST["email_description"]);
+
+		//use custom label if set
+		$email_label = ($email_label_custom != '') ? $email_label_custom : $email_label;
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_email_uuid = check_str($_POST["contact_email_uuid"]);
+	}
+
+	//check for all required data
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "resources/header.php";
+			require_once "resources/persist_form_var.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 "resources/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+
+		//if primary, unmark other primary numbers
+		if ($email_primary) {
+			$sql = "update v_contact_emails set email_primary = 0 ";
+			$sql .= "where domain_uuid = '".$domain_uuid."' ";
+			$sql .= "and contact_uuid = '".$contact_uuid."' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+		}
+
+		if ($action == "add") {
+			$contact_email_uuid = uuid();
+			$sql = "insert into v_contact_emails ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_email_uuid, ";
+			$sql .= "email_label, ";
+			$sql .= "email_address, ";
+			$sql .= "email_primary, ";
+			$sql .= "email_description ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$_SESSION['domain_uuid']."', ";
+			$sql .= "'".$contact_uuid."', ";
+			$sql .= "'".$contact_email_uuid."', ";
+			$sql .= "'".$email_label."', ";
+			$sql .= "'".$email_address."', ";
+			$sql .= (($email_primary) ? 1 : 0).", ";
+			$sql .= "'".$email_description."' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			$_SESSION["message"] = $text['message-add'];
+			header("Location: contact_edit.php?id=".$contact_uuid);
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contact_emails set ";
+			$sql .= "contact_uuid = '".$contact_uuid."', ";
+			$sql .= "email_label = '".$email_label."', ";
+			$sql .= "email_address = '".$email_address."', ";
+			$sql .= "email_primary = ".(($email_primary) ? 1 : 0).", ";
+			$sql .= "email_description = '".$email_description."' ";
+			$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+			$sql .= "and contact_email_uuid = '".$contact_email_uuid."'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			$_SESSION["message"] = $text['message-update'];
+			header("Location: contact_edit.php?id=".$contact_uuid);
+			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_email_uuid = $_GET["id"];
+		$sql = "select * from v_contact_emails ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_email_uuid = '".$contact_email_uuid."' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$email_label = $row["email_label"];
+			$email_address = $row["email_address"];
+			$email_primary = $row["email_primary"];
+			$email_description = $row["email_description"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "resources/header.php";
+	if ($action == "update") {
+		$document['title'] = $text['title-contact_email-edit'];
+	}
+	else if ($action == "add") {
+		$document['title'] = $text['title-contact_email-add'];
+	}
+
+//javascript to toggle input/select boxes
+	echo "<script type='text/javascript'>";
+	echo "	function toggle_custom(field) {";
+	echo "		$('#'+field).toggle();";
+	echo "		document.getElementById(field).selectedIndex = 0;";
+	echo "		document.getElementById(field+'_custom').value = '';";
+	echo "		$('#'+field+'_custom').toggle();";
+	echo "		if ($('#'+field+'_custom').is(':visible')) { $('#'+field+'_custom').focus(); } else { $('#'+field).focus(); }";
+	echo "	}";
+	echo "</script>";
+
+//show the content
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "<td align='left' valign='top' nowrap='nowrap'><b>";
+	if ($action == "update") {
+		echo $text['header-contact_email-edit'];
+	}
+	else if ($action == "add") {
+		echo $text['header-contact_email-add'];
+	}
+	echo "</b></td>\n";
+	echo "<td align='right' valign='top'>";
+	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=".$contact_uuid."'\" value='".$text['button-back']."'>";
+	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	if ($action == "update") {
+		echo $text['description-contact_email-edit'];
+	}
+	else if ($action == "add") {
+		echo $text['description-contact_email-add'];
+	}
+	echo "<br /><br />\n";
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-email_label']."\n";
+	echo "</td>\n";
+	echo "<td width='70%' class='vtable' align='left'>\n";
+	if (is_array($_SESSION["contact"]["email_label"])) {
+		sort($_SESSION["contact"]["email_label"]);
+		foreach($_SESSION["contact"]["email_label"] as $row) {
+			$email_label_options[] = "<option value='".$row."' ".(($row == $email_label) ? "selected='selected'" : null).">".$row."</option>";
+		}
+		$email_label_found = (in_array($email_label, $_SESSION["contact"]["email_label"])) ? true : false;
+	}
+	else {
+		$selected[$email_label] = "selected";
+		$default_labels[] = $text['option-work'];
+		$default_labels[] = $text['option-home'];
+		$default_labels[] = $text['option-other'];
+		foreach ($default_labels as $default_label) {
+			$email_label_options[] = "<option value='".$default_label."' ".$selected[$default_label].">".$default_label."</option>";
+		}
+		$email_label_found = (in_array($email_label, $default_labels)) ? true : false;
+	}
+	echo "	<select class='formfld' ".((!$email_label_found && $email_label != '') ? "style='display: none;'" : null)." name='email_label' id='email_label' onchange=\"getElementById('email_label_custom').value='';\">\n";
+	echo "		<option value=''></option>\n";
+	echo 		(is_array($email_label_options)) ? implode("\n", $email_label_options) : null;
+	echo "	</select>\n";
+	echo "	<input type='text' class='formfld' ".(($email_label_found || $email_label == '') ? "style='display: none;'" : null)." name='email_label_custom' id='email_label_custom' value=\"".((!$email_label_found) ? htmlentities($email_label) : null)."\">\n";
+	echo "	<input type='button' id='btn_toggle_label' class='btn' alt='".$text['button-back']."' value='&#9665;' onclick=\"toggle_custom('email_label');\">\n";
+	echo "<br />\n";
+	echo $text['description-email_label']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-email_address']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='email_address' maxlength='255' value=\"".$email_address."\">\n";
+	echo "<br />\n";
+	echo $text['description-email_address']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-primary']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='email_primary' id='email_primary'>\n";
+	echo "		<option value='0'>".$text['option-false']."</option>\n";
+	echo "		<option value='1' ".(($email_primary) ? "selected" : null).">".$text['option-true']."</option>\n";
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo $text['description-email_primary']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-email_description']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='email_description' maxlength='255' value=\"".$email_description."\">\n";
+	echo "<br />\n";
+	echo $text['description-email_description']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "			<br>\n";
+	echo "			<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	if ($action == "update") {
+		echo "		<input type='hidden' name='contact_email_uuid' value='".$contact_email_uuid."'>\n";
+	}
+	echo "			<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "		</td>\n";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+//include the footer
+	require_once "resources/footer.php";
+?>

+ 140 - 0
contact_emails.php

@@ -0,0 +1,140 @@
+<?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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//require_once "resources/header.php";
+require_once "resources/paging.php";
+
+//get variables used to control the order
+// 	$order_by = $_GET["order_by"];
+// 	$order = $_GET["order"];
+
+//show the content
+
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>".$text['label-emails']."</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+// 		$sql = " select count(*) as num_rows from v_contact_emails ";
+// 		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+// 		$sql .= " and contact_uuid = '$contact_uuid' ";
+// 		$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_emails ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$sql .= "order by email_primary desc, email_label asc ";
+// 		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 class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<th>".$text['label-email_label']."</th>\n";
+	echo "<th>".$text['label-email_address']."</th>\n";
+	echo "<th>".$text['label-email_description']."</th>\n";
+	echo "<td class='list_control_icons'>";
+	echo 	"<a href='contact_email_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	if ($result_count > 0) {
+		foreach($result as $row) {
+			$tr_link = "href='contact_email_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_email_uuid']."'";
+			echo "<tr ".$tr_link." ".(($row['email_primary']) ? "style='font-weight: bold;'" : null).">\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['email_label']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]." tr_link_void'><a href='mailto:".$row['email_address']."'>".$row['email_address']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='row_stylebg'>".$row['address_description']."&nbsp;</td>\n";
+			echo "	<td class='list_control_icons'>";
+			echo 		"<a href='contact_email_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_email_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
+			echo 		"<a href='contact_email_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_email_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
+			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 class='list_control_icons'>";
+	echo 			"<a href='contact_email_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "</div>";
+
+?>

+ 3 - 3
contact_extensions.php

@@ -117,9 +117,9 @@ require_once "resources/paging.php";
 	echo "<div align='center'>\n";
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo th_order_by('extension', $text['label-extension'], $order_by, $order);
-	echo th_order_by('enabled', $text['label-enabled'], $order_by, $order);
-	echo th_order_by('phone_description', $text['label-description'], $order_by, $order);
+	echo "<th>".$text['label-extension']."</th>\n";
+	echo "<th>".$text['label-enabled']."</th>\n";
+	echo "<th>".$text['label-description']."</th>\n";
 	echo "<td class='list_control_icons'>";
 	if (permission_exists('extension_add')) {
 		echo "  <a href='/app/extensions/extension_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>\n";

+ 47 - 29
contact_import.php

@@ -203,62 +203,76 @@ else {
 							$x = 0;
 							if (strlen($data['BusinessFax']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['BusinessFax']);
-								$phone_array[$x]['phone_type'] = 'fax';
+								$phone_array[$x]['phone_type_fax'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-fax'];
+								$phone_array[$x]['phone_description'] = $text['option-work'];
 								$x++;
 							}
 							if (strlen($data['BusinessPhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['BusinessPhone']);
-								$phone_array[$x]['phone_type'] = 'work';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-work'];
 								$x++;
 							}
 							if (strlen($data['BusinessPhone2']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['BusinessPhone2']);
-								$phone_array[$x]['phone_type'] = 'work';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-work'];
 								$x++;
 							}
 							if (strlen($data['CompanyMainPhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['CompanyMainPhone']);
-								$phone_array[$x]['phone_type'] = 'pref';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-main'];
 								$x++;
 							}
 							if (strlen($data['HomeFax']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['HomeFax']);
-								$phone_array[$x]['phone_type'] = 'fax';
+								$phone_array[$x]['phone_type_fax'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-fax'];
+								$phone_array[$x]['phone_description'] = $text['option-home'];
 								$x++;
 							}
 							if (strlen($data['HomePhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['HomePhone']);
-								$phone_array[$x]['phone_type'] = 'home';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-home'];
 								$x++;
 							}
 							if (strlen($data['HomePhone2']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['HomePhone2']);
-								$phone_array[$x]['phone_type'] = 'home';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-home'];
 								$x++;
 							}
 							if (strlen($data['MobilePhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['MobilePhone']);
-								$phone_array[$x]['phone_type'] = 'cell';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-mobile'];
 								$x++;
 							}
 							if (strlen($data['OtherFax']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['OtherFax']);
-								$phone_array[$x]['phone_type'] = 'fax';
+								$phone_array[$x]['phone_type_fax'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-fax'];
 								$x++;
 							}
 							if (strlen($data['OtherPhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['OtherPhone']);
-								$phone_array[$x]['phone_type'] = 'home';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-other'];
 								$x++;
 							}
 							if (strlen($data['Pager']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['Pager']);
-								$phone_array[$x]['phone_type'] = 'page';
+								$phone_array[$x]['phone_type_text'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-pager'];
 								$x++;
 							}
 							if (strlen($data['PrimaryPhone']) > 0) {
 								$phone_array[$x]['phone_number'] = preg_replace('{\D}', '', $data['PrimaryPhone']);
-								$phone_array[$x]['phone_type'] = 'pref';
+								$phone_array[$x]['phone_type_voice'] = 1;
+								$phone_array[$x]['phone_label'] = $text['option-main'];
 								$x++;
 							}
 							foreach ($phone_array as $row) {
@@ -268,16 +282,26 @@ else {
 								$sql .= "domain_uuid, ";
 								$sql .= "contact_uuid, ";
 								$sql .= "contact_phone_uuid, ";
-								$sql .= "phone_type, ";
-								$sql .= "phone_number ";
+								$sql .= "phone_type_voice, ";
+								$sql .= "phone_type_fax, ";
+								$sql .= "phone_type_video, ";
+								$sql .= "phone_type_text, ";
+								$sql .= "phone_label, ";
+								$sql .= "phone_number, ";
+								$sql .= "phone_description ";
 								$sql .= ")";
 								$sql .= "values ";
 								$sql .= "(";
 								$sql .= "'$domain_uuid', ";
 								$sql .= "'$contact_uuid', ";
 								$sql .= "'$contact_phone_uuid', ";
-								$sql .= "'".$row['phone_type']."', ";
-								$sql .= "'".$row['phone_number']."' ";
+								$sql .= (($row['phone_type_voice']) ? 1 : 0).", ";
+								$sql .= (($row['phone_type_fax']) ? 1 : 0).", ";
+								$sql .= (($row['phone_type_video']) ? 1 : 0).", ";
+								$sql .= (($row['phone_type_text']) ? 1 : 0).", ";
+								$sql .= "'".$row['phone_label']."', ";
+								$sql .= "'".$row['phone_number']."', ";
+								$sql .= "'".$row['phone_description']."', ";
 								$sql .= ")";
 								$db->exec(check_sql($sql));
 								unset($sql);
@@ -299,8 +323,7 @@ else {
 
 		//show the header
 			require_once "resources/header.php";
-			echo "<div align='center'>\n";
-			echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
+			echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 			echo "<tr>\n";
 			echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['header-contacts_import']."</b></td>\n";
 			echo "<td width='70%' align='right'>\n";
@@ -315,7 +338,7 @@ else {
 			echo "</table>\n";
 
 		//show the results
-			echo "<table width='100%'  border='0' cellpadding='3' cellspacing='0' width='100%'>\n";
+			echo "<table width='100%'  border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
 			echo "<tr>\n";
 			echo "	<th>".$text['label-contact_name']."</th>\n";
 			echo "	<th>".$text['label-contact_organization']."</th>\n";
@@ -351,19 +374,13 @@ else {
 	require_once "resources/header.php";
 
 //begin 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 "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "	<tr>\n";
-	echo "	<td align='left' width='30%' nowrap='nowrap'>\n";
+	echo "	<td valign='top' align='left' width='30%' nowrap='nowrap'>\n";
 	echo "		<b>".$text['header-contacts_import']."</b><br />\n";
 	echo "		".$text['description-contacts_import']."\n";
 	echo "	</td>\n";
-	echo "	<td width='70%' align='right'>\n";
+	echo "	<td valign='top' width='70%' align='right'>\n";
 	echo "		<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contacts.php?".$_GET["query_string"]."'\" value='".$text['button-back']."'>\n";
 	echo "		<input name=\"submit\" type=\"submit\" class=\"btn\" id=\"upload\" value=\"".$text['button-upload']."\">\n";
 	echo "	</td>\n";
@@ -373,7 +390,7 @@ else {
 	echo "<br />\n";
 
 	echo "<form action=\"\" method=\"POST\" enctype=\"multipart/form-data\" name=\"frmUpload\" onSubmit=\"\">\n";
-	echo "	<table border='0' width='100%'>\n";
+	echo "	<table border='0' cellpadding='0' cellspacing='0' width='100%'>\n";
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
@@ -419,6 +436,7 @@ else {
 	echo "			&nbsp;\n";
 	echo "		</td>\n";
 	echo "		<td valign=\"top\" align='right' class=\"label\" nowrap>\n";
+	echo "			<br />\n";
 	echo "			<input name=\"type\" type=\"hidden\" value=\"csv\">\n";
 	echo "			<input name=\"submit\" type=\"submit\"  class=\"btn\" id=\"upload\" value=\"".$text['button-upload']."\">\n";
 	echo "		</td>\n";

+ 1 - 2
contact_note_delete.php

@@ -46,8 +46,7 @@ if (count($_GET)>0) {
 }
 
 if (strlen($id)>0) {
-	$sql = "";
-	$sql .= "delete from v_contact_notes ";
+	$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));

+ 12 - 21
contact_note_edit.php

@@ -162,55 +162,46 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	}
 
 //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 "<table width='100%'  border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
+	echo "<td align='left' width='30%' nowrap='nowrap'>";
 	if ($action == "add") {
-		echo "<td align='left' width='15%' nowrap='nowrap'><b>".$text['header-contact_notes-add']."</b></td>\n";
+		echo "<b>".$text['header-contact_notes-add']."</b>";
 	}
 	if ($action == "update") {
-		echo "<td align='left' width='15%' nowrap='nowrap'><b>".$text['header-contact_notes-edit']."</b></td>\n";
+		echo "<b>".$text['header-contact_notes-edit']."</b>\n";
 	}
+	echo "</td>\n";
 	echo "<td width='70%' align='right'>";
 	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=$contact_uuid'\" value='".$text['button-back']."'>";
 	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "</td>\n";
 	echo "</tr>\n";
+	echo "<tr><td colspan='2'>&nbsp;</td></tr>\n";
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-contact_note'].":\n";
+	echo "	".$text['label-contact_note']."\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 "  <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";
+	echo "			<br>";
+	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='hidden' name='contact_note_uuid' value='$contact_note_uuid'>\n";
 	}
-	echo "				<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "			<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "		</td>\n";
 	echo "	</tr>";
 	echo "</table>";
 	echo "</form>";
 
-	echo "	</td>";
-	echo "	</tr>";
-	echo "</table>";
-	echo "</div>";
-
 //include the footer
 	require_once "resources/footer.php";
 ?>

+ 36 - 50
contact_notes.php

@@ -57,36 +57,36 @@ require_once "resources/paging.php";
 	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';
-			}
-		}
+// 		$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;
+// 		$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 ";
+		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();
@@ -99,38 +99,25 @@ require_once "resources/paging.php";
 	$row_style["0"] = "row_style0";
 	$row_style["1"] = "row_style1";
 
-	echo "<div align='center'>\n";
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 
-	if ($result_count == 0) {
-		echo "<tr>\n";
-		echo "<th>&nbsp;</th>\n";
-		echo "<td class='list_control_icon'>";
-		echo 	"<a href='contact_note_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
-		echo "</td>\n";
-		echo "</tr>\n";
-	}
-	else {
+	echo "<tr>\n";
+	echo "<th>".$text['label-note_content']."</th>\n";
+	echo "<th style='text-align: right;'>".$text['label-note_user']."</th>\n";
+	echo "<td class='list_control_icons'>";
+	echo 	"<a href='contact_note_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "</td>\n";
+	echo "</tr>\n";
+	if ($result_count != 0) {
 		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_note_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
-			echo "</td>\n";
-			echo "</tr>\n";
 			$tr_link = "href='contact_note_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_note_uuid']."'";
 			echo "<tr ".$tr_link.">\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>".$contact_note."&nbsp;</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' class='".$row_style[$c]."' colspan='2'>";
+			echo "		<div style='display: inline-block; float: right; margin: -5px -7px 5px 5px; padding: 3px 4px; font-size: 10px; background-color: #f0f2f6;'><span style='color: #000; font-weight: bold;'>".$row['last_mod_user']."</span>: ".date("j M Y @ H:i:s", strtotime($row['last_mod_date']))."</div>";
+			echo 		$contact_note."&nbsp;";
+			echo "	</td>\n";
 			echo "	<td class='list_control_icons'>";
 			echo 		"<a href='contact_note_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_note_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
 			echo 		"<a href='contact_note_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_note_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
@@ -143,7 +130,7 @@ require_once "resources/paging.php";
 	} //end if results
 
 	echo "<tr>\n";
-	echo "<td colspan='4' align='left'>\n";
+	echo "<td colspan='3' align='left'>\n";
 	echo "	<table width='100%' cellpadding='0' cellspacing='0'>\n";
 	echo "	<tr>\n";
 	echo "		<td width='33.3%' nowrap>&nbsp;</td>\n";
@@ -157,6 +144,5 @@ require_once "resources/paging.php";
 	echo "</tr>\n";
 
 	echo "</table>";
-	echo "</div>";
 
 ?>

+ 1 - 2
contact_phone_delete.php

@@ -46,8 +46,7 @@ if (count($_GET)>0) {
 }
 
 if (strlen($id)>0) {
-	$sql = "";
-	$sql .= "delete from v_contact_phones ";
+	$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));

+ 131 - 153
contact_phone_edit.php

@@ -55,13 +55,22 @@ if (strlen($_GET["contact_uuid"]) > 0) {
 
 //get http post variables and set them to php variables
 	if (count($_POST)>0) {
-		$phone_type = check_str($_POST["phone_type"]);
+		$phone_type_voice = check_str($_POST["phone_type_voice"]);
+		$phone_type_fax = check_str($_POST["phone_type_fax"]);
+		$phone_type_video = check_str($_POST["phone_type_video"]);
+		$phone_type_text = check_str($_POST["phone_type_text"]);
+		$phone_label = check_str($_POST["phone_label"]);
+		$phone_label_custom = check_str($_POST["phone_label_custom"]);
 		$phone_number = check_str($_POST["phone_number"]);
 		$phone_extension = check_str($_POST["phone_extension"]);
+		$phone_primary = check_str($_POST["phone_primary"]);
 		$phone_description = check_str($_POST["phone_description"]);
 
 		//remove any phone number formatting
 		$phone_number = preg_replace('{\D}', '', $phone_number);
+
+		//use custom label if set
+		$phone_label = ($phone_label_custom != '') ? $phone_label_custom : $phone_label;
 	}
 
 if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
@@ -72,8 +81,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	}
 
 	//check for all required data
-		//if (strlen($phone_type) == 0) { $msg .= $text['message-required'].$text['label-phone_type']."<br>\n"; }
-		//if (strlen($phone_number) == 0) { $msg .= $text['message-required'].$text['label-phone_number']."<br>\n"; }
 		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
 			require_once "resources/header.php";
 			require_once "resources/persist_form_var.php";
@@ -89,6 +96,16 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	//add or update the database
 	if ($_POST["persistformvar"] != "true") {
+
+		//if primary, unmark other primary numbers
+		if ($phone_primary) {
+			$sql = "update v_contact_phones set phone_primary = 0 ";
+			$sql .= "where domain_uuid = '".$domain_uuid."' ";
+			$sql .= "and contact_uuid = '".$contact_uuid."' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+		}
+
 		if ($action == "add") {
 			$contact_phone_uuid = uuid();
 			$sql = "insert into v_contact_phones ";
@@ -96,20 +113,30 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 			$sql .= "domain_uuid, ";
 			$sql .= "contact_uuid, ";
 			$sql .= "contact_phone_uuid, ";
-			$sql .= "phone_type, ";
+			$sql .= "phone_type_voice, ";
+			$sql .= "phone_type_fax, ";
+			$sql .= "phone_type_video, ";
+			$sql .= "phone_type_text, ";
+			$sql .= "phone_label, ";
 			$sql .= "phone_number, ";
 			$sql .= "phone_extension, ";
+			$sql .= "phone_primary, ";
 			$sql .= "phone_description ";
 			$sql .= ")";
 			$sql .= "values ";
 			$sql .= "(";
-			$sql .= "'$domain_uuid', ";
-			$sql .= "'$contact_uuid', ";
-			$sql .= "'$contact_phone_uuid', ";
-			$sql .= "'$phone_type', ";
-			$sql .= "'$phone_number', ";
-			$sql .= "'$phone_extension', ";
-			$sql .= "'$phone_description' ";
+			$sql .= "'".$domain_uuid."', ";
+			$sql .= "'".$contact_uuid."', ";
+			$sql .= "'".$contact_phone_uuid."', ";
+			$sql .= (($phone_type_voice) ? 1 : 'null').", ";
+			$sql .= (($phone_type_fax) ? 1 : 'null').", ";
+			$sql .= (($phone_type_video) ? 1 : 'null').", ";
+			$sql .= (($phone_type_text) ? 1 : 'null').", ";
+			$sql .= "'".$phone_label."', ";
+			$sql .= "'".$phone_number."', ";
+			$sql .= "'".$phone_extension."', ";
+			$sql .= (($phone_primary) ? 1 : 0).", ";
+			$sql .= "'".$phone_description."' ";
 			$sql .= ")";
 			$db->exec(check_sql($sql));
 			unset($sql);
@@ -122,12 +149,17 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		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 .= "phone_extension = '$phone_extension', ";
-			$sql .= "phone_description = '$phone_description' ";
-			$sql .= "where domain_uuid = '$domain_uuid'";
-			$sql .= "and contact_phone_uuid = '$contact_phone_uuid'";
+			$sql .= "phone_type_voice = ".(($phone_type_voice) ? 1 : 'null').", ";
+			$sql .= "phone_type_fax = ".(($phone_type_fax) ? 1 : 'null').", ";
+			$sql .= "phone_type_video = ".(($phone_type_video) ? 1 : 'null').", ";
+			$sql .= "phone_type_text = ".(($phone_type_text) ? 1 : 'null').", ";
+			$sql .= "phone_label = '".$phone_label."', ";
+			$sql .= "phone_number = '".$phone_number."', ";
+			$sql .= "phone_extension = '".$phone_extension."', ";
+			$sql .= "phone_primary = ".(($phone_primary) ? 1 : 0).", ";
+			$sql .= "phone_description = '".$phone_description."' ";
+			$sql .= "where domain_uuid = '".$domain_uuid."' ";
+			$sql .= "and contact_phone_uuid = '".$contact_phone_uuid."'";
 			$db->exec(check_sql($sql));
 			unset($sql);
 
@@ -148,9 +180,14 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		$prep_statement->execute();
 		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
 		foreach ($result as &$row) {
-			$phone_type = $row["phone_type"];
+			$phone_type_voice = $row["phone_type_voice"];
+			$phone_type_fax = $row["phone_type_fax"];
+			$phone_type_video = $row["phone_type_video"];
+			$phone_type_text = $row["phone_type_text"];
+			$phone_label = $row["phone_label"];
 			$phone_number = $row["phone_number"];
 			$phone_extension = $row["phone_extension"];
+			$phone_primary = $row["phone_primary"];
 			$phone_description = $row["phone_description"];
 		}
 		unset ($prep_statement);
@@ -165,18 +202,22 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		$document['title'] = $text['title-contact_phones-add'];
 	}
 
-//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>";
+//javascript to toggle input/select boxes
+	echo "<script type='text/javascript'>\n";
+	echo "	function toggle_custom(field) {\n";
+	echo "		$('#'+field).toggle();\n";
+	echo "		document.getElementById(field).selectedIndex = 0;\n";
+	echo "		document.getElementById(field+'_custom').value = '';\n";
+	echo "		$('#'+field+'_custom').toggle();\n";
+	echo "		if ($('#'+field+'_custom').is(':visible')) { $('#'+field+'_custom').focus(); } else { $('#'+field).focus(); }\n";
+	echo "	}";
+	echo "</script>";
 
+//show the content
 	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 "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td align='left' width='30%' nowrap='nowrap'><b>";
+	echo "<td align='left' valign='top' nowrap='nowrap'><b>";
 	if ($action == "update") {
 		echo $text['header-contact_phones-edit'];
 	}
@@ -184,136 +225,63 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 		echo $text['header-contact_phones-add'];
 	}
 	echo "</b></td>\n";
-	echo "<td width='70%' align='right'>";
+	echo "<td align='right' valign='top'>";
 	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=$contact_uuid'\" value='".$text['button-back']."'>";
 	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
+	echo "<br>\n";
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td align='left' colspan='2'>\n";
+	echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-phone_label']."\n";
+	echo "</td>\n";
+	echo "<td width='70%' class='vtable' align='left'>\n";
+	if (is_array($_SESSION["contact"]["phone_label"])) {
+		sort($_SESSION["contact"]["phone_label"]);
+		foreach($_SESSION["contact"]["phone_label"] as $row) {
+			$phone_label_options[] = "<option value='".$row."' ".(($row == $phone_label) ? "selected='selected'" : null).">".$row."</option>";
+		}
+		$phone_label_found = (in_array($phone_label, $_SESSION["contact"]["phone_label"])) ? true : false;
+	}
+	else {
+		$selected[$phone_label] = "selected";
+		$default_labels[] = $text['option-work'];
+		$default_labels[] = $text['option-home'];
+		$default_labels[] = $text['option-mobile'];
+		$default_labels[] = $text['option-main'];
+		$default_labels[] = $text['option-fax'];
+		$default_labels[] = $text['option-pager'];
+		$default_labels[] = $text['option-voicemail'];
+		$default_labels[] = $text['option-text'];
+		$default_labels[] = $text['option-other'];
+		foreach ($default_labels as $default_label) {
+			$phone_label_options[] = "<option value='".$default_label."' ".$selected[$default_label].">".$default_label."</option>";
+		}
+		$phone_label_found = (in_array($phone_label, $default_labels)) ? true : false;
+	}
+	echo "	<select class='formfld' ".((!$phone_label_found && $phone_label != '') ? "style='display: none;'" : null)." name='phone_label' id='phone_label' onchange=\"getElementById('phone_label_custom').value='';\">\n";
+	echo "		<option value=''></option>\n";
+	echo 		(is_array($phone_label_options)) ? implode("\n", $phone_label_options) : null;
+	echo "	</select>\n";
+	echo "	<input type='text' class='formfld' ".(($phone_label_found || $phone_label == '') ? "style='display: none;'" : null)." name='phone_label_custom' id='phone_label_custom' value=\"".((!$phone_label_found) ? htmlentities($phone_label) : null)."\">\n";
+	echo "	<input type='button' id='btn_toggle_type' class='btn' alt='".$text['button-back']."' value='&#9665;' onclick=\"toggle_custom('phone_label');\">\n";
+	echo "<br />\n";
+	echo $text['description-phone_label']."\n";
 	echo "</td>\n";
 	echo "</tr>\n";
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-phone_type'].":\n";
+	echo "	".$text['label-phone_type']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' align='left'>\n";
-	if (is_array($_SESSION["contact"]["phone_type"])) {
-		sort($_SESSION["contact"]["phone_type"]);
-		echo "	<select class='formfld' style='width:85%;' name='phone_type'>\n";
-		echo "	<option value=''></option>\n";
-		foreach($_SESSION["contact"]["phone_type"] as $row) {
-			if ($row == $phone_type) {
-				echo "	<option value='".$row."' selected='selected'>".$row."</option>\n";
-			}
-			else {
-				echo "	<option value='".$row."'>".$row."</option>\n";
-			}
-		}
-		echo "	</select>\n";
-	}
-	else {
-		echo "	<select class='formfld' name='phone_type'>\n";
-		echo "	<option value=''></option>\n";
-		if ($phone_type == "home") {
-			echo "	<option value='home' selected='selected'>Home</option>\n";
-		}
-		else {
-			echo "	<option value='home'>Home</option>\n";
-		}
-		if ($phone_type == "work") {
-			echo "	<option value='work' selected='selected'>Work</option>\n";
-		}
-		else {
-			echo "	<option value='work'>Work</option>\n";
-		}
-		if ($phone_type == "pref") {
-			echo "	<option value='pref' selected='selected'>Pref</option>\n";
-		}
-		else {
-			echo "	<option value='pref'>Pref</option>\n";
-		}
-		if ($phone_type == "voice") {
-			echo "	<option value='voice' selected='selected'>Voice</option>\n";
-		}
-		else {
-			echo "	<option value='voice'>Voice</option>\n";
-		}
-		if ($phone_type == "fax") {
-			echo "	<option value='fax' selected='selected'>Fax</option>\n";
-		}
-		else {
-			echo "	<option value='fax'>Fax</option>\n";
-		}
-		if ($phone_type == "msg") {
-			echo "	<option value='msg' selected='selected'>MSG</option>\n";
-		}
-		else {
-			echo "	<option value='msg'>MSG</option>\n";
-		}
-		if ($phone_type == "cell") {
-			echo "	<option value='cell' selected='selected'>Cell</option>\n";
-		}
-		else {
-			echo "	<option value='cell'>Cell</option>\n";
-		}
-		if ($phone_type == "pager") {
-			echo "	<option value='pager' selected='selected'>Pager</option>\n";
-		}
-		else {
-			echo "	<option value='pager'>Pager</option>\n";
-		}
-		if ($phone_type == "bbs") {
-			echo "	<option value='bbs' selected='selected'>BBS</option>\n";
-		}
-		else {
-			echo "	<option value='bbs'>BBS</option>\n";
-		}
-		if ($phone_type == "modem") {
-			echo "	<option value='modem' selected='selected'>Modem</option>\n";
-		}
-		else {
-			echo "	<option value='modem'>Modem</option>\n";
-		}
-		if ($phone_type == "car") {
-			echo "	<option value='car' selected='selected'>Car</option>\n";
-		}
-		else {
-			echo "	<option value='car'>Car</option>\n";
-		}
-		if ($phone_type == "isdn") {
-			echo "	<option value='isdn' selected='selected'>ISDN</option>\n";
-		}
-		else {
-			echo "	<option value='isdn'>ISDN</option>\n";
-		}
-		if ($phone_type == "video") {
-			echo "	<option value='video' selected='selected'>Video</option>\n";
-		}
-		else {
-			echo "	<option value='video'>Video</option>\n";
-		}
-		if ($phone_type == "pcs") {
-			echo "	<option value='pcs' selected='selected'>PCS</option>\n";
-		}
-		else {
-			echo "	<option value='pcs'>PCS</option>\n";
-		}
-		if ($phone_type == "iana-token") {
-			echo "	<option value='iana-token' selected='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='selected'>x-name</option>\n";
-		}
-		else {
-			echo "	<option value='x-name'>x-name</option>\n";
-		}
-		echo "	</select>\n";
-	}
+	echo "	<input type='checkbox' name='phone_type_voice' id='phone_type_voice' value='1' ".(($phone_type_voice) ? "checked='checked'" : null)."><label for='phone_type_voice'>&nbsp;".$text['label-voice']."</label>&nbsp;\n";
+	echo "	<input type='checkbox' name='phone_type_fax' id='phone_type_fax' value='1' ".(($phone_type_fax) ? "checked='checked'" : null)."><label for='phone_type_fax'>&nbsp;".$text['label-fax']."</label>&nbsp;\n";
+	echo "	<input type='checkbox' name='phone_type_video' id='phone_type_video' value='1' ".(($phone_type_video) ? "checked='checked'" : null)."><label for='phone_type_video'>&nbsp;".$text['label-video']."</label>&nbsp;\n";
+	echo "	<input type='checkbox' name='phone_type_text' id='phone_type_text' value='1' ".(($phone_type_text) ? "checked='checked'" : null)."><label for='phone_type_text'>&nbsp;".$text['label-text']."</label>\n";
 	echo "<br />\n";
 	echo $text['description-phone_type']."\n";
 	echo "</td>\n";
@@ -321,7 +289,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-phone_number'].":\n";
+	echo "	".$text['label-phone_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";
@@ -332,7 +300,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-phone_extension'].":\n";
+	echo "	".$text['label-phone_extension']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' align='left'>\n";
 	echo "	<input class='formfld' type='text' name='phone_extension' maxlength='255' value=\"$phone_extension\">\n";
@@ -343,7 +311,21 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "<tr>\n";
 	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-	echo "	".$text['label-phone_description'].":\n";
+	echo "	".$text['label-primary']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='phone_primary' id='phone_primary'>\n";
+	echo "		<option value='0'>".$text['option-false']."</option>\n";
+	echo "		<option value='1' ".(($phone_primary) ? "selected" : null).">".$text['option-true']."</option>\n";
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo $text['description-phone_primary']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-phone_description']."\n";
 	echo "</td>\n";
 	echo "<td class='vtable' align='left'>\n";
 	echo "	<input class='formfld' type='text' name='phone_description' maxlength='255' value=\"$phone_description\">\n";
@@ -354,6 +336,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 
 	echo "	<tr>\n";
 	echo "		<td colspan='2' align='right'>\n";
+	echo "				<br>\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";
@@ -364,11 +347,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
 	echo "</table>";
 	echo "</form>";
 
-	echo "	</td>";
-	echo "	</tr>";
-	echo "</table>";
-	echo "</div>";
-
 //include the footer
 	require_once "resources/footer.php";
 ?>

+ 52 - 39
contact_phones.php

@@ -38,8 +38,8 @@ else {
 require_once "resources/paging.php";
 
 //get variables used to control the order
-	$order_by = $_GET["order_by"];
-	$order = $_GET["order"];
+// 	$order_by = $_GET["order_by"];
+// 	$order = $_GET["order"];
 
 //javascript function: send_cmd
 	echo "<script type=\"text/javascript\">\n";
@@ -66,36 +66,37 @@ require_once "resources/paging.php";
 	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';
-			}
-		}
+// 		$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;
+// 		$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 ";
+		$sql .= "where domain_uuid = '$domain_uuid' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$sql .= "order by phone_primary desc, phone_label asc ";
+// 		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);
@@ -109,10 +110,11 @@ require_once "resources/paging.php";
 	echo "<div align='center'>\n";
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo th_order_by('phone_type', $text['label-phone_type'], $order_by, $order);
-	echo th_order_by('phone_number', $text['label-phone_number'], $order_by, $order);
+	echo "<th>".$text['label-phone_label']."</th>\n";
+	echo "<th>".$text['label-phone_number']."</th>\n";
+	echo "<th>".$text['label-phone_type']."</th>\n";
 	echo "<th>".$text['label-phone_tools']."</th>\n";
-	echo th_order_by('phone_description', $text['label-phone_description'], $order_by, $order);
+	echo "<th>".$text['label-phone_description']."</th>\n";
 	echo "<td class='list_control_icons'>";
 	echo 	"<a href='contact_phone_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
 	echo "</td>\n";
@@ -120,17 +122,28 @@ require_once "resources/paging.php";
 	if ($result_count > 0) {
 		foreach($result as $row) {
 			$tr_link = "href='contact_phone_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_phone_uuid']."'";
-			echo "<tr ".$tr_link.">\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>".ucwords($row['phone_type'])."&nbsp;</td>\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>\n";
+			echo "<tr ".$tr_link." ".(($row['phone_primary']) ? "style='font-weight: bold;'" : null).">\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".(($row['phone_label'] == strtolower($row['phone_label'])) ? ucwords($row['phone_label']) : $row['phone_label'])."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]." tr_link_void'>\n";
 			echo "		<a href=\"javascript:void(0)\" onclick=\"send_cmd('".PROJECT_PATH."/app/click_to_call/click_to_call.php?src_cid_name=".urlencode($row['phone_number'])."&src_cid_number=".urlencode($row['phone_number'])."&dest_cid_name=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_name'])."&dest_cid_number=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_number'])."&src=".urlencode($_SESSION['user']['extension'][0]['user'])."&dest=".urlencode($row['phone_number'])."&rec=false&ringback=us-ring&auto_answer=true');\">\n";
 			echo "		".format_phone($row['phone_number'])."</a>&nbsp;\n";
 			echo "	</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>\n";
+			if ($row['phone_type_voice']) { $phone_types[] = $text['label-voice']; }
+			if ($row['phone_type_fax']) { $phone_types[] = $text['label-fax']; }
+			if ($row['phone_type_video']) { $phone_types[] = $text['label-video']; }
+			if ($row['phone_type_text']) { $phone_types[] = $text['label-text']; }
+			if (is_array($phone_types)) {
+				echo "	".implode(", ", $phone_types)."\n";
+			}
+			unset($phone_types);
+			echo "	</td>\n";
 			echo "	<td valign='top' class='".$row_style[$c]." tr_link_void' nowrap='nowrap'>\n";
-			echo "		<a href=\"javascript:void(0)\" onclick=\"send_cmd('".PROJECT_PATH."/app/click_to_call/click_to_call.php?src_cid_name=".urlencode($row['phone_number'])."&src_cid_number=".urlencode($row['phone_number'])."&dest_cid_name=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_name'])."&dest_cid_number=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_number'])."&src=".urlencode($_SESSION['user']['extension'][0]['user'])."&dest=".urlencode($row['phone_number'])."&rec=false&ringback=us-ring&auto_answer=true');\">".$text['label-phone_call']."</a>\n";
-			echo "		&nbsp;\n";
 			echo "		<a href=\"".PROJECT_PATH."/app/xml_cdr/xml_cdr.php?caller_id_number=".$row['phone_number']."&destination_number=".$row['phone_number']."\">CDR</a>\n";
-			echo "		&nbsp;\n";
+			if ($row['phone_type_voice']) {
+				echo "		&nbsp;\n";
+				echo "		<a href=\"javascript:void(0)\" onclick=\"send_cmd('".PROJECT_PATH."/app/click_to_call/click_to_call.php?src_cid_name=".urlencode($row['phone_number'])."&src_cid_number=".urlencode($row['phone_number'])."&dest_cid_name=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_name'])."&dest_cid_number=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_number'])."&src=".urlencode($_SESSION['user']['extension'][0]['user'])."&dest=".urlencode($row['phone_number'])."&rec=false&ringback=us-ring&auto_answer=true');\">".$text['label-phone_call']."</a>\n";
+			}
 			echo "	</td>\n";
 			echo "	<td valign='top' class='row_stylebg'>".$row['phone_description']."&nbsp;</td>\n";
 			echo "	<td class='list_control_icons'>";
@@ -144,11 +157,11 @@ require_once "resources/paging.php";
 	} //end if results
 
 	echo "<tr>\n";
-	echo "<td colspan='5' align='left'>\n";
+	echo "<td colspan='6' 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%' nowrap>&nbsp;</td>\n";
+//	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
 	echo "		<td class='list_control_icons'>";
 	echo 			"<a href='contact_phone_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
 	echo "		</td>\n";

+ 6 - 6
contact_setting_delete.php

@@ -42,12 +42,12 @@ require_once "resources/check_auth.php";
 
 //delete domain_setting
 	if (strlen($id) > 0) {
-			$sql = "delete from v_contact_settings ";
-			$sql .= "where contact_uuid = '$contact_uuid' ";
-			$sql .= "and contact_setting_uuid = '$id' ";
-			$prep_statement = $db->prepare(check_sql($sql));
-			$prep_statement->execute();
-			unset($sql);
+		$sql = "delete from v_contact_settings ";
+		$sql .= "where contact_uuid = '$contact_uuid' ";
+		$sql .= "and contact_setting_uuid = '$id' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		unset($sql);
 	}
 
 //redirect the user

+ 3 - 15
contact_setting_edit.php

@@ -185,17 +185,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
 	}
 
 //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 "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
-	echo "<td align='left' width='30%' nowrap='nowrap'><b>";
+	echo "<td valign='top' align='left' width='30%' nowrap='nowrap'><b>";
 	if ($action == "update") {
 		echo $text['header-contact_setting-edit'];
 	}
@@ -203,7 +196,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
 		echo $text['header-contact_setting_add'];
 	}
 	echo "</b></td>\n";
-	echo "<td width='70%' align='right'>";
+	echo "<td valign='top' width='70%' align='right'>";
 	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=$contact_uuid'\" value='".$text['button-back']."'>";
 	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
 	echo "</td>\n";
@@ -342,11 +335,6 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
 	echo "</table>";
 	echo "</form>";
 
-	echo "	</td>";
-	echo "	</tr>";
-	echo "</table>";
-	echo "</div>";
-
 //include the footer
 	require_once "resources/footer.php";
 ?>

+ 53 - 59
contact_settings.php

@@ -27,7 +27,6 @@
 require_once "root.php";
 require_once "resources/require.php";
 require_once "resources/check_auth.php";
-//require_once "resources/header.php";
 require_once "resources/paging.php";
 
 //get variables used to control the order
@@ -35,40 +34,43 @@ require_once "resources/paging.php";
 	$order = check_str($_GET["order"]);
 
 //prepare to page the results
-	$sql = "select count(*) as num_rows from v_contact_settings ";
-	$sql .= "where 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';
-		}
-	}
+// 	$sql = "select count(*) as num_rows from v_contact_settings ";
+// 	$sql .= "where 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 = 100;
-	$param = "";
-	$page = $_GET['page'];
-	if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
-	list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
-	$offset = $rows_per_page * $page;
+// 	$rows_per_page = 2;
+// 	$param = "";
+// 	$page = $_GET['page'];
+// 	if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
+// 	list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
+// 	$offset = $rows_per_page * $page;
 
 //get the list
 	$sql = "select * from v_contact_settings ";
 	$sql .= "where domain_uuid = '$domain_uuid' ";
 	$sql .= "and contact_uuid = '$contact_uuid' ";
 	if (strlen($order_by) == 0) {
-		$sql .= "order by contact_setting_category, contact_setting_subcategory, contact_setting_order asc ";
+		$sql .= "order by ";
+		$sql .= "contact_setting_category asc ";
+		$sql .= ", contact_setting_subcategory asc ";
+		$sql .= ", contact_setting_order asc ";
 	}
 	else {
-		$sql .= "order by $order_by $order ";
+		$sql .= "order by ".$order_by." ".$order." ";
 	}
-	$sql .= "limit $rows_per_page offset $offset ";
+//	$sql .= "limit ".$rows_per_page." offset ".$offset." ";
 	$prep_statement = $db->prepare(check_sql($sql));
 	$prep_statement->execute();
 	$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
@@ -80,45 +82,37 @@ require_once "resources/paging.php";
 	$row_style["1"] = "row_style1";
 
 //show the content
-	if ($num_rows == 0) {
-		echo "<table width='100%' border='0'>\n";
-		echo "<tr>\n";
-		echo "<td width='50%' align='left' nowrap='nowrap'><b>".$text['label-contact_settings']."</b></td>\n";
-		echo "<td width='50%' align='right'>&nbsp;</td>\n";
-		echo "</tr>\n";
-		echo "</table>\n";
-	}
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>".$text['label-contact_settings']."</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
 
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>";
+	echo "	<td colspan='6' align='left'>\n";
+	echo "		<b>".ucfirst($row['contact_setting_category'])."</b>\n";
+	echo "	</td>\n";
+	echo "</tr>\n";
+	echo "<tr>\n";
+	echo "<th>".$text['label-contact_category']."</th>";
+	echo "<th>".$text['label-contact_subcategory']."</th>";
+	echo "<th>".$text['label-contact_type']."</th>";
+	echo "<th>".$text['label-contact_value']."</th>";
+	echo "<th style='text-align: center;'>".$text['label-enabled']."</th>";
+	echo "<th>".$text['label-description']."</th>";
+	echo "<td class='list_control_icons'>";
+	echo 	"<a href='contact_setting_edit.php?contact_uuid=".$contact_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "</td>\n";
+	echo "</tr>\n";
 	if ($result_count > 0) {
 		$previous_category = '';
 		foreach($result as $row) {
-			if ($previous_category != $row['contact_setting_category']) {
-				echo "<tr>";
-				echo "	<td colspan='6' align='left'>\n";
-				echo "		<br />\n";
-				echo "		<br />\n";
-				echo "		<b>";
-				echo "		".ucfirst($row['contact_setting_category']);
-				echo "		</b>\n";
-				echo "	</td>\n";
-				echo "</tr>\n";
-				echo "<tr>\n";
-				echo "<th>".$text['label-contact_subcategory']."</th>";
-				echo "<th>".$text['label-contact_type']."</th>";
-				echo "<th>".$text['label-contact_value']."</th>";
-				echo "<th style='text-align: center;'>".$text['label-enabled']."</th>";
-				echo "<th>".$text['label-description']."</th>";
-				echo "<td class='list_control_icons'>";
-				echo "<a href='contact_setting_edit.php?contact_uuid=".$contact_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>";
-				echo "</td>\n";
-				echo "</tr>\n";
-			}
 			$tr_link = " href='contact_setting_edit.php?contact_uuid=".$contact_uuid."&id=".$row['contact_setting_uuid']."'";
 			echo "<tr ".$tr_link.">\n";
-			echo "	<td valign='top' class='".$row_style[$c]."'>";
-			echo 	"<a href='contact_setting_edit.php?contact_uuid=".$contact_uuid."&id=".$row['contact_setting_uuid']."'>".$row['contact_setting_subcategory']."</a>";
-			echo "	</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_setting_category']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'><a href='contact_setting_edit.php?contact_uuid=".$contact_uuid."&id=".$row['contact_setting_uuid']."'>".$row['contact_setting_subcategory']."</a></td>\n";
 			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['contact_setting_name']."&nbsp;</td>\n";
 			echo "	<td valign='top' class='".$row_style[$c]."'>\n";
 
@@ -149,11 +143,11 @@ require_once "resources/paging.php";
 	} //end if results
 
 	echo "<tr>\n";
-	echo "<td colspan='6' align='left'>\n";
+	echo "<td colspan='7' 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%' nowrap>&nbsp;</td>\n";
+//	echo "		<td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
 	echo "		<td class='list_control_icons'>";
 	echo 		"<a href='contact_setting_edit.php?contact_uuid=".$contact_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>";
 	echo "		</td>\n";

+ 63 - 0
contact_url_delete.php

@@ -0,0 +1,63 @@
+<?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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_delete')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//add multi-lingual support
+	require_once "app_languages.php";
+	foreach($text as $key => $value) {
+		$text[$key] = $value[$_SESSION['domain']['language']['code']];
+	}
+
+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_urls ";
+	$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+	$sql .= "and contact_url_uuid = '".$id."' ";
+
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	unset($sql);
+}
+
+$_SESSION["message"] = $text['message-delete'];
+header("Location: contact_edit.php?id=".$contact_uuid);
+return;
+
+?>

+ 301 - 0
contact_url_edit.php

@@ -0,0 +1,301 @@
+<?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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_edit')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//add multi-lingual support
+	require_once "app_languages.php";
+	foreach($text as $key => $value) {
+		$text[$key] = $value[$_SESSION['domain']['language']['code']];
+	}
+
+//action add or update
+	if (isset($_REQUEST["id"])) {
+		$action = "update";
+		$contact_url_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) {
+		$url_label = check_str($_POST["url_label"]);
+		$url_label_custom = check_str($_POST["url_label_custom"]);
+		$url_address = check_str($_POST["url_address"]);
+		$url_primary = check_str($_POST["url_primary"]);
+		$url_description = check_str($_POST["url_description"]);
+
+		//use custom label if set
+		$url_label = ($url_label_custom != '') ? $url_label_custom : $url_label;
+	}
+
+if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
+
+	$msg = '';
+	if ($action == "update") {
+		$contact_url_uuid = check_str($_POST["contact_url_uuid"]);
+	}
+
+	//check for all required data
+		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
+			require_once "resources/header.php";
+			require_once "resources/persist_form_var.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 "resources/footer.php";
+			return;
+		}
+
+	//add or update the database
+	if ($_POST["persistformvar"] != "true") {
+
+		//if primary, unmark other primary numbers
+		if ($url_primary) {
+			$sql = "update v_contact_urls set url_primary = 0 ";
+			$sql .= "where domain_uuid = '".$domain_uuid."' ";
+			$sql .= "and contact_uuid = '".$contact_uuid."' ";
+			$db->exec(check_sql($sql));
+			unset($sql);
+		}
+
+		if ($action == "add") {
+			$contact_url_uuid = uuid();
+			$sql = "insert into v_contact_urls ";
+			$sql .= "(";
+			$sql .= "domain_uuid, ";
+			$sql .= "contact_uuid, ";
+			$sql .= "contact_url_uuid, ";
+			$sql .= "url_label, ";
+			$sql .= "url_address, ";
+			$sql .= "url_primary, ";
+			$sql .= "url_description ";
+			$sql .= ")";
+			$sql .= "values ";
+			$sql .= "(";
+			$sql .= "'".$_SESSION['domain_uuid']."', ";
+			$sql .= "'".$contact_uuid."', ";
+			$sql .= "'".$contact_url_uuid."', ";
+			$sql .= "'".$url_label."', ";
+			$sql .= "'".$url_address."', ";
+			$sql .= (($url_primary) ? 1 : 0).", ";
+			$sql .= "'".$url_description."' ";
+			$sql .= ")";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			$_SESSION["message"] = $text['message-add'];
+			header("Location: contact_edit.php?id=".$contact_uuid);
+			return;
+		} //if ($action == "add")
+
+		if ($action == "update") {
+			$sql = "update v_contact_urls set ";
+			$sql .= "contact_uuid = '".$contact_uuid."', ";
+			$sql .= "url_label = '".$url_label."', ";
+			$sql .= "url_address = '".$url_address."', ";
+			$sql .= "url_primary = ".(($url_primary) ? 1 : 0).", ";
+			$sql .= "url_description = '".$url_description."' ";
+			$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+			$sql .= "and contact_url_uuid = '".$contact_url_uuid."'";
+			$db->exec(check_sql($sql));
+			unset($sql);
+
+			$_SESSION["message"] = $text['message-update'];
+			header("Location: contact_edit.php?id=".$contact_uuid);
+			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_url_uuid = $_GET["id"];
+		$sql = "select * from v_contact_urls ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_url_uuid = '".$contact_url_uuid."' ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$url_label = $row["url_label"];
+			$url_address = $row["url_address"];
+			$url_primary = $row["url_primary"];
+			$url_description = $row["url_description"];
+			break; //limit to 1 row
+		}
+		unset ($prep_statement);
+	}
+
+//show the header
+	require_once "resources/header.php";
+	if ($action == "update") {
+		$document['title'] = $text['title-contact_url-edit'];
+	}
+	else if ($action == "add") {
+		$document['title'] = $text['title-contact_url-add'];
+	}
+
+//javascript to toggle input/select boxes
+	echo "<script type='text/javascript'>";
+	echo "	function toggle_custom(field) {";
+	echo "		$('#'+field).toggle();";
+	echo "		document.getElementById(field).selectedIndex = 0;";
+	echo "		document.getElementById(field+'_custom').value = '';";
+	echo "		$('#'+field+'_custom').toggle();";
+	echo "		if ($('#'+field+'_custom').is(':visible')) { $('#'+field+'_custom').focus(); } else { $('#'+field).focus(); }";
+	echo "	}";
+	echo "</script>";
+
+//show the content
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "<td align='left' valign='top' nowrap='nowrap'><b>";
+	if ($action == "update") {
+		echo $text['header-contact_url-edit'];
+	}
+	else if ($action == "add") {
+		echo $text['header-contact_url-add'];
+	}
+	echo "</b></td>\n";
+	echo "<td align='right' valign='top'>";
+	echo "	<input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=".$contact_uuid."'\" value='".$text['button-back']."'>";
+	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	if ($action == "update") {
+		echo $text['description-contact_url-edit'];
+	}
+	else if ($action == "add") {
+		echo $text['description-contact_url-add'];
+	}
+	echo "<br /><br />\n";
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-url_label']."\n";
+	echo "</td>\n";
+	echo "<td width='70%' class='vtable' align='left'>\n";
+	if (is_array($_SESSION["contact"]["url_label"])) {
+		sort($_SESSION["contact"]["url_label"]);
+		foreach($_SESSION["contact"]["url_label"] as $row) {
+			$url_label_options[] = "<option value='".$row."' ".(($row == $url_label) ? "selected='selected'" : null).">".$row."</option>";
+		}
+		$url_label_found = (in_array($url_label, $_SESSION["contact"]["url_label"])) ? true : false;
+	}
+	else {
+		$selected[$url_label] = "selected";
+		$default_labels[] = $text['option-work'];
+		$default_labels[] = $text['option-personal'];
+		$default_labels[] = $text['option-other'];
+		foreach ($default_labels as $default_label) {
+			$url_label_options[] = "<option value='".$default_label."' ".$selected[$default_label].">".$default_label."</option>";
+		}
+		$url_label_found = (in_array($url_label, $default_labels)) ? true : false;
+	}
+	echo "	<select class='formfld' ".((!$url_label_found && $url_label != '') ? "style='display: none;'" : null)." name='url_label' id='url_label' onchange=\"getElementById('url_label_custom').value='';\">\n";
+	echo "		<option value=''></option>\n";
+	echo 		(is_array($url_label_options)) ? implode("\n", $url_label_options) : null;
+	echo "	</select>\n";
+	echo "	<input type='text' class='formfld' ".(($url_label_found || $url_label == '') ? "style='display: none;'" : null)." name='url_label_custom' id='url_label_custom' value=\"".((!$url_label_found) ? htmlentities($url_label) : null)."\">\n";
+	echo "	<input type='button' id='btn_toggle_label' class='btn' alt='".$text['button-back']."' value='&#9665;' onclick=\"toggle_custom('url_label');\">\n";
+	echo "<br />\n";
+	echo $text['description-url_label']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-url_address']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='url_address' maxlength='255' value=\"".$url_address."\" placeholder='http://...'>\n";
+	echo "<br />\n";
+	echo $text['description-url_address']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-primary']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select class='formfld' name='url_primary' id='url_primary'>\n";
+	echo "		<option value='0'>".$text['option-false']."</option>\n";
+	echo "		<option value='1' ".(($url_primary) ? "selected" : null).">".$text['option-true']."</option>\n";
+	echo "	</select>\n";
+	echo "<br />\n";
+	echo $text['description-url_primary']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	".$text['label-url_description']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='url_description' maxlength='255' value=\"".$url_description."\">\n";
+	echo "<br />\n";
+	echo $text['description-url_description']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "			<br>\n";
+	echo "			<input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
+	if ($action == "update") {
+		echo "		<input type='hidden' name='contact_url_uuid' value='".$contact_url_uuid."'>\n";
+	}
+	echo "			<input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
+	echo "		</td>\n";
+	echo "	</tr>";
+	echo "</table>";
+	echo "</form>";
+
+//include the footer
+	require_once "resources/footer.php";
+?>

+ 138 - 0
contact_urls.php

@@ -0,0 +1,138 @@
+<?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 "resources/require.php";
+require_once "resources/check_auth.php";
+if (permission_exists('contact_view')) {
+	//access granted
+}
+else {
+	echo "access denied";
+	exit;
+}
+
+//require_once "resources/header.php";
+require_once "resources/paging.php";
+
+//get variables used to control the order
+// 	$order_by = $_GET["order_by"];
+// 	$order = $_GET["order"];
+
+//show the content
+
+	echo "<table width='100%' border='0'>\n";
+	echo "<tr>\n";
+	echo "<td width='50%' align='left' nowrap='nowrap'><b>".$text['label-urls']."</b></td>\n";
+	echo "<td width='50%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+
+	//prepare to page the results
+// 		$sql = " select count(*) as num_rows from v_contact_urls ";
+// 		$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+// 		$sql .= " and contact_uuid = '$contact_uuid' ";
+// 		$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_urls ";
+		$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
+		$sql .= "and contact_uuid = '$contact_uuid' ";
+		$sql .= "order by url_primary desc, url_label asc ";
+// 		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 "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<th>".$text['label-url_label']."</th>\n";
+	echo "<th>".$text['label-url_address']."</th>\n";
+	echo "<th>".$text['label-url_description']."</th>\n";
+	echo "<td class='list_control_icons'>";
+	echo 	"<a href='contact_url_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	if ($result_count > 0) {
+		foreach($result as $row) {
+			$tr_link = "href='contact_url_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_url_uuid']."'";
+			echo "<tr ".$tr_link." ".(($row['url_primary']) ? "style='font-weight: bold;'" : null).">\n";
+			echo "	<td valign='top' class='".$row_style[$c]."'>".$row['url_label']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='".$row_style[$c]." tr_link_void' style='width: 40%; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'><a href='".$row['url_address']."' target='_blank'>".$row['url_address']."&nbsp;</td>\n";
+			echo "	<td valign='top' class='row_stylebg'>".$row['address_description']."&nbsp;</td>\n";
+			echo "	<td class='list_control_icons'>";
+			echo 		"<a href='contact_url_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_url_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
+			echo 		"<a href='contact_url_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_url_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
+			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 class='list_control_icons'>";
+	echo 			"<a href='contact_url_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>";
+	echo "		</td>\n";
+	echo "	</tr>\n";
+ 	echo "	</table>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+
+?>

+ 1 - 2
contacts.php

@@ -57,7 +57,7 @@ require_once "resources/paging.php";
 	echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
 	echo "	<tr>\n";
 	echo "	<td align=\"left\" valign=\"top\">\n";
-	echo "		<span class='title'><strong>".$text['header-contacts']."</strong></span><br>\n";
+	echo "		<b>".$text['header-contacts']."</b><br>\n";
 	echo "		".$text['description-contacts']."<br /><br />\n";
 	echo "	</td>\n";
 	echo "	<td align=\"right\" valign=\"top\">\n";
@@ -174,7 +174,6 @@ require_once "resources/paging.php";
 	$row_style["0"] = "row_style0";
 	$row_style["1"] = "row_style1";
 
-	echo "<div align='center'>\n";
 	echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo th_order_by('contact_type', $text['label-contact_type'], $order_by, $order);

+ 59 - 19
contacts_vcard.php

@@ -35,6 +35,15 @@ else {
 }
 
 if (count($_GET)>0) {
+
+	//add multi-lingual support
+		if ($_GET['type'] == 'download' || $_GET['type'] == 'html') {
+			require_once "app_languages.php";
+			foreach($text as $key => $value) {
+				$text[$key] = $value[$_SESSION['domain']['language']['code']];
+			}
+		}
+
 	//create the vcard object
 		require_once "resources/classes/vcard.php";
 		$vcard = new vcard();
@@ -43,10 +52,9 @@ if (count($_GET)>0) {
 		$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' ";
+		$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);
@@ -58,8 +66,6 @@ if (count($_GET)>0) {
 			$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
@@ -69,8 +75,36 @@ if (count($_GET)>0) {
 		$vcard->data['company'] = $contact_organization;
 		$vcard->data['first_name'] = $contact_name_given;
 		$vcard->data['last_name'] = $contact_name_family;
-		$vcard->data['email1'] = $contact_email;
-		$vcard->data['url'] = $contact_url;
+
+	//get the contact's primary (and a secondary, if available) email
+		$sql = "select email_address from v_contact_emails ";
+		$sql .= "where domain_uuid = '".$domain_uuid."' ";
+		$sql .= "and contact_uuid = '".$contact_uuid."' ";
+		$sql .= "order by email_primary desc ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		$e = 0;
+		foreach ($result as &$row) {
+			$vcard->data['email'.$e] = $row["email_address"];
+			if (++$e == 2) { break; } //limit to 2 rows
+		}
+		unset ($prep_statement);
+
+	//get the contact's primary url
+		$sql = "select url_address from v_contact_urls ";
+		$sql .= "where domain_uuid = '".$domain_uuid."' ";
+		$sql .= "and contact_uuid = '".$contact_uuid."' ";
+		$sql .= "and url_primary = 1 ";
+		$prep_statement = $db->prepare(check_sql($sql));
+		$prep_statement->execute();
+		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+		foreach ($result as &$row) {
+			$vcard->data['url'] = $row["url_address"];
+			break;	//limit to 1 row
+		}
+		unset ($prep_statement);
+
 
 		if ($_GET['type'] == "image" || $_GET['type'] == "html") {
 			//don't add this to the QR code at this time
@@ -85,17 +119,24 @@ if (count($_GET)>0) {
 		}
 
 	//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' ";
+		$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_label = $row["phone_label"];
 			$phone_number = $row["phone_number"];
-			$vcard->data[$phone_type.'_tel'] = $phone_number;
+			if ($phone_label == $text['option-work']) { $vcard_phone_type = 'work'; }
+			else if ($phone_label == $text['option-home']) { $vcard_phone_type = 'home'; }
+			else if ($phone_label == $text['option-mobile']) { $vcard_phone_type = 'cell'; }
+			else if ($phone_label == $text['option-fax']) { $vcard_phone_type = 'fax'; }
+			else if ($phone_label == $text['option-pager']) { $vcard_phone_type = 'pager'; }
+			else { $vcard_phone_type = 'voice'; }
+			if ($vcard_phone_type != '') {
+				$vcard->data[$vcard_phone_type.'_tel'] = $phone_number;
+			}
 		}
 		unset ($prep_statement);
 
@@ -104,10 +145,9 @@ if (count($_GET)>0) {
 			//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' ";
+			$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);
@@ -138,7 +178,7 @@ if (count($_GET)>0) {
 			$vcard->download();
 		}
 
-	//show the vcard in an text qr code
+	//show the vcard in a text qr code
 		if ($_GET['type'] == "text") {
 			$vcard->build();
 			$content = $vcard->card;

BIN
icon_gmaps.png