mobile_twinning_edit.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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-2016
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[email protected]>
  20. Mark J Crane <[email protected]>
  21. */
  22. //includes
  23. require_once dirname(__DIR__, 2) . "/resources/require.php";
  24. require_once "resources/pdo.php";
  25. require_once "resources/check_auth.php";
  26. require_once "resources/paging.php";
  27. //check permissions
  28. if (permission_exists('mobile_twinning_view')) {
  29. //access granted
  30. }
  31. else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //get the https values and set as variables
  39. $extension_uuid = check_str($_GET["extid"]);
  40. $mobile_twinning_uuid = check_str($_GET["id"]);
  41. //action add or update
  42. if (isset($_REQUEST["id"])) {
  43. $action = "update";
  44. $mobile_twinning_uuid = check_str($_GET["id"]);
  45. }
  46. else {
  47. $action = "add";
  48. }
  49. //get the http values and set them as php variables
  50. if (count($_POST) > 0 && $_POST["persistform"] != "1") {
  51. $mobile_twinning_number = check_str($_POST["mobile_twinning_number"]);
  52. if ($action == "update") {
  53. $mobile_twinning_uuid = check_str($_POST["mobile_twinning_uuid"]);
  54. $extension_uuid = check_str($_POST["extension_uuid"]);
  55. $extension = check_str($_POST["extension"]);
  56. }
  57. }
  58. //process the user data and save it to the database
  59. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  60. //check for duplicate mobile in database
  61. $database = new database;
  62. $database->table = "v_mobile_twinnings";
  63. $where[0]["name"] = "mobile_twinning_number";
  64. $where[0]["operator"] = "=";
  65. $where[0]["value"] = "$mobile_twinning_number";
  66. $where[1]["name"] = "mobile_twinning_uuid";
  67. $where[1]["operator"] = "!=";
  68. $where[1]["value"] = "$mobile_twinning_uuid";
  69. $database->where = $where;
  70. $result = $database->count();
  71. if ($result > 0) {
  72. $msg .= $text['message-warning'].$text['message-duplicate_mobile_twinning_number']."<br>\n";
  73. }
  74. unset($result,$database);
  75. //check for a valid 10 digit mobile number
  76. if (strlen($mobile_twinning_number) != 10) {
  77. if (strlen($mobile_twinning_number) != 0) {
  78. $msg .= $text['message-warning'].$text['message-invalid_mobile_twinning_number']."<br>\n";
  79. }
  80. }
  81. //display error msg if error found
  82. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  83. require_once "resources/header.php";
  84. require_once "resources/persist_form_var.php";
  85. echo "<div align='center'>\n";
  86. echo "<table><tr><td>\n";
  87. echo $msg."<br />";
  88. echo "</td></tr></table>\n";
  89. persistformvar($_POST);
  90. echo "</div>\n";
  91. require_once "resources/footer.php";
  92. return;
  93. }
  94. //insert into v_mobile_twinnings
  95. $i = 0;
  96. $array["mobile_twinnings"][$i]["domain_uuid"] = $_SESSION['domain_uuid'];;
  97. $array["mobile_twinnings"][$i]["mobile_twinning_uuid"] = $mobile_twinning_uuid;
  98. $array["mobile_twinnings"][$i]["extension_uuid"] = $extension_uuid;
  99. $array["mobile_twinnings"][$i]["mobile_twinning_number"] = $mobile_twinning_number;
  100. //save to the datbase
  101. $database = new database;
  102. $database->app_name = 'mobile_twinnings';
  103. $database->app_uuid = null;
  104. $database->save($array);
  105. $message = $database->message;
  106. //echo "<pre>".print_r($message, true)."<pre>\n";
  107. //exit;
  108. }
  109. //pre-populate the form
  110. if (is_array($_GET) && $_POST["persistformvar"] != "true") {
  111. $sql = "SELECT e.extension, m.mobile_twinning_number, e.description, m.mobile_twinning_uuid, e.extension_uuid \n";
  112. $sql .= "FROM v_extensions AS e \n ";
  113. $sql .= "LEFT OUTER JOIN v_mobile_twinnings AS m ON m.extension_uuid = e.extension_uuid \n";
  114. $sql .= "WHERE e.domain_uuid = '$domain_uuid' ";
  115. if ($mobile_twinning_uuid != null) {
  116. $sql .= "AND m.mobile_twinning_uuid = '$mobile_twinning_uuid' \n";
  117. }
  118. $sql .= "AND e.extension_uuid = '$extension_uuid' ";
  119. $prep_statement = $db->prepare(check_sql($sql));
  120. $prep_statement->execute();
  121. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  122. unset ($prep_statement, $sql);
  123. //set the variables
  124. foreach ($result as $row) {
  125. $mobile_twinning_number = $row['mobile_twinning_number'];
  126. $mobile_twinning_uuid = $row['mobile_twinning_uuid'];
  127. $extension = $row['extension'];
  128. $description = $row['description'];
  129. $extension_uuid = $row['extension_uuid'];
  130. }
  131. if (strlen($mobile_twinning_uuid) == 0) {
  132. $mobile_twinning_uuid = uuid();
  133. }
  134. }
  135. //show the header
  136. require_once "resources/header.php";
  137. //show the content
  138. echo "<form name='frm' id='frm' method='post' action=''>\n";
  139. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  140. echo "<input type='hidden' name='extension_uuid' id='extension_uuid' value='".$extension_uuid."'>\n";
  141. echo "<input type='hidden' name='mobile_twinning_uuid' id='mobile_twinning_uuid' value='".$mobile_twinning_uuid."'>\n";
  142. echo "<input type='hidden' name='extension' id='mobile_twinning_uuid' value='".$extension."'>\n";
  143. echo "<tr>\n";
  144. echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-mobile_twinning']."</b><br><br></td>\n";
  145. echo "<td width='70%' align='right' valign='top'>\n";
  146. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='mobile_twinning.php'\" value='".$text['button-back']."'>";
  147. echo " <input type='submit' class='btn' value='".$text['button-save']."'>";
  148. echo "</td>\n";
  149. echo "</tr>\n";
  150. echo "</table>\n";
  151. echo "<div class='card'>\n";
  152. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  153. //Extension
  154. echo "<tr>\n";
  155. echo "<td class='vncellreq' width='30%' valign='top' align='left' nowrap='nowrap'>\n";
  156. echo " ".$text['label-extension']."\n";
  157. echo "</td>\n";
  158. echo "<td class='vtable' align='left' padding: 5px; >\n";
  159. echo $extension."\n";
  160. echo "</td>\n";
  161. echo "</tr>\n";
  162. echo "<tr>\n";
  163. echo "<td width=\"30%\" class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  164. echo " ".$text['label-mobile_twinning_number']."\n";
  165. echo "</td>\n";
  166. echo "<td class='vtable' align='left'>\n";
  167. echo " <input class='formfld' type='text' name='mobile_twinning_number' maxlength='255' value=\"".escape($mobile_twinning_number)."\">\n";
  168. echo "<br />\n";
  169. echo $text['description-mobile_twinning_number']."\n";
  170. echo "</td>\n";
  171. echo "</tr>\n";
  172. echo "</table>";
  173. echo "</div>";
  174. echo "</form>";
  175. echo "<br /><br />";
  176. //include the footer
  177. require_once "resources/footer.php";
  178. ?>