contact_setting_edit.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. Luis Daniel Lucio Quiroz <[email protected]>
  21. */
  22. //includes
  23. require_once "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. //check permissions
  27. if (permission_exists('contact_setting_edit') || permission_exists('contact_setting_add')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //action add or update
  38. if (is_uuid($_REQUEST["id"])) {
  39. $action = "update";
  40. $contact_setting_uuid = $_REQUEST["id"];
  41. }
  42. else {
  43. $action = "add";
  44. }
  45. //get the contact uuid
  46. if (is_uuid($_GET["contact_uuid"])) {
  47. $contact_uuid = $_GET["contact_uuid"];
  48. }
  49. //set the session domain uuid as a variable
  50. $domain_uuid = $_SESSION['domain_uuid'];
  51. //get http post variables and set them to php variables
  52. if (count($_POST) > 0) {
  53. $contact_setting_category = strtolower($_POST["contact_setting_category"]);
  54. $contact_setting_subcategory = strtolower($_POST["contact_setting_subcategory"]);
  55. $contact_setting_name = strtolower($_POST["contact_setting_name"]);
  56. $contact_setting_value = $_POST["contact_setting_value"];
  57. $contact_setting_order = $_POST["contact_setting_order"];
  58. $contact_setting_enabled = strtolower($_POST["contact_setting_enabled"]);
  59. $contact_setting_description = $_POST["contact_setting_description"];
  60. }
  61. //process the form data
  62. if (is_array($_POST) && sizeof($_POST) != 0 && strlen($_POST["persistformvar"]) == 0) {
  63. //set the uuid
  64. if ($action == "update") {
  65. $contact_setting_uuid = $_POST["contact_setting_uuid"];
  66. }
  67. //validate the token
  68. $token = new token;
  69. if (!$token->validate($_SERVER['PHP_SELF'])) {
  70. message::add($text['message-invalid_token'],'negative');
  71. header('Location: contacts.php');
  72. exit;
  73. }
  74. //check for all required data
  75. $msg = '';
  76. //if (strlen($domain_setting_category) == 0) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
  77. //if (strlen($domain_setting_subcategory) == 0) { $msg .= $text['message-required'].$text['label-subcategory']."<br>\n"; }
  78. //if (strlen($domain_setting_name) == 0) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
  79. //if (strlen($domain_setting_value) == 0) { $msg .= $text['message-required'].$text['label-value']."<br>\n"; }
  80. //if (strlen($domain_setting_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
  81. //if (strlen($domain_setting_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
  82. //if (strlen($domain_setting_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  83. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  84. require_once "resources/header.php";
  85. require_once "resources/persist_form_var.php";
  86. echo "<div align='center'>\n";
  87. echo "<table><tr><td>\n";
  88. echo $msg."<br />";
  89. echo "</td></tr></table>\n";
  90. persistformvar($_POST);
  91. echo "</div>\n";
  92. require_once "resources/footer.php";
  93. return;
  94. }
  95. //add or update the database
  96. if ($_POST["persistformvar"] != "true") {
  97. //set the order
  98. $contact_setting_order = $contact_setting_order != '' ? $contact_setting_order : null;
  99. //update last modified
  100. $array['contacts'][0]['contact_uuid'] = $contact_uuid;
  101. $array['contacts'][0]['domain_uuid'] = $domain_uuid;
  102. $array['contacts'][0]['last_mod_date'] = 'now()';
  103. $array['contacts'][0]['last_mod_user'] = $_SESSION['username'];
  104. $p = new permissions;
  105. $p->add('contact_edit', 'temp');
  106. $database = new database;
  107. $database->app_name = 'contacts';
  108. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  109. $database->save($array);
  110. unset($array);
  111. $p->delete('contact_edit', 'temp');
  112. //add the setting
  113. if ($action == "add" && permission_exists('contact_setting_add')) {
  114. $contact_setting_uuid = uuid();
  115. $array['contact_settings'][0]['contact_setting_uuid'] = $contact_setting_uuid;
  116. message::add($text['message-add']);
  117. }
  118. //update the setting
  119. if ($action == "update" && permission_exists('contact_setting_edit')) {
  120. $array['contact_settings'][0]['contact_setting_uuid'] = $contact_setting_uuid;
  121. message::add($text['message-update']);
  122. }
  123. //execute
  124. if (is_array($array) && @sizeof($array) != 0) {
  125. $array['contact_settings'][0]['contact_uuid'] = $contact_uuid;
  126. $array['contact_settings'][0]['domain_uuid'] = $domain_uuid;
  127. $array['contact_settings'][0]['contact_setting_category'] = $contact_setting_category;
  128. $array['contact_settings'][0]['contact_setting_subcategory'] = $contact_setting_subcategory;
  129. $array['contact_settings'][0]['contact_setting_name'] = $contact_setting_name;
  130. $array['contact_settings'][0]['contact_setting_value'] = $contact_setting_value;
  131. $array['contact_settings'][0]['contact_setting_order'] = $contact_setting_order;
  132. $array['contact_settings'][0]['contact_setting_enabled'] = $contact_setting_enabled;
  133. $array['contact_settings'][0]['contact_setting_description'] = $contact_setting_description;
  134. $database = new database;
  135. $database->app_name = 'contacts';
  136. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  137. $database->save($array);
  138. unset($array);
  139. }
  140. //redirect the browser
  141. header("Location: contact_edit.php?id=".escape($contact_uuid));
  142. exit;
  143. }
  144. }
  145. //pre-populate the form
  146. if (is_array($_GET) && sizeof($_GET) != 0 && $_POST["persistformvar"] != "true") {
  147. $contact_setting_uuid = $_GET["id"];
  148. $sql = "select * from v_contact_settings ";
  149. $sql .= "where domain_uuid = :domain_uuid ";
  150. $sql .= "and contact_setting_uuid = :contact_setting_uuid ";
  151. $parameters['domain_uuid'] = $domain_uuid;
  152. $parameters['contact_setting_uuid'] = $contact_setting_uuid;
  153. $database = new database;
  154. $row = $database->select($sql, $parameters, 'row');
  155. if (is_array($row) && sizeof($row) != 0) {
  156. $contact_setting_category = escape($row["contact_setting_category"]);
  157. $contact_setting_subcategory = escape($row["contact_setting_subcategory"]);
  158. $contact_setting_name = escape($row["contact_setting_name"]);
  159. $contact_setting_value = escape($row["contact_setting_value"]);
  160. $contact_setting_order = escape($row["contact_setting_order"]);
  161. $contact_setting_enabled = escape($row["contact_setting_enabled"]);
  162. $contact_setting_description = escape($row["contact_setting_description"]);
  163. }
  164. unset($sql, $parameters, $row);
  165. }
  166. //create token
  167. $object = new token;
  168. $token = $object->create($_SERVER['PHP_SELF']);
  169. //show the header
  170. if ($action == "update") {
  171. $document['title'] = $text['title-contact_setting_edit'];
  172. }
  173. elseif ($action == "add") {
  174. $document['title'] = $text['title-contact_setting_add'];
  175. }
  176. require_once "resources/header.php";
  177. //show the content
  178. echo "<form method='post' name='frm'>\n";
  179. echo "<div class='action_bar' id='action_bar'>\n";
  180. echo " <div class='heading'>";
  181. if ($action == "update") {
  182. echo "<b>".$text['header-contact_setting_edit']."</b>";
  183. }
  184. else if ($action == "add") {
  185. echo "<b>".$text['header-contact_setting_add']."</b>";
  186. }
  187. echo " </div>\n";
  188. echo " <div class='actions'>\n";
  189. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'contact_edit.php?id='.urlencode($contact_uuid)]);
  190. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save']);
  191. echo " </div>\n";
  192. echo " <div style='clear: both;'></div>\n";
  193. echo "</div>\n";
  194. if ($action == "update") {
  195. echo $text['description-contact_setting_edit'];
  196. }
  197. if ($action == "add") {
  198. echo $text['description-contact_setting_add'];
  199. }
  200. echo "<br /><br />\n";
  201. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  202. echo "<tr>\n";
  203. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  204. echo " ".$text['label-contact_setting_category']."\n";
  205. echo "</td>\n";
  206. echo "<td class='vtable' align='left'>\n";
  207. echo " <input class='formfld' type='text' name='contact_setting_category' maxlength='255' value=\"".escape($contact_setting_category)."\" required='required'>\n";
  208. echo "<br />\n";
  209. echo $text['description-contact_setting_category']."\n";
  210. echo "</td>\n";
  211. echo "</tr>\n";
  212. echo "<tr>\n";
  213. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  214. echo " ".$text['label-contact_setting_subcategory']."\n";
  215. echo "</td>\n";
  216. echo "<td class='vtable' align='left'>\n";
  217. echo " <input class='formfld' type='text' name='contact_setting_subcategory' maxlength='255' value=\"".escape($contact_setting_subcategory)."\">\n";
  218. echo "<br />\n";
  219. echo $text['description-contact_setting_subcategory']."\n";
  220. echo "</td>\n";
  221. echo "</tr>\n";
  222. echo "<tr>\n";
  223. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  224. echo " ".$text['label-contact_setting_type']."\n";
  225. echo "</td>\n";
  226. echo "<td class='vtable' align='left'>\n";
  227. echo " <input class='formfld' type='text' name='contact_setting_name' maxlength='255' value=\"".escape($contact_setting_name)."\">\n";
  228. echo "<br />\n";
  229. echo $text['description-contact_setting_type']."\n";
  230. echo "</td>\n";
  231. echo "</tr>\n";
  232. echo "<tr>\n";
  233. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  234. echo " ".$text['label-contact_setting_value']."\n";
  235. echo "</td>\n";
  236. echo "<td class='vtable' align='left'>\n";
  237. echo " <input class='formfld' type='text' name='contact_setting_value' maxlength='255' value=\"".escape($contact_setting_value)."\">\n";
  238. echo "<br />\n";
  239. echo $text['description-contact_setting_value']."\n";
  240. echo "</td>\n";
  241. echo "</tr>\n";
  242. if ($contact_setting_name == "array") {
  243. echo "<tr>\n";
  244. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='30%'>\n";
  245. echo " ".$text['label-order']."\n";
  246. echo "</td>\n";
  247. echo "<td class='vtable' align='left'>\n";
  248. echo " <select name='contact_setting_order' class='formfld'>\n";
  249. $i=0;
  250. while($i<=999) {
  251. $selected = ($i == $contact_setting_order) ? "selected" : null;
  252. if (strlen($i) == 1) {
  253. echo " <option value='00$i' ".$selected.">00$i</option>\n";
  254. }
  255. if (strlen($i) == 2) {
  256. echo " <option value='0$i' ".$selected.">0$i</option>\n";
  257. }
  258. if (strlen($i) == 3) {
  259. echo " <option value='$i' ".$selected.">$i</option>\n";
  260. }
  261. $i++;
  262. }
  263. echo " </select>\n";
  264. echo " <br />\n";
  265. echo $text['description-order']."\n";
  266. echo "</td>\n";
  267. echo "</tr>\n";
  268. }
  269. echo "<tr>\n";
  270. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  271. echo " ".$text['label-enabled']."\n";
  272. echo "</td>\n";
  273. echo "<td class='vtable' align='left'>\n";
  274. echo " <select class='formfld' name='contact_setting_enabled'>\n";
  275. if ($contact_setting_enabled == "true") {
  276. echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
  277. }
  278. else {
  279. echo " <option value='true'>".$text['label-true']."</option>\n";
  280. }
  281. if ($contact_setting_enabled == "false") {
  282. echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
  283. }
  284. else {
  285. echo " <option value='false'>".$text['label-false']."</option>\n";
  286. }
  287. echo " </select>\n";
  288. echo "<br />\n";
  289. echo $text['description-enabled']."\n";
  290. echo "</td>\n";
  291. echo "</tr>\n";
  292. echo "<tr>\n";
  293. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  294. echo " ".$text['label-description']."\n";
  295. echo "</td>\n";
  296. echo "<td class='vtable' align='left'>\n";
  297. echo " <input class='formfld' type='text' name='contact_setting_description' maxlength='255' value=\"".escape($contact_setting_description)."\">\n";
  298. echo "<br />\n";
  299. echo $text['description-description']."\n";
  300. echo "</td>\n";
  301. echo "</tr>\n";
  302. echo "</table>";
  303. echo "<br><br>";
  304. echo "<input type='hidden' name='contact_uuid' value='".$contact_uuid."'>\n";
  305. if ($action == "update") {
  306. echo "<input type='hidden' name='contact_setting_uuid' value='".$contact_setting_uuid."'>\n";
  307. }
  308. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  309. echo "</form>";
  310. //include the footer
  311. require_once "resources/footer.php";
  312. ?>