servers_edit.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. require_once "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (if_group("admin") || if_group("superadmin")) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //action add or update
  32. if (isset($_REQUEST["id"])) {
  33. $action = "update";
  34. $server_uuid = check_str($_REQUEST["id"]);
  35. }
  36. else {
  37. $action = "add";
  38. }
  39. //get http post variables and set them to php variables
  40. if (count($_POST)>0) {
  41. $server_name = check_str($_POST["server_name"]);
  42. $server_description = check_str($_POST["server_description"]);
  43. }
  44. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  45. $msg = '';
  46. if ($action == "update") {
  47. $server_uuid = check_str($_POST["server_uuid"]);
  48. }
  49. //check for all required data
  50. //if (strlen($server_name) == 0) { $msg .= "Please provide: Server Name<br>\n"; }
  51. //if (strlen($server_description) == 0) { $msg .= "Please provide: Description<br>\n"; }
  52. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  53. require_once "resources/header.php";
  54. require_once "resources/persist_form_var.php";
  55. echo "<div align='center'>\n";
  56. echo "<table><tr><td>\n";
  57. echo $msg."<br />";
  58. echo "</td></tr></table>\n";
  59. persistformvar($_POST);
  60. echo "</div>\n";
  61. require_once "resources/footer.php";
  62. return;
  63. }
  64. //add or update the database
  65. if ($_POST["persistformvar"] != "true") {
  66. if ($action == "add") {
  67. $sql = "insert into v_servers ";
  68. $sql .= "(";
  69. $sql .= "domain_uuid, ";
  70. $sql .= "server_name, ";
  71. $sql .= "server_description ";
  72. $sql .= ")";
  73. $sql .= "values ";
  74. $sql .= "(";
  75. $sql .= "'$domain_uuid', ";
  76. $sql .= "'$server_name', ";
  77. $sql .= "'$server_description' ";
  78. $sql .= ")";
  79. $db->exec(check_sql($sql));
  80. unset($sql);
  81. require_once "resources/header.php";
  82. echo "<meta http-equiv=\"refresh\" content=\"2;url=servers.php\">\n";
  83. echo "<div align='center'>\n";
  84. echo "Add Complete\n";
  85. echo "</div>\n";
  86. require_once "resources/footer.php";
  87. return;
  88. } //if ($action == "add")
  89. if ($action == "update") {
  90. $sql = "update v_servers set ";
  91. $sql .= "server_name = '$server_name', ";
  92. $sql .= "server_description = '$server_description' ";
  93. $sql .= "where domain_uuid = '$domain_uuid' ";
  94. $sql .= "and server_uuid = '$server_uuid'";
  95. $db->exec(check_sql($sql));
  96. unset($sql);
  97. require_once "resources/header.php";
  98. echo "<meta http-equiv=\"refresh\" content=\"2;url=servers.php\">\n";
  99. echo "<div align='center'>\n";
  100. echo "Update Complete\n";
  101. echo "</div>\n";
  102. require_once "resources/footer.php";
  103. return;
  104. } //if ($action == "update")
  105. } //if ($_POST["persistformvar"] != "true")
  106. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  107. //pre-populate the form
  108. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  109. $server_uuid = $_GET["id"];
  110. $sql = "select * from v_servers ";
  111. $sql .= "where domain_uuid = '$domain_uuid' ";
  112. $sql .= "and server_uuid = '$server_uuid' ";
  113. $prep_statement = $db->prepare(check_sql($sql));
  114. $prep_statement->execute();
  115. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  116. foreach ($result as &$row) {
  117. $server_name = $row["server_name"];
  118. $server_description = $row["server_description"];
  119. break; //limit to 1 row
  120. }
  121. unset ($prep_statement);
  122. }
  123. //show the header
  124. require_once "resources/header.php";
  125. //show the content
  126. echo "<div align='center'>";
  127. echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
  128. echo "<tr class='border'>\n";
  129. echo " <td align=\"left\">\n";
  130. echo " <br>";
  131. echo "<form method='post' name='frm' action=''>\n";
  132. echo "<div align='center'>\n";
  133. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  134. echo "<tr>\n";
  135. if ($action == "add") {
  136. echo "<td align='left' width='30%' nowrap='nowrap'><b>Server Add</b></td>\n";
  137. }
  138. if ($action == "update") {
  139. echo "<td align='left' width='30%' nowrap='nowrap'><b>Server Edit</b></td>\n";
  140. }
  141. echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='back' onclick=\"window.location='servers.php'\" value='Back'></td>\n";
  142. echo "</tr>\n";
  143. echo "<tr>\n";
  144. echo "<td colspan='2'>\n";
  145. echo "Servers Settings<br /><br />\n";
  146. echo "</td>\n";
  147. echo "</tr>\n";
  148. echo "<tr>\n";
  149. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  150. echo " Server Name:\n";
  151. echo "</td>\n";
  152. echo "<td class='vtable' align='left'>\n";
  153. echo " <input class='formfld' type='text' name='server_name' maxlength='255' value=\"$server_name\">\n";
  154. echo "<br />\n";
  155. echo "Enter the name.\n";
  156. echo "</td>\n";
  157. echo "</tr>\n";
  158. echo "<tr>\n";
  159. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  160. echo " Description:\n";
  161. echo "</td>\n";
  162. echo "<td class='vtable' align='left'>\n";
  163. echo " <input class='formfld' type='text' name='server_description' maxlength='255' value=\"$server_description\">\n";
  164. echo "<br />\n";
  165. echo "Enter the description.\n";
  166. echo "</td>\n";
  167. echo "</tr>\n";
  168. echo " <tr>\n";
  169. echo " <td colspan='2' align='right'>\n";
  170. if ($action == "update") {
  171. echo " <input type='hidden' name='server_uuid' value='$server_uuid'>\n";
  172. }
  173. echo " <input type='submit' name='submit' class='btn' value='Save'>\n";
  174. echo " </td>\n";
  175. echo " </tr>";
  176. echo "</table>";
  177. echo "</form>";
  178. if ($action == "update") {
  179. require "server_settings.php";
  180. }
  181. echo " </td>";
  182. echo " </tr>";
  183. echo "</table>";
  184. echo "</div>";
  185. //include the footer
  186. require_once "resources/footer.php";
  187. ?>