contact_url_edit.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. if (permission_exists('contact_url_edit') || permission_exists('contact_url_add')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //action add or update
  36. if (is_uuid($_REQUEST["id"])) {
  37. $action = "update";
  38. $contact_url_uuid = $_REQUEST["id"];
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. //get the contact uuid
  44. if (is_uuid($_GET["contact_uuid"])) {
  45. $contact_uuid = $_GET["contact_uuid"];
  46. }
  47. //get http post variables and set them to php variables
  48. if (count($_POST) > 0) {
  49. $url_label = $_POST["url_label"];
  50. $url_label_custom = $_POST["url_label_custom"];
  51. $url_address = $_POST["url_address"];
  52. $url_primary = $_POST["url_primary"];
  53. $url_description = $_POST["url_description"];
  54. //use custom label if set
  55. $url_label = $url_label_custom != '' ? $url_label_custom : $url_label;
  56. }
  57. //process the form data
  58. if (is_array($_POST) && @sizeof($_POST) != 0 && strlen($_POST["persistformvar"]) == 0) {
  59. //set the uuid
  60. if ($action == "update") {
  61. $contact_url_uuid = $_POST["contact_url_uuid"];
  62. }
  63. //check for all required data
  64. $msg = '';
  65. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  66. require_once "resources/header.php";
  67. require_once "resources/persist_form_var.php";
  68. echo "<div align='center'>\n";
  69. echo "<table><tr><td>\n";
  70. echo $msg."<br />";
  71. echo "</td></tr></table>\n";
  72. persistformvar($_POST);
  73. echo "</div>\n";
  74. require_once "resources/footer.php";
  75. return;
  76. }
  77. //add or update the database
  78. if ($_POST["persistformvar"] != "true") {
  79. //update last modified
  80. $array['contacts'][0]['contact_uuid'] = $contact_uuid;
  81. $array['contacts'][0]['domain_uuid'] = $domain_uuid;
  82. $array['contacts'][0]['last_mod_date'] = 'now()';
  83. $array['contacts'][0]['last_mod_user'] = $_SESSION['username'];
  84. $p = new permissions;
  85. $p->add('contact_edit', 'temp');
  86. $database = new database;
  87. $database->app_name = 'contacts';
  88. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  89. $database->save($array);
  90. unset($array);
  91. $p->delete('contact_edit', 'temp');
  92. //if primary, unmark other primary numbers
  93. if ($url_primary) {
  94. $sql = "update v_contact_urls set url_primary = 0 ";
  95. $sql .= "where domain_uuid = :domain_uuid ";
  96. $sql .= "and contact_uuid = :contact_uuid ";
  97. $parameters['domain_uuid'] = $domain_uuid;
  98. $parameters['contact_uuid'] = $contact_uuid;
  99. $database = new database;
  100. $database->execute($sql, $parameters);
  101. unset($sql, $parameters);
  102. }
  103. if ($action == "add") {
  104. $contact_url_uuid = uuid();
  105. $array['contact_urls'][0]['contact_url_uuid'] = $contact_url_uuid;
  106. message::add($text['message-add']);
  107. }
  108. if ($action == "update") {
  109. $array['contact_urls'][0]['contact_url_uuid'] = $contact_url_uuid;
  110. message::add($text['message-update']);
  111. }
  112. if (is_array($array) && @sizeof($array) != 0) {
  113. $array['contact_urls'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
  114. $array['contact_urls'][0]['contact_uuid'] = $contact_uuid;
  115. $array['contact_urls'][0]['url_label'] = $url_label;
  116. $array['contact_urls'][0]['url_address'] = $url_address;
  117. $array['contact_urls'][0]['url_primary'] = $url_primary ? 1 : 0;
  118. $array['contact_urls'][0]['url_description'] = $url_description;
  119. $database = new database;
  120. $database->app_name = 'contacts';
  121. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  122. $database->save($array);
  123. unset($array);
  124. }
  125. header("Location: contact_edit.php?id=".$contact_uuid);
  126. exit;
  127. }
  128. }
  129. //pre-populate the form
  130. if (is_array($_GET) && @sizeof($_GET) != 0 && $_POST["persistformvar"] != "true") {
  131. $contact_url_uuid = $_GET["id"];
  132. $sql = "select * from v_contact_urls ";
  133. $sql .= "where domain_uuid = :domain_uuid ";
  134. $sql .= "and contact_url_uuid = :contact_url_uuid ";
  135. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  136. $parameters['contact_url_uuid'] = $contact_url_uuid;
  137. $database = new database;
  138. $row = $database->select($sql, $parameters, 'row');
  139. if (is_array($row) && @sizeof($row) != 0) {
  140. $url_label = $row["url_label"];
  141. $url_address = $row["url_address"];
  142. $url_primary = $row["url_primary"];
  143. $url_description = $row["url_description"];
  144. }
  145. unset($sql, $parameters, $row);
  146. }
  147. //show the header
  148. require_once "resources/header.php";
  149. if ($action == "update") {
  150. $document['title'] = $text['title-contact_url-edit'];
  151. }
  152. else if ($action == "add") {
  153. $document['title'] = $text['title-contact_url-add'];
  154. }
  155. //javascript to toggle input/select boxes
  156. echo "<script type='text/javascript'>";
  157. echo " function toggle_custom(field) {";
  158. echo " $('#'+field).toggle();";
  159. echo " document.getElementById(field).selectedIndex = 0;";
  160. echo " document.getElementById(field+'_custom').value = '';";
  161. echo " $('#'+field+'_custom').toggle();";
  162. echo " if ($('#'+field+'_custom').is(':visible')) { $('#'+field+'_custom').focus(); } else { $('#'+field).focus(); }";
  163. echo " }";
  164. echo "</script>";
  165. //show the content
  166. echo "<form method='post' name='frm' action=''>\n";
  167. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  168. echo "<tr>\n";
  169. echo "<td align='left' valign='top' nowrap='nowrap'><b>";
  170. if ($action == "update") {
  171. echo $text['header-contact_url-edit'];
  172. }
  173. else if ($action == "add") {
  174. echo $text['header-contact_url-add'];
  175. }
  176. echo "</b></td>\n";
  177. echo "<td align='right' valign='top'>";
  178. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='contact_edit.php?id=".escape($contact_uuid)."'\" value='".$text['button-back']."'>";
  179. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  180. echo "</td>\n";
  181. echo "</tr>\n";
  182. echo "</table>\n";
  183. if ($action == "update") {
  184. echo $text['description-contact_url-edit'];
  185. }
  186. else if ($action == "add") {
  187. echo $text['description-contact_url-add'];
  188. }
  189. echo "<br /><br />\n";
  190. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  191. echo "<tr>\n";
  192. echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  193. echo " ".$text['label-url_label']."\n";
  194. echo "</td>\n";
  195. echo "<td width='70%' class='vtable' align='left'>\n";
  196. if (is_array($_SESSION["contact"]["url_label"])) {
  197. sort($_SESSION["contact"]["url_label"]);
  198. foreach($_SESSION["contact"]["url_label"] as $row) {
  199. $url_label_options[] = "<option value='".$row."' ".(($row == $url_label) ? "selected='selected'" : null).">".$row."</option>";
  200. }
  201. $url_label_found = (in_array($url_label, $_SESSION["contact"]["url_label"])) ? true : false;
  202. }
  203. else {
  204. $selected[$url_label] = "selected";
  205. $default_labels[] = $text['option-work'];
  206. $default_labels[] = $text['option-personal'];
  207. $default_labels[] = $text['option-other'];
  208. foreach ($default_labels as $default_label) {
  209. $url_label_options[] = "<option value='".$default_label."' ".$selected[$default_label].">".$default_label."</option>";
  210. }
  211. $url_label_found = (in_array($url_label, $default_labels)) ? true : false;
  212. }
  213. echo " <select class='formfld' ".((!$url_label_found && $url_label != '') ? "style='display: none;'" : null)." name='url_label' id='url_label' onchange=\"getElementById('url_label_custom').value='';\">\n";
  214. echo " <option value=''></option>\n";
  215. echo (is_array($url_label_options)) ? implode("\n", $url_label_options) : null;
  216. echo " </select>\n";
  217. echo " <input type='text' class='formfld' ".(($url_label_found || $url_label == '') ? "style='display: none;'" : null)." name='url_label_custom' id='url_label_custom' value=\"".((!$url_label_found) ? htmlentities($url_label) : null)."\">\n";
  218. echo " <input type='button' id='btn_toggle_label' class='btn' alt='".$text['button-back']."' value='&#9665;' onclick=\"toggle_custom('url_label');\">\n";
  219. echo "<br />\n";
  220. echo $text['description-url_label']."\n";
  221. echo "</td>\n";
  222. echo "</tr>\n";
  223. echo "<tr>\n";
  224. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  225. echo " ".$text['label-url_address']."\n";
  226. echo "</td>\n";
  227. echo "<td class='vtable' align='left'>\n";
  228. echo " <input class='formfld' type='url' name='url_address' maxlength='255' value=\"".escape($url_address)."\" placeholder='http://...'>\n";
  229. echo "<br />\n";
  230. echo $text['description-url_address']."\n";
  231. echo "</td>\n";
  232. echo "</tr>\n";
  233. echo "<tr>\n";
  234. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  235. echo " ".$text['label-primary']."\n";
  236. echo "</td>\n";
  237. echo "<td class='vtable' align='left'>\n";
  238. echo " <select class='formfld' name='url_primary' id='url_primary'>\n";
  239. echo " <option value='0'>".$text['option-false']."</option>\n";
  240. echo " <option value='1' ".(($url_primary) ? "selected" : null).">".$text['option-true']."</option>\n";
  241. echo " </select>\n";
  242. echo "<br />\n";
  243. echo $text['description-url_primary']."\n";
  244. echo "</td>\n";
  245. echo "</tr>\n";
  246. echo "<tr>\n";
  247. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  248. echo " ".$text['label-url_description']."\n";
  249. echo "</td>\n";
  250. echo "<td class='vtable' align='left'>\n";
  251. echo " <input class='formfld' type='text' name='url_description' maxlength='255' value=\"".escape($url_description)."\">\n";
  252. echo "<br />\n";
  253. echo $text['description-url_description']."\n";
  254. echo "</td>\n";
  255. echo "</tr>\n";
  256. echo " <tr>\n";
  257. echo " <td colspan='2' align='right'>\n";
  258. echo " <br>\n";
  259. echo " <input type='hidden' name='contact_uuid' value='".escape($contact_uuid)."'>\n";
  260. if ($action == "update") {
  261. echo " <input type='hidden' name='contact_url_uuid' value='".escape($contact_url_uuid)."'>\n";
  262. }
  263. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  264. echo " </td>\n";
  265. echo " </tr>";
  266. echo "</table>";
  267. echo "<br><br>";
  268. echo "</form>";
  269. //include the footer
  270. require_once "resources/footer.php";
  271. ?>