Sfoglia il codice sorgente

Merge pull request #1 from fusionpbx/master

test
blackc2004 9 anni fa
parent
commit
edf9b36c57
100 ha cambiato i file con 5413 aggiunte e 2660 eliminazioni
  1. 18 0
      core/app_languages.php
  2. 0 174
      core/databases/app_defaults.php
  3. 1 1
      core/domain_settings/domain_delete.php
  4. 2 2
      core/domain_settings/domain_edit.php
  5. 28 0
      core/install/app_config.php
  6. 606 0
      core/install/app_languages.php
  7. 10 0
      core/install/app_menu.php
  8. 83 0
      core/install/index.php
  9. 390 0
      core/install/install_first_time.php
  10. 173 0
      core/install/resources/classes/detect_switch.php
  11. 223 0
      core/install/resources/classes/global_settings.php
  12. 1124 0
      core/install/resources/classes/install_fusionpbx.php
  13. 455 0
      core/install/resources/classes/install_switch.php
  14. 250 0
      core/install/resources/classes/iso_countries.php
  15. 281 0
      core/install/resources/page_parts/install_config_database.php
  16. 147 0
      core/install/resources/page_parts/install_config_detail.php
  17. 144 0
      core/install/resources/page_parts/install_event_socket.php
  18. 69 0
      core/install/resources/page_parts/install_select_language.php
  19. 50 0
      core/install/root.php
  20. 59 0
      core/install/upgrade_switch.php
  21. 3 0
      core/upgrade/app_config.php
  22. 0 13
      core/upgrade/app_defaults.php
  23. 20 0
      core/upgrade/app_languages.php
  24. 27 5
      core/upgrade/index.php
  25. 4 1
      core/upgrade/upgrade.php
  26. 1 1
      index.php
  27. 127 0
      resources/classes/config.php
  28. 18 40
      resources/classes/domains.php
  29. 0 207
      resources/classes/install.php
  30. 14 2
      resources/classes/schema.php
  31. 20 15
      resources/classes/text.php
  32. 916 0
      resources/countries.php
  33. 13 0
      resources/functions.php
  34. 0 2113
      resources/install.php
  35. 123 82
      themes/enhanced/app_defaults.php
  36. 14 4
      themes/enhanced/template.php
  37. BIN
      themes/flags/Afghanistan.png
  38. BIN
      themes/flags/Aland Islands.png
  39. BIN
      themes/flags/Albania.png
  40. BIN
      themes/flags/Algeria.png
  41. BIN
      themes/flags/American Samoa.png
  42. BIN
      themes/flags/Andorra.png
  43. BIN
      themes/flags/Angola.png
  44. BIN
      themes/flags/Anguilla.png
  45. BIN
      themes/flags/Antigua and Barbuda.png
  46. BIN
      themes/flags/Argentina.png
  47. BIN
      themes/flags/Armenia.png
  48. BIN
      themes/flags/Aruba.png
  49. BIN
      themes/flags/Australia.png
  50. BIN
      themes/flags/Austria.png
  51. BIN
      themes/flags/Azerbaijan.png
  52. BIN
      themes/flags/Bahamas.png
  53. BIN
      themes/flags/Bahrain.png
  54. BIN
      themes/flags/Bangladesh.png
  55. BIN
      themes/flags/Barbados.png
  56. BIN
      themes/flags/Belarus.png
  57. BIN
      themes/flags/Belgium.png
  58. BIN
      themes/flags/Belize.png
  59. BIN
      themes/flags/Benin.png
  60. BIN
      themes/flags/Bermuda.png
  61. BIN
      themes/flags/Bhutan.png
  62. BIN
      themes/flags/Bolivia, Plurinational State of.png
  63. BIN
      themes/flags/Bosnia and Herzegovina.png
  64. BIN
      themes/flags/Botswana.png
  65. BIN
      themes/flags/Bouvet Island.png
  66. BIN
      themes/flags/Brazil.png
  67. BIN
      themes/flags/British Indian Ocean Territory.png
  68. BIN
      themes/flags/Brunei Darussalam.png
  69. BIN
      themes/flags/Bulgaria.png
  70. BIN
      themes/flags/Burkina Faso.png
  71. BIN
      themes/flags/Burundi.png
  72. BIN
      themes/flags/Cabo Verde.png
  73. BIN
      themes/flags/Cambodia.png
  74. BIN
      themes/flags/Cameroon.png
  75. BIN
      themes/flags/Canada.png
  76. BIN
      themes/flags/Cayman Islands.png
  77. BIN
      themes/flags/Central African Republic.png
  78. BIN
      themes/flags/Chad.png
  79. BIN
      themes/flags/Chile.png
  80. BIN
      themes/flags/China.png
  81. BIN
      themes/flags/Christmas Island.png
  82. BIN
      themes/flags/Cocos (Keeling) Islands.png
  83. BIN
      themes/flags/Colombia.png
  84. BIN
      themes/flags/Comoros.png
  85. BIN
      themes/flags/Congo, the Democratic Republic of the.png
  86. BIN
      themes/flags/Congo.png
  87. BIN
      themes/flags/Cook Islands.png
  88. BIN
      themes/flags/Costa Rica.png
  89. BIN
      themes/flags/Cote d'Ivoire.png
  90. BIN
      themes/flags/Croatia.png
  91. BIN
      themes/flags/Cuba.png
  92. BIN
      themes/flags/Cyprus.png
  93. BIN
      themes/flags/Czech Republic.png
  94. BIN
      themes/flags/Denmark.png
  95. BIN
      themes/flags/Djibouti.png
  96. BIN
      themes/flags/Dominica.png
  97. BIN
      themes/flags/Dominican Republic.png
  98. BIN
      themes/flags/Ecuador.png
  99. BIN
      themes/flags/Egypt.png
  100. BIN
      themes/flags/El Salvador.png

+ 18 - 0
core/app_languages.php

@@ -0,0 +1,18 @@
+<?php
+
+// Fill in the value in the native language
+// rename the corerct flag in /theme/flags/*.png
+
+$language_name['en-us'] = "English - United States";
+$language_name['es-cl'] = "Español - Chile";
+$language_name['pt-pt'] = "Português - Portugal";
+$language_name['fr-fr'] = "Français - France";
+$language_name['nl-nl'] = "Nederlands - De Nederland";
+$language_name['pt-br'] = "Brasileiro - Português";
+$language_name['pl'] = "Polski - Polska";
+$language_name['sv-se'] = "Svenska - Sverige";
+$language_name['uk'] = "Українська - Україна";
+$language_name['de-at'] = "Deutsch - Österreich";
+$language_name['ar-eg'] = "العربية - مصر";
+
+?>

+ 0 - 174
core/databases/app_defaults.php

@@ -24,22 +24,6 @@
 	Mark J Crane <[email protected]>
 */
 
-global $IS_WINDOWS;
-
-if ($IS_WINDOWS == null) {
-	if (stristr(PHP_OS, 'WIN')) { $IS_WINDOWS = true; } else { $IS_WINDOWS = false; }
-}
-
-if (!function_exists('correct_path')) {
-	function correct_path($p) {
-		global $IS_WINDOWS;
-		if ($IS_WINDOWS) {
-			return str_replace('/', '\\', $p);
-		}
-		return $p;
-	}
-}
-
 //proccess this only one time
 if ($domains_processed == 1) {
 
@@ -66,163 +50,5 @@ if ($domains_processed == 1) {
 			unset($sql);
 		}
 		unset($prep_statement, $result);
-
-	//replace the backslash with a forward slash
-		$db_path = str_replace("\\", "/", $db_path);
-
-	if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
-		//get the odbc information
-			$sql = "select count(*) as num_rows from v_databases ";
-			$sql .= "where database_driver = 'odbc' ";
-			if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
-			$prep_statement = $db->prepare($sql);
-			if ($prep_statement) {
-				$prep_statement->execute();
-				$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
-				unset($prep_statement);
-				if ($row['num_rows'] > 0) {
-					$odbc_num_rows = $row['num_rows'];
-
-					$sql = "select * from v_databases ";
-					$sql .= "where database_driver = 'odbc' ";
-					$prep_statement = $db->prepare(check_sql($sql));
-					$prep_statement->execute();
-					$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-					foreach ($result as &$row) {
-						$dsn_name = $row["database_name"];
-						$dsn_username = $row["database_username"];
-						$dsn_password = $row["database_password"];
-						break; //limit to 1 row
-					}
-					unset ($prep_statement);
-				}
-				else {
-					$odbc_num_rows = '0';
-				}
-			}
-
-		//get the recordings directory
-			if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
-				$sql = "select * from v_default_settings ";
-				$sql .= "where default_setting_category = 'switch' ";
-				$sql .= "and default_setting_subcategory = 'recordings' ";
-				$sql .= "and default_setting_name = 'dir' ";
-				$prep_statement = $db->prepare(check_sql($sql));
-				$prep_statement->execute();
-				$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-				foreach ($result as &$row) {
-					$recordings_dir = $row["default_setting_value"];
-				}
-				unset($prep_statement, $result);
-			}
-
-		//config.lua
-			if (is_dir("/etc/fusionpbx")){
-				$config = "/etc/fusionpbx/config.lua";
-			} elseif (is_dir("/usr/local/etc/fusionpbx")){
-				$config = "/usr/local/etc/fusionpbx/config.lua";
-			}
-			else {
-				$config = $_SESSION['switch']['scripts']['dir']."/resources/config.lua";
-			}
-			$fout = fopen($config,"w");
-			$tmp = "\n";
-			$tmp .= "--set the variables\n";
-			if (strlen($_SESSION['switch']['sounds']['dir']) > 0) {
-				$tmp .= correct_path("	sounds_dir = [[".$_SESSION['switch']['sounds']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['phrases']['dir']) > 0) {
-				$tmp .= correct_path("	phrases_dir = [[".$_SESSION['switch']['phrases']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['db']['dir']) > 0) {
-				$tmp .= correct_path("	database_dir = [[".$_SESSION['switch']['db']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
-				$tmp .= correct_path("	recordings_dir = [[".$recordings_dir."]];\n");
-			}
-			if (strlen($_SESSION['switch']['storage']['dir']) > 0) {
-				$tmp .= correct_path("	storage_dir = [[".$_SESSION['switch']['storage']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['voicemail']['dir']) > 0) {
-				$tmp .= correct_path("	voicemail_dir = [[".$_SESSION['switch']['voicemail']['dir']."]];\n");
-			}
-			if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
-				$tmp .= correct_path("	scripts_dir = [[".$_SESSION['switch']['scripts']['dir']."]];\n");
-			}
-			$tmp .= correct_path("	php_dir = [[".PHP_BINDIR."]];\n");
-			if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
-				$tmp .= "	php_bin = \"php.exe\";\n";
-			}
-			else {
-				$tmp .= "	php_bin = \"php\";\n";
-			}
-			$tmp .= correct_path("	document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
-			$tmp .= "\n";
-
-			if ((strlen($db_type) > 0) || (strlen($dsn_name) > 0)) {
-				$tmp .= "--database information\n";
-				$tmp .= "	database = {}\n";
-				$tmp .= "	database[\"type\"] = \"".$db_type."\";\n";
-				$tmp .= "	database[\"name\"] = \"".$db_name."\";\n";
-				$tmp .= correct_path("	database[\"path\"] = [[".$db_path."]];\n");
-
-				if (strlen($dsn_name) > 0) {
-					$tmp .= "	database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n";
-					$tmp .= "	database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n";
-				}
-				elseif ($db_type == "pgsql") {
-					if ($db_host == "localhost") { $db_host = "127.0.0.1"; }
-					$tmp .= "	database[\"system\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=".$db_name." user=".$db_username." password=".$db_password." options='' application_name='".$db_name."'\";\n";
-					$tmp .= "	database[\"switch\"] = \"pgsql://hostaddr=".$db_host." port=".$db_port." dbname=freeswitch user=".$db_username." password=".$db_password." options='' application_name='freeswitch'\";\n";
-				}
-				elseif ($db_type == "sqlite") {
-					$tmp .= "	database[\"system\"] = \"sqlite://".$db_path."/".$db_name."\";\n";
-					$tmp .= "	database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
-				}
-				elseif ($db_type == "mysql") {
-					$tmp .= "	database[\"system\"] = \"\";\n";
-					$tmp .= "	database[\"switch\"] = \"\";\n";
-				}
-				$tmp .= "\n";
-			}
-			$tmp .= "--set defaults\n";
-			$tmp .= "	expire = {}\n";
-			$tmp .= "	expire[\"directory\"] = \"3600\";\n";
-			$tmp .= "	expire[\"dialplan\"] = \"3600\";\n";
-			$tmp .= "	expire[\"languages\"] = \"3600\";\n";
-			$tmp .= "	expire[\"sofia.conf\"] = \"3600\";\n";
-			$tmp .= "	expire[\"acl.conf\"] = \"3600\";\n";
-			$tmp .= "\n";
-			$tmp .= "--set xml_handler\n";
-			$tmp .= "	xml_handler = {}\n";
-			$tmp .= "	xml_handler[\"fs_path\"] = false;\n";
-			$tmp .= "\n";
-			$tmp .= "--set the debug options\n";
-			$tmp .= "	debug[\"params\"] = false;\n";
-			$tmp .= "	debug[\"sql\"] = false;\n";
-			$tmp .= "	debug[\"xml_request\"] = false;\n";
-			$tmp .= "	debug[\"xml_string\"] = false;\n";
-			$tmp .= "	debug[\"cache\"] = false;\n";
-			$tmp .= "\n";
-			$tmp .= "--additional info\n";
-			$tmp .= "	domain_count = ".count($_SESSION["domains"]).";\n";
-			$tmp .= correct_path("	temp_dir = [[".$_SESSION['server']['temp']['dir']."]];\n");
-			if (isset($_SESSION['domain']['dial_string']['text'])) {
-				$tmp .= "	dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
-			}
-			$tmp .= "\n";
-			$tmp .= "--include local.lua\n";
-			$tmp .= "	require(\"resources.functions.file_exists\");\n";
-			$tmp .= "	if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
-			$tmp .= "		dofile(\"/etc/fusionpbx/local.lua\");\n";
-			$tmp .= "	elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
-			$tmp .= "		dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
-			$tmp .= "	elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
-			$tmp .= "		require(\"resources.local\");\n";
-			$tmp .= "	end\n";
-			fwrite($fout, $tmp);
-			unset($tmp);
-			fclose($fout);
-	}
 }
 ?>

+ 1 - 1
core/domain_settings/domain_delete.php

@@ -176,7 +176,7 @@ if (strlen($id) > 0) {
 
 		//delete the recordings
 			if (strlen($_SESSION['switch'][recordings]['dir']) > 0) {
-				system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$domain_name);
+				system('rm -rf '.$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$domain_name);
 			}
 
 		//delete voicemail

+ 2 - 2
core/domain_settings/domain_edit.php

@@ -234,8 +234,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
 						}
 
 					// rename switch/recordings/[domain] (folder)
-						if ( isset($_SESSION['switch']['recordings']['dir']) ) {
-							$switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $_SESSION['switch']['recordings']['dir']);
+						if ( file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']) ) {
+							$switch_recordings_dir = str_replace("/".$_SESSION["domain_name"], "", $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']);
 							if ( file_exists($switch_recordings_dir."/".$original_domain_name) ) {
 								@rename($switch_recordings_dir."/".$original_domain_name, $switch_recordings_dir."/".$domain_name); // folder
 							}

+ 28 - 0
core/install/app_config.php

@@ -0,0 +1,28 @@
+<?php
+
+	//application details
+		$apps[$x]['name'] = "Install";
+		$apps[$x]['uuid'] = "75507e6e-891e-11e5-af63-feff819cdc9f";
+		$apps[$x]['category'] = "Core";
+		$apps[$x]['subcategory'] = "";
+		$apps[$x]['version'] = "";
+		$apps[$x]['url'] = "http://www.fusionpbx.com";
+		$apps[$x]['description']['en-us'] = "Install the fuisionPBX system or add new switches";
+		$apps[$x]['description']['es-cl'] = "";
+		$apps[$x]['description']['de-de'] = "";
+		$apps[$x]['description']['de-ch'] = "";
+		$apps[$x]['description']['de-at'] = "";
+		$apps[$x]['description']['fr-fr'] = "";
+		$apps[$x]['description']['fr-ca'] = "";
+		$apps[$x]['description']['fr-ch'] = "";
+		$apps[$x]['description']['pt-pt'] = "";
+		$apps[$x]['description']['pt-br'] = "";
+
+	//permission details
+		//$y = 0;
+		//$apps[$x]['permissions'][$y]['name'] = "install";
+		//$apps[$x]['permissions'][$y]['menu']['uuid'] = "75507e6e-891e-11e5-af63-feff819cdc9f";
+		//$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
+		//$y++;
+
+?>

+ 606 - 0
core/install/app_languages.php

@@ -0,0 +1,606 @@
+<?php
+
+$text['title-install_first_time']['en-us'] = "First Time Install";
+$text['title-install_first_time']['es-cl'] = "Instale Primera Vez";
+$text['title-install_first_time']['pt-pt'] = "Première installation";
+$text['title-install_first_time']['fr-fr'] = "";
+$text['title-install_first_time']['pt-br'] = "";
+$text['title-install_first_time']['pl'] = "";
+$text['title-install_first_time']['sv-se'] = "";
+$text['title-install_first_time']['uk'] = "";
+$text['title-install_first_time']['de-at'] = "";
+$text['title-install_first_time']['ar-eg'] = "";
+
+$text['title-detected_configuration']['en-us'] = "Detected Configuration";
+$text['title-detected_configuration']['es-cl'] = "";
+$text['title-detected_configuration']['pt-pt'] = "";
+$text['title-detected_configuration']['fr-fr'] = "";
+$text['title-detected_configuration']['pt-br'] = "";
+$text['title-detected_configuration']['pl'] = "";
+$text['title-detected_configuration']['sv-se'] = "";
+$text['title-detected_configuration']['uk'] = "";
+$text['title-detected_configuration']['de-at'] = "";
+$text['title-detected_configuration']['ar-eg'] = "";
+
+$text['title-assumed_configuration']['en-us'] = "Assumed Configuration";
+$text['title-assumed_configuration']['es-cl'] = "";
+$text['title-assumed_configuration']['pt-pt'] = "";
+$text['title-assumed_configuration']['fr-fr'] = "";
+$text['title-assumed_configuration']['pt-br'] = "";
+$text['title-assumed_configuration']['pl'] = "";
+$text['title-assumed_configuration']['sv-se'] = "";
+$text['title-assumed_configuration']['uk'] = "";
+$text['title-assumed_configuration']['de-at'] = "";
+$text['title-assumed_configuration']['ar-eg'] = "";
+
+$text['message-update']['en-us'] = "Update Completed";
+$text['message-update']['es-cl'] = "Actualización Completada";
+$text['message-update']['pt-pt'] = "Actualização Efectuada";
+$text['message-update']['fr-fr'] = "Mis à jour";
+$text['message-update']['pt-br'] = "Atualização Efetuada";
+$text['message-update']['pl'] = "Zaktualizowano poprawnie";
+$text['message-update']['sv-se'] = "Uppdatering Klar";
+$text['message-update']['uk'] = "Оновлення завершено";
+$text['message-update']['de-at'] = "Aktualisierung durchgeführt";
+$text['message-update']['ar-eg'] = "اكتمال التحديث";
+
+$text['message-required']['en-us'] = "Please provide: ";
+$text['message-required']['es-cl'] = "Por favor indique: ";
+$text['message-required']['pt-pt'] = "Por favor indique: ";
+$text['message-required']['fr-fr'] = "Merci d'indiquer: ";
+$text['message-required']['pt-br'] = "Por favor Indique:";
+$text['message-required']['pl'] = "Wpisz:";
+$text['message-required']['sv-se'] = "Var god uppge:";
+$text['message-required']['uk'] = "Будь ласка, вкажіть:";
+$text['message-required']['de-at'] = "Bitte geben Sie folgendes an:";
+$text['message-required']['ar-eg'] = "من فضلك أدخل";
+
+$text['message-message']['en-us'] = "Message";
+$text['message-message']['es-cl'] = "Mensaje";
+$text['message-message']['pt-pt'] = "Mensagem";
+$text['message-message']['fr-fr'] = "Message";
+$text['message-message']['pt-br'] = "Mensagem";
+$text['message-message']['pl'] = "Wiadomość";
+$text['message-message']['sv-se'] = "Meddelande";
+$text['message-message']['uk'] = "Повідомлення";
+$text['message-message']['de-at'] = "Nachricht";
+$text['message-message']['ar-eg'] = "رسالة";
+
+$text['message-delete']['en-us'] = "Delete Completed";
+$text['message-delete']['es-cl'] = "Eliminación Completada";
+$text['message-delete']['pt-pt'] = "Remoção Efectuada";
+$text['message-delete']['fr-fr'] = "Supprimé";
+$text['message-delete']['pt-br'] = "Remoção Efetuada";
+$text['message-delete']['pl'] = "Usunięto poprawnie";
+$text['message-delete']['sv-se'] = "Borttagning Klar";
+$text['message-delete']['uk'] = "Видалено";
+$text['message-delete']['de-at'] = "Erfolgreich gelöscht";
+$text['message-delete']['ar-eg'] = "تم المسح";
+
+$text['label-ft-install']['en-us'] = "First Time Install";
+$text['label-ft-install']['es-cl'] = "";
+$text['label-ft-install']['pt-pt'] = "";
+$text['label-ft-install']['fr-fr'] = "";
+$text['label-ft-install']['pt-br'] = "";
+$text['label-ft-install']['pl'] = "";
+$text['label-ft-install']['sv-se'] = "";
+$text['label-ft-install']['uk'] = "";
+$text['label-ft-install']['de-at'] = "";
+$text['label-ft-install']['ar-eg'] = "";
+
+$text['description-ft-install']['en-us'] = "Perform all actions for a First Time Install";
+$text['description-ft-install']['es-cl'] = "";
+$text['description-ft-install']['pt-pt'] = "";
+$text['description-ft-install']['fr-fr'] = "";
+$text['description-ft-install']['pt-br'] = "";
+$text['description-ft-install']['pl'] = "";
+$text['description-ft-install']['sv-se'] = "";
+$text['description-ft-install']['uk'] = "";
+$text['description-ft-install']['de-at'] = "";
+$text['description-ft-install']['ar-eg'] = "";
+
+$text['label-add-switch']['en-us'] = "Add a new switch";
+$text['label-add-switch']['es-cl'] = "";
+$text['label-add-switch']['pt-pt'] = "";
+$text['label-add-switch']['fr-fr'] = "";
+$text['label-add-switch']['pt-br'] = "";
+$text['label-add-switch']['pl'] = "";
+$text['label-add-switch']['sv-se'] = "";
+$text['label-add-switch']['uk'] = "";
+$text['label-add-switch']['de-at'] = "";
+$text['label-add-switch']['ar-eg'] = "";
+
+$text['label-select_language']['en-us'] = "Language";
+$text['label-select_language']['es-cl'] = "";
+$text['label-select_language']['pt-pt'] = "";
+$text['label-select_language']['fr-fr'] = "";
+$text['label-select_language']['pt-br'] = "";
+$text['label-select_language']['pl'] = "";
+$text['label-select_language']['sv-se'] = "";
+$text['label-select_language']['uk'] = "";
+$text['label-select_language']['de-at'] = "";
+$text['label-select_language']['ar-eg'] = "";
+
+$text['label-event_host']['en-us'] = "Host/IP";
+$text['label-event_host']['es-cl'] = "";
+$text['label-event_host']['pt-pt'] = "";
+$text['label-event_host']['fr-fr'] = "";
+$text['label-event_host']['pt-br'] = "";
+$text['label-event_host']['pl'] = "";
+$text['label-event_host']['sv-se'] = "";
+$text['label-event_host']['uk'] = "";
+$text['label-event_host']['de-at'] = "";
+$text['label-event_host']['ar-eg'] = "";
+
+$text['label-event_port']['en-us'] = "Port";
+$text['label-event_port']['es-cl'] = "Puerto";
+$text['label-event_port']['pt-pt'] = "Porto";
+$text['label-event_port']['fr-fr'] = "Port";
+$text['label-event_port']['pt-br'] = "Porta";
+$text['label-event_port']['pl'] = "Port";
+$text['label-event_port']['sv-se'] = "Port";
+$text['label-event_port']['uk'] = "Порт";
+$text['label-event_port']['de-at'] = "Port";
+$text['label-event_port']['ar-eg'] = "منفذ";
+
+$text['label-event_password']['en-us'] = "Password";
+$text['label-event_password']['es-cl'] = "Contreseña";
+$text['label-event_password']['pt-pt'] = "Palavra-Chave";
+$text['label-event_password']['fr-fr'] = "Mot de Passe";
+$text['label-event_password']['pt-br'] = "Senha";
+$text['label-event_password']['pl'] = "Hasło";
+$text['label-event_password']['sv-se'] = "Lösenord";
+$text['label-event_password']['uk'] = "Пароль";
+$text['label-event_password']['de-at'] = "Passwort";
+$text['label-event_password']['ar-eg'] = "كلمة السر";
+
+$text['label-username']['en-us'] = "Username";
+$text['label-username']['es-cl'] = "Nombre de usuario";
+$text['label-username']['pt-pt'] = "Utilizador";
+$text['label-username']['fr-fr'] = "Utilisateur";
+$text['label-username']['pt-br'] = "Nome do Usuário";
+$text['label-username']['pl'] = "Użytkownik";
+$text['label-username']['sv-se'] = "Användarnamn";
+$text['label-username']['uk'] = "Ім’я користувача";
+$text['label-username']['de-at'] = "Benutzername";
+$text['label-username']['ar-eg'] = "اسم المستخدم";
+
+$text['label-type']['en-us'] = "Type";
+$text['label-type']['es-cl'] = "Tipo";
+$text['label-type']['pt-pt'] = "Tipo";
+$text['label-type']['fr-fr'] = "Type";
+$text['label-type']['pt-br'] = "Tipo";
+$text['label-type']['pl'] = "Typ";
+$text['label-type']['sv-se'] = "Typ";
+$text['label-type']['uk'] = "Тип";
+$text['label-type']['de-at'] = "Typ";
+$text['label-type']['ar-eg'] = "النوع";
+
+$text['label-port']['en-us'] = "Port";
+$text['label-port']['es-cl'] = "Puerto";
+$text['label-port']['pt-pt'] = "Porto";
+$text['label-port']['fr-fr'] = "Port";
+$text['label-port']['pt-br'] = "Porta";
+$text['label-port']['pl'] = "Port";
+$text['label-port']['sv-se'] = "Port";
+$text['label-port']['uk'] = "Порт";
+$text['label-port']['de-at'] = "Port";
+$text['label-port']['ar-eg'] = "منفذ";
+
+$text['label-path']['en-us'] = "Path";
+$text['label-path']['es-cl'] = "Ruta";
+$text['label-path']['pt-pt'] = "Caminho";
+$text['label-path']['fr-fr'] = "Chemin";
+$text['label-path']['pt-br'] = "Caminho";
+$text['label-path']['pl'] = "Ścieżka";
+$text['label-path']['sv-se'] = "Sökväg";
+$text['label-path']['uk'] = "Шлях";
+$text['label-path']['de-at'] = "Pfad";
+$text['label-path']['ar-eg'] = "";
+
+$text['label-password']['en-us'] = "Password";
+$text['label-password']['es-cl'] = "Contreseña";
+$text['label-password']['pt-pt'] = "Palavra-Chave";
+$text['label-password']['fr-fr'] = "Mot de Passe";
+$text['label-password']['pt-br'] = "Senha";
+$text['label-password']['pl'] = "Hasło";
+$text['label-password']['sv-se'] = "Lösenord";
+$text['label-password']['uk'] = "Пароль";
+$text['label-password']['de-at'] = "Passwort";
+$text['label-password']['ar-eg'] = "كلمة السر";
+
+$text['label-name']['en-us'] = "Name";
+$text['label-name']['es-cl'] = "Nombre";
+$text['label-name']['pt-pt'] = "Nome";
+$text['label-name']['fr-fr'] = "Nom";
+$text['label-name']['pt-br'] = "Nome";
+$text['label-name']['pl'] = "Nazwa";
+$text['label-name']['sv-se'] = "Namn";
+$text['label-name']['uk'] = "Назва";
+$text['label-name']['de-at'] = "Name";
+$text['label-name']['ar-eg'] = "الأسم";
+
+$text['label-host']['en-us'] = "Host";
+$text['label-host']['es-cl'] = "Host";
+$text['label-host']['pt-pt'] = "Máquina";
+$text['label-host']['fr-fr'] = "Hôte";
+$text['label-host']['pt-br'] = "Máquina";
+$text['label-host']['pl'] = "Host";
+$text['label-host']['sv-se'] = "Värd";
+$text['label-host']['uk'] = "Хост";
+$text['label-host']['de-at'] = "Host";
+$text['label-host']['ar-eg'] = "مضيف";
+
+$text['label-driver']['en-us'] = "Driver";
+$text['label-driver']['es-cl'] = "Controlador";
+$text['label-driver']['pt-pt'] = "Driver";
+$text['label-driver']['fr-fr'] = "Driver";
+$text['label-driver']['pt-br'] = "Driver";
+$text['label-driver']['pl'] = "Sterownik";
+$text['label-driver']['sv-se'] = "Drivrutin";
+$text['label-driver']['uk'] = "Драйвер";
+$text['label-driver']['de-at'] = "Treiber";
+$text['label-driver']['ar-eg'] = "";
+
+$text['label-description']['en-us'] = "Description";
+$text['label-description']['es-cl'] = "Descripción";
+$text['label-description']['pt-pt'] = "Descrição";
+$text['label-description']['fr-fr'] = "Description";
+$text['label-description']['pt-br'] = "Descrição";
+$text['label-description']['pl'] = "Opis";
+$text['label-description']['sv-se'] = "Beskrivning";
+$text['label-description']['uk'] = "Опис";
+$text['label-description']['de-at'] = "Beschreibung";
+$text['label-description']['ar-eg'] = "الوصف";
+
+$text['header-install']['en-us'] = "Install";
+$text['header-install']['es-cl'] = "";
+$text['header-install']['pt-pt'] = "";
+$text['header-install']['fr-fr'] = "";
+$text['header-install']['pt-br'] = "";
+$text['header-install']['pl'] = "";
+$text['header-install']['sv-se'] = "";
+$text['header-install']['uk'] = "";
+$text['header-install']['de-at'] = "";
+$text['header-install']['ar-eg'] = "";
+
+$text['header-select_language']['en-us'] = "Select Language";
+$text['header-select_language']['es-cl'] = "";
+$text['header-select_language']['pt-pt'] = "";
+$text['header-select_language']['fr-fr'] = "";
+$text['header-select_language']['pt-br'] = "";
+$text['header-select_language']['pl'] = "";
+$text['header-select_language']['sv-se'] = "";
+$text['header-select_language']['uk'] = "";
+$text['header-select_language']['de-at'] = "";
+$text['header-select_language']['ar-eg'] = "";
+
+$text['header-event_socket']['en-us'] = "Event Socket Configuration";
+$text['header-event_socket']['es-cl'] = "";
+$text['header-event_socket']['pt-pt'] = "";
+$text['header-event_socket']['fr-fr'] = "";
+$text['header-event_socket']['pt-br'] = "";
+$text['header-event_socket']['pl'] = "";
+$text['header-event_socket']['sv-se'] = "";
+$text['header-event_socket']['uk'] = "";
+$text['header-event_socket']['de-at'] = "";
+$text['header-event_socket']['ar-eg'] = "";
+
+$text['header-config_detail']['en-us'] = "Admin Configuration";
+$text['header-config_detail']['es-cl'] = "";
+$text['header-config_detail']['pt-pt'] = "";
+$text['header-config_detail']['fr-fr'] = "";
+$text['header-config_detail']['pt-br'] = "";
+$text['header-config_detail']['pl'] = "";
+$text['header-config_detail']['sv-se'] = "";
+$text['header-config_detail']['uk'] = "";
+$text['header-config_detail']['de-at'] = "";
+$text['header-config_detail']['ar-eg'] = "";
+
+$text['header-config_database']['en-us'] = "Database Configuration";
+$text['header-config_database']['es-cl'] = "";
+$text['header-config_database']['pt-pt'] = "";
+$text['header-config_database']['fr-fr'] = "";
+$text['header-config_database']['pt-br'] = "";
+$text['header-config_database']['pl'] = "";
+$text['header-config_database']['sv-se'] = "";
+$text['header-config_database']['uk'] = "";
+$text['header-config_database']['de-at'] = "";
+$text['header-config_database']['ar-eg'] = "";
+
+$text['header-installing']['en-us'] = "Executing Install";
+$text['header-installing']['es-cl'] = "";
+$text['header-installing']['pt-pt'] = "";
+$text['header-installing']['fr-fr'] = "";
+$text['header-installing']['pt-br'] = "";
+$text['header-installing']['pl'] = "";
+$text['header-installing']['sv-se'] = "";
+$text['header-installing']['uk'] = "";
+$text['header-installing']['de-at'] = "";
+$text['header-installing']['ar-eg'] = "";
+
+$text['description-event_host']['en-us'] = "Enter the event socket host name/IP.";
+$text['description-event_host']['es-cl'] = "";
+$text['description-event_host']['pt-pt'] = "";
+$text['description-event_host']['fr-fr'] = "";
+$text['description-event_host']['pt-br'] = "";
+$text['description-event_host']['pl'] = "";
+$text['description-event_host']['sv-se'] = "";
+$text['description-event_host']['uk'] = "";
+$text['description-event_host']['de-at'] = "";
+$text['description-event_host']['ar-eg'] = "";
+
+$text['description-event_port']['en-us'] = "Enter the event socket port number.";
+$text['description-event_port']['es-cl'] = "";
+$text['description-event_port']['pt-pt'] = "";
+$text['description-event_port']['fr-fr'] = "";
+$text['description-event_port']['pt-br'] = "";
+$text['description-event_port']['pl'] = "";
+$text['description-event_port']['sv-se'] = "";
+$text['description-event_port']['uk'] = "";
+$text['description-event_port']['de-at'] = "";
+$text['description-event_port']['ar-eg'] = "";
+
+$text['description-event_password']['en-us'] = "Enter the event socket password.";
+$text['description-event_password']['es-cl'] = "";
+$text['description-event_password']['pt-pt'] = "";
+$text['description-event_password']['fr-fr'] = "";
+$text['description-event_password']['pt-br'] = "";
+$text['description-event_password']['pl'] = "";
+$text['description-event_password']['sv-se'] = "";
+$text['description-event_password']['uk'] = "";
+$text['description-event_password']['de-at'] = "";
+$text['description-event_password']['ar-eg'] = "";
+
+$text['description-username']['en-us'] = "Enter the database username.";
+$text['description-username']['es-cl'] = "Ingrese el nombre de usuario de la base de datos.";
+$text['description-username']['pt-pt'] = "Introduza o utilizador da base de dados.";
+$text['description-username']['fr-fr'] = "Entrer le nom d'utilisateur de la Base de données.";
+$text['description-username']['pt-br'] = "Insira o nome do usuário";
+$text['description-username']['pl'] = "Wprowadź nazwę użytkownika";
+$text['description-username']['sv-se'] = "Ange databasen användarnamn här.";
+$text['description-username']['uk'] = "Введіть ім’я користувача бази даних";
+$text['description-username']['de-at'] = "Geben Sie den Datenbank Benutzernamen an.";
+$text['description-username']['ar-eg'] = "أدخل اسم المستخدم هنا";
+
+$text['description-type']['en-us'] = "Select the database type.";
+$text['description-type']['es-cl'] = "Seleccione el tipo de base de datos";
+$text['description-type']['pt-pt'] = "Escolha o tipo de base de dados.";
+$text['description-type']['fr-fr'] = "Choisir le type de Base de données.";
+$text['description-type']['pt-br'] = "Introduza o tipo de definição.";
+$text['description-type']['pl'] = "Wprowadź rodzaj bazy danych";
+$text['description-type']['sv-se'] = "Välj databastyp";
+$text['description-type']['uk'] = "Виберіть тип бази даних";
+$text['description-type']['de-at'] = "Wählen Sie den Datenbank Typ.";
+$text['description-type']['ar-eg'] = "إختر نوع قاعدة البيانات";
+
+$text['description-port']['en-us'] = "Enter the port number.";
+$text['description-port']['es-cl'] = "Ingrese el número del puerto.";
+$text['description-port']['pt-pt'] = "Introduza o número do porto.";
+$text['description-port']['fr-fr'] = "Entrer le numéro de port.";
+$text['description-port']['pt-br'] = "Insira o número da porta";
+$text['description-port']['pl'] = "Wprowadź numer portu";
+$text['description-port']['sv-se'] = "Ange portnummer";
+$text['description-port']['uk'] = "Введіть номер порта";
+$text['description-port']['de-at'] = "Geben Sie die Port Nummer an.";
+$text['description-port']['ar-eg'] = "أدخل رقم المنفذ";
+
+$text['description-path']['en-us'] = "Enter the database file path (SQLite only).";
+$text['description-path']['es-cl'] = "Ingrese la ruta al archivo de datos (solo SQLite).";
+$text['description-path']['pt-pt'] = "Introduza o caminho da base de dados (apenas SQLite)";
+$text['description-path']['fr-fr'] = "Entrer le chemin du fichier Base de données (Spécifique SQLite).";
+$text['description-path']['pt-br'] = "Insira o caminho da base de dados (SQLite)";
+$text['description-path']['pl'] = "Wprowadź ścieżkę do pliku bazy danych (tylko SQLite)";
+$text['description-path']['sv-se'] = "Ange databasens sökväg (gäller endast SQLite).";
+$text['description-path']['uk'] = "Вкажіть шлях до файлу бази даних (тільки SQLite).";
+$text['description-path']['de-at'] = "Geben Sie den Datenbank Pfad an (nur für SQLite).";
+$text['description-path']['ar-eg'] = "";
+
+$text['description-password']['en-us'] = "Enter the database password.";
+$text['description-password']['es-cl'] = "Ingrese la contraseña de la base de datos.";
+$text['description-password']['pt-pt'] = "Introduza a palavra-chave da base de dados.";
+$text['description-password']['fr-fr'] = "Entrer le mot de passe pour la Base de données.";
+$text['description-password']['pt-br'] = "Introduza a senha";
+$text['description-password']['pl'] = "Wpisz hasło";
+$text['description-password']['sv-se'] = "Ange databasens lösenord.";
+$text['description-password']['uk'] = "Введіть пароль бази даних.";
+$text['description-password']['de-at'] = "Geben Sie das Datenbank Passwort ein.";
+$text['description-password']['ar-eg'] = "أدخل الرقم السري الخاص بقاعدة البيانات";
+
+$text['description-name']['en-us'] = "Enter the database name.";
+$text['description-name']['es-cl'] = "Ingrese el nombre de la base de datos.";
+$text['description-name']['pt-pt'] = "Introduza o nome da base de dados.";
+$text['description-name']['fr-fr'] = "Entrer le nom de la Base de données.";
+$text['description-name']['pt-br'] = "Insira o nome do menu";
+$text['description-name']['pl'] = "Wprowadź nazwę bazy danych.";
+$text['description-name']['sv-se'] = "Ange databasens namn.";
+$text['description-name']['uk'] = "Введіть ім'я бази даних.";
+$text['description-name']['de-at'] = "Geben Sie den Namen der Datenbank an";
+$text['description-name']['ar-eg'] = "أدخل إسم قاعدة البيانات";
+
+$text['description-host']['en-us'] = "Enter the host name.";
+$text['description-host']['es-cl'] = "Ingrese el nombre de host";
+$text['description-host']['pt-pt'] = "Introduza o nome da máquina.";
+$text['description-host']['fr-fr'] = "Entrer le nom de l'hôte.";
+$text['description-host']['pt-br'] = "Insira o nome da máquina ";
+$text['description-host']['pl'] = "Wprowadź nazwę hosta.";
+$text['description-host']['sv-se'] = "Ange värdnamnet";
+$text['description-host']['uk'] = "Введіть ім'я хоста.";
+$text['description-host']['de-at'] = "Geben Sie den Host Namen ein.";
+$text['description-host']['ar-eg'] = "أدخل إسم المضيف";
+
+$text['description-driver']['en-us'] = "Select the database driver.";
+$text['description-driver']['es-cl'] = "Seleccione un controlador de base de datos.";
+$text['description-driver']['pt-pt'] = "Escolha o driver da base de dados";
+$text['description-driver']['fr-fr'] = "Choisir le driver de la Base de données.";
+$text['description-driver']['pt-br'] = "Escolha o driver da base de dados";
+$text['description-driver']['pl'] = "Wybierz sterownik bazy danych.";
+$text['description-driver']['sv-se'] = "Välj databas drivrutin.";
+$text['description-driver']['uk'] = "Виберіть драйвер бази даних.";
+$text['description-driver']['de-at'] = "Wählen Sie den Datenbank Treiber.";
+$text['description-driver']['ar-eg'] = "";
+
+$text['description-description']['en-us'] = "Enter a description for this database, if desired.";
+$text['description-description']['es-cl'] = "Ingrese una descripción para esta base de datos, opcional.";
+$text['description-description']['pt-pt'] = "Introduza a descrição para a base de dados (opcional).";
+$text['description-description']['fr-fr'] = "Entrer une description pour cette Base de données. (optionnel)";
+$text['description-description']['pt-br'] = "Insira a descrição, caso desejar";
+$text['description-description']['pl'] = "Wprowadź opis  bazy danych (opcjonalne)";
+$text['description-description']['sv-se'] = "Fyll i en beskrivning för denna databas, om nödvändigt.";
+$text['description-description']['uk'] = "Введіть опис, якщо це необхідно.";
+$text['description-description']['de-at'] = "Falls gewünscht, geben Sie eine Beschreibung an.";
+$text['description-description']['ar-eg'] = "";
+
+$text['description-install']['en-us'] = "Select the action below you wish to perform.";
+$text['description-install']['es-cl'] = "Seleccione las accion a continuación que desea realizar.";
+$text['description-install']['pt-pt'] = "Selecione as ações abaixo você deseja executar.";	//action signular needed
+$text['description-install']['fr-fr'] = "Sélectionnez les action ci-dessous que vous souhaitez effectuer.";
+$text['description-install']['pt-br'] = "Seleciona as ações abaixo que deseja executar ";	//action signular needed
+$text['description-install']['pl'] = "Wybierz opcje, które chcesz wykonać.";	//action signular needed
+$text['description-install']['sv-se'] = "Välj de åtgärder nedan som du vill utföra.";	//action signular needed
+$text['description-install']['uk'] = "Виберіть об’єкти для оновлення";	//action signular needed
+$text['description-install']['de-at'] = "Wählen Sie eine Aktion.";	//action signular needed
+
+$text['description-database-edit']['en-us'] = "Database connection information.";
+$text['description-database-edit']['es-cl'] = "Información de conexión a base de datos.";
+$text['description-database-edit']['pt-pt'] = "Informação da ligação à base de dados.";
+$text['description-database-edit']['fr-fr'] = "Informations de connexion à la Base";
+$text['description-database-edit']['pt-br'] = "Informações da ligação na base de dados";
+$text['description-database-edit']['pl'] = "Informacje o połączeniach z bazą danych.";
+$text['description-database-edit']['sv-se'] = "Information om Databasanslutning";
+$text['description-database-edit']['uk'] = "інформація про підключення до бази даних.";
+$text['description-database-edit']['de-at'] = "Datenbank Verbindungs Information.";
+$text['description-database-edit']['ar-eg'] = "بيانات الإتصال الخاص بقاعدة البيانات";
+
+$text['description-database-add']['en-us'] = "Database connection information.";
+$text['description-database-add']['es-cl'] = "Información de conexión a base de datos.";
+$text['description-database-add']['pt-pt'] = "Informação da ligação à base de dados.";
+$text['description-database-add']['fr-fr'] = "Informations de connexion à la Base.";
+$text['description-database-add']['pt-br'] = "Informações da ligação na base de dados";
+$text['description-database-add']['pl'] = "Informacje o połączeniach z bazą danych.";
+$text['description-database-add']['sv-se'] = "Information om Databasanslutning";
+$text['description-database-add']['uk'] = "інформація про підключення до бази даних.";
+$text['description-database-add']['de-at'] = "Datenbank Verbindungs Information.";
+$text['description-database-add']['ar-eg'] = "بيانات الإتصال الخاص بقاعدة البيانات";
+
+$text['description-select_language']['en-us'] = "Please select the language you want to use";
+$text['description-select_language']['es-cl'] = "";
+$text['description-select_language']['pt-pt'] = "";
+$text['description-select_language']['fr-fr'] = "";
+$text['description-select_language']['pt-br'] = "";
+$text['description-select_language']['pl'] = "";
+$text['description-select_language']['sv-se'] = "";
+$text['description-select_language']['uk'] = "";
+$text['description-select_language']['de-at'] = "";
+$text['description-select_language']['ar-eg'] = "";
+
+$text['confirm-delete']['en-us'] = "Do you really want to delete this?";
+$text['confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?";
+$text['confirm-delete']['pt-pt'] = "Deseja realmente remover isto?";
+$text['confirm-delete']['fr-fr'] = "Voulez-vous vraiment supprimer cela?";
+$text['confirm-delete']['pt-br'] = "Deseja realmente remover isto?";
+$text['confirm-delete']['pl'] = "Czy na pewno chcesz to usunąć?";
+$text['confirm-delete']['sv-se'] = "Vill du verkligen ta bort detta?";
+$text['confirm-delete']['uk'] = "Ви дійсно бажаєте це видалити?";
+$text['confirm-delete']['de-at'] = "Wollen Sie das wirklich löschen?";
+$text['confirm-delete']['ar-eg'] = "هل تريد حقا مسح هذا؟";
+
+$text['button-save']['en-us'] = "Save";
+$text['button-save']['es-cl'] = "Guardar";
+$text['button-save']['pt-pt'] = "Guardar";
+$text['button-save']['fr-fr'] = "Sauvegarder";
+$text['button-save']['pt-br'] = "Salvar";
+$text['button-save']['pl'] = "Zachowaj";
+$text['button-save']['sv-se'] = "Spara";
+$text['button-save']['uk'] = "Зберегти";
+$text['button-save']['de-at'] = "Speichern";
+$text['button-save']['ar-eg'] = "حفظ";
+
+$text['button-next']['en-us'] = "Next";
+$text['button-next']['es-cl'] = "";
+$text['button-next']['pt-pt'] = "";
+$text['button-next']['fr-fr'] = "";
+$text['button-next']['pt-br'] = "";
+$text['button-next']['pl'] = "";
+$text['button-next']['sv-se'] = "";
+$text['button-next']['uk'] = "";
+$text['button-next']['de-at'] = "";
+$text['button-next']['ar-eg'] = "";
+
+$text['button-detect']['en-us'] = "Detect Configuration";
+$text['button-detect']['es-cl'] = "";
+$text['button-detect']['pt-pt'] = "";
+$text['button-detect']['fr-fr'] = "";
+$text['button-detect']['pt-br'] = "";
+$text['button-detect']['pl'] = "";
+$text['button-detect']['sv-se'] = "";
+$text['button-detect']['uk'] = "";
+$text['button-detect']['de-at'] = "";
+$text['button-detect']['ar-eg'] = "";
+
+$text['button-select']['en-us'] = "Select";
+$text['button-select']['es-cl'] = "";
+$text['button-select']['pt-pt'] = "";
+$text['button-select']['fr-fr'] = "";
+$text['button-select']['pt-br'] = "";
+$text['button-select']['pl'] = "";
+$text['button-select']['sv-se'] = "";
+$text['button-select']['uk'] = "";
+$text['button-select']['de-at'] = "";
+$text['button-select']['ar-eg'] = "";
+
+$text['button-edit']['en-us'] = "Edit";
+$text['button-edit']['es-cl'] = "Editar";
+$text['button-edit']['pt-pt'] = "Editar";
+$text['button-edit']['fr-fr'] = "Editer";
+$text['button-edit']['pt-br'] = "Editar";
+$text['button-edit']['pl'] = "Edytuj";
+$text['button-edit']['sv-se'] = "Editera";
+$text['button-edit']['uk'] = "Редагувати";
+$text['button-edit']['de-at'] = "Bearbeiten";
+$text['button-edit']['ar-eg'] = "تعديل";
+
+$text['button-delete']['en-us'] = "Delete";
+$text['button-delete']['es-cl'] = "Eliminar";
+$text['button-delete']['pt-pt'] = "Remover";
+$text['button-delete']['fr-fr'] = "Supprimé";
+$text['button-delete']['pt-br'] = "Remover";
+$text['button-delete']['pl'] = "Usuń";
+$text['button-delete']['sv-se'] = "Ta Bort";
+$text['button-delete']['uk'] = "Видалити";
+$text['button-delete']['de-at'] = "Löschen";
+$text['button-delete']['ar-eg'] = "مسح";
+
+$text['button-back']['en-us'] = "Back";
+$text['button-back']['es-cl'] = "Volver";
+$text['button-back']['pt-pt'] = "Voltar";
+$text['button-back']['fr-fr'] = "Retour";
+$text['button-back']['pt-br'] = "Voltar";
+$text['button-back']['pl'] = "Wróć";
+$text['button-back']['sv-se'] = "Tillbaka";
+$text['button-back']['uk'] = "Назад";
+$text['button-back']['de-at'] = "Zurück";
+$text['button-back']['ar-eg'] = "رجوع";
+
+$text['button-add']['en-us'] = "Add";
+$text['button-add']['es-cl'] = "Agregar";
+$text['button-add']['pt-pt'] = "Adicionar";
+$text['button-add']['fr-fr'] = "Ajouter";
+$text['button-add']['pt-br'] = "Adicionar";
+$text['button-add']['pl'] = "Dodaj";
+$text['button-add']['sv-se'] = "Lägg Till";
+$text['button-add']['uk'] = "Додати";
+$text['button-add']['de-at'] = "Hinzufügen";
+$text['button-add']['ar-eg'] = "اضافة";
+
+$text['button-install_execute']['en-us'] = "Execute";
+$text['button-install_execute']['es-cl'] = "Ejecutar";
+$text['button-install_execute']['pt-pt'] = "Executar";
+$text['button-install_execute']['fr-fr'] = "Exécuter";
+$text['button-install_execute']['pt-br'] = "Executar";
+$text['button-install_execute']['pl'] = "Wykonaj";
+$text['button-install_execute']['sv-se'] = "Kör";
+$text['button-install_execute']['uk'] = "Виконати";
+$text['button-install_execute']['de-at'] = "Ausführen";
+
+?>

+ 10 - 0
core/install/app_menu.php

@@ -0,0 +1,10 @@
+<?php
+
+//$apps[$x]['menu'][0]['title']['en-us'] = "Install";
+//$apps[$x]['menu'][0]['uuid'] = "75507e6e-891e-11e5-af63-feff819cdc9f";
+//$apps[$x]['menu'][0]['parent_uuid'] = "594d99c5-6128-9c88-ca35-4b33392cec0f";
+//$apps[$x]['menu'][0]['category'] = "internal";
+//$apps[$x]['menu'][0]['path'] = "/core/install/index.php";
+//$apps[$x]['menu'][0]['groups'][] = "superadmin";
+
+?>

+ 83 - 0
core/install/index.php

@@ -0,0 +1,83 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+	Matthew Vale <[email protected]>
+*/
+require_once "root.php";
+require_once "resources/require.php";
+require_once "resources/check_auth.php";
+
+//detect install state
+
+$first_time_install = true;
+if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
+	$first_time_install = false;
+} elseif (file_exists("/etc/fusionpbx/config.php")) {
+	//linux
+	$first_time_install = false;
+} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
+	$first_time_install = false;
+}
+
+if($first_time_install) {
+	header("Location: ".PROJECT_PATH."/core/install/install_first_time.php");
+	exit;
+}
+require_once "resources/check_auth.php";
+if (!if_group("superadmin")) {
+	echo "access denied";
+	exit;
+}
+
+//add multi-lingual support
+	$language = new text;
+	$text = $language->get();
+
+//includes and title
+	require_once "resources/header.php";
+	$document['title'] = $text['title-install'];
+
+	echo "<b>".$text['header-install']."</b>";
+	echo "<br><br>";
+	echo $text['description-install'];
+	echo "<br><br>";
+	
+	echo "<form name='frm' method='post' action='/core/install/install_first_time.php'>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "	<td width='30%' class='vncell'>\n";
+	echo "		<input id='do_ft-install' type='submit' class='btn' value='".$text['label-ft-install']."'/>";
+	echo "	</td>\n";
+	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
+	echo "		<label for='do_ft-install'>";
+	echo "			".$text['description-ft-install'];
+	echo "		</label>\n";
+	echo "	</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+	echo "</form>\n";
+
+//include the footer
+	require_once "resources/footer.php";
+?>

+ 390 - 0
core/install/install_first_time.php

@@ -0,0 +1,390 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2015
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+	Matthew Vale <[email protected]>
+*/
+require_once "root.php";
+require_once "resources/functions.php";
+require_once "resources/classes/text.php";
+
+//initialize variables we are going to use
+	$event_host = '';
+	$event_port = '';
+	$event_password = '';
+	$install_language = 'en-us';
+	$admin_username = '';
+	$admin_password = '';
+	$install_default_country = 'US';
+	$install_template_name = '';
+	$domain_name = '';
+	$db_type = '';
+	$db_path = '';
+	$db_host = '';
+	$db_port = '';
+	$db_name = '';
+	$db_username = '';
+	$db_password = '';
+	$db_create = '';
+	$db_create_username = '';
+	$db_create_password = '';
+
+//detect the iso country code from the locale
+//TBD $locale = Locale::getDefault();
+$timezone = 'UTC';
+if (is_link('/etc/localtime')) {
+    // Mac OS X (and older Linuxes)    
+    // /etc/localtime is a symlink to the 
+    // timezone in /usr/share/zoneinfo.
+    $filename = readlink('/etc/localtime');
+    if (strpos($filename, '/usr/share/zoneinfo/') === 0) {
+        $timezone = substr($filename, 20);
+    }
+} elseif (file_exists('/etc/timezone')) {
+    // Ubuntu / Debian.
+    $data = file_get_contents('/etc/timezone');
+    if ($data) {
+        $timezone = rtrim($data);
+    }
+} elseif (file_exists('/etc/sysconfig/clock')) {
+    // RHEL / CentOS
+    $data = parse_ini_file('/etc/sysconfig/clock');
+    if (!empty($data['ZONE'])) {
+        $timezone = $data['ZONE'];
+    }
+}
+ 
+date_default_timezone_set($timezone);
+
+//detect install state
+$first_time_install = true;
+if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
+	$first_time_install = false;
+} elseif (file_exists("/etc/fusionpbx/config.php")) {
+	$first_time_install = false;
+} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
+	$first_time_install = false;
+}
+
+if(!$first_time_install) {
+	require_once "resources/require.php";
+	require_once "resources/check_auth.php";
+	if (!if_group("superadmin")) {
+		echo "access denied";
+		exit;
+	}
+}
+
+$install_step = '';
+$return_install_step = '';
+
+if (count($_POST) > 0) {
+	$install_language = check_str($_POST["install_language"]);
+	$install_step = check_str($_POST["install_step"]);
+	$return_install_step = check_str($_POST["return_install_step"]);
+	if(isset($_POST["event_host"])){
+		$event_host		= check_str($_POST["event_host"]);
+		$event_port		= check_str($_POST["event_port"]);
+		$event_password	= check_str($_POST["event_password"]);
+	}
+	if(isset($_POST["db_type"])){
+		$db_type					= $_POST["db_type"];
+		$admin_username				= $_POST["admin_username"];
+		$admin_password				= $_POST["admin_password"];
+		$install_default_country	= $_POST["install_default_country"];
+		$install_template_name		= $_POST["install_template_name"];
+		$domain_name				= $_POST["domain_name"];
+	}
+}
+
+if(!$install_step) { $install_step = 'select_language'; }
+
+	$_SESSION['domain']['language']['code'] = $install_language;
+
+//add multi-lingual support
+	$language = new text;
+	$text = $language->get();
+
+//set a default template
+	$default_template = 'enhanced';
+	if (isset($_SESSION['domain']['template']['name']) and strlen($_SESSION['domain']['template']['name']) != 0) {
+		$default_template = $_SESSION['domain']['template']['name'];
+	}
+
+//set a default enviroment if first_time
+	if($first_time_install){
+	//initialize some varibles to cut down on warnings
+		$_SESSION['message'] = '';
+		$v_link_label_play = '';
+		$v_link_label_pause = '';
+		$default_login = 0;
+		$onload = '';
+	}
+
+//get the contents of the template and save it to the template variable
+	$template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$default_template.'/template.php');
+
+//buffer the content
+	ob_end_clean(); //clean the buffer
+	ob_start();
+
+	$messages = array();
+	if (!extension_loaded('PDO')) {
+		$messages[] = "<b>PHP PDO was not detected</b>. Please install it before proceeding";
+	}
+
+	echo "<div align='center'>\n";
+	$msg = '';
+	//make sure the includes directory is writable so the config.php file can be written.
+		if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/pdo.php")) {
+			$messages[] = "<b>Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."</b> and its sub-directories are required during the install.";
+		}
+	//test for selinux
+		if (file_exists('/usr/sbin/getenforce')) {
+			$enforcing;
+			exec('getenforce', $enforcing);
+			if($enforcing[0] == 'Enforcing'){
+				$messages[] = "<b>SELinux is enabled and enforcing</b> you must have a policy installed to let the webserver connect to the switch event socket<br/>".
+				"<sm>You can use the following to find what ports are allowed<pre>semanage port -l | grep '^http_port_t'</pre></sm>";
+			}
+		}
+	//test for windows and non sqlite
+		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' and strlen($db_type) > 0 and $db_type !='sqlite') {
+			$messages[] = "<b>Windows requires a system DSN ODBC connection</b> this must be configured.";
+		}
+
+	//action code
+	if($return_install_step == 'config_detail'){
+	//check for all required data
+		$existing_errors = count($messages);
+		if (strlen($admin_username) == 0) { $messages[] = "Please provide the Admin Username"; }
+		if (strlen($admin_password) == 0) {	$messages[] = "Please provide the Admin Password"; }
+		elseif (strlen($admin_password) < 5) { $messages[] = "Please provide an Admin Password that is 5 or more characters.<br>\n"; }
+		if ( count($messages) > $existing_errors) { $install_step = 'config_detail'; }
+	}
+
+	if($install_step =='execute')
+	{
+		//start the rocket launch!
+		
+		//set the max execution time to 1 hour
+		ini_set('max_execution_time',3600);
+	}
+
+	//display messages
+	if (count($messages)>0) {
+		echo "<br />\n";
+		echo "<div align='center'>\n";
+		echo "<table width='75%'>\n";
+		echo "<tr>\n";
+		echo "<th align='left'>Messages</th>\n";
+		echo "</tr>\n";
+		echo "<tr>\n";
+		echo "<td class='row_style1'><strong><ul>\n";
+		foreach ($messages as $message){
+			echo "<li>$message</li>\n";
+		}
+		echo "</ul></strong></td>\n";
+		echo "</tr>\n";
+		echo "</table>\n";
+		echo "</div>\n";
+	}
+
+//includes and title
+	$document['title'] = $text['title-install_first_time'];
+
+	//view code
+	if($install_step == 'select_language'){
+		include "resources/page_parts/install_select_language.php";
+		echo "<form method='post' name='frm' action=''>\n";
+		echo "	<input type='hidden' name='install_language' value='".$_SESSION['domain']['language']['code']."'/>\n";
+		echo "	<input type='hidden' name='return_install_step' value='select_language'/>\n";
+		echo "	<input type='hidden' name='install_step' value='detect_config'/>\n";
+		echo "	<div style='text-align:right'>\n";
+		echo "    <button type='submit' id='next'>".$text['button-next']."</button>\n";
+		echo "	</div>\n";
+		echo "</form>\n";
+	}elseif($install_step == 'detect_config'){
+		if(!($event_host == '' || $event_host == 'localhost' || $event_host == '::1' || $event_host == '127.0.0.1' )){
+			echo "<p><b>Warning</b> you have choosen a value other than localhost for event_host, this is unsoported at present</p>\n";
+		}
+		include "resources/page_parts/install_event_socket.php";
+		if($detect_ok){
+			echo "<form method='post' name='frm' action=''>\n";
+			echo "	<input type='hidden' name='install_language' value='".$_SESSION['domain']['language']['code']."'/>\n";
+			echo "	<input type='hidden' name='return_install_step' value='detect_config'/>\n";
+			echo "	<input type='hidden' name='install_step' value='config_detail'/>\n";
+			echo "	<input type='hidden' name='event_host' value='$event_host'/>\n";
+			echo "	<input type='hidden' name='event_port' value='$event_port'/>\n";
+			echo "	<input type='hidden' name='event_password' value='$event_password'/>\n";
+			echo "	<div style='text-align:right'>\n";
+			echo "    <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
+			echo "    <button type='submit' id='next'>".$text['button-next']."</button>\n";
+			echo "	</div>\n";
+			echo "</form>\n";
+		}else{
+			echo "<form method='post' name='frm' action=''>\n";
+			echo "	<div style='text-align:right'>\n";
+			echo "    <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
+			echo "	</div>\n";
+			echo "</form>\n";
+		}
+	}
+	elseif($install_step == 'config_detail'){
+		if(!$domain_name){
+		//get the domain
+			$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
+			$domain_name = $domain_array[0];
+		}
+		include "resources/page_parts/install_config_detail.php";
+	}
+	elseif($install_step == 'config_database'){
+		include "resources/page_parts/install_config_database.php";
+	}
+	elseif($install_step == 'execute'){
+		echo "<p><b>".$text['header-installing']."</b></p>\n";
+		//$protocol = 'http';
+		//if($_SERVER['HTTPS']) { $protocol = 'https'; }
+		//echo "<iframe src='$protocol://$domain_name/core/install/install_first_time.php' style='border:solid 1px #000;width:100%;height:auto'></iframe>";
+		require_once "core/install/resources/classes/detect_switch.php";
+		$detect_switch = new detect_switch($event_host, $event_port, $event_password);
+		$detect_ok = true;
+		try {
+			$detect_switch->detect();
+		} catch(Exception $e){
+			echo "<p>Failed to detect configuration detect_switch reported: " . $e->getMessage() . "</p>\n";
+			$detect_ok = false;
+		}
+		if($detect_ok){
+			$install_ok = true;
+			echo "<pre style='text-align:left;'>\n";
+			function error_handler($err_severity, $errstr, $errfile, $errline ) {
+				if (0 === error_reporting()) { return false;}
+				switch($err_severity)
+				{
+					case E_ERROR:               throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_PARSE:               throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_CORE_ERROR:          throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_COMPILE_ERROR:       throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_USER_ERROR:          throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_STRICT:              throw new Exception ($errstr . " in $errfile line: $errline");
+					case E_RECOVERABLE_ERROR:   throw new Exception ($errstr . " in $errfile line: $errline");
+					default: 					return false;
+				}
+			}
+			#set_error_handler("error_handler");
+			try {
+				require_once "resources/classes/global_settings.php";
+				$global_settings = new global_settings($detect_switch, $domain_name);
+				if(is_null($global_settings)){ throw new Exception("Error global_settings came back with null");	}
+				require_once "resources/classes/install_fusionpbx.php";
+				$system = new install_fusionpbx($global_settings);
+				$system->admin_username = $admin_username;
+				$system->admin_password = $admin_password;
+				$system->default_country = $install_default_country;
+				$system->install_language = $install_language;
+				$system->template_name = $install_template_name;
+
+				require_once "resources/classes/install_switch.php";
+				$switch = new install_switch($global_settings);
+				//$switch->debug = true;
+				//$system->debug = true;
+				$switch->echo_progress = true;
+				$system->echo_progress = true;
+				$system->install_phase_1();
+				$switch->install_phase_1();
+				$system->install_phase_2();
+				$switch->install_phase_2();
+			}catch(Exception $e){
+				echo "</pre>\n";
+				echo "<p><b>Failed to install</b><br/>" . $e->getMessage() . "</p>\n";
+				try {
+					require_once "resources/classes/install_fusionpbx.php";
+					$system = new install_fusionpbx($global_settings);
+					$system->remove_config();
+				}catch(Exception $e){
+					echo "<p><b>Failed to remove config:</b> " . $e->getMessage() . "</p>\n";
+				}
+				$install_ok = false;
+			}
+			restore_error_handler();
+			if($install_ok){
+				echo "</pre>\n";
+				header("Location: ".PROJECT_PATH."/logout.php");
+				$_SESSION['message'] = 'Install complete';
+			}else{
+				echo "<form method='post' name='frm' action=''>\n";
+				echo "	<div style='text-align:right'>\n";
+				echo "    <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
+				echo "    <button type='button' onclick=\"location.reload(true);\">".$text['button-install_execute']."</button>\n";
+				echo "	</div>\n";
+				echo "</form>\n";
+			}
+		}
+	}else{
+		echo "<p>Unkown install_step '$install_step'</p>\n";
+	}
+
+if($first_time_install){
+	//grab the default theme
+		$set_session_theme = 1;
+		$domains_processed = 1;
+		include "themes/enhanced/app_defaults.php";
+		unset($set_session_theme, $domains_processed);
+	//initialize some defaults so we can be 'logged in'
+		$_SESSION['username'] = 'first_time_install';
+		$_SESSION['permissions'][]['permission_name'] = 'superadmin';
+		$_SESSION['menu'] = '';
+}
+
+// add the content to the template and then send output
+	$body = ob_get_contents(); //get the output from the buffer
+	ob_end_clean(); //clean the buffer
+
+	//replace known used constants
+	$body = str_replace ("<!--{project_path}-->", PROJECT_PATH, $body); //defined in /resources/menu.php
+
+	ob_start();
+	eval('?>' . $template . '<?php ');
+	$template = ob_get_contents(); //get the output from the buffer
+	ob_end_clean(); //clean the buffer
+
+	$custom_head = '';
+	$output = str_replace ("<!--{title}-->", $document['title'], $template); //<!--{title}--> defined in each individual page
+	$output = str_replace ("<!--{head}-->", $custom_head, $output); //<!--{head}--> defined in each individual page
+	$output = str_replace ("<!--{menu}-->", $_SESSION["menu"], $output); //defined in /resources/menu.php
+	$output = str_replace ("<!--{project_path}-->", PROJECT_PATH, $output); //defined in /resources/menu.php
+
+	$pos = strrpos($output, "<!--{body}-->");
+	if ($pos === false) {
+		$output = $body; //if tag not found just show the body
+	}
+	else {
+		//replace the body
+		$output = str_replace ("<!--{body}-->", $body, $output);
+	}
+
+	echo $output;
+	unset($output);
+
+?>

+ 173 - 0
core/install/resources/classes/detect_switch.php

@@ -0,0 +1,173 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2010-2015
+	All Rights Reserved.
+
+	Contributor(s):
+	Matthew Vale <[email protected]>
+	
+*/
+require_once "root.php";
+require_once "resources/classes/EventSocket.php";
+
+//define the install class
+	class detect_switch {
+
+		// cached data
+		protected $_dirs;
+		protected $_vdirs;
+		public function get_dirs()	{ return $this->_dirs; }
+		public function get_vdirs()	{ return $this->_vdirs; }
+
+		// version information
+		protected $_major;
+		protected $_minor;
+		protected $_build;
+		public function major()		{ return $this->_major; }
+		public function minor()		{ return $this->_minor; }
+		public function build()		{ return $this->_build; }
+		public function version()	{ return $this->_major.".".$this->_minor.".".$this->_build; }
+
+		// dirs - detected by from the switch
+		protected $_base_dir = '';
+		protected $_cache_dir = '';
+		protected $_certs_dir = '';
+		protected $_conf_dir = '';
+		protected $_db_dir = '';
+		protected $_external_ssl_dir = '';
+		protected $_grammar_dir = '';
+		protected $_htdocs_dir = '';
+		protected $_internal_ssl_dir = '';
+		protected $_log_dir = '';
+		protected $_mod_dir = '';
+		protected $_recordings_dir = '';
+		protected $_run_dir = '';
+		protected $_script_dir = '';
+		protected $_sounds_dir = '';
+		protected $_storage_dir = '';
+		protected $_temp_dir = '';
+		public function base_dir()			{ return $this->_base_dir; }
+		public function cache_dir()			{ return $this->_cache_dir; }
+		public function certs_dir()			{ return $this->_certs_dir; }
+		public function conf_dir()			{ return $this->_conf_dir; }
+		public function db_dir()			{ return $this->_db_dir; }
+		public function external_ssl_dir()	{ return $this->_external_ssl_dir; }
+		public function grammar_dir()		{ return $this->_grammar_dir; }
+		public function htdocs_dir()		{ return $this->_htdocs_dir; }
+		public function internal_ssl_dir()	{ return $this->_internal_ssl_dir; }
+		public function log_dir()			{ return $this->_log_dir; }
+		public function mod_dir()			{ return $this->_mod_dir; }
+		public function recordings_dir()	{ return $this->_recordings_dir; }
+		public function run_dir()			{ return $this->_run_dir; }
+		public function script_dir()		{ return $this->_script_dir; }
+		public function sounds_dir()		{ return $this->_sounds_dir; }
+		public function storage_dir()		{ return $this->_storage_dir; }
+		public function temp_dir()			{ return $this->_temp_dir; }
+
+		// virtual dirs - assumed based on the detected dirs
+		protected $_voicemail_vdir = '';
+		protected $_phrases_vdir = '';
+		protected $_extensions_vdir = '';
+		protected $_sip_profiles_vdir = '';
+		protected $_dialplan_vdir = '';
+		protected $_backup_vdir = '';
+		public function voicemail_vdir()	{ return $this->_voicemail_vdir; }
+		public function phrases_vdir()		{ return $this->_phrases_vdir; }
+		public function extensions_vdir()	{ return $this->_extensions_vdir; }
+		public function sip_profiles_vdir()	{ return $this->_sip_profiles_vdir; }
+		public function dialplan_vdir()		{ return $this->_dialplan_vdir; }
+		public function backup_vdir()		{ return $this->_backup_vdir; }
+
+		// event socket
+		public $event_host = 'localhost';
+		public $event_port = '8021';
+		public $event_password = 'ClueCon';
+		protected $event_socket;
+
+		public function __construct($event_host, $event_port, $event_password) {
+			//do not take these settings from session as they be detecting a new switch
+			if($event_host){		$this->event_host = $event_host; }
+			if($event_port){		$this->event_port = $event_port; }
+			if($event_password){	$this->event_password = $event_password; }
+			$this->connect_event_socket();
+			if(!$this->event_socket){
+				$this->detect_event_socket();
+			}
+			$this->_dirs = preg_grep ('/.*_dir$/', get_class_methods('detect_switch') );
+			sort( $this->_dirs );
+			$this->_vdirs = preg_grep ('/.*_vdir$/', get_class_methods('detect_switch') );
+			sort( $this->_vdirs );
+		}
+
+		protected function detect_event_socket() {
+			//perform searches for user's config here
+		}
+
+		public function detect() {
+			$this->connect_event_socket();
+			if(!$this->event_socket){
+				throw new Exception('Failed to use event socket');
+			}
+			$FS_Version = $this->event_socket_request('api version');
+			preg_match("/FreeSWITCH Version (\d+)\.(\d+)\.(\d+(?:\.\d+)?)/", $FS_Version, $matches);
+			$this->_major = $matches[1];
+			$this->_minor = $matches[2];
+			$this->_build = $matches[3];
+			$FS_Vars = $this->event_socket_request('api global_getvar');
+			foreach (explode("\n",$FS_Vars) as $FS_Var){
+				preg_match("/(\w+_dir)=(.*)/", $FS_Var, $matches);
+				if(count($matches) > 0 and property_exists($this, "_" . $matches[1])){
+					$field = "_" . $matches[1];
+					$this->$field = normalize_path($matches[2]);
+				}
+			}
+			$this->_voicemail_vdir = 	normalize_path($this->_storage_dir . DIRECTORY_SEPARATOR . "voicemail");
+			$this->_phrases_vdir = 		normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "lang");
+			$this->_extensions_vdir = 	normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "directory");
+			$this->_sip_profiles_vdir =	normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "sip_profiles");
+			$this->_dialplan_vdir =		normalize_path($this->_conf_dir . DIRECTORY_SEPARATOR . "dialplan");
+			$this->_backup_vdir =		normalize_path(sys_get_temp_dir());
+		}	
+	
+		protected function connect_event_socket(){
+			$esl = new EventSocket;
+			if ($esl->connect($this->event_host, $this->event_port, $this->event_password)) {
+				$this->event_socket = $esl->reset_fp();
+				return true;
+			}
+			return false;
+		}
+	
+		protected function event_socket_request($cmd) {
+			$esl = new EventSocket($this->event_socket);
+			$result = $esl->request($cmd);
+			$esl->reset_fp();
+			return $result;
+		}
+		
+		public function restart_switch() {
+			$this->connect_event_socket();
+			if(!$this->event_socket){
+				throw new Exception('Failed to use event socket');
+			}
+			$this->event_socket_request('api fsctl shutdown restart elegant');
+		}
+	}
+?>

+ 223 - 0
core/install/resources/classes/global_settings.php

@@ -0,0 +1,223 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2010-2015
+	All Rights Reserved.
+
+	Contributor(s):
+	Matthew Vale <[email protected]>
+	
+*/
+require_once "root.php";
+
+//define the install class
+	class global_settings {
+
+		// cached data
+		protected $_switch_dirs;
+		protected $_switch_vdirs;
+		public function get_switch_dirs()	{ return $this->_switch_dirs; }
+		public function get_switch_vdirs()	{ return $this->_switch_vdirs; }
+
+		// dirs - detected from the switch
+		protected $_switch_base_dir = '';
+		protected $_switch_cache_dir = '';
+		protected $_switch_certs_dir = '';
+		protected $_switch_conf_dir = '';
+		protected $_switch_db_dir = '';
+		protected $_switch_external_ssl_dir = '';
+		protected $_switch_grammar_dir = '';
+		protected $_switch_htdocs_dir = '';
+		protected $_switch_internal_ssl_dir = '';
+		protected $_switch_log_dir = '';
+		protected $_switch_mod_dir = '';
+		protected $_switch_recordings_dir = '';
+		protected $_switch_run_dir = '';
+		protected $_switch_script_dir = '';
+		protected $_switch_sounds_dir = '';
+		protected $_switch_storage_dir = '';
+		protected $_switch_temp_dir = '';
+		public function switch_base_dir()			{ return $this->_switch_base_dir; }
+		public function switch_cache_dir()			{ return $this->_switch_cache_dir; }
+		public function switch_certs_dir()			{ return $this->_switch_certs_dir; }
+		public function switch_conf_dir()			{ return $this->_switch_conf_dir; }
+		public function switch_db_dir()				{ return $this->_switch_db_dir; }
+		public function switch_external_ssl_dir()	{ return $this->_switch_external_ssl_dir; }
+		public function switch_grammar_dir()		{ return $this->_switch_grammar_dir; }
+		public function switch_htdocs_dir()			{ return $this->_switch_htdocs_dir; }
+		public function switch_internal_ssl_dir()	{ return $this->_switch_internal_ssl_dir; }
+		public function switch_log_dir()			{ return $this->_switch_log_dir; }
+		public function switch_mod_dir()			{ return $this->_switch_mod_dir; }
+		public function switch_recordings_dir()		{ return $this->_switch_recordings_dir; }
+		public function switch_run_dir()			{ return $this->_switch_run_dir; }
+		public function switch_script_dir()			{ return $this->_switch_script_dir; }
+		public function switch_sounds_dir()			{ return $this->_switch_sounds_dir; }
+		public function switch_storage_dir()		{ return $this->_switch_storage_dir; }
+		public function switch_temp_dir()			{ return $this->_switch_temp_dir; }
+
+		// virtual dirs - assumed based on the detected dirs
+		protected $_switch_voicemail_vdir = '';
+		protected $_switch_phrases_vdir = '';
+		protected $_switch_extensions_vdir = '';
+		protected $_switch_sip_profiles_vdir = '';
+		protected $_switch_dialplan_vdir = '';
+		protected $_switch_backup_vdir = '';
+		public function switch_voicemail_vdir()		{ return $this->_switch_voicemail_vdir; }
+		public function switch_phrases_vdir()		{ return $this->_switch_phrases_vdir; }
+		public function switch_extensions_vdir()	{ return $this->_switch_extensions_vdir; }
+		public function switch_sip_profiles_vdir()	{ return $this->_switch_sip_profiles_vdir; }
+		public function switch_dialplan_vdir()		{ return $this->_switch_dialplan_vdir; }
+		public function switch_backup_vdir()		{ return $this->_switch_backup_vdir; }
+
+		// event socket
+		protected $_switch_event_host;
+		protected $_switch_event_port;
+		protected $_switch_event_password;
+		public function switch_event_host()		{ return $this->_switch_event_host; }
+		public function switch_event_port()		{ return $this->_switch_event_port; }
+		public function switch_event_password()	{ return $this->_switch_event_password; }
+
+		// database information
+		protected $_db_type;
+		protected $_db_path;
+		protected $_db_host;
+		protected $_db_port;
+		protected $_db_name;
+		protected $_db_username;
+		protected $_db_password;
+		protected $_db_create;
+		protected $_db_create_username;
+		protected $_db_create_password;
+		public function db_type()	 			{ return $this->_db_type; }
+		public function db_path()	 			{ return $this->_db_path; }
+		public function db_host()	 			{ return $this->_db_host; }
+		public function db_port()	 			{ return $this->_db_port; }
+		public function db_name()	 			{ return $this->_db_name; }
+		public function db_username()	 		{ return $this->_db_username; }
+		public function db_password()	 		{ return $this->_db_password; }
+		public function db_create()	 			{ return $this->_db_create; }
+		public function db_create_username()	{ return $this->_db_create_username; }
+		public function db_create_password()	{ return $this->_db_create_password; }
+
+		//misc information
+		protected $_domain_uuid;
+		protected $_domain_name;
+		protected $_domain_count;
+		public function domain_uuid()	 		{ return $this->_domain_uuid; }
+		public function domain_name()	 		{ return $this->_domain_name; }
+		public function domain_count()	 		{ return $this->_domain_count; }
+		public function set_domain_uuid($domain_uuid) {
+			$e = new Exception();
+			$trace = $e->getTrace();
+			if($trace[1]['function'] != 'create_domain'){
+				throw new Exception('Only create_domain is allowed to update the domain_uuid');
+			}
+			$this->_domain_uuid = $domain_uuid;
+		}
+
+		public function __construct($detect_switch = null, $domain_name = null, $domain_uuid = null) {
+			$this->_switch_dirs = preg_grep ('/^switch_.*_dir$/', get_class_methods('global_settings') );
+			sort( $this->_switch_dirs );
+			$this->_switch_vdirs = preg_grep ('/^switch_.*_vdir$/', get_class_methods('global_settings') );
+			sort( $this->_switch_vdirs );
+			if(is_null($detect_switch)){
+				//take settings from session
+				if(!isset($_SESSION['switch'])){
+					throw new Exception("No detect_switch was passed to me but \$_SESSION['switch'] is empty!");
+				}
+				foreach ($this->_switch_dirs as $dir){
+					$category = 'switch';
+					$session_var;
+					preg_match( '/^switch_(.*)_dir$/', $dir, $session_var);
+					$dir = "_$dir";
+					if($session_var[1] == 'script'){ $session_var[1] = 'scripts'; }
+					if($session_var[1] == 'temp'){ $category = 'server'; }
+					$this->$dir = $_SESSION[$category][$session_var[1]]['dir'];
+				}
+				foreach ($this->_switch_vdirs as $vdir){
+					$category = 'switch';
+					$session_var;
+					preg_match( '/^switch_(.*)_vdir$/', $vdir, $session_var);
+					$vdir = "_$vdir";
+					if($session_var[1] == 'backup'){ $category = 'server'; }
+					$this->$vdir = $_SESSION[$category][$session_var[1]]['dir'];
+				}
+				$this->_switch_event_host		= $_SESSION['event_socket_ip_address'];
+				$this->_switch_event_port		= $_SESSION['event_socket_port'];
+				$this->_switch_event_password	= $_SESSION['event_socket_password'];
+
+				// domain info
+				$this->_domain_name = $_SESSION['domain_name'];
+				$this->_domain_uuid = $_SESSION['domain_uuid'];
+
+				// collect misc info
+				$this->_domain_count = count($_SESSION["domains"]);
+
+				// collect db_info
+				global $db_type, $db_path, $db_host, $db_port, $db_name, $db_username, $db_password;
+				$this->_db_type = $db_type;
+				$this->_db_path = $db_path;
+				$this->_db_host = $db_host;
+				$this->_db_port = $db_port;
+				$this->_db_name = $db_name;
+				$this->_db_username = $db_username;
+				$this->_db_password = $db_password;
+
+			}elseif(!is_a($detect_switch, 'detect_switch')){
+				throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
+
+			}else{
+				//copy from detect_switch
+				foreach($detect_switch->get_dirs() as $dir){
+					$t_dir = "_switch_$dir";
+					$this->$t_dir = $detect_switch->$dir();
+				}
+				foreach($detect_switch->get_vdirs() as $vdir){
+					$t_vdir = "_switch_$vdir";
+					$this->$t_vdir = $detect_switch->$vdir();
+				}
+				$this->_switch_event_host		= $detect_switch->event_host;
+				$this->_switch_event_port		= $detect_switch->event_port;
+				$this->_switch_event_password	= $detect_switch->event_password;
+
+				//copy from _POST
+				foreach($_POST as $key=>$value){
+					if(substr($key,0,3) == "db_"){
+						$o_key = "_$key";
+						$this->$o_key = $value;
+					}
+				}
+				if($this->_db_create and strlen($this->_db_create_username) == 0)
+				{
+					$this->_db_create_username = $this->_db_username;
+					$this->_db_create_password = $this->_db_password;
+				}
+				if (strlen($this->_db_port) == 0) { $this->_db_port = "5432"; }
+
+				// domain info
+				if(strlen($domain_uuid) == 0){ $domain_uuid = uuid(); }
+				$this->_domain_name = $domain_name;
+				$this->_domain_uuid = $domain_uuid;
+
+				//collect misc info
+				$this->_domain_count = 1;	//assumed to be one
+			}
+		}
+	}
+?>

+ 1124 - 0
core/install/resources/classes/install_fusionpbx.php

@@ -0,0 +1,1124 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2010-2015
+	All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+	Matthew Vale <[email protected]>
+*/
+include "root.php";
+
+//define the install class
+	class install_fusionpbx {
+
+		protected $global_settings;
+		protected $config_php;
+		protected $menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
+		protected $dbh;
+
+		public $debug = false;
+		public $echo_progress = false;
+
+	 	public $install_language = 'en-us';
+	 	public $admin_username;
+	 	public $admin_password;
+	 	public $default_country = 'US';
+		public $template_name = 'enhanced';
+
+	 	function __construct($global_settings) {
+			if(is_null($global_settings)){
+				require_once "resources/classes/global_settings.php";
+				$global_settings = new global_settings();
+			}elseif(!is_a($global_settings, 'global_settings')){
+				throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
+			}
+			$this->global_settings = $global_settings;
+			if (is_dir("/etc/fusionpbx")){
+				$this->config_php = "/etc/fusionpbx/config.php";
+			} elseif (is_dir("/usr/local/etc/fusionpbx")){
+				$this->config_php = "/usr/local/etc/fusionpbx/config.php";
+			}
+			elseif (is_dir($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources")) {
+				$this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
+			}
+			else {
+				$this->config_php = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
+			}
+			$this->config_php = normalize_path_to_os($this->config_php);
+		}
+
+		function write_debug($message) {
+			if($this->debug){
+				echo "$message\n";
+			}
+		}
+		
+		function write_progress($message) {
+			if($this->echo_progress){
+				echo "$message\n";
+			}
+		}
+
+		function install_phase_1() {
+			ini_set('max_execution_time',3600);
+			$this->write_progress("Install phase 1 started for FusionPBX");
+			$this->create_config_php();
+			$this->write_progress("\tExecuting config.php");
+			require $this->config_php;
+			global $db;
+			$db = $this->dbh;
+			$this->create_database();
+			$this->create_domain();
+			$this->create_superuser();
+			$this->write_progress("\tRunning requires");
+			require "resources/require.php";
+			$this->create_menus();
+			$this->write_progress("Install phase 1 complete for FusionPBX");
+		}
+		
+		function install_phase_2() {
+			ini_set('max_execution_time',3600);
+			$this->write_progress("Install phase 2 started for FusionPBX");
+			$this->app_defaults();
+			$this->write_progress("Install phase 2 complete for FusionPBX");
+		}
+		
+		function upgrade() {
+			$this->app_defaults();
+		}
+
+		protected function create_config_php() {
+			$this->write_progress("\tCreating " . $this->config_php);
+			$tmp_config = "<?php\n";
+			$tmp_config .= "/* \$Id\$ */\n";
+			$tmp_config .= "/*\n";
+			$tmp_config .= "	config.php\n";
+			$tmp_config .= "	Copyright (C) 2008, 2013 Mark J Crane\n";
+			$tmp_config .= "	All rights reserved.\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "	Redistribution and use in source and binary forms, with or without\n";
+			$tmp_config .= "	modification, are permitted provided that the following conditions are met:\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "	1. Redistributions of source code must retain the above copyright notice,\n";
+			$tmp_config .= "	   this list of conditions and the following disclaimer.\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "	2. Redistributions in binary form must reproduce the above copyright\n";
+			$tmp_config .= "	   notice, this list of conditions and the following disclaimer in the\n";
+			$tmp_config .= "	   documentation and/or other materials provided with the distribution.\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\n";
+			$tmp_config .= "	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\n";
+			$tmp_config .= "	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n";
+			$tmp_config .= "	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n";
+			$tmp_config .= "	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n";
+			$tmp_config .= "	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n";
+			$tmp_config .= "	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n";
+			$tmp_config .= "	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n";
+			$tmp_config .= "	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n";
+			$tmp_config .= "	POSSIBILITY OF SUCH DAMAGE.\n";
+			$tmp_config .= "*/\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "//-----------------------------------------------------\n";
+			$tmp_config .= "// settings:\n";
+			$tmp_config .= "//-----------------------------------------------------\n";
+			$tmp_config .= "\n";
+			$tmp_config .= "	//set the database type\n";
+			$tmp_config .= "		\$db_type = '".$this->global_settings->db_type()."'; //sqlite, mysql, pgsql, others with a manually created PDO connection\n";
+			$tmp_config .= "\n";
+			if ($this->global_settings->db_type() == "sqlite") {
+				$tmp_config .= "	//sqlite: the db_name and db_path are automatically assigned however the values can be overidden by setting the values here.\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."'; //host name/ip address + '.db' is the default database filename\n";
+				$tmp_config .= "		\$db_path = '".$this->global_settings->db_path()."'; //the path is determined by a php variable\n";
+			}
+			$tmp_config .= "\n";
+			$tmp_config .= "	//mysql: database connection information\n";
+			if ($this->global_settings->db_type() == "mysql") {
+				$db_host = $this->global_settings->db_host();
+				if ( $db_host == "localhost") {
+					//if localhost is used it defaults to a Unix Socket which doesn't seem to work.
+					//replace localhost with 127.0.0.1 so that it will connect using TCP
+					$db_host = "127.0.0.1";
+				}
+				$tmp_config .= "		\$db_host = '".$db_host."';\n";
+				$tmp_config .= "		\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		\$db_password = '".$this->global_settings->db_password()."';\n";
+			}
+			else {
+				$tmp_config .= "		//\$db_host = '';\n";
+				$tmp_config .= "		//\$db_port = '';\n";
+				$tmp_config .= "		//\$db_name = '';\n";
+				$tmp_config .= "		//\$db_username = '';\n";
+				$tmp_config .= "		//\$db_password = '';\n";
+			}
+			$tmp_config .= "\n";
+			$tmp_config .= "	//pgsql: database connection information\n";
+			if ($this->global_settings->db_type() == "pgsql") {
+				$cmt_out = '';
+				if($this->global_settings->db_host() != 'localhost') { $cmt_out = "//"; }
+				$tmp_config .= "		$cmt_out\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n";
+				$tmp_config .= "		\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		\$db_password = '".$this->global_settings->db_password()."';\n";
+			}
+			else {
+				$tmp_config .= "		//\$db_host = '".$this->global_settings->db_host()."'; //set the host only if the database is not local\n";
+				$tmp_config .= "		//\$db_port = '".$this->global_settings->db_port()."';\n";
+				$tmp_config .= "		//\$db_name = '".$this->global_settings->db_name()."';\n";
+				$tmp_config .= "		//\$db_username = '".$this->global_settings->db_username()."';\n";
+				$tmp_config .= "		//\$db_password = '".$this->global_settings->db_password()."';\n";
+			}
+			$tmp_config .= "\n";
+			$tmp_config .= "	//show errors\n";
+			$tmp_config .= "		ini_set('display_errors', '1');\n";
+			$tmp_config .= "		//error_reporting (E_ALL); // Report everything\n";
+			$tmp_config .= "		//error_reporting (E_ALL ^ E_NOTICE); // Report everything\n";
+			$tmp_config .= "		error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings";
+			$tmp_config .= "\n";
+			$tmp_config .= "?>";
+
+			if((file_exists($this->config_php)
+				and !is_writable($this->config_php))
+				or !is_writable(dirname($this->config_php))
+				) {
+				throw new Exception("cannot write to '" . $this->config_php . "'" );
+			}
+			$fout = fopen($this->config_php,"w");
+			fwrite($fout, $tmp_config);
+			unset($tmp_config);
+			fclose($fout);
+		}
+
+		protected function create_database() {
+			$this->write_progress("\tUsing database as type " . $this->global_settings->db_type());
+			$function = "create_database_" . $this->global_settings->db_type();
+			$this->$function();
+
+			//sqlite is natively supported under all known OS'es
+			if($this->global_settings->db_type() != 'sqlite'){
+				if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
+				//non sqlite database support only uses ODBC under windows
+					$this->create_odbc_database_connection();
+				}elseif($this->global_settings->db_type() != 'pgsql'){
+				//switch supports postgresql natively
+					$this->create_odbc_database_connection();
+				}
+			}
+		}
+		
+		protected function create_odbc_database_connection() {
+		//needed for non native database support
+				$database_uuid = uuid();
+				$sql = "insert into v_databases ";
+				$sql .= "(";
+				$sql .= "database_uuid, ";
+				$sql .= "database_driver, ";
+				$sql .= "database_type, ";
+				$sql .= "database_host, ";
+				$sql .= "database_port, ";
+				$sql .= "database_name, ";
+				$sql .= "database_username, ";
+				$sql .= "database_password, ";
+				$sql .= "database_path, ";
+				$sql .= "database_description ";
+				$sql .= ")";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'$database_uuid', ";
+				$sql .= "'odbc', ";
+				$sql .= "'".$this->global_settings->db_type()."', ";
+				$sql .= "'".$this->global_settings->db_host()."', ";
+				$sql .= "'".$this->global_settings->db_port()."', ";
+				$sql .= "'".$this->global_settings->db_name()."', ";
+				$sql .= "'".$this->global_settings->db_username()."', ";
+				$sql .= "'".$this->global_settings->db_password()."', ";
+				$sql .= "'".$this->global_settings->db_path()."', ";
+				$sql .= "'Created by installer' ";
+				$sql .= ")";
+				if($this->dbh->exec(check_sql($sql)) === false){
+					throw new Exception("Failed to create odbc_database entery: " . join(":", $this->dbh->errorInfo()));
+				}
+				unset($sql);
+		}
+
+		protected function create_database_sqlite() {
+		//sqlite database will be created when the config.php is loaded and only if the database file does not exist
+			try {
+				$this->dbh = new PDO('sqlite:'.$this->global_settings->db_path().'/'.$this->global_settings->db_name()); //sqlite 3
+				//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
+			}
+			catch (PDOException $error) {
+				throw Exception("Failed to create database: " . $error->getMessage());
+			}
+
+		//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
+			if (!function_exists('php_now')) {
+				function php_now() {
+					if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
+						@date_default_timezone_set(@date_default_timezone_get());
+					}
+					return date("Y-m-d H:i:s");
+				}
+			}
+			$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
+
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->global_settings->db_type();
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
+			}
+			else {
+				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
+			}
+			$file_contents = file_get_contents($filename);
+			unset($filename);
+
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
+
+		//loop line by line through all the lines of sql code
+			$this->dbh->beginTransaction();
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
+				try {
+					$this->dbh->query($sql);
+				}
+				catch (PDOException $error) {
+							throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
+				}
+				$x++;
+			}
+			unset ($file_contents, $sql);
+			$this->dbh->commit();
+
+		//set the file permissions
+			chmod($this->global_settings->db_path().'/'.$this->global_settings->db_name(), 0777);
+		}
+
+		protected function create_database_pgsql() {
+			if ($this->global_settings->db_create()) {
+			//Attempt to create new PG role and database
+				$this->write_progress("\tCreating database");
+				try {
+					if (strlen($this->global_settings->db_host()) > 0) {
+						$this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1");
+					} else {
+						$this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_create_username()} password={$this->global_settings->db_create_password()} dbname=template1");
+					}
+				} catch (PDOException $error) {
+					throw new Exception("error connecting to database in order to create: " . $error->getMessage());
+				}
+
+				//create the database, user, grant perms
+				if($this->dbh->exec("CREATE DATABASE {$this->global_settings->db_name()}") === false) {
+					throw new Exception("Failed to create database {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
+				}
+				if($this->global_settings->db_username() != $this->global_settings->db_create_username()){
+					if($this->dbh->exec("CREATE USER {$this->global_settings->db_username()} WITH PASSWORD '{$this->global_settings->db_password()}'") === false){
+						throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
+					}
+					if($this->dbh->exec("GRANT ALL ON {$this->global_settings->db_name()} TO {$this->global_settings->db_username()}") === false){
+						throw new Exception("Failed to create user {$this->global_settings->db_name()}: " . join(":", $this->dbh->errorInfo()));
+					}
+				}
+
+				//close database connection_aborted
+				$this->dbh = null;
+			}
+
+			$this->write_progress("\tInstalling data to database");				
+		//open database connection with $this->global_settings->db_name()
+			try {
+				if (strlen($this->global_settings->db_host()) > 0) {
+					$this->dbh = new PDO("pgsql:host={$this->global_settings->db_host()} port={$this->global_settings->db_port()} dbname={$this->global_settings->db_name()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()}");
+				} else {
+					$this->dbh = new PDO("pgsql:host=localhost port={$this->global_settings->db_port()} user={$this->global_settings->db_username()} password={$this->global_settings->db_password()} dbname={$this->global_settings->db_name()}");
+				}
+			}
+			catch (PDOException $error) {
+				throw new Exception("error connecting to database: " . $error->getMessage());
+			}
+
+
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->global_settings->db_type();
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
+			}
+			else {
+			$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
+			}
+			$file_contents = file_get_contents($filename);
+
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
+
+		//loop line by line through all the lines of sql code
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
+				if (strlen($sql) > 3) {
+					try {
+						$this->dbh->query($sql);
+					}
+					catch (PDOException $error) {
+						throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
+					}
+				}
+				$x++;
+			}
+			unset ($file_contents, $sql);
+		}
+
+		protected function create_database_mysql() {
+				//database connection
+					$connect_string;
+					if (strlen($this->global_settings->db_host()) == 0 && strlen($this->global_settings->db_port()) == 0) {
+						//if both host and port are empty use the unix socket
+						$connect_string = "mysql:host=$this->global_settings->db_host();unix_socket=/var/run/mysqld/mysqld.sock;";
+					}
+					elseif (strlen($this->global_settings->db_port()) == 0) {
+						//leave out port if it is empty
+						$connect_string = "mysql:host=$this->global_settings->db_host();";
+					}
+					else {
+						$connect_string = "mysql:host=$this->global_settings->db_host();port=$this->global_settings->db_port();";
+					}
+
+				//create the table, user and set the permissions only if the db_create_username was provided
+					if ($this->global_settings->db_create()) {
+						$this->write_progress("\tCreating database");				
+						try {
+							$this->dbh = new PDO($connect_string, $this->global_settings->db_create_username(), db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+							$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+							$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+						}
+						catch (PDOException $error) {
+							throw new Exception("error connecting to database for ccreate: " . $error->getMessage() . "\n" . $sql );
+						}
+						//select the mysql database
+							try {
+								$this->dbh->query("USE mysql;");
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+
+						//create user and set the permissions
+							try {
+								$tmp_sql = "CREATE USER '".$this->global_settings->db_username()."'@'%' IDENTIFIED BY '".$this->global_settings->db_password()."'; ";
+								$this->dbh->query($tmp_sql);
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+
+						//set account to unlimited use
+							try {
+								if ($this->global_settings->db_host() == "localhost" || $this->global_settings->db_host() == "127.0.0.1") {
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'localhost' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
+									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
+									$this->dbh->query($tmp_sql);
+
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'127.0.0.1' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
+									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
+									$this->dbh->query($tmp_sql);
+								}
+								else {
+									$tmp_sql = "GRANT USAGE ON * . * TO '".$this->global_settings->db_username()."'@'".$this->global_settings->db_host()."' ";
+									$tmp_sql .= "IDENTIFIED BY '".$this->global_settings->db_password()."' ";
+									$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
+									$this->dbh->query($tmp_sql);
+								}
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+
+						//create the database and set the create user with permissions
+							try {
+								$tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$this->global_settings->db_name()."; ";
+								$this->dbh->query($tmp_sql);
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+
+						//set user permissions
+							try {
+								$this->dbh->query("GRANT ALL PRIVILEGES ON ".$this->global_settings->db_name().".* TO '".$this->global_settings->db_username()."'@'%'; ");
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+
+						//make the changes active
+							try {
+								$tmp_sql = "FLUSH PRIVILEGES; ";
+								$this->dbh->query($tmp_sql);
+							}
+							catch (PDOException $error) {
+								throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+							}
+							$this->dbh = null;
+					} //if (strlen($this->global_settings->db_create_username()) > 0)
+
+				$this->write_progress("\tInstalling data to database");
+				//select the database
+					try {
+						$this->dbh = new PDO($connect_string, $this->global_settings->db_username(), db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
+						$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+						$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
+					}
+					catch (PDOException $error) {
+						throw new Exception("error connecting to database: " . $error->getMessage() . "\n" . $sql );
+					}
+					try {
+						$this->dbh->query("USE ".$this->global_settings->db_name().";");
+					}
+					catch (PDOException $error) {
+						throw new Exception("error in database: " . $error->getMessage() . "\n" . $sql );
+					}
+
+				//add the database structure
+					require_once "resources/classes/schema.php";
+					$schema = new schema;
+					$schema->db = $this->dbh;
+					$schema->db_type = $this->global_settings->db_type();
+					$schema->sql();
+					$schema->exec();
+
+				//add the defaults data into the database
+					//get the contents of the sql file
+					if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql')){
+						$filename = "/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql";
+					}
+					else {
+						$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql';
+					}
+					$file_contents = file_get_contents($filename);
+
+					//replace \r\n with \n then explode on \n
+						$file_contents = str_replace("\r\n", "\n", $file_contents);
+
+					//loop line by line through all the lines of sql code
+						$string_array = explode("\n", $file_contents);
+						$x = 0;
+						foreach($string_array as $sql) {
+							if (strlen($sql) > 3) {
+								try {
+									if ($this->debug) {
+										$this->write_debug( $sql."\n");
+									}
+									$this->dbh->query($sql);
+								}
+								catch (PDOException $error) {
+									//echo "error on line $x: " . $error->getMessage() . " sql: $sql<br/>";
+									//die();
+								}
+							}
+							$x++;
+						}
+						unset ($file_contents, $sql);
+		}
+
+		protected function create_domain() {
+			$this->write_progress("\tChecking if domain exists '" . $this->global_settings->domain_name() . "'");
+			$sql = "select * from v_domains ";
+			$sql .= "where domain_name = '".$this->global_settings->domain_name()."' ";
+			$sql .= "limit 1";
+			$this->write_debug($sql);
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			if($prep_statement->execute() === false){
+				throw new Exception("Failed to search for domain: " . join(":", $this->dbh->errorInfo()));
+			}
+			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
+			unset($sql, $prep_statement);
+			if ($result) {
+				$this->global_settings->set_domain_uuid($result['domain_uuid']);
+				$this->write_progress("... domain exists as '" . $this->global_settings->domain_uuid() . "'");
+				if($result['domain_enabled'] != 'true'){
+					throw new Exception("Domain already exists but is disabled, this is unexpected");
+				}
+			} else {
+				$this->write_progress("\t... creating domain");
+				$sql = "insert into v_domains ";
+				$sql .= "(";
+				$sql .= "domain_uuid, ";
+				$sql .= "domain_name, ";
+				$sql .= "domain_description ";
+				$sql .= ") ";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
+				$sql .= "'".$this->global_settings->domain_name()."', ";
+				$sql .= "'Default Domain' ";
+				$sql .= ");";
+
+				$this->write_debug($sql);
+				if($this->dbh->exec(check_sql($sql)) === false){
+					throw new Exception("Failed to execute sql statement: " . join(":", $this->dbh->errorInfo()));
+				}
+				unset($sql);
+
+				//domain settings
+				$x = 0;
+				$tmp[$x]['name'] = 'uuid';
+				$tmp[$x]['value'] = $this->menu_uuid;
+				$tmp[$x]['category'] = 'domain';
+				$tmp[$x]['subcategory'] = 'menu';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'name';
+				$tmp[$x]['category'] = 'domain';
+				$tmp[$x]['subcategory'] = 'time_zone';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'code';
+				$tmp[$x]['value'] = 'en-us';
+				$tmp[$x]['category'] = 'domain';
+				$tmp[$x]['subcategory'] = 'language';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'iso_code';
+				$tmp[$x]['value'] = $this->default_country;
+				$tmp[$x]['category'] = 'domain';
+				$tmp[$x]['subcategory'] = 'country';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'name';
+				$tmp[$x]['value'] = $this->template_name;
+				$tmp[$x]['category'] = 'domain';
+				$tmp[$x]['subcategory'] = 'template';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+
+				//switch settings
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $switch_bin_dir;
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'bin';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_base_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'base';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_conf_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'conf';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_db_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'db';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_log_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'log';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_mod_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'mod';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_script_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'scripts';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_grammar_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'grammar';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_storage_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'storage';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_voicemail_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'voicemail';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_recordings_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'recordings';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_sounds_dir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'sounds';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_phrases_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'phrases';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = '';
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'provision';
+				$tmp[$x]['enabled'] = 'false';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_extensions_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'extensions';
+				$tmp[$x]['enabled'] = 'false';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_sip_profiles_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'sip_profiles';
+				$tmp[$x]['enabled'] = 'false';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_dialplan_vdir();
+				$tmp[$x]['category'] = 'switch';
+				$tmp[$x]['subcategory'] = 'dialplan';
+				$tmp[$x]['enabled'] = 'false';
+				$x++;
+
+				//server settings
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_temp_dir();
+				$tmp[$x]['category'] = 'server';
+				$tmp[$x]['subcategory'] = 'temp';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				#throw new Exception("I don't know how to find /etc/init.d for server > startup_scripts");
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = '';
+				$tmp[$x]['category'] = 'server';
+				$tmp[$x]['subcategory'] = 'startup_script';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+				$tmp[$x]['name'] = 'dir';
+				$tmp[$x]['value'] = $this->global_settings->switch_backup_vdir();
+				$tmp[$x]['category'] = 'server';
+				$tmp[$x]['subcategory'] = 'backup';
+				$tmp[$x]['enabled'] = 'true';
+				$x++;
+
+				$this->dbh->beginTransaction();
+				foreach($tmp as $row) {
+					$sql = "insert into v_default_settings ";
+					$sql .= "(";
+					$sql .= "default_setting_uuid, ";
+					$sql .= "default_setting_name, ";
+					$sql .= "default_setting_value, ";
+					$sql .= "default_setting_category, ";
+					$sql .= "default_setting_subcategory, ";
+					$sql .= "default_setting_enabled ";
+					$sql .= ") ";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$row['name']."', ";
+					$sql .= "'".$row['value']."', ";
+					$sql .= "'".$row['category']."', ";
+					$sql .= "'".$row['subcategory']."', ";
+					$sql .= "'".$row['enabled']."' ";
+					$sql .= ");";
+					$this->write_debug($sql);
+					$this->dbh->exec(check_sql($sql));
+					unset($sql);
+				}
+				$this->dbh->commit();
+				unset($tmp);
+
+			//get the list of installed apps from the core and mod directories
+				$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
+				$x=0;
+				foreach ($config_list as $config_path) {
+					include($config_path);
+					$x++;
+				}
+
+			//add the groups
+				$x = 0;
+				$tmp[$x]['group_name'] = 'superadmin';
+				$tmp[$x]['group_description'] = 'Super Administrator Group';
+				$x++;
+				$tmp[$x]['group_name'] = 'admin';
+				$tmp[$x]['group_description'] = 'Administrator Group';
+				$x++;
+				$tmp[$x]['group_name'] = 'user';
+				$tmp[$x]['group_description'] = 'User Group';
+				$x++;
+				$tmp[$x]['group_name'] = 'public';
+				$tmp[$x]['group_description'] = 'Public Group';
+				$x++;
+				$tmp[$x]['group_name'] = 'agent';
+				$tmp[$x]['group_description'] = 'Call Center Agent Group';
+				$this->dbh->beginTransaction();
+				foreach($tmp as $row) {
+					$sql = "insert into v_groups ";
+					$sql .= "(";
+					$sql .= "group_uuid, ";
+					$sql .= "group_name, ";
+					$sql .= "group_description ";
+					$sql .= ") ";
+					$sql .= "values ";
+					$sql .= "(";
+					$sql .= "'".uuid()."', ";
+					$sql .= "'".$row['group_name']."', ";
+					$sql .= "'".$row['group_description']."' ";
+					$sql .= ");";
+					$this->write_debug($sql);
+					$this->dbh->exec(check_sql($sql));
+					unset($sql);
+				}
+				unset($tmp);
+				$this->dbh->commit();
+				//assign the default permissions to the groups
+				$this->dbh->beginTransaction();
+				foreach($apps as $app) {
+					if ($app['permissions']) {
+						foreach ($app['permissions'] as $row) {
+							if ($this->debug) {
+								$this->write_debug( "v_group_permissions\n");
+								$this->write_debug( json_encode($row)."\n\n");
+							}
+							if ($row['groups']) {
+								foreach ($row['groups'] as $group) {
+									//add the record
+									$sql = "insert into v_group_permissions ";
+									$sql .= "(";
+									$sql .= "group_permission_uuid, ";
+									$sql .= "permission_name, ";
+									$sql .= "group_name ";
+									$sql .= ") ";
+									$sql .= "values ";
+									$sql .= "(";
+									$sql .= "'".uuid()."', ";
+									$sql .= "'".$row['name']."', ";
+									$sql .= "'".$group."' ";
+									$sql .= ");";
+									if ($this->debug) {
+										$this->write_debug( $sql."\n");
+									}
+									$this->dbh->exec(check_sql($sql));
+									unset($sql);
+								}
+							}
+						}
+					}
+				}
+				$this->dbh->commit();
+			}
+		}
+
+		protected function create_superuser() {
+			$this->write_progress("\tChecking if superuser exists '" . $this->admin_username . "'");
+			$sql = "select * from v_users ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
+			$sql .= "and username = '".$this->admin_username."' ";
+			$sql .= "limit 1 ";
+			$this->write_debug($sql);
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
+			unset($sql, $prep_statement);
+			$salt = generate_password('20', '4');
+			if ($result) {
+				$this->admin_uuid = $result['user_uuid'];
+				$this->write_progress("... superuser exists as '" . $this->admin_uuid . "', updating password");
+				$sql = "update v_users ";
+				$sql .= "set password = '".md5($salt.$this->admin_password)."' ";
+				$sql .= "set salt = '$salt' ";
+				$sql .= "where USER_uuid = '".$this->admin_uuid."' ";
+				$this->write_debug($sql);
+				$this->dbh->exec(check_sql($sql));
+			}else{
+				$this->write_progress("\t... creating super user");
+			//add a user and then add the user to the superadmin group
+			//prepare the values
+				$this->admin_uuid = uuid();
+				$contact_uuid = uuid();
+			//set a sessiong variable
+				$_SESSION["user_uuid"] = $user_uuid;
+			//salt used with the password to create a one way hash
+			//add the user account
+				$sql = "insert into v_users ";
+				$sql .= "(";
+				$sql .= "domain_uuid, ";
+				$sql .= "user_uuid, ";
+				$sql .= "contact_uuid, ";
+				$sql .= "username, ";
+				$sql .= "password, ";
+				$sql .= "salt, ";
+				$sql .= "add_date, ";
+				$sql .= "add_user ";
+				$sql .= ") ";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
+				$sql .= "'".$this->admin_uuid."', ";
+				$sql .= "'$contact_uuid', ";
+				$sql .= "'".$this->admin_username."', ";
+				$sql .= "'".md5($salt.$this->admin_password)."', ";
+				$sql .= "'$salt', ";
+				$sql .= "now(), ";
+				$sql .= "'".$this->admin_username."' ";
+				$sql .= ");";
+				$this->write_debug( $sql."\n");
+				$this->dbh->exec(check_sql($sql));
+				unset($sql);
+			}
+			$this->write_progress("\tChecking if superuser contact exists");
+			$sql = "select count(*) from v_contacts ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
+			$sql .= "and contact_name_given = '".$this->admin_username."' ";
+			$sql .= "and contact_nickname = '".$this->admin_username."' ";
+			$sql .= "limit 1 ";
+			$this->write_debug($sql);
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['count'] == 0) {
+				$sql = "insert into v_contacts ";
+				$sql .= "(";
+				$sql .= "domain_uuid, ";
+				$sql .= "contact_uuid, ";
+				$sql .= "contact_type, ";
+				$sql .= "contact_name_given, ";
+				$sql .= "contact_nickname ";
+				$sql .= ") ";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
+				$sql .= "'$contact_uuid', ";
+				$sql .= "'user', ";
+				$sql .= "'".$this->admin_username."', ";
+				$sql .= "'".$this->admin_username."' ";
+				$sql .= ")";
+				$this->dbh->exec(check_sql($sql));
+				unset($sql);
+			}
+			$this->write_progress("\tChecking if superuser is in the correct group");
+			$sql = "select count(*) from v_group_users ";
+			$sql .= "where domain_uuid = '".$this->global_settings->domain_uuid()."' ";
+			$sql .= "and user_uuid = '".$this->admin_uuid."' ";
+			$sql .= "and group_name = 'superadmin' ";
+			$sql .= "limit 1 ";
+			$this->write_debug($sql);
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+			if ($row['count'] == 0) {
+			//add the user to the superadmin group
+				$sql = "insert into v_group_users ";
+				$sql .= "(";
+				$sql .= "group_user_uuid, ";
+				$sql .= "domain_uuid, ";
+				$sql .= "user_uuid, ";
+				$sql .= "group_name ";
+				$sql .= ") ";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".uuid()."', ";
+				$sql .= "'".$this->global_settings->domain_uuid()."', ";
+				$sql .= "'".$this->admin_uuid."', ";
+				$sql .= "'superadmin' ";
+				$sql .= ");";
+				$this->write_debug( $sql."\n");
+				$this->dbh->exec(check_sql($sql));
+				unset($sql);
+			}
+		}
+
+		protected function create_menus() {
+			$this->write_progress("\tCreating menus");
+		//set the defaults
+			$menu_name = 'default';
+			$menu_language = 'en-us';
+			$menu_description = 'Default Menu Set';
+
+			$this->write_progress("\tChecking if menu exists");
+			$sql = "select count(*) from v_menus ";
+			$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
+			$sql .= "limit 1 ";
+			$this->write_debug($sql);
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$result = $prep_statement->fetch(PDO::FETCH_NAMED);
+			unset($sql, $prep_statement);
+			if ($result['count'] == 0) {
+				$this->write_progress("\t... creating menu '" . $menu_name. "'");
+				$sql = "insert into v_menus ";
+				$sql .= "(";
+				$sql .= "menu_uuid, ";
+				$sql .= "menu_name, ";
+				$sql .= "menu_language, ";
+				$sql .= "menu_description ";
+				$sql .= ") ";
+				$sql .= "values ";
+				$sql .= "(";
+				$sql .= "'".$this->menu_uuid."', ";
+				$sql .= "'$menu_name', ";
+				$sql .= "'$menu_language', ";
+				$sql .= "'$menu_description' ";
+				$sql .= ");";
+				if ($this->debug) {
+					$this->write_debug( $sql."\n");
+				}
+				$this->dbh->exec(check_sql($sql));
+				unset($sql);
+
+			//add the menu items
+				require_once "resources/classes/menu.php";
+				$menu = new menu;
+				$menu->db = $this->dbh;
+				$menu->menu_uuid = $this->menu_uuid;
+				$menu->restore();
+				unset($menu);
+			}
+		}
+
+		protected function app_defaults() {
+			$this->write_progress("\tRunning app_defaults");
+
+		//set needed session settings
+			$_SESSION["username"] = $this->admin_username;
+			$_SESSION["domain_uuid"] = $this->global_settings->domain_uuid();
+			require $this->config_php;
+			require "resources/require.php";
+			$_SESSION['event_socket_ip_address'] = $this->global_settings->event_host;
+			$_SESSION['event_socket_port'] = $this->global_settings->event_port;
+			$_SESSION['event_socket_password'] = $this->global_settings->event_password;
+
+		//get the groups assigned to the user and then set the groups in $_SESSION["groups"]
+			$sql = "SELECT * FROM v_group_users ";
+			$sql .= "where domain_uuid=:domain_uuid ";
+			$sql .= "and user_uuid=:user_uuid ";
+			$prep_statement = $this->dbh->prepare(check_sql($sql));
+			$prep_statement->bindParam(':domain_uuid', $this->global_settings->domain_uuid);
+			$prep_statement->bindParam(':user_uuid', $this->admin_uuid);
+			$prep_statement->execute();
+			$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			$_SESSION["groups"] = $result;
+			unset($sql, $row_count, $prep_statement);
+
+		//get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions']
+			$x = 0;
+			$sql = "select distinct(permission_name) from v_group_permissions ";
+			foreach($_SESSION["groups"] as $field) {
+				if (strlen($field['group_name']) > 0) {
+					if ($x == 0) {
+						$sql .= "where (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') ";
+					}
+					else {
+						$sql .= "or (domain_uuid = '".$this->global_settings->domain_uuid."' and group_name = '".$field['group_name']."') ";
+					}
+					$x++;
+				}
+			}
+			$prep_statement_sub = $this->dbh->prepare($sql);
+			$prep_statement_sub->execute();
+			$_SESSION['permissions'] = $prep_statement_sub->fetchAll(PDO::FETCH_NAMED);
+			unset($sql, $prep_statement_sub);
+
+		//include the config.php
+			$db_type = $this->global_settings->db_type();
+			$db_path = $this->global_settings->db_path();
+			$db_host = $this->global_settings->db_host();
+			$db_port = $this->global_settings->db_port();
+			$db_name = $this->global_settings->db_name();
+			$db_username = $this->global_settings->db_username();
+			$db_password = $this->global_settings->db_password();
+
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			echo $schema->schema();
+
+		//run all app_defaults.php files
+			$default_language = $this->install_language;
+			$domain = new domains;
+			$domain->upgrade();
+
+		//synchronize the config with the saved settings
+			save_switch_xml();
+
+		//do not show the apply settings reminder on the login page
+			$_SESSION["reload_xml"] = false;
+
+		//clear the menu
+			$_SESSION["menu"] = "";
+
+		}
+
+		public function remove_config() {
+			if (file_exists('/bin/rm')) {
+				$this->write_debug('rm -f ' . $this->config_php);
+				exec ('rm -f ' . $this->config_php);
+			}
+			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
+				$this->write_debug("del /S /F /Q '$dir'");
+				exec("del /F /Q '" . $this->config_php . "'");
+			}
+			else {
+				$this->write_debug("delete file: ".$file);
+				unlink($this->config_php);
+			}
+			clearstatcache();
+		}
+	}
+
+?>

+ 455 - 0
core/install/resources/classes/install_switch.php

@@ -0,0 +1,455 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Copyright (C) 2010-2015
+	All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+include "root.php";
+
+//define the install class
+	class install_switch {
+
+		protected $global_settings;
+		protected $config_lua;
+		protected $dbh;
+
+		public $debug = false;
+		public $echo_progress = false;
+
+		function __construct($global_settings) {
+			if(is_null($global_settings)){
+				require_once "core/install/resources/classes/global_settings.php";
+				$global_settings = new global_settings();
+			}elseif(!is_a($global_settings, 'global_settings')){
+				throw new Exception('The parameter $global_settings must be a global_settings object (or a subclass of)');
+			}
+			$this->global_settings = $global_settings;
+			if (is_dir("/etc/fusionpbx")){
+				$this->config_lua = "/etc/fusionpbx/config.lua";
+			}elseif (is_dir("/usr/local/etc/fusionpbx")){
+				$this->config_lua = "/usr/local/etc/fusionpbx/config.lua";
+			}elseif(strlen($this->global_settings->switch_script_dir()) > 0) {
+				$this->config_lua = $this->global_settings->switch_script_dir()."/resources/config.lua";
+			}else{
+				throw new Exception("Could not work out where to put the config.lua");
+			}
+			$this->config_lua = normalize_path_to_os($this->config_lua);
+		}
+
+		//utility Functions
+		
+		function write_debug($message) {
+			if($this->debug){
+				echo "$message\n";
+			}
+		}
+		
+		function write_progress($message) {
+			if($this->echo_progress){
+				echo "$message\n";
+			}
+		}
+
+		//$options '-n' --no-clobber
+		protected function recursive_copy($src, $dst, $options = '') {
+			if (file_exists('/bin/cp')) {
+				if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
+					//copy -R recursive, preserve attributes for SUN
+					$cmd = 'cp -Rp '.$src.'/* '.$dst;
+				} else {
+					//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
+					$cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
+				}
+				$this->write_debug($cmd);
+				exec ($cmd);
+			}
+			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
+				$src = normalize_path_to_os($src);
+				$dst = normalize_path_to_os($dst);
+				exec("xcopy /E /Y \"$src\" \"$dst\"");
+			}
+			else {
+				throw new Exception('Could not perform copy operation on this platform, implementation missing');
+				$dir = opendir($src);
+				if (!$dir) {
+					if (!mkdir($src, 0755, true)) {
+						throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
+					}
+				}
+				if (!is_dir($dst)) {
+					if (!mkdir($dst, 0755, true)) {
+						throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
+					}
+				}
+				//This looks wrong, essentially if we can't use /bin/cp it manually fils dirs, not correct
+				$script_dir_target = $_SESSION['switch']['scripts']['dir'];
+				$script_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
+				foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
+					if (
+					substr_count($file_path_source, '/..') == 0 &&
+					substr_count($file_path_source, '/.') == 0 &&
+					substr_count($file_path_source, '/.svn') == 0 &&
+					substr_count($file_path_source, '/.git') == 0
+					) {
+						if ($dst != $src.'/resources/config.lua') {
+							$this->write_debug($file_path_source.' ---> '.$dst);
+							copy($file_path_source, $dst);
+							chmod($dst, 0755);
+						}
+					}
+				}
+
+				while(false !== ($file = readdir($dir))) {
+					if (($file != '.') && ($file != '..')) {
+						if (is_dir($src.'/'.$file)) {
+							$this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
+						}
+						else {
+						//copy only missing files -n --no-clobber
+							if (strpos($options,'-n') !== false) {
+								if (!file_exists($dst.'/'.$file)) {
+									$this->write_debug("copy(".$src."/".$file.", ".$dst."/".$file.")");
+									copy($src.'/'.$file, $dst.'/'.$file);
+								}
+							}
+							else {
+								copy($src.'/'.$file, $dst.'/'.$file);
+							}
+						}
+					}
+				}
+				closedir($dir);
+			}
+		}
+
+		protected function recursive_delete($dir) {
+			if (file_exists('/bin/rm')) {
+				$this->write_debug('rm -Rf '.$dir.'/*');
+				exec ('rm -Rf '.$dir.'/*');
+			}
+			elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'){
+				$dst = normalize_path_to_os($dst);
+				$this->write_debug("del /S /F /Q \"$dir\"");
+				exec("del /S /F /Q \"$dir\"");
+			}
+			else {
+				foreach (glob($dir) as $file) {
+					if (is_dir($file)) {
+						$this->write_debug("rm dir: ".$file);
+						$this->recursive_delete("$file/*");
+						rmdir($file);
+					} else {
+						$this->write_debug("delete file: ".$file);
+						unlink($file);
+					}
+				}
+			}
+			clearstatcache();
+		}
+		
+		protected function backup_dir($dir, $backup_name){
+			if (!is_readable($dir)) {
+				throw new Exception("backup_dir() source directory '".$dir."' does not exist.");
+			}
+			$dst_tar = join( DIRECTORY_SEPARATOR, array(sys_get_temp_dir(), "$backup_name.tar"));
+			//pharData is the correct ay to do it, but it keeps creating incomplete archives
+			//$tar = new PharData($dst_tar);
+			//$tar->buildFromDirectory($dir);
+			$this->write_debug("backing up to $dst_tar");
+			if (file_exists('/bin/tar')) {
+				exec('tar -cvf ' .$dst_tar. ' -C '.$dir .' .');
+			}else{
+				$this->write_debug('WARN: old config could not be compressed');
+				$dst_dir = join( DIRECTORY_SEPARATOR, array(sys_get_temp_dir(), "$backup_name"));
+				recursive_copy($dir, $dst_dir);
+			}
+		}
+
+		function install_phase_1() {
+			$this->write_progress("Install phase 1 started for switch");
+			$this->copy_conf();
+			$this->copy_scripts();
+			$this->write_progress("Install phase 1 completed for switch");
+		}
+
+		function install_phase_2() {
+			$this->write_progress("Install phase 2 started for switch");
+			$this->create_config_lua();
+			$this->restart_switch();
+			$this->write_progress("Install phase 2 completed for switch");
+		}
+
+		function upgrade() {
+			$this->copy_scripts();
+			$this->create_config_lua();
+		}
+
+		protected function copy_conf() {
+			$this->write_progress("\tCopying Config");
+			//make a backup of the config
+				if (file_exists($this->global_settings->switch_conf_dir())) {
+					$this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config');
+					$this->recursive_delete($this->global_settings->switch_conf_dir());
+				}
+			//make sure the conf directory exists
+				if (!is_dir($this->global_settings->switch_conf_dir())) {
+					if (!mkdir($this->global_settings->switch_conf_dir(), 0774, true)) {
+						throw new Exception("Failed to create the switch conf directory '".$this->global_settings->switch_conf_dir()."'. ");
+					}
+				}
+			//copy resources/templates/conf to the freeswitch conf dir
+				if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
+					$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
+				}
+				else {
+					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
+				}
+				$dst_dir = $this->global_settings->switch_conf_dir();
+				if (is_readable($dst_dir)) {
+					$this->recursive_copy($src_dir, $dst_dir);
+					unset($src_dir, $dst_dir);
+				}
+				$fax_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax'));
+				if (!is_readable($fax_dir)) { mkdir($fax_dir,0777,true); }
+				$voicemail_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
+				if (!is_readable($voicemail_dir)) { mkdir($voicemail_dir,0777,true); }
+			
+			//create the dialplan/default.xml for single tenant or dialplan/domain.xml
+				if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) {
+					$dialplan = new dialplan;
+					$dialplan->domain_uuid = $this->domain_uuid;
+					$dialplan->domain = $this->domain_name;
+					$dialplan->switch_dialplan_dir = join( DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan"));
+					$dialplan->restore_advanced_xml();
+					if($this->_debug){
+						print_r($dialplan->result, $message);
+						$this->write_debug($message);
+					}
+				}
+
+			//write the xml_cdr.conf.xml file
+				if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/xml_cdr")) {
+					xml_cdr_conf_xml();
+				}
+
+			//write the switch.conf.xml file
+				if (file_exists($this->global_settings->switch_conf_dir())) {
+					switch_conf_xml();
+				}
+
+		}
+
+		protected function copy_scripts() {
+			$this->write_progress("\tCopying Scripts");
+			$script_dir = $this->global_settings->switch_script_dir();
+			if(strlen($script_dir) == 0) {
+				throw new Exception("Cannot copy scripts the 'script_dir' is empty");
+			}
+			if (file_exists($script_dir)) {
+				if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
+					$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
+				}
+				else {
+					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts';
+				}
+				$dst_dir = $script_dir;
+				if (is_readable($script_dir)) {
+					$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
+					unset($src_dir, $dst_dir);
+				}else{
+					throw new Exception("Cannot read from '$src_dir' to get the scripts");
+				}
+				chmod($dst_dir, 0774);
+			}else{
+				$this->write_progress("\tSkipping scripts, script_dir is unset");
+			}
+		}
+
+		public function create_config_lua() {
+			//define the database connection as global
+				global $db;
+
+			//send progress
+				$this->write_progress("\tCreating " . $this->config_lua);
+
+			//set the directories
+				$path = dirname($this->config_lua);
+				$parent_dir = basename($path);
+				if ($parent_dir == 'resources' and !file_exists($path)){
+					$this->write_progress("\t... creating missing '$path'");
+					if (!mkdir($path, 0755, true)) {
+						throw new Exception("Failed to create the missing resources directory '$path'");
+					}
+				}
+
+			//get the odbc information
+				$sql = "select count(*) as num_rows from v_databases ";
+				$sql .= "where database_driver = 'odbc' ";
+				if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
+				$prep_statement = $db->prepare($sql);
+				if ($prep_statement) {
+					$prep_statement->execute();
+					$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+					unset($prep_statement);
+					if ($row['num_rows'] > 0) {
+						$odbc_num_rows = $row['num_rows'];
+						$sql = "select * from v_databases ";
+						$sql .= "where database_driver = 'odbc' ";
+						$prep_statement = $db->prepare(check_sql($sql));
+						$prep_statement->execute();
+						$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+						foreach ($result as &$row) {
+							$dsn_name = $row["database_name"];
+							$dsn_username = $row["database_username"];
+							$dsn_password = $row["database_password"];
+							break; //limit to 1 row
+						}
+						unset ($prep_statement);
+					}
+					else {
+						$odbc_num_rows = '0';
+					}
+				}
+
+			//config.lua
+				$fout = fopen($this->config_lua,"w");
+				if(!$fout){
+					throw new Exception("Failed to open '".$this->config_lua."' for writing");
+				}
+				$tmp = "\n";
+				$tmp .= "--set the variables\n";
+				if (strlen($this->global_settings->switch_sounds_dir()) > 0) {
+					$tmp .= normalize_path_to_os("	sounds_dir = [[".$this->global_settings->switch_sounds_dir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_phrases_vdir()) > 0) {
+					$tmp .= normalize_path_to_os("	phrases_dir = [[".$this->global_settings->switch_phrases_vdir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_db_dir()) > 0) {
+					$tmp .= normalize_path_to_os("	database_dir = [[".$this->global_settings->switch_db_dir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_recordings_dir()) > 0) {
+					$tmp .= normalize_path_to_os("	recordings_dir = [[".$this->global_settings->switch_recordings_dir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_storage_dir()) > 0) {
+					$tmp .= normalize_path_to_os("	storage_dir = [[".$this->global_settings->switch_storage_dir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_voicemail_vdir()) > 0) {
+					$tmp .= normalize_path_to_os("	voicemail_dir = [[".$this->global_settings->switch_voicemail_vdir()."]];\n");
+				}
+				if (strlen($this->global_settings->switch_script_dir()) > 0) {
+					$tmp .= normalize_path_to_os("	scripts_dir = [[".$this->global_settings->switch_script_dir()."]];\n");
+				}
+				$tmp .= normalize_path_to_os("	php_dir = [[".PHP_BINDIR."]];\n");
+				if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
+					$tmp .= "	php_bin = \"php.exe\";\n";
+				}
+				else {
+					$tmp .= "	php_bin = \"php\";\n";
+				}
+				$tmp .= normalize_path_to_os("	document_root = [[".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."]];\n");
+				$tmp .= "\n";
+
+				if ((strlen($this->global_settings->db_type()) > 0) || (strlen($dsn_name) > 0)) {
+					$tmp .= "--database information\n";
+					$tmp .= "	database = {}\n";
+					$tmp .= "	database[\"type\"] = \"".$this->global_settings->db_type()."\";\n";
+					$tmp .= "	database[\"name\"] = \"".$this->global_settings->db_name()."\";\n";
+					$tmp .= normalize_path_to_os("	database[\"path\"] = [[".$this->global_settings->db_path()."]];\n");
+
+					if (strlen($dsn_name) > 0) {
+						$tmp .= "	database[\"system\"] = \"odbc://".$dsn_name.":".$dsn_username.":".$dsn_password."\";\n";
+						$tmp .= "	database[\"switch\"] = \"odbc://freeswitch:".$dsn_username.":".$dsn_password."\";\n";
+					}
+					elseif ($this->global_settings->db_type() == "pgsql") {
+						$db_host = $this->global_settings->db_host();
+						if($db_host == 'localhost') { $db_host = '127.0.0.1'; } // lua cannot resolve localhost
+						if (filter_var($db_host, FILTER_VALIDATE_IP)) {
+							$host_type = "hostaddr";
+						}
+						else {
+							$host_type = "host";
+						}
+						$tmp .= "	database[\"system\"] = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=".$this->global_settings->db_name()." user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='".$this->global_settings->db_name()."'\";\n";
+						$tmp .= "	database[\"switch\"] = \"pgsql://".$host_type."=".$db_host." port=".$this->global_settings->db_port()." dbname=freeswitch user=".$this->global_settings->db_username()." password=".$this->global_settings->db_password()." options='' application_name='freeswitch'\";\n";
+					}
+					elseif ($this->global_settings->db_type() == "sqlite") {
+						$tmp .= "	database[\"system\"] = \"sqlite://".$this->global_settings->db_path()."/".$this->global_settings->db_name()."\";\n";
+						$tmp .= "	database[\"switch\"] = \"sqlite://".$_SESSION['switch']['db']['dir']."\";\n";
+					}
+					elseif ($this->global_settings->db_type() == "mysql") {
+						$tmp .= "	database[\"system\"] = \"\";\n";
+						$tmp .= "	database[\"switch\"] = \"\";\n";
+					}
+					$tmp .= "\n";
+				}
+				$tmp .= "--set defaults\n";
+				$tmp .= "	expire = {}\n";
+				$tmp .= "	expire[\"directory\"] = \"3600\";\n";
+				$tmp .= "	expire[\"dialplan\"] = \"3600\";\n";
+				$tmp .= "	expire[\"languages\"] = \"3600\";\n";
+				$tmp .= "	expire[\"sofia.conf\"] = \"3600\";\n";
+				$tmp .= "	expire[\"acl.conf\"] = \"3600\";\n";
+				$tmp .= "\n";
+				$tmp .= "--set xml_handler\n";
+				$tmp .= "	xml_handler = {}\n";
+				$tmp .= "	xml_handler[\"fs_path\"] = false;\n";
+				$tmp .= "\n";
+				$tmp .= "--set the debug options\n";
+				$tmp .= "	debug[\"params\"] = false;\n";
+				$tmp .= "	debug[\"sql\"] = false;\n";
+				$tmp .= "	debug[\"xml_request\"] = false;\n";
+				$tmp .= "	debug[\"xml_string\"] = false;\n";
+				$tmp .= "	debug[\"cache\"] = false;\n";
+				$tmp .= "\n";
+				$tmp .= "--additional info\n";
+				$tmp .= "	domain_count = ".$this->global_settings->domain_count().";\n";
+				$tmp .= normalize_path_to_os("	temp_dir = [[".$this->global_settings->switch_temp_dir()."]];\n");
+				if (isset($_SESSION['domain']['dial_string']['text'])) {
+					$tmp .= "	dial_string = \"".$_SESSION['domain']['dial_string']['text']."\";\n";
+				}
+				$tmp .= "\n";
+				$tmp .= "--include local.lua\n";
+				$tmp .= "	require(\"resources.functions.file_exists\");\n";
+				$tmp .= "	if (file_exists(\"/etc/fusionpbx/local.lua\")) then\n";
+				$tmp .= "		dofile(\"/etc/fusionpbx/local.lua\");\n";
+				$tmp .= "	elseif (file_exists(\"/usr/local/etc/fusionpbx/local.lua\")) then\n";
+				$tmp .= "		dofile(\"/usr/local/etc/fusionpbx/local.lua\");\n";
+				$tmp .= "	elseif (file_exists(scripts_dir..\"/resources/local.lua\")) then\n";
+				$tmp .= "		require(\"resources.local\");\n";
+				$tmp .= "	end\n";
+				fwrite($fout, $tmp);
+				unset($tmp);
+				fclose($fout);
+		}
+
+		protected function restart_switch() {
+			$esl = new EventSocket;
+			if(!$esl->connect($this->global_settings->switch_event_host(), $this->global_settings->switch_event_port(), $this->global_settings->switch_event_password())) {
+				throw new Exception("Failed to connect to switch");
+			}
+			if (!$esl->request('api fsctl shutdown restart elegant')){
+				throw new Exception("Failed to send switch restart");
+			}
+			$esl->reset_fp();
+		}
+	}
+?>

+ 250 - 0
core/install/resources/classes/iso_countries.php

@@ -0,0 +1,250 @@
+<?php
+$iso_countries = array
+(
+	'AF' => 'Afghanistan',
+	'AX' => 'Aland Islands',
+	'AL' => 'Albania',
+	'DZ' => 'Algeria',
+	'AS' => 'American Samoa',
+	'AD' => 'Andorra',
+	'AO' => 'Angola',
+	'AI' => 'Anguilla',
+	'AQ' => 'Antarctica',
+	'AG' => 'Antigua And Barbuda',
+	'AR' => 'Argentina',
+	'AM' => 'Armenia',
+	'AW' => 'Aruba',
+	'AU' => 'Australia',
+	'AT' => 'Austria',
+	'AZ' => 'Azerbaijan',
+	'BS' => 'Bahamas',
+	'BH' => 'Bahrain',
+	'BD' => 'Bangladesh',
+	'BB' => 'Barbados',
+	'BY' => 'Belarus',
+	'BE' => 'Belgium',
+	'BZ' => 'Belize',
+	'BJ' => 'Benin',
+	'BM' => 'Bermuda',
+	'BT' => 'Bhutan',
+	'BO' => 'Bolivia',
+	'BA' => 'Bosnia And Herzegovina',
+	'BW' => 'Botswana',
+	'BV' => 'Bouvet Island',
+	'BR' => 'Brazil',
+	'IO' => 'British Indian Ocean Territory',
+	'BN' => 'Brunei Darussalam',
+	'BG' => 'Bulgaria',
+	'BF' => 'Burkina Faso',
+	'BI' => 'Burundi',
+	'KH' => 'Cambodia',
+	'CM' => 'Cameroon',
+	'CA' => 'Canada',
+	'CV' => 'Cape Verde',
+	'KY' => 'Cayman Islands',
+	'CF' => 'Central African Republic',
+	'TD' => 'Chad',
+	'CL' => 'Chile',
+	'CN' => 'China',
+	'CX' => 'Christmas Island',
+	'CC' => 'Cocos (Keeling) Islands',
+	'CO' => 'Colombia',
+	'KM' => 'Comoros',
+	'CG' => 'Congo',
+	'CD' => 'Congo, Democratic Republic',
+	'CK' => 'Cook Islands',
+	'CR' => 'Costa Rica',
+	'CI' => 'Cote D\'Ivoire',
+	'HR' => 'Croatia',
+	'CU' => 'Cuba',
+	'CY' => 'Cyprus',
+	'CZ' => 'Czech Republic',
+	'DK' => 'Denmark',
+	'DJ' => 'Djibouti',
+	'DM' => 'Dominica',
+	'DO' => 'Dominican Republic',
+	'EC' => 'Ecuador',
+	'EG' => 'Egypt',
+	'SV' => 'El Salvador',
+	'GQ' => 'Equatorial Guinea',
+	'ER' => 'Eritrea',
+	'EE' => 'Estonia',
+	'ET' => 'Ethiopia',
+	'FK' => 'Falkland Islands (Malvinas)',
+	'FO' => 'Faroe Islands',
+	'FJ' => 'Fiji',
+	'FI' => 'Finland',
+	'FR' => 'France',
+	'GF' => 'French Guiana',
+	'PF' => 'French Polynesia',
+	'TF' => 'French Southern Territories',
+	'GA' => 'Gabon',
+	'GM' => 'Gambia',
+	'GE' => 'Georgia',
+	'DE' => 'Germany',
+	'GH' => 'Ghana',
+	'GI' => 'Gibraltar',
+	'GR' => 'Greece',
+	'GL' => 'Greenland',
+	'GD' => 'Grenada',
+	'GP' => 'Guadeloupe',
+	'GU' => 'Guam',
+	'GT' => 'Guatemala',
+	'GG' => 'Guernsey',
+	'GN' => 'Guinea',
+	'GW' => 'Guinea-Bissau',
+	'GY' => 'Guyana',
+	'HT' => 'Haiti',
+	'HM' => 'Heard Island & Mcdonald Islands',
+	'VA' => 'Holy See (Vatican City State)',
+	'HN' => 'Honduras',
+	'HK' => 'Hong Kong',
+	'HU' => 'Hungary',
+	'IS' => 'Iceland',
+	'IN' => 'India',
+	'ID' => 'Indonesia',
+	'IR' => 'Iran, Islamic Republic Of',
+	'IQ' => 'Iraq',
+	'IE' => 'Ireland',
+	'IM' => 'Isle Of Man',
+	'IL' => 'Israel',
+	'IT' => 'Italy',
+	'JM' => 'Jamaica',
+	'JP' => 'Japan',
+	'JE' => 'Jersey',
+	'JO' => 'Jordan',
+	'KZ' => 'Kazakhstan',
+	'KE' => 'Kenya',
+	'KI' => 'Kiribati',
+	'KR' => 'Korea',
+	'KW' => 'Kuwait',
+	'KG' => 'Kyrgyzstan',
+	'LA' => 'Lao People\'s Democratic Republic',
+	'LV' => 'Latvia',
+	'LB' => 'Lebanon',
+	'LS' => 'Lesotho',
+	'LR' => 'Liberia',
+	'LY' => 'Libyan Arab Jamahiriya',
+	'LI' => 'Liechtenstein',
+	'LT' => 'Lithuania',
+	'LU' => 'Luxembourg',
+	'MO' => 'Macao',
+	'MK' => 'Macedonia',
+	'MG' => 'Madagascar',
+	'MW' => 'Malawi',
+	'MY' => 'Malaysia',
+	'MV' => 'Maldives',
+	'ML' => 'Mali',
+	'MT' => 'Malta',
+	'MH' => 'Marshall Islands',
+	'MQ' => 'Martinique',
+	'MR' => 'Mauritania',
+	'MU' => 'Mauritius',
+	'YT' => 'Mayotte',
+	'MX' => 'Mexico',
+	'FM' => 'Micronesia, Federated States Of',
+	'MD' => 'Moldova',
+	'MC' => 'Monaco',
+	'MN' => 'Mongolia',
+	'ME' => 'Montenegro',
+	'MS' => 'Montserrat',
+	'MA' => 'Morocco',
+	'MZ' => 'Mozambique',
+	'MM' => 'Myanmar',
+	'NA' => 'Namibia',
+	'NR' => 'Nauru',
+	'NP' => 'Nepal',
+	'NL' => 'Netherlands',
+	'AN' => 'Netherlands Antilles',
+	'NC' => 'New Caledonia',
+	'NZ' => 'New Zealand',
+	'NI' => 'Nicaragua',
+	'NE' => 'Niger',
+	'NG' => 'Nigeria',
+	'NU' => 'Niue',
+	'NF' => 'Norfolk Island',
+	'MP' => 'Northern Mariana Islands',
+	'NO' => 'Norway',
+	'OM' => 'Oman',
+	'PK' => 'Pakistan',
+	'PW' => 'Palau',
+	'PS' => 'Palestinian Territory, Occupied',
+	'PA' => 'Panama',
+	'PG' => 'Papua New Guinea',
+	'PY' => 'Paraguay',
+	'PE' => 'Peru',
+	'PH' => 'Philippines',
+	'PN' => 'Pitcairn',
+	'PL' => 'Poland',
+	'PT' => 'Portugal',
+	'PR' => 'Puerto Rico',
+	'QA' => 'Qatar',
+	'RE' => 'Reunion',
+	'RO' => 'Romania',
+	'RU' => 'Russian Federation',
+	'RW' => 'Rwanda',
+	'BL' => 'Saint Barthelemy',
+	'SH' => 'Saint Helena',
+	'KN' => 'Saint Kitts And Nevis',
+	'LC' => 'Saint Lucia',
+	'MF' => 'Saint Martin',
+	'PM' => 'Saint Pierre And Miquelon',
+	'VC' => 'Saint Vincent And Grenadines',
+	'WS' => 'Samoa',
+	'SM' => 'San Marino',
+	'ST' => 'Sao Tome And Principe',
+	'SA' => 'Saudi Arabia',
+	'SN' => 'Senegal',
+	'RS' => 'Serbia',
+	'SC' => 'Seychelles',
+	'SL' => 'Sierra Leone',
+	'SG' => 'Singapore',
+	'SK' => 'Slovakia',
+	'SI' => 'Slovenia',
+	'SB' => 'Solomon Islands',
+	'SO' => 'Somalia',
+	'ZA' => 'South Africa',
+	'GS' => 'South Georgia And Sandwich Isl.',
+	'ES' => 'Spain',
+	'LK' => 'Sri Lanka',
+	'SD' => 'Sudan',
+	'SR' => 'Suriname',
+	'SJ' => 'Svalbard And Jan Mayen',
+	'SZ' => 'Swaziland',
+	'SE' => 'Sweden',
+	'CH' => 'Switzerland',
+	'SY' => 'Syrian Arab Republic',
+	'TW' => 'Taiwan',
+	'TJ' => 'Tajikistan',
+	'TZ' => 'Tanzania',
+	'TH' => 'Thailand',
+	'TL' => 'Timor-Leste',
+	'TG' => 'Togo',
+	'TK' => 'Tokelau',
+	'TO' => 'Tonga',
+	'TT' => 'Trinidad And Tobago',
+	'TN' => 'Tunisia',
+	'TR' => 'Turkey',
+	'TM' => 'Turkmenistan',
+	'TC' => 'Turks And Caicos Islands',
+	'TV' => 'Tuvalu',
+	'UG' => 'Uganda',
+	'UA' => 'Ukraine',
+	'AE' => 'United Arab Emirates',
+	'GB' => 'United Kingdom',
+	'US' => 'United States',
+	'UM' => 'United States Outlying Islands',
+	'UY' => 'Uruguay',
+	'UZ' => 'Uzbekistan',
+	'VU' => 'Vanuatu',
+	'VE' => 'Venezuela',
+	'VN' => 'Viet Nam',
+	'VG' => 'Virgin Islands, British',
+	'VI' => 'Virgin Islands, U.S.',
+	'WF' => 'Wallis And Futuna',
+	'EH' => 'Western Sahara',
+	'YE' => 'Yemen',
+	'ZM' => 'Zambia',
+	'ZW' => 'Zimbabwe',
+);
+?>

+ 281 - 0
core/install/resources/page_parts/install_config_database.php

@@ -0,0 +1,281 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+	Matthew Vale <[email protected]>
+*/
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<input type='hidden' name='install_language' value='".$_SESSION['domain']['language']['code']."'/>\n";
+	echo "<input type='hidden' name='return_install_step' value='config_database'/>\n";
+	echo "<input type='hidden' name='install_step' value='execute'/>\n";
+
+	echo "<input type='hidden' name='event_host' value='$event_host'/>\n";
+	echo "<input type='hidden' name='event_port' value='$event_port'/>\n";
+	echo "<input type='hidden' name='event_password' value='$event_password'/>\n";
+	echo "<input type='hidden' name='db_type' value='$db_type'/>\n";
+	echo "<input type='hidden' name='admin_username' value='$admin_username'/>\n";
+	echo "<input type='hidden' name='admin_password' value='$admin_password'/>\n";
+	echo "<input type='hidden' name='install_default_country' value='$install_default_country'/>\n";
+	echo "<input type='hidden' name='install_template_name' value='$install_template_name'/>\n";
+	echo "<input type='hidden' name='domain_name' value='$domain_name'/>\n";
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<td align='left' width='30%' nowrap><b>".$text['header-config_database']."</b></td>\n";
+	echo "<td width='70%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+
+	if ($db_type == "sqlite") {
+
+		echo "<tr>\n";
+		echo "<td class='vncell' 'valign='top' align='left' nowrap>\n";
+		echo "	Database Filename\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
+		echo "	Set the database filename. The file extension should be '.db'.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' 'valign='top' align='left' nowrap>\n";
+		echo "	Database Directory\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<input class='formfld' type='text' name='db_path' maxlength='255' value=\"$db_path\"><br />\n";
+		echo "	Set the path to the database directory.\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+	}
+
+	if ($db_type == "mysql") {
+
+		//set defaults
+			if (strlen($db_host) == 0) { $db_host = 'localhost'; }
+			if (strlen($db_port) == 0) { $db_port = '3306'; }
+			//if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; }
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Host\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_host' maxlength='255' value=\"$db_host\"><br />\n";
+		echo "		Enter the host address for the database server.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Database Port\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_port' maxlength='255' value=\"$db_port\"><br />\n";
+		echo "		Enter the port number. It is optional if the database is using the default port.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Name\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
+		echo "		Enter the name of the database.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Username\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_username' maxlength='255' value=\"$db_username\"><br />\n";
+		echo "		Enter the database username. \n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Password\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_password' maxlength='255' value=\"$db_password\"><br />\n";
+		echo "		Enter the database password.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Options\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='none'";
+		if($db_create_option=='none') { echo " checked='checked'"; }
+		echo "/>Do not create database</label>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='same'";
+		if($db_create_option=='same') { echo " checked='checked'"; }
+		echo "/>Create database using above username/password</label>\n";
+		echo "	<label class='radio'><input type='radio' name='create_db_option' value='user'";
+		if($db_create_option=='user') { echo " checked='checked'"; }
+		echo "/>Create database using below username/password</label>\n";
+		echo "<br />\n";
+		echo "Choose whether to create the database\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Username\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
+		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
+		echo "		By default this username is 'root' however it can be any account with permission to add a database, user, and grant permissions. \n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Password\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_create_password' maxlength='255' value=\"$db_create_password\"><br />\n";
+		echo "		Enter the create database password.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+	}
+
+	if ($db_type == "pgsql") {
+		if (strlen($db_host) == 0) { $db_host = 'localhost'; }
+		if (strlen($db_port) == 0) { $db_port = '5432'; }
+		if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; }
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Host\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_host' maxlength='255' value=\"$db_host\"><br />\n";
+		echo "		Enter the host address for the database server.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Database Port\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_port' maxlength='255' value=\"$db_port\"><br />\n";
+		echo "		Enter the port number. It is optional if the database is using the default port.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Name\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
+		echo "		Enter the name of the database.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Username\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_username' maxlength='255' value=\"$db_username\"><br />\n";
+		echo "		Enter the database username.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+		echo "		Database Password\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_password' maxlength='255' value=\"$db_password\"><br />\n";
+		echo "		Enter the database password.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Options\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "	<label class='radio'><input type='checkbox' name='db_create' value='1'";
+		if($db_create=='1') { echo " checked='checked'"; }
+		echo "/>Create the database</label>\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Username\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
+		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
+		echo "		By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n";
+		echo "		Leave blank to use the details above. \n";
+		echo "</td>\n";
+		echo "</tr>\n";
+
+		echo "<tr>\n";
+		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
+		echo "		Create Database Password\n";
+		echo "</td>\n";
+		echo "<td class='vtable' align='left'>\n";
+		echo "		<input class='formfld' type='text' name='db_create_password' maxlength='255' value=\"$db_create_password\"><br />\n";
+		echo "		Enter the create database password.\n";
+		echo "\n";
+		echo "</td>\n";
+		echo "</tr>\n";
+	}
+
+	echo "</table>";
+	echo "	<div style='text-align:right'>\n";
+	echo "    <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
+	echo "    <button type='submit'>".$text['button-install_execute']."</button>\n";
+	echo "	</div>\n";
+	echo "</form>\n";
+?>

+ 147 - 0
core/install/resources/page_parts/install_config_detail.php

@@ -0,0 +1,147 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+	Matthew Vale <[email protected]>
+*/
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<input type='hidden' name='install_language' value='".$_SESSION['domain']['language']['code']."'/>\n";
+	echo "<input type='hidden' name='return_install_step' value='config_detail'/>\n";
+	echo "<input type='hidden' name='install_step' value='config_database'/>\n";
+
+	echo "<input type='hidden' name='event_host' value='$event_host'/>\n";
+	echo "<input type='hidden' name='event_port' value='$event_port'/>\n";
+	echo "<input type='hidden' name='event_password' value='$event_password'/>\n";
+
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<td align='left' width='30%' nowrap><b>".$text['header-config_detail']."</b></td>\n";
+	echo "<td width='70%' align='right'>&nbsp;</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Username\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='admin_username' maxlength='255' value=\"$admin_username\"><br />\n";
+	echo "	Enter the username to use when logging in with the browser.<br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Password\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='admin_password' maxlength='255' value=\"$admin_password\"><br />\n";
+	echo "	Enter the password to use when logging in with the browser.<br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
+	echo "	Country\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "		<select id='install_default_country' name='install_default_country' class='formfld' style=''>\n";
+	require "resources/countries.php";
+ 
+	foreach ($countries as $iso_code => $country ){
+		if($iso_code == $install_default_country){
+			echo "			<option value='$iso_code' selected='selected'>".$country['country']."</option>\n";
+		}else{
+			echo "			<option value='$iso_code'>".$country['country']."</option>\n";
+		}
+	}
+	echo "		</select>\n";
+	echo "		<br />\n";
+	echo "	Select ISO country code used to initialize calling contry code variables.<br />\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "	<tr>\n";
+	echo "	<td width='20%' class=\"vncellreq\" align='left' nowrap='nowrap'>\n";
+	echo "		Theme: \n";
+	echo "	</td>\n";
+	echo "	<td class=\"vtable\" align='left'>\n";
+	echo "		<select id='install_template_name' name='install_template_name' class='formfld' style=''>\n";
+	echo "		<option value=''></option>\n";
+	//add all the themes to the list
+		$theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
+		if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
+			while (false !== ($dir_name = readdir($handle))) {
+				if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && $dir_name != "flags" && is_readable($theme_dir.'/'.$dir_name)) {
+					$dir_label = str_replace('_', ' ', $dir_name);
+					$dir_label = str_replace('-', ' ', $dir_label);
+					if ($dir_name == 'enhanced') {
+						echo "		<option value='$dir_name' selected='selected'>$dir_label</option>\n";
+					}
+					else {
+						echo "		<option value='$dir_name'>$dir_label</option>\n";
+					}
+				}
+			}
+			closedir($handle);
+		}
+	echo "		</select>\n";
+	echo "		<br />\n";
+	echo "		Select a theme to set as the default.<br />\n";
+	echo "	</td>\n";
+	echo "	</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "		Domain name\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "		<input class='formfld' type='text' name='domain_name' maxlength='255' value=\"$domain_name\"><br />\n";
+	echo "		Enter the default domain name. \n";
+	echo "\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "	Database Type\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<select name='db_type' id='db_type' class='formfld' id='form_tag' onchange='db_type_onchange();'>\n";
+	if (extension_loaded('pdo_pgsql')) {	echo "	<option value='pgsql'>postgresql</option>\n"; }
+	if (extension_loaded('pdo_mysql')) {	echo "	<option value='mysql'>mysql</option>\n"; }
+	if (extension_loaded('pdo_sqlite')) {	echo "	<option value='sqlite' selected='selected'>sqlite</option>\n"; } //set sqlite as the default
+	echo "	</select><br />\n";
+	echo "		Select the database type.\n";
+	echo "\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "	<div style='text-align:right'>\n";
+	echo "    <button type='button' onclick=\"history.go(-1);\">".$text['button-back']."</button>\n";
+	echo "    <button type='submit' id='next'>".$text['button-next']."</button>\n";
+	echo "	</div>\n";
+	echo "</form>\n";
+?>

+ 144 - 0
core/install/resources/page_parts/install_event_socket.php

@@ -0,0 +1,144 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Matthew Vale <[email protected]>
+*/
+	//fetch the values
+	require_once "core/install/resources/classes/detect_switch.php";
+	$switch_detect = new detect_switch($event_host, $event_port, $event_password);
+	//$switch_detect->event_port = 2021;
+	$detect_ok = true;
+	try {
+		$switch_detect->detect();
+	} catch(Exception $e){
+		echo "<p><b>Failed to detect configuration</b> detect_switch reported: " . $e->getMessage() ."</p>\n";
+		$detect_ok = false;
+	}
+	echo "<form method='post' name='detect_switch' action=''>\n";
+	echo "<input type='hidden' name='install_language' value='".$_SESSION['domain']['language']['code']."'/>\n";
+	echo "<input type='hidden' name='install_step' value='detect_config'/>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<td width='30%' align='left' nowrap><b>".$text['header-event_socket']."</b><br><br></td>\n";
+	echo "<td width='70%' align='right'>";
+	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-detect']."'/>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "	".$text['label-event_host']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='event_host' maxlength='255' value=\"".$switch_detect->event_host."\" onchange='JavaScript:disable_next()'/>\n";
+	echo "<br />\n";
+	echo $text['description-event_host']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "	".$text['label-event_port']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='text' name='event_port' maxlength='255' value=\"".$switch_detect->event_port."\" onchange='JavaScript:disable_next()'/>\n";
+	echo "<br />\n";
+	echo $text['description-event_port']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "	".$text['label-event_password']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+	echo "	<input class='formfld' type='password' name='event_password' maxlength='255' value=\"".$switch_detect->event_password."\" onchange='JavaScript:disable_next()'/>\n";
+	echo "<br />\n";
+	echo $text['description-event_password']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "	<tr>\n";
+	echo "		<td colspan='2' align='right'>\n";
+	echo "			<br>";
+	echo "		</td>\n";
+	echo "	</tr>";
+
+	echo "</table>";
+	echo "</form>";
+	if($detect_ok){
+		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	
+		echo "<tr>\n";
+		echo "<td colspan='4' align='left' nowrap><b>".$text['title-detected_configuration']."</b></td>\n";
+		echo "</tr>\n";
+
+		$id = 1;
+		echo "<tr>\n";
+		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
+		echo "Switch version\n";
+		echo "</td>\n";
+		echo "<td class='vtable' width='35%' align='left'>\n";
+		echo "    ".$switch_detect->version()."\n";
+		echo "</td>\n";
+		
+		foreach ($switch_detect->get_dirs() as $folder)
+		{
+			if($id % 2 == 0){ echo "<tr>\n"; }
+			echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
+			echo $folder."\n";
+			echo "</td>\n";
+			echo "<td class='vtable' width='35%' align='left'>\n";
+			echo "    ".$switch_detect->$folder()."\n";
+			echo "</td>\n";
+			if($id % 2 == 1){ echo "</tr>\n"; }
+			$id++;
+		}
+		if($id % 2 == 1){ echo "</tr>\n"; }
+		echo "<tr>\n";
+		echo "<td colspan='4' align='left' nowrap><br/><b>".$text['title-assumed_configuration']."</b></td>\n";
+		echo "</tr>\n";
+		$id=0;
+		foreach ($switch_detect->get_vdirs() as $folder)
+		{
+			if($id % 2 == 0){ echo "<tr>\n"; }
+			echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='15%'>\n";
+			echo $folder."\n";
+			echo "</td>\n";
+			echo "<td class='vtable' width='35%' align='left'>\n";
+			echo "    ".$switch_detect->$folder()."\n";
+			echo "</td>\n";
+			if($id % 2 == 1){ echo "</tr>\n"; }
+			$id++;
+		}
+			
+		echo "</table>";
+	}
+
+
+?><script type='text/javascript'>
+function disable_next() {
+	document.getElementById("next").style.display = 'none';
+}
+</script>

+ 69 - 0
core/install/resources/page_parts/install_select_language.php

@@ -0,0 +1,69 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Matthew Vale <[email protected]>
+*/
+
+	echo "<form method='post' name='frm' action=''>\n";
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+
+	echo "<tr>\n";
+	echo "<td width='30%' align='left' nowrap><b>".$text['header-select_language']."</b><br><br></td>\n";
+	echo "<td width='70%' align='right'>";
+	echo "	<input type='submit' name='submit' class='btn' value='".$text['button-select']."'/>\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+	
+	echo "<tr>\n";
+	echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
+	echo "	".$text['label-select_language']."\n";
+	echo "</td>\n";
+	echo "<td class='vtable' align='left'>\n";
+		echo "<fieldset class='container'>";
+	foreach($_SESSION['app']['languages'] as $lang_code){
+		echo "<fieldset class='container'>";
+		echo "	<label class='radio' style='width:200px;'>";
+		echo "<input type='radio' name='install_language' value='$lang_code' id='lang_$lang_code' onchange='JavaScript:disable_next()'";
+		if($lang_code == $_SESSION['domain']['language']['code'])
+		{
+			echo " checked='checked'";
+		}
+		echo "/>";
+		echo "<img src='<!--{project_path}-->/themes/flags/$lang_code.png' alt='$lang_code'/>&nbsp;".$text["language-$lang_code"];
+		echo "</label>\n";
+		echo "</fieldset>";
+	}
+	echo "</fieldset>";
+	echo "<br />\n";
+	echo $text['description-select_language']."\n";
+	echo "</td>\n";
+	echo "</tr>\n";
+
+	echo "</table>";
+	echo "<br><br>";
+	echo "</form>";
+?><script type='text/javascript'>
+function disable_next() {
+	document.getElementById("next").style.display = 'none';
+}
+</script>

+ 50 - 0
core/install/root.php

@@ -0,0 +1,50 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+
+// make sure the PATH_SEPARATOR is defined
+	if (!defined("PATH_SEPARATOR")) {
+		if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); }
+	}
+
+// make sure the document_root is set
+	$_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]);
+	$_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]);
+	//echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."<br />\n";
+	//echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."<br />\n";
+	//echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."<br />\n";
+
+// if the project directory exists then add it to the include path otherwise add the document root to the include path
+	if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' );
+	}
+	else {
+		if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); }
+		set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] );
+	}
+
+?>

+ 59 - 0
core/install/upgrade_switch.php

@@ -0,0 +1,59 @@
+<?php
+/*
+	FusionPBX
+	Version: MPL 1.1
+
+	The contents of this file are subject to the Mozilla Public License Version
+	1.1 (the "License"); you may not use this file except in compliance with
+	the License. You may obtain a copy of the License at
+	http://www.mozilla.org/MPL/
+
+	Software distributed under the License is distributed on an "AS IS" basis,
+	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+	for the specific language governing rights and limitations under the
+	License.
+
+	The Original Code is FusionPBX
+
+	The Initial Developer of the Original Code is
+	Mark J Crane <[email protected]>
+	Portions created by the Initial Developer are Copyright (C) 2008-2012
+	the Initial Developer. All Rights Reserved.
+
+	Contributor(s):
+	Mark J Crane <[email protected]>
+*/
+
+// set included, if not
+	if (!isset($included)) { $included = false; }
+
+//check the permission
+	if(defined('STDIN')) {
+		$document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
+		preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
+		$document_root = $matches[1];
+		set_include_path($document_root);
+		require_once "resources/require.php";
+		$_SERVER["DOCUMENT_ROOT"] = $document_root;
+		$format = 'text'; //html, text
+	}
+	else if (!$included) {
+		include "root.php";
+		require_once "resources/require.php";
+		require_once "resources/check_auth.php";
+		if (permission_exists('upgrade_switch') || if_group("superadmin")) {
+			//echo "access granted";
+		}
+		else {
+			echo "access denied";
+			exit;
+		}
+		$format = 'html'; //html, text
+	}
+
+//run switch upgrade
+	require_once "resources/classes/install_switch.php";
+	$switch = new install_switch();
+	$switch->upgrade();
+
+?>

+ 3 - 0
core/upgrade/app_config.php

@@ -32,6 +32,9 @@
 		$apps[$x]['permissions'][$y]['menu']['uuid'] = "e7bb1296-3141-48c9-a95a-82d2768d0ae4";
 		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
 		$y++;
+		$apps[$x]['permissions'][$y]['name'] = "upgrade_switch";
+		$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
+		$y++;
 
 	//schema details
 		$y = 0; //table array index

+ 0 - 13
core/upgrade/app_defaults.php

@@ -26,19 +26,6 @@
 
 
 if ($domains_processed == 1) {
-	//process if the scripts directory exists
-		if (strlen($_SESSION['switch']['scripts']['dir']) > 0) {
-			//if the resource scripts resource directory does not exist then create it
-				if (!is_dir($_SESSION['switch']['scripts']['dir']."/resources")) {
-					mkdir($_SESSION['switch']['scripts']['dir']."/resources",0755,true);
-				}
-
-			//copy the files and directories from resources/install
-				$install = new install;
-				$install->domain_uuid = $domain_uuid;
-				$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
-				$install->copy_scripts();
-		}
 
 	//update the software table
 		$sql = "select count(*) as num_rows from v_software ";

+ 20 - 0
core/upgrade/app_languages.php

@@ -180,6 +180,16 @@ $text['label-upgrade_apps']['sv-se'] = "App Standard";
 $text['label-upgrade_apps']['uk'] = "Типові значення додатків";
 $text['label-upgrade_apps']['de-at'] = "Applikationen zurücksetzen";
 
+$text['label-upgrade_switch']['en-us'] = "Switch Upgrade";
+$text['label-upgrade_switch']['es-cl'] = "";
+$text['label-upgrade_switch']['pt-pt'] = "";
+$text['label-upgrade_switch']['fr-fr'] = "";
+$text['label-upgrade_switch']['pt-br'] = "";
+$text['label-upgrade_switch']['pl'] = "";
+$text['label-upgrade_switch']['sv-se'] = "";
+$text['label-upgrade_switch']['uk'] = "";
+$text['label-upgrade_switch']['de-at'] = "";
+
 $text['label-upgrade']['en-us'] = "Upgrade";
 $text['label-upgrade']['es-cl'] = "Actualizar";
 $text['label-upgrade']['pt-pt'] = "Actualizar";
@@ -390,6 +400,16 @@ $text['description-upgrade_apps']['sv-se'] = "Återställer standardinställning
 $text['description-upgrade_apps']['uk'] = "Встановлює типові значення для додатків";
 $text['description-upgrade_apps']['de-at'] = "Setzt alle Applikationen auf die Standardeinstellungen zurück.";
 
+$text['description-upgrade_switch']['en-us'] = "Runs the upgrade switch routine.";
+$text['description-upgrade_switch']['es-cl'] = "";
+$text['description-upgrade_switch']['pt-pt'] = "";
+$text['description-upgrade_switch']['fr-fr'] = "";
+$text['description-upgrade_switch']['pt-br'] = "";
+$text['description-upgrade_switch']['pl'] = "";
+$text['description-upgrade_switch']['sv-se'] = "";
+$text['description-upgrade_switch']['uk'] = "";
+$text['description-upgrade_switch']['de-at'] = "";
+
 $text['description-upgrade']['en-us'] = "Select the actions below you wish to perform.";
 $text['description-upgrade']['es-cl'] = "Seleccione las acciones a continuación que desea realizar.";
 $text['description-upgrade']['pt-pt'] = "Selecione as ações abaixo você deseja executar.";

+ 27 - 5
core/upgrade/index.php

@@ -35,6 +35,7 @@ if (
 	!permission_exists('upgrade_source') &&
 	!permission_exists('upgrade_schema') &&
 	!permission_exists('upgrade_apps') &&
+	!permission_exists('upgrade_switch') &&
 	!permission_exists('menu_restore') &&
 	!permission_exists('group_edit')
 	) {
@@ -52,7 +53,7 @@ if (sizeof($_POST) > 0) {
 
 	// run source update
 	if ($do["source"] && permission_exists("upgrade_source") && !is_dir("/usr/share/examples/fusionpbx")) {
-		chdir("/var/www/fusionpbx/");
+		chdir($_SERVER["DOCUMENT_ROOT"]);
 		exec("git pull", $response_source_update);
 		$update_failed = true;
 		if (sizeof($response_source_update) > 0) {
@@ -72,10 +73,8 @@ if (sizeof($_POST) > 0) {
 			//update scripts folder, if allowed (default)
 				if ($_SESSION['switch']['scripts']['dir'] != '') {
 					//copy the files and directories from resources/install
-						$install = new install;
-						$install->domain_uuid = $domain_uuid;
-						$install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
-						$install->copy_scripts();
+						$obj = new install_switch;
+						$obj->upgrade();
 					//set the message
 						$response_message = $text['message-upgrade_source_scripts'];
 				}
@@ -123,6 +122,13 @@ if (sizeof($_POST) > 0) {
 		$response_message = "Permission Defaults Restored";
 	}
 
+	// upgrade switch
+	if ($do["switch"] && permission_exists("upgrade_switch")) {
+		$included = true;
+		require_once("core/install/upgrade_switch.php");
+		$response_message = "Switch Upgraded";
+	}
+
 	if (sizeof($_POST['do']) > 1) {
 		$response_message = $text['message-upgrade'];
 	}
@@ -252,6 +258,22 @@ if (permission_exists("group_edit")) {
 	echo "</table>\n";
 }
 
+if (permission_exists("upgrade_switch")) {
+	echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
+	echo "<tr>\n";
+	echo "	<td width='30%' class='vncell'>\n";
+	echo "		".$text['label-upgrade_switch'];
+	echo "	</td>\n";
+	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
+	echo "		<label for='do_switch'>";
+	echo "			<input type='checkbox' class='formfld' name='do[switch]' id='do_switch' value='1'>";
+	echo "			".$text['description-upgrade_switch'];
+	echo "		</label>\n";
+	echo "	</td>\n";
+	echo "</tr>\n";
+	echo "</table>\n";
+}
+
 echo "<br>";
 echo "<div style='text-align: right;'><input type='submit' class='btn' value='".$text['button-upgrade_execute']."'></div>";
 echo "<br><br>";

+ 4 - 1
core/upgrade/upgrade.php

@@ -67,7 +67,10 @@
 	$obj = new schema;
 	echo $obj->schema("text");
 
-//run all app_defaults.php files
+//request the switch to perform upgrade functions
+	$obj = new install_switch;
+	$obj->upgrade();
+
 	require_once "resources/classes/domains.php";
 	$domain = new domains;
 	$domain->upgrade();

+ 1 - 1
index.php

@@ -41,7 +41,7 @@ include "root.php";
 	} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
 		//bsd
 	} else {
-		header("Location: ".PROJECT_PATH."/resources/install.php");
+		header("Location: ".PROJECT_PATH."/core/install/install_first_time.php");
 		exit;
 	}
 

+ 127 - 0
resources/classes/config.php

@@ -0,0 +1,127 @@
+<?php
+
+/**
+ * config
+ *
+ * @method get config.php
+ * @method find find the path to the config.php file
+ * @method exists determin if the the config.php file exists
+ */
+class config {
+
+	/**
+	 * database variables and config path
+	 */
+	public $db_type;
+	public $db_name;
+	public $db_username;
+	public $db_password;
+	public $db_host;
+	public $db_path;
+	public $db_port;
+	public $config_path;
+
+	/**
+	 * Called when the object is created
+	 */
+	public function __construct() {
+		//place holder
+	}
+
+	/**
+	 * Called when there are no references to a particular object
+	 * unset the variables used in the class
+	 */
+	public function __destruct() {
+		foreach ($this as $key => $value) {
+			unset($this->$key);
+		}
+	}
+
+	/**
+	 * Determine whether the config.php exists
+	 * @var string $db_type - type of database
+	 * @var string $db_name - name of the database
+	 * @var string $db_username - username to access the database
+	 * @var string $db_password - password to access the database
+	 * @var string $db_host - hostname of the database server
+	 * @var string $db_path - path of the database file
+	 * @var string $db_port - network port to connect to the database
+	 */
+	public function get() {
+		$this->find();
+		if ($this->exists()) {
+			require $this->config_path;
+			$this->db_type = $db_type;
+			$this->db_name = $db_name;
+			$this->db_username = $db_username;
+			$this->db_password = $db_password;
+			$this->db_host = $db_host;
+			$this->db_path = $db_path;
+			$this->db_port = $db_port;
+		}
+	}
+
+	/**
+	 * Find the path to the config.php
+	 * @var string $config_path - full path to the config.php file
+	 */
+	public function find() {
+		//get the PROJECT PATH
+			include "root.php";
+		// find the file
+			if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
+				$this->config_path = $_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php";
+			} elseif (file_exists("/etc/fusionpbx/config.php")) {
+				$this->config_path = "/etc/fusionpbx/config.php";
+			} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
+				$this->config_path = "/usr/local/etc/fusionpbx/config.php";
+			}
+			else {
+				$this->config_path = '';
+			}
+		//return the path
+			return $this->config_path;
+	}
+
+	/**
+	 * Determine whether the config.php exists
+	 */
+	public function exists() {
+		$this->find();
+		if (strlen($this->config_path) > 0) {
+			return true;
+		}
+		else {
+			return false;
+		}
+	}
+}
+/*
+$config = new config;
+$config_exists = $config->exists();
+$config_path = $config->find();
+$config->get();
+$db_type = $config->db_type;
+$db_name = $config->db_name;
+$db_username = $config->db_username;
+$db_password = $config->db_password;
+$db_host = $config->db_host;
+$db_path = $config->db_path;
+$db_port = $config->db_port;
+echo "config_path: ".$config_path."\n";
+if ($config_exists) {
+	echo "config_exists: true\n";
+} else {
+	echo "config_exists: false\n";
+}
+echo "db_type: ".$db_type."\n";
+echo "db_name: ".$db_name."\n";
+echo "db_username: ".$db_username."\n";
+echo "db_password: ".$db_password."\n";
+echo "db_host: ".$db_host."\n";
+echo "db_path: ".$db_path."\n";
+echo "db_port: ".$db_port."\n";
+*/
+
+?>

+ 18 - 40
resources/classes/domains.php

@@ -186,36 +186,25 @@
 			//set the context
 				$_SESSION["context"] = $_SESSION["domain_name"];
 
-			//recordings add the domain to the path if there is more than one domains
-				if (count($_SESSION["domains"]) > 1) {
-					if (strlen($_SESSION['switch']['recordings']['dir']) > 0) {
-						if (substr($_SESSION['switch']['recordings']['dir'], -strlen($_SESSION["domain_name"])) != $_SESSION["domain_name"]) {
-							//get the default recordings directory
-							$sql = "select * from v_default_settings ";
-							$sql .= "where default_setting_enabled = 'true' ";
-							$sql .= "and default_setting_category = 'switch' ";
-							$sql .= "and default_setting_subcategory = 'recordings' ";
-							$sql .= "and default_setting_name = 'dir' ";
-							$prep_statement = $db->prepare($sql);
-							$prep_statement->execute();
-							$result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-							foreach ($result_default_settings as $row) {
-								$name = $row['default_setting_name'];
-								$category = $row['default_setting_category'];
-								$subcategory = $row['default_setting_subcategory'];
-								$switch_recordings_dir = $row['default_setting_value'];
-							}
-							//add the domain
-							$_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir . '/' . $_SESSION["domain_name"];
-						}
-					}
-				}
 		}
 
 		public function upgrade() {
 
 			//set the global variable
-				global $db, $db_type, $db_name, $db_username, $db_password, $db_host, $db_path, $db_port;
+				global $db;
+
+			//get the db variables
+				$config = new config;
+				$config_exists = $config->exists();
+				$config_path = $config->find();
+				$config->get();
+				$db_type = $config->db_type;
+				$db_name = $config->db_name;
+				$db_username = $config->db_username;
+				$db_password = $config->db_password;
+				$db_host = $config->db_host;
+				$db_path = $config->db_path;
+				$db_port = $config->db_port;
 
 			//get the PROJECT PATH
 				include "root.php";
@@ -259,16 +248,6 @@
 				$prep_statement->execute();
 				$result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
 
-			//get the default recordings directory
-				foreach($result_default_settings as $row) {
-					$name = $row['default_setting_name'];
-					$category = $row['default_setting_category'];
-					$subcategory = $row['default_setting_subcategory'];
-					if ($category == 'switch' && $subcategory == 'recordings' && $name == 'dir') {
-						$switch_recordings_dir = $row['default_setting_value'];
-					}
-				}
-
 			//loop through all domains
 				$sql = "select * from v_domains ";
 				$v_prep_statement = $db->prepare(check_sql($sql));
@@ -336,11 +315,6 @@
 							}
 						}
 
-					//set the recordings directory
-						if (strlen($switch_recordings_dir) > 1 && count($_SESSION["domains"]) > 1) {
-							$_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir."/".$domain_name;
-						}
-
 					//get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
 						$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
 						foreach ($default_list as &$default_path) {
@@ -356,6 +330,10 @@
 				if (function_exists('save_dialplan_xml')) {
 					save_dialplan_xml();
 				}
+			//update config.lua
+				require_once "core/install/resources/classes/install_switch.php";
+				$switch = new install_switch;
+				$switch->create_config_lua();
 
 			//clear the session variables
 				unset($_SESSION['domain']);

+ 0 - 207
resources/classes/install.php

@@ -1,207 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Copyright (C) 2010-2015
-	All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-include "root.php";
-
-//define the install class
-	class install {
-
-		var $result;
-		var $domain_uuid;
-		var $domain;
-		var $switch_conf_dir;
-		var $switch_scripts_dir;
-		var $switch_sounds_dir;
-
-		//$options '-n' --no-clobber
-		public function recursive_copy($src, $dst, $options = '') {
-			if (file_exists('/bin/cp')) {
-				if (strtoupper(substr(PHP_OS, 0, 3)) === 'SUN') {
-					//copy -R recursive, preserve attributes for SUN
-					$cmd = 'cp -Rp '.$src.'/* '.$dst;
-				} else {
-					//copy -R recursive, -L follow symbolic links, -p preserve attributes for other Posix systemss
-					$cmd = 'cp -RLp '.$options.' '.$src.'/* '.$dst;
-				}
-				exec ($cmd);
-				//echo $cmd."\n";
-			}
-			else {
-				$dir = opendir($src);
-				if (!$dir) {
-					if (!mkdir($src, 0755, true)) {
-						throw new Exception("recursive_copy() source directory '".$src."' does not exist.");
-					}
-				}
-				if (!is_dir($dst)) {
-					if (!mkdir($dst, 0755, true)) {
-						throw new Exception("recursive_copy() failed to create destination directory '".$dst."'");
-					}
-				}
-				$scripts_dir_target = $_SESSION['switch']['scripts']['dir'];
-				$scripts_dir_source = realpath($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts');
-				foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($src)) as $file_path_source) {
-					if (
-					substr_count($file_path_source, '/..') == 0 &&
-					substr_count($file_path_source, '/.') == 0 &&
-					substr_count($file_path_source, '/.svn') == 0 &&
-					substr_count($file_path_source, '/.git') == 0
-					) {
-						if ($dst != $src.'/resources/config.lua') {
-							//echo $file_path_source.' ---> '.$dst.'<br>';
-							copy($file_path_source, $dst);
-							chmod($dst, 0755);
-						}
-					}
-				}
-
-				while(false !== ($file = readdir($dir))) {
-					if (($file != '.') && ($file != '..')) {
-						if (is_dir($src.'/'.$file)) {
-							$this->recursive_copy($src.'/'.$file, $dst.'/'.$file);
-						}
-						else {
-							//copy only missing files -n --no-clobber
-								if (strpos($options,'-n') !== false) {
-									if (!file_exists($dst.'/'.$file)) {
-										copy($src.'/'.$file, $dst.'/'.$file);
-										//echo "copy(".$src."/".$file.", ".$dst."/".$file.");<br />\n";
-									}
-								}
-								else {
-									copy($src.'/'.$file, $dst.'/'.$file);
-								}
-						}
-					}
-				}
-				closedir($dir);
-			}
-		}
-
-		function recursive_delete($dir) {
-			if (file_exists('/bin/rm')) {
-				 exec ('rm -Rf '.$dir.'/*');
-			}
-			else {
-				foreach (glob($dir) as $file) {
-					if (is_dir($file)) {
-						$this->recursive_delete("$file/*");
-						rmdir($file);
-						//echo "rm dir: ".$file."\n";
-					} else {
-						//echo "delete file: ".$file."\n";
-						unlink($file);
-					}
-				}
-			}
-			clearstatcache();
-		}
-
-		function copy() {
-			$this->copy_scripts();
-			//$this->copy_sounds();
-		}
-
-		function copy_conf() {
-			if (file_exists($this->switch_conf_dir)) {
-				//make a backup copy of the conf directory
-					$src_dir = $this->switch_conf_dir;
-					$dst_dir = $this->switch_conf_dir.'.orig';
-					if (is_readable($src_dir)) {
-						$this->recursive_copy($src_dir, $dst_dir);
-						$this->recursive_delete($src_dir);
-					}
-					else {
-						if ($src_dir != "/conf") {
-							mkdir($src_dir, 0774, true);
-						}
-					}
-				//make sure the conf directory exists
-					if (!is_dir($this->switch_conf_dir)) {
-						if (!mkdir($this->switch_conf_dir, 0774, true)) {
-							throw new Exception("Failed to create the switch conf directory '".$this->switch_conf_dir."'. ");
-						}
-					}
-				//copy resources/templates/conf to the freeswitch conf dir
-					if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
-						$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
-					}
-					else {
-						$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
-					}
-					$dst_dir = $this->switch_conf_dir;
-					if (is_readable($dst_dir)) {
-						$this->recursive_copy($src_dir, $dst_dir);
-					}
-					//print_r($install->result);
-			}
-		}
-		// added /examples/ into the string
-		function copy_scripts() {
-			if (file_exists($this->switch_scripts_dir)) {
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/scripts')){
-					$src_dir = '/usr/share/examples/fusionpbx/resources/install/scripts';
-				}
-				else {
-					$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/scripts';
-				}
-				$dst_dir = $this->switch_scripts_dir;
-				if (is_readable($this->switch_scripts_dir)) {
-					$this->recursive_copy($src_dir, $dst_dir, $_SESSION['scripts']['options']['text']);
-					unset($src_dir, $dst_dir);
-				}
-				chmod($dst_dir, 0774);
-			}
-		}
-		
-		//function copy_sounds() {
-		//	if (file_exists($this->switch_sounds_dir)) {
-		//			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/')){
-		//			$src_dir = '/usr/share/examples/fusionpbx/resources/install/sounds/en/us/callie/custom/';
-					// changes the output dir for testing
-		//			$dst_dir = $this->switch_sounds_dir.'/en/us/fusionpbx/custom/';
-		//		}
-		//		else {
-		//			$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sounds/en/us/callie/custom/';
-		//			$dst_dir = $this->switch_sounds_dir.'/en/us/callie/custom/';
-		//		}
-		//		$this->recursive_copy($src_dir, $dst_dir, "-n");
-		//		if (is_readable($this->switch_sounds_dir)) {
-		//			$this->recursive_copy($src_dir, $dst_dir);
-		//			chmod($dst_dir, 0664);
-		//		}
-		//	}
-		//}
-	}
-
-//how to use the class
-	//$install = new install;
-	//$install->domain_uuid = $domain_uuid;
-	//$install->switch_conf_dir = $switch_conf_dir;
-	//$install->switch_scripts_dir = $switch_scripts_dir;
-	//$install->switch_sounds_dir = $switch_sounds_dir;
-	//$install->copy();
-	//print_r($install->result);
-?>

+ 14 - 2
resources/classes/schema.php

@@ -448,8 +448,20 @@ include "root.php";
 			public function schema ($format) {
 
 				//set the global variable
-					global $db, $db_type, $db_name, $db_username, $db_password;
-					global $db_host, $db_path, $db_port, $upgrade_data_types, $text;
+					global $db, $upgrade_data_types, $text;
+
+				//get the db variables
+					$config = new config;
+					$config_exists = $config->exists();
+					$config_path = $config->find();
+					$config->get();
+					$db_type = $config->db_type;
+					$db_name = $config->db_name;
+					$db_username = $config->db_username;
+					$db_password = $config->db_password;
+					$db_host = $config->db_host;
+					$db_path = $config->db_path;
+					$db_port = $config->db_port;
 
 				//get the PROJECT PATH
 					include "root.php";

+ 20 - 15
resources/classes/text.php

@@ -1,19 +1,16 @@
 <?php
-
 /**
  * Get the text for the correct translation
  *
  * @method array get
  */
 class text {
-
 	/**
 	 * Called when the object is created
 	 */
 	public function __construct() {
 		//place holder
 	}
-
 	/**
 	 * Called when there are no references to a particular object
 	 * unset the variables used in the class
@@ -23,13 +20,14 @@ class text {
 			unset($this->$key);
 		}
 	}
-
 	/**
 	 * Get a specific item from the cache
 	 * @var string $language_code	examples: en-us, es-cl, fr-fr, pt-pt
 	 * @var string $app_path		examples: app/exec or core/domains
 	 */
 	public function get($language_code = null, $app_path = null) {
+		//get the global app_languages.php
+			include $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/core/app_languages.php";
 		//get the app_languages.php
 			if ($app_path != null) {
 				include $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/".$app_path."/app_languages.php";
@@ -37,7 +35,6 @@ class text {
 			else {
 				include getcwd().'/app_languages.php';
 			}
-
 		//get the available languages
 			krsort($text);
 			foreach ($text as $lang_label => $lang_codes) {
@@ -48,24 +45,32 @@ class text {
 				}
 			}
 			$_SESSION['app']['languages'] = array_unique($app_languages);
-
+		//check the session language
+			if(isset($_SESSION['domain'])){
+				$language_code = $_SESSION['domain']['language']['code'];
+			}elseif($language_code == null){
+				$language_code = 'en-us';
+			}
 		//reduce to specific language
 			if ($language_code != 'all') {
 				foreach($text as $key => $value) {
-					if ($language_code == null) {
-						$text[$key] = $value[$_SESSION['domain']['language']['code']];
-					}
-					else {
-						$text[$key] = $value[$language_code];
+					$text[$key] = $value[$language_code];
+				}
+			}
+			if ($language_code != 'all') {
+				foreach($language_name as $code => $value) {
+					$text["language-$code"] = $value;
+				}
+			}else{
+				foreach($language_name as $code => $value) {
+					foreach($language_name as $c_code => $value) {
+						$text["language-$code"][$c_code] = $value;
 					}
 				}
 			}
-
+			
 		//return the array of translations
 			return $text;
-
 	}
-
 }
-
 ?>

+ 916 - 0
resources/countries.php

@@ -0,0 +1,916 @@
+<?php
+
+$countries['AF']['country'] = 'Afghanistan';
+$countries['AF']['countrycode'] = '93';
+$countries['AF']['exitcode'] = '00';
+$countries['AF']['isocode'] = 'AF';
+$countries['AL']['country'] = 'Albania';
+$countries['AL']['countrycode'] = '355';
+$countries['AL']['exitcode'] = '00';
+$countries['AL']['isocode'] = 'AL';
+$countries['DZ']['country'] = 'Algeria';
+$countries['DZ']['countrycode'] = '213';
+$countries['DZ']['exitcode'] = '00';
+$countries['DZ']['isocode'] = 'DZ';
+$countries['AS']['country'] = 'American Samoa';
+$countries['AS']['countrycode'] = '1';
+$countries['AS']['exitcode'] = '011';
+$countries['AS']['isocode'] = 'AS';
+$countries['AD']['country'] = 'Andorra';
+$countries['AD']['countrycode'] = '376';
+$countries['AD']['exitcode'] = '00';
+$countries['AD']['isocode'] = 'AD';
+$countries['AO']['country'] = 'Angola';
+$countries['AO']['countrycode'] = '244';
+$countries['AO']['exitcode'] = '00';
+$countries['AO']['isocode'] = 'AO';
+$countries['AI']['country'] = 'Anguilla';
+$countries['AI']['countrycode'] = '1';
+$countries['AI']['exitcode'] = '011';
+$countries['AI']['isocode'] = 'AI';
+$countries['AG']['country'] = 'Antigua and Barbuda';
+$countries['AG']['countrycode'] = '1';
+$countries['AG']['exitcode'] = '011';
+$countries['AG']['isocode'] = 'AG';
+$countries['AR']['country'] = 'Argentina';
+$countries['AR']['countrycode'] = '54';
+$countries['AR']['exitcode'] = '00';
+$countries['AR']['isocode'] = 'AR';
+$countries['AM']['country'] = 'Armenia';
+$countries['AM']['countrycode'] = '374';
+$countries['AM']['exitcode'] = '00';
+$countries['AM']['isocode'] = 'AM';
+$countries['AW']['country'] = 'Aruba';
+$countries['AW']['countrycode'] = '297';
+$countries['AW']['exitcode'] = '00';
+$countries['AW']['isocode'] = 'AW';
+$countries['AC']['country'] = 'Ascension';
+$countries['AC']['countrycode'] = '247';
+$countries['AC']['exitcode'] = '00';
+$countries['AC']['isocode'] = 'AC';
+$countries['AU']['country'] = 'Australia';
+$countries['AU']['countrycode'] = '61';
+$countries['AU']['exitcode'] = '0011';
+$countries['AU']['isocode'] = 'AU';
+$countries['AT']['country'] = 'Austria';
+$countries['AT']['countrycode'] = '43';
+$countries['AT']['exitcode'] = '00';
+$countries['AT']['isocode'] = 'AT';
+$countries['AZ']['country'] = 'Azerbaijan';
+$countries['AZ']['countrycode'] = '994';
+$countries['AZ']['exitcode'] = '00';
+$countries['AZ']['isocode'] = 'AZ';
+$countries['BS']['country'] = 'Bahamas';
+$countries['BS']['countrycode'] = '1';
+$countries['BS']['exitcode'] = '011';
+$countries['BS']['isocode'] = 'BS';
+$countries['BH']['country'] = 'Bahrain';
+$countries['BH']['countrycode'] = '973';
+$countries['BH']['exitcode'] = '00';
+$countries['BH']['isocode'] = 'BH';
+$countries['BD']['country'] = 'Bangladesh';
+$countries['BD']['countrycode'] = '880';
+$countries['BD']['exitcode'] = '00';
+$countries['BD']['isocode'] = 'BD';
+$countries['BB']['country'] = 'Barbados';
+$countries['BB']['countrycode'] = '1';
+$countries['BB']['exitcode'] = '011';
+$countries['BB']['isocode'] = 'BB';
+$countries['BY']['country'] = 'Belarus';
+$countries['BY']['countrycode'] = '375';
+$countries['BY']['exitcode'] = '810';
+$countries['BY']['isocode'] = 'BY';
+$countries['BE']['country'] = 'Belgium';
+$countries['BE']['countrycode'] = '32';
+$countries['BE']['exitcode'] = '00';
+$countries['BE']['isocode'] = 'BE';
+$countries['BZ']['country'] = 'Belize';
+$countries['BZ']['countrycode'] = '501';
+$countries['BZ']['exitcode'] = '00';
+$countries['BZ']['isocode'] = 'BZ';
+$countries['BJ']['country'] = 'Benin';
+$countries['BJ']['countrycode'] = '229';
+$countries['BJ']['exitcode'] = '00';
+$countries['BJ']['isocode'] = 'BJ';
+$countries['BM']['country'] = 'Bermuda';
+$countries['BM']['countrycode'] = '1';
+$countries['BM']['exitcode'] = '011';
+$countries['BM']['isocode'] = 'BM';
+$countries['BT']['country'] = 'Bhutan';
+$countries['BT']['countrycode'] = '975';
+$countries['BT']['exitcode'] = '00';
+$countries['BT']['isocode'] = 'BT';
+$countries['BO']['country'] = 'Bolivia';
+$countries['BO']['countrycode'] = '591';
+$countries['BO']['exitcode'] = '00';
+$countries['BO']['isocode'] = 'BO';
+$countries['BA']['country'] = 'Bosnia and Herzegovina';
+$countries['BA']['countrycode'] = '387';
+$countries['BA']['exitcode'] = '00';
+$countries['BA']['isocode'] = 'BA';
+$countries['BW']['country'] = 'Botswana';
+$countries['BW']['countrycode'] = '267';
+$countries['BW']['exitcode'] = '00';
+$countries['BW']['isocode'] = 'BW';
+$countries['BR']['country'] = 'Brazil';
+$countries['BR']['countrycode'] = '55';
+$countries['BR']['exitcode'] = '0014';
+$countries['BR']['isocode'] = 'BR';
+$countries['VG']['country'] = 'British Virgin Islands';
+$countries['VG']['countrycode'] = '1';
+$countries['VG']['exitcode'] = '011';
+$countries['VG']['isocode'] = 'VG';
+$countries['BN']['country'] = 'Brunei';
+$countries['BN']['countrycode'] = '673';
+$countries['BN']['exitcode'] = '00';
+$countries['BN']['isocode'] = 'BN';
+$countries['BG']['country'] = 'Bulgaria';
+$countries['BG']['countrycode'] = '359';
+$countries['BG']['exitcode'] = '00';
+$countries['BG']['isocode'] = 'BG';
+$countries['BF']['country'] = 'Burkina Faso';
+$countries['BF']['countrycode'] = '226';
+$countries['BF']['exitcode'] = '00';
+$countries['BF']['isocode'] = 'BF';
+$countries['BI']['country'] = 'Burundi';
+$countries['BI']['countrycode'] = '257';
+$countries['BI']['exitcode'] = '00';
+$countries['BI']['isocode'] = 'BI';
+$countries['KH']['country'] = 'Cambodia';
+$countries['KH']['countrycode'] = '855';
+$countries['KH']['exitcode'] = '001, 007, 008';
+$countries['KH']['isocode'] = 'KH';
+$countries['CM']['country'] = 'Cameroon';
+$countries['CM']['countrycode'] = '237';
+$countries['CM']['exitcode'] = '00';
+$countries['CM']['isocode'] = 'CM';
+$countries['CA']['country'] = 'Canada';
+$countries['CA']['countrycode'] = '1';
+$countries['CA']['exitcode'] = '011';
+$countries['CA']['isocode'] = 'CA';
+$countries['CV']['country'] = 'Cape Verde';
+$countries['CV']['countrycode'] = '238';
+$countries['CV']['exitcode'] = '00';
+$countries['CV']['isocode'] = 'CV';
+$countries['KY']['country'] = 'Cayman Islands';
+$countries['KY']['countrycode'] = '1';
+$countries['KY']['exitcode'] = '011';
+$countries['KY']['isocode'] = 'KY';
+$countries['CF']['country'] = 'Central African Republic';
+$countries['CF']['countrycode'] = '236';
+$countries['CF']['exitcode'] = '00';
+$countries['CF']['isocode'] = 'CF';
+$countries['TD']['country'] = 'Chad';
+$countries['TD']['countrycode'] = '235';
+$countries['TD']['exitcode'] = '00';
+$countries['TD']['isocode'] = 'TD';
+$countries['CL']['country'] = 'Chile';
+$countries['CL']['countrycode'] = '56';
+$countries['CL']['exitcode'] = '1230';
+$countries['CL']['isocode'] = 'CL';
+$countries['CN']['country'] = 'China';
+$countries['CN']['countrycode'] = '86';
+$countries['CN']['exitcode'] = '00';
+$countries['CN']['isocode'] = 'CN';
+$countries['CO']['country'] = 'Colombia';
+$countries['CO']['countrycode'] = '57';
+$countries['CO']['exitcode'] = '005';
+$countries['CO']['isocode'] = 'CO';
+$countries['KM']['country'] = 'Comoros';
+$countries['KM']['countrycode'] = '269';
+$countries['KM']['exitcode'] = '00';
+$countries['KM']['isocode'] = 'KM';
+$countries['CD']['country'] = 'Congo';
+$countries['CD']['countrycode'] = '242';
+$countries['CD']['exitcode'] = '00';
+$countries['CD']['isocode'] = 'CD';
+$countries['CK']['country'] = 'Cook Islands';
+$countries['CK']['countrycode'] = '682';
+$countries['CK']['exitcode'] = '00';
+$countries['CK']['isocode'] = 'CK';
+$countries['CR']['country'] = 'Costa Rica';
+$countries['CR']['countrycode'] = '506';
+$countries['CR']['exitcode'] = '00';
+$countries['CR']['isocode'] = 'CR';
+$countries['HR']['country'] = 'Croatia';
+$countries['HR']['countrycode'] = '385';
+$countries['HR']['exitcode'] = '00';
+$countries['HR']['isocode'] = 'HR';
+$countries['CU']['country'] = 'Cuba';
+$countries['CU']['countrycode'] = '53';
+$countries['CU']['exitcode'] = '119';
+$countries['CU']['isocode'] = 'CU';
+$countries['CY']['country'] = 'Cyprus';
+$countries['CY']['countrycode'] = '357';
+$countries['CY']['exitcode'] = '00';
+$countries['CY']['isocode'] = 'CY';
+$countries['CZ']['country'] = 'Czech Republic';
+$countries['CZ']['countrycode'] = '420';
+$countries['CZ']['exitcode'] = '00';
+$countries['CZ']['isocode'] = 'CZ';
+$countries['CD']['country'] = 'Democratic Republic of Congo';
+$countries['CD']['countrycode'] = '243';
+$countries['CD']['exitcode'] = '00';
+$countries['CD']['isocode'] = 'CD';
+$countries['DK']['country'] = 'Denmark';
+$countries['DK']['countrycode'] = '45';
+$countries['DK']['exitcode'] = '00';
+$countries['DK']['isocode'] = 'DK';
+$countries['DJ']['country'] = 'Djibouti';
+$countries['DJ']['countrycode'] = '253';
+$countries['DJ']['exitcode'] = '00';
+$countries['DJ']['isocode'] = 'DJ';
+$countries['DM']['country'] = 'Dominica';
+$countries['DM']['countrycode'] = '1';
+$countries['DM']['exitcode'] = '011';
+$countries['DM']['isocode'] = 'DM';
+$countries['DO']['country'] = 'Dominican Republic';
+$countries['DO']['countrycode'] = '1';
+$countries['DO']['exitcode'] = '011';
+$countries['DO']['isocode'] = 'DO';
+$countries['TL']['country'] = 'East Timor';
+$countries['TL']['countrycode'] = '670';
+$countries['TL']['exitcode'] = '00';
+$countries['TL']['isocode'] = 'TL';
+$countries['EC']['country'] = 'Ecuador';
+$countries['EC']['countrycode'] = '593';
+$countries['EC']['exitcode'] = '00';
+$countries['EC']['isocode'] = 'EC';
+$countries['EG']['country'] = 'Egypt';
+$countries['EG']['countrycode'] = '20';
+$countries['EG']['exitcode'] = '00';
+$countries['EG']['isocode'] = 'EG';
+$countries['SV']['country'] = 'El Salvador';
+$countries['SV']['countrycode'] = '503';
+$countries['SV']['exitcode'] = '00';
+$countries['SV']['isocode'] = 'SV';
+$countries['GQ']['country'] = 'Equatorial Guinea';
+$countries['GQ']['countrycode'] = '240';
+$countries['GQ']['exitcode'] = '00';
+$countries['GQ']['isocode'] = 'GQ';
+$countries['ER']['country'] = 'Eritrea';
+$countries['ER']['countrycode'] = '291';
+$countries['ER']['exitcode'] = '00';
+$countries['ER']['isocode'] = 'ER';
+$countries['EE']['country'] = 'Estonia';
+$countries['EE']['countrycode'] = '372';
+$countries['EE']['exitcode'] = '00';
+$countries['EE']['isocode'] = 'EE';
+$countries['ET']['country'] = 'Ethiopia';
+$countries['ET']['countrycode'] = '251';
+$countries['ET']['exitcode'] = '00';
+$countries['ET']['isocode'] = 'ET';
+$countries['FK']['country'] = 'Falkland (Malvinas) Islands';
+$countries['FK']['countrycode'] = '500';
+$countries['FK']['exitcode'] = '00';
+$countries['FK']['isocode'] = 'FK';
+$countries['FO']['country'] = 'Faroe Islands';
+$countries['FO']['countrycode'] = '298';
+$countries['FO']['exitcode'] = '00';
+$countries['FO']['isocode'] = 'FO';
+$countries['FJ']['country'] = 'Fiji';
+$countries['FJ']['countrycode'] = '679';
+$countries['FJ']['exitcode'] = '00';
+$countries['FJ']['isocode'] = 'FJ';
+$countries['FI']['country'] = 'Finland';
+$countries['FI']['countrycode'] = '358';
+$countries['FI']['exitcode'] = '00, 990, 994, 999';
+$countries['FI']['isocode'] = 'FI';
+$countries['FR']['country'] = 'France';
+$countries['FR']['countrycode'] = '33';
+$countries['FR']['exitcode'] = '00';
+$countries['FR']['isocode'] = 'FR';
+$countries['GF']['country'] = 'French Guiana';
+$countries['GF']['countrycode'] = '594';
+$countries['GF']['exitcode'] = '00';
+$countries['GF']['isocode'] = 'GF';
+$countries['PF']['country'] = 'French Polynesia';
+$countries['PF']['countrycode'] = '689';
+$countries['PF']['exitcode'] = '00';
+$countries['PF']['isocode'] = 'PF';
+$countries['GA']['country'] = 'Gabon';
+$countries['GA']['countrycode'] = '241';
+$countries['GA']['exitcode'] = '00';
+$countries['GA']['isocode'] = 'GA';
+$countries['GM']['country'] = 'Gambia';
+$countries['GM']['countrycode'] = '220';
+$countries['GM']['exitcode'] = '00';
+$countries['GM']['isocode'] = 'GM';
+$countries['GE']['country'] = 'Georgia';
+$countries['GE']['countrycode'] = '995';
+$countries['GE']['exitcode'] = '00';
+$countries['GE']['isocode'] = 'GE';
+$countries['DE']['country'] = 'Germany';
+$countries['DE']['countrycode'] = '49';
+$countries['DE']['exitcode'] = '00';
+$countries['DE']['isocode'] = 'DE';
+$countries['GH']['country'] = 'Ghana';
+$countries['GH']['countrycode'] = '233';
+$countries['GH']['exitcode'] = '00';
+$countries['GH']['isocode'] = 'GH';
+$countries['GI']['country'] = 'Gibraltar';
+$countries['GI']['countrycode'] = '350';
+$countries['GI']['exitcode'] = '00';
+$countries['GI']['isocode'] = 'GI';
+$countries['GR']['country'] = 'Greece';
+$countries['GR']['countrycode'] = '30';
+$countries['GR']['exitcode'] = '00';
+$countries['GR']['isocode'] = 'GR';
+$countries['GL']['country'] = 'Greenland';
+$countries['GL']['countrycode'] = '299';
+$countries['GL']['exitcode'] = '00';
+$countries['GL']['isocode'] = 'GL';
+$countries['GD']['country'] = 'Grenada';
+$countries['GD']['countrycode'] = '1';
+$countries['GD']['exitcode'] = '011';
+$countries['GD']['isocode'] = 'GD';
+$countries['GP']['country'] = 'Guadeloupe';
+$countries['GP']['countrycode'] = '590';
+$countries['GP']['exitcode'] = '00';
+$countries['GP']['isocode'] = 'GP';
+$countries['GU']['country'] = 'Guam';
+$countries['GU']['countrycode'] = '1';
+$countries['GU']['exitcode'] = '011';
+$countries['GU']['isocode'] = 'GU';
+$countries['GT']['country'] = 'Guatemala';
+$countries['GT']['countrycode'] = '502';
+$countries['GT']['exitcode'] = '00';
+$countries['GT']['isocode'] = 'GT';
+$countries['GN']['country'] = 'Guinea';
+$countries['GN']['countrycode'] = '224';
+$countries['GN']['exitcode'] = '00';
+$countries['GN']['isocode'] = 'GN';
+$countries['GW']['country'] = 'Guinea-Bissau';
+$countries['GW']['countrycode'] = '245';
+$countries['GW']['exitcode'] = '00';
+$countries['GW']['isocode'] = 'GW';
+$countries['GY']['country'] = 'Guyana';
+$countries['GY']['countrycode'] = '592';
+$countries['GY']['exitcode'] = '001';
+$countries['GY']['isocode'] = 'GY';
+$countries['HT']['country'] = 'Haiti';
+$countries['HT']['countrycode'] = '509';
+$countries['HT']['exitcode'] = '00';
+$countries['HT']['isocode'] = 'HT';
+$countries['HN']['country'] = 'Honduras';
+$countries['HN']['countrycode'] = '504';
+$countries['HN']['exitcode'] = '00';
+$countries['HN']['isocode'] = 'HN';
+$countries['HK']['country'] = 'Hong Kong';
+$countries['HK']['countrycode'] = '852';
+$countries['HK']['exitcode'] = '001';
+$countries['HK']['isocode'] = 'HK';
+$countries['HU']['country'] = 'Hungary';
+$countries['HU']['countrycode'] = '36';
+$countries['HU']['exitcode'] = '00';
+$countries['HU']['isocode'] = 'HU';
+$countries['IS']['country'] = 'Iceland';
+$countries['IS']['countrycode'] = '354';
+$countries['IS']['exitcode'] = '00';
+$countries['IS']['isocode'] = 'IS';
+$countries['IN']['country'] = 'India';
+$countries['IN']['countrycode'] = '91';
+$countries['IN']['exitcode'] = '00';
+$countries['IN']['isocode'] = 'IN';
+$countries['ID']['country'] = 'Indonesia';
+$countries['ID']['countrycode'] = '62';
+$countries['ID']['exitcode'] = '001';
+$countries['ID']['isocode'] = 'ID';
+$countries['IR']['country'] = 'Iran';
+$countries['IR']['countrycode'] = '98';
+$countries['IR']['exitcode'] = '00';
+$countries['IR']['isocode'] = 'IR';
+$countries['IQ']['country'] = 'Iraq';
+$countries['IQ']['countrycode'] = '964';
+$countries['IQ']['exitcode'] = '00';
+$countries['IQ']['isocode'] = 'IQ';
+$countries['IE']['country'] = 'Ireland';
+$countries['IE']['countrycode'] = '353';
+$countries['IE']['exitcode'] = '00';
+$countries['IE']['isocode'] = 'IE';
+$countries['IL']['country'] = 'Israel';
+$countries['IL']['countrycode'] = '972';
+$countries['IL']['exitcode'] = '00, 012, 013, 014, 018';
+$countries['IL']['isocode'] = 'IL';
+$countries['IT']['country'] = 'Italy';
+$countries['IT']['countrycode'] = '39';
+$countries['IT']['exitcode'] = '00';
+$countries['IT']['isocode'] = 'IT';
+$countries['CI']['country'] = 'Ivory Coast';
+$countries['CI']['countrycode'] = '225';
+$countries['CI']['exitcode'] = '00';
+$countries['CI']['isocode'] = 'CI';
+$countries['JM']['country'] = 'Jamaica';
+$countries['JM']['countrycode'] = '1';
+$countries['JM']['exitcode'] = '011';
+$countries['JM']['isocode'] = 'JM';
+$countries['JP']['country'] = 'Japan';
+$countries['JP']['countrycode'] = '81';
+$countries['JP']['exitcode'] = '010';
+$countries['JP']['isocode'] = 'JP';
+$countries['JO']['country'] = 'Jordan';
+$countries['JO']['countrycode'] = '962';
+$countries['JO']['exitcode'] = '00';
+$countries['JO']['isocode'] = 'JO';
+$countries['KZ']['country'] = 'Kazakhstan';
+$countries['KZ']['countrycode'] = '7';
+$countries['KZ']['exitcode'] = '810';
+$countries['KZ']['isocode'] = 'KZ';
+$countries['KE']['country'] = 'Kenya';
+$countries['KE']['countrycode'] = '254';
+$countries['KE']['exitcode'] = '000';
+$countries['KE']['isocode'] = 'KE';
+$countries['KI']['country'] = 'Kiribati';
+$countries['KI']['countrycode'] = '686';
+$countries['KI']['exitcode'] = '00';
+$countries['KI']['isocode'] = 'KI';
+$countries['KW']['country'] = 'Kuwait';
+$countries['KW']['countrycode'] = '965';
+$countries['KW']['exitcode'] = '00';
+$countries['KW']['isocode'] = 'KW';
+$countries['KG']['country'] = 'Kyrgyzstan';
+$countries['KG']['countrycode'] = '996';
+$countries['KG']['exitcode'] = '00';
+$countries['KG']['isocode'] = 'KG';
+$countries['LA']['country'] = 'Laos';
+$countries['LA']['countrycode'] = '856';
+$countries['LA']['exitcode'] = '00';
+$countries['LA']['isocode'] = 'LA';
+$countries['LV']['country'] = 'Latvia';
+$countries['LV']['countrycode'] = '371';
+$countries['LV']['exitcode'] = '00';
+$countries['LV']['isocode'] = 'LV';
+$countries['LB']['country'] = 'Lebanon';
+$countries['LB']['countrycode'] = '961';
+$countries['LB']['exitcode'] = '00';
+$countries['LB']['isocode'] = 'LB';
+$countries['LS']['country'] = 'Lesotho';
+$countries['LS']['countrycode'] = '266';
+$countries['LS']['exitcode'] = '00';
+$countries['LS']['isocode'] = 'LS';
+$countries['LR']['country'] = 'Liberia';
+$countries['LR']['countrycode'] = '231';
+$countries['LR']['exitcode'] = '00';
+$countries['LR']['isocode'] = 'LR';
+$countries['LY']['country'] = 'Libya';
+$countries['LY']['countrycode'] = '218';
+$countries['LY']['exitcode'] = '00';
+$countries['LY']['isocode'] = 'LY';
+$countries['LI']['country'] = 'Liechtenstein';
+$countries['LI']['countrycode'] = '423';
+$countries['LI']['exitcode'] = '00';
+$countries['LI']['isocode'] = 'LI';
+$countries['LT']['country'] = 'Lithuania';
+$countries['LT']['countrycode'] = '370';
+$countries['LT']['exitcode'] = '00';
+$countries['LT']['isocode'] = 'LT';
+$countries['LU']['country'] = 'Luxembourg';
+$countries['LU']['countrycode'] = '352';
+$countries['LU']['exitcode'] = '00';
+$countries['LU']['isocode'] = 'LU';
+$countries['MO']['country'] = 'Macau';
+$countries['MO']['countrycode'] = '853';
+$countries['MO']['exitcode'] = '00';
+$countries['MO']['isocode'] = 'MO';
+$countries['MK']['country'] = 'Macedonia';
+$countries['MK']['countrycode'] = '389';
+$countries['MK']['exitcode'] = '00';
+$countries['MK']['isocode'] = 'MK';
+$countries['MG']['country'] = 'Madagascar';
+$countries['MG']['countrycode'] = '261';
+$countries['MG']['exitcode'] = '00';
+$countries['MG']['isocode'] = 'MG';
+$countries['MW']['country'] = 'Malawi';
+$countries['MW']['countrycode'] = '265';
+$countries['MW']['exitcode'] = '00';
+$countries['MW']['isocode'] = 'MW';
+$countries['MY']['country'] = 'Malaysia';
+$countries['MY']['countrycode'] = '60';
+$countries['MY']['exitcode'] = '00';
+$countries['MY']['isocode'] = 'MY';
+$countries['MV']['country'] = 'Maldives';
+$countries['MV']['countrycode'] = '960';
+$countries['MV']['exitcode'] = '00';
+$countries['MV']['isocode'] = 'MV';
+$countries['ML']['country'] = 'Mali';
+$countries['ML']['countrycode'] = '223';
+$countries['ML']['exitcode'] = '00';
+$countries['ML']['isocode'] = 'ML';
+$countries['MT']['country'] = 'Malta';
+$countries['MT']['countrycode'] = '356';
+$countries['MT']['exitcode'] = '00';
+$countries['MT']['isocode'] = 'MT';
+$countries['MH']['country'] = 'Marshall Islands';
+$countries['MH']['countrycode'] = '692';
+$countries['MH']['exitcode'] = '011';
+$countries['MH']['isocode'] = 'MH';
+$countries['MQ']['country'] = 'Martinique';
+$countries['MQ']['countrycode'] = '596';
+$countries['MQ']['exitcode'] = '00';
+$countries['MQ']['isocode'] = 'MQ';
+$countries['MR']['country'] = 'Mauritania';
+$countries['MR']['countrycode'] = '222';
+$countries['MR']['exitcode'] = '00';
+$countries['MR']['isocode'] = 'MR';
+$countries['MU']['country'] = 'Mauritius';
+$countries['MU']['countrycode'] = '230';
+$countries['MU']['exitcode'] = '00';
+$countries['MU']['isocode'] = 'MU';
+$countries['YT']['country'] = 'Mayotte';
+$countries['YT']['countrycode'] = '262';
+$countries['YT']['exitcode'] = '00';
+$countries['YT']['isocode'] = 'YT';
+$countries['MX']['country'] = 'Mexico';
+$countries['MX']['countrycode'] = '52';
+$countries['MX']['exitcode'] = '00';
+$countries['MX']['isocode'] = 'MX';
+$countries['FM']['country'] = 'Micronesia';
+$countries['FM']['countrycode'] = '691';
+$countries['FM']['exitcode'] = '011';
+$countries['FM']['isocode'] = 'FM';
+$countries['MD']['country'] = 'Moldova';
+$countries['MD']['countrycode'] = '373';
+$countries['MD']['exitcode'] = '00';
+$countries['MD']['isocode'] = 'MD';
+$countries['MC']['country'] = 'Monaco';
+$countries['MC']['countrycode'] = '377';
+$countries['MC']['exitcode'] = '00';
+$countries['MC']['isocode'] = 'MC';
+$countries['MN']['country'] = 'Mongolia';
+$countries['MN']['countrycode'] = '976';
+$countries['MN']['exitcode'] = '001';
+$countries['MN']['isocode'] = 'MN';
+$countries['ME']['country'] = 'Montenegro';
+$countries['ME']['countrycode'] = '382';
+$countries['ME']['exitcode'] = '00';
+$countries['ME']['isocode'] = 'ME';
+$countries['MS']['country'] = 'Montserrat';
+$countries['MS']['countrycode'] = '1';
+$countries['MS']['exitcode'] = '011';
+$countries['MS']['isocode'] = 'MS';
+$countries['MA']['country'] = 'Morocco';
+$countries['MA']['countrycode'] = '212';
+$countries['MA']['exitcode'] = '00';
+$countries['MA']['isocode'] = 'MA';
+$countries['MZ']['country'] = 'Mozambique';
+$countries['MZ']['countrycode'] = '258';
+$countries['MZ']['exitcode'] = '00';
+$countries['MZ']['isocode'] = 'MZ';
+$countries['MM']['country'] = 'Myanmar';
+$countries['MM']['countrycode'] = '95';
+$countries['MM']['exitcode'] = '00';
+$countries['MM']['isocode'] = 'MM';
+$countries['NA']['country'] = 'Namibia';
+$countries['NA']['countrycode'] = '264';
+$countries['NA']['exitcode'] = '00';
+$countries['NA']['isocode'] = 'NA';
+$countries['NR']['country'] = 'Nauru';
+$countries['NR']['countrycode'] = '674';
+$countries['NR']['exitcode'] = '00';
+$countries['NR']['isocode'] = 'NR';
+$countries['NP']['country'] = 'Nepal';
+$countries['NP']['countrycode'] = '977';
+$countries['NP']['exitcode'] = '00';
+$countries['NP']['isocode'] = 'NP';
+$countries['NL']['country'] = 'Netherlands';
+$countries['NL']['countrycode'] = '31';
+$countries['NL']['exitcode'] = '00';
+$countries['NL']['isocode'] = 'NL';
+$countries['AN']['country'] = 'Netherlands Antilles';
+$countries['AN']['countrycode'] = '599';
+$countries['AN']['exitcode'] = '00';
+$countries['AN']['isocode'] = 'AN';
+$countries['NC']['country'] = 'New Caledonia';
+$countries['NC']['countrycode'] = '687';
+$countries['NC']['exitcode'] = '00';
+$countries['NC']['isocode'] = 'NC';
+$countries['NZ']['country'] = 'New Zealand';
+$countries['NZ']['countrycode'] = '64';
+$countries['NZ']['exitcode'] = '00';
+$countries['NZ']['isocode'] = 'NZ';
+$countries['NI']['country'] = 'Nicaragua';
+$countries['NI']['countrycode'] = '505';
+$countries['NI']['exitcode'] = '00';
+$countries['NI']['isocode'] = 'NI';
+$countries['NE']['country'] = 'Niger';
+$countries['NE']['countrycode'] = '227';
+$countries['NE']['exitcode'] = '00';
+$countries['NE']['isocode'] = 'NE';
+$countries['NG']['country'] = 'Nigeria';
+$countries['NG']['countrycode'] = '234';
+$countries['NG']['exitcode'] = '009';
+$countries['NG']['isocode'] = 'NG';
+$countries['NU']['country'] = 'Niue';
+$countries['NU']['countrycode'] = '683';
+$countries['NU']['exitcode'] = '00';
+$countries['NU']['isocode'] = 'NU';
+$countries['NF']['country'] = 'Norfolk Island';
+$countries['NF']['countrycode'] = '6723';
+$countries['NF']['exitcode'] = '00';
+$countries['NF']['isocode'] = 'NF';
+$countries['KP']['country'] = 'North Korea';
+$countries['KP']['countrycode'] = '850';
+$countries['KP']['exitcode'] = '99';
+$countries['KP']['isocode'] = 'KP';
+$countries['NO']['country'] = 'Norway';
+$countries['NO']['countrycode'] = '47';
+$countries['NO']['exitcode'] = '00';
+$countries['NO']['isocode'] = 'NO';
+$countries['OM']['country'] = 'Oman';
+$countries['OM']['countrycode'] = '968';
+$countries['OM']['exitcode'] = '00';
+$countries['OM']['isocode'] = 'OM';
+$countries['PK']['country'] = 'Pakistan';
+$countries['PK']['countrycode'] = '92';
+$countries['PK']['exitcode'] = '00';
+$countries['PK']['isocode'] = 'PK';
+$countries['PW']['country'] = 'Palau';
+$countries['PW']['countrycode'] = '680';
+$countries['PW']['exitcode'] = '011';
+$countries['PW']['isocode'] = 'PW';
+$countries['PA']['country'] = 'Panama';
+$countries['PA']['countrycode'] = '507';
+$countries['PA']['exitcode'] = '00';
+$countries['PA']['isocode'] = 'PA';
+$countries['PG']['country'] = 'Papua New Guinea';
+$countries['PG']['countrycode'] = '675';
+$countries['PG']['exitcode'] = '00';
+$countries['PG']['isocode'] = 'PG';
+$countries['PY']['country'] = 'Paraguay';
+$countries['PY']['countrycode'] = '595';
+$countries['PY']['exitcode'] = '00';
+$countries['PY']['isocode'] = 'PY';
+$countries['PE']['country'] = 'Peru';
+$countries['PE']['countrycode'] = '51';
+$countries['PE']['exitcode'] = '00';
+$countries['PE']['isocode'] = 'PE';
+$countries['PH']['country'] = 'Philippines';
+$countries['PH']['countrycode'] = '63';
+$countries['PH']['exitcode'] = '00';
+$countries['PH']['isocode'] = 'PH';
+$countries['PL']['country'] = 'Poland';
+$countries['PL']['countrycode'] = '48';
+$countries['PL']['exitcode'] = '00';
+$countries['PL']['isocode'] = 'PL';
+$countries['PT']['country'] = 'Portugal';
+$countries['PT']['countrycode'] = '351';
+$countries['PT']['exitcode'] = '00';
+$countries['PT']['isocode'] = 'PT';
+$countries['PR']['country'] = 'Puerto Rico';
+$countries['PR']['countrycode'] = '1';
+$countries['PR']['exitcode'] = '011';
+$countries['PR']['isocode'] = 'PR';
+$countries['QA']['country'] = 'Qatar';
+$countries['QA']['countrycode'] = '974';
+$countries['QA']['exitcode'] = '00';
+$countries['QA']['isocode'] = 'QA';
+$countries['RE']['country'] = 'Reunion';
+$countries['RE']['countrycode'] = '262';
+$countries['RE']['exitcode'] = '00';
+$countries['RE']['isocode'] = 'RE';
+$countries['RO']['country'] = 'Romania';
+$countries['RO']['countrycode'] = '40';
+$countries['RO']['exitcode'] = '00';
+$countries['RO']['isocode'] = 'RO';
+$countries['RU']['country'] = 'Russian Federation';
+$countries['RU']['countrycode'] = '7';
+$countries['RU']['exitcode'] = '810';
+$countries['RU']['isocode'] = 'RU';
+$countries['RW']['country'] = 'Rwanda';
+$countries['RW']['countrycode'] = '250';
+$countries['RW']['exitcode'] = '00';
+$countries['RW']['isocode'] = 'RW';
+$countries['SH']['country'] = 'Saint Helena';
+$countries['SH']['countrycode'] = '290';
+$countries['SH']['exitcode'] = '00';
+$countries['SH']['isocode'] = 'SH';
+$countries['KN']['country'] = 'Saint Kitts and Nevis';
+$countries['KN']['countrycode'] = '1';
+$countries['KN']['exitcode'] = '011';
+$countries['KN']['isocode'] = 'KN';
+$countries['LC']['country'] = 'Saint Lucia';
+$countries['LC']['countrycode'] = '1';
+$countries['LC']['exitcode'] = '011';
+$countries['LC']['isocode'] = 'LC';
+$countries['GP']['country'] = 'Saint Barthelemy';
+$countries['GP']['countrycode'] = '590';
+$countries['GP']['exitcode'] = '00';
+$countries['GP']['isocode'] = 'GP';
+$countries['PM']['country'] = 'Saint Pierre and Miquelon';
+$countries['PM']['countrycode'] = '508';
+$countries['PM']['exitcode'] = '00';
+$countries['PM']['isocode'] = 'PM';
+$countries['VC']['country'] = 'Saint Vincent and the Grenadines';
+$countries['VC']['countrycode'] = '1';
+$countries['VC']['exitcode'] = '011';
+$countries['VC']['isocode'] = 'VC';
+$countries['WS']['country'] = 'Samoa';
+$countries['WS']['countrycode'] = '685';
+$countries['WS']['exitcode'] = '0';
+$countries['WS']['isocode'] = 'WS';
+$countries['SM']['country'] = 'San Marino';
+$countries['SM']['countrycode'] = '378';
+$countries['SM']['exitcode'] = '00';
+$countries['SM']['isocode'] = 'SM';
+$countries['ST']['country'] = 'Sao Tome and Principe';
+$countries['ST']['countrycode'] = '239';
+$countries['ST']['exitcode'] = '00';
+$countries['ST']['isocode'] = 'ST';
+$countries['SA']['country'] = 'Saudi Arabia';
+$countries['SA']['countrycode'] = '966';
+$countries['SA']['exitcode'] = '00';
+$countries['SA']['isocode'] = 'SA';
+$countries['SN']['country'] = 'Senegal';
+$countries['SN']['countrycode'] = '221';
+$countries['SN']['exitcode'] = '00';
+$countries['SN']['isocode'] = 'SN';
+$countries['RS']['country'] = 'Serbia';
+$countries['RS']['countrycode'] = '381';
+$countries['RS']['exitcode'] = '00';
+$countries['RS']['isocode'] = 'RS';
+$countries['SC']['country'] = 'Seychelles';
+$countries['SC']['countrycode'] = '248';
+$countries['SC']['exitcode'] = '00';
+$countries['SC']['isocode'] = 'SC';
+$countries['SL']['country'] = 'Sierra Leone';
+$countries['SL']['countrycode'] = '232';
+$countries['SL']['exitcode'] = '00';
+$countries['SL']['isocode'] = 'SL';
+$countries['SG']['country'] = 'Singapore';
+$countries['SG']['countrycode'] = '65';
+$countries['SG']['exitcode'] = '001, 008';
+$countries['SG']['isocode'] = 'SG';
+$countries['SK']['country'] = 'Slovakia';
+$countries['SK']['countrycode'] = '421';
+$countries['SK']['exitcode'] = '00';
+$countries['SK']['isocode'] = 'SK';
+$countries['SI']['country'] = 'Slovenia';
+$countries['SI']['countrycode'] = '386';
+$countries['SI']['exitcode'] = '00';
+$countries['SI']['isocode'] = 'SI';
+$countries['SB']['country'] = 'Solomon Islands';
+$countries['SB']['countrycode'] = '677';
+$countries['SB']['exitcode'] = '00';
+$countries['SB']['isocode'] = 'SB';
+$countries['SO']['country'] = 'Somalia';
+$countries['SO']['countrycode'] = '252';
+$countries['SO']['exitcode'] = '00';
+$countries['SO']['isocode'] = 'SO';
+$countries['ZA']['country'] = 'South Africa';
+$countries['ZA']['countrycode'] = '27';
+$countries['ZA']['exitcode'] = '00';
+$countries['ZA']['isocode'] = 'ZA';
+$countries['KR']['country'] = 'South Korea';
+$countries['KR']['countrycode'] = '82';
+$countries['KR']['exitcode'] = '001, 002';
+$countries['KR']['isocode'] = 'KR';
+$countries['ES']['country'] = 'Spain';
+$countries['ES']['countrycode'] = '34';
+$countries['ES']['exitcode'] = '00';
+$countries['ES']['isocode'] = 'ES';
+$countries['LK']['country'] = 'Sri Lanka';
+$countries['LK']['countrycode'] = '94';
+$countries['LK']['exitcode'] = '00';
+$countries['LK']['isocode'] = 'LK';
+$countries['SD']['country'] = 'Sudan';
+$countries['SD']['countrycode'] = '249';
+$countries['SD']['exitcode'] = '00';
+$countries['SD']['isocode'] = 'SD';
+$countries['SR']['country'] = 'Suriname';
+$countries['SR']['countrycode'] = '597';
+$countries['SR']['exitcode'] = '00';
+$countries['SR']['isocode'] = 'SR';
+$countries['SZ']['country'] = 'Swaziland';
+$countries['SZ']['countrycode'] = '268';
+$countries['SZ']['exitcode'] = '00';
+$countries['SZ']['isocode'] = 'SZ';
+$countries['SE']['country'] = 'Sweden';
+$countries['SE']['countrycode'] = '46';
+$countries['SE']['exitcode'] = '00';
+$countries['SE']['isocode'] = 'SE';
+$countries['CH']['country'] = 'Switzerland';
+$countries['CH']['countrycode'] = '41';
+$countries['CH']['exitcode'] = '00';
+$countries['CH']['isocode'] = 'CH';
+$countries['SY']['country'] = 'Syria';
+$countries['SY']['countrycode'] = '963';
+$countries['SY']['exitcode'] = '00';
+$countries['SY']['isocode'] = 'SY';
+$countries['TW']['country'] = 'Taiwan';
+$countries['TW']['countrycode'] = '886';
+$countries['TW']['exitcode'] = '002';
+$countries['TW']['isocode'] = 'TW';
+$countries['TJ']['country'] = 'Tajikistan';
+$countries['TJ']['countrycode'] = '992';
+$countries['TJ']['exitcode'] = '810';
+$countries['TJ']['isocode'] = 'TJ';
+$countries['TZ']['country'] = 'Tanzania';
+$countries['TZ']['countrycode'] = '255';
+$countries['TZ']['exitcode'] = '000';
+$countries['TZ']['isocode'] = 'TZ';
+$countries['TH']['country'] = 'Thailand';
+$countries['TH']['countrycode'] = '66';
+$countries['TH']['exitcode'] = '001';
+$countries['TH']['isocode'] = 'TH';
+$countries['TG']['country'] = 'Togo';
+$countries['TG']['countrycode'] = '228';
+$countries['TG']['exitcode'] = '00';
+$countries['TG']['isocode'] = 'TG';
+$countries['TK']['country'] = 'Tokelau';
+$countries['TK']['countrycode'] = '690';
+$countries['TK']['exitcode'] = '00';
+$countries['TK']['isocode'] = 'TK';
+$countries['TO']['country'] = 'Tonga';
+$countries['TO']['countrycode'] = '676';
+$countries['TO']['exitcode'] = '00';
+$countries['TO']['isocode'] = 'TO';
+$countries['TT']['country'] = 'Trinidad and Tobago';
+$countries['TT']['countrycode'] = '1';
+$countries['TT']['exitcode'] = '011';
+$countries['TT']['isocode'] = 'TT';
+$countries['TN']['country'] = 'Tunisia';
+$countries['TN']['countrycode'] = '216';
+$countries['TN']['exitcode'] = '00';
+$countries['TN']['isocode'] = 'TN';
+$countries['TR']['country'] = 'Turkey';
+$countries['TR']['countrycode'] = '90';
+$countries['TR']['exitcode'] = '00';
+$countries['TR']['isocode'] = 'TR';
+$countries['TM']['country'] = 'Turkmenistan';
+$countries['TM']['countrycode'] = '993';
+$countries['TM']['exitcode'] = '810';
+$countries['TM']['isocode'] = 'TM';
+$countries['TC']['country'] = 'Turks and Caicos Islands';
+$countries['TC']['countrycode'] = '1';
+$countries['TC']['exitcode'] = '0';
+$countries['TC']['isocode'] = 'TC';
+$countries['TV']['country'] = 'Tuvalu';
+$countries['TV']['countrycode'] = '688';
+$countries['TV']['exitcode'] = '00';
+$countries['TV']['isocode'] = 'TV';
+$countries['UG']['country'] = 'Uganda';
+$countries['UG']['countrycode'] = '256';
+$countries['UG']['exitcode'] = '000';
+$countries['UG']['isocode'] = 'UG';
+$countries['UA']['country'] = 'Ukraine';
+$countries['UA']['countrycode'] = '380';
+$countries['UA']['exitcode'] = '00';
+$countries['UA']['isocode'] = 'UA';
+$countries['AE']['country'] = 'United Arab Emirates';
+$countries['AE']['countrycode'] = '971';
+$countries['AE']['exitcode'] = '00';
+$countries['AE']['isocode'] = 'AE';
+$countries['GB']['country'] = 'United Kingdom';
+$countries['GB']['countrycode'] = '44';
+$countries['GB']['exitcode'] = '00';
+$countries['GB']['isocode'] = 'GB';
+$countries['US']['country'] = 'United States';
+$countries['US']['countrycode'] = '1';
+$countries['US']['exitcode'] = '011';
+$countries['US']['isocode'] = 'US';
+$countries['VI']['country'] = 'U.S. Virgin Islands';
+$countries['VI']['countrycode'] = '1';
+$countries['VI']['exitcode'] = '011';
+$countries['VI']['isocode'] = 'VI';
+$countries['UY']['country'] = 'Uruguay';
+$countries['UY']['countrycode'] = '598';
+$countries['UY']['exitcode'] = '00';
+$countries['UY']['isocode'] = 'UY';
+$countries['UZ']['country'] = 'Uzbekistan';
+$countries['UZ']['countrycode'] = '998';
+$countries['UZ']['exitcode'] = '8 - wait for dial tone - 10';
+$countries['UZ']['isocode'] = 'UZ';
+$countries['VU']['country'] = 'Vanuatu';
+$countries['VU']['countrycode'] = '678';
+$countries['VU']['exitcode'] = '00';
+$countries['VU']['isocode'] = 'VU';
+$countries['VA']['country'] = 'Vatican City';
+$countries['VA']['countrycode'] = '379, 39';
+$countries['VA']['exitcode'] = '00';
+$countries['VA']['isocode'] = 'VA';
+$countries['VE']['country'] = 'Venezuela';
+$countries['VE']['countrycode'] = '58';
+$countries['VE']['exitcode'] = '00';
+$countries['VE']['isocode'] = 'VE';
+$countries['VN']['country'] = 'Vietnam';
+$countries['VN']['countrycode'] = '84';
+$countries['VN']['exitcode'] = '00';
+$countries['VN']['isocode'] = 'VN';
+$countries['WF']['country'] = 'Wallis and Futuna';
+$countries['WF']['countrycode'] = '681';
+$countries['WF']['exitcode'] = '00';
+$countries['WF']['isocode'] = 'WF';
+$countries['YE']['country'] = 'Yemen';
+$countries['YE']['countrycode'] = '967';
+$countries['YE']['exitcode'] = '00';
+$countries['YE']['isocode'] = 'YE';
+$countries['ZM']['country'] = 'Zambia';
+$countries['ZM']['countrycode'] = '260';
+$countries['ZM']['exitcode'] = '00';
+$countries['ZM']['isocode'] = 'ZM';
+$countries['ZW']['country'] = 'Zimbabwe';
+$countries['ZW']['countrycode'] = '263';
+$countries['ZW']['exitcode'] = '00';
+$countries['ZW']['isocode'] = 'ZW';
+
+?>

+ 13 - 0
resources/functions.php

@@ -600,6 +600,19 @@
 	}
 	//echo realpath(sys_get_temp_dir());
 
+	if ( !function_exists('normalize_path')) {
+		//don't use DIRECTORY_SEPARATOR as it will change on a per platform basis and we need consistency
+		function normalize_path($path) {
+			return str_replace(array('/','\\'), '/', $path);
+		}
+	}
+	
+	if ( !function_exists('normalize_path_to_os')) {
+		function normalize_path_to_os($path) {
+			return str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $path);
+		}
+	}
+
 	if (!function_exists('username_exists')) {
 		function username_exists($username) {
 			global $db, $domain_uuid;

+ 0 - 2113
resources/install.php

@@ -1,2113 +0,0 @@
-<?php
-/*
-	FusionPBX
-	Version: MPL 1.1
-
-	The contents of this file are subject to the Mozilla Public License Version
-	1.1 (the "License"); you may not use this file except in compliance with
-	the License. You may obtain a copy of the License at
-	http://www.mozilla.org/MPL/
-
-	Software distributed under the License is distributed on an "AS IS" basis,
-	WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-	for the specific language governing rights and limitations under the
-	License.
-
-	The Original Code is FusionPBX
-
-	The Initial Developer of the Original Code is
-	Mark J Crane <[email protected]>
-	Portions created by the Initial Developer are Copyright (C) 2008-2014
-	the Initial Developer. All Rights Reserved.
-
-	Contributor(s):
-	Mark J Crane <[email protected]>
-*/
-include "root.php";
-require_once "resources/functions.php";
-
-//include required classes
-	require_once "resources/classes/text.php";
-
-//set debug to true or false
-	$v_debug = true;
-
-//set the default domain_uuid
-	$_SESSION["domain_uuid"] = uuid();
-
-//add the menu uuid
-	$menu_uuid = 'b4750c3f-2a86-b00d-b7d0-345c14eca286';
-
-//error reporting
-	ini_set('display_errors', '1');
-	//error_reporting (E_ALL); // Report everything
-	error_reporting (E_ALL ^ E_NOTICE); // Report everything
-	//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings
-
-//set the default time zone
-	date_default_timezone_set('UTC');
-
-//if the config file exists then disable the install page
-	$config_exists = false;
-	if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources/config.php")) {
-		$config_exists = true;
-	} elseif (file_exists("/etc/fusionpbx/config.php")) {
-		//linux
-		$config_exists = true;
-	} elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
-		$config_exists = true;
-	}
-	if ($config_exists) {
-		$msg .= "Already Installed";
-		header("Location: ".PROJECT_PATH."/index.php?msg=".urlencode($msg));
-		exit;
-	}
-
-//set the max execution time to 1 hour
-	ini_set('max_execution_time',3600);
-
-//save an install log if debug is true
-	if ($v_debug) {
-		$fp = fopen(sys_get_temp_dir()."/install.log", "w");
-	}
-
-//set php variables with data from http post
-	$db_type = $_POST["db_type"];
-	$admin_username = $_POST["admin_username"];
-	$admin_password = $_POST["admin_password"];
-	$db_name = $_POST["db_name"];
-	$db_host = $_POST["db_host"];
-	$db_port = $_POST["db_port"];
-	$db_name = $_POST["db_name"];
-	$domain_name = $_POST["domain_name"];
-	$db_username = $_POST["db_username"];
-	$db_password = $_POST["db_password"];
-	$db_create_username = $_POST["db_create_username"];
-	$db_create_password = $_POST["db_create_password"];
-	$db_path = $_POST["db_path"];
-	$install_step = $_POST["install_step"];
-	$install_tmp_dir = $_POST["install_tmp_dir"];
-	$install_backup_dir = $_POST["install_backup_dir"];
-	$install_switch_base_dir = $_POST["install_switch_base_dir"];
-	$install_default_country = $_POST["install_default_country"];
-	$install_template_name = $_POST["install_template_name"];
-
-	if(!$domain_name){
-	//get the domain
-		$domain_array = explode(":", $_SERVER["HTTP_HOST"]);
-		$domain_name = $domain_array[0];
-	}
-
-//clean up the values
-	if (strlen($install_switch_base_dir) > 0) {
-		$install_switch_base_dir = realpath($install_switch_base_dir);
-		$install_switch_base_dir = str_replace("\\", "/", $install_switch_base_dir);
-	}
-
-	$install_tmp_dir = realpath($_POST["install_tmp_dir"]);
-	$install_tmp_dir = str_replace("\\", "/", $install_tmp_dir);
-
-	$install_backup_dir = realpath($_POST["install_backup_dir"]);
-	$install_backup_dir = str_replace("\\", "/", $install_backup_dir);
-
-//set the default db_name
-	if ($db_type == "sqlite") {
-		if (strlen($db_name) == 0) { $db_name = "fusionpbx.db"; }
-	}
-
-//set the required directories
-
-	//set the freeswitch bin directory
-		if (file_exists('/usr/local/freeswitch/bin')) {
-			$install_switch_base_dir = '/usr/local/freeswitch';
-			$switch_bin_dir = '/usr/local/freeswitch/bin';
-		}
-		if (file_exists('/opt/freeswitch')) {
-			$install_switch_base_dir = '/opt/freeswitch';
-			$switch_bin_dir = '/opt/freeswitch/bin';
-		}
-
-	//set the default startup script directory
-		if (file_exists('/usr/local/etc/rc.d')) {
-			$startup_script_dir = '/usr/local/etc/rc.d';
-		}
-		if (file_exists('/etc/init.d')) {
-			$startup_script_dir = '/etc/init.d';
-		}
-
-	//set the default directories
-		$switch_bin_dir = $install_switch_base_dir.'/bin'; //freeswitch bin directory
-		$switch_conf_dir = $install_switch_base_dir.'/conf';
-		$switch_db_dir = $install_switch_base_dir.'/db';
-		$switch_log_dir = $install_switch_base_dir.'/log';
-		$switch_mod_dir = $install_switch_base_dir.'/mod';
-		$switch_extensions_dir = $switch_conf_dir.'/directory';
-		$switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles';
-		$switch_dialplan_dir = $switch_conf_dir.'/dialplan';
-		$switch_scripts_dir = $install_switch_base_dir.'/scripts';
-		$switch_grammar_dir = $install_switch_base_dir.'/grammar';
-		$switch_storage_dir = $install_switch_base_dir.'/storage';
-		$switch_voicemail_dir = $install_switch_base_dir.'/storage/voicemail';
-		$switch_recordings_dir = $install_switch_base_dir.'/recordings';
-		$switch_sounds_dir = $install_switch_base_dir.'/sounds';
-		$install_tmp_dir = realpath(sys_get_temp_dir());
-		$install_backup_dir = realpath(sys_get_temp_dir());
-		$v_download_path = '';
-
-	//set specific alternative directories as required
-		switch (PHP_OS) {
-		case "Linux":
-			//set the default db_path
-				if (strlen($db_path) == 0) {
-					if (file_exists('/var/lib/fusionpbx/db')) {
-						$db_path = '/var/lib/fusionpbx/db';
-					}
-				}
-			//set the other default directories
-				if (file_exists('/usr/bin')) {
-					$switch_bin_dir = '/usr/bin'; //freeswitch bin directory
-				}
-				 //new
-				if (file_exists('/etc/fusionpbx/switch/conf')) {
-					$switch_conf_dir = '/etc/fusionpbx/switch/conf';
-					$switch_extensions_dir = $switch_conf_dir.'/directory';
-					$switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles';
-					$switch_dialplan_dir = $switch_conf_dir.'/dialplan';
-				}
-				//old
-				//if (file_exists('/etc/freeswitch/vars.xml')) {
-				//	$switch_conf_dir = '/etc/freeswitch';
-				//	$switch_extensions_dir = $switch_conf_dir.'/directory';
-				//	$switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles';
-				//	$switch_dialplan_dir = $switch_conf_dir.'/dialplan';
-				//}
-				if (file_exists('/var/lib/freeswitch/db')) {
-					$switch_db_dir = '/var/lib/freeswitch/db';
-				}
-				if (file_exists('/var/log/freeswitch')) {
-					$switch_log_dir = '/var/log/freeswitch';
-				}
-				if (file_exists('/usr/lib/freeswitch/mod')) {
-					$switch_mod_dir = '/usr/lib/freeswitch/mod';
-				}
-				//new
-				if (file_exists('/var/lib/fusionpbx/scripts')) {
-					$switch_scripts_dir = '/var/lib/fusionpbx/scripts';
-				}
-				//old
-				//if (file_exists('/usr/share/freeswitch/scripts')) {
-				//	$switch_scripts_dir = '/usr/share/freeswitch/scripts';
-				//}
-				//new
-				if (file_exists('/usr/share/freeswitch/grammar')) {
-					$switch_grammar_dir = '/usr/share/freeswitch/grammar';
-				}
-				//old
-				//if (file_exists('/usr/share/freeswitch/grammar')) {
-				//	$switch_grammar_dir = '/usr/share/freeswitch/grammar';
-				//}
-				//new
-				if (file_exists('/var/lib/fusionpbx/storage')) {
-					$switch_storage_dir = '/var/lib/fusionpbx/storage';
-					$switch_voicemail_dir = $switch_storage_dir.'/voicemail';
-				}
-				//old
-				//if (file_exists('/var/lib/freeswitch/storage')) {
-				//	$switch_storage_dir = '/var/lib/freeswitch/storage';
-				//	$switch_voicemail_dir = $switch_storage_dir.'/voicemail';
-				//}
-				//new
-				if (file_exists('/var/lib/fusionpbx/recordings')) {
-					$switch_recordings_dir = '/var/lib/fusionpbx/recordings';
-				}
-				//old
-				//if (file_exists('/var/lib/freeswitch/recordings')) {
-				//	$switch_recordings_dir = '/var/lib/freeswitch/recordings';
-				//}
-				if (file_exists('/usr/share/freeswitch/sounds')) {
-					$switch_sounds_dir = '/usr/share/freeswitch/sounds';
-				}
-			break;
-		case "FreeBSD":
-			//if the FreeBSD port is installed use the following paths by default.
-				if (file_exists('/var/db/freeswitch')) {
-					//FreeBSD port
-						//set the default db_path
-							if (strlen($db_path) == 0) {
-								$db_path = '/var/db/fusionpbx';
-								if (!is_readable($db_path)) { mkdir($db_path,0774,true); }
-							}
-						//set the other default directories
-							$switch_bin_dir = '/usr/local/bin'; //freeswitch bin directory
-							$switch_conf_dir = '/usr/local/etc/freeswitch';
-							$switch_db_dir = '/var/db/freeswitch';
-							$switch_log_dir = '/var/log/freeswitch';
-							$switch_mod_dir = '/usr/local/lib/freeswitch/mod';
-							$switch_extensions_dir = $switch_conf_dir.'/directory';
-							$switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles';
-							$switch_dialplan_dir = $switch_conf_dir.'/dialplan';
-							$switch_scripts_dir = '/var/cache/freeswitch/scripts';
-							$switch_grammar_dir = '/usr/local/share/freeswitch/grammar';
-							$switch_storage_dir = '/var/cache/freeswitch/storage';
-							$switch_recordings_dir = '/var/cache/freeswitch/recordings';
-							$switch_sounds_dir = '/usr/local/share/freeswitch/sounds';
-				}
-				elseif (file_exists('/data/freeswitch')) {
-					//FreeBSD embedded
-						//set the default db_path
-							if (strlen($db_path) == 0) {
-								$db_path = '/data/db/fusionpbx';
-								if (!is_readable($db_path)) { mkdir($db_path,0777,true); }
-							}
-						//set the other default directories
-							$switch_bin_dir = '/usr/local/bin'; //freeswitch bin directory
-							$switch_conf_dir = '/usr/local/etc/freeswitch/conf';
-							$switch_db_dir = '/data/freeswitch/db';
-							if (is_readable('/var/log/freeswitch')) {
-								$switch_log_dir = '/var/log/freeswitch';
-							}
-							else {
-								$switch_log_dir = '/data/freeswitch/log';
-							}
-							$switch_mod_dir = '/usr/local/lib/freeswitch/mod';
-							$switch_extensions_dir = $switch_conf_dir.'/directory';
-							$switch_sip_profiles_dir = $switch_conf_dir.'/sip_profiles';
-							$switch_dialplan_dir = $switch_conf_dir.'/dialplan';
-							$switch_scripts_dir = '/usr/local/etc/freeswitch/scripts';
-							$switch_grammar_dir = '/usr/local/etc/freeswitch/grammar';
-							$switch_storage_dir = '/data/freeswitch';
-							$switch_voicemail_dir = '/data/freeswitch/voicemail';
-							$switch_recordings_dir = '/data/freeswitch/recordings';
-							$switch_sounds_dir = '/data/freeswitch/sounds';
-				}
-				else {
-					//set the default db_path
-						if (strlen($db_path) == 0) {
-							$db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure';
-						}
-				}
-			break;
-		case "NetBSD":
-			$startup_script_dir = '';
-			//set the default db_path
-				if (strlen($db_path) == 0) {
-					$db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure';
-				}
-			break;
-		case "OpenBSD":
-			$startup_script_dir = '';
-			//set the default db_path
-				if (strlen($db_path) == 0) {
-					$db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure';
-				}
-			break;
-		default:
-			//set the default db_path
-				if (strlen($db_path) == 0) {
-					$db_path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/secure';
-				}
-		}
-		//
-		// CYGWIN_NT-5.1
-		// Darwin
-		// FreeBSD
-		// HP-UX
-		// IRIX64
-		// Linux
-		// NetBSD
-		// OpenBSD
-		// SunOS
-		// Unix
-		// WIN32
-		// WINNT
-		// Windows
-		// CYGWIN_NT-5.1
-		// IRIX64
-		// SunOS
-		// HP-UX
-		// OpenBSD (not in Wikipedia)
-
-	//set the dir defaults for windows
-		if (substr(strtoupper(PHP_OS), 0, 3) == "WIN") {
-			if (substr($_SERVER["DOCUMENT_ROOT"], -3) == "www") {
-				//integrated installer
-				$install_switch_base_dir = realpath($_SERVER["DOCUMENT_ROOT"]."/..");
-				$startup_script_dir = '';
-			} elseif (is_readable('C:/program files/FreeSWITCH')) {
-				$install_switch_base_dir = 'C:/program files/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('D:/program files/FreeSWITCH')) {
-				$install_switch_base_dir = 'D:/program files/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('E:/program files/FreeSWITCH')) {
-				$install_switch_base_dir = 'E:/program files/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('F:/program files/FreeSWITCH')) {
-				$install_switch_base_dir = 'F:/program files/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('C:/FreeSWITCH')) {
-				$install_switch_base_dir = 'C:/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('D:/FreeSWITCH')) {
-				$install_switch_base_dir = 'D:/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('E:/FreeSWITCH')) {
-				$install_switch_base_dir = 'E:/FreeSWITCH';
-				$startup_script_dir = '';
-			} elseif (is_readable('F:/FreeSWITCH')) {
-				$install_switch_base_dir = 'F:/FreeSWITCH';
-				$startup_script_dir = '';
-			}
-		}
-$msg = '';
-if ($_POST["install_step"] == "2" && count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
-	//check for all required data
-		if (strlen($admin_username) == 0) { $msg .= "Please provide the Admin Username<br>\n"; }
-		if (strlen($admin_password) == 0) {
-			$msg .= "Please provide the Admin Password<br>\n";
-		}
-		else {
-			if (strlen($admin_password) < 5) {
-				$msg .= "Please provide an Admin Password that is 5 or more characters.<br>\n";
-			}
-		}
-	//define the step to return to
-		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
-			$_POST["install_step"] = "";
-		}
-}
-if ($_POST["install_step"] == "3" && count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
-	//check for all required data
-		if (strlen($db_type) == 0) { $msg .= "Please provide the Database Type<br>\n"; }
-		if (PHP_OS == "FreeBSD" && file_exists('/usr/local/etc/freeswitch/conf')) {
-			//install_switch_base_dir not required for the freebsd freeswitch port;
-		}
-		if (strlen($install_tmp_dir) == 0) { $msg .= "Please provide the Temp Directory.<br>\n"; }
-		if (strlen($install_backup_dir) == 0) { $msg .= "Please provide the Backup Directory.<br>\n"; }
-		if (strlen($install_template_name) == 0) { $msg .= "Please provide the Theme.<br>\n"; }
-	//define the step to return to
-		if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
-			$_POST["install_step"] = "2";
-		}
-}
-//show the error message if one exists
-	if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
-		require_once "resources/persist_form_var.php";
-		echo "<br />\n";
-		echo "<br />\n";
-		echo "<div align='center'>\n";
-		echo "<table><tr><td>\n";
-		echo $msg."<br />";
-		echo "</td></tr></table>\n";
-		persistformvar($_POST);
-		echo "</div>\n";
-		exit;
-	}
-
-if ($_POST["install_step"] == "3" && count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
-
-	//generate the config.php
-		$tmp_config = "<?php\n";
-		$tmp_config .= "/* \$Id\$ */\n";
-		$tmp_config .= "/*\n";
-		$tmp_config .= "	config.php\n";
-		$tmp_config .= "	Copyright (C) 2008, 2013 Mark J Crane\n";
-		$tmp_config .= "	All rights reserved.\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "	Redistribution and use in source and binary forms, with or without\n";
-		$tmp_config .= "	modification, are permitted provided that the following conditions are met:\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "	1. Redistributions of source code must retain the above copyright notice,\n";
-		$tmp_config .= "	   this list of conditions and the following disclaimer.\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "	2. Redistributions in binary form must reproduce the above copyright\n";
-		$tmp_config .= "	   notice, this list of conditions and the following disclaimer in the\n";
-		$tmp_config .= "	   documentation and/or other materials provided with the distribution.\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\n";
-		$tmp_config .= "	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\n";
-		$tmp_config .= "	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\n";
-		$tmp_config .= "	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n";
-		$tmp_config .= "	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n";
-		$tmp_config .= "	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n";
-		$tmp_config .= "	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n";
-		$tmp_config .= "	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n";
-		$tmp_config .= "	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n";
-		$tmp_config .= "	POSSIBILITY OF SUCH DAMAGE.\n";
-		$tmp_config .= "*/\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "//-----------------------------------------------------\n";
-		$tmp_config .= "// settings:\n";
-		$tmp_config .= "//-----------------------------------------------------\n";
-		$tmp_config .= "\n";
-		$tmp_config .= "	//set the database type\n";
-		$tmp_config .= "		\$db_type = '".$db_type."'; //sqlite, mysql, pgsql, others with a manually created PDO connection\n";
-		$tmp_config .= "\n";
-		if ($db_type == "sqlite") {
-			$tmp_config .= "	//sqlite: the db_name and db_path are automatically assigned however the values can be overidden by setting the values here.\n";
-			$tmp_config .= "		\$db_name = '".$db_name."'; //host name/ip address + '.db' is the default database filename\n";
-			$tmp_config .= "		\$db_path = '".$db_path."'; //the path is determined by a php variable\n";
-		}
-		$tmp_config .= "\n";
-		$tmp_config .= "	//mysql: database connection information\n";
-		if ($db_type == "mysql") {
-			if ($db_host == "localhost") {
-				//if localhost is used it defaults to a Unix Socket which doesn't seem to work.
-				//replace localhost with 127.0.0.1 so that it will connect using TCP
-				$db_host = "127.0.0.1";
-			}
-			$tmp_config .= "		\$db_host = '".$db_host."';\n";
-			$tmp_config .= "		\$db_port = '".$db_port."';\n";
-			$tmp_config .= "		\$db_name = '".$db_name."';\n";
-			$tmp_config .= "		\$db_username = '".$db_username."';\n";
-			$tmp_config .= "		\$db_password = '".$db_password."';\n";
-		}
-		else {
-			$tmp_config .= "		//\$db_host = '';\n";
-			$tmp_config .= "		//\$db_port = '';\n";
-			$tmp_config .= "		//\$db_name = '';\n";
-			$tmp_config .= "		//\$db_username = '';\n";
-			$tmp_config .= "		//\$db_password = '';\n";
-		}
-		$tmp_config .= "\n";
-		$tmp_config .= "	//pgsql: database connection information\n";
-		if ($db_type == "pgsql") {
-			$tmp_config .= "		\$db_host = '".$db_host."'; //set the host only if the database is not local\n";
-			$tmp_config .= "		\$db_port = '".$db_port."';\n";
-			$tmp_config .= "		\$db_name = '".$db_name."';\n";
-			$tmp_config .= "		\$db_username = '".$db_username."';\n";
-			$tmp_config .= "		\$db_password = '".$db_password."';\n";
-		}
-		else {
-			$tmp_config .= "		//\$db_host = '".$db_host."'; //set the host only if the database is not local\n";
-			$tmp_config .= "		//\$db_port = '".$db_port."';\n";
-			$tmp_config .= "		//\$db_name = '".$db_name."';\n";
-			$tmp_config .= "		//\$db_username = '".$db_username."';\n";
-			$tmp_config .= "		//\$db_password = '".$db_password."';\n";
-		}
-		$tmp_config .= "\n";
-		$tmp_config .= "	//show errors\n";
-		$tmp_config .= "		ini_set('display_errors', '1');\n";
-		$tmp_config .= "		//error_reporting (E_ALL); // Report everything\n";
-		$tmp_config .= "		//error_reporting (E_ALL ^ E_NOTICE); // Report everything\n";
-		$tmp_config .= "		error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ); //hide notices and warnings";
-		$tmp_config .= "\n";
-		$tmp_config .= "?>";
-
-		if (is_dir("/etc/fusionpbx")){
-			$config = "/etc/fusionpbx/config.php";
-		} elseif (is_dir("/usr/local/etc/fusionpbx")){
-			$config = "/usr/local/etc/fusionpbx/config.php";
-		}
-		elseif (is_dir($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/resources")) {
-			$config = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
-		}
-		else {
-			$config = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/config.php";
-		}
-		$fout = fopen($config,"w");
-		fwrite($fout, $tmp_config);
-		unset($tmp_config);
-		fclose($fout);
-
-	//include the new config.php file
-		require $config;
-
-	//create the sqlite database
-		if ($db_type == "sqlite") {
-			//sqlite database will be created when the config.php is loaded and only if the database file does not exist
-				try {
-					$db_tmp = new PDO('sqlite:'.$db_path.'/'.$db_name); //sqlite 3
-					//$db_tmp = new PDO('sqlite::memory:'); //sqlite 3
-				}
-				catch (PDOException $error) {
-					print "error: " . $error->getMessage() . "<br/>";
-					die();
-				}
-
-			//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
-				if (!function_exists('php_now')) {
-					function php_now() {
-						if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
-							@date_default_timezone_set(@date_default_timezone_get());
-						}
-						return date("Y-m-d H:i:s");
-					}
-				}
-				$db_tmp->sqliteCreateFunction('now', 'php_now', 0);
-
-			//add the database structure
-				require_once "resources/classes/schema.php";
-				$schema = new schema;
-				$schema->db = $db_tmp;
-				$schema->db_type = $db_type;
-				$schema->sql();
-				$schema->exec();
-
-			//get the contents of the sql file
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
-					$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
-				}
-				else {
-				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
-				}
-				$file_contents = file_get_contents($filename);
-				unset($filename);
-
-			//replace \r\n with \n then explode on \n
-				$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-			//loop line by line through all the lines of sql code
-				$db_tmp->beginTransaction();
-				$string_array = explode("\n", $file_contents);
-				$x = 0;
-				foreach($string_array as $sql) {
-					try {
-						$db_tmp->query($sql);
-					}
-					catch (PDOException $error) {
-						echo "error: " . $error->getMessage() . " sql: $sql<br/>";
-						//die();
-					}
-					$x++;
-				}
-				unset ($file_contents, $sql);
-				$db_tmp->commit();
-
-			//set the file permissions
-				chmod($db_path.'/'.$db_name, 0777);
-		}
-
-	//create the pgsql database
-		if ($db_type == "pgsql") {
-
-			//echo "DB Name: {$db_name}<br>";
-			//echo "DB Host: {$db_host}<br>";
-			//echo "DB User: {$db_username}<br>";
-			//echo "DB Pass: {$db_password}<br>";
-			//echo "DB Port: {$db_port}<br>";
-			//echo "DB Create User: {$db_create_username}<br>";
-			//echo "DB Create Pass: {$db_create_password}<br>";
-
-			//if $db_create_username provided, attempt to create new PG role and database
-				if (strlen($db_create_username) > 0) {
-					try {
-						if (strlen($db_port) == 0) { $db_port = "5432"; }
-						if (strlen($db_host) > 0) {
-							$db_tmp = new PDO("pgsql:host={$db_host} port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1");
-						} else {
-							$db_tmp = new PDO("pgsql:host=localhost port={$db_port} user={$db_create_username} password={$db_create_password} dbname=template1");
-						}
-					} catch (PDOException $error) {
-						print "error: " . $error->getMessage() . "<br/>";
-						die();
-					}
-
-					//create the database, user, grant perms
-					$db_tmp->exec("CREATE DATABASE {$db_name}");
-					$db_tmp->exec("CREATE USER {$db_username} WITH PASSWORD '{$db_password}'");
-					$db_tmp->exec("GRANT ALL ON {$db_name} TO {$db_username}");
-
-					//close database connection_aborted
-					$db_tmp = null;
-				}
-
-			//open database connection with $db_name
-				try {
-					if (strlen($db_port) == 0) { $db_port = "5432"; }
-					if (strlen($db_host) > 0) {
-						$db_tmp = new PDO("pgsql:host={$db_host} port={$db_port} dbname={$db_name} user={$db_username} password={$db_password}");
-					} else {
-						$db_tmp = new PDO("pgsql:host=localhost port={$db_port} user={$db_username} password={$db_password} dbname={$db_name}");
-					}
-				}
-				catch (PDOException $error) {
-					print "error: " . $error->getMessage() . "<br/>";
-					die();
-				}
-
-			//add the database structure
-				require_once "resources/classes/schema.php";
-				$schema = new schema;
-				$schema->db = $db_tmp;
-				$schema->db_type = $db_type;
-				$schema->sql();
-				$schema->exec();
-
-			//get the contents of the sql file
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
-					$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
-				}
-				else {
-				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
-				}
-				$file_contents = file_get_contents($filename);
-
-			//replace \r\n with \n then explode on \n
-				$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-			//loop line by line through all the lines of sql code
-				$string_array = explode("\n", $file_contents);
-				$x = 0;
-				foreach($string_array as $sql) {
-					if (strlen($sql) > 3) {
-						try {
-							$db_tmp->query($sql);
-						}
-						catch (PDOException $error) {
-							echo "error: " . $error->getMessage() . " sql: $sql<br/>";
-							die();
-						}
-					}
-					$x++;
-				}
-				unset ($file_contents, $sql);
-		}
-
-	//create the mysql database
-		if ($db_type == "mysql") {
-			//database connection
-				try {
-					if (strlen($db_host) == 0 && strlen($db_port) == 0) {
-						//if both host and port are empty use the unix socket
-						if (strlen($db_create_username) == 0) {
-							$db_tmp = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-						}
-						else {
-							$db_tmp = new PDO("mysql:host=$db_host;unix_socket=/var/run/mysqld/mysqld.sock;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-						}
-					}
-					else {
-						if (strlen($db_port) == 0) {
-							//leave out port if it is empty
-							if (strlen($db_create_username) == 0) {
-								$db_tmp = new PDO("mysql:host=$db_host;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-							}
-							else {
-								$db_tmp = new PDO("mysql:host=$db_host;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));							}
-						}
-						else {
-							if (strlen($db_create_username) == 0) {
-								$db_tmp = new PDO("mysql:host=$db_host;port=$db_port;", $db_username, $db_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-							}
-							else {
-								$db_tmp = new PDO("mysql:host=$db_host;port=$db_port;", $db_create_username, $db_create_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
-							}
-						}
-					}
-					$db_tmp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-					$db_tmp->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
-				}
-				catch (PDOException $error) {
-					if ($v_debug) {
-						print "error: " . $error->getMessage() . "<br/>";
-					}
-				}
-
-			//create the table, user and set the permissions only if the db_create_username was provided
-				if (strlen($db_create_username) > 0) {
-					//select the mysql database
-						try {
-							$db_tmp->query("USE mysql;");
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-					//create user and set the permissions
-						try {
-							$tmp_sql = "CREATE USER '".$db_username."'@'%' IDENTIFIED BY '".$db_password."'; ";
-							$db_tmp->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-					//set account to unlimited use
-						try {
-							if ($db_host == "localhost" || $db_host == "127.0.0.1") {
-								$tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'localhost' ";
-								$tmp_sql .= "IDENTIFIED BY '".$db_password."' ";
-								$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
-								$db_tmp->query($tmp_sql);
-
-								$tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'127.0.0.1' ";
-								$tmp_sql .= "IDENTIFIED BY '".$db_password."' ";
-								$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
-								$db_tmp->query($tmp_sql);
-							}
-							else {
-								$tmp_sql = "GRANT USAGE ON * . * TO '".$db_username."'@'".$db_host."' ";
-								$tmp_sql .= "IDENTIFIED BY '".$db_password."' ";
-								$tmp_sql .= "WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; ";
-								$db_tmp->query($tmp_sql);
-							}
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-					//create the database and set the create user with permissions
-						try {
-							$tmp_sql = "CREATE DATABASE IF NOT EXISTS ".$db_name."; ";
-							$db_tmp->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-					//set user permissions
-						try {
-							$db_tmp->query("GRANT ALL PRIVILEGES ON ".$db_name.".* TO '".$db_username."'@'%'; ");
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-					//make the changes active
-						try {
-							$tmp_sql = "FLUSH PRIVILEGES; ";
-							$db_tmp->query($tmp_sql);
-						}
-						catch (PDOException $error) {
-							if ($v_debug) {
-								print "error: " . $error->getMessage() . "<br/>";
-							}
-						}
-
-				} //if (strlen($db_create_username) > 0)
-
-			//select the database
-				try {
-					$db_tmp->query("USE ".$db_name.";");
-				}
-				catch (PDOException $error) {
-					if ($v_debug) {
-						print "error: " . $error->getMessage() . "<br/>";
-					}
-				}
-
-			//add the database structure
-				require_once "resources/classes/schema.php";
-				$schema = new schema;
-				$schema->db = $db_tmp;
-				$schema->db_type = $db_type;
-				$schema->sql();
-				$schema->exec();
-
-			//add the defaults data into the database
-				//get the contents of the sql file
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql')){
-					$filename = "/usr/share/examples/fusionpbx/resources/install/sql/mysql.sql";
-				}
-				else {
-					$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/mysql.sql';
-				}
-				$file_contents = file_get_contents($filename);
-
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$string_array = explode("\n", $file_contents);
-					$x = 0;
-					foreach($string_array as $sql) {
-						if (strlen($sql) > 3) {
-							try {
-								if ($v_debug) {
-									fwrite($fp, $sql."\n");
-								}
-								$db_tmp->query($sql);
-							}
-							catch (PDOException $error) {
-								//echo "error on line $x: " . $error->getMessage() . " sql: $sql<br/>";
-								//die();
-							}
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
-		}
-
-	//replace back slashes with forward slashes
-		$install_switch_base_dir = str_replace("\\", "/", $install_switch_base_dir);
-		$startup_script_dir = str_replace("\\", "/", $startup_script_dir);
-		$install_tmp_dir = str_replace("\\", "/", $install_tmp_dir);
-		$install_backup_dir = str_replace("\\", "/", $install_backup_dir);
-
-	//add the domain
-		$sql = "insert into v_domains ";
-		$sql .= "(";
-		$sql .= "domain_uuid, ";
-		$sql .= "domain_name, ";
-		$sql .= "domain_description ";
-		$sql .= ") ";
-		$sql .= "values ";
-		$sql .= "(";
-		$sql .= "'".$_SESSION["domain_uuid"]."', ";
-		$sql .= "'".$domain_name."', ";
-		$sql .= "'' ";
-		$sql .= ");";
-		if ($v_debug) {
-			fwrite($fp, $sql."\n");
-		}
-		$db_tmp->exec(check_sql($sql));
-		unset($sql);
-
-	//get the web server protocol
-		//$install_server_protocol = $_SERVER["SERVER_PORT"];
-		//$server_protocol_array = explode('/', $_SERVER["SERVER_PROTOCOL"]);
-		//$install_server_protocol = strtolower($server_protocol[0]);
-		//unset($server_protocol_array);
-
-	//add the default settings
-		$x = 0;
-		$tmp[$x]['name'] = 'uuid';
-		$tmp[$x]['value'] = $menu_uuid;
-		$tmp[$x]['category'] = 'domain';
-		$tmp[$x]['subcategory'] = 'menu';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'name';
-		$tmp[$x]['category'] = 'domain';
-		$tmp[$x]['subcategory'] = 'time_zone';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-        $tmp[$x]['name'] = 'code';
-		$tmp[$x]['value'] = 'en-us';
-		$tmp[$x]['category'] = 'domain';
-		$tmp[$x]['subcategory'] = 'language';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'iso_code';
-		$tmp[$x]['value'] = $install_default_country;
-		$tmp[$x]['category'] = 'domain';
-		$tmp[$x]['subcategory'] = 'country';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'name';
-		$tmp[$x]['value'] = $install_template_name;
-		$tmp[$x]['category'] = 'domain';
-		$tmp[$x]['subcategory'] = 'template';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $install_tmp_dir;
-		$tmp[$x]['category'] = 'server';
-		$tmp[$x]['subcategory'] = 'temp';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $startup_script_dir;
-		$tmp[$x]['category'] = 'server';
-		$tmp[$x]['subcategory'] = 'startup_script';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $install_backup_dir;
-		$tmp[$x]['category'] = 'server';
-		$tmp[$x]['subcategory'] = 'backup';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_bin_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'bin';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $install_switch_base_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'base';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_conf_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'conf';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_db_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'db';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_log_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'log';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_extensions_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'extensions';
-		$tmp[$x]['enabled'] = 'false';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_sip_profiles_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'sip_profiles';
-		$tmp[$x]['enabled'] = 'false';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_dialplan_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'dialplan';
-		$tmp[$x]['enabled'] = 'false';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_mod_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'mod';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_scripts_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'scripts';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_grammar_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'grammar';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_storage_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'storage';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_voicemail_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'voicemail';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_recordings_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'recordings';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = $switch_sounds_dir;
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'sounds';
-		$tmp[$x]['enabled'] = 'true';
-		$x++;
-		$tmp[$x]['name'] = 'dir';
-		$tmp[$x]['value'] = '';
-		$tmp[$x]['category'] = 'switch';
-		$tmp[$x]['subcategory'] = 'provision';
-		$tmp[$x]['enabled'] = 'false';
-		$x++;
-		$db_tmp->beginTransaction();
-		foreach($tmp as $row) {
-			$sql = "insert into v_default_settings ";
-			$sql .= "(";
-			$sql .= "default_setting_uuid, ";
-			$sql .= "default_setting_name, ";
-			$sql .= "default_setting_value, ";
-			$sql .= "default_setting_category, ";
-			$sql .= "default_setting_subcategory, ";
-			$sql .= "default_setting_enabled ";
-			$sql .= ") ";
-			$sql .= "values ";
-			$sql .= "(";
-			$sql .= "'".uuid()."', ";
-			$sql .= "'".$row['name']."', ";
-			$sql .= "'".$row['value']."', ";
-			$sql .= "'".$row['category']."', ";
-			$sql .= "'".$row['subcategory']."', ";
-			$sql .= "'".$row['enabled']."' ";
-			$sql .= ");";
-			if ($v_debug) {
-				fwrite($fp, $sql."\n");
-			}
-			$db_tmp->exec(check_sql($sql));
-			unset($sql);
-		}
-		$db_tmp->commit();
-		unset($tmp);
-
-	//get the list of installed apps from the core and mod directories
-		$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
-		$x=0;
-		foreach ($config_list as $config_path) {
-			include($config_path);
-			$x++;
-		}
-
-	//add the groups
-		$x = 0;
-		$tmp[$x]['group_name'] = 'superadmin';
-		$tmp[$x]['group_description'] = 'Super Administrator Group';
-		$x++;
-		$tmp[$x]['group_name'] = 'admin';
-		$tmp[$x]['group_description'] = 'Administrator Group';
-		$x++;
-		$tmp[$x]['group_name'] = 'user';
-		$tmp[$x]['group_description'] = 'User Group';
-		$x++;
-		$tmp[$x]['group_name'] = 'public';
-		$tmp[$x]['group_description'] = 'Public Group';
-		$x++;
-		$tmp[$x]['group_name'] = 'agent';
-		$tmp[$x]['group_description'] = 'Call Center Agent Group';
-		$db_tmp->beginTransaction();
-		foreach($tmp as $row) {
-			$sql = "insert into v_groups ";
-			$sql .= "(";
-			$sql .= "group_uuid, ";
-			$sql .= "group_name, ";
-			$sql .= "group_description ";
-			$sql .= ") ";
-			$sql .= "values ";
-			$sql .= "(";
-			$sql .= "'".uuid()."', ";
-			$sql .= "'".$row['group_name']."', ";
-			$sql .= "'".$row['group_description']."' ";
-			$sql .= ");";
-			if ($v_debug) {
-				fwrite($fp, $sql."\n");
-			}
-			$db_tmp->exec(check_sql($sql));
-			unset($sql);
-		}
-		unset($tmp);
-		$db_tmp->commit();
-
-	//add a user and then add the user to the superadmin group
-		//prepare the values
-			$user_uuid = uuid();
-			$contact_uuid = uuid();
-		//set a sessiong variable
-			$_SESSION["user_uuid"] = $user_uuid;
-		//salt used with the password to create a one way hash
-			$salt = generate_password('20', '4');
-		//add the user account
-			$sql = "insert into v_users ";
-			$sql .= "(";
-			$sql .= "domain_uuid, ";
-			$sql .= "user_uuid, ";
-			$sql .= "contact_uuid, ";
-			$sql .= "username, ";
-			$sql .= "password, ";
-			$sql .= "salt, ";
-			$sql .= "add_date, ";
-			$sql .= "add_user ";
-			$sql .= ") ";
-			$sql .= "values ";
-			$sql .= "(";
-			$sql .= "'".$_SESSION["domain_uuid"]."', ";
-			$sql .= "'$user_uuid', ";
-			$sql .= "'$contact_uuid', ";
-			$sql .= "'".$admin_username."', ";
-			$sql .= "'".md5($salt.$admin_password)."', ";
-			$sql .= "'$salt', ";
-			$sql .= "now(), ";
-			$sql .= "'".$admin_username."' ";
-			$sql .= ");";
-			if ($v_debug) {
-				fwrite($fp, $sql."\n");
-			}
-			$db_tmp->exec(check_sql($sql));
-			unset($sql);
-
-		//add to contacts
-			$sql = "insert into v_contacts ";
-			$sql .= "(";
-			$sql .= "domain_uuid, ";
-			$sql .= "contact_uuid, ";
-			$sql .= "contact_type, ";
-			$sql .= "contact_name_given, ";
-			$sql .= "contact_nickname ";
-			$sql .= ") ";
-			$sql .= "values ";
-			$sql .= "(";
-			$sql .= "'".$_SESSION["domain_uuid"]."', ";
-			$sql .= "'$contact_uuid', ";
-			$sql .= "'user', ";
-			$sql .= "'$admin_username', ";
-			$sql .= "'$admin_username' ";
-			$sql .= ")";
-			$db_tmp->exec(check_sql($sql));
-			unset($sql);
-
-	//add the user to the superadmin group
-		$sql = "insert into v_group_users ";
-		$sql .= "(";
-		$sql .= "group_user_uuid, ";
-		$sql .= "domain_uuid, ";
-		$sql .= "user_uuid, ";
-		$sql .= "group_name ";
-		$sql .= ") ";
-		$sql .= "values ";
-		$sql .= "(";
-		$sql .= "'".uuid()."', ";
-		$sql .= "'".$_SESSION["domain_uuid"]."', ";
-		$sql .= "'".$_SESSION["user_uuid"]."', ";
-		$sql .= "'superadmin' ";
-		$sql .= ");";
-		if ($v_debug) {
-			fwrite($fp, $sql."\n");
-		}
-		$db_tmp->exec(check_sql($sql));
-		unset($sql);
-
-	//assign the default permissions to the groups
-		$db_tmp->beginTransaction();
-		foreach($apps as $app) {
-			if ($app['permissions']) {
-				foreach ($app['permissions'] as $row) {
-					if ($v_debug) {
-						fwrite($fp, "v_group_permissions\n");
-						fwrite($fp, json_encode($row)."\n\n");
-					}
-					if ($row['groups']) {
-						foreach ($row['groups'] as $group) {
-							//add the record
-							$sql = "insert into v_group_permissions ";
-							$sql .= "(";
-							$sql .= "group_permission_uuid, ";
-							$sql .= "permission_name, ";
-							$sql .= "group_name ";
-							$sql .= ") ";
-							$sql .= "values ";
-							$sql .= "(";
-							$sql .= "'".uuid()."', ";
-							$sql .= "'".$row['name']."', ";
-							$sql .= "'".$group."' ";
-							$sql .= ");";
-							if ($v_debug) {
-								fwrite($fp, $sql."\n");
-							}
-							$db_tmp->exec(check_sql($sql));
-							unset($sql);
-						}
-					}
-				}
-			}
-		}
-		$db_tmp->commit();
-
-	//unset the temporary database connection
-		unset($db_tmp);
-
-	//include additional files
-		require "resources/require.php";
-
-	//set the defaults
-		$menu_name = 'default';
-		$menu_language = 'en-us';
-		$menu_description = '';
-	//add the parent menu
-		$sql = "insert into v_menus ";
-		$sql .= "(";
-		$sql .= "menu_uuid, ";
-		$sql .= "menu_name, ";
-		$sql .= "menu_language, ";
-		$sql .= "menu_description ";
-		$sql .= ") ";
-		$sql .= "values ";
-		$sql .= "(";
-		$sql .= "'".$menu_uuid."', ";
-		$sql .= "'$menu_name', ";
-		$sql .= "'$menu_language', ";
-		$sql .= "'$menu_description' ";
-		$sql .= ");";
-		if ($v_debug) {
-			fwrite($fp, $sql."\n");
-		}
-		$db->exec(check_sql($sql));
-		unset($sql);
-
-	//add the menu items
-		require_once "resources/classes/menu.php";
-		$menu = new menu;
-		$menu->db = $db;
-		$menu->menu_uuid = $menu_uuid;
-		$menu->restore();
-		unset($menu);
-
-	//setup the switch config directory if it exists
-		if (file_exists($switch_conf_dir) && $switch_conf_dir != "/conf") {
-			if ($v_debug) {
-				fwrite($fp, "switch_base_dir: ".$install_switch_base_dir."\n");
-				fwrite($fp, "switch_conf_dir: ".$switch_conf_dir."\n");
-				fwrite($fp, "switch_dialplan_dir: ".$switch_dialplan_dir."\n");
-				fwrite($fp, "switch_scripts_dir: ".$switch_scripts_dir."\n");
-				fwrite($fp, "switch_sounds_dir: ".$switch_sounds_dir."\n");
-				fwrite($fp, "switch_recordings_dir: ".$switch_recordings_dir."\n");
-			}
-
-			//create the necessary directories
-				if (!is_readable($install_tmp_dir)) { mkdir($install_tmp_dir,0777,true); }
-				if (!is_readable($install_backup_dir)) { mkdir($install_backup_dir,0777,true); }
-				if (is_readable($switch_log_dir)) {
-					if (!is_readable($switch_scripts_dir.'') && $switch_scripts_dir != "/scripts") { mkdir($switch_scripts_dir.'',0777,true); }
-			//		if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/8000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/8000',0777,true); }
-			//		if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/16000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/16000',0777,true); }
-			//		if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/32000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/32000',0777,true); }
-			//		if (!is_readable($switch_sounds_dir.'/en/us/callie/custom/48000') && $switch_scripts_dir != "/sounds") { mkdir($switch_sounds_dir.'/en/us/callie/custom/48000',0777,true); }
-					if (!is_readable($switch_storage_dir.'/fax/') && $switch_scripts_dir != "/storage") { mkdir($switch_storage_dir.'/fax',0777,true); }
-					if (!is_readable($switch_recordings_dir.'') && $switch_scripts_dir != "/recordings") { mkdir($switch_recordings_dir.'',0777,true); }
-				}
-
-			//copy the files and directories from resources/install
-				require_once "resources/classes/install.php";
-				$install = new install;
-				$install->domain_uuid = $_SESSION["domain_uuid"];
-				$install->domain = $domain_name;
-				$install->switch_conf_dir = $switch_conf_dir;
-				$install->switch_scripts_dir = $switch_scripts_dir;
-			//	$install->switch_sounds_dir = $switch_sounds_dir;
-				$install->copy_conf();
-				$install->copy();
-
-			//create the dialplan/default.xml for single tenant or dialplan/domain.xml
-				if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/dialplan")) {
-					$dialplan = new dialplan;
-					$dialplan->domain_uuid = $_SESSION["domain_uuid"];
-					$dialplan->domain = $domain_name;
-					$dialplan->switch_dialplan_dir = $switch_dialplan_dir;
-					$dialplan->restore_advanced_xml();
-					//print_r($dialplan->result);
-				}
-
-			//write the xml_cdr.conf.xml file
-				if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/xml_cdr")) {
-					xml_cdr_conf_xml();
-				}
-
-			//write the switch.conf.xml file
-				if (file_exists($switch_conf_dir)) {
-					switch_conf_xml();
-				}
-		}
-
-	//login the user account
-		$_SESSION["username"] = $admin_username;
-
-	//get the groups assigned to the user and then set the groups in $_SESSION["groups"]
-		$sql = "SELECT * FROM v_group_users ";
-		$sql .= "where domain_uuid=:domain_uuid ";
-		$sql .= "and user_uuid=:user_uuid ";
-		$prep_statement = $db->prepare(check_sql($sql));
-		$prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"]);
-		$prep_statement->bindParam(':user_uuid', $_SESSION["user_uuid"]);
-		$prep_statement->execute();
-		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-		$_SESSION["groups"] = $result;
-		unset($sql, $row_count, $prep_statement);
-
-	//get the permissions assigned to the groups that the user is a member of set the permissions in $_SESSION['permissions']
-		$x = 0;
-		$sql = "select distinct(permission_name) from v_group_permissions ";
-		foreach($_SESSION["groups"] as $field) {
-			if (strlen($field['group_name']) > 0) {
-				if ($x == 0) {
-					$sql .= "where (domain_uuid = '".$_SESSION["domain_uuid"]."' and group_name = '".$field['group_name']."') ";
-				}
-				else {
-					$sql .= "or (domain_uuid = '".$_SESSION["domain_uuid"]."' and group_name = '".$field['group_name']."') ";
-				}
-				$x++;
-			}
-		}
-		$prep_statementsub = $db->prepare($sql);
-		$prep_statementsub->execute();
-		$_SESSION['permissions'] = $prep_statementsub->fetchAll(PDO::FETCH_NAMED);
-		unset($sql, $prep_statementsub);
-
-	//make sure the database schema and installation have performed all necessary tasks
-		$display_results = false;
-		$display_type = 'none';
-		require_once "resources/classes/schema.php";
-		$obj = new schema;
-		$obj->schema($db, $db_type, $db_name, $display_type);
-
-	//run all app_defaults.php files
-		require_once "resources/classes/domains.php";
-		$domain = new domains;
-		$domain->upgrade();
-
-	//synchronize the config with the saved settings
-		save_switch_xml();
-
-	//do not show the apply settings reminder on the login page
-		$_SESSION["reload_xml"] = false;
-
-	//clear the menu
-		$_SESSION["menu"] = "";
-
-	//redirect to the login page
-		$msg = "install complete";
-		header("Location: ".PROJECT_PATH."/logout.php?msg=".urlencode($msg));
-}
-
-//set a default template
-	if (strlen($_SESSION['domain']['template']['name']) == 0) { $_SESSION['domain']['template']['name'] = 'enhanced'; }
-
-//get the contents of the template and save it to the template variable
-	$template = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes/'.$_SESSION['domain']['template']['name'].'/template.php');
-
-//buffer the content
-	ob_end_clean(); //clean the buffer
-	ob_start();
-
-//show the html form
-	if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/header.php")) {
-		$install_msg .= "<li>Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/ is required during the install.</li>\n";
-	}
-	if (!extension_loaded('PDO')) {
-		$install_msg .= "<li>PHP PDO was not detected. Please install it before proceeding.</li>";
-	}
-
-	if ($install_msg) {
-		echo "<br />\n";
-		echo "<div align='center'>\n";
-		echo "<table width='75%'>\n";
-		echo "<tr>\n";
-		echo "<th align='left'>Message</th>\n";
-		echo "</tr>\n";
-		echo "<tr>\n";
-		echo "<td class='row_style1'><strong><ul>$install_msg</ul></strong></td>\n";
-		echo "</tr>\n";
-		echo "</table>\n";
-		echo "</div>\n";
-	}
-
-	echo "<div align='center'>\n";
-	$msg = '';
-	//make sure the includes directory is writable so the config.php file can be written.
-		if (!is_writable($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/pdo.php")) {
-			$msg .= "<b>Write access to ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."</b><br />";
-			$msg .= "and its sub-directories are required during the install.<br /><br />\n";
-		}
-
-	//display the message
-		if (strlen($msg) > 0) {
-			//echo "not writable";
-			echo $msg;
-			echo "<br />\n";
-			echo "<br />\n";
-			unset($msg);
-			//exit;
-		}
-
-// step 1
-	if ($_POST["install_step"] == "") {
-		echo "<div id='page' align='center'>\n";
-		echo "<form method='post' name='frm' action=''>\n";
-		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-
-		//echo "<tr>\n";
-		//echo "<td colspan='2' align='left' width='30%' nowrap><b>Installation</b></td>\n";
-		//echo "</tr>\n";
-		echo "<tr>\n";
-		echo "<td colspan='2' width='100%' align='left'>\n";
-		echo "	<strong>The installation is a simple two step process.</strong> \n";
-		echo "	<ul>\n";
-		echo "	<li>Step 1 is used for selecting the database engine to use. After making that section then ensure the paths are correct and then press next. </li> ";
-		echo "	<li>Step 2 requests the database specific settings. When finished press save. The installation will then complete the tasks required to do the install. </li></td>\n";
-		echo "	</ul>\n";
-		//echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_dialplan_edit.php?id=".$dialplan_uuid."'\" value='Back'></td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td align='left' width='30%' nowrap><b>Step 1</b></td>\n";
-		echo "<td width='70%' align='right'>&nbsp;</td>\n";
-		//echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='v_dialplan_edit.php?id=".$dialplan_uuid."'\" value='Back'></td>\n";
-		echo "</tr>\n";
-
-		$db_type = $_POST["db_type"];
-		$install_step = $_POST["install_step"];
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "	Database Type\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<select name='db_type' id='db_type' class='formfld' id='form_tag' onchange='db_type_onchange();'>\n";
-		if (extension_loaded('pdo_pgsql')) {	echo "	<option value='pgsql'>postgresql</option>\n"; }
-		if (extension_loaded('pdo_mysql')) {	echo "	<option value='mysql'>mysql</option>\n"; }
-		if (extension_loaded('pdo_sqlite')) {	echo "	<option  value='sqlite' selected>sqlite</option>\n"; } //set sqlite as the default
-		echo "	</select><br />\n";
-		echo "		Select the database type.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	Username\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<input class='formfld' type='text' name='admin_username' maxlength='255' value=\"$admin_username\"><br />\n";
-		echo "	Enter the username to use when logging in with the browser.<br />\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	Password\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<input class='formfld' type='text' name='admin_password' maxlength='255' value=\"$admin_password\"><br />\n";
-		echo "	Enter the password to use when logging in with the browser.<br />\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
-		echo "	Country\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<select id='install_default_country' name='install_default_country' class='formfld' style=''>\n";
-echo <<<EOL
-<option value="AF">Afghanistan</option>
-<option value="AX">Åland Islands</option>
-<option value="AL">Albania</option>
-<option value="DZ">Algeria</option>
-<option value="AS">American Samoa</option>
-<option value="AD">Andorra</option>
-<option value="AO">Angola</option>
-<option value="AI">Anguilla</option>
-<option value="AQ">Antarctica</option>
-<option value="AG">Antigua and Barbuda</option>
-<option value="AR">Argentina</option>
-<option value="AM">Armenia</option>
-<option value="AW">Aruba</option>
-<option value="AU">Australia</option>
-<option value="AT">Austria</option>
-<option value="AZ">Azerbaijan</option>
-<option value="BS">Bahamas</option>
-<option value="BH">Bahrain</option>
-<option value="BD">Bangladesh</option>
-<option value="BB">Barbados</option>
-<option value="BY">Belarus</option>
-<option value="BE">Belgium</option>
-<option value="BZ">Belize</option>
-<option value="BJ">Benin</option>
-<option value="BM">Bermuda</option>
-<option value="BT">Bhutan</option>
-<option value="BO">Bolivia</option>
-<option value="BA">Bosnia and Herzegovina</option>
-<option value="BW">Botswana</option>
-<option value="BV">Bouvet Island</option>
-<option value="BR">Brazil</option>
-<option value="IO">British Indian Ocean Territory</option>
-<option value="BN">Brunei Darussalam</option>
-<option value="BG">Bulgaria</option>
-<option value="BF">Burkina Faso</option>
-<option value="BI">Burundi</option>
-<option value="KH">Cambodia</option>
-<option value="CM">Cameroon</option>
-<option value="CA">Canada</option>
-<option value="CV">Cape Verde</option>
-<option value="KY">Cayman Islands</option>
-<option value="CF">Central African Republic</option>
-<option value="TD">Chad</option>
-<option value="CL">Chile</option>
-<option value="CN">China</option>
-<option value="CX">Christmas Island</option>
-<option value="CC">Cocos (Keeling) Islands</option>
-<option value="CO">Colombia</option>
-<option value="KM">Comoros</option>
-<option value="CG">Congo</option>
-<option value="CD">Congo, The Democratic Republic of The</option>
-<option value="CK">Cook Islands</option>
-<option value="CR">Costa Rica</option>
-<option value="CI">Cote D'ivoire</option>
-<option value="HR">Croatia</option>
-<option value="CU">Cuba</option>
-<option value="CY">Cyprus</option>
-<option value="CZ">Czech Republic</option>
-<option value="DK">Denmark</option>
-<option value="DJ">Djibouti</option>
-<option value="DM">Dominica</option>
-<option value="DO">Dominican Republic</option>
-<option value="EC">Ecuador</option>
-<option value="EG">Egypt</option>
-<option value="SV">El Salvador</option>
-<option value="GQ">Equatorial Guinea</option>
-<option value="ER">Eritrea</option>
-<option value="EE">Estonia</option>
-<option value="ET">Ethiopia</option>
-<option value="FK">Falkland Islands (Malvinas)</option>
-<option value="FO">Faroe Islands</option>
-<option value="FJ">Fiji</option>
-<option value="FI">Finland</option>
-<option value="FR">France</option>
-<option value="GF">French Guiana</option>
-<option value="PF">French Polynesia</option>
-<option value="TF">French Southern Territories</option>
-<option value="GA">Gabon</option>
-<option value="GM">Gambia</option>
-<option value="GE">Georgia</option>
-<option value="DE">Germany</option>
-<option value="GH">Ghana</option>
-<option value="GI">Gibraltar</option>
-<option value="GR">Greece</option>
-<option value="GL">Greenland</option>
-<option value="GD">Grenada</option>
-<option value="GP">Guadeloupe</option>
-<option value="GU">Guam</option>
-<option value="GT">Guatemala</option>
-<option value="GG">Guernsey</option>
-<option value="GN">Guinea</option>
-<option value="GW">Guinea-bissau</option>
-<option value="GY">Guyana</option>
-<option value="HT">Haiti</option>
-<option value="HM">Heard Island and Mcdonald Islands</option>
-<option value="VA">Holy See (Vatican City State)</option>
-<option value="HN">Honduras</option>
-<option value="HK">Hong Kong</option>
-<option value="HU">Hungary</option>
-<option value="IS">Iceland</option>
-<option value="IN">India</option>
-<option value="ID">Indonesia</option>
-<option value="IR">Iran, Islamic Republic of</option>
-<option value="IQ">Iraq</option>
-<option value="IE">Ireland</option>
-<option value="IM">Isle of Man</option>
-<option value="IL">Israel</option>
-<option value="IT">Italy</option>
-<option value="JM">Jamaica</option>
-<option value="JP">Japan</option>
-<option value="JE">Jersey</option>
-<option value="JO">Jordan</option>
-<option value="KZ">Kazakhstan</option>
-<option value="KE">Kenya</option>
-<option value="KI">Kiribati</option>
-<option value="KP">Korea, Democratic People's Republic of</option>
-<option value="KR">Korea, Republic of</option>
-<option value="KW">Kuwait</option>
-<option value="KG">Kyrgyzstan</option>
-<option value="LA">Lao People's Democratic Republic</option>
-<option value="LV">Latvia</option>
-<option value="LB">Lebanon</option>
-<option value="LS">Lesotho</option>
-<option value="LR">Liberia</option>
-<option value="LY">Libyan Arab Jamahiriya</option>
-<option value="LI">Liechtenstein</option>
-<option value="LT">Lithuania</option>
-<option value="LU">Luxembourg</option>
-<option value="MO">Macao</option>
-<option value="MK">Macedonia, The Former Yugoslav Republic of</option>
-<option value="MG">Madagascar</option>
-<option value="MW">Malawi</option>
-<option value="MY">Malaysia</option>
-<option value="MV">Maldives</option>
-<option value="ML">Mali</option>
-<option value="MT">Malta</option>
-<option value="MH">Marshall Islands</option>
-<option value="MQ">Martinique</option>
-<option value="MR">Mauritania</option>
-<option value="MU">Mauritius</option>
-<option value="YT">Mayotte</option>
-<option value="MX">Mexico</option>
-<option value="FM">Micronesia, Federated States of</option>
-<option value="MD">Moldova, Republic of</option>
-<option value="MC">Monaco</option>
-<option value="MN">Mongolia</option>
-<option value="ME">Montenegro</option>
-<option value="MS">Montserrat</option>
-<option value="MA">Morocco</option>
-<option value="MZ">Mozambique</option>
-<option value="MM">Myanmar</option>
-<option value="NA">Namibia</option>
-<option value="NR">Nauru</option>
-<option value="NP">Nepal</option>
-<option value="NL">Netherlands</option>
-<option value="AN">Netherlands Antilles</option>
-<option value="NC">New Caledonia</option>
-<option value="NZ">New Zealand</option>
-<option value="NI">Nicaragua</option>
-<option value="NE">Niger</option>
-<option value="NG">Nigeria</option>
-<option value="NU">Niue</option>
-<option value="NF">Norfolk Island</option>
-<option value="MP">Northern Mariana Islands</option>
-<option value="NO">Norway</option>
-<option value="OM">Oman</option>
-<option value="PK">Pakistan</option>
-<option value="PW">Palau</option>
-<option value="PS">Palestinian Territory, Occupied</option>
-<option value="PA">Panama</option>
-<option value="PG">Papua New Guinea</option>
-<option value="PY">Paraguay</option>
-<option value="PE">Peru</option>
-<option value="PH">Philippines</option>
-<option value="PN">Pitcairn</option>
-<option value="PL">Poland</option>
-<option value="PT">Portugal</option>
-<option value="PR">Puerto Rico</option>
-<option value="QA">Qatar</option>
-<option value="RE">Reunion</option>
-<option value="RO">Romania</option>
-<option value="RU">Russian Federation</option>
-<option value="RW">Rwanda</option>
-<option value="SH">Saint Helena</option>
-<option value="KN">Saint Kitts and Nevis</option>
-<option value="LC">Saint Lucia</option>
-<option value="PM">Saint Pierre and Miquelon</option>
-<option value="VC">Saint Vincent and The Grenadines</option>
-<option value="WS">Samoa</option>
-<option value="SM">San Marino</option>
-<option value="ST">Sao Tome and Principe</option>
-<option value="SA">Saudi Arabia</option>
-<option value="SN">Senegal</option>
-<option value="RS">Serbia</option>
-<option value="SC">Seychelles</option>
-<option value="SL">Sierra Leone</option>
-<option value="SG">Singapore</option>
-<option value="SK">Slovakia</option>
-<option value="SI">Slovenia</option>
-<option value="SB">Solomon Islands</option>
-<option value="SO">Somalia</option>
-<option value="ZA">South Africa</option>
-<option value="GS">South Georgia and The South Sandwich Islands</option>
-<option value="ES">Spain</option>
-<option value="LK">Sri Lanka</option>
-<option value="SD">Sudan</option>
-<option value="SR">Suriname</option>
-<option value="SJ">Svalbard and Jan Mayen</option>
-<option value="SZ">Swaziland</option>
-<option value="SE">Sweden</option>
-<option value="CH">Switzerland</option>
-<option value="SY">Syrian Arab Republic</option>
-<option value="TW">Taiwan, Province of China</option>
-<option value="TJ">Tajikistan</option>
-<option value="TZ">Tanzania, United Republic of</option>
-<option value="TH">Thailand</option>
-<option value="TL">Timor-leste</option>
-<option value="TG">Togo</option>
-<option value="TK">Tokelau</option>
-<option value="TO">Tonga</option>
-<option value="TT">Trinidad and Tobago</option>
-<option value="TN">Tunisia</option>
-<option value="TR">Turkey</option>
-<option value="TM">Turkmenistan</option>
-<option value="TC">Turks and Caicos Islands</option>
-<option value="TV">Tuvalu</option>
-<option value="UG">Uganda</option>
-<option value="UA">Ukraine</option>
-<option value="AE">United Arab Emirates</option>
-<option value="GB">United Kingdom</option>
-<option value="US" selected='selected'>United States</option>
-<option value="UM">United States Minor Outlying Islands</option>
-<option value="UY">Uruguay</option>
-<option value="UZ">Uzbekistan</option>
-<option value="VU">Vanuatu</option>
-<option value="VE">Venezuela</option>
-<option value="VN">Viet Nam</option>
-<option value="VG">Virgin Islands, British</option>
-<option value="VI">Virgin Islands, U.S.</option>
-<option value="WF">Wallis and Futuna</option>
-<option value="EH">Western Sahara</option>
-<option value="YE">Yemen</option>
-<option value="ZM">Zambia</option>
-<option value="ZW">Zimbabwe</option>
-EOL;
-		echo "		</select>\n";
-		echo "		<br />\n";
-		echo "	Select ISO country code used to initialize calling contry code variables.<br />\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-
-		echo "	<tr>\n";
-		echo "	<td width='20%' class=\"vncellreq\" align='left' nowrap='nowrap'>\n";
-		echo "		Theme: \n";
-		echo "	</td>\n";
-		echo "	<td class=\"vtable\" align='left'>\n";
-		echo "		<select id='install_template_name' name='install_template_name' class='formfld' style=''>\n";
-		echo "		<option value=''></option>\n";
-		//set the default theme
-			$install_template_name = "enhanced";
-		//add all the themes to the list
-			$theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
-			if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
-				while (false !== ($dir_name = readdir($handle))) {
-					if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && is_readable($theme_dir.'/'.$dir_name)) {
-						$dir_label = str_replace('_', ' ', $dir_name);
-						$dir_label = str_replace('-', ' ', $dir_label);
-						if ($dir_name == $install_template_name) {
-							echo "		<option value='$dir_name' selected='selected'>$dir_label</option>\n";
-						}
-						else {
-							echo "		<option value='$dir_name'>$dir_label</option>\n";
-						}
-					}
-				}
-				closedir($handle);
-			}
-		echo "		</select>\n";
-		echo "		<br />\n";
-		echo "		Select a theme to set as the default.<br />\n";
-		echo "	</td>\n";
-		echo "	</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Domain name\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='domain_name' maxlength='255' value=\"$domain_name\"><br />\n";
-		echo "		Enter the default domain name. \n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "	<tr>\n";
-		echo "		<td colspan='2' align='right'>\n";
-		echo "			<input type='hidden' name='install_switch_base_dir' value='$install_switch_base_dir'>\n";
-		echo "			<input type='hidden' name='install_tmp_dir' value='$install_tmp_dir'>\n";
-		echo "			<input type='hidden' name='install_backup_dir' value='$install_backup_dir'>\n";
-		echo "			<input type='hidden' name='install_step' value='2'>\n";
-		echo "			<input type='submit' name='submit' class='btn' value='Next'>\n";
-		echo "		</td>\n";
-		echo "	</tr>";
-
-		echo "</table>";
-		echo "</form>";
-		echo "</div>";
-	}
-
-// step 2, sqlite
-	if ($_POST["install_step"] == "2" && $_POST["db_type"] == "sqlite") {
-		echo "<div id='page' align='center'>\n";
-		echo "<form method='post' name='frm' action=''>\n";
-		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-
-		echo "<tr>\n";
-		echo "<td align='left' width='30%' nowrap><b>Installation: Step 2 - SQLite</b></td>\n";
-		echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'></td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' 'valign='top' align='left' nowrap>\n";
-		echo "	Database Filename\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
-		echo "	Set the database filename. The file extension should be '.db'.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' 'valign='top' align='left' nowrap>\n";
-		echo "	Database Directory\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "	<input class='formfld' type='text' name='db_path' maxlength='255' value=\"$db_path\"><br />\n";
-		echo "	Set the path to the database directory.\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "	<tr>\n";
-		echo "		<td colspan='2' align='right'>\n";
-		echo "			<input type='hidden' name='db_type' value='$db_type'>\n";
-		echo "			<input type='hidden' name='admin_username' value='$admin_username'>\n";
-		echo "			<input type='hidden' name='admin_password' value='$admin_password'>\n";
-		echo "			<input type='hidden' name='domain_name' value='$domain_name'>\n";
-		echo "			<input type='hidden' name='install_switch_base_dir' value='$install_switch_base_dir'>\n";
-		echo "			<input type='hidden' name='install_tmp_dir' value='$install_tmp_dir'>\n";
-		echo "			<input type='hidden' name='install_backup_dir' value='$install_backup_dir'>\n";
-		echo "			<input type='hidden' name='install_step' value='3'>\n";
-		echo "			<input type='hidden' name='install_template_name' value='$install_template_name'>\n";
-		echo "			<input type='hidden' name='install_default_country' value='$install_default_country'>\n";
-		echo "			<input type='submit' name='submit' class='btn' value='Next'>\n";
-		echo "		</td>\n";
-		echo "	</tr>";
-
-		echo "</table>";
-		echo "</form>";
-		echo "</div>";
-	}
-
-// step 2, mysql
-	if ($_POST["install_step"] == "2" && $_POST["db_type"] == "mysql") {
-
-		//set defaults
-			if (strlen($db_host) == 0) { $db_host = 'localhost'; }
-			if (strlen($db_port) == 0) { $db_port = '3306'; }
-			//if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; }
-
-		//echo "However if preferred the database can be created manually with the <a href='". echo PROJECT_PATH; ."/resources/install/sql/mysql.sql' target='_blank'>mysql.sql</a> script. ";
-		echo "<div id='page' align='center'>\n";
-		echo "<form method='post' name='frm' action=''>\n";
-		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-
-		echo "<tr>\n";
-		echo "<td align='left' width='30%' nowrap><b>Installation: Step 2 - MySQL</b></td>\n";
-		echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'></td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Host\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_host' maxlength='255' value=\"$db_host\"><br />\n";
-		echo "		Enter the host address for the database server.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Database Port\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_port' maxlength='255' value=\"$db_port\"><br />\n";
-		echo "		Enter the port number. It is optional if the database is using the default port.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Name\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
-		echo "		Enter the name of the database.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Username\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_username' maxlength='255' value=\"$db_username\"><br />\n";
-		echo "		Enter the database username. \n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Password\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_password' maxlength='255' value=\"$db_password\"><br />\n";
-		echo "		Enter the database password.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Create Database Username\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
-		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
-		echo "		By default this username is 'root' however it can be any account with permission to add a database, user, and grant permissions. \n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Create Database Password\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_create_password' maxlength='255' value=\"$db_create_password\"><br />\n";
-		echo "		Enter the create database password.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "	<tr>\n";
-		echo "		<td colspan='2' align='right'>\n";
-		echo "			<input type='hidden' name='db_type' value='$db_type'>\n";
-		echo "			<input type='hidden' name='admin_username' value='$admin_username'>\n";
-		echo "			<input type='hidden' name='admin_password' value='$admin_password'>\n";
-		echo "			<input type='hidden' name='domain_name' value='$domain_name'>\n";
-		echo "			<input type='hidden' name='install_switch_base_dir' value='$install_switch_base_dir'>\n";
-		echo "			<input type='hidden' name='install_tmp_dir' value='$install_tmp_dir'>\n";
-		echo "			<input type='hidden' name='install_backup_dir' value='$install_backup_dir'>\n";
-		echo "			<input type='hidden' name='install_step' value='3'>\n";
-		echo "			<input type='hidden' name='install_template_name' value='$install_template_name'>\n";
-		echo "			<input type='hidden' name='install_default_country' value='$install_default_country'>\n";
-		echo "			<input type='submit' name='submit' class='btn' value='Next'>\n";
-		echo "		</td>\n";
-		echo "	</tr>";
-
-		echo "</table>";
-		echo "</form>";
-		echo "</div>";
-	}
-
-// step 2, pgsql
-	if ($_POST["install_step"] == "2" && $_POST["db_type"] == "pgsql") {
-		if (strlen($db_host) == 0) { $db_host = 'localhost'; }
-		if (strlen($db_port) == 0) { $db_port = '5432'; }
-		if (strlen($db_name) == 0) { $db_name = 'fusionpbx'; }
-
-		echo "<div id='page' align='center'>\n";
-		echo "<form method='post' name='frm' action=''>\n";
-		echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
-
-		echo "<tr>\n";
-		echo "<td align='left' width='30%' nowrap><b>Installation: Step 2 - Postgres</b></td>\n";
-		echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'></td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Host\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_host' maxlength='255' value=\"$db_host\"><br />\n";
-		echo "		Enter the host address for the database server.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Database Port\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_port' maxlength='255' value=\"$db_port\"><br />\n";
-		echo "		Enter the port number. It is optional if the database is using the default port.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Name\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_name' maxlength='255' value=\"$db_name\"><br />\n";
-		echo "		Enter the name of the database.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Username\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_username' maxlength='255' value=\"$db_username\"><br />\n";
-		echo "		Enter the database username.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
-		echo "		Database Password\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_password' maxlength='255' value=\"$db_password\"><br />\n";
-		echo "		Enter the database password.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Create Database Username\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_create_username' maxlength='255' value=\"$db_create_username\"><br />\n";
-		echo "		Optional, this username is used to create the database, a database user and set the permissions. \n";
-		echo "		By default this username is 'pgsql' however it can be any account with permission to add a database, user, and grant permissions. \n";
-		echo "		Leave blank if the user and empty database already exist and you do not want them created. \n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "<tr>\n";
-		echo "<td class='vncell' valign='top' align='left' nowrap>\n";
-		echo "		Create Database Password\n";
-		echo "</td>\n";
-		echo "<td class='vtable' align='left'>\n";
-		echo "		<input class='formfld' type='text' name='db_create_password' maxlength='255' value=\"$db_create_password\"><br />\n";
-		echo "		Enter the create database password.\n";
-		echo "\n";
-		echo "</td>\n";
-		echo "</tr>\n";
-
-		echo "	<tr>\n";
-		echo "		<td colspan='2' align='right'>\n";
-		echo "			<input type='hidden' name='db_type' value='$db_type'>\n";
-		echo "			<input type='hidden' name='admin_username' value='$admin_username'>\n";
-		echo "			<input type='hidden' name='admin_password' value='$admin_password'>\n";
-		echo "			<input type='hidden' name='domain_name' value='$domain_name'>\n";
-		echo "			<input type='hidden' name='install_switch_base_dir' value='$install_switch_base_dir'>\n";
-		echo "			<input type='hidden' name='install_tmp_dir' value='$install_tmp_dir'>\n";
-		echo "			<input type='hidden' name='install_backup_dir' value='$install_backup_dir'>\n";
-		echo "			<input type='hidden' name='install_step' value='3'>\n";
-		echo "			<input type='hidden' name='install_template_name' value='$install_template_name'>\n";
-		echo "			<input type='hidden' name='install_default_country' value='$install_default_country'>\n";
-		echo "			<input type='submit' name='submit' class='btn' value='Install'>\n";
-		echo "		</td>\n";
-		echo "	</tr>";
-
-		echo "</table>";
-		echo "</form>";
-		echo "</div>";
-	}
-
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-	echo "<br />\n";
-
-// add the content to the template and then send output
-	$body = $content_from_db.ob_get_contents(); //get the output from the buffer
-	ob_end_clean(); //clean the buffer
-
-	ob_start();
-	eval('?>' . $template . '<?php ');
-	$template = ob_get_contents(); //get the output from the buffer
-	ob_end_clean(); //clean the buffer
-
-	$custom_title = '';
-	$custom_head = '';
-	$output = str_replace ("<!--{title}-->", $custom_title, $template); //<!--{title}--> defined in each individual page
-	$output = str_replace ("<!--{head}-->", $custom_head, $output); //<!--{head}--> defined in each individual page
-	$output = str_replace ("<!--{menu}-->", $_SESSION["menu"], $output); //defined in /resources/menu.php
-	$output = str_replace ("<!--{project_path}-->", PROJECT_PATH, $output); //defined in /resources/menu.php
-
-	$pos = strrpos($output, "<!--{body}-->");
-	if ($pos === false) {
-		$output = $body; //if tag not found just show the body
-	}
-	else {
-		//replace the body
-		$output = str_replace ("<!--{body}-->", $body, $output);
-	}
-
-	echo $output;
-	unset($output);
-
-?>

+ 123 - 82
themes/enhanced/app_defaults.php

@@ -26,7 +26,64 @@
 
 if ($domains_processed == 1) {
 
+	//get the background images
+		$relative_path = PROJECT_PATH.'/themes/enhanced/images/backgrounds';
+		$backgrounds = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$relative_path);
+		unset($array);
+		$x = 0;
+		while (false !== ($file = readdir($backgrounds))) {
+			if ($file != "." AND $file != ".."){
+				$new_path = $dir.'/'.$file;
+				$level = explode('/',$new_path);
+				$ext = pathinfo($file, PATHINFO_EXTENSION);
+				if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") {
+					$x++;
+					$array[$x]['default_setting_category'] = 'theme';
+					$array[$x]['default_setting_subcategory'] = 'background_image';
+					$array[$x]['default_setting_name'] = 'array';
+					$array[$x]['default_setting_value'] = $relative_path.'/'.$file;
+					$array[$x]['default_setting_enabled'] = 'false';
+					$array[$x]['default_setting_description'] = 'Set a relative path or URL within a selected compatible template.';
+				}
+				if ($x > 300) { break; };
+			}
+		}
+		
+		if(!$set_session_theme){
+		//get default settings
+			$sql = "select * from v_default_settings ";
+			$sql .= "where default_setting_category = 'theme' ";
+			$sql .= "and default_setting_subcategory = 'background_image' ";
+			$prep_statement = $db->prepare(check_sql($sql));
+			$prep_statement->execute();
+			$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
+			unset($prep_statement);
+	
+			$background_image_enabled = false;
+		//add theme default settings
+			foreach ($array as $row) {
+				$found = false;
+				foreach ($default_settings as $field) {
+					if ($field["default_setting_value"] == $row["default_setting_value"]) {
+						$found = true;
+					}
+					//enable_background_image is a new setting, if a user has any background images enabled we should turn it on
+					if ($field["default_setting_enabled"] == 'enabled') {
+						$background_image_enabled = true;
+					}
+				}
+				if (!$found) {
+					$orm = new orm;
+					$orm->name('default_settings');
+					$orm->save($row);
+					$message = $orm->message;
+					//print_r($message);
+				}
+			}
+		}
+
 	//define array of settings
+		unset($array);
 		$x = 0;
 		$array[$x]['default_setting_category'] = 'theme';
 		$array[$x]['default_setting_subcategory'] = 'login_opacity';
@@ -181,25 +238,46 @@ if ($domains_processed == 1) {
 		$array[$x]['default_setting_value'] = '0.96';
 		$array[$x]['default_setting_enabled'] = 'false';
 		$array[$x]['default_setting_description'] = 'Set the opacity of the main menu (decimal, Minimized theme only).';
+		$x++;
+		$array[$x]['default_setting_category'] = 'theme';
+		$array[$x]['default_setting_subcategory'] = 'background_image_enabled';
+		$array[$x]['default_setting_name'] = 'boolean';
+		$array[$x]['default_setting_value'] = 'true';
+		$array[$x]['default_setting_enabled'] = 'false';
+		if($background_image_enabled) { $array[$x]['default_setting_enabled'] = 'true'; }
+		$array[$x]['default_setting_description'] = 'Enable use of background images.';
 
-	//iterate and add each, if necessary
-		foreach ($array as $index => $default_settings) {
-			//add theme default settings
-			$sql = "select count(*) as num_rows from v_default_settings ";
-			$sql .= "where default_setting_category = 'theme' ";
-			$sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' ";
-			$prep_statement = $db->prepare($sql);
-			if ($prep_statement) {
-				$prep_statement->execute();
-				$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
-				unset($prep_statement);
-				if ($row['num_rows'] == 0) {
-					$orm = new orm;
-					$orm->name('default_settings');
-					$orm->save($array[$index]);
-					$message = $orm->message;
+		if($set_session_theme){
+			foreach ($array as $index => $default_settings) {
+				$sub_category = $array[$index]['default_setting_subcategory'];
+				$name = $array[$index]['default_setting_name'];
+				if($array[$index]['default_setting_enabled'] == 'true'){
+					$_SESSION['theme'][$sub_category][$name] = $array[$index]['default_setting_value'];
+				}else{
+					$_SESSION['theme'][$sub_category][$name] = '';
+				}
+			}
+		}
+		else{
+		//iterate and add each, if necessary
+			foreach ($array as $index => $default_settings) {
+				//add theme default settings
+				$sql = "select count(*) as num_rows from v_default_settings ";
+				$sql .= "where default_setting_category = 'theme' ";
+				$sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' ";
+				$prep_statement = $db->prepare($sql);
+				if ($prep_statement) {
+					$prep_statement->execute();
+					$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+					unset($prep_statement);
+					if ($row['num_rows'] == 0) {
+						$orm = new orm;
+						$orm->name('default_settings');
+						$orm->save($array[$index]);
+						$message = $orm->message;
+					}
+					unset($row);
 				}
-				unset($row);
 			}
 		}
 
@@ -209,7 +287,7 @@ if ($domains_processed == 1) {
 		$array[$x]['default_setting_category'] = 'theme';
 		$array[$x]['default_setting_subcategory'] = 'background_color';
 		$array[$x]['default_setting_name'] = 'array';
-		$array[$x]['default_setting_value'] = '#ffffff';
+		$array[$x]['default_setting_value'] = '#6c89b5';
 		$array[$x]['default_setting_enabled'] = 'true';
 		$array[$x]['default_setting_order'] = '0';
 		$array[$x]['default_setting_description'] = 'Set a background (HTML compatible) color.';
@@ -217,78 +295,41 @@ if ($domains_processed == 1) {
 		$array[$x]['default_setting_category'] = 'theme';
 		$array[$x]['default_setting_subcategory'] = 'background_color';
 		$array[$x]['default_setting_name'] = 'array';
-		$array[$x]['default_setting_value'] = '#e7ebf1';
+		$array[$x]['default_setting_value'] = '#144794';
 		$array[$x]['default_setting_order'] = '1';
 		$array[$x]['default_setting_enabled'] = 'true';
 		$array[$x]['default_setting_description'] = 'Set a secondary background (HTML compatible) color, for a gradient effect.';
 
-	//add secondary background color separately, if missing
-		$sql = "select count(*) as num_rows from v_default_settings ";
-		$sql .= "where default_setting_category = 'theme' ";
-		$sql .= "and default_setting_subcategory = 'background_color' ";
-		$prep_statement = $db->prepare($sql);
-		if ($prep_statement) {
-			$prep_statement->execute();
-			$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
-			unset($prep_statement);
-			if ($row['num_rows'] == 0) {
-				$orm = new orm;
-				$orm->name('default_settings');
-				foreach ($array as $index => $null) {
-					$orm->save($array[$index]);
+		if($set_session_theme){
+			foreach ($array as $index => $default_settings) {
+				$sub_category = $array[$index]['default_setting_subcategory'];
+				$idx = $array[$index]['default_setting_order'];
+				if($array[$index]['default_setting_enabled'] == 'true'){
+					$_SESSION['theme'][$sub_category][$idx] = $array[$index]['default_setting_value'];
 				}
-				$message = $orm->message;
-				//print_r($message);
 			}
-			unset($row);
+			return;
 		}
-
-	//get the background images
-		$relative_path = PROJECT_PATH.'/themes/enhanced/images/backgrounds';
-		$backgrounds = opendir($_SERVER["DOCUMENT_ROOT"].'/'.$relative_path);
-		unset($array);
-		$x = 0;
-		while (false !== ($file = readdir($backgrounds))) {
-			if ($file != "." AND $file != ".."){
-				$new_path = $dir.'/'.$file;
-				$level = explode('/',$new_path);
-				$ext = pathinfo($file, PATHINFO_EXTENSION);
-				if ($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif") {
-					$x++;
-					$array[$x]['default_setting_category'] = 'theme';
-					$array[$x]['default_setting_subcategory'] = 'background_image';
-					$array[$x]['default_setting_name'] = 'array';
-					$array[$x]['default_setting_value'] = $relative_path.'/'.$file;
-					$array[$x]['default_setting_enabled'] = 'false';
-					$array[$x]['default_setting_description'] = 'Set a relative path or URL within a selected compatible template.';
-				}
-				if ($x > 300) { break; };
-			}
-		}
-
-	//get default settings
-		$sql = "select * from v_default_settings ";
-		$sql .= "where default_setting_category = 'theme' ";
-		$sql .= "and default_setting_subcategory = 'background_image' ";
-		$prep_statement = $db->prepare(check_sql($sql));
-		$prep_statement->execute();
-		$default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
-		unset($prep_statement);
-
-	//add theme default settings
-		foreach ($array as $row) {
-			$found = false;
-			foreach ($default_settings as $field) {
-				if ($field["default_setting_value"] == $row["default_setting_value"]) {
-					$found = true;
+		else{
+		//add secondary background color separately, if missing
+			$sql = "select count(*) as num_rows from v_default_settings ";
+			$sql .= "where default_setting_category = 'theme' ";
+			$sql .= "and default_setting_subcategory = 'background_color' ";
+			$prep_statement = $db->prepare($sql);
+			if ($prep_statement) {
+				$prep_statement->execute();
+				$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
+				unset($prep_statement);
+				if ($row['num_rows'] == 0) {
+					$orm = new orm;
+					$orm->name('default_settings');
+					foreach ($array as $index => $null) {
+						$orm->save($array[$index]);
+					}
+					$message = $orm->message;
+					//print_r($message);
 				}
-			}
-			if (!$found) {
-				$orm = new orm;
-				$orm->name('default_settings');
-				$orm->save($row);
-				$message = $orm->message;
-				//print_r($message);
+				unset($row);
 			}
 		}
 

+ 14 - 4
themes/enhanced/template.php

@@ -251,7 +251,7 @@ form {
 	margin: 0;
 	}
 
-input.btn, input.button {
+input.btn, input.button, button {
 	font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
 	padding: 2px 6px 3px 6px;
 	color: #fff;
@@ -273,7 +273,7 @@ input.btn, input.button {
 	-moz-opacity: 0.9;
 	}
 
-input.btn:hover, input.button:hover, img.list_control_icon:hover {
+input.btn:hover, input.button:hover, img.list_control_icon:hover, button:hover {
 	box-shadow: 0 0 5px #cddaf0;
 	-webkit-box-shadow: 0 0 5px #cddaf0;
 	-moz-box-shadow: 0 0 5px #cddaf0;
@@ -282,7 +282,7 @@ input.btn:hover, input.button:hover, img.list_control_icon:hover {
 	cursor: pointer;
 	}
 
-input.txt, textarea.txt, select.txt, .formfld {
+input.txt, textarea.txt, select.txt, .formfld, label.radio {
 	font-family: arial;
 	font-size: 12px;
 	color: #000;
@@ -311,6 +311,16 @@ input.txt:focus, .formfld:focus {
 	box-shadow: 0 0 5px #cddaf0;
 	}
 
+fieldset.container {
+	border:none;
+	padding:0;
+	margin:1px;
+	display:inline-block;
+}
+label.radio
+{
+	display:block;
+}
 /* removes spinners (increment/decrement controls) inside input fields */
 input[type=number] { -moz-appearance: textfield; }
 ::-webkit-inner-spin-button { -webkit-appearance: none; }
@@ -1424,7 +1434,7 @@ if (strlen($_SESSION['message']) > 0) {
 
 	<?php
 	// check for background image
-	if (isset($_SESSION['theme']['background_image'])) {
+	if (isset($_SESSION['theme']['background_image_enabled']['boolean']) and $_SESSION['theme']['background_image_enabled']['boolean'] == 'true') {
 		// background image is enabled
 		$image_extensions = array('jpg','jpeg','png','gif');
 

BIN
themes/flags/Afghanistan.png


BIN
themes/flags/Aland Islands.png


BIN
themes/flags/Albania.png


BIN
themes/flags/Algeria.png


BIN
themes/flags/American Samoa.png


BIN
themes/flags/Andorra.png


BIN
themes/flags/Angola.png


BIN
themes/flags/Anguilla.png


BIN
themes/flags/Antigua and Barbuda.png


BIN
themes/flags/Argentina.png


BIN
themes/flags/Armenia.png


BIN
themes/flags/Aruba.png


BIN
themes/flags/Australia.png


BIN
themes/flags/Austria.png


BIN
themes/flags/Azerbaijan.png


BIN
themes/flags/Bahamas.png


BIN
themes/flags/Bahrain.png


BIN
themes/flags/Bangladesh.png


BIN
themes/flags/Barbados.png


BIN
themes/flags/Belarus.png


BIN
themes/flags/Belgium.png


BIN
themes/flags/Belize.png


BIN
themes/flags/Benin.png


BIN
themes/flags/Bermuda.png


BIN
themes/flags/Bhutan.png


BIN
themes/flags/Bolivia, Plurinational State of.png


BIN
themes/flags/Bosnia and Herzegovina.png


BIN
themes/flags/Botswana.png


BIN
themes/flags/Bouvet Island.png


BIN
themes/flags/Brazil.png


BIN
themes/flags/British Indian Ocean Territory.png


BIN
themes/flags/Brunei Darussalam.png


BIN
themes/flags/Bulgaria.png


BIN
themes/flags/Burkina Faso.png


BIN
themes/flags/Burundi.png


BIN
themes/flags/Cabo Verde.png


BIN
themes/flags/Cambodia.png


BIN
themes/flags/Cameroon.png


BIN
themes/flags/Canada.png


BIN
themes/flags/Cayman Islands.png


BIN
themes/flags/Central African Republic.png


BIN
themes/flags/Chad.png


BIN
themes/flags/Chile.png


BIN
themes/flags/China.png


BIN
themes/flags/Christmas Island.png


BIN
themes/flags/Cocos (Keeling) Islands.png


BIN
themes/flags/Colombia.png


BIN
themes/flags/Comoros.png


BIN
themes/flags/Congo, the Democratic Republic of the.png


BIN
themes/flags/Congo.png


BIN
themes/flags/Cook Islands.png


BIN
themes/flags/Costa Rica.png


BIN
themes/flags/Cote d'Ivoire.png


BIN
themes/flags/Croatia.png


BIN
themes/flags/Cuba.png


BIN
themes/flags/Cyprus.png


BIN
themes/flags/Czech Republic.png


BIN
themes/flags/Denmark.png


BIN
themes/flags/Djibouti.png


BIN
themes/flags/Dominica.png


BIN
themes/flags/Dominican Republic.png


BIN
themes/flags/Ecuador.png


BIN
themes/flags/Egypt.png


BIN
themes/flags/El Salvador.png


Some files were not shown because too many files changed in this diff