Contacts: Added ability to import Google Contacts. Requires: PHP curl and Google: Account, API Console Project, Contacts API and OAuth Client ID credentials.

This commit is contained in:
Nate Jones
2014-11-25 08:35:53 +00:00
parent 1f1838485f
commit 0efc467795
12 changed files with 1006 additions and 102 deletions

View File

@@ -26,6 +26,11 @@
$text['button-search']['pt-pt'] = "Pesquisar";
$text['button-search']['fr-fr'] = "Chercher";
$text['label-contact_google']['en-us'] = "Google Contact";
$text['label-contact_google']['es-cl'] = "Google Contacto";
$text['label-contact_google']['pt-pt'] = "Google Contact";
$text['label-contact_google']['fr-fr'] = "Google Contact";
// contact
$text['title-contact-add']['en-us'] = "Contact Add";
$text['title-contact-add']['es-cl'] = "Agregar Contacto";
@@ -160,17 +165,7 @@
$text['description-contact_category']['en-us'] = "Enter the category.";
$text['description-contact_category']['es-cl'] = "Ingrese la categoría.";
$text['description-contact_category']['pt-pt'] = "Introduza a categoria.";
$text['description-contact_category']['fr-fr'] = "";
$text['label-contact_subcategory']['en-us'] = "Subcategory";
$text['label-contact_subcategory']['es-cl'] = "Subcategoría";
$text['label-contact_subcategory']['pt-pt'] = "Subcategoria";
$text['label-contact_subcategory']['fr-fr'] = "Sous-Catégorie";
$text['description-contact_subcategory']['en-us'] = "Enter the subcategory.";
$text['description-contact_subcategory']['es-cl'] = "Ingrese la categoría.";
$text['description-contact_subcategory']['pt-pt'] = "Introduza a subcategoria";
$text['description-contact_subcategory']['fr-fr'] = "";
$text['description-contact_category']['fr-fr'] = "Entrez la catégorie.";
$text['label-contact_role']['en-us'] = "Role";
$text['label-contact_role']['es-cl'] = "Rol";
@@ -180,7 +175,7 @@
$text['description-contact_role']['en-us'] = "Enter the role.";
$text['description-contact_role']['es-cl'] = "Ingrese el rol.";
$text['description-contact_role']['pt-pt'] = "Introduza o papel desempenhado";
$text['description-contact_role']['fr-fr'] = "";
$text['description-contact_role']['fr-fr'] = "Entrez le rôle.";
$text['label-contact_email']['en-us'] = "Email";
$text['label-contact_email']['es-cl'] = "Correo Electrónico";
@@ -222,21 +217,6 @@
$text['description-contact_note']['pt-pt'] = "Introduza uma nota.";
$text['description-contact_note']['fr-fr'] = "";
$text['label-contact_settings']['en-us'] = "Settings";
$text['label-contact_settings']['es-cl'] = "Ajustes";
$text['label-contact_settings']['pt-pt'] = "Configurações";
$text['label-contact_settings']['fr-fr'] = "Paramètres";
$text['label-contact_value']['en-us'] = "Value";
$text['label-contact_value']['es-cl'] = "Valor";
$text['label-contact_value']['pt-pt'] = "Valor";
$text['label-contact_value']['fr-fr'] = "Valeur";
$text['description-contact_value']['en-us'] = "Enter the value of this setting.";
$text['description-contact_value']['es-cl'] = "Ingrese el valor para esta configuración.";
$text['description-contact_value']['pt-pt'] = "Introduza o valor desta definição.";
$text['description-contact_value']['fr-fr'] = "";
$text['label-true']['en-us'] = "True";
$text['label-true']['es-cl'] = "Verdadero";
$text['label-true']['pt-pt'] = "Sim";
@@ -257,31 +237,6 @@
$text['description-order']['pt-pt'] = "Defina a ordem (<ED>ndice) para este elemento da matriz.";
$text['description-order']['fr-fr'] = "D<E9>finir l'ordre (index) pour cet <E9>l<E9>ment de tableau.";
$text['header-contact_setting_edit']['en-us'] = "Contact Setting";
$text['header-contact_setting_edit']['es-cl'] = "Configuraciones de contacto";
$text['header-contact_setting_edit']['pt-pt'] = "Definições do Contacto";
$text['header-contact_setting_edit']['fr-fr'] = "Paramètres du Contact";
$text['header-contact_setting_add']['en-us'] = "Contact Setting Add";
$text['header-contact_setting_add']['es-cl'] = "Agregar Configuración de Contacto";
$text['header-contact_setting_add']['pt-pt'] = "Adicionar Definição ao Contacto";
$text['header-contact_setting_add']['fr-fr'] = "Ajouter un paramètre au Contact";
$text['title-contact_setting_edit']['en-us'] = "Contact Setting";
$text['title-contact_setting_edit']['es-cl'] = "Configuraciones de contacto";
$text['title-contact_setting_edit']['pt-pt'] = "Definições do Contacto";
$text['title-contact_setting_edit']['fr-fr'] = "Paramètres du Contact";
$text['title-contact_setting_add']['en-us'] = "Contact Setting Add";
$text['title-contact_setting_add']['es-cl'] = "Agregar Configuración de Contacto";
$text['title-contact_setting_add']['pt-pt'] = "Adicionar Definição ao Contacto";
$text['title-contact_setting_add']['fr-fr'] = "Ajouter un paramètre au Contact";
$text['description-contact_setting_edit']['en-us'] = "Edit a setting for this contact.";
$text['description-contact_setting_edit']['es-cl'] = "Edita una configuración para este contacto.";
$text['description-contact_setting_edit']['pt-pt'] = "Editar uma definição deste contacto.";
$text['description-contact_setting_edit']['fr-fr'] = "Editer un paramètre du contact.";
$text['label-shared']['en-us'] = "Shared";
$text['label-shared']['es-cl'] = "Compartido";
$text['label-shared']['pt-pt'] = "Partilhada";
@@ -848,6 +803,82 @@
$text['label-note_user']['pt-pt'] = "Usuário";
$text['label-note_user']['fr-fr'] = "Utilisateur";
// contact settings
$text['label-contact_settings']['en-us'] = "Settings";
$text['label-contact_settings']['es-cl'] = "Ajustes";
$text['label-contact_settings']['pt-pt'] = "Configurações";
$text['label-contact_settings']['fr-fr'] = "Paramètres";
$text['title-contact_setting_add']['en-us'] = "Contact Setting Add";
$text['title-contact_setting_add']['es-cl'] = "Agregar Configuración de Contacto";
$text['title-contact_setting_add']['pt-pt'] = "Adicionar Definição ao Contacto";
$text['title-contact_setting_add']['fr-fr'] = "Ajouter un paramètre au Contact";
$text['header-contact_setting_add']['en-us'] = "Contact Setting Add";
$text['header-contact_setting_add']['es-cl'] = "Agregar Configuración de Contacto";
$text['header-contact_setting_add']['pt-pt'] = "Adicionar Definição ao Contacto";
$text['header-contact_setting_add']['fr-fr'] = "Ajouter un paramètre au Contact";
$text['description-contact_setting_add']['en-us'] = "Add a setting for this contact.";
$text['description-contact_setting_add']['es-cl'] = "Agregar una configuración para este contacto.";
$text['description-contact_setting_add']['pt-pt'] = "Adicionar uma definição deste contacto.";
$text['description-contact_setting_add']['fr-fr'] = "Ajouter un paramètre du contact.";
$text['title-contact_setting_edit']['en-us'] = "Contact Setting Edit";
$text['title-contact_setting_edit']['es-cl'] = "Configuraciones de contacto";
$text['title-contact_setting_edit']['pt-pt'] = "Definições do Contacto";
$text['title-contact_setting_edit']['fr-fr'] = "Paramètres du Contact";
$text['header-contact_setting_edit']['en-us'] = "Contact Setting Edit";
$text['header-contact_setting_edit']['es-cl'] = "Configuraciones de contacto";
$text['header-contact_setting_edit']['pt-pt'] = "Definições do Contacto";
$text['header-contact_setting_edit']['fr-fr'] = "Paramètres du Contact";
$text['description-contact_setting_edit']['en-us'] = "Edit a setting for this contact.";
$text['description-contact_setting_edit']['es-cl'] = "Edita una configuración para este contacto.";
$text['description-contact_setting_edit']['pt-pt'] = "Editar uma definição deste contacto.";
$text['description-contact_setting_edit']['fr-fr'] = "Editer un paramètre du contact.";
$text['label-contact_setting_category']['en-us'] = "Category";
$text['label-contact_setting_category']['es-cl'] = "Categoría";
$text['label-contact_setting_category']['pt-pt'] = "Categoria";
$text['label-contact_setting_category']['fr-fr'] = "Catégorie";
$text['description-contact_setting_category']['en-us'] = "Enter the category.";
$text['description-contact_setting_category']['es-cl'] = "Ingrese la categoría.";
$text['description-contact_setting_category']['pt-pt'] = "Introduza a categoria.";
$text['description-contact_setting_category']['fr-fr'] = "Entrez la catégorie.";
$text['label-contact_setting_subcategory']['en-us'] = "Subcategory";
$text['label-contact_setting_subcategory']['es-cl'] = "Subcategoría";
$text['label-contact_setting_subcategory']['pt-pt'] = "Subcategoria";
$text['label-contact_setting_subcategory']['fr-fr'] = "Sous-Catégorie";
$text['description-contact_setting_subcategory']['en-us'] = "Enter the subcategory.";
$text['description-contact_setting_subcategory']['es-cl'] = "Ingrese la categoría.";
$text['description-contact_setting_subcategory']['pt-pt'] = "Introduza a subcategoria";
$text['description-contact_setting_subcategory']['fr-fr'] = "Entrez la sous-catégorie.";
$text['label-contact_setting_type']['en-us'] = "Type";
$text['label-contact_setting_type']['es-cl'] = "Tipo";
$text['label-contact_setting_type']['pt-pt'] = "Tipo";
$text['label-contact_setting_type']['fr-fr'] = "Type";
$text['description-contact_setting_type']['en-us'] = "Enter the type.";
$text['description-contact_setting_type']['es-cl'] = "Introduzca el tipo.";
$text['description-contact_setting_type']['pt-pt'] = "Digite o tipo.";
$text['description-contact_setting_type']['fr-fr'] = "Entrez le type.";
$text['label-contact_setting_value']['en-us'] = "Value";
$text['label-contact_setting_value']['es-cl'] = "Valor";
$text['label-contact_setting_value']['pt-pt'] = "Valor";
$text['label-contact_setting_value']['fr-fr'] = "Valeur";
$text['description-contact_setting_value']['en-us'] = "Enter the value of this setting.";
$text['description-contact_setting_value']['es-cl'] = "Ingrese el valor para esta configuración.";
$text['description-contact_setting_value']['pt-pt'] = "Introduza o valor desta definição.";
$text['description-contact_setting_value']['fr-fr'] = "";
// contact import
$text['title-contacts_import']['en-us'] = "Import Contacts";
$text['title-contacts_import']['es-cl'] = "Importar Contactos";
@@ -929,6 +960,11 @@
$text['label-contacts_import_google_account']['pt-pt'] = "Conta";
$text['label-contacts_import_google_account']['fr-fr'] = "Compte";
$text['label-group']['en-us'] = "Group";
$text['label-group']['es-cl'] = "Grupo";
$text['label-group']['pt-pt'] = "Grupo";
$text['label-group']['fr-fr'] = "Group";
$text['button-reload']['en-us'] = "Reload";
$text['button-reload']['es-cl'] = "Recargar";
$text['button-reload']['pt-pt'] = "Recarregar";
@@ -944,6 +980,10 @@
$text['message-google_signed_out']['pt-pt'] = "Conta do Google: Assinado Fora";
$text['message-google_signed_out']['fr-fr'] = "Compte Google: Déconnecté";
$text['message-contacts_imported']['en-us'] = "Contacts Imported: ";
$text['message-contacts_imported']['es-cl'] = "";
$text['message-contacts_imported']['pt-pt'] = "";
$text['message-contacts_imported']['fr-fr'] = "";
// general labels
$text['label-primary']['en-us'] = "Primary";

