contact_setting_edit.php 13 KB

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