contacts_vcard.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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) 2008-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('contact_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. if (is_array($_GET) && @sizeof($_GET) != 0) {
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //create the vcard object
  36. require_once "resources/classes/vcard.php";
  37. $vcard = new vcard();
  38. //get the contact id
  39. $contact_uuid = $_GET["id"];
  40. //get the contact's information
  41. $sql = "select * from v_contacts ";
  42. $sql .= "where domain_uuid = :domain_uuid ";
  43. $sql .= "and contact_uuid = :contact_uuid ";
  44. $parameters['domain_uuid'] = $domain_uuid;
  45. $parameters['contact_uuid'] = $contact_uuid;
  46. $database = new database;
  47. $row = $database->select($sql, $parameters, 'row');
  48. if (is_array($row) && @sizeof($row) != 0) {
  49. $contact_type = $row["contact_type"];
  50. $contact_organization = $row["contact_organization"];
  51. $contact_name_given = $row["contact_name_given"];
  52. $contact_name_family = $row["contact_name_family"];
  53. $contact_nickname = $row["contact_nickname"];
  54. $contact_title = $row["contact_title"];
  55. $contact_role = $row["contact_role"];
  56. $contact_time_zone = $row["contact_time_zone"];
  57. $contact_note = $row["contact_note"];
  58. }
  59. unset($sql, $parameters, $row);
  60. $vcard->data['company'] = $contact_organization;
  61. $vcard->data['first_name'] = $contact_name_given;
  62. $vcard->data['last_name'] = $contact_name_family;
  63. //get the contact's primary (and a secondary, if available) email
  64. $sql = "select email_address from v_contact_emails ";
  65. $sql .= "where domain_uuid = :domain_uuid ";
  66. $sql .= "and contact_uuid = :contact_uuid ";
  67. $sql .= "order by email_primary desc ";
  68. $parameters['domain_uuid'] = $domain_uuid;
  69. $parameters['contact_uuid'] = $contact_uuid;
  70. $database = new database;
  71. $result = $database->select($sql, $parameters, 'all');
  72. if (is_array($result) && @sizeof($result) != 0) {
  73. $e = 1;
  74. foreach ($result as &$row) {
  75. $vcard->data['email'.$e] = $row["email_address"];
  76. if ($e++ == 2) { break; } //limit to 2 rows
  77. }
  78. }
  79. unset($sql, $parameters, $result, $row);
  80. //get the contact's primary url
  81. $sql = "select url_address from v_contact_urls ";
  82. $sql .= "where domain_uuid = :domain_uuid ";
  83. $sql .= "and contact_uuid = :contact_uuid ";
  84. $sql .= "and url_primary = 1 ";
  85. $parameters['domain_uuid'] = $domain_uuid;
  86. $parameters['contact_uuid'] = $contact_uuid;
  87. $database = new database;
  88. $url_address = $database->select($sql, $parameters, 'column');
  89. $vcard->data['url'] = $url_address;
  90. unset($sql, $parameters, $row);
  91. if ($_GET['type'] == "image" || $_GET['type'] == "html") {
  92. //don't add this to the QR code at this time
  93. }
  94. else {
  95. $vcard->data['display_name'] = $contact_name_given." ".$contact_name_family;
  96. $vcard->data['contact_nickname'] = $contact_nickname;
  97. $vcard->data['contact_title'] = $contact_title;
  98. $vcard->data['contact_role'] = $contact_role;
  99. $vcard->data['timezone'] = $contact_time_zone;
  100. $vcard->data['contact_note'] = $contact_note;
  101. }
  102. //get the contact's telephone numbers
  103. $sql = "select * from v_contact_phones ";
  104. $sql .= "where domain_uuid = :domain_uuid ";
  105. $sql .= "and contact_uuid = :contact_uuid ";
  106. $parameters['domain_uuid'] = $domain_uuid;
  107. $parameters['contact_uuid'] = $contact_uuid;
  108. $database = new database;
  109. $result = $database->select($sql, $parameters, 'all');
  110. if (is_array($result) && @sizeof($result) != 0) {
  111. foreach ($result as &$row) {
  112. $phone_label = $row["phone_label"];
  113. $phone_number = $row["phone_number"];
  114. if ($phone_label == $text['option-work']) { $vcard_phone_type = 'work'; }
  115. else if ($phone_label == $text['option-home']) { $vcard_phone_type = 'home'; }
  116. else if ($phone_label == $text['option-mobile']) { $vcard_phone_type = 'cell'; }
  117. else if ($phone_label == $text['option-fax']) { $vcard_phone_type = 'fax'; }
  118. else if ($phone_label == $text['option-pager']) { $vcard_phone_type = 'pager'; }
  119. else { $vcard_phone_type = 'voice'; }
  120. if ($vcard_phone_type != '') {
  121. $vcard->data[$vcard_phone_type.'_tel'] = $phone_number;
  122. }
  123. }
  124. }
  125. unset($sql, $parameters, $result, $row);
  126. //get the contact's addresses
  127. if ($_GET['type'] == "image" || $_GET['type'] == "html") {
  128. //don't add this to the QR code at this time
  129. }
  130. else {
  131. $sql = "select * from v_contact_addresses ";
  132. $sql .= "where domain_uuid = :domain_uuid ";
  133. $sql .= "and contact_uuid = :contact_uuid ";
  134. $parameters['domain_uuid'] = $domain_uuid;
  135. $parameters['contact_uuid'] = $contact_uuid;
  136. $database = new database;
  137. $result = $database->select($sql, $parameters, 'all');
  138. if (is_array($result) && @sizeof($result) != 0) {
  139. foreach ($result as &$row) {
  140. $address_type = $row["address_type"];
  141. $address_street = $row["address_street"];
  142. $address_extended = $row["address_extended"];
  143. $address_locality = $row["address_locality"];
  144. $address_region = $row["address_region"];
  145. $address_postal_code = $row["address_postal_code"];
  146. $address_country = $row["address_country"];
  147. $address_latitude = $row["address_latitude"];
  148. $address_longitude = $row["address_longitude"];
  149. $address_type = strtolower(trim($address_type));
  150. $vcard->data[$address_type.'_address'] = $address_street;
  151. $vcard->data[$address_type.'_extended_address'] = $address_extended;
  152. $vcard->data[$address_type.'_city'] = $address_locality;
  153. $vcard->data[$address_type.'_state'] = $address_region;
  154. $vcard->data[$address_type.'_postal_code'] = $address_postal_code;
  155. $vcard->data[$address_type.'_country'] = $address_country;
  156. }
  157. }
  158. unset($sql, $parameters, $result, $row);
  159. }
  160. //download the vcard
  161. if ($_GET['type'] == "download") {
  162. $vcard->download();
  163. }
  164. //show the vcard in a text qr code
  165. if ($_GET['type'] == "text") {
  166. $vcard->build();
  167. $content = $vcard->card;
  168. if ($qr_vcard) {
  169. $qr_vcard = $content;
  170. }
  171. else {
  172. echo $content;
  173. }
  174. }
  175. //show the vcard in an image qr code
  176. if ($_GET['type'] == "image" || $_GET['type'] == "html") {
  177. $vcard->build();
  178. $content = $vcard->card;
  179. if (isset($_GET['debug'])) {
  180. echo "<pre>";
  181. print_r($vcard->data);
  182. echo "</pre>";
  183. exit;
  184. }
  185. //include
  186. require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/qr/qrcode.php";
  187. //error correction level
  188. //QR_ERROR_CORRECT_LEVEL_L : $e = 0;
  189. //QR_ERROR_CORRECT_LEVEL_M : $e = 1;
  190. //QR_ERROR_CORRECT_LEVEL_Q : $e = 2;
  191. //QR_ERROR_CORRECT_LEVEL_H : $e = 3;
  192. //get the qr object
  193. $qr = QRCode::getMinimumQRCode($content, QR_ERROR_CORRECT_LEVEL_L);
  194. }
  195. //show the vcard as an png image
  196. if ($_GET['type'] == "image") {
  197. header("Content-type: image/png");
  198. $im = $qr->createImage(5, 10);
  199. imagepng($im);
  200. imagedestroy($im);
  201. }
  202. //show the vcard in an html qr code
  203. if ($_GET['type'] == "html") {
  204. $qr->make();
  205. $qr->printHTML();
  206. }
  207. }
  208. /*
  209. //additional un accounted fields
  210. additional_name
  211. name_prefix
  212. name_suffix
  213. department
  214. work_po_box
  215. home_po_box
  216. home_extended_address
  217. home_address
  218. home_city
  219. home_state
  220. home_postal_code
  221. home_country
  222. pager_tel
  223. contact_email2
  224. photo
  225. birthday
  226. sort_string
  227. */
  228. ?>