schema_name_value_edit.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 (permission_exists('schema_edit')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //add multi-lingual support
  32. $language = new text;
  33. $text = $language->get();
  34. //action add or update
  35. if (isset($_REQUEST["id"])) {
  36. $action = "update";
  37. $schema_name_value_uuid = check_str($_REQUEST["id"]);
  38. }
  39. else {
  40. $action = "add";
  41. }
  42. if (strlen($_GET["schema_field_uuid"]) > 0) {
  43. $schema_field_uuid = check_str($_GET["schema_field_uuid"]);
  44. }
  45. //POST to PHP variables
  46. if (count($_POST)>0) {
  47. //$domain_uuid = check_str($_POST["domain_uuid"]);
  48. $data_types_name = check_str($_POST["data_types_name"]);
  49. $data_types_value = check_str($_POST["data_types_value"]);
  50. $schema_uuid = $_REQUEST["schema_uuid"];
  51. $schema_field_uuid = $_REQUEST["schema_field_uuid"];
  52. }
  53. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  54. $msg = '';
  55. if ($action == "update") {
  56. $schema_name_value_uuid = check_str($_POST["schema_name_value_uuid"]);
  57. }
  58. //check for all required data
  59. if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid<br>\n"; }
  60. if (strlen($schema_uuid) == 0) { $msg .= $text['message-required']."schema_uuid<br>\n"; }
  61. if (strlen($schema_field_uuid) == 0) { $msg .= $text['message-required']."schema_field_uuid<br>\n"; }
  62. if (strlen($data_types_name) == 0) { $msg .= $text['message-required'].$text['label-name_value_name']."<br>\n"; }
  63. if (strlen($data_types_value) == 0) { $msg .= $text['message-required'].$text['label-name_value_value']."<br>\n"; }
  64. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  65. require_once "resources/header.php";
  66. require_once "resources/persist_form_var.php";
  67. echo "<div align='center'>\n";
  68. echo "<table><tr><td>\n";
  69. echo $msg."<br />";
  70. echo "</td></tr></table>\n";
  71. persistformvar($_POST);
  72. echo "</div>\n";
  73. require_once "resources/footer.php";
  74. return;
  75. }
  76. //add or update the database
  77. if ($_POST["persistformvar"] != "true") {
  78. if ($action == "add") {
  79. $sql = "insert into v_schema_name_values ";
  80. $sql .= "(";
  81. $sql .= "schema_name_value_uuid, ";
  82. $sql .= "domain_uuid, ";
  83. $sql .= "schema_uuid, ";
  84. $sql .= "schema_field_uuid, ";
  85. $sql .= "data_types_name, ";
  86. $sql .= "data_types_value ";
  87. $sql .= ") ";
  88. $sql .= "values ";
  89. $sql .= "(";
  90. $sql .= "'".uuid()."', ";
  91. $sql .= "'".$_SESSION['domain_uuid']."', ";
  92. $sql .= "'$schema_uuid', ";
  93. $sql .= "'$schema_field_uuid', ";
  94. $sql .= "'$data_types_name', ";
  95. $sql .= "'$data_types_value' ";
  96. $sql .= ")";
  97. $db->exec(check_sql($sql));
  98. unset($sql);
  99. $_SESSION["message"] = $text['message-add'];
  100. header("Location: schema_field_edit.php?schema_uuid=".$schema_uuid."&id=".$schema_field_uuid);
  101. return;
  102. } //if ($action == "add")
  103. if ($action == "update") {
  104. $sql = "update v_schema_name_values set ";
  105. $sql .= "data_types_name = '$data_types_name', ";
  106. $sql .= "data_types_value = '$data_types_value' ";
  107. $sql .= "where domain_uuid = '$domain_uuid' ";
  108. $sql .= "and schema_uuid = '$schema_uuid' ";
  109. $sql .= "and schema_field_uuid = '$schema_field_uuid' ";
  110. $sql .= "and schema_name_value_uuid = '$schema_name_value_uuid' ";
  111. $db->exec(check_sql($sql));
  112. unset($sql);
  113. $_SESSION["message"] = $text['message-update'];
  114. header("Location: schema_field_edit.php?schema_uuid=".$schema_uuid."&id=".$schema_field_uuid);
  115. return;
  116. } //if ($action == "update")
  117. } //if ($_POST["persistformvar"] != "true")
  118. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  119. //pre-populate the form
  120. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  121. $schema_uuid = $_GET["schema_uuid"];
  122. $schema_field_uuid = $_GET["schema_field_uuid"];
  123. $schema_name_value_uuid = $_GET["id"];
  124. $sql = "select * from v_schema_name_values ";
  125. $sql .= "where domain_uuid = '$domain_uuid' ";
  126. //$sql .= "and schema_uuid = '$schema_uuid' ";
  127. $sql .= "and schema_field_uuid = '$schema_field_uuid' ";
  128. $sql .= "and schema_name_value_uuid = '$schema_name_value_uuid' ";
  129. $prep_statement = $db->prepare(check_sql($sql));
  130. $prep_statement->execute();
  131. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  132. foreach ($result as &$row) {
  133. $data_types_name = $row["data_types_name"];
  134. $data_types_value = $row["data_types_value"];
  135. break; //limit to 1 row
  136. }
  137. unset ($prep_statement);
  138. }
  139. //show the header
  140. require_once "resources/header.php";
  141. $document['title'] = $text['title-name_value'];
  142. //show the content
  143. echo "<form method='post' name='frm' action=''>\n";
  144. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  145. echo "<tr>\n";
  146. if ($action == "add") {
  147. echo "<td align='left' width='30%' nowrap=\"nowrap\"><b>".$text['header-name_value']." ".$text['button-add']."</b></td>\n";
  148. }
  149. if ($action == "update") {
  150. echo "<td align='left' width='30%' nowrap=\"nowrap\"><b>".$text['header-name_value']." ".$text['button-edit']."</b></td>\n";
  151. }
  152. echo "<td width='70%' align=\"right\">";
  153. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"history.go(-1);return true;\" value='".$text['button-back']."'>";
  154. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  155. echo "</td>\n";
  156. echo "</tr>\n";
  157. echo "<tr>\n";
  158. echo "<td align=\"left\" colspan='2'>\n";
  159. echo $text['description-name_value']."<br /><br />\n";
  160. echo "</td>\n";
  161. echo "</tr>\n";
  162. echo "<tr>\n";
  163. echo "<td class='vncellreq' valign='top' align='left' nowrap=\"nowrap\">\n";
  164. echo " ".$text['label-name_value_name']."\n";
  165. echo "</td>\n";
  166. echo "<td class='vtable' align='left'>\n";
  167. echo " <input class='formfld' type='text' name='data_types_name' maxlength='255' value=\"$data_types_name\">\n";
  168. echo "<br />\n";
  169. echo $text['description-name_value_name']."\n";
  170. echo "</td>\n";
  171. echo "</tr>\n";
  172. echo "<tr>\n";
  173. echo "<td class='vncellreq' valign='top' align='left' nowrap=\"nowrap\">\n";
  174. echo " ".$text['label-name_value_value']."\n";
  175. echo "</td>\n";
  176. echo "<td class='vtable' align='left'>\n";
  177. echo " <input class='formfld' type='text' name='data_types_value' maxlength='255' value=\"$data_types_value\">\n";
  178. echo "<br />\n";
  179. echo $text['description-name_value_value']."\n";
  180. echo "</td>\n";
  181. echo "</tr>\n";
  182. echo " <tr>\n";
  183. echo " <td colspan='2' align='right'>\n";
  184. echo " <input type='hidden' name='schema_uuid' value='$schema_uuid'>\n";
  185. echo " <input type='hidden' name='schema_field_uuid' value='$schema_field_uuid'>\n";
  186. if ($action == "update") {
  187. echo " <input type='hidden' name='schema_name_value_uuid' value='$schema_name_value_uuid'>\n";
  188. }
  189. echo " <br>";
  190. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  191. echo " </td>\n";
  192. echo " </tr>";
  193. echo "</table>";
  194. echo "<br><br>";
  195. echo "</form>";
  196. require_once "resources/footer.php";
  197. ?>