Parcourir la source

Contacts - Import: Support multiple numbers per contact and ability to set number label.

Nate il y a 5 ans
Parent
commit
7b02e57723
1 fichiers modifiés avec 37 ajouts et 8 suppressions
  1. 37 8
      contact_import.php

+ 37 - 8
contact_import.php

@@ -172,21 +172,43 @@
 
 
 			echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 			echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
 
 
+			//define phone label options
+			if (is_array($_SESSION["contact"]["phone_label"]) && @sizeof($_SESSION["contact"]["phone_label"]) != 0) {
+				sort($_SESSION["contact"]["phone_label"]);
+				foreach($_SESSION["contact"]["phone_label"] as $row) {
+					$label_options[] = "<option value='".$row.">".$row."</option>";
+				}
+			}
+			else {
+				$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) {
+					$label_options[] = "<option value='".$default_label."'>".$default_label."</option>";
+				}
+			}
+
 			//loop through user columns
 			//loop through user columns
 			$x = 0;
 			$x = 0;
 			foreach ($line_fields as $line_field) {
 			foreach ($line_fields as $line_field) {
 				$line_field = trim(trim($line_field), $enclosure);
 				$line_field = trim(trim($line_field), $enclosure);
 				echo "<tr>\n";
 				echo "<tr>\n";
 				echo "	<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
 				echo "	<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
-				//echo "    ".$text['label-zzz']."\n";
 				echo $line_field;
 				echo $line_field;
 				echo "	</td>\n";
 				echo "	</td>\n";
 				echo "	<td width='70%' class='vtable' align='left'>\n";
 				echo "	<td width='70%' class='vtable' align='left'>\n";
-				echo "		<select class='formfld' style='' name='fields[$x]'>\n";
+				echo "		<select class='formfld' style='' name='fields[$x]' onchange=\"document.getElementById('labels_$x').style.display = this.options[this.selectedIndex].value == 'contact_phones.phone_number' ? 'inline' : 'none';\">\n";
 				echo "			<option value=''></option>\n";
 				echo "			<option value=''></option>\n";
 				foreach($schema as $row) {
 				foreach($schema as $row) {
 					echo "			<optgroup label='".$row['table']."'>\n";
 					echo "			<optgroup label='".$row['table']."'>\n";
 					foreach($row['fields'] as $field) {
 					foreach($row['fields'] as $field) {
+						if ($field == 'phone_label') { continue; }
 						$selected = '';
 						$selected = '';
 						if ($field == $line_field) {
 						if ($field == $line_field) {
 							$selected = "selected='selected'";
 							$selected = "selected='selected'";
@@ -198,8 +220,9 @@
 					echo "			</optgroup>\n";
 					echo "			</optgroup>\n";
 				}
 				}
 				echo "		</select>\n";
 				echo "		</select>\n";
-				//echo "<br />\n";
-				//echo $text['description-zzz']."\n";
+				echo "		<select class='formfld' style='display: none;' id='labels_$x' name='labels[$x]'>\n";
+				echo 			is_array($label_options) ? implode("\n", $label_options) : null;
+				echo "		</select>\n";
 				echo "	</td>\n";
 				echo "	</td>\n";
 				echo "</tr>\n";
 				echo "</tr>\n";
 				$x++;
 				$x++;
@@ -251,8 +274,9 @@
 				exit;
 				exit;
 			}
 			}
 
 
-		//user selected fields
+		//user selected fields, labels
 			$fields = $_POST['fields'];
 			$fields = $_POST['fields'];
+			$labels = $_POST['labels'];
 			
 			
 		//set the domain_uuid
 		//set the domain_uuid
 			$domain_uuid = $_SESSION['domain_uuid'];
 			$domain_uuid = $_SESSION['domain_uuid'];
@@ -312,6 +336,9 @@
 											if ($field_name != "username" && $field_name != "group_name") {
 											if ($field_name != "username" && $field_name != "group_name") {
 												$array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid;
 												$array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid;
 												$array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key];
 												$array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key];
+												if ($field_name == 'phone_number') {
+													$array[$parent][$row_id][$table_name][$y]['phone_label'] = $labels[$key];
+												}
 											}
 											}
 										}
 										}
 	
 	
@@ -337,11 +364,12 @@
 											}
 											}
 										}
 										}
 									}
 									}
+									if (is_array($array[$parent][$row_id])) { $y++; }
 								}
 								}
 	
 	
 							//process a chunk of the array
 							//process a chunk of the array
 								if ($row_id === 1000) {
 								if ($row_id === 1000) {
-	
+
 									//save to the data
 									//save to the data
 										$database = new database;
 										$database = new database;
 										$database->app_name = 'contacts';
 										$database->app_name = 'contacts';
@@ -349,8 +377,8 @@
 										$database->save($array);
 										$database->save($array);
 
 
 									//clear the array
 									//clear the array
-										unset($array);
-										
+ 										unset($array);
+
 									//set the row id back to 0
 									//set the row id back to 0
 										$row_id = 0;
 										$row_id = 0;
 								}
 								}
@@ -359,6 +387,7 @@
 						$row_number++;
 						$row_number++;
 						$row_id++;
 						$row_id++;
 					} //end while
 					} //end while
+
 					fclose($handle);
 					fclose($handle);
 
 
 				//save to the data
 				//save to the data