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

This commit is contained in:
Nate
2020-10-08 15:13:45 -06:00
parent 9207647fbe
commit 55e1e2ea35

View File

@@ -172,21 +172,43 @@
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
$x = 0;
foreach ($line_fields as $line_field) {
$line_field = trim(trim($line_field), $enclosure);
echo "<tr>\n";
echo " <td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
//echo " ".$text['label-zzz']."\n";
echo $line_field;
echo " </td>\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";
foreach($schema as $row) {
echo " <optgroup label='".$row['table']."'>\n";
foreach($row['fields'] as $field) {
if ($field == 'phone_label') { continue; }
$selected = '';
if ($field == $line_field) {
$selected = "selected='selected'";
@@ -198,8 +220,9 @@
echo " </optgroup>\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 "</tr>\n";
$x++;
@@ -251,8 +274,9 @@
exit;
}
//user selected fields
//user selected fields, labels
$fields = $_POST['fields'];
$labels = $_POST['labels'];
//set the domain_uuid
$domain_uuid = $_SESSION['domain_uuid'];
@@ -312,6 +336,9 @@
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][$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
if ($row_id === 1000) {
//save to the data
$database = new database;
$database->app_name = 'contacts';
@@ -349,8 +377,8 @@
$database->save($array);
//clear the array
unset($array);
unset($array);
//set the row id back to 0
$row_id = 0;
}
@@ -359,6 +387,7 @@
$row_number++;
$row_id++;
} //end while
fclose($handle);
//save to the data