contact_timer.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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-2015
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. require_once "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (!permission_exists('contact_time_add')) { echo "access denied"; exit; }
  25. //add multi-lingual support
  26. $language = new text;
  27. $text = $language->get();
  28. //get contact uuid
  29. $domain_uuid = $_REQUEST['domain_uuid'];
  30. $contact_uuid = $_REQUEST['contact_uuid'];
  31. //get posted variables & set time status
  32. if (is_array($_POST) && @sizeof($_POST) != 0) {
  33. $contact_time_uuid = $_POST['contact_time_uuid'];
  34. $contact_uuid = $_POST['contact_uuid'];
  35. $time_action = $_POST['time_action'];
  36. $time_description = $_POST['time_description'];
  37. if ($time_description == 'Description...') { unset($time_description); }
  38. if ($time_action == 'start') {
  39. $contact_time_uuid = uuid();
  40. $array['contact_times'][0]['domain_uuid'] = $domain_uuid;
  41. $array['contact_times'][0]['contact_time_uuid'] = $contact_time_uuid;
  42. $array['contact_times'][0]['contact_uuid'] = $contact_uuid;
  43. $array['contact_times'][0]['user_uuid'] = $_SESSION["user"]["user_uuid"];
  44. $array['contact_times'][0]['time_start'] = date("Y-m-d H:i:s");
  45. $array['contact_times'][0]['time_description'] = $time_description;
  46. }
  47. if ($time_action == 'stop') {
  48. $array['contact_times'][0]['contact_time_uuid'] = $contact_time_uuid;
  49. $array['contact_times'][0]['time_stop'] = date("Y-m-d H:i:s");
  50. $array['contact_times'][0]['time_description'] = $time_description;
  51. }
  52. if (is_array($array) && @sizeof($array) != 0) {
  53. $database = new database;
  54. $database->app_name = 'contacts';
  55. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  56. $database->save($array);
  57. unset($array);
  58. }
  59. header("Location: contact_timer.php?domain_uuid=".$domain_uuid."&contact_uuid=".$contact_uuid);
  60. }
  61. //get contact details
  62. $sql = "select ";
  63. $sql .= "contact_organization, ";
  64. $sql .= "contact_name_given, ";
  65. $sql .= "contact_name_family, ";
  66. $sql .= "contact_nickname ";
  67. $sql .= "from v_contacts ";
  68. $sql .= "where domain_uuid = :domain_uuid ";
  69. $sql .= "and contact_uuid = :contact_uuid ";
  70. $parameters['domain_uuid'] = $domain_uuid;
  71. $parameters['contact_uuid'] = $contact_uuid;
  72. $database = new database;
  73. $row = $database->select($sql, $parameters, 'row');
  74. if (is_array($row) && @sizeof($row) != 0) {
  75. $contact_organization = $row["contact_organization"];
  76. $contact_name_given = $row["contact_name_given"];
  77. $contact_name_family = $row["contact_name_family"];
  78. $contact_nickname = $row["contact_nickname"];
  79. }
  80. else {
  81. exit;
  82. }
  83. unset($sql, $parameters, $row);
  84. //determine timer state and action
  85. $sql = "select ";
  86. $sql .= "contact_time_uuid, ";
  87. $sql .= "time_description ";
  88. $sql .= "from v_contact_times ";
  89. $sql .= "where domain_uuid = :domain_uuid ";
  90. $sql .= "and user_uuid = :user_uuid ";
  91. $sql .= "and contact_uuid = :contact_uuid ";
  92. $sql .= "and time_start is not null ";
  93. $sql .= "and time_stop is null ";
  94. $parameters['domain_uuid'] = $domain_uuid;
  95. $parameters['user_uuid'] = $_SESSION['user']['user_uuid'];
  96. $parameters['contact_uuid'] = $contact_uuid;
  97. $database = new database;
  98. $row = $database->select($sql, $parameters, 'row');
  99. if (is_array($row) && @sizeof($row) != 0) {
  100. $contact_time_uuid = $row["contact_time_uuid"];
  101. $time_description = $row["time_description"];
  102. }
  103. unset($sql, $parameters, $row);
  104. $timer_state = is_uuid($contact_time_uuid) ? 'running' : 'stopped';
  105. $timer_action = $timer_state == 'running' ? 'stop' : 'start';
  106. //determine contact name to display
  107. if ($contact_nickname != '') {
  108. $contact = $contact_nickname;
  109. }
  110. else if ($contact_name_given != '') {
  111. $contact = $contact_name_given;
  112. }
  113. if ($contact_name_family != '') {
  114. $contact .= ($contact != '') ? ' '.$contact_name_family : $contact_name_family;
  115. }
  116. if ($contact_organization != '') {
  117. $contact .= ($contact != '') ? ', '.$contact_organization : $contact_organization;
  118. }
  119. //get the browser version
  120. $user_agent = http_user_agent();
  121. $browser_version = $user_agent['version'];
  122. $browser_name = $user_agent['name'];
  123. $browser_version_array = explode('.', $browser_version);
  124. //set the doctype
  125. echo ($browser_name != "Internet Explorer") ? "<!DOCTYPE html>\n" : "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
  126. ?>
  127. <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
  128. <head>
  129. <title><?php echo $text['label-time_timer']; ?>: <?php echo $contact; ?></title>
  130. <style>
  131. body {
  132. color: #5f5f5f;
  133. font-size: 12px;
  134. font-family: arial;
  135. margin: 0;
  136. padding: 15px;
  137. }
  138. b {
  139. color: #952424;
  140. font-size: 15px;
  141. font-family: arial;
  142. }
  143. a {
  144. color: #004083;
  145. width: 100%;
  146. }
  147. a:hover {
  148. color: #5082ca;
  149. }
  150. form {
  151. margin: 0;
  152. }
  153. input.btn, input.button {
  154. font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif;
  155. padding: 2px 6px 3px 6px;
  156. color: #fff;
  157. font-weight: bold;
  158. cursor: pointer;
  159. font-size: 11px;
  160. -moz-border-radius: 3px;
  161. -webkit-border-radius: 3px;
  162. -khtml-border-radius: 3px;
  163. border-radius: 3px;
  164. background-image: -moz-linear-gradient(top, #524f59 25%, #000 64%);
  165. background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.25, #524f59), color-stop(0.64, #000));
  166. border: 1px solid #26242a;
  167. background-color: #000;
  168. text-align: center;
  169. text-transform: uppercase;
  170. text-shadow: 0px 0px 1px rgba(0, 0, 0, 0.85);
  171. opacity: 0.9;
  172. -moz-opacity: 0.9;
  173. }
  174. input.btn:hover, input.button:hover, img.list_control_icon:hover {
  175. box-shadow: 0 0 5px #cddaf0;
  176. -webkit-box-shadow: 0 0 5px #cddaf0;
  177. -moz-box-shadow: 0 0 5px #cddaf0;
  178. opacity: 1.0;
  179. -moz-opacity: 1.0;
  180. cursor: pointer;
  181. }
  182. input.txt, textarea.txt, select.txt, .formfld {
  183. font-family: arial;
  184. font-size: 12px;
  185. color: #000;
  186. text-align: left;
  187. padding: 5px;
  188. border: 1px solid #c0c0c0;
  189. background-color: #fff;
  190. box-shadow: 0 0 3px #cddaf0 inset;
  191. -moz-box-shadow: 0 0 3px #cddaf0 inset;
  192. -webkit-box-shadow: 0 0 3px #cddaf0 inset;
  193. border-radius: 3px;
  194. -moz-border-radius: 3px;
  195. -webkit-border-radius: 3px;
  196. }
  197. input.txt, .formfld {
  198. transition: width 0.25s;
  199. -moz-transition: width 0.25s;
  200. -webkit-transition: width 0.25s;
  201. max-width: 500px;
  202. }
  203. input.txt:focus, .formfld:focus {
  204. -webkit-box-shadow: 0 0 5px #cddaf0;
  205. -moz-box-shadow: 0 0 5px #cddaf0;
  206. box-shadow: 0 0 5px #cddaf0;
  207. }
  208. td {
  209. color: #5f5f5f;
  210. font-size: 12px;
  211. font-family: arial;
  212. }
  213. .vncell {
  214. border-bottom: 1px solid #fff;
  215. background-color: #e5e9f0;
  216. padding: 8px;
  217. text-align: right;
  218. color: #000;
  219. -moz-border-radius: 4px;
  220. -webkit-border-radius: 4px;
  221. border-radius: 4px;
  222. border-right: 3px solid #e5e9f0;
  223. }
  224. DIV.timer_running {
  225. vertical-align: middle;
  226. padding-top: 7px;
  227. line-height: 50px;
  228. width: 100%;
  229. height: 53px;
  230. text-align: center;
  231. background-color: #2C9DE8;
  232. font-size: 50px;
  233. color: #FFFFFF;
  234. /*-webkit-text-shadow: 0px 0px 5px #000;*/
  235. /*-moz-text-shadow: 0px 0px 5px #000;*/
  236. /*text-shadow: 0px 0px 5px #000;*/
  237. font-weight: bold;
  238. letter-spacing: -0.05em;
  239. font-family: "Courier New",Courier,"Lucida Sans Typewriter","Lucida Typewriter",monospace;
  240. -moz-border-radius: 4px;
  241. -webkit-border-radius: 4px;
  242. border-radius: 4px;
  243. }
  244. DIV.timer_stopped {
  245. vertical-align: middle;
  246. padding-top: 7px;
  247. line-height: 50px;
  248. width: 100%;
  249. height: 53px;
  250. text-align: center;
  251. background-color: #2C9DE8;
  252. font-size: 50px;
  253. color: #FFFFFF;
  254. /*-webkit-text-shadow: 0px 0px 5px #000;*/
  255. /*-moz-text-shadow: 0px 0px 5px #000;*/
  256. /*text-shadow: 0px 0px 5px #000;*/
  257. font-weight: bold;
  258. letter-spacing: -0.05em;
  259. font-family: "Courier New",Courier,"Lucida Sans Typewriter","Lucida Typewriter",monospace;
  260. -moz-border-radius: 4px;
  261. -webkit-border-radius: 4px;
  262. border-radius: 4px;
  263. }
  264. </style>
  265. <script language='JavaScript' type='text/javascript' src='<?php echo PROJECT_PATH; ?>/resources/jquery/jquery-3.4.1.min.js'></script>
  266. <script src='https://code.jquery.com/jquery-migrate-3.1.0.js'></script>
  267. <script type="text/javascript">
  268. $(document).ready(function(){
  269. //ajax for refresh
  270. var refresh = 1500;
  271. var source_url = 'contact_timer_inc.php?domain_uuid=<?php echo escape($domain_uuid); ?>&contact_uuid=<?php echo escape($contact_uuid); ?>&contact_time_uuid=<?php echo escape($contact_time_uuid); ?>';
  272. var ajax_get = function () {
  273. $.ajax({
  274. url: source_url, success: function(response){
  275. $("#ajax_reponse").html(response);
  276. }
  277. });
  278. setTimeout(ajax_get, refresh);
  279. };
  280. <?php if ($timer_state == 'running') { ?>
  281. ajax_get();
  282. <?php } ?>
  283. });
  284. //set window title to time when timer is running
  285. function set_title(title_text) {
  286. window.document.title = title_text;
  287. }
  288. </script>
  289. </head>
  290. <body>
  291. <img src='resources/images/icon_timer.png' style='width: 24px; height: 24px; border: none; margin-left: 15px;' alt="<?php echo $text['label-time_timer']; ?>" align='right'>
  292. <b><?php echo $text['label-time_timer']; ?></b>
  293. <br><br>
  294. <?php echo $text['description_timer']; ?>
  295. <br><br>
  296. <strong><a href="javascript:void(0);" onclick="window.opener.location.href='contact_edit.php?id=<?php echo escape($contact_uuid); ?>';"><?php echo escape($contact); ?></a></strong>
  297. <br><br>
  298. <div id='ajax_reponse' class='timer_<?php echo escape($timer_state);?>'>00:00:00</div>
  299. <br>
  300. <form name='frm' id='frm' method='post'>
  301. <input type='hidden' name='domain_uuid' value="<?php echo escape($domain_uuid); ?>">
  302. <input type='hidden' name='contact_time_uuid' value="<?php echo escape($contact_time_uuid); ?>">
  303. <input type='hidden' name='contact_uuid' value="<?php echo escape($contact_uuid); ?>">
  304. <input type='hidden' name='time_action' value="<?php echo escape($timer_action); ?>">
  305. <table cellpadding='0' cellspacing='0' border='0' style='width: 100%;'>
  306. <tr>
  307. <td class='vncell' style='text-align: center; border: none; padding: 0 !important; padding-top: 10px !important;'>
  308. <?php echo $text['label-description']; ?><br>
  309. <textarea name='time_description' id='timer_description' class='formfld' style='width: calc(100% - 30px); height: 50px; margin: 5px 10px 10px;'><?php echo escape($time_description); ?></textarea>
  310. </td>
  311. </tr>
  312. </table>
  313. <br>
  314. <center>
  315. <?php if ($timer_state == 'running') { ?>
  316. <input type='submit' class='btn' value="<?php echo $text['button-stop']; ?>">
  317. <?php } else if ($timer_state == 'stopped') { ?>
  318. <input type='submit' class='btn' value="<?php echo $text['button-start']; ?>">
  319. <?php } ?>
  320. </center>
  321. </form>
  322. <?php if ($timer_state == 'stopped') { ?><script>$('#timer_description').trigger('focus');</script><?php } ?>
  323. </body>
  324. </html>