message_contact.php 16 KB

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