messages.php 29 KB

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