Przeglądaj źródła

Fax: Upgrade script to generate and store meta-data from existing fax files, fix Lua script to insert correct fax file path into db, JavaScript prompt corrections, adjust redirect after send to use new interface, fix delete so files on file system are removed (using path from db), fix paging and sorting on Inbox and Sent, fix TIF to PDF conversion for viewing sent/received faxes (if PDF version not present).

Nate Jones 10 lat temu
rodzic
commit
787d2427f0
1 zmienionych plików z 197 dodań i 0 usunięć
  1. 197 0
      upgrade/fax_import.php

+ 197 - 0
upgrade/fax_import.php

@@ -0,0 +1,197 @@
+<?php
+//check the permission
+	if (defined('STDIN')) {
+		$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
+		preg_match("/^(.*)\/app\/.*$/", $document_root, $matches);
+		@$document_root = $matches[1];
+		set_include_path($document_root);
+		$_SERVER["DOCUMENT_ROOT"] = $document_root;
+		require_once "resources/require.php";
+		$html = false;
+	}
+	else {
+		include "root.php";
+		require_once "resources/require.php";
+		require_once "resources/pdo.php";
+		require_once "resources/check_auth.php";
+		if (permission_exists('fax_extension_edit')) {
+			//access granted
+		}
+		else {
+			echo "access denied";
+			exit;
+		}
+		$html = true;
+	}
+
+//increase limits
+	set_time_limit(3600);
+	ini_set('memory_limit', '256M');
+	ini_set("precision", 6);
+
+//set pdo attribute that enables exception handling
+	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+//get default storage directory
+	$sql = "select default_setting_value from v_default_settings ";
+	$sql .= "where default_setting_category = 'switch' ";
+	$sql .= "and default_setting_subcategory = 'storage' ";
+	$sql .= "and default_setting_name = 'dir' ";
+	$sql .= "and default_setting_enabled = 'true' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$result = $prep_statement->fetch(PDO::FETCH_ASSOC);
+	$default_storage_folder = $result['default_setting_value'];
+	unset($prep_statement, $sql, $result);
+
+//get domain storage directory
+	$sql = "select domain_uuid, domain_setting_value from v_domain_settings ";
+	$sql .= "where domain_setting_category = 'switch' ";
+	$sql .= "and domain_setting_subcategory = 'storage' ";
+	$sql .= "and domain_setting_name = 'dir' ";
+	$sql .= "and domain_setting_enabled = 'true' ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$results = $prep_statement->fetch(PDO::FETCH_ASSOC);
+	foreach ($results as $index => $row) {
+		$domain_storage_folders[$row['domain_uuid']] = $row['default_setting_value'];
+	}
+	unset($prep_statement, $sql, $results);
+
+//get domains and uuids
+	$sql = "select domain_uuid, domain_name from v_domains ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$results = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+	if (count($results) > 0) {
+		foreach ($results as $row) {
+			$domain_namez[$row['domain_uuid']] = $row['domain_name'];
+		}
+	}
+	unset($prep_statement, $sql, $results);
+
+//get fax extensions and uuids
+	$sql = "select fax_uuid, domain_uuid, fax_extension, fax_caller_id_name, fax_caller_id_number from v_fax ";
+	$prep_statement = $db->prepare(check_sql($sql));
+	$prep_statement->execute();
+	$results = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+	if (count($results) > 0) {
+		foreach ($results as $row) {
+			$fax_extension_uuids[$row['domain_uuid']][$row['fax_extension']] = $row['fax_uuid'];
+			$fax_extension_cid[$row['domain_uuid']][$row['fax_extension']]['name'] = $row['fax_caller_id_name'];
+			$fax_extension_cid[$row['domain_uuid']][$row['fax_extension']]['number'] = $row['fax_caller_id_number'];
+		}
+	}
+	unset($prep_statement, $sql, $results);
+
+//set domain fax storage folder paths to check
+	foreach ($domain_namez as $domain_uuid => $domain_name) {
+		$domain_fax_storage_paths[$domain_uuid] = (($domain_storage_folders[$domain_uuid] != '') ? $domain_storage_folders[$domain_uuid] : $default_storage_folder).'/fax/'.$domain_name;
+	}
+
+//traverse through domain fax storage folders
+	foreach ($domain_fax_storage_paths as $domain_uuid => $domain_fax_storage_path) {
+		if (file_exists($domain_fax_storage_path)) {
+			$domain_fax_file_paths[$domain_uuid] = glob($domain_fax_storage_path.'/*/*/*.tif');
+		}
+	}
+
+//traverse through domain fax file paths
+	foreach ($domain_fax_file_paths as $domain_uuid => $fax_file_paths) {
+		echo "\n\nImporting ".$domain_namez[$domain_uuid]." faxes...".(($html) ? "<br><br>" : null)."\n\n";
+		foreach ($fax_file_paths as $fax_file_path) {
+			$fax_ext_path = str_replace($domain_fax_storage_paths[$domain_uuid].'/', '', $fax_file_path);
+			$tmp_array = explode('/', $fax_ext_path);
+			$fax_ext = $tmp_array[0];
+			$fax_box = $tmp_array[1];
+			$fax_file = $tmp_array[2];
+			if ($fax_box == 'temp') { continue; }
+			else {
+				if ($fax_box == 'inbox') {
+					$record['fax_file_uuid'] = uuid();
+					$record['fax_uuid'] = $fax_extension_uuids[$domain_uuid][$fax_ext];
+					$record['fax_mode'] = 'rx';
+					$record['fax_destination'] = '';
+					$record['fax_file_type'] = substr($fax_file, -3);
+					$record['fax_file_path'] = $fax_file_path;
+					$record['fax_caller_id_name'] = substr($fax_file, 0, strpos($fax_file, '-'));
+					$record['fax_caller_id_number'] = (is_numeric($record['fax_caller_id_name'])) ? (int) $record['fax_caller_id_name'] : null;
+					$tmp_array = explode('-',substr($fax_file, strpos($fax_file, '-')+1));
+					$record['fax_date'] = $tmp_array[0].'-'.$tmp_array[1].'-'.$tmp_array[2].' '.$tmp_array[3].':'.$tmp_array[4].':'.str_replace('.'.$record['fax_file_type'], '', $tmp_array[5]);
+					$record['fax_epoch'] = strtotime($record['fax_date']);
+				}
+				if ($fax_box == 'sent') {
+					$xml_cdr_uuid = substr($fax_file, 0, strpos($fax_file, '.'));
+
+					$record['fax_file_uuid'] = $xml_cdr_uuid;
+					$record['fax_uuid'] = $fax_extension_uuids[$domain_uuid][$fax_ext];
+					$record['fax_mode'] = 'tx';
+					$record['fax_file_type'] = substr($fax_file, -3);
+					$record['fax_file_path'] = $fax_file_path;
+
+					//get cdr details (if any)
+					$sql = "select destination_number, caller_id_name, caller_id_number, start_stamp, start_epoch from v_xml_cdr ";
+					$sql .= "where uuid = '".$xml_cdr_uuid."' ";
+					$sql .= "and domain_uuid = '".$domain_uuid."' ";
+					$prep_statement = $db->prepare(check_sql($sql));
+					$prep_statement->execute();
+					$cdr = $prep_statement->fetch(PDO::FETCH_ASSOC);
+					if (is_array($cdr) && count($cdr) > 0) {
+						$record['fax_destination'] = $cdr['destination_number'];
+						$record['fax_caller_id_name'] = $cdr['caller_id_name'];
+						$record['fax_caller_id_number'] = $cdr['caller_id_number'];
+						$record['fax_date'] = $cdr['start_stamp'];
+						$record['fax_epoch'] = $cdr['start_epoch'];
+					}
+					else {
+						$record['fax_caller_id_name'] = $fax_extension_cid[$domain_uuid][$fax_ext]['name'];
+						$record['fax_caller_id_number'] = $fax_extension_cid[$domain_uuid][$fax_ext]['number'];
+						$record['fax_epoch'] = filemtime($fax_file_path);
+						$record['fax_date'] = date("Y-m-d H:i:s", $record['fax_epoch']);
+					}
+
+					unset($prep_statement, $sql, $cdr);
+				}
+
+				//create record in the db
+					$sql = "insert into v_fax_files ";
+					$sql .= "( ";
+					$sql .= "fax_file_uuid, ";
+					$sql .= "fax_uuid, ";
+					$sql .= "domain_uuid, ";
+					$sql .= "fax_mode, ";
+					$sql .= "fax_destination, ";
+					$sql .= "fax_file_type, ";
+					$sql .= "fax_file_path, ";
+					$sql .= "fax_caller_id_name, ";
+					$sql .= "fax_caller_id_number, ";
+					$sql .= "fax_date, ";
+					$sql .= "fax_epoch ";
+					$sql .= ") ";
+					$sql .= "values ";
+					$sql .= "( ";
+					$sql .= "'".$record['fax_file_uuid']."', ";
+					$sql .= "'".$record['fax_uuid']."', ";
+					$sql .= "'".$domain_uuid."', ";
+					$sql .= "'".$record['fax_mode']."', ";
+					$sql .= "'".$record['fax_destination']."', ";
+					$sql .= "'".$record['fax_file_type']."', ";
+					$sql .= "'".$record['fax_file_path']."', ";
+					$sql .= "'".$record['fax_caller_id_name']."', ";
+					$sql .= "'".$record['fax_caller_id_number']."', ";
+					$sql .= "'".$record['fax_date']."', ";
+					$sql .= "'".$record['fax_epoch']."' ";
+					$sql .= ") ";
+					$db->exec($sql);
+
+				echo $fax_ext.", ".strtoupper($fax_box).", ".$fax_file.(($html) ? "<br>" : null)."\n";
+
+				unset($record);
+			} //if
+
+		} //foreach
+	} //foreach
+
+	echo (($html) ? "<br>" : null)."\nImport complete.".(($html) ? "<br><br><br>" : null)."\n\n\n";
+
+?>