contact_note_edit.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (permission_exists('contact_note_edit') || permission_exists('contact_note_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 (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
  37. $action = "update";
  38. $contact_note_uuid = $_REQUEST["id"];
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. //get the primary id for the contact
  44. if (!empty($_GET["contact_uuid"]) && 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 (!empty($_POST)) {
  49. $contact_note = $_POST["contact_note"];
  50. $last_mod_date = $_POST["last_mod_date"] ?? null;
  51. $last_mod_user = $_POST["last_mod_user"] ?? null;
  52. }
  53. //process the form data
  54. if (!empty($_POST) && empty($_POST["persistformvar"])) {
  55. //get the primary id for the contact note
  56. if ($action == "update") {
  57. $contact_note_uuid = $_POST["contact_note_uuid"];
  58. }
  59. //validate the token
  60. $token = new token;
  61. if (!$token->validate($_SERVER['PHP_SELF'])) {
  62. message::add($text['message-invalid_token'],'negative');
  63. header('Location: contacts.php');
  64. exit;
  65. }
  66. //check for all required data
  67. $msg = '';
  68. if (!empty($msg) && empty($_POST["persistformvar"])) {
  69. require_once "resources/header.php";
  70. require_once "resources/persist_form_var.php";
  71. echo "<div align='center'>\n";
  72. echo "<table><tr><td>\n";
  73. echo $msg."<br />";
  74. echo "</td></tr></table>\n";
  75. persistformvar($_POST);
  76. echo "</div>\n";
  77. require_once "resources/footer.php";
  78. return;
  79. }
  80. //add or update the database
  81. if (empty($_POST["persistformvar"])) {
  82. //update last modified
  83. $array['contacts'][0]['contact_uuid'] = $contact_uuid;
  84. $array['contacts'][0]['domain_uuid'] = $domain_uuid;
  85. $array['contacts'][0]['last_mod_date'] = 'now()';
  86. $array['contacts'][0]['last_mod_user'] = $_SESSION['username'];
  87. $p = permissions::new();
  88. $p->add('contact_edit', 'temp');
  89. $database = new database;
  90. $database->app_name = 'contacts';
  91. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  92. $database->save($array);
  93. unset($array);
  94. $p->delete('contact_edit', 'temp');
  95. //add the note
  96. if ($action == "add" && permission_exists('contact_note_add')) {
  97. $contact_note_uuid = uuid();
  98. $array['contact_notes'][0]['contact_note_uuid'] = $contact_note_uuid;
  99. message::add($text['message-add']);
  100. }
  101. //update the note
  102. if ($action == "update" && permission_exists('contact_note_edit')) {
  103. $array['contact_notes'][0]['contact_note_uuid'] = $contact_note_uuid;
  104. message::add($text['message-update']);
  105. }
  106. //execute
  107. if (!empty($array)) {
  108. $array['contact_notes'][0]['contact_uuid'] = $contact_uuid;
  109. $array['contact_notes'][0]['domain_uuid'] = $domain_uuid;
  110. $array['contact_notes'][0]['contact_note'] = $contact_note;
  111. $array['contact_notes'][0]['last_mod_date'] = 'now()';
  112. $array['contact_notes'][0]['last_mod_user'] = $_SESSION['username'];
  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. }
  119. //redirect
  120. header("Location: contact_edit.php?id=".escape($contact_uuid));
  121. exit;
  122. }
  123. }
  124. //pre-populate the form
  125. if (!empty($_GET) && empty($_POST["persistformvar"])) {
  126. $contact_note_uuid = $_GET["id"] ?? '';
  127. $sql = "select * from v_contact_notes ";
  128. $sql .= "where domain_uuid = :domain_uuid ";
  129. $sql .= "and contact_note_uuid = :contact_note_uuid ";
  130. $parameters['domain_uuid'] = $domain_uuid;
  131. $parameters['contact_note_uuid'] = $contact_note_uuid;
  132. $database = new database;
  133. $row = $database->select($sql, $parameters, 'row');
  134. if (!empty($row)) {
  135. $contact_note = $row["contact_note"];
  136. $last_mod_date = $row["last_mod_date"];
  137. $last_mod_user = $row["last_mod_user"];
  138. }
  139. unset($sql, $parameters, $row);
  140. }
  141. //create token
  142. $object = new token;
  143. $token = $object->create($_SERVER['PHP_SELF']);
  144. //show the header
  145. if ($action == "update") {
  146. $document['title'] = $text['title-contact_notes-edit'];
  147. }
  148. else if ($action == "add") {
  149. $document['title'] = $text['title-contact_notes-add'];
  150. }
  151. require_once "resources/header.php";
  152. //show the content
  153. echo "<form method='post' name='frm'>\n";
  154. echo "<div class='action_bar' id='action_bar'>\n";
  155. echo " <div class='heading'>";
  156. if ($action == "update") {
  157. echo "<b>".$text['header-contact_notes-edit']."</b>";
  158. }
  159. else if ($action == "add") {
  160. echo "<b>".$text['header-contact_notes-add']."</b>";
  161. }
  162. echo " </div>\n";
  163. echo " <div class='actions'>\n";
  164. 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)]);
  165. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save']);
  166. echo " </div>\n";
  167. echo " <div style='clear: both;'></div>\n";
  168. echo "</div>\n";
  169. echo "<div class='card'>\n";
  170. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  171. echo "<tr>\n";
  172. echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  173. echo " ".$text['label-contact_note']."\n";
  174. echo "</td>\n";
  175. echo "<td width='70%' class='vtable' align='left'>\n";
  176. echo " <textarea class='formfld' name='contact_note' style='min-width: 100%; height: 400px;'>".escape($contact_note ?? '')."</textarea>\n";
  177. echo "</td>\n";
  178. echo "</tr>\n";
  179. echo "</table>";
  180. echo "</div>\n";
  181. echo "<br><br>";
  182. echo "<input type='hidden' name='contact_uuid' value='".escape($contact_uuid)."'>\n";
  183. if ($action == "update") {
  184. echo "<input type='hidden' name='contact_note_uuid' value='".escape($contact_note_uuid)."'>\n";
  185. }
  186. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  187. echo "</form>";
  188. //include the footer
  189. require_once "resources/footer.php";
  190. ?>