message_contact.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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('contact_view')) {
  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(null, '/app/contacts');
  35. //action add or update
  36. if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
  37. $contact_uuid = $_REQUEST["id"];
  38. }
  39. elseif (!empty($_REQUEST["destination"]) ) {
  40. $destination = $_REQUEST["destination"];
  41. }
  42. else {
  43. echo '<html><body>&nbsp;</body></html> ';
  44. exit;
  45. }
  46. //main contact details
  47. $sql = "select * from v_contacts as c \n";
  48. $sql .= "where domain_uuid = :domain_uuid \n";
  49. if (!empty($destination)) {
  50. $sql .= "and contact_uuid in ( \n";
  51. $sql .= " select contact_uuid from v_contact_phones \n";
  52. $sql .= " where domain_uuid = :domain_uuid \n";
  53. $sql .= " and ( \n";
  54. $sql .= " concat('+',phone_country_code, phone_number) = :destination \n";
  55. $sql .= " or concat(phone_country_code, phone_number) = :destination \n";
  56. $sql .= " or phone_number = :destination \n";
  57. $sql .= " ) \n";
  58. $sql .= ") \n";
  59. $parameters['destination'] = $destination;
  60. }
  61. if (!empty($contact_uuid)) {
  62. $sql .= "and contact_uuid = :contact_uuid ";
  63. $parameters['contact_uuid'] = $contact_uuid;
  64. }
  65. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  66. $database = new database;
  67. $row = $database->select($sql, $parameters, 'row');
  68. if (!empty($row)) {
  69. $contact_uuid = $row["contact_uuid"];
  70. $contact_type = $row["contact_type"];
  71. $contact_organization = $row["contact_organization"];
  72. $contact_name_prefix = $row["contact_name_prefix"];
  73. $contact_name_given = $row["contact_name_given"];
  74. $contact_name_middle = $row["contact_name_middle"];
  75. $contact_name_family = $row["contact_name_family"];
  76. $contact_name_suffix = $row["contact_name_suffix"];
  77. $contact_nickname = $row["contact_nickname"];
  78. $contact_title = $row["contact_title"];
  79. $contact_category = $row["contact_category"];
  80. $contact_role = $row["contact_role"];
  81. $contact_time_zone = $row["contact_time_zone"];
  82. $contact_note = $row["contact_note"];
  83. }
  84. unset($sql, $parameters, $row);
  85. //check contact permisions if this is set to enabled. default is false
  86. if ($_SESSION['contact']['permissions']['boolean'] == "true") {
  87. //get the available users for this contact
  88. $sql = "select * from v_users ";
  89. $sql .= "where domain_uuid = :domain_uuid ";
  90. $sql .= "order by username asc ";
  91. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  92. $database = new database;
  93. $users = $database->select($sql, $parameters ?? null, 'all');
  94. unset($sql, $parameters);
  95. //determine if contact assigned to a user
  96. if (!empty($users)) {
  97. foreach ($users as $user) {
  98. if ($user['contact_uuid'] == $contact_uuid) {
  99. $contact_user_uuid = $user['user_uuid'];
  100. break;
  101. }
  102. }
  103. }
  104. //get the assigned users that can view this contact
  105. $sql = "select u.username, u.user_uuid, a.contact_user_uuid from v_contacts as c, v_users as u, v_contact_users as a ";
  106. $sql .= "where c.contact_uuid = :contact_uuid ";
  107. $sql .= "and c.domain_uuid = :domain_uuid ";
  108. $sql .= "and u.user_uuid = a.user_uuid ";
  109. $sql .= "and c.contact_uuid = a.contact_uuid ";
  110. $sql .= "order by u.username asc ";
  111. $parameters['contact_uuid'] = $contact_uuid;
  112. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  113. $database = new database;
  114. $contact_users_assigned = $database->select($sql, $parameters, 'all');
  115. unset($sql, $parameters);
  116. //get the assigned groups that can view this contact
  117. $sql = "select g.*, cg.contact_group_uuid ";
  118. $sql .= "from v_groups as g, v_contact_groups as cg ";
  119. $sql .= "where cg.group_uuid = g.group_uuid ";
  120. $sql .= "and cg.domain_uuid = :domain_uuid ";
  121. $sql .= "and cg.contact_uuid = :contact_uuid ";
  122. $sql .= "and cg.group_uuid <> :group_uuid ";
  123. $sql .= "order by g.group_name asc ";
  124. $parameters['domain_uuid'] = $domain_uuid;
  125. $parameters['contact_uuid'] = $contact_uuid;
  126. $parameters['group_uuid'] = $_SESSION["user_uuid"];
  127. $database = new database;
  128. $contact_groups_assigned = $database->select($sql, $parameters, 'all');
  129. if (!empty($contact_groups_assigned)) {
  130. foreach ($contact_groups_assigned as $field) {
  131. $contact_groups[] = "'".$field['group_uuid']."'";
  132. }
  133. }
  134. unset($sql, $parameters);
  135. //get the available groups for this contact
  136. $sql = "select group_uuid, group_name from v_groups ";
  137. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  138. if (!empty($contact_groups)) {
  139. $sql .= "and group_uuid not in (".implode(',', $contact_groups).") ";
  140. }
  141. $sql .= "order by group_name asc ";
  142. $parameters['domain_uuid'] = $domain_uuid;
  143. $database = new database;
  144. $contact_groups_available = $database->select($sql, $parameters, 'all');
  145. unset($sql, $parameters, $contact_groups);
  146. }
  147. //determine title name
  148. if ($contact_name_given || $contact_name_family) {
  149. $contact_name = $contact_name_prefix ? escape($contact_name_prefix).' ' : null;
  150. $contact_name .= $contact_name_given ? escape($contact_name_given).' ' : null;
  151. $contact_name .= $contact_name_middle ? escape($contact_name_middle).' ' : null;
  152. $contact_name .= $contact_name_family ? escape($contact_name_family).' ' : null;
  153. $contact_name .= $contact_name_suffix ? escape($contact_name_suffix).' ' : null;
  154. }
  155. else {
  156. $contact_name = $contact_organization;
  157. }
  158. //show the content
  159. echo "<!DOCTYPE html>\n";
  160. echo "<html>\n";
  161. echo "<head>\n";
  162. echo "<meta charset='utf-8'>\n";
  163. echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n";
  164. echo "<meta http-equiv='X-UA-Compatible' content='IE=edge'>\n";
  165. echo "<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />\n";
  166. echo "<meta name='robots' content='noindex, nofollow, noarchive' />\n";
  167. echo "<link rel='stylesheet' type='text/css' href='".PROJECT_PATH."/resources/fontawesome/css/all.min.css.php'>\n";
  168. echo "<link rel='stylesheet' type='text/css' href='".PROJECT_PATH."/resources/bootstrap/css/bootstrap.min.css.php'>\n";
  169. echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/fontawesome/js/solid.min.js.php' defer></script>\n";
  170. echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/bootstrap/js/bootstrap.min.js.php'></script>\n";
  171. //css
  172. echo "<link rel='stylesheet' type='text/css' href='/themes/default/css.php'>\n";
  173. echo "<style>\n";
  174. echo " body {\n";
  175. echo " margin-right: 0;\n";
  176. echo " }\n";
  177. echo " div.box.contact-details {\n";
  178. echo " padding: 10px !important;\n";
  179. echo " }\n";
  180. echo "</style>\n";
  181. //end the header and start the body
  182. echo "</head>\n";
  183. echo "<body>\n";
  184. echo "<div id='main_content' style='margin-top: 0; width: calc(100% - 10px); padding-right: 0;'>\n";
  185. //show the content
  186. echo "<div class='action_bar' id='action_bar' style='position: relative; top: 0; width: calc(100% + 13px); margin-left: -10px; padding-right: 0; margin-bottom: 0;'>\n";
  187. echo " <div class='heading'><b>".($contact_name ? $contact_name : $text['header-contact-edit'])."</b></div>\n";
  188. echo " <div class='actions'>\n";
  189. if (!empty($contact_user_uuid) && permission_exists('user_edit') && is_uuid($contact_user_uuid)) {
  190. echo button::create(['type'=>'button','label'=>$text['button-user'],'icon'=>'user','collapse'=>'hide-sm-dn','link'=>'../../core/users/user_edit.php?id='.urlencode($contact_user_uuid)]);
  191. }
  192. if (permission_exists('contact_edit')) {
  193. echo button::create(['type'=>'button','label'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'id'=>'btn_edit','style'=>'margin-left: 15px; margin-right: 0;','onclick'=>"window.open('../contacts/contact_edit.php?id=".urlencode($contact_uuid)."');"]);
  194. }
  195. echo " </div>\n";
  196. echo " <div style='clear: both;'></div>\n";
  197. echo "</div>\n";
  198. if ($contact_title || $contact_organization) {
  199. echo ($contact_title ? '<i>'.$contact_title.'</i>' : null).($contact_title && $contact_organization ? ', ' : null).($contact_organization ? '<strong>'.$contact_organization.'</strong>' : null)."\n";
  200. }
  201. else {
  202. echo $contact_note."\n";
  203. }
  204. echo "<br />\n";
  205. echo "<div class='grid' style='grid-gap: 10px; grid-template-columns: auto;'>\n";
  206. //general info
  207. echo " <div class='box contact-details'>\n";
  208. echo " <div class='grid contact-details'>\n";
  209. echo " <div class='box'><b class='fas fa-user fa-fw fa-md'></b></div>\n";
  210. echo " <div class='box'>\n";
  211. echo " <div class='grid' style='grid-template-columns: 70px auto;'>\n";
  212. //nickname
  213. if ($contact_nickname) {
  214. echo "<div class='box contact-details-label'>".$text['label-contact_nickname']."</div>\n";
  215. echo "<div class='box'>\"".escape($contact_nickname)."\"</div>\n";
  216. }
  217. //name
  218. if ($contact_name_given) {
  219. echo "<div class='box contact-details-label'>".$text['label-name']."</div>\n";
  220. echo "<div class='box'>".escape($contact_name_given).(!empty($contact_name_family) ? ' '.escape($contact_name_family) : null)."</div>\n";
  221. }
  222. //contact type
  223. if ($contact_type) {
  224. echo "<div class='box contact-details-label'>".$text['label-contact_type']."</div>\n";
  225. echo "<div class='box'>";
  226. if (!empty($_SESSION["contact"]["type"])) {
  227. sort($_SESSION["contact"]["type"]);
  228. foreach ($_SESSION["contact"]["type"] as $type) {
  229. if ($contact_type == $type) {
  230. echo escape($type);
  231. }
  232. }
  233. }
  234. else if ($text['option-contact_type_'.$contact_type]) {
  235. echo $text['option-contact_type_'.$contact_type];
  236. }
  237. else {
  238. echo escape($contact_type);
  239. }
  240. echo "</div>\n";
  241. }
  242. //category
  243. if ($contact_category) {
  244. echo "<div class='box contact-details-label'>".$text['label-contact_category']."</div>\n";
  245. echo "<div class='box'>";
  246. if (!empty($_SESSION["contact"]["category"])) {
  247. sort($_SESSION["contact"]["category"]);
  248. foreach ($_SESSION["contact"]["category"] as $category) {
  249. if ($contact_category == $category) {
  250. echo escape($category);
  251. break;
  252. }
  253. }
  254. }
  255. else {
  256. echo escape($contact_category);
  257. }
  258. echo "</div>\n";
  259. }
  260. //role
  261. if ($contact_role) {
  262. echo "<div class='box contact-details-label'>".$text['label-contact_role']."</div>\n";
  263. echo "<div class='box'>";
  264. if (!empty($_SESSION["contact"]["role"])) {
  265. sort($_SESSION["contact"]["role"]);
  266. foreach ($_SESSION["contact"]["role"] as $role) {
  267. if ($contact_role == $role) {
  268. echo escape($role);
  269. break;
  270. }
  271. }
  272. }
  273. else {
  274. echo escape($contact_role);
  275. }
  276. echo "</div>\n";
  277. }
  278. //time_zone
  279. if ($contact_time_zone) {
  280. echo "<div class='box contact-details-label'>".$text['label-contact_time_zone']."</div>\n";
  281. echo "<div class='box'>";
  282. echo $contact_time_zone."<br>\n";
  283. echo "</div>\n";
  284. }
  285. //users (viewing contact)
  286. if (permission_exists('contact_user_view') && !empty($contact_users_assigned)) {
  287. echo "<div class='box contact-details-label'>".$text['label-users']."</div>\n";
  288. echo "<div class='box'>";
  289. foreach ($contact_users_assigned as $field) {
  290. echo escape($field['username'])."<br>\n";
  291. }
  292. echo "</div>\n";
  293. }
  294. //groups (viewing contact)
  295. if (permission_exists('contact_group_view') && !empty($contact_groups_assigned)) {
  296. echo "<div class='box contact-details-label'>".$text['label-groups']."</div>\n";
  297. echo "<div class='box'>";
  298. foreach ($contact_groups_assigned as $field) {
  299. echo escape($field['group_name'])."<br>\n";
  300. }
  301. echo "</div>\n";
  302. }
  303. echo " </div>\n";
  304. echo " </div>\n";
  305. echo " </div>\n";
  306. echo " </div>\n";
  307. //numbers
  308. if (permission_exists('contact_phone_view')) {
  309. echo " <div class='box contact-details'>\n";
  310. echo " <div class='grid contact-details'>\n";
  311. echo " <div class='box' title=\"".$text['label-phone_numbers']."\"><b class='fas fa-hashtag fa-fw fa-lg'></b></div>\n";
  312. echo " <div class='box'>\n";
  313. require 'app/contacts/contact_phones_view.php';
  314. echo " </div>\n";
  315. echo " </div>\n";
  316. echo " </div>\n";
  317. }
  318. //emails
  319. if (permission_exists('contact_email_view')) {
  320. echo " <div class='box contact-details'>\n";
  321. echo " <div class='grid contact-details'>\n";
  322. echo " <div class='box' title=\"".$text['label-emails']."\"><b class='fas fa-envelope fa-fw fa-lg'></b></div>\n";
  323. echo " <div class='box'>\n";
  324. require 'app/contacts/contact_emails_view.php';
  325. echo " </div>\n";
  326. echo " </div>\n";
  327. echo " </div>\n";
  328. }
  329. //addresses
  330. if (permission_exists('contact_address_view')) {
  331. echo " <div class='box contact-details'>\n";
  332. echo " <div class='grid contact-details'>\n";
  333. echo " <div class='box' title=\"".$text['label-addresses']."\"><b class='fas fa-map-marker-alt fa-fw fa-lg'></b></div>\n";
  334. echo " <div class='box'>\n";
  335. require 'app/contacts/contact_addresses_view.php';
  336. echo " </div>\n";
  337. echo " </div>\n";
  338. echo " </div>\n";
  339. }
  340. //urls
  341. if (permission_exists('contact_url_view')) {
  342. echo " <div class='box contact-details'>\n";
  343. echo " <div class='grid contact-details'>\n";
  344. echo " <div class='box' title=\"".$text['label-urls']."\"><b class='fas fa-link fa-fw fa-lg'></b></div>\n";
  345. echo " <div class='box'>\n";
  346. require "app/contacts/contact_urls_view.php";
  347. echo " </div>\n";
  348. echo " </div>\n";
  349. echo " </div>\n";
  350. }
  351. //relations
  352. if (permission_exists('contact_relation_view')) {
  353. echo " <div class='box contact-details'>\n";
  354. echo " <div class='grid contact-details'>\n";
  355. echo " <div class='box' title=\"".$text['header-contact_relations']."\"><b class='fas fa-project-diagram fa-fw fa-lg'></b></div>\n";
  356. echo " <div class='box'>\n";
  357. require "app/contacts/contact_relations_view.php";
  358. echo " </div>\n";
  359. echo " </div>\n";
  360. echo " </div>\n";
  361. }
  362. //attachments
  363. if (permission_exists('contact_attachment_view')) {
  364. echo " <div class='box contact-details'>\n";
  365. echo " <div class='grid contact-details'>\n";
  366. echo " <div class='box' title=\"".$text['label-attachments']."\"><b class='fas fa-paperclip fa-fw fa-lg'></b></div>\n";
  367. echo " <div class='box'>\n";
  368. require "app/contacts/contact_attachments_view.php";
  369. echo " </div>\n";
  370. echo " </div>\n";
  371. echo " </div>\n";
  372. }
  373. //times
  374. if (permission_exists('contact_time_view')) {
  375. echo " <div class='box contact-details'>\n";
  376. echo " <div class='grid contact-details'>\n";
  377. echo " <div class='box' title=\"".$text['header_contact_times']."\"><b class='fas fa-clock fa-fw fa-lg'></b></div>\n";
  378. echo " <div class='box'>\n";
  379. require "app/contacts/contact_times_view.php";
  380. echo " </div>\n";
  381. echo " </div>\n";
  382. echo " </div>\n";
  383. }
  384. //extensions
  385. if (permission_exists('contact_extension_view')) {
  386. echo " <div class='box contact-details'>\n";
  387. echo " <div class='grid contact-details'>\n";
  388. echo " <div class='box' title=\"".$text['label-contact_extensions']."\"><b class='fas fa-fax fa-fw fa-lg'></b></div>\n";
  389. echo " <div class='box'>\n";
  390. require "app/contacts/contact_extensions_view.php";
  391. echo " </div>\n";
  392. echo " </div>\n";
  393. echo " </div>\n";
  394. }
  395. //notes
  396. if (permission_exists('contact_note_view')) {
  397. echo " <div class='box contact-details'>\n";
  398. echo " <div class='grid contact-details'>\n";
  399. echo " <div class='box' title=\"".$text['label-contact_notes']."\"><b class='fas fa-sticky-note fa-fw fa-lg'></b></div>\n";
  400. echo " <div class='box'>\n";
  401. require "app/contacts/contact_notes_view.php";
  402. echo " </div>\n";
  403. echo " </div>\n";
  404. echo " </div>\n";
  405. }
  406. echo "</div>\n";
  407. echo "</body>\n";
  408. echo "</html>\n";
  409. ?>