View File

@@ -114,10 +114,10 @@ require_once "resources/paging.php";
echo "<tr ".$tr_link." ".(($row['address_primary']) ? "style='font-weight: bold;'" : null).">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['address_label']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='width: 25%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['address_street']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".$row['address_locality'].(($row['address_region'] != '') ? ", ".$row['address_region'] : null)."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".$row['address_locality'].(($row['address_locality'] != '' && $row['address_region'] != '') ? ", " : null).$row['address_region']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: center;'>".$row['address_country']."&nbsp;</td>\n";
echo " <td valign='middle' class='".$row_style[$c]." tr_link_void' style='padding: 0px;'>\n";
echo " <a href=\"http://maps.google.com/maps?q=".urlencode($map_query)."&hl=en\" target=\"_blank\"><img src='icon_gmaps.png' style='width: 21px; height: 21px; alt='".$text['label-google_map']."' title='".$text['label-google_map']."'></a>\n";
echo " <a href=\"http://maps.google.com/maps?q=".urlencode($map_query)."&hl=en\" target=\"_blank\"><img src='resources/images/icon_gmaps.png' style='width: 21px; height: 21px; alt='".$text['label-google_map']."' title='".$text['label-google_map']."'></a>\n";
echo " </td>\n";
echo " <td valign='top' class='row_stylebg'>".$row['address_description']."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";

