contact_url_edit.php 11 KB

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