upgrade_domains.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //check the permission
  22. if(defined('STDIN')) {
  23. $document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]);
  24. preg_match("/^(.*)\/core\/.*$/", $document_root, $matches);
  25. $document_root = $matches[1];
  26. set_include_path($document_root);
  27. require_once "includes/require.php";
  28. $_SERVER["DOCUMENT_ROOT"] = $document_root;
  29. $display_type = 'text'; //html, text
  30. }
  31. else {
  32. include "root.php";
  33. require_once "includes/require.php";
  34. require_once "includes/checkauth.php";
  35. if (permission_exists('upgrade_schema') || permission_exists('upgrade_svn') || if_group("superadmin")) {
  36. //echo "access granted";
  37. }
  38. else {
  39. echo "access denied";
  40. exit;
  41. }
  42. }
  43. //copy the files and directories from includes/install
  44. require_once "includes/classes/install.php";
  45. $install = new install;
  46. $install->domain_uuid = $domain_uuid;
  47. $install->domain_name = $domain;
  48. $install->switch_conf_dir = $_SESSION['switch']['conf']['dir'];
  49. $install->switch_scripts_dir = $_SESSION['switch']['scripts']['dir'];
  50. $install->switch_sounds_dir = $_SESSION['switch']['sounds']['dir'];
  51. $install->copy();
  52. //print_r($install->result);
  53. //get the list of installed apps from the core and mod directories
  54. $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
  55. $x=0;
  56. foreach ($config_list as &$config_path) {
  57. include($config_path);
  58. $x++;
  59. }
  60. //get the domain_uuid
  61. $sql = "select * from v_domains ";
  62. $prep_statement = $db->prepare($sql);
  63. $prep_statement->execute();
  64. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  65. foreach($result as $row) {
  66. if (count($result) == 0) {
  67. $_SESSION["domain_uuid"] = $row["domain_uuid"];
  68. $_SESSION["domain_name"] = $row['domain_name'];
  69. }
  70. else {
  71. if ($row['domain_name'] == $domain_array[0] || $row['domain_name'] == 'www.'.$domain_array[0]) {
  72. $_SESSION["domain_uuid"] = $row["domain_uuid"];
  73. $_SESSION["domain_name"] = $row['domain_name'];
  74. }
  75. $_SESSION['domains'][$row['domain_uuid']]['domain_uuid'] = $row['domain_uuid'];
  76. $_SESSION['domains'][$row['domain_uuid']]['domain_name'] = $row['domain_name'];
  77. }
  78. }
  79. unset($result, $prep_statement);
  80. //get the default settings
  81. $sql = "select * from v_default_settings ";
  82. $sql .= "where default_setting_enabled = 'true' ";
  83. $prep_statement = $db->prepare($sql);
  84. $prep_statement->execute();
  85. $result_default_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  86. //get the default recordings directory
  87. foreach($result_default_settings as $row) {
  88. $name = $row['default_setting_name'];
  89. $category = $row['default_setting_category'];
  90. $subcategory = $row['default_setting_subcategory'];
  91. if ($category == 'switch' && $subcategory == 'recordings' && $name == 'dir') {
  92. $switch_recordings_dir = $row['default_setting_value'];
  93. }
  94. }
  95. //loop through all domains
  96. $sql = "select * from v_domains ";
  97. $v_prep_statement = $db->prepare(check_sql($sql));
  98. $v_prep_statement->execute();
  99. $main_result = $v_prep_statement->fetchAll(PDO::FETCH_ASSOC);
  100. $domain_count = count($main_result);
  101. foreach ($main_result as &$row) {
  102. //get the values from database and set them as php variables
  103. $domain_uuid = $row["domain_uuid"];
  104. $domain_name = $row["domain_name"];
  105. //get the context
  106. if ($domain_count == 1) {
  107. $context = "default";
  108. }
  109. else {
  110. $context = $domain_name;
  111. }
  112. //show the domain when display_type is set to text
  113. if ($display_type == "text") {
  114. echo "\n";
  115. echo $domain_name;
  116. echo "\n";
  117. }
  118. //get the default settings - this needs to be done to reset the session values back to the defaults for each domain in the loop
  119. foreach($result_defaults_settings as $row) {
  120. $name = $row['default_setting_name'];
  121. $category = $row['default_setting_category'];
  122. $subcategory = $row['default_setting_subcategory'];
  123. if (strlen($subcategory) == 0) {
  124. $_SESSION[$category][$name] = $row['default_setting_value'];
  125. }
  126. else {
  127. $_SESSION[$category][$subcategory][$name] = $row['default_setting_value'];
  128. }
  129. }
  130. //get the domains settings
  131. $sql = "select * from v_domain_settings ";
  132. $sql .= "where domain_uuid = '".$domain_uuid."' ";
  133. $sql .= "and domain_setting_enabled = 'true' ";
  134. $prep_statement = $db->prepare($sql);
  135. $prep_statement->execute();
  136. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  137. foreach($result as $row) {
  138. $name = $row['domain_setting_name'];
  139. $category = $row['domain_setting_category'];
  140. $subcategory = $row['domain_setting_subcategory'];
  141. if (strlen($subcategory) == 0) {
  142. //$$category[$name] = $row['domain_setting_value'];
  143. $_SESSION[$category][$name] = $row['domain_setting_value'];
  144. }
  145. else {
  146. //$$category[$subcategory][$name] = $row['domain_setting_value'];
  147. $_SESSION[$category][$subcategory][$name] = $row['domain_setting_value'];
  148. }
  149. }
  150. //set the recordings directory
  151. if (strlen($switch_recordings_dir) > 1 && count($_SESSION["domains"]) > 1) {
  152. $_SESSION['switch']['recordings']['dir'] = $switch_recordings_dir."/".$domain_name;
  153. }
  154. //get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
  155. $default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
  156. foreach ($default_list as &$default_path) {
  157. include($default_path);
  158. }
  159. // synchronize the dialplan
  160. if (function_exists('save_dialplan_xml')) {
  161. save_dialplan_xml();
  162. }
  163. }
  164. unset ($v_prep_statement);
  165. //clear the session variables
  166. unset($_SESSION['domain']);
  167. unset($_SESSION['switch']);
  168. ?>