diff --git a/app/voicemails/voicemail_imports.php b/app/voicemails/voicemail_imports.php
index 408bcb7e99..627846c94f 100644
--- a/app/voicemails/voicemail_imports.php
+++ b/app/voicemails/voicemail_imports.php
@@ -62,9 +62,21 @@
$delimiter = $_POST["data_delimiter"] ?? '';
$enclosure = $_POST["data_enclosure"] ?? '';
+//get the domain details
+ $domain_uuid = $_SESSION['domain_uuid'];
+ $domain_name = $_SESSION['domain_name'];
+
+//add the settings object
+ $settings = new settings(["domain_uuid" => $domain_uuid]);
+ $switch_voicemail = $settings->get('switch', 'voicemail', '');
+ $temp_dir = $settings->get('server', 'temp', '');
+ $theme_button_icon_back = $settings->get('theme', 'button_icon_back', '');
+ $theme_button_icon_import = $settings->get('theme', 'button_icon_import', '');
+ $theme_button_icon_upload = $settings->get('theme', 'button_icon_upload', '');
+
//save the data to the csv file
if (isset($_POST['data'])) {
- $file = $_SESSION['server']['temp']['dir']."/voicemails-".$_SESSION['domain_name'].".csv";
+ $file = $temp_dir."/voicemails-".$domain_name.".csv";
file_put_contents($file, $_POST['data']);
$_SESSION['file'] = $file;
}
@@ -73,11 +85,11 @@
//$_POST['submit'] == "Upload" &&
if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('voicemail_import')) {
if ($_POST['type'] == 'csv') {
- move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']);
- $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']);
- //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*');
+ move_uploaded_file($_FILES['ulfile']['tmp_name'], $temp_dir.'/'.$_FILES['ulfile']['name']);
+ $save_msg = "Uploaded file to ".$temp_dir."/". htmlentities($_FILES['ulfile']['name']);
+ //system('chmod -R 744 '.$temp_dir.'*');
unset($_POST['txtCommand']);
- $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name'];
+ $file = $temp_dir.'/'.$_FILES['ulfile']['name'];
$_SESSION['file'] = $file;
}
}
@@ -148,8 +160,8 @@
echo "
\n";
echo "
".$text['header-voicemail_import']."
\n";
echo "
\n";
- echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'voicemails.php']);
- echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']);
+ echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$theme_button_icon_back,'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'voicemails.php']);
+ echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$theme_button_icon_import,'id'=>'btn_save']);
echo "
\n";
echo "
\n";
echo "
\n";
@@ -240,9 +252,6 @@
//user selected fields
$fields = $_POST['fields'];
-
- //set the domain_uuid
- $domain_uuid = $_SESSION['domain_uuid'];
//get the contents of the csv file and convert them into an array
$handle = @fopen($_SESSION['file'], "r");
@@ -259,7 +268,7 @@
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];
@@ -267,7 +276,7 @@
//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);
@@ -281,6 +290,11 @@
$result[$key] = strtolower($result[$key]);
}
+ //get the voicemail_id
+ if ($field_name == "voicemail_id") {
+ $voicemail_id = $result[$key];
+ }
+
//build the data array
if (!empty($table_name)) {
if (empty($parent)) {
@@ -294,20 +308,26 @@
}
}
+ //add the voicemail directory if the directory doesn't exist
+ $voicemail_path = $switch_voicemail.'/default/'.$domain_name.'/'.$voicemail_id;
+ if (!file_exists($voicemail_path) && !empty($voicemail_id)) {
+ mkdir($voicemail_path, 0770, false);
+ }
+
//process a chunk of the array
if ($row_id === 1000) {
//save to the data
- $database = new database;
- $database->app_name = 'voicemails';
- $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
- $database->save($array);
+ $database = new database;
+ $database->app_name = 'voicemails';
+ $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
+ $database->save($array);
//clear the array
- unset($array);
+ unset($array);
//set the row id back to 0
- $row_id = 0;
+ $row_id = 0;
}
} //if ($from_row <= $row_number)
@@ -345,8 +365,8 @@
echo "\n";
echo "
".$text['header-voicemail_import']."
\n";
echo "
\n";
- echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'voicemails.php']);
- echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']);
+ echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$theme_button_icon_back,'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'voicemails.php']);
+ echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$theme_button_icon_upload,'id'=>'btn_save']);
echo "
\n";
echo "
\n";
echo "
\n";