message_contact.php 15 KB

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