messages.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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) 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('message_view')) {
  26. echo "access denied";
  27. exit;
  28. }
  29. //connect to the database
  30. $database = database::new();
  31. //missing application - app/providers is required
  32. if (!file_exists($_SERVER["PROJECT_ROOT"].'/app/providers/app_config.php')) {
  33. $document['title'] = $text['title-messages'];
  34. require_once "resources/header.php";
  35. echo "<br /><br />\n";
  36. echo "<div>\n";
  37. echo " <div class='heading' style=\"text-align: center;\"><b>Missing Application</b></div>\n";
  38. echo " <div style=\"text-align: center;\">\n";
  39. echo " <br />\n";
  40. echo " This feature requires the seperate <strong>Providers</strong> app to be installed.<br />\n";
  41. echo " Please install it using the <strong>Application Manager</strong>.\n";
  42. echo " </div>\n";
  43. echo " <div style='clear: both;'></div>\n";
  44. echo "</div>\n";
  45. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
  46. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
  47. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
  48. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
  49. echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
  50. require_once "resources/footer.php";
  51. exit;
  52. }
  53. //add multi-lingual support
  54. $language = new text;
  55. $text = $language->get();
  56. //build a list of groups the user is a member of to be used in a SQL in
  57. foreach($_SESSION['user']['groups'] as $group) {
  58. if (is_uuid($group['group_uuid'])) {
  59. $group_uuids[] = $group['group_uuid'];
  60. }
  61. }
  62. $group_uuids_in = "'".implode("','", $group_uuids)."'";
  63. //get the message from
  64. $sql = "select destination_number from v_destinations ";
  65. $sql .= "where domain_uuid = :domain_uuid ";
  66. $sql .= "and (user_uuid = :user_uuid OR group_uuid IN (".$group_uuids_in.")) ";
  67. $sql .= "and destination_type_text = 1 ";
  68. $sql .= "and destination_enabled = 'true' ";
  69. $sql .= "order by destination_number asc ";
  70. $parameters['domain_uuid'] = $domain_uuid;
  71. $parameters['user_uuid'] = $_SESSION['user']['user_uuid'];
  72. $rows = $database->select($sql, $parameters, 'all');
  73. if (is_array($rows) && @sizeof($rows)) {
  74. foreach ($rows as $row) {
  75. $destinations[] = $row['destination_number'];
  76. }
  77. }
  78. unset($sql, $parameters, $rows, $row);
  79. $message_from = $destinations[0] ?? null;
  80. //view_array($destinations);
  81. //get the message to
  82. if (isset($_SESSION['user']['contact_number']) && !empty($_SESSION['user']['contact_number'])) {
  83. $message_to = $_SESSION['user']['contact_number'];
  84. }
  85. //get self (primary contact attachment) image
  86. /*
  87. if (!is_array($_SESSION['tmp']['messages']['contact_me'])) {
  88. $sql = "select attachment_filename as filename, attachment_content as image ";
  89. $sql .= "from v_contact_attachments ";
  90. $sql .= "where domain_uuid = :domain_uuid ";
  91. $sql .= "and contact_uuid = :contact_uuid ";
  92. $sql .= "and attachment_primary = 1 ";
  93. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  94. $parameters['contact_uuid'] = $_SESSION['user']['contact_uuid'];
  95. $row = $database->select($sql, $parameters, 'row');
  96. $_SESSION['tmp']['messages']['contact_me'] = $row;
  97. unset($sql, $parameters, $row);
  98. }
  99. */
  100. //get the cache
  101. $cache = new cache;
  102. $message_update = $cache->get("messages:user:last_message:".$_SESSION['user']['user_uuid']);
  103. //additional includes
  104. $document['title'] = $text['title-messages'];
  105. require_once "resources/header.php";
  106. //add audio
  107. echo "<audio id='message_audio' >\n";
  108. echo " <source src=\"".$_SESSION['message']['notify_sound']['text']."\" type='audio/mpeg'>\n";
  109. echo "</audio>\n";
  110. echo "<script language='JavaScript' type='text/javascript'>\n";
  111. echo " var audio = document.getElementById('message_audio');\n";
  112. echo " function message_notify(){\n";
  113. echo " audio.play();\n";
  114. echo " }\n";
  115. echo "</script>\n";
  116. //additional sound notes
  117. //https://notificationsounds.com/notification-sounds/clearly-602
  118. //echo " <source src=\"http://soundbible.com/grab.php?id=1682&type=mp3\" type=\"audio/mpeg\">\n";
  119. //https://soundbible.com/search.php?q=beep
  120. //https://freesound.org/search/?q=notify&page=2#sound
  121. //check for updates with ajax
  122. echo "<script language='JavaScript' type='text/javascript'>\n";
  123. echo "\n";
  124. echo "function check_updates() {\n";
  125. echo " var xhttp = new XMLHttpRequest();\n";
  126. echo " xhttp.open('GET', 'message_update.php?id=".$_SESSION['user']['user_uuid']."');\n";
  127. echo " xhttp.send();\n";
  128. echo " xhttp.onreadystatechange = function() {\n";
  129. //echo " var time_now = date_now.getTime();\n";
  130. //echo " var time_diff = time_now - date_now;\n";
  131. //echo " var seconds_elapsed = Math.floor ( time_diff / 1000 );\n";
  132. //echo " if (this.readyState == 4 && this.status == 200 && seconds_elapsed > 2) {\n";
  133. echo " if (this.readyState == 4 && this.status == 200) {\n";
  134. echo " if (this.responseText != document.getElementById('message_update').value) {\n";
  135. //echo " alert('update ajax: '+this.responseText+ ' input: '+document.getElementById('message_update').value);\n";
  136. echo " document.getElementById('message_update').value = this.responseText;\n";
  137. echo " message_to = document.getElementById('message_to').value;\n";
  138. echo " contacts_url = 'messages_contacts.php';\n";
  139. echo " document.getElementById('contacts_frame').src = contacts_url;\n";
  140. echo " document.getElementById('contacts_frame').onload = function() {\n";
  141. echo " scroll_to_bottom('messages_frame');\n";
  142. echo " }\n";
  143. echo " messages_url = 'messages_thread.php?number='+message_to;\n";
  144. echo " document.getElementById('messages_frame').src = messages_url;\n";
  145. echo " document.getElementById('messages_frame').onload = function() {\n";
  146. echo " scroll_to_bottom('messages_frame');\n";
  147. echo " }\n";
  148. echo " message_notify();\n";
  149. echo " }\n";
  150. echo " }\n";
  151. echo " };\n";
  152. echo "}\n";
  153. echo "setInterval(check_updates, 1000);\n";
  154. echo "\n";
  155. echo "</script>\n";
  156. //body onload
  157. echo "<body onload=\"scroll_to_bottom('messages_frame');\">\n";
  158. //resize thread window on window resize
  159. echo "<script language='JavaScript' type='text/javascript'>\n";
  160. echo " $(document).ready(function() {\n";
  161. echo " $(window).on('resizeEnd', function() {\n";
  162. echo " $('div#thread_messages').animate({ 'max-height': $(window).height() - 480 }, 200);\n";
  163. echo " });\n";
  164. echo " });\n";
  165. echo "</script>\n";
  166. //styles
  167. echo "<style>\n";
  168. echo "\n";
  169. echo " #message_new_layer {\n";
  170. echo " z-index: 999999;\n";
  171. echo " position: absolute;\n";
  172. echo " left: 0px;\n";
  173. echo " top: 0px;\n";
  174. echo " right: 0px;\n";
  175. echo " bottom: 0px;\n";
  176. echo " text-align: center;\n";
  177. echo " vertical-align: middle;\n";
  178. echo " }\n";
  179. echo " #message_new_container {\n";
  180. echo " display: block;\n";
  181. echo " background-color: #fff;\n";
  182. echo " padding: 20px 30px;\n";
  183. if (http_user_agent('mobile')) {
  184. echo " margin: 0;\n";
  185. }
  186. else {
  187. echo " margin: auto 30%;\n";
  188. }
  189. echo " text-align: left;\n";
  190. echo " -webkit-box-shadow: 0px 1px 20px #888;\n";
  191. echo " -moz-box-shadow: 0px 1px 20px #888;\n";
  192. echo " box-shadow: 0px 1px 20px #888;\n";
  193. echo " }\n";
  194. echo " #message_media_layer {\n";
  195. echo " z-index: 999999;\n";
  196. echo " position: absolute;\n";
  197. echo " left: 0px;\n";
  198. echo " top: 0px;\n";
  199. echo " right: 0px;\n";
  200. echo " bottom: 0px;\n";
  201. echo " text-align: center;\n";
  202. echo " vertical-align: middle;\n";
  203. echo " }\n";
  204. echo " td.contact_selected {\n";
  205. echo " border-right: 5px solid ".($_SESSION['theme']['table_row_border_color']['text'] ?? '#c5d1e5').";\n";
  206. echo " }\n";
  207. echo " .contact_list_image {\n";
  208. echo " float: left;\n";
  209. echo " width: 75px;\n";
  210. echo " height: 75px;\n";
  211. echo " margin: 3px 8px 3px 2px;\n";
  212. echo " border: 1px solid ".($_SESSION['theme']['table_row_border_color']['text'] ?? '#c5d1e5').";\n";
  213. echo " background-repeat: no-repeat;\n";
  214. echo " background-size: cover;\n";
  215. echo " background-position: center center;\n";
  216. echo " border-radius: 11px;\n";
  217. echo " }\n";
  218. echo " div.container {\n";
  219. echo " width: 100%;\n";
  220. echo " height: 75vh;\n";
  221. echo " max-width: 100%;\n";
  222. //echo " max-height: 100%;\n";
  223. //echo " border:1px solid black;\n";
  224. echo " display: grid;\n";
  225. echo " padding-left: 0;\n";
  226. echo " padding-right: 0;\n";
  227. //flex
  228. //echo " flex: 1;\n";
  229. //echo " display: flex;\n";
  230. //echo " flex-direction: column;\n";
  231. //echo " justify-content: space-between;\n";
  232. //echo " display: inline-grid;\n";
  233. if (!empty($_SESSION['message']['contact_details']['boolean']) && $_SESSION['message']['contact_details']['boolean'] == 'true') {
  234. echo " grid-template-columns: minmax(120px, 1fr) minmax(200px, 3fr) 1fr;\n";
  235. }
  236. else {
  237. echo " grid-template-columns: minmax(120px, 1fr) minmax(200px, 4fr);\n";
  238. }
  239. echo " grid-template-rows: 1fr;\n";
  240. echo " gap: 10px 10px;\n";
  241. //echo " grid-auto-flow: row;\n";
  242. echo " grid-template-areas:\n";
  243. //echo " \"contacts header header\"\n";
  244. echo " \"contacts messages details\"\n";
  245. echo " \"contacts send details\"\n";
  246. //echo " width: 100%;\n";
  247. //echo " height: 100%;\n";
  248. echo " }\n";
  249. echo " div.contacts {\n";
  250. echo " grid-area: contacts;\n";
  251. //echo " min-width: 120px;\n";
  252. //echo " height: 100%;\n";
  253. echo " background: ".($_SESSION['theme']['form_table_field_background_color']['text'] ?? '#fff').";\n";
  254. echo " border-right: 1px solid #ccc;\n";
  255. echo " }\n";
  256. echo " div.messages {\n";
  257. echo " grid-area: messages;\n";
  258. // echo " border-top: 1px dashed #ccc;\n";
  259. // echo " border-bottom: 1px dashed #ccc;\n";
  260. echo " }\n";
  261. echo " div.send {\n";
  262. echo " grid-area: send;\n";
  263. echo " margin: 4px;\n";
  264. echo " }\n";
  265. echo " div.details {\n";
  266. echo " min-width: 330px;\n";
  267. echo " grid-area: details;\n";
  268. echo " border-left: 1px solid #ccc;\n";
  269. echo " }\n";
  270. echo " @media (max-width: 992px) {\n";
  271. echo " div.container {\n";
  272. echo " grid-template-columns: 120px minmax(200px, 3fr);\n";
  273. echo " }\n";
  274. echo " }\n";
  275. echo "</style>\n";
  276. //cache self (primary contact attachment) image
  277. if (!empty($_SESSION['tmp']) && is_array($_SESSION['tmp']['messages']['contact_me']) && !empty($_SESSION['tmp']['messages']['contact_me'])) {
  278. $attachment_type = strtolower(pathinfo($_SESSION['tmp']['messages']['contact_me']['filename'], PATHINFO_EXTENSION));
  279. echo "<img id='src_message-bubble-image-me' style='display: none;' src='data:image/".$attachment_type.";base64,".$_SESSION['tmp']['messages']['contact_me']['image']."'>\n";
  280. }
  281. //new message layer
  282. if (permission_exists('message_add')) {
  283. echo "<iframe name=\"message_new_frame\" style=\"display: none; width: 0px; height: 0px;\"></iframe>\n";
  284. echo "<div id='message_new_layer' style='display: none;'>\n";
  285. echo " <table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'>\n";
  286. echo " <tr>\n";
  287. echo " <td align='center' valign='middle'>\n";
  288. echo " <form id='message_new' method='post' enctype='multipart/form-data' action='message_send.php' target='message_new_frame'>\n";
  289. echo " <span id='message_new_container'>\n";
  290. echo " <b>".$text['label-new_message']."</b><br /><br />\n";
  291. echo " <table width='100%'>\n";
  292. echo " <tr>\n";
  293. echo " <td class='vncell'>".$text['label-message_from']."</td>\n";
  294. echo " <td class='vtable'>\n";
  295. if (!empty($destinations) && is_array($destinations)) {
  296. echo " <select class='formfld' name='message_from' id='message_new_from' onchange=\"$('#message_new_to').focus();\">\n";
  297. foreach ($destinations as $destination) {
  298. echo " <option value='".$destination."'>".format_phone($destination)."</option>\n";
  299. }
  300. echo " </select>\n";
  301. }
  302. else {
  303. echo " <input type='text' class='formfld' name='message_from' id='message_new_from'>\n";
  304. }
  305. echo " </td>\n";
  306. echo " </tr>\n";
  307. echo " <tr>\n";
  308. echo " <td class='vncell'>".$text['label-message_to']."</td>\n";
  309. echo " <td class='vtable'>\n";
  310. echo " <input type='text' class='formfld' name='message_to' id='message_new_to'>\n";
  311. echo " </td>\n";
  312. echo " </tr>\n";
  313. echo " <tr>\n";
  314. echo " <td class='vncell'>".$text['label-message_text']."</td>\n";
  315. echo " <td class='vtable'>\n";
  316. echo " <textarea class='formfld' style='width: 100%; height: 80px;' name='message_text' name='message_new_text'></textarea>\n";
  317. echo " </td>\n";
  318. echo " </tr>\n";
  319. echo " <tr>\n";
  320. echo " <td class='vncell'>".$text['label-message_media']."</td>\n";
  321. echo " <td class='vtable'>\n";
  322. echo " <input type='file' class='formfld' multiple='multiple' name='message_media[]' id='message_new_media'>\n";
  323. echo " </td>\n";
  324. echo " </tr>\n";
  325. echo " </table>\n";
  326. echo " <center style='margin-top: 15px;'>\n";
  327. echo button::create(['type'=>'reset','label'=>$text['button-clear'],'icon'=>$_SESSION['theme']['button_icon_reset'],'style'=>'float: left;','onclick'=>"document.getElementById('message_new').reset();"]);
  328. echo button::create(['type'=>'button','label'=>$text['button-close'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'onclick'=>"$('#message_new_layer').fadeOut(200);"]);
  329. echo button::create(['type'=>'submit','label'=>$text['button-send'],'icon'=>'paper-plane','style'=>'float: right;','onclick'=>"document.getElementById('message_new').submit();document.getElementById('message_new_layer').style.display='none'"]);
  330. //echo button::create(['type'=>'reset','label'=>$text['button-clear'],'icon'=>$_SESSION['theme']['button_icon_reset'],'style'=>'float: left;','onclick'=>"$('#message_new').reset();"]);
  331. //echo " <input type='reset' class='btn' style='float: left; margin-top: 15px;' value='".$text['button-clear']."' onclick=\"$('#message_new').reset();\">\n";
  332. //echo " <input type='button' class='btn' style='margin-top: 15px;' value='".$text['button-close']."' onclick=\"$('#message_new_layer').fadeOut(200);\">\n";
  333. //echo " <input type='submit' class='btn' style='float: right; margin-top: 15px;' value='".$text['button-send']."'>\n";
  334. echo " </center>\n";
  335. echo " </span>\n";
  336. echo " </form>\n";
  337. echo " </td>\n";
  338. echo " </tr>\n";
  339. echo " </table>\n";
  340. echo "</div>\n";
  341. }
  342. //message media layer
  343. echo "<div id='message_media_layer' style='display: none;'></div>\n";
  344. //show the content
  345. echo "<div class='action_bar' id='action_bar'>\n";
  346. echo " <div class='heading'><b>".$text['title-messages']."</b></div>\n";
  347. echo " <div class='actions'>\n";
  348. if (permission_exists('message_add')) {
  349. echo button::create(['type'=>'button','label'=>$text['label-new_message'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','onclick'=>"document.getElementById('message_new').reset(); $('#message_new_layer').fadeIn(200); unload_thread();"]);
  350. //echo button::create(['type'=>'button','label'=>$text['label-new_message'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','onclick'=>"document.getElementById('message_new').reset();$('#message_new_layer').fadeIn(200); unload_thread();"]);
  351. }
  352. if (permission_exists('message_log_view')) {
  353. echo button::create(['type'=>'button','label'=>$text['label-log'],'icon'=>'list','link'=>'message_logs.php']);
  354. }
  355. echo " </div>\n";
  356. echo " <div style='clear: both;'></div>\n";
  357. echo "</div>\n";
  358. echo "<div class='card'>\n";
  359. echo " <div class='container'>\n";
  360. echo " <div class='contacts'>\n";
  361. echo " <iframe id='contacts_frame' style='width: 100%; height: 100%;' src='messages_contacts.php' frameborder='0'></iframe>\n";
  362. echo " </div>\n";
  363. echo " <div class='messages'>\n";
  364. echo " <iframe id='messages_frame' class='myautoscroll' style='width: 100%; height: 100%;' src='messages_thread.php' frameborder='0'></iframe>\n";
  365. echo " </div>\n";
  366. if (permission_exists('message_add')) {
  367. echo " <div class='send'>\n";
  368. //output input form
  369. //echo "<iframe name=\"message_reply_frame\" style=\"display: none; width: 0px; height: 0px;\"></iframe>\n";
  370. //echo "<form id='message_reply' method='post' onsubmit='document.getElementById(\"message_text\").value = \"\";' enctype='multipart/form-data' action='message_send.php' target='message_reply_frame'>\n";
  371. echo "<form id='message_reply' method='post' onsubmit='' enctype='multipart/form-data' action='message_send.php'>\n";
  372. echo "<input type='hidden' name='message_update' id='message_update' value='".$message_update."'>\n";
  373. //echo "<div>\n";
  374. //echo " To <div id='div_message_to'>".escape($message_to)."</div>\n";
  375. echo " <input type='hidden' class='formfld' name='message_to' id='message_to' value='".urlencode($message_to ?? '')."'>\n";
  376. //echo "</div>\n";
  377. echo "<textarea class='formfld' id='message_text' name='message_text' style='width: 100%; min-height: 55px; resize: vertical; padding: 5px 8px; margin: 3px 0 10px 0;' placeholder=\"".$text['description-enter_response']."\"></textarea>";
  378. //echo "<input type='input' class='formfld' name='message_text' id='message_text' style='width: 90%; max-width: 100%;'>\n";
  379. // echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='margin-top: 5px;'>\n";
  380. // echo " <tr>\n";
  381. // echo " <td class='attachment_image' style='width: 20px;'><img src='resources/images/attachment.png' style='min-width: 20px; height: 20px; border: none; padding-right: 5px;'></td>\n";
  382. // echo " <td>\n";
  383. echo "<input type='file' class='formfld' style='max-width: 170px;' multiple='multiple' name='message_media[]' id='message_new_media'>\n";
  384. // echo " </td>\n";
  385. // echo " <td style='text-align: right;'>\n";
  386. echo button::create(['type'=>'submit','label'=>$text['button-send'],'title'=>$text['label-ctrl_enter'],'icon'=>'paper-plane','class'=>'default d-none d-sm-inline-block','style'=>'float: right; margin-left: 10px; margin-right: 0;']);
  387. if (!empty($destinations) && count($destinations) > 1) {
  388. echo "<select class='formfld' name='message_from' id='message_from' style='float: right; padding: 0 5px 0 8px; margin-bottom: 10px;'>\n";
  389. echo " <option value='' disabled='disabled'>".$text['label-message_from']."...</option>\n";
  390. foreach ($destinations as $destination) {
  391. echo "<option value='".$destination."'>".format_phone($destination)."</option>\n";
  392. }
  393. echo "</select>\n";
  394. }
  395. else {
  396. //echo " From \n";
  397. echo "<input type='hidden' class='formfld' name='message_from' id='message_from' value='".urlencode($message_from ?? '')."'>\n";
  398. }
  399. // echo " </td>\n";
  400. // echo " </tr>\n";
  401. // echo "</table>\n";
  402. echo button::create(['type'=>'submit','label'=>$text['button-send'],'title'=>$text['label-ctrl_enter'],'icon'=>'paper-plane','class'=>'default d-block d-sm-none','style'=>'width: 100%; margin-left: 0;']);
  403. //echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' style='margin-top: 15px;'>\n";
  404. //echo " <tr>\n";
  405. //echo " <td align='left' width='50%'>";
  406. //echo button::create(['label'=>$text['button-clear'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'reset','onclick'=>"$('#message_text').focus();"]);
  407. //echo " </td>\n";
  408. //echo " <td align='center'><span id='thread_refresh_state'><img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; cursor: pointer;' onclick=\"refresh_thread_stop('".$number."','".$contact_uuid."');\" alt=\"".$text['label-refresh_pause']."\" title=\"".$text['label-refresh_pause']."\"></span></td>\n";
  409. //echo " <td align='right' width='50%'>";
  410. //echo button::create(['type'=>'submit','label'=>$text['button-send'],'title'=>$text['label-ctrl_enter'],'icon'=>'paper-plane']);
  411. //echo " </td>\n";
  412. //echo " </tr>\n";
  413. //echo "</table>\n";
  414. echo "</form>\n";
  415. //js to load messages for clicked number
  416. echo "<script>\n";
  417. //scroll to the bottom
  418. echo " function scroll_to_bottom(id) {\n";
  419. echo " document.getElementById(id).contentWindow.scrollTo(0, 999999);\n";
  420. echo " }\n";
  421. echo "\n";
  422. //update the url
  423. echo " function update_url(id, url) {\n";
  424. echo " document.getElementById(id).src = url;\n";
  425. echo " }\n";
  426. //define form submit function
  427. echo " $('#message_reply').submit(function(event) {\n";
  428. echo " event.preventDefault();\n";
  429. echo " $.ajax({\n";
  430. echo " url: $(this).attr('action'),\n";
  431. echo " type: $(this).attr('method'),\n";
  432. echo " data: new FormData(this),\n";
  433. echo " processData: false,\n";
  434. echo " contentType: false,\n";
  435. echo " cache: false,\n";
  436. echo " success: function(){\n";
  437. echo " document.getElementById('message_reply').reset();\n";
  438. if (!http_user_agent('mobile')) {
  439. echo " if ($('#message_new_layer').is(':hidden')) {\n";
  440. echo " $('#message_text').focus();\n";
  441. echo " }\n";
  442. }
  443. //refresh the message thread
  444. //echo " setTimeout(function() {\n";
  445. //echo " refresh_thread()\n";
  446. //echo " }, 1000);\n";
  447. //echo " refresh_thread('".$number."', '".$contact_uuid."', 'true');\n";
  448. echo " }\n";
  449. echo " });\n";
  450. echo " });\n";
  451. //enable ctrl+enter to send
  452. echo " $('#message_text').keydown(function (event) {\n";
  453. echo " if ((event.keyCode == 10 || event.keyCode == 13) && event.ctrlKey) {\n";
  454. echo " $('#message_compose').submit();\n";
  455. echo " }\n";
  456. echo " });\n";
  457. echo "</script>\n";
  458. echo " </div>\n"; //send
  459. }
  460. if (!empty($_SESSION['message']['contact_details']['boolean']) && $_SESSION['message']['contact_details']['boolean'] == 'true') {
  461. echo " <div class='details d-none d-md-block'>\n";
  462. if (permission_exists('contact_view')) {
  463. echo " <iframe id='contact_frame' style='width: 100%; height: 100%;' src='message_contact.php' frameborder='0'></iframe>\n";
  464. }
  465. echo " </div>\n";
  466. }
  467. echo " </div>\n"; //container
  468. echo "</div>\n";
  469. /*
  470. echo "<script>\n";
  471. echo " function refresh_thread() {\n";
  472. echo " message_to = parent.document.getElementById('message_to').value;\n";
  473. echo " update_url('messages_frame', 'messages_thread.php?number='+message_to);\n";
  474. echo " }\n";
  475. echo "</script>\n";
  476. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  477. echo " <tr>\n";
  478. echo " <th width='30%'>".$text['label-contacts']."</th>\n";
  479. echo " <th style='white-space: nowrap;'><nobr>".$text['label-messages']."<nobr></th>\n";
  480. echo " <th width='70%' style='text-align: right; font-weight: normal;' id='contact_current_name'>\n";
  481. echo " <iframe id=\"frame\" src=\"/app/messages/messages_contacts.php\" frameborder=\"0\"></iframe>\n";
  482. echo " </th>\n";
  483. echo " </tr>\n";
  484. echo " <tr>\n";
  485. echo " <td id='contacts' valign='top'><center>&middot;&middot;&middot;</center></td>\n";
  486. echo " <td id='thread' colspan='2' valign='top' style='border-left: 1px solid #c5d1e5; padding: 15px 0 15px 15px;'><center>&middot;&middot;&middot;</center></td>\n";
  487. echo " </tr>\n";
  488. echo "</table>\n";
  489. echo "<input type='hidden' id='contact_current_number' value=''>\n";
  490. //js to load messages for clicked number
  491. echo "<script>\n";
  492. /*
  493. $refresh_contacts = is_numeric($_SESSION['message']['refresh_contacts']['numeric']) && $_SESSION['message']['refresh_contacts']['numeric'] > 0 ? $_SESSION['message']['refresh_contacts']['numeric'] : 10; //default (seconds)
  494. $refresh_thread = is_numeric($_SESSION['message']['refresh_thread']['numeric']) && $_SESSION['message']['refresh_thread']['numeric'] > 0 ? $_SESSION['message']['refresh_thread']['numeric'] : 5; //default (seconds)
  495. echo " var contacts_refresh = ".($refresh_contacts * 1000).";\n";
  496. echo " var thread_refresh = ".($refresh_thread * 1000).";\n";
  497. echo " var timer_contacts;\n";
  498. echo " var timer_thread;\n";
  499. echo " function refresh_contacts() {\n";
  500. echo " clearTimeout(timer_contacts);\n";
  501. echo " $('#contacts').load('messages_contacts.php?sel=' + $('#contact_current_number').val(), function(){\n";
  502. echo " timer_contacts = setTimeout(refresh_contacts, contacts_refresh);\n";
  503. echo " });\n";
  504. echo " }\n";
  505. echo " function load_thread(number, contact_uuid) {\n";
  506. echo " clearTimeout(timer_thread);\n";
  507. echo " $('#thread').load('messages_thread.php?number=' + encodeURIComponent(number) + '&contact_uuid=' + encodeURIComponent(contact_uuid), function(){\n";
  508. echo " $('div#thread_messages').animate({ 'max-height': $(window).height() - 470 }, 200, function() {\n";
  509. echo " $('#thread_messages').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
  510. echo " $('span#thread_bottom')[0].scrollIntoView(true);\n"; //others
  511. //note: the order of the above two lines matters!
  512. if (!http_user_agent('mobile')) {
  513. echo " if ($('#message_new_layer').is(':hidden')) {\n";
  514. echo " $('#message_text').focus();\n";
  515. echo " }\n";
  516. }
  517. echo " refresh_contacts();\n";
  518. echo " timer_thread = setTimeout(refresh_thread_start, thread_refresh, number, contact_uuid);\n";
  519. echo " });\n";
  520. echo " });\n";
  521. echo " }\n";
  522. echo " function unload_thread() {\n";
  523. echo " clearTimeout(timer_thread);\n";
  524. echo " $('#thread').html('<center>&middot;&middot;&middot;</center>');\n";
  525. echo " $('#contact_current_number').val('');\n";
  526. echo " $('#contact_current_name').html('');\n";
  527. echo " refresh_contacts();\n";
  528. echo " }\n";
  529. echo " function refresh_thread(number, contact_uuid, onsent) {\n";
  530. echo " $('#thread_messages').load('messages_thread.php?refresh=true&number=' + encodeURIComponent(number) + '&contact_uuid=' + encodeURIComponent(contact_uuid), function(){\n";
  531. echo " $('div#thread_messages').animate({ 'max-height': $(window).height() - 470 }, 200, function() {\n";
  532. echo " $('#thread_messages').scrollTop(Number.MAX_SAFE_INTEGER);\n"; //chrome
  533. echo " $('span#thread_bottom')[0].scrollIntoView(true);\n"; //others
  534. //note: the order of the above two lines matters!
  535. if (!http_user_agent('mobile')) {
  536. echo " if ($('#message_new_layer').is(':hidden')) {\n";
  537. echo " $('#message_text').focus();\n";
  538. echo " }\n";
  539. }
  540. echo " if (onsent != 'true') {\n";
  541. echo " timer_thread = setTimeout(refresh_thread, thread_refresh, number, contact_uuid);\n";
  542. echo " }\n";
  543. echo " });\n";
  544. echo " });\n";
  545. echo " }\n";
  546. //refresh controls
  547. echo " function refresh_contacts_stop() {\n";
  548. echo " clearTimeout(timer_contacts);\n";
  549. echo " document.getElementById('contacts_refresh_state').innerHTML = \"<img src='resources/images/refresh_paused.png' style='width: 16px; height: 16px; border: none; margin-top: 1px; cursor: pointer;' onclick='refresh_contacts_start();' alt='".$text['label-refresh_enable']."' title='".$text['label-refresh_enable']."'>\";\n";
  550. echo " }\n";
  551. echo " function refresh_contacts_start() {\n";
  552. echo " if (document.getElementById('contacts_refresh_state')) {\n";
  553. echo " document.getElementById('contacts_refresh_state').innerHTML = \"<img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick='refresh_contacts_stop();' alt='".$text['label-refresh_pause']."' title='".$text['label-refresh_pause']."'>\";\n";
  554. echo " refresh_contacts();\n";
  555. echo " }\n";
  556. echo " }\n";
  557. echo " function refresh_thread_stop(number, contact_uuid) {\n";
  558. echo " clearTimeout(timer_thread);\n";
  559. ?> document.getElementById('thread_refresh_state').innerHTML = "<img src='resources/images/refresh_paused.png' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick=\"refresh_thread_start('" + number + "', '" + contact_uuid + "');\" alt=\"<?php echo $text['label-refresh_enable']; ?>\" title=\"<?php echo $text['label-refresh_enable']; ?>\">";<?php
  560. echo " }\n";
  561. echo " function refresh_thread_start(number, contact_uuid) {\n";
  562. echo " if (document.getElementById('thread_refresh_state')) {\n";
  563. ?> document.getElementById('thread_refresh_state').innerHTML = "<img src='resources/images/refresh_active.gif' style='width: 16px; height: 16px; border: none; margin-top: 3px; cursor: pointer;' onclick=\"refresh_thread_stop('" + number + "', '" + contact_uuid + "');\" alt=\"<?php echo $text['label-refresh_pause']; ?>\" title=\"<?php echo $text['label-refresh_pause']; ?>\">";<?php
  564. echo " refresh_thread(number, contact_uuid);\n";
  565. echo " }\n";
  566. echo " }\n";
  567. //define form submit function
  568. if (permission_exists('message_add')) {
  569. echo " $('#message_new').submit(function(event) {\n";
  570. echo " event.preventDefault();\n";
  571. echo " $.ajax({\n";
  572. echo " url: $(this).attr('action'),\n";
  573. echo " type: $(this).attr('method'),\n";
  574. echo " data: new FormData(this),\n";
  575. echo " processData: false,\n";
  576. echo " contentType: false,\n";
  577. echo " cache: false,\n";
  578. echo " success: function(){\n";
  579. echo " if ($.isNumeric($('#message_new_to').val())) {\n";
  580. echo " $('#contact_current_number').val($('#message_new_to').val());\n";
  581. echo " load_thread($('#message_new_to').val());\n";
  582. echo " }\n";
  583. echo " $('#message_new_layer').fadeOut(400);\n";
  584. echo " document.getElementById('message_new').reset();\n";
  585. echo " refresh_contacts();\n";
  586. echo " }\n";
  587. echo " });\n";
  588. echo " });\n";
  589. }
  590. */
  591. //include the footer
  592. require_once "resources/footer.php";
  593. ?>