message_contact.php 17 KB

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