diff --git a/app/contacts/contact_import.php b/app/contacts/contact_import.php
index 91eaea2a2f..804c308d69 100644
--- a/app/contacts/contact_import.php
+++ b/app/contacts/contact_import.php
@@ -61,6 +61,7 @@
$action = check_str($_POST["action"]);
$order_by = check_str($_POST["order_by"]);
$order = check_str($_POST["order"]);
+ $from_row = check_str($_POST["from_row"]);
$delimiter = check_str($_POST["data_delimiter"]);
$enclosure = check_str($_POST["data_enclosure"]);
@@ -200,6 +201,7 @@
echo "
\n";
echo " \n";
echo " \n";
+ echo " \n";
echo " \n";
echo " \n";
echo " \n";
@@ -256,93 +258,97 @@
$prep_statement->execute();
$users = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+
//get the contents of the csv file and convert them into an array
$handle = @fopen($_SESSION['file'], "r");
if ($handle) {
- //set the row id
+ //pre-set the numbers
+ $row_number = 1;
$row_id = 0;
-
+
//loop through the array
while (($line = fgets($handle, 4096)) !== false) {
-
- //format the data
- $y = 0;
- foreach ($fields as $key => $value) {
- //get the line
- $result = str_getcsv($line, $delimiter, $enclosure);
-
- //get the table and field name
- $field_array = explode(".",$value);
- $table_name = $field_array[0];
- $field_name = $field_array[1];
- //echo "value: $value \n";
- //echo "table_name: $table_name \n";
- //echo "field_name: $field_name \n";
-
- //get the parent table name
- $parent = get_parent($schema, $table_name);
-
- //remove formatting from the phone number
- // if ($field_name == "phone_number") {
- // $result[$key] = preg_replace('{\D}', '', $result[$key]);
- // }
-
- //build the data array
- if (strlen($table_name) > 0) {
- if (strlen($parent) == 0) {
- $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid;
- $array[$table_name][$row_id][$field_name] = $result[$key];
- }
- else {
- 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 == "group_name") {
- foreach ($groups as $field) {
- if ($field['group_name'] == $result[$key]) {
- //$array[$parent][$row_id]['contact_group_uuid'] = uuid();
- $array[$parent][$row_id]['contact_groups'][$y]['domain_uuid'] = $domain_uuid;
- //$array['contact_groups'][$x]['contact_uuid'] = $row['contact_uuid'];
- $array[$parent][$row_id]['contact_groups'][$y]['group_uuid'] = $field['group_uuid'];
- }
- }
- }
-
- if ($field_name == "username") {
- foreach ($users as $field) {
- if ($field['username'] == $result[$key]) {
- //$array[$parent][$row_id]['contact_users'][$y]['contact_group_uuid'] = uuid();
- $array[$parent][$row_id]['contact_users'][$y]['domain_uuid'] = $domain_uuid;
- //$array['contact_groups'][$x]['contact_uuid'] = $row['contact_uuid'];
- $array[$parent][$row_id]['contact_users'][$y]['user_uuid'] = $field['user_uuid'];
- }
- }
- }
- } //if (strlen($table_name) > 0)
- } //end foreach
-
- //process a chunk of the array
- if ($row_id === 1000) {
-
- //save to the data
- $database = new database;
- $database->app_name = 'contacts';
- $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
- $database->save($array);
- //$message = $database->message;
-
- //clear the array
- unset($array);
+ if ($from_row <= $row_number) {
+ //format the data
+ $y = 0;
+ foreach ($fields as $key => $value) {
+ //get the line
+ $result = str_getcsv($line, $delimiter, $enclosure);
- //set the row id back to 0
- $row_id = 0;
- }
-
- //increment row id
- $row_id++;
+ //get the table and field name
+ $field_array = explode(".",$value);
+ $table_name = $field_array[0];
+ $field_name = $field_array[1];
+ //echo "value: $value \n";
+ //echo "table_name: $table_name \n";
+ //echo "field_name: $field_name \n";
+
+ //get the parent table name
+ $parent = get_parent($schema, $table_name);
+
+ //remove formatting from the phone number
+ // if ($field_name == "phone_number") {
+ // $result[$key] = preg_replace('{\D}', '', $result[$key]);
+ // }
+
+ //build the data array
+ if (strlen($table_name) > 0) {
+ if (strlen($parent) == 0) {
+ $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid;
+ $array[$table_name][$row_id][$field_name] = $result[$key];
+ }
+ else {
+ 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 == "group_name") {
+ foreach ($groups as $field) {
+ if ($field['group_name'] == $result[$key]) {
+ //$array[$parent][$row_id]['contact_group_uuid'] = uuid();
+ $array[$parent][$row_id]['contact_groups'][$y]['domain_uuid'] = $domain_uuid;
+ //$array['contact_groups'][$x]['contact_uuid'] = $row['contact_uuid'];
+ $array[$parent][$row_id]['contact_groups'][$y]['group_uuid'] = $field['group_uuid'];
+ }
+ }
+ }
+
+ if ($field_name == "username") {
+ foreach ($users as $field) {
+ if ($field['username'] == $result[$key]) {
+ //$array[$parent][$row_id]['contact_users'][$y]['contact_group_uuid'] = uuid();
+ $array[$parent][$row_id]['contact_users'][$y]['domain_uuid'] = $domain_uuid;
+ //$array['contact_groups'][$x]['contact_uuid'] = $row['contact_uuid'];
+ $array[$parent][$row_id]['contact_users'][$y]['user_uuid'] = $field['user_uuid'];
+ }
+ }
+ }
+ } //if (strlen($table_name) > 0)
+ } //end foreach
+
+ //process a chunk of the array
+ if ($row_id === 1000) {
+
+ //save to the data
+ $database = new database;
+ $database->app_name = 'contacts';
+ $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
+ $database->save($array);
+ //$message = $database->message;
+
+ //clear the array
+ unset($array);
+
+ //set the row id back to 0
+ $row_id = 0;
+ }
+
+ //increment row id
+ $row_id++;
+ } //if ($from_row <= $row_number)
+ $row_number++;
}
fclose($handle);
@@ -450,6 +456,24 @@
echo " | \n";
echo "
\n";
+ echo "\n";
+ echo "| \n";
+ echo " ".$text['label-from_row']."\n";
+ echo " | \n";
+ echo "\n";
+ echo " \n";
+ echo " \n";
+ echo $text['description-from_row']."\n";
+ echo " | \n";
+ echo "
\n";
+
echo "\n";
echo "| \n";
echo " ".$text['label-import_delimiter']."\n";
|