View File

@@ -0,0 +1,124 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('contact_add')) {
//access granted
}
else {
echo "access denied";
exit;
}
/*
echo "bang!";
exit;
*/
//add multi-lingual support
require_once "app_languages.php";
foreach($text as $key => $value) {
$text[$key] = $value[$_SESSION['domain']['language']['code']];
}
$_SESSION['contact_auth']['source'] = ($_SESSION['contact_auth']['source'] == '') ? $_REQUEST['source'] : $_SESSION['contact_auth']['source'];
$_SESSION['contact_auth']['target'] = ($_SESSION['contact_auth']['target'] == '') ? $_REQUEST['target'] : $_SESSION['contact_auth']['target'];
//google api authentication
if ($_SESSION['contact_auth']['source'] == 'google') {
if ($_REQUEST['error']) {
$_SESSION['message'] = ($text['message-'.$_REQUEST['error']] != '') ? $text['message-'.$_REQUEST['error']] : $_REQUEST['error'];
$_SESSION['message_mood'] = 'negative';
header("Location: ".$_SESSION['contact_auth']['referer']);
unset($_SESSION['contact_auth']);
exit;
}
if (isset($_REQUEST['signout'])) {
unset($_SESSION['contact_auth']['token']);
$_SESSION['message'] = $text['message-google_signed_out'];
header("Location: https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=".(($_SERVER["HTTPS"] == "on") ? "https" : "http")."://".$_SERVER['HTTP_HOST'].PROJECT_PATH."/app/contacts/".$_SESSION['contact_auth']['referer']);
exit;
}
if ($_GET['code'] == '') {
header("Location: https://accounts.google.com/o/oauth2/auth?client_id=".$_SESSION['contact']['google_oauth_client_id']['text']."&redirect_uri=".(($_SERVER["HTTPS"] == "on") ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."&scope=https://www.google.com/m8/feeds/&response_type=code");
exit;
}
else {
$auth_code = $_GET["code"];
}
/*******************************************************************************************/
// request access token
$fields = array(
'code' => urlencode($auth_code),
'client_id' => urlencode($_SESSION['contact']['google_oauth_client_id']['text']),
'client_secret' => urlencode($_SESSION['contact']['google_oauth_client_secret']['text']),
'redirect_uri' => urlencode((($_SERVER["HTTPS"] == "on") ? "https" : "http")."://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']),
'grant_type' => urlencode('authorization_code')
);
foreach($fields as $key => $value) {
$post_fields[] = $key.'='.$value;
}
$post_fields = implode("&", $post_fields);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl, CURLOPT_POST, 5);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$result = curl_exec($curl);
curl_close($curl);
$response = json_decode($result);
$access_token = $response->access_token;
if ($access_token != '') {
// redirect to target script
$_SESSION['contact_auth']['token'] = $access_token;
header("Location: ".$_SESSION['contact_auth']['target']);
exit;
}
}
else {
$_SESSION['message'] = $text['message-access_denied'];
$_SESSION['message_mood'] = 'negative';
header("Location: ".$_SESSION['contact_auth']['referer']);
unset($_SESSION['contact_auth']);
exit;
}
?>

View File

@@ -427,13 +427,12 @@ else {
echo "<td class='vtable' align='left'>\n";
echo " <input name=\"ulfile\" type=\"file\" class=\"formfld fileinput\" id=\"ulfile\">\n";
echo "<br />\n";
//echo "Select the enclosure.\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td valign=\"bottom\" class=\"label\">\n";
echo " &nbsp;\n";
echo " <a href='contact_import_google.php'><img src='resources/images/icon_gcontacts.png' style='width: 21px; height: 21px; border: none; text-decoration: none; margin-right: 5px;' align='absmiddle'>".$text['header-contacts_import_google']."</a>\n";
echo " </td>\n";
echo " <td valign=\"bottom\" align='right' class=\"label\" nowrap>\n";
echo " <br />\n";

View File

@@ -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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
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;'>&nbsp;</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)."&nbsp;";
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']."&nbsp;";
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 "&nbsp;"; }
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 "&nbsp;"; }
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 "&nbsp;"; }
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 "&nbsp;"; }
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;
}
?>

