contact_time_edit.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. */
  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_time_edit') || permission_exists('contact_time_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_time_uuid = $_REQUEST["id"];
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. //get the contact uuid
  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. $time_start = $_POST["time_start"];
  50. $time_stop = $_POST["time_stop"];
  51. $time_description = $_POST["time_description"];
  52. }
  53. //process the form data
  54. if (!empty($_POST) && empty($_POST["persistformvar"])) {
  55. //set the uuid
  56. if ($action == "update") {
  57. $contact_time_uuid = $_POST["contact_time_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. if ($action == "add" && permission_exists('contact_time_add')) {
  96. $contact_time_uuid = uuid();
  97. $array['contact_times'][0]['contact_time_uuid'] = $contact_time_uuid;
  98. message::add($text['message-add']);
  99. }
  100. if ($action == "update" && permission_exists('contact_time_edit')) {
  101. $array['contact_times'][0]['contact_time_uuid'] = $contact_time_uuid;
  102. message::add($text['message-update']);
  103. }
  104. if (!empty($array)) {
  105. $array['contact_times'][0]['domain_uuid'] = $domain_uuid;
  106. $array['contact_times'][0]['contact_uuid'] = $contact_uuid;
  107. $array['contact_times'][0]['user_uuid'] = $_SESSION["user"]["user_uuid"];
  108. $array['contact_times'][0]['time_start'] = $time_start;
  109. $array['contact_times'][0]['time_stop'] = $time_stop;
  110. $array['contact_times'][0]['time_description'] = $time_description;
  111. $database = new database;
  112. $database->app_name = 'contacts';
  113. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  114. $database->save($array);
  115. unset($array);
  116. }
  117. header("Location: contact_edit.php?id=".$contact_uuid);
  118. exit;
  119. }
  120. }
  121. //pre-populate the form
  122. if (!empty($_GET) && empty($_POST["persistformvar"])) {
  123. $contact_time_uuid = $_GET["id"];
  124. $sql = "select ct.*, u.username ";
  125. $sql .= "from v_contact_times as ct, v_users as u ";
  126. $sql .= "where ct.user_uuid = u.user_uuid ";
  127. $sql .= "and ct.domain_uuid = :domain_uuid ";
  128. $sql .= "and ct.contact_uuid = :contact_uuid ";
  129. $sql .= "and ct.user_uuid = :user_uuid ";
  130. $sql .= "and contact_time_uuid = :contact_time_uuid ";
  131. $parameters['domain_uuid'] = $domain_uuid;
  132. $parameters['contact_uuid'] = $contact_uuid ?? '';
  133. $parameters['user_uuid'] = $_SESSION["user"]["user_uuid"];
  134. $parameters['contact_time_uuid'] = $contact_time_uuid;
  135. $database = new database;
  136. $row = $database->select($sql, $parameters, 'row');
  137. $time_start = $row["time_start"];
  138. $time_stop = $row["time_stop"];
  139. $time_description = $row["time_description"];
  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_time_edit'];
  148. }
  149. else if ($action == "add") {
  150. $document['title'] = $text['title-contact_time_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_time_edit']."</b>";
  159. }
  160. else if ($action == "add") {
  161. echo "<b>".$text['header-contact_time_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 "<div class='card'>\n";
  171. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  172. echo "<tr>\n";
  173. echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  174. echo " ".$text['label-time_start']."\n";
  175. echo "</td>\n";
  176. echo "<td width='70%' class='vtable' style='position: relative;' align='left'>\n";
  177. echo " <input class='formfld datetimesecpicker' data-toggle='datetimepicker' data-target='#time_start' type='text' name='time_start' id='time_start' style='min-width: 135px; width: 135px;' value='".$time_start."' onblur=\"$(this).datetimepicker('hide');\">\n";
  178. echo "</td>\n";
  179. echo "</tr>\n";
  180. echo "<tr>\n";
  181. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  182. echo " ".$text['label-time_stop']."\n";
  183. echo "</td>\n";
  184. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  185. echo " <input class='formfld datetimesecpicker' data-toggle='datetimepicker' data-target='#time_stop' type='text' name='time_stop' id='time_stop' style='min-width: 135px; width: 135px;' value='".$time_stop."' onblur=\"$(this).datetimepicker('hide');\">\n";
  186. echo "</td>\n";
  187. echo "</tr>\n";
  188. echo "<tr>\n";
  189. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  190. echo " ".$text['label-time_description']."\n";
  191. echo "</td>\n";
  192. echo "<td class='vtable' align='left'>\n";
  193. echo " <textarea class='formfld' type='text' name='time_description' id='time_description' style='width: 400px; height: 100px;'>".$time_description."</textarea>\n";
  194. echo "</td>\n";
  195. echo "</tr>\n";
  196. echo "</table>";
  197. echo "</div>\n";
  198. echo "<br><br>";
  199. echo "<input type='hidden' name='contact_uuid' value='".escape($contact_uuid)."'>\n";
  200. if ($action == "update") {
  201. echo "<input type='hidden' name='contact_time_uuid' value='".escape($contact_time_uuid)."'>\n";
  202. }
  203. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  204. echo "</form>";
  205. //include the footer
  206. require_once "resources/footer.php";
  207. ?>