|
@@ -0,0 +1,534 @@
|
|
|
|
+<?php
|
|
|
|
+/*
|
|
|
|
+ FusionPBX
|
|
|
|
+ Version: MPL 1.1
|
|
|
|
+
|
|
|
|
+ The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
+ 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
+ the License. You may obtain a copy of the License at
|
|
|
|
+ http://www.mozilla.org/MPL/
|
|
|
|
+
|
|
|
|
+ Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
+ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
+ for the specific language governing rights and limitations under the
|
|
|
|
+ License.
|
|
|
|
+
|
|
|
|
+ The Original Code is FusionPBX
|
|
|
|
+
|
|
|
|
+ The Initial Developer of the Original Code is
|
|
|
|
+ Mark J Crane <[email protected]>
|
|
|
|
+ Portions created by the Initial Developer are Copyright (C) 2008-2013
|
|
|
|
+ the Initial Developer. All Rights Reserved.
|
|
|
|
+
|
|
|
|
+ Contributor(s):
|
|
|
|
+ Mark J Crane <[email protected]>
|
|
|
|
+*/
|
|
|
|
+require_once "root.php";
|
|
|
|
+require_once "resources/require.php";
|
|
|
|
+require_once "resources/check_auth.php";
|
|
|
|
+require_once "resources/functions/google_get_groups.php";
|
|
|
|
+require_once "resources/functions/google_get_contacts.php";
|
|
|
|
+
|
|
|
|
+if (permission_exists('contact_add')) {
|
|
|
|
+ //access granted
|
|
|
|
+}
|
|
|
|
+else {
|
|
|
|
+ echo "access denied";
|
|
|
|
+ exit;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//add multi-lingual support
|
|
|
|
+ require_once "app_languages.php";
|
|
|
|
+ foreach($text as $key => $value) {
|
|
|
|
+ $text[$key] = $value[$_SESSION['domain']['language']['code']];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+//handle import
|
|
|
|
+if ($_POST['a'] == 'import') {
|
|
|
|
+ if (sizeof($_POST['group_id']) > 0) {
|
|
|
|
+ //get contact ids for those in the submitted groups
|
|
|
|
+ if (sizeof($_SESSION['contact_auth']['google']) > 0) {
|
|
|
|
+ foreach ($_SESSION['contact_auth']['google'] as $contact['id'] => $contact) {
|
|
|
|
+ foreach ($contact['groups'] as $contact_group['id'] => $meh) {
|
|
|
|
+ if (in_array($contact_group['id'], $_POST['group_id'])) {
|
|
|
|
+ $import_ids[] = $contact['id'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sizeof($_POST['contact_id']) > 0) {
|
|
|
|
+ foreach ($_POST['contact_id'] as $contact_id) {
|
|
|
|
+ $import_ids[] = $contact_id;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //iterate selected contact ids, insert contact into database
|
|
|
|
+ $contacts_imported = 0;
|
|
|
|
+ if (sizeof($import_ids) > 0) {
|
|
|
|
+
|
|
|
|
+ $import_ids = array_unique($import_ids);
|
|
|
|
+ foreach ($import_ids as $contact_id) {
|
|
|
|
+
|
|
|
|
+ //extract contact record from array using contact id
|
|
|
|
+ $contact = $_SESSION['contact_auth']['google'][$contact_id];
|
|
|
|
+
|
|
|
|
+ //insert contact
|
|
|
|
+ $contact_uuid = uuid();
|
|
|
|
+ $sql = "insert into v_contacts ";
|
|
|
|
+ $sql .= "( ";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "contact_organization, ";
|
|
|
|
+ $sql .= "contact_name_prefix, ";
|
|
|
|
+ $sql .= "contact_name_given, ";
|
|
|
|
+ $sql .= "contact_name_middle, ";
|
|
|
|
+ $sql .= "contact_name_family, ";
|
|
|
|
+ $sql .= "contact_name_suffix, ";
|
|
|
|
+ $sql .= "contact_nickname, ";
|
|
|
|
+ $sql .= "contact_title, ";
|
|
|
|
+ $sql .= "contact_note ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "( ";
|
|
|
|
+ $sql .= "'".$_SESSION['domain_uuid']."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['organization'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['name_prefix'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['name_given'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['name_middle'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['name_family'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['name_suffix'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['nickname'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['title'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact['notes'])."' ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ //echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+
|
|
|
|
+ //make contact private
|
|
|
|
+ $sql = "insert into v_contact_groups ";
|
|
|
|
+ $sql .= "( ";
|
|
|
|
+ $sql .= "contact_group_uuid, ";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "group_uuid ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "( ";
|
|
|
|
+ $sql .= "'".uuid()."', ";
|
|
|
|
+ $sql .= "'".$_SESSION['domain_uuid']."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".$_SESSION["user_uuid"]."' ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ //echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+
|
|
|
|
+ //insert emails
|
|
|
|
+ if (sizeof($contact['emails']) > 0) {
|
|
|
|
+ foreach ($contact['emails'] as $contact_email) {
|
|
|
|
+ $sql = "insert into v_contact_emails ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "contact_email_uuid, ";
|
|
|
|
+ $sql .= "email_label, ";
|
|
|
|
+ $sql .= "email_address, ";
|
|
|
|
+ $sql .= "email_primary ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "'".$_SESSION['domain_uuid']."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".uuid()."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_email['label'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_email['address'])."', ";
|
|
|
|
+ $sql .= (($contact_email['primary']) ? 1 : 0)." ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ //echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //insert numbers
|
|
|
|
+ if (sizeof($contact['numbers']) > 0) {
|
|
|
|
+ foreach ($contact['numbers'] as $contact_number) {
|
|
|
|
+ $sql = "insert into v_contact_phones ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "contact_phone_uuid, ";
|
|
|
|
+ $sql .= "phone_type_voice, ";
|
|
|
|
+ $sql .= "phone_type_fax, ";
|
|
|
|
+ $sql .= "phone_label, ";
|
|
|
|
+ $sql .= "phone_number, ";
|
|
|
|
+ $sql .= "phone_primary ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "'".$domain_uuid."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".uuid()."', ";
|
|
|
|
+ $sql .= ((substr_count(strtoupper($contact_number['label']), strtoupper($text['label-fax'])) == 0) ? 1 : 'null').", ";
|
|
|
|
+ $sql .= ((substr_count(strtoupper($contact_number['label']), strtoupper($text['label-fax'])) != 0) ? 1 : 'null').", ";
|
|
|
|
+ $sql .= "'".check_str($contact_number['label'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_number['number'])."', ";
|
|
|
|
+ $sql .= ((sizeof($contact['numbers']) == 1) ? 1 : 0)." ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ //echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //insert urls
|
|
|
|
+ if (sizeof($contact['urls']) > 0) {
|
|
|
|
+ foreach ($contact['urls'] as $contact_url) {
|
|
|
|
+ $sql = "insert into v_contact_urls ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "contact_url_uuid, ";
|
|
|
|
+ $sql .= "url_label, ";
|
|
|
|
+ $sql .= "url_address, ";
|
|
|
|
+ $sql .= "url_primary ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "'".$_SESSION['domain_uuid']."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".uuid()."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_url['label'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_url['url'])."', ";
|
|
|
|
+ $sql .= ((sizeof($contact['urls']) == 1) ? 1 : 0)." ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ //echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //insert addresses
|
|
|
|
+ if (sizeof($contact['addresses']) > 0) {
|
|
|
|
+ foreach ($contact['addresses'] as $contact_address) {
|
|
|
|
+ $sql = "insert into v_contact_addresses ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "contact_address_uuid, ";
|
|
|
|
+ $sql .= "address_type, ";
|
|
|
|
+ $sql .= "address_label, ";
|
|
|
|
+ $sql .= "address_street, ";
|
|
|
|
+ $sql .= "address_extended, ";
|
|
|
|
+ $sql .= "address_community, ";
|
|
|
|
+ $sql .= "address_locality, ";
|
|
|
|
+ $sql .= "address_region, ";
|
|
|
|
+ $sql .= "address_postal_code, ";
|
|
|
|
+ $sql .= "address_country, ";
|
|
|
|
+ $sql .= "address_primary ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "'".$_SESSION['domain_uuid']."', ";
|
|
|
|
+ $sql .= "'".$contact_uuid."', ";
|
|
|
|
+ $sql .= "'".uuid()."', ";
|
|
|
|
+ if (substr_count(strtoupper($contact_address['label']), strtoupper($text['option-home'])) != 0) {
|
|
|
|
+ $sql .= "'home', "; // vcard address type
|
|
|
|
+ }
|
|
|
|
+ else if (substr_count(strtoupper($contact_address['label']), strtoupper($text['option-work'])) != 0) {
|
|
|
|
+ $sql .= "'work', "; // vcard address type
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $sql .= "'', ";
|
|
|
|
+ }
|
|
|
|
+ $sql .= "'".check_str($contact_address['label'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['street'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['extended'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['community'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['locality'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['region'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['postal_code'])."', ";
|
|
|
|
+ $sql .= "'".check_str($contact_address['country'])."', ";
|
|
|
|
+ $sql .= ((sizeof($contact['addresses']) == 1) ? 1 : 0)." ";
|
|
|
|
+ $sql .= ")";
|
|
|
|
+ echo $sql."<br><br>";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //add google contact id, etag and updated date to contact settings
|
|
|
|
+ $contact['updated'] = str_replace('T', ' ', $contact['updated']);
|
|
|
|
+ $contact['updated'] = str_replace('Z', '', $contact['updated']);
|
|
|
|
+ $sql = "insert into v_contact_settings ";
|
|
|
|
+ $sql .= "(";
|
|
|
|
+ $sql .= "contact_setting_uuid, ";
|
|
|
|
+ $sql .= "contact_uuid, ";
|
|
|
|
+ $sql .= "domain_uuid, ";
|
|
|
|
+ $sql .= "contact_setting_category, ";
|
|
|
|
+ $sql .= "contact_setting_subcategory, ";
|
|
|
|
+ $sql .= "contact_setting_name, ";
|
|
|
|
+ $sql .= "contact_setting_value, ";
|
|
|
|
+ $sql .= "contact_setting_order, ";
|
|
|
|
+ $sql .= "contact_setting_enabled ";
|
|
|
|
+ $sql .= ") ";
|
|
|
|
+ $sql .= "values ";
|
|
|
|
+ $sql .= "('".uuid()."', '".$contact_uuid."', '".$_SESSION['domain_uuid']."', 'sync', 'source', 'array', 'google', 0, 'true' )";
|
|
|
|
+ $sql .= ",('".uuid()."', '".$contact_uuid."', '".$_SESSION['domain_uuid']."', 'google', 'id', 'text', '".check_str($contact_id)."', 0, 'true' )";
|
|
|
|
+ $sql .= ",('".uuid()."', '".$contact_uuid."', '".$_SESSION['domain_uuid']."', 'google', 'updated', 'date', '".check_str($contact['updated'])."', 0, 'true' )";
|
|
|
|
+ $sql .= ",('".uuid()."', '".$contact_uuid."', '".$_SESSION['domain_uuid']."', 'google', 'etag', 'text', '".check_str($contact['etag'])."', 0, 'true' )";
|
|
|
|
+ $db->exec(check_sql($sql));
|
|
|
|
+ unset($sql);
|
|
|
|
+
|
|
|
|
+ $contacts_imported++;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $_SESSION["message"] = $text['message-contacts_imported']." ".$contacts_imported;
|
|
|
|
+ header("Location: contacts.php");
|
|
|
|
+ exit;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+
|
|
|
|
+ // no contacts imported
|
|
|
|
+ $_SESSION['message_mood'] = 'negative';
|
|
|
|
+ $_SESSION["message"] = $text['message-contacts_imported']." ".$contacts_imported;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//*******************************************************************************************
|
|
|
|
+
|
|
|
|
+//check if authenticated
|
|
|
|
+if ($_SESSION['contact_auth']['token'] == '') {
|
|
|
|
+ $_SESSION['contact_auth']['referer'] = substr($_SERVER["HTTP_REFERER"], strrpos($_SERVER["HTTP_REFERER"],'/')+1);
|
|
|
|
+ header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
|
|
|
|
+ exit;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+unset($_SESSION['contact_auth']['source'], $_SESSION['contact_auth']['target']);
|
|
|
|
+
|
|
|
|
+//get groups & contacts
|
|
|
|
+$groups = google_get_groups($_SESSION['contact_auth']['token']);
|
|
|
|
+$contacts = google_get_contacts($_SESSION['contact_auth']['token'], 1000);
|
|
|
|
+
|
|
|
|
+//store in session variable for use on import
|
|
|
|
+$_SESSION['contact_auth']['google'] = $contacts;
|
|
|
|
+
|
|
|
|
+//include the header
|
|
|
|
+$document['title'] = $text['title-contacts_import_google'];
|
|
|
|
+require_once "resources/header.php";
|
|
|
|
+
|
|
|
|
+echo "<table cellpadding='0' cellspacing='0' border='0' align='right'>";
|
|
|
|
+echo " <tr>";
|
|
|
|
+echo " <td style='text-align: right;'>";
|
|
|
|
+echo " <input type='button' class='btn' id='btn_back' onclick=\"document.location.href='contact_import.php';\" value=\"".$text['button-back']."\">";
|
|
|
|
+echo " <input type='button' class='btn' id='btn_refresh' onclick='document.location.reload();' value=\"".$text['button-reload']."\">";
|
|
|
|
+echo " <input type='button' class='btn' id='btn_signout' onclick=\"document.location.href='contact_auth.php?source=google&signout'\" value=\"".$text['button-sign_out']."\">";
|
|
|
|
+echo " </td>";
|
|
|
|
+echo " </tr>";
|
|
|
|
+echo " <tr>";
|
|
|
|
+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>";
|
|
|
|
+echo " </tr>";
|
|
|
|
+echo "</table>";
|
|
|
|
+echo "<b>".$text['header-contacts_import_google']."</b>";
|
|
|
|
+echo "<br><br>";
|
|
|
|
+echo $text['description-contacts_import_google'];
|
|
|
|
+echo "<br><br><br>";
|
|
|
|
+
|
|
|
|
+$row_style["0"] = "row_style0";
|
|
|
|
+$row_style["1"] = "row_style1";
|
|
|
|
+
|
|
|
|
+echo "<form name='frm_import' id='frm_import' method='post'>\n";
|
|
|
|
+echo "<input type='hidden' name='a' value='import'>\n";
|
|
|
|
+
|
|
|
|
+//display groups
|
|
|
|
+echo "<b>".$text['label-groups']."</b>";
|
|
|
|
+echo "<br><br>";
|
|
|
|
+
|
|
|
|
+echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
|
|
|
+echo "<tr>\n";
|
|
|
|
+echo " <th style='width: 30px; text-align: center; padding: 0px;'> </th>";
|
|
|
|
+echo " <th>".$text['label-contact_name']."</th>\n";
|
|
|
|
+echo "</tr>\n";
|
|
|
|
+
|
|
|
|
+//determine contact count in groups
|
|
|
|
+foreach ($contacts as $contact) {
|
|
|
|
+ foreach ($contact['groups'] as $group_id => $meh) {
|
|
|
|
+ $groups[$group_id]['count']++;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+$c = 0;
|
|
|
|
+foreach ($groups as $group['id'] => $group) {
|
|
|
|
+ if ($group['count'] > 0) {
|
|
|
|
+ echo "<tr>\n";
|
|
|
|
+ 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";
|
|
|
|
+ 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";
|
|
|
|
+ echo "</tr>\n";
|
|
|
|
+ $c=($c)?0:1;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+echo "</table>\n";
|
|
|
|
+echo "<br>";
|
|
|
|
+
|
|
|
|
+echo "<div style='text-align: right;'><input type='submit' class='btn' id='btn_submit' value=\"".$text['button-import']."\"></div>";
|
|
|
|
+
|
|
|
|
+echo "<br>";
|
|
|
|
+
|
|
|
|
+//display contacts
|
|
|
|
+echo "<b>".$text['header-contacts']."</b>";
|
|
|
|
+echo "<br><br>";
|
|
|
|
+
|
|
|
|
+echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
|
|
|
+echo "<tr>\n";
|
|
|
|
+echo " <th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
|
|
|
|
+echo " <th>".$text['label-contact_name']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-contact_organization']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-contact_email']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-phone_number']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-contact_url']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-address_address']."</th>\n";
|
|
|
|
+echo " <th>".$text['label-group']."</th>\n";
|
|
|
|
+echo "</tr>\n";
|
|
|
|
+$c = 0;
|
|
|
|
+foreach ($contacts as $contact['id'] => $contact) {
|
|
|
|
+ $contact_ids[] = $contact['id'];
|
|
|
|
+ echo "<tr>\n";
|
|
|
|
+ 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";
|
|
|
|
+ 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;\">";
|
|
|
|
+ $contact_name[] = $contact['name_prefix'];
|
|
|
|
+ $contact_name[] = $contact['name_given'];
|
|
|
|
+ $contact_name[] = $contact['name_middle'];
|
|
|
|
+ $contact_name[] = $contact['name_family'];
|
|
|
|
+ $contact_name[] = $contact['name_suffix'];
|
|
|
|
+ echo " ".implode(' ', $contact_name)." ";
|
|
|
|
+ unset($contact_name);
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
|
|
|
|
+ echo " ".(($contact['title']) ? $contact['title']."<br>" : null).$contact['organization']." ";
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
|
|
|
|
+ if (sizeof($contact['emails']) > 0) {
|
|
|
|
+ foreach ($contact['emails'] as $contact_email) {
|
|
|
|
+ $contact_emails[] = "<span style='font-size: 80%;'>".$contact_email['label'].":</span> <a href='mailto: ".$contact_email['address']."'>".$contact_email['address']."</a>";
|
|
|
|
+ }
|
|
|
|
+ echo implode('<br>', $contact_emails);
|
|
|
|
+ unset($contact_emails);
|
|
|
|
+ } else { echo " "; }
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
|
|
|
|
+ if (sizeof($contact['numbers']) > 0) {
|
|
|
|
+ foreach ($contact['numbers'] as $contact_number) {
|
|
|
|
+ $contact_number_part = "<span style='font-size: 80%;'>".$contact_number['label'].":</span> ";
|
|
|
|
+ if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) {
|
|
|
|
+ $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');\">";
|
|
|
|
+ }
|
|
|
|
+ $contact_number_part .= format_phone($contact_number['number']);
|
|
|
|
+ if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) {
|
|
|
|
+ $contact_number_part .= "</a>";
|
|
|
|
+ }
|
|
|
|
+ $contact_numbers[] = $contact_number_part;
|
|
|
|
+ unset($contact_number_part);
|
|
|
|
+ }
|
|
|
|
+ echo implode('<br>', $contact_numbers);
|
|
|
|
+ unset($contact_numbers);
|
|
|
|
+ } else { echo " "; }
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
|
|
|
|
+ if (sizeof($contact['urls']) > 0) {
|
|
|
|
+ foreach ($contact['urls'] as $contact_url) {
|
|
|
|
+ $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>";
|
|
|
|
+ }
|
|
|
|
+ echo implode('<br>', $contact_urls);
|
|
|
|
+ unset($contact_urls);
|
|
|
|
+ } else { echo " "; }
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='width: 15%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>";
|
|
|
|
+ if (sizeof($contact['addresses']) > 0) {
|
|
|
|
+ foreach ($contact['addresses'] as $contact_address) {
|
|
|
|
+ if ($contact_address['street'] != '') { $contact_address_parts[] = $contact_address['street']; }
|
|
|
|
+ if ($contact_address['extended'] != '') { $contact_address_parts[] = $contact_address['extended']; }
|
|
|
|
+ if ($contact_address['community'] != '') { $contact_address_parts[] = $contact_address['community']; }
|
|
|
|
+ if ($contact_address['locality'] != '') { $contact_address_parts[] = $contact_address['locality']; }
|
|
|
|
+ if ($contact_address['region'] != '') { $contact_address_parts[] = $contact_address['region']; }
|
|
|
|
+ if ($contact_address['postal_code'] != '') { $contact_address_parts[] = $contact_address['postal_code']; }
|
|
|
|
+ if ($contact_address['country'] != '') { $contact_address_parts[] = $contact_address['country']; }
|
|
|
|
+ $contact_addresses[] = "<span style='font-size: 80%;'>".$contact_address['label'].":</span> ".implode(', ', $contact_address_parts);
|
|
|
|
+ unset($contact_address_parts);
|
|
|
|
+ }
|
|
|
|
+ echo implode('<br>', $contact_addresses);
|
|
|
|
+ unset($contact_addresses);
|
|
|
|
+ } else { echo " "; }
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>";
|
|
|
|
+ foreach ($contact['groups'] as $contact_group['id'] => $contact_group['name']) {
|
|
|
|
+ $contact_groups[] = $contact_group['name'];
|
|
|
|
+ }
|
|
|
|
+ echo " ".implode('<br>', $contact_groups);
|
|
|
|
+ unset($contact_groups);
|
|
|
|
+ echo " </td>\n";
|
|
|
|
+ echo "</tr>\n";
|
|
|
|
+ $c=($c)?0:1;
|
|
|
|
+}
|
|
|
|
+echo "</table>\n";
|
|
|
|
+echo "<br>";
|
|
|
|
+
|
|
|
|
+echo "<div style='text-align: right;'><input type='submit' class='btn' id='btn_submit' value=\"".$text['button-import']."\"></div>";
|
|
|
|
+
|
|
|
|
+echo "</form>";
|
|
|
|
+echo "<br><br>";
|
|
|
|
+
|
|
|
|
+// check or uncheck all contact checkboxes
|
|
|
|
+if (sizeof($contact_ids) > 0) {
|
|
|
|
+ echo "<script>\n";
|
|
|
|
+ echo " function check(what) {\n";
|
|
|
|
+ foreach ($contact_ids as $contact_id) {
|
|
|
|
+ echo " document.getElementById('contact_id_".$contact_id."').checked = (what == 'all') ? true : false;\n";
|
|
|
|
+ }
|
|
|
|
+ echo " }\n";
|
|
|
|
+ echo "</script>\n";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+echo "<pre>";
|
|
|
|
+print_r($contacts);
|
|
|
|
+echo "</pre>";
|
|
|
|
+echo "<br><br>";
|
|
|
|
+
|
|
|
|
+echo "<hr>";
|
|
|
|
+echo "<br><br><b>SOURCE JSON DECODED ARRAY</b>...<br><br><pre>";
|
|
|
|
+print_r($records);
|
|
|
|
+echo "</pre>";
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+//include the footer
|
|
|
|
+require_once "resources/footer.php";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// used above
|
|
|
|
+function curl_file_get_contents($url) {
|
|
|
|
+ $curl = curl_init();
|
|
|
|
+ $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
|
|
|
|
+
|
|
|
|
+ curl_setopt($curl, CURLOPT_URL, $url); //The URL to fetch. This can also be set when initializing a session with curl_init().
|
|
|
|
+ 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.
|
|
|
|
+ curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); //The number of seconds to wait while trying to connect.
|
|
|
|
+ curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
|
|
|
|
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
|
|
|
|
+ curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
|
|
|
|
+ curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.
|
|
|
|
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); //To stop cURL from verifying the peer's certificate.
|
|
|
|
+
|
|
|
|
+ $contents = curl_exec($curl);
|
|
|
|
+ curl_close($curl);
|
|
|
|
+ return $contents;
|
|
|
|
+}
|
|
|
|
+?>
|