contact_note_edit.php 6.9 KB

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