View File

@@ -178,10 +178,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//show the header
require_once "resources/header.php";
if ($action == "update") {
$document['title'] = $text['title-contact_setting-edit'];
$document['title'] = $text['title-contact_setting_edit'];
}
elseif ($action == "add") {
$document['title'] = $text['title-contact_setting-add'];
$document['title'] = $text['title-contact_setting_add'];
}
//show the content
@@ -190,7 +190,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n";
echo "<td valign='top' align='left' width='30%' nowrap='nowrap'><b>";
if ($action == "update") {
echo $text['header-contact_setting-edit'];
echo $text['header-contact_setting_edit'];
}
if ($action == "add") {
echo $text['header-contact_setting_add'];
@@ -204,10 +204,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n";
echo "<td align='left' colspan='2'>\n";
if ($action == "update") {
echo $text['description-contact_setting-edit'];
echo $text['description-contact_setting_edit'];
}
if ($action == "add") {
echo $text['header-contact_setting_add'];
echo $text['description-contact_setting_add'];
}
echo "<br /><br />\n";
echo "</td>\n";
@@ -215,40 +215,40 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-contact_category'].":\n";
echo " ".$text['label-contact_setting_category']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='contact_setting_category' maxlength='255' value=\"$contact_setting_category\">\n";
echo " <input class='formfld' type='text' name='contact_setting_category' maxlength='255' value=\"".$contact_setting_category."\">\n";
echo "<br />\n";
echo $text['description-contact_category']."\n";
echo $text['description-contact_setting_category']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-contact_subcategory'].":\n";
echo " ".$text['label-contact_setting_subcategory']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='contact_setting_subcategory' maxlength='255' value=\"$contact_setting_subcategory\">\n";
echo " <input class='formfld' type='text' name='contact_setting_subcategory' maxlength='255' value=\"".$contact_setting_subcategory."\">\n";
echo "<br />\n";
echo $text['description-contact_subcategory']."\n";
echo $text['description-contact_setting_subcategory']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-contact_name'].":\n";
echo " ".$text['label-contact_setting_type']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='contact_setting_name' maxlength='255' value=\"$contact_setting_name\">\n";
echo " <input class='formfld' type='text' name='contact_setting_name' maxlength='255' value=\"".$contact_setting_name."\">\n";
echo "<br />\n";
echo $text['description-contact_name']."\n";
echo $text['description-contact_setting_type']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-contact_value'].":\n";
echo " ".$text['label-contact_setting_value']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
$category = $row['contact_setting_category'];
@@ -256,7 +256,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$name = $row['contact_setting_name'];
echo " <input class='formfld' type='text' name='contact_setting_value' maxlength='255' value=\"".$row['contact_setting_value']."\">\n";
echo "<br />\n";
echo $text['description-contact_value']."\n";
echo $text['description-contact_setting_value']."\n";
echo "</td>\n";
echo "</tr>\n";
@@ -290,7 +290,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-enabled'].":\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='contact_setting_enabled'>\n";
@@ -314,7 +314,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-description'].":\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='contact_setting_description' maxlength='255' value=\"$contact_setting_description\">\n";
@@ -325,11 +325,12 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
echo " <br>";
echo " <input type='hidden' name='contact_uuid' value='$contact_uuid'>\n";
if ($action == "update") {
echo " <input type='hidden' name='contact_setting_uuid' value='$contact_setting_uuid'>\n";
echo " <input type='hidden' name='contact_setting_uuid' value='$contact_setting_uuid'>\n";
}
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";

View File

@@ -96,10 +96,10 @@ require_once "resources/paging.php";
echo " </td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<th>".$text['label-contact_category']."</th>";
echo "<th>".$text['label-contact_subcategory']."</th>";
echo "<th>".$text['label-contact_name']."</th>";
echo "<th>".$text['label-contact_value']."</th>";
echo "<th>".$text['label-contact_setting_category']."</th>";
echo "<th>".$text['label-contact_setting_subcategory']."</th>";
echo "<th>".$text['label-contact_setting_type']."</th>";
echo "<th>".$text['label-contact_setting_value']."</th>";
echo "<th style='text-align: center;'>".$text['label-enabled']."</th>";
echo "<th>".$text['label-description']."</th>";
echo "<td class='list_control_icons'>";

View File

@@ -107,7 +107,7 @@ require_once "resources/paging.php";
$tr_link = "href='contact_url_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_url_uuid']."'";
echo "<tr ".$tr_link." ".(($row['url_primary']) ? "style='font-weight: bold;'" : null).">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['url_label']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='width: 40%; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'><a href='".$row['url_address']."' target='_blank'>".$row['url_address']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='width: 40%; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'><a href='".$row['url_address']."' target='_blank'>".str_replace("http://", "", str_replace("https://", "", $row['url_address']))."</a>&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg'>".$row['address_description']."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
echo "<a href='contact_url_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['contact_url_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";

View File

@@ -80,12 +80,49 @@ require_once "resources/paging.php";
//add user's uuid to group uuid list to include private (non-shared) contacts
$user_group_uuids[] = $_SESSION["user_uuid"];
//prepare to page the results
$sql = "select count(*) as num_rows from v_contacts ";
//get contact sync sources
$sql = "select ";
$sql .= "contact_uuid, ";
$sql .= "contact_setting_value ";
$sql .= "from ";
$sql .= "v_contact_settings ";
$sql .= "where ";
$sql .= "domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and contact_setting_category = 'sync' ";
$sql .= "and contact_setting_subcategory = 'source' ";
$sql .= "and contact_setting_name = 'array' ";
$sql .= "and contact_setting_value <> '' ";
$sql .= "and contact_setting_value is not null ";
if (sizeof($user_group_uuids) > 0) {
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
$sql .= " where group_uuid in ('".implode("','", $user_group_uuids)."') ";
$sql .= " and domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= " ) \n";
$sql .= " or \n";
$sql .= " contact_uuid not in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= " ) \n";
$sql .= ") \n";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
foreach($result as $row) {
$contact_sync_sources[$row['contact_uuid']][] = $row['contact_setting_value'];
}
}
unset ($sql, $prep_statement, $result);
//build query for paging and list
$sql = "select count(*) as num_rows ";
$sql .= "from v_contacts as c ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
if (sizeof($user_group_uuids) > 0) {
//only show contacts assigned to current user's group(s) and those not assigned to any group
$sql .= "and ( \n";
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( \n";
$sql .= " select contact_uuid from v_contact_groups ";
$sql .= " where group_uuid in ('".implode("','", $user_group_uuids)."') ";
@@ -182,12 +219,8 @@ require_once "resources/paging.php";
echo th_order_by('contact_name_family', $text['label-contact_name_family'], $order_by, $order);
echo th_order_by('contact_nickname', $text['label-contact_nickname'], $order_by, $order);
echo th_order_by('contact_title', $text['label-contact_title'], $order_by, $order);
//echo th_order_by('contact_category', $text['label-contact_category'], $order_by, $order);
echo th_order_by('contact_role', $text['label-contact_role'], $order_by, $order);
//echo th_order_by('contact_email', $text['label-contact_email'], $order_by, $order);
//echo th_order_by('contact_url', $text['label-contact_url'], $order_by, $order);
//echo th_order_by('contact_time_zone', $text['label-contact_time_zone'], $order_by, $order);
//echo th_order_by('contact_note', $text['label-contact_note'], $order_by, $order);
echo "<th style='padding: 0px;'>&nbsp;</th>\n";
echo "<td class='list_control_icons'>";
echo "<a href='contact_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
echo "</td>\n";
@@ -198,17 +231,22 @@ require_once "resources/paging.php";
$tr_link = "href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'";
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".ucwords($row['contact_type'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_organization']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_given']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_family']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_nickname']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_title']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_category']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_role']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_email']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_url']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_time_zone']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_note']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='width: 35%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_organization']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_given']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_family']."</a>&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".$row['contact_nickname']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='width: 10%; max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['contact_title']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='width: 10%; max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['contact_role']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='padding: 2px 2px; text-align: center; width: 25px;'>";
if (sizeof($contact_sync_sources[$row['contact_uuid']]) > 0) {
foreach ($contact_sync_sources[$row['contact_uuid']] as $contact_sync_source) {
switch ($contact_sync_source) {
case 'google': echo "<img src='resources/images/icon_gcontacts.png' style='width: 21px; height: 21px; border: none; padding-left: 2px;' alt='".$text['label-contact_google']."'>"; break;
}
}
}
else { echo "&nbsp;"; }
echo " </td>\n";
echo " <td class='list_control_icons'>";
echo "<a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
echo "<a href='contact_delete.php?id=".$row['contact_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";

View File

@@ -0,0 +1,114 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
function google_get_contacts($token, $max_results = 50) {
//global $records;
global $groups;
//$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&oauth_token='.$_SESSION['contact_auth']['token']; // all contacts as xml
//$url = 'https://www.google.com/m8/feeds/contacts/default/full/78967d550d3fdd99?alt=json&v=3.0&oauth_token='.$_SESSION['contact_auth']['token']; // single contact
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$token; // all contacts as json
$xml_response = curl_file_get_contents($url);
$records = json_decode($xml_response, true);
//check for authentication errors (logged out of google account, or app access permission revoked, etc)
if ($records['error']['code']) {
header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
exit;
}
//create new array of contacts
foreach($records['feed']['entry'] as $contact['number'] => $contact) {
$contact_id = substr($contact['id']['$t'], strrpos($contact['id']['$t'], "/")+1);
$contacts[$contact_id]['etag'] = $contact['gd$etag'];
$contacts[$contact_id]['updated'] = $contact['updated']['$t'];
$contacts[$contact_id]['name_prefix'] = $contact['gd$name']['gd$namePrefix']['$t'];
$contacts[$contact_id]['name_given'] = $contact['gd$name']['gd$givenName']['$t'];
$contacts[$contact_id]['name_middle'] = $contact['gd$name']['gd$additionalName']['$t'];
$contacts[$contact_id]['name_family'] = $contact['gd$name']['gd$familyName']['$t'];
$contacts[$contact_id]['name_suffix'] = $contact['gd$name']['gd$nameSuffix']['$t'];
$contacts[$contact_id]['nickname'] = $contact['gContact$nickname']['$t'];
$contacts[$contact_id]['title'] = $contact['gd$organization'][0]['gd$orgTitle']['$t'];
$contacts[$contact_id]['organization'] = $contact['gd$organization'][0]['gd$orgName']['$t'];
foreach ($contact['gd$email'] as $contact_email['number'] => $contact_email) {
if ($contact_email['label']) {
$contact_email_label = $contact_email['label'];
}
else {
$contact_email_label = substr($contact_email['rel'], strpos($contact_email['rel'], "#")+1);
$contact_email_label = ucwords(str_replace("_", " ", $contact_email_label));
}
$contacts[$contact_id]['emails'][$contact_email['number']]['label'] = $contact_email_label;
$contacts[$contact_id]['emails'][$contact_email['number']]['address'] = $contact_email['address'];
$contacts[$contact_id]['emails'][$contact_email['number']]['primary'] = ($contact_email['primary']) ? 1 : 0;
}
foreach ($contact['gd$phoneNumber'] as $contact_phone['number'] => $contact_phone) {
if ($contact_phone['label']) {
$contact_phone_label = $contact_phone['label'];
}
else {
$contact_phone_label = substr($contact_phone['rel'], strpos($contact_phone['rel'], "#")+1);
$contact_phone_label = ucwords(str_replace("_", " ", $contact_phone_label));
}
$contacts[$contact_id]['numbers'][$contact_phone['number']]['label'] = $contact_phone_label;
$contacts[$contact_id]['numbers'][$contact_phone['number']]['number'] = preg_replace('{\D}', '', $contact_phone['$t']);
}
foreach ($contact['gContact$website'] as $contact_website['number'] => $contact_website) {
$contact_website_label = ($contact_website['label']) ? $contact_website['label'] : ucwords(str_replace("_", " ", $contact_website['rel']));
$contacts[$contact_id]['urls'][$contact_website['number']]['label'] = $contact_website_label;
$contacts[$contact_id]['urls'][$contact_website['number']]['url'] = $contact_website['href'];
}
foreach ($contact['gd$structuredPostalAddress'] as $contact_address['number'] => $contact_address) {
if ($contact_address['label']) {
$contact_address_label = $contact_address['label'];
}
else {
$contact_address_label = substr($contact_address['rel'], strpos($contact_address['rel'], "#")+1);
$contact_address_label = ucwords(str_replace("_", " ", $contact_address_label));
}
$contacts[$contact_id]['addresses'][$contact_address['number']]['label'] = $contact_address_label;
$contacts[$contact_id]['addresses'][$contact_address['number']]['street'] = $contact_address['gd$street']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['extended'] = $contact_address['gd$pobox']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['community'] = $contact_address['gd$neighborhood']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['locality'] = $contact_address['gd$city']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['region'] = $contact_address['gd$region']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['postal_code'] = $contact_address['gd$postcode']['$t'];
$contacts[$contact_id]['addresses'][$contact_address['number']]['country'] = $contact_address['gd$country']['$t'];
}
foreach ($contact['gContact$groupMembershipInfo'] as $contact_group['number'] => $contact_group) {
$contact_group_id = substr($contact_group['href'], strrpos($contact_group['href'], "/")+1);
$contacts[$contact_id]['groups'][$contact_group_id] = $groups[$contact_group_id]['name'];
}
$contacts[$contact_id]['notes'] = $contact['content']['$t'];
}
//set account holder info
$_SESSION['contact_auth']['name'] = $records['feed']['author'][0]['name']['$t'];
$_SESSION['contact_auth']['email'] = $records['feed']['author'][0]['email']['$t'];
return $contacts;
}
?>

View File

@@ -0,0 +1,54 @@
<?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 <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2013
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
function google_get_groups($token) {
// retrieve groups
$url = 'https://www.google.com/m8/feeds/groups/default/full?alt=json&v=3.0&oauth_token='.$token;
$xml_response = curl_file_get_contents($url);
$records = json_decode($xml_response, true);
//check for authentication errors
if ($records['error']['code']) {
header("Location: contact_auth.php?source=google&target=".substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],'/')+1));
exit;
}
//create new array of groups
foreach($records['feed']['entry'] as $group['number'] => $group) {
$group_id = substr($group['id']['$t'], strrpos($group['id']['$t'], "/")+1);
$groups[$group_id]['name'] = ($group['gContact$systemGroup']['id']) ? $group['gContact$systemGroup']['id'] : $group['title']['$t'];
$groups[$group_id]['count'] = 0;
unset($group_id);
}
unset($group);
//set account holder info
$_SESSION['contact_auth']['name'] = $records['feed']['author'][0]['name']['$t'];
$_SESSION['contact_auth']['email'] = $records['feed']['author'][0]['email']['$t'];
return $groups;
}
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB