contact_import_google.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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-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. require_once "resources/functions/google_get_groups.php";
  25. require_once "resources/functions/google_get_contacts.php";
  26. //check permissions
  27. if (permission_exists('contact_add')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //handle import
  38. if ($_POST['a'] == 'import') {
  39. if (sizeof($_POST['group_id']) > 0) {
  40. //get contact ids for those in the submitted groups
  41. if (sizeof($_SESSION['contact_auth']['google']) > 0) {
  42. foreach ($_SESSION['contact_auth']['google'] as $contact['id'] => $contact) {
  43. foreach ($contact['groups'] as $contact_group['id'] => $meh) {
  44. if (in_array($contact_group['id'], $_POST['group_id'])) {
  45. $import_ids[] = $contact['id'];
  46. }
  47. }
  48. }
  49. }
  50. }
  51. if (sizeof($_POST['contact_id']) > 0) {
  52. foreach ($_POST['contact_id'] as $contact_id) {
  53. $import_ids[] = $contact_id;
  54. }
  55. }
  56. //iterate selected contact ids, insert contact into database
  57. $contacts_imported = 0;
  58. $contacts_skipped = 0;
  59. $contacts_replaced = 0;
  60. if (sizeof($import_ids) > 0) {
  61. $import_ids = array_unique($import_ids);
  62. foreach ($import_ids as $index_1 => $contact_id) {
  63. //check for duplicate contact (already exists, previously imported, etc)
  64. $sql = "select contact_uuid from v_contact_settings ";
  65. $sql .= "where domain_uuid = :domain_uuid ";
  66. $sql .= "and contact_setting_category = 'google' ";
  67. $sql .= "and contact_setting_subcategory = 'id' ";
  68. $sql .= "and contact_setting_value = :contact_setting_value ";
  69. $sql .= "and contact_setting_enabled = 'true' ";
  70. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  71. $parameters['contact_setting_value'] = $contact_id;
  72. $database = new database;
  73. $result = $database->select($sql, $parameters, 'row');
  74. if (is_uuid($result['contact_uuid'])) {
  75. $duplicate_exists = true;
  76. $duplicate_contact_uuid = $result['contact_uuid'];
  77. }
  78. else {
  79. $duplicate_exists = false;
  80. }
  81. unset($sql, $parameters, $result);
  82. //skip importing contact
  83. if ($duplicate_exists && $_POST['import_duplicates'] == 'skip') {
  84. $contacts_skipped++;
  85. continue;
  86. }
  87. //replace contact (delete before inserts below)
  88. else if ($duplicate_exists && $_POST['import_duplicates'] == 'replace') {
  89. //build array
  90. $array[0]['checked'] = 'true';
  91. $array[0]['uuid'] = $duplicate_contact_uuid;
  92. unset($duplicate_contact_uuid);
  93. //grant temporary permissions
  94. $p = permissions::new();
  95. $p->add('contact_delete', 'temp');
  96. //delete duplicate contact
  97. $obj = new contacts;
  98. $obj->delete($array);
  99. unset($array);
  100. //revoke temporary permissions
  101. $p->delete('contact_delete', 'temp');
  102. //increase counter
  103. $contacts_replaced++;
  104. }
  105. //extract contact record from array using contact id
  106. $contact = $_SESSION['contact_auth']['google'][$contact_id];
  107. //insert contact
  108. $contact_uuid = uuid();
  109. $array['contacts'][$index_1]['domain_uuid'] = $_SESSION['domain_uuid'];
  110. $array['contacts'][$index_1]['contact_uuid'] = $contact_uuid;
  111. $array['contacts'][$index_1]['contact_type'] = $_POST['import_type'];
  112. $array['contacts'][$index_1]['contact_organization'] = $contact['organization'];
  113. $array['contacts'][$index_1]['contact_name_prefix'] = $contact['name_prefix'];
  114. $array['contacts'][$index_1]['contact_name_given'] = $contact['name_given'];
  115. $array['contacts'][$index_1]['contact_name_middle'] = $contact['name_middle'];
  116. $array['contacts'][$index_1]['contact_name_family'] = $contact['name_family'];
  117. $array['contacts'][$index_1]['contact_name_suffix'] = $contact['name_suffix'];
  118. $array['contacts'][$index_1]['contact_nickname'] = $contact['nickname'];
  119. $array['contacts'][$index_1]['contact_title'] = $contact['title'];
  120. $array['contacts'][$index_1]['contact_category'] = $_POST['import_category'];
  121. $array['contacts'][$index_1]['contact_note'] = $contact['notes'];
  122. //set sharing
  123. if ($_POST['import_shared'] != 'true') {
  124. $contact_group_uuid = uuid();
  125. $array['contact_groups'][$index_1]['contact_group_uuid'] = $contact_group_uuid;
  126. $array['contact_groups'][$index_1]['domain_uuid'] = $_SESSION['domain_uuid'];
  127. $array['contact_groups'][$index_1]['contact_uuid'] = $contact_uuid;
  128. $array['contact_groups'][$index_1]['group_uuid'] = $_SESSION["user_uuid"];
  129. }
  130. //insert emails
  131. if (!empty($contact['emails']) && $_POST['import_fields']['email']) {
  132. foreach ($contact['emails'] as $index_2 => $contact_email) {
  133. $contact_email_uuid = uuid();
  134. $array['contact_emails'][$index_2]['domain_uuid'] = $_SESSION['domain_uuid'];
  135. $array['contact_emails'][$index_2]['contact_uuid'] = $contact_uuid;
  136. $array['contact_emails'][$index_2]['contact_email_uuid'] = $contact_email_uuid;
  137. $array['contact_emails'][$index_2]['email_label'] = $contact_email['label'];
  138. $array['contact_emails'][$index_2]['email_address'] = $contact_email['address'];
  139. $array['contact_emails'][$index_2]['email_primary'] = $contact_email['primary'] ? 1 : 0;
  140. }
  141. }
  142. //insert numbers
  143. if (!empty($contact['numbers']) && $_POST['import_fields']['number']) {
  144. foreach ($contact['numbers'] as $index_3 => $contact_number) {
  145. $contact_phone_uuid = uuid();
  146. $array['contact_phones'][$index_3]['domain_uuid'] = $domain_uuid;
  147. $array['contact_phones'][$index_3]['contact_uuid'] = $contact_uuid;
  148. $array['contact_phones'][$index_3]['contact_phone_uuid'] = $contact_phone_uuid;
  149. $array['contact_phones'][$index_3]['phone_type_voice'] = substr_count(strtoupper($contact_number['label']), strtoupper($text['label-fax'])) == 0 ? 1 : null;
  150. $array['contact_phones'][$index_3]['phone_type_fax'] = substr_count(strtoupper($contact_number['label']), strtoupper($text['label-fax'])) != 0 ? 1 : null;
  151. $array['contact_phones'][$index_3]['phone_label'] = $contact_number['label'];
  152. $array['contact_phones'][$index_3]['phone_number'] = $contact_number['number'];
  153. $array['contact_phones'][$index_3]['phone_primary'] = @sizeof($contact['numbers']) == 1 ? 1 : 0;
  154. }
  155. }
  156. //insert urls
  157. if (!empty($contact['urls']) && $_POST['import_fields']['url']) {
  158. foreach ($contact['urls'] as $index_4 => $contact_url) {
  159. $contact_url_uuid = uuid();
  160. $array['contact_urls'][$index_4]['domain_uuid'] = $_SESSION['domain_uuid'];
  161. $array['contact_urls'][$index_4]['contact_uuid'] = $contact_uuid;
  162. $array['contact_urls'][$index_4]['contact_url_uuid'] = $contact_url_uuid;
  163. $array['contact_urls'][$index_4]['url_label'] = $contact_url['label'];
  164. $array['contact_urls'][$index_4]['url_address'] = $contact_url['url'];
  165. $array['contact_urls'][$index_4]['url_primary'] = @sizeof($contact['urls']) == 1 ? 1 : 0;
  166. }
  167. }
  168. //insert addresses
  169. if (!empty($contact['addresses']) && $_POST['import_fields']['address']) {
  170. foreach ($contact['addresses'] as $index_5 => $contact_address) {
  171. $contact_address_uuid = uuid();
  172. $array['contact_addresses'][$index_5]['domain_uuid'] = $_SESSION['domain_uuid'];
  173. $array['contact_addresses'][$index_5]['contact_uuid'] = $contact_uuid;
  174. $array['contact_addresses'][$index_5]['contact_address_uuid'] = $contact_address_uuid;
  175. if (substr_count(strtoupper($contact_address['label']), strtoupper($text['option-home'])) != 0) {
  176. $array['contact_addresses'][$index_5]['address_type'] = 'home';
  177. }
  178. else if (substr_count(strtoupper($contact_address['label']), strtoupper($text['option-work'])) != 0) {
  179. $array['contact_addresses'][$index_5]['address_type'] = 'work';
  180. }
  181. else {
  182. $array['contact_addresses'][$index_5]['address_type'] = null;
  183. }
  184. $array['contact_addresses'][$index_5]['address_label'] = $contact_address['label'];
  185. $array['contact_addresses'][$index_5]['address_street'] = $contact_address['street'];
  186. $array['contact_addresses'][$index_5]['address_extended'] = $contact_address['extended'];
  187. $array['contact_addresses'][$index_5]['address_community'] = $contact_address['community'];
  188. $array['contact_addresses'][$index_5]['address_locality'] = $contact_address['locality'];
  189. $array['contact_addresses'][$index_5]['address_region'] = $contact_address['region'];
  190. $array['contact_addresses'][$index_5]['address_postal_code'] = $contact_address['postal_code'];
  191. $array['contact_addresses'][$index_5]['address_country'] = $contact_address['country'];
  192. $array['contact_addresses'][$index_5]['address_primary'] = @sizeof($contact['addresses']) == 1 ? 1 : 0;
  193. }
  194. }
  195. //add google contact id, etag and updated date to contact settings
  196. $contact['updated'] = str_replace('T', ' ', $contact['updated']);
  197. $contact['updated'] = str_replace('Z', '', $contact['updated']);
  198. $contact_setting_columns = array('contact_setting_category', 'contact_setting_subcategory', 'contact_setting_name', 'contact_setting_value', 'contact_setting_order', 'contact_setting_enabled');
  199. $contact_setting_array[] = array('sync', 'source', 'array', 'google', 0, 'true');
  200. $contact_setting_array[] = array('google', 'id', 'text', $contact_id, 0, 'true');
  201. $contact_setting_array[] = array('google', 'updated', 'date', $contact['updated'], 0, 'true');
  202. $contact_setting_array[] = array('google', 'etag', 'text', $contact['etag'], 0, 'true');
  203. foreach ($contact_setting_array as $index_6 => $values) {
  204. $contact_setting_uuid = uuid();
  205. $array['contact_settings'][$index_6]['contact_setting_uuid'] = $contact_setting_uuid;
  206. $array['contact_settings'][$index_6]['contact_uuid'] = $contact_uuid;
  207. $array['contact_settings'][$index_6]['domain_uuid'] = $_SESSION['domain_uuid'];
  208. foreach ($values as $index_7 => $value) {
  209. foreach ($contact_setting_columns as $column) {
  210. $array['contact_settings'][$index_6][$contact_setting_columns[$index_7]] = $value;
  211. }
  212. }
  213. }
  214. unset($contact_setting_columns, $contact_setting_array);
  215. //insert records
  216. $database = new database;
  217. $database->app_name = 'contacts';
  218. $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c';
  219. $database->save($array);
  220. unset($array);
  221. //increment counter
  222. $contacts_imported++;
  223. }
  224. $message = $text['message-contacts_imported']." ".$contacts_imported;
  225. if ($contacts_replaced > 0) { $message .= " (".$text['message_contacts_imported_replaced']." ".$contacts_replaced.")"; }
  226. if ($contacts_skipped > 0) { $message .= ", ".$text['message_contacts_imported_skipped']." ".$contacts_skipped; }
  227. message::add($message);
  228. header("Location: contacts.php");
  229. exit;
  230. }
  231. else {
  232. // no contacts imported
  233. message::add($text['message-contacts_imported']." ".$contacts_imported, 'negative');
  234. }
  235. }
  236. //*******************************************************************************************
  237. //check if authenticated
  238. if (empty($_SESSION['contact_auth']['token'])) {
  239. $_SESSION['contact_auth']['referer'] = substr($_SERVER["HTTP_REFERER"], strrpos($_SERVER["HTTP_REFERER"],'/')+1);
  240. header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
  241. exit;
  242. }
  243. unset($_SESSION['contact_auth']['source'], $_SESSION['contact_auth']['target']);
  244. //get groups & contacts
  245. $groups = google_get_groups($_SESSION['contact_auth']['token']);
  246. $contacts = google_get_contacts($_SESSION['contact_auth']['token'], 1000);
  247. //store in session variable for use on import
  248. $_SESSION['contact_auth']['google'] = $contacts;
  249. //include the header
  250. $document['title'] = $text['title-contacts_import_google'];
  251. require_once "resources/header.php";
  252. echo "<table cellpadding='0' cellspacing='0' border='0' align='right'>";
  253. echo " <tr>";
  254. echo " <td style='text-align: right;'>";
  255. echo " <input type='button' class='btn' id='btn_back' onclick=\"document.location.href='contact_import.php';\" value=\"".$text['button-back']."\">";
  256. echo " <input type='button' class='btn' id='btn_refresh' onclick='document.location.reload();' value=\"".$text['button-reload']."\">";
  257. echo " <input type='button' class='btn' id='btn_signout' onclick=\"document.location.href='contact_auth.php?source=google&signout'\" value=\"".$text['button-sign_out']."\">";
  258. echo " </td>";
  259. echo " </tr>";
  260. echo " <tr>";
  261. echo " <td style='text-align: right; white-space: nowrap; padding-top: 8px;'><span style='font-weight: bold; color: #000;'>".$_SESSION['contact_auth']['name']."</a> (<a href='https://www.google.com/contacts/#contacts' target='_blank'>".$_SESSION['contact_auth']['email']."</a>)"."</td>";
  262. echo " </tr>";
  263. echo "</table>";
  264. echo "<b>".$text['header-contacts_import_google']."</b>";
  265. echo "<br><br>";
  266. echo $text['description-contacts_import_google'];
  267. echo "<br><br><br>";
  268. $row_style["0"] = "row_style0";
  269. $row_style["1"] = "row_style1";
  270. echo "<form name='frm_import' id='frm_import' method='post'>\n";
  271. echo "<input type='hidden' name='a' value='import'>\n";
  272. echo "<div class='card'>\n";
  273. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  274. echo "<tr>\n";
  275. echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  276. echo " ".$text['label-import_fields']."\n";
  277. echo "</td>\n";
  278. echo "<td width='70%' class='vtable' align='left'>\n";
  279. echo " <input type='checkbox' disabled='disabled' checked>&nbsp;".$text['label-contact_name']."&nbsp;\n";
  280. echo " <input type='checkbox' disabled='disabled' checked>&nbsp;".$text['label-contact_organization']."&nbsp;\n";
  281. echo " <input type='checkbox' name='import_fields[email]' id='field_email' value='1' checked><label for='field_email'>&nbsp;".$text['label-contact_email']."</label>&nbsp;\n";
  282. echo " <input type='checkbox' name='import_fields[number]' id='field_number' value='1' checked><label for='field_number'>&nbsp;".$text['label-phone_number']."</label>&nbsp;\n";
  283. echo " <input type='checkbox' name='import_fields[url]' id='field_url' value='1' checked><label for='field_url'>&nbsp;".$text['label-contact_url']."</label>&nbsp;\n";
  284. echo " <input type='checkbox' name='import_fields[address]' id='field_address' value='1' checked><label for='field_address'>&nbsp;".$text['label-address_address']."</label>\n";
  285. echo "<br />\n";
  286. echo $text['description-import_fields']."\n";
  287. echo "</td>\n";
  288. echo "</tr>\n";
  289. echo "<tr>\n";
  290. echo "<td width='30%' class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  291. echo " ".$text['label-contact_type']."\n";
  292. echo "</td>\n";
  293. echo "<td class='vtable' align='left'>\n";
  294. if (!empty($_SESSION["contact"]["type"])) {
  295. sort($_SESSION["contact"]["type"]);
  296. echo " <select class='formfld' name='import_type'>\n";
  297. echo " <option value=''></option>\n";
  298. foreach($_SESSION["contact"]["type"] as $row) {
  299. echo " <option value='".$row."'>".$row."</option>\n";
  300. }
  301. echo " </select>\n";
  302. }
  303. else {
  304. echo " <select class='formfld' name='import_type'>\n";
  305. echo " <option value=''></option>\n";
  306. echo " <option value='customer'>".$text['option-contact_type_customer']."</option>\n";
  307. echo " <option value='contractor'>".$text['option-contact_type_contractor']."</option>\n";
  308. echo " <option value='friend'>".$text['option-contact_type_friend']."</option>\n";
  309. echo " <option value='lead'>".$text['option-contact_type_lead']."</option>\n";
  310. echo " <option value='member'>".$text['option-contact_type_member']."</option>\n";
  311. echo " <option value='family'>".$text['option-contact_type_family']."</option>\n";
  312. echo " <option value='subscriber'>".$text['option-contact_type_subscriber']."</option>\n";
  313. echo " <option value='supplier'>".$text['option-contact_type_supplier']."</option>\n";
  314. echo " <option value='provider'>".$text['option-contact_type_provider']."</option>\n";
  315. echo " <option value='user'>".$text['option-contact_type_user']."</option>\n";
  316. echo " <option value='volunteer'>".$text['option-contact_type_volunteer']."</option>\n";
  317. echo " </select>\n";
  318. }
  319. echo "<br />\n";
  320. echo $text['description-contact_type_import']."\n";
  321. echo "</td>\n";
  322. echo "</tr>\n";
  323. echo "<tr>\n";
  324. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  325. echo " ".$text['label-contact_category']."\n";
  326. echo "</td>\n";
  327. echo "<td class='vtable' align='left'>\n";
  328. if (!empty($_SESSION["contact"]["category"])) {
  329. sort($_SESSION["contact"]["category"]);
  330. echo " <select class='formfld' name='import_category'>\n";
  331. echo " <option value=''></option>\n";
  332. foreach($_SESSION["contact"]["category"] as $row) {
  333. echo " <option value='".$row."'>".$row."</option>\n";
  334. }
  335. echo " </select>\n";
  336. }
  337. else {
  338. echo " <input class='formfld' type='text' name='import_category' maxlength='255'>\n";
  339. }
  340. echo "<br />\n";
  341. echo $text['description-contact_category_import']."\n";
  342. echo "</td>\n";
  343. echo "</tr>\n";
  344. echo "<tr>\n";
  345. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  346. echo " ".$text['label-shared']."\n";
  347. echo "</td>\n";
  348. echo "<td class='vtable' align='left'>\n";
  349. echo " <select class='formfld' name='import_shared' id='import_shared'>\n";
  350. echo " <option value='false'>".$text['option-false']."</option>\n";
  351. echo " <option value='true'>".$text['option-true']."</option>\n";
  352. echo " </select>\n";
  353. echo " <br />\n";
  354. echo $text['description-shared_import']."\n";
  355. echo "</td>\n";
  356. echo "</tr>\n";
  357. echo "<tr>\n";
  358. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  359. echo " ".$text['label-import_duplicates']."\n";
  360. echo "</td>\n";
  361. echo "<td class='vtable' align='left'>\n";
  362. echo " <select class='formfld' style='width: 150px;' name='import_duplicates'>\n";
  363. echo " <option value='skip'>".$text['option-import_duplicates_skip']."</option>\n";
  364. echo " <option value='replace'>".$text['option-import_duplicates_replace']."</option>\n";
  365. echo " </select>\n";
  366. echo "<br />\n";
  367. echo $text['description-import_duplicates']."\n";
  368. echo "</td>\n";
  369. echo "</tr>\n";
  370. echo "</table>";
  371. echo "<br><br>";
  372. //display groups
  373. echo "<b>".$text['label-groups']."</b>";
  374. echo "<br><br>";
  375. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  376. echo "<tr>\n";
  377. echo " <th style='width: 30px; text-align: center; padding: 0px;'>&nbsp;</th>";
  378. echo " <th>".$text['label-contact_name']."</th>\n";
  379. echo "</tr>\n";
  380. //determine contact count in groups
  381. foreach ($contacts as $contact) {
  382. foreach ($contact['groups'] as $group_id => $meh) {
  383. $groups[$group_id]['count']++;
  384. }
  385. }
  386. $c = 0;
  387. foreach ($groups as $group['id'] => $group) {
  388. if ($group['count'] > 0) {
  389. echo "<tr>\n";
  390. echo " <td valign='top' class='".$row_style[$c]."' style='text-align: center; padding: 3px 0px 0px 0px;'><input type='checkbox' name='group_id[]' id='group_id_".$group['id']."' value='".$group['id']."'></td>\n";
  391. echo " <td valign='top' class='".$row_style[$c]."' onclick=\"document.getElementById('group_id_".$group['id']."').checked = (document.getElementById('group_id_".$group['id']."').checked) ? false : true;\">".$group['name']." (".$group['count'].")</td>\n";
  392. echo "</tr>\n";
  393. $c=($c)?0:1;
  394. }
  395. }
  396. echo "</table>\n";
  397. echo "<br>";
  398. echo "<div style='text-align: right;'><input type='submit' class='btn' id='btn_submit' value=\"".$text['button-import']."\"></div>";
  399. echo "<br>";
  400. //display contacts
  401. echo "<b>".$text['header-contacts']."</b>";
  402. echo "<br><br>";
  403. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  404. echo "<tr>\n";
  405. echo " <th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
  406. echo " <th>".$text['label-contact_name']."</th>\n";
  407. echo " <th>".$text['label-contact_organization']."</th>\n";
  408. echo " <th>".$text['label-contact_email']."</th>\n";
  409. echo " <th>".$text['label-phone_number']."</th>\n";
  410. echo " <th>".$text['label-contact_url']."</th>\n";
  411. echo " <th>".$text['label-address_address']."</th>\n";
  412. echo " <th>".$text['label-group']."</th>\n";
  413. echo "</tr>\n";
  414. $c = 0;
  415. foreach ($contacts as $contact['id'] => $contact) {
  416. $contact_ids[] = $contact['id'];
  417. echo "<tr>\n";
  418. echo " <td valign='top' class='".$row_style[$c]."' style='text-align: center; padding: 3px 0px 0px 0px;'><input type='checkbox' name='contact_id[]' id='contact_id_".$contact['id']."' value='".$contact['id']."'></td>\n";
  419. echo " <td valign='top' class='".$row_style[$c]."' onclick=\"document.getElementById('contact_id_".$contact['id']."').checked = (document.getElementById('contact_id_".$contact['id']."').checked) ? false : true;\">";
  420. $contact_name[] = $contact['name_prefix'];
  421. $contact_name[] = $contact['name_given'];
  422. $contact_name[] = $contact['name_middle'];
  423. $contact_name[] = $contact['name_family'];
  424. $contact_name[] = $contact['name_suffix'];
  425. echo " ".implode(' ', $contact_name)."&nbsp;";
  426. unset($contact_name);
  427. echo " </td>\n";
  428. echo " <td valign='top' class='".$row_style[$c]."' style='max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
  429. echo " ".(($contact['title']) ? $contact['title']."<br>" : null).$contact['organization']."&nbsp;";
  430. echo " </td>\n";
  431. echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
  432. if (sizeof($contact['emails']) > 0) {
  433. foreach ($contact['emails'] as $contact_email) {
  434. $contact_emails[] = "<span style='font-size: 80%;'>".$contact_email['label'].":</span> <a href='mailto: ".$contact_email['address']."'>".$contact_email['address']."</a>";
  435. }
  436. echo implode('<br>', $contact_emails);
  437. unset($contact_emails);
  438. } else { echo "&nbsp;"; }
  439. echo " </td>\n";
  440. echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
  441. if (sizeof($contact['numbers']) > 0) {
  442. foreach ($contact['numbers'] as $contact_number) {
  443. $contact_number_part = "<span style='font-size: 80%;'>".$contact_number['label'].":</span> ";
  444. if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) {
  445. $contact_number_part .= "<a href='javascript:void(0);' onclick=\"send_cmd('".PROJECT_PATH."/app/click_to_call/click_to_call.php?src_cid_name=".urlencode($contact_number['number'])."&src_cid_number=".urlencode($contact_number['number'])."&dest_cid_name=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_name'])."&dest_cid_number=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_number'])."&src=".urlencode($_SESSION['user']['extension'][0]['user'])."&dest=".urlencode($contact_number['number'])."&rec=false&ringback=us-ring&auto_answer=true');\">";
  446. }
  447. $contact_number_part .= format_phone($contact_number['number']);
  448. if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) {
  449. $contact_number_part .= "</a>";
  450. }
  451. $contact_numbers[] = $contact_number_part;
  452. unset($contact_number_part);
  453. }
  454. echo implode('<br>', $contact_numbers);
  455. unset($contact_numbers);
  456. } else { echo "&nbsp;"; }
  457. echo " </td>\n";
  458. echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
  459. if (sizeof($contact['urls']) > 0) {
  460. foreach ($contact['urls'] as $contact_url) {
  461. $contact_urls[] = "<span style='font-size: 80%;'>".$contact_url['label'].":</span> <a href='".$contact_url['url']."' target='_blank'>".str_replace("http://", "", str_replace("https://", "", $contact_url['url']))."</a>";
  462. }
  463. echo implode('<br>', $contact_urls);
  464. unset($contact_urls);
  465. } else { echo "&nbsp;"; }
  466. echo " </td>\n";
  467. echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
  468. if (sizeof($contact['addresses']) > 0) {
  469. foreach ($contact['addresses'] as $contact_address) {
  470. if ($contact_address['street'] != '') { $contact_address_parts[] = $contact_address['street']; }
  471. if ($contact_address['extended'] != '') { $contact_address_parts[] = $contact_address['extended']; }
  472. if ($contact_address['community'] != '') { $contact_address_parts[] = $contact_address['community']; }
  473. if ($contact_address['locality'] != '') { $contact_address_parts[] = $contact_address['locality']; }
  474. if ($contact_address['region'] != '') { $contact_address_parts[] = $contact_address['region']; }
  475. if ($contact_address['postal_code'] != '') { $contact_address_parts[] = $contact_address['postal_code']; }
  476. if ($contact_address['country'] != '') { $contact_address_parts[] = $contact_address['country']; }
  477. $contact_addresses[] = "<span style='font-size: 80%;'>".$contact_address['label'].":</span> ".implode(', ', $contact_address_parts);
  478. unset($contact_address_parts);
  479. }
  480. echo implode('<br>', $contact_addresses);
  481. unset($contact_addresses);
  482. } else { echo "&nbsp;"; }
  483. echo " </td>\n";
  484. echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>";
  485. foreach ($contact['groups'] as $contact_group['id'] => $contact_group['name']) {
  486. $contact_groups[] = $contact_group['name'];
  487. }
  488. echo " ".implode('<br>', $contact_groups);
  489. unset($contact_groups);
  490. echo " </td>\n";
  491. echo "</tr>\n";
  492. $c=($c)?0:1;
  493. }
  494. echo "</table>\n";
  495. echo "</div>\n";
  496. echo "<br>";
  497. echo "<div style='text-align: right;'><input type='submit' class='btn' id='btn_submit' value=\"".$text['button-import']."\"></div>";
  498. echo "</form>";
  499. echo "<br><br>";
  500. // check or uncheck all contact checkboxes
  501. if (sizeof($contact_ids) > 0) {
  502. echo "<script>\n";
  503. echo " function check(what) {\n";
  504. foreach ($contact_ids as $contact_id) {
  505. echo " document.getElementById('contact_id_".$contact_id."').checked = (what == 'all') ? true : false;\n";
  506. }
  507. echo " }\n";
  508. echo "</script>\n";
  509. }
  510. /*
  511. echo "<pre>";
  512. print_r($contacts);
  513. echo "</pre>";
  514. echo "<br><br>";
  515. echo "<hr>";
  516. echo "<br><br><b>SOURCE JSON DECODED ARRAY</b>...<br><br><pre>";
  517. print_r($records);
  518. echo "</pre>";
  519. */
  520. //include the footer
  521. require_once "resources/footer.php";
  522. // used above
  523. function curl_file_get_contents($url) {
  524. $curl = curl_init();
  525. $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
  526. curl_setopt($curl, CURLOPT_URL, $url); //The URL to retrieve. This can also be set when initializing a session with curl_init().
  527. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
  528. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); //The number of seconds to wait while trying to connect.
  529. curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
  530. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
  531. curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
  532. curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
  533. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //To stop cURL from verifying the peer's certificate.
  534. $contents = curl_exec($curl);
  535. curl_close($curl);
  536. return $contents;
  537. }
  538. ?>