From 0efc467795b7d5fba3b119130bba2c58a4dd84ba Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Tue, 25 Nov 2014 08:35:53 +0000 Subject: [PATCH] Contacts: Added ability to import Google Contacts. Requires: PHP curl and Google: Account, API Console Project, Contacts API and OAuth Client ID credentials. --- app/contacts/app_languages.php | 144 +++-- app/contacts/contact_addresses.php | 4 +- app/contacts/contact_auth.php | 124 ++++ app/contacts/contact_import.php | 3 +- app/contacts/contact_import_google.php | 534 ++++++++++++++++++ app/contacts/contact_setting_edit.php | 43 +- app/contacts/contact_settings.php | 8 +- app/contacts/contact_urls.php | 2 +- app/contacts/contacts.php | 78 ++- .../functions/google_get_contacts.php | 114 ++++ .../resources/functions/google_get_groups.php | 54 ++ .../resources/images/icon_gcontacts.png | Bin 0 -> 2261 bytes 12 files changed, 1006 insertions(+), 102 deletions(-) create mode 100644 app/contacts/contact_auth.php create mode 100644 app/contacts/contact_import_google.php create mode 100644 app/contacts/resources/functions/google_get_contacts.php create mode 100644 app/contacts/resources/functions/google_get_groups.php create mode 100644 app/contacts/resources/images/icon_gcontacts.png diff --git a/app/contacts/app_languages.php b/app/contacts/app_languages.php index 199be61684..65a9c9a78f 100644 --- a/app/contacts/app_languages.php +++ b/app/contacts/app_languages.php @@ -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 (ndice) para este elemento da matriz."; $text['description-order']['fr-fr'] = "Dfinir l'ordre (index) pour cet lment 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"; diff --git a/app/contacts/contact_addresses.php b/app/contacts/contact_addresses.php index 72210f78b0..010805b0b0 100644 --- a/app/contacts/contact_addresses.php +++ b/app/contacts/contact_addresses.php @@ -114,10 +114,10 @@ require_once "resources/paging.php"; echo "\n"; echo " ".$row['address_label']." \n"; echo " ".$row['address_street']." \n"; - echo " ".$row['address_locality'].(($row['address_region'] != '') ? ", ".$row['address_region'] : null)." \n"; + echo " ".$row['address_locality'].(($row['address_locality'] != '' && $row['address_region'] != '') ? ", " : null).$row['address_region']." \n"; echo " ".$row['address_country']." \n"; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " ".$row['address_description']." \n"; echo " "; diff --git a/app/contacts/contact_auth.php b/app/contacts/contact_auth.php new file mode 100644 index 0000000000..0d7e357d30 --- /dev/null +++ b/app/contacts/contact_auth.php @@ -0,0 +1,124 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2013 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +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; + +} +?> \ No newline at end of file diff --git a/app/contacts/contact_import.php b/app/contacts/contact_import.php index 6c12b31879..13db5a6888 100644 --- a/app/contacts/contact_import.php +++ b/app/contacts/contact_import.php @@ -427,13 +427,12 @@ else { echo "\n"; echo " \n"; echo "
\n"; - //echo "Select the enclosure.\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; - echo "  \n"; + echo " ".$text['header-contacts_import_google']."\n"; echo " \n"; echo " \n"; echo "
\n"; diff --git a/app/contacts/contact_import_google.php b/app/contacts/contact_import_google.php new file mode 100644 index 0000000000..492b744fda --- /dev/null +++ b/app/contacts/contact_import_google.php @@ -0,0 +1,534 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2013 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +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."

"; + $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."

"; + $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."

"; + $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."

"; + $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."

"; + $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."

"; + $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 ""; +echo " "; +echo " "; +echo " "; +echo " "; +echo " "; +echo " "; +echo "
"; +echo " "; +echo " "; +echo " "; +echo "
".$_SESSION['contact_auth']['name']." (".$_SESSION['contact_auth']['email'].")"."
"; +echo "".$text['header-contacts_import_google'].""; +echo "

"; +echo $text['description-contacts_import_google']; +echo "


"; + +$row_style["0"] = "row_style0"; +$row_style["1"] = "row_style1"; + +echo "
\n"; +echo "\n"; + +//display groups +echo "".$text['label-groups'].""; +echo "

"; + +echo "\n"; +echo "\n"; +echo " "; +echo " \n"; +echo "\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 "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + $c=($c)?0:1; + } +} +echo "
 ".$text['label-contact_name']."
".$group['name']." (".$group['count'].")
\n"; +echo "
"; + +echo "
"; + +echo "
"; + +//display contacts +echo "".$text['header-contacts'].""; +echo "

"; + +echo "\n"; +echo "\n"; +echo " "; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo "\n"; +$c = 0; +foreach ($contacts as $contact['id'] => $contact) { + $contact_ids[] = $contact['id']; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + $c=($c)?0:1; +} +echo "
".$text['label-contact_name']."".$text['label-contact_organization']."".$text['label-contact_email']."".$text['label-phone_number']."".$text['label-contact_url']."".$text['label-address_address']."".$text['label-group']."
"; + $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 " "; + echo " ".(($contact['title']) ? $contact['title']."
" : null).$contact['organization']." "; + echo "
"; + if (sizeof($contact['emails']) > 0) { + foreach ($contact['emails'] as $contact_email) { + $contact_emails[] = "".$contact_email['label'].": ".$contact_email['address'].""; + } + echo implode('
', $contact_emails); + unset($contact_emails); + } else { echo " "; } + echo "
"; + if (sizeof($contact['numbers']) > 0) { + foreach ($contact['numbers'] as $contact_number) { + $contact_number_part = "".$contact_number['label'].": "; + if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) { + $contact_number_part .= ""; + } + $contact_number_part .= format_phone($contact_number['number']); + if (substr_count(strtoupper($contact_number['label']), 'FAX') == 0) { + $contact_number_part .= ""; + } + $contact_numbers[] = $contact_number_part; + unset($contact_number_part); + } + echo implode('
', $contact_numbers); + unset($contact_numbers); + } else { echo " "; } + echo "
"; + if (sizeof($contact['urls']) > 0) { + foreach ($contact['urls'] as $contact_url) { + $contact_urls[] = "".$contact_url['label'].": ".str_replace("http://", "", str_replace("https://", "", $contact_url['url'])).""; + } + echo implode('
', $contact_urls); + unset($contact_urls); + } else { echo " "; } + echo "
"; + 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[] = "".$contact_address['label'].": ".implode(', ', $contact_address_parts); + unset($contact_address_parts); + } + echo implode('
', $contact_addresses); + unset($contact_addresses); + } else { echo " "; } + echo "
"; + foreach ($contact['groups'] as $contact_group['id'] => $contact_group['name']) { + $contact_groups[] = $contact_group['name']; + } + echo " ".implode('
', $contact_groups); + unset($contact_groups); + echo "
\n"; +echo "
"; + +echo "
"; + +echo "
"; +echo "

"; + +// check or uncheck all contact checkboxes +if (sizeof($contact_ids) > 0) { + echo "\n"; +} + +/* +echo "
";
+print_r($contacts);
+echo "
"; +echo "

"; + +echo "
"; +echo "

SOURCE JSON DECODED ARRAY...

";
+print_r($records);
+echo "
"; +*/ + +//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; +} +?> \ No newline at end of file diff --git a/app/contacts/contact_setting_edit.php b/app/contacts/contact_setting_edit.php index a236057200..2955d7e95d 100644 --- a/app/contacts/contact_setting_edit.php +++ b/app/contacts/contact_setting_edit.php @@ -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 "\n"; echo ""; 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 "\n"; echo "\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 "

\n"; echo "\n"; @@ -215,40 +215,40 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; - echo " ".$text['label-contact_category'].":\n"; + echo " ".$text['label-contact_setting_category']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo $text['description-contact_category']."\n"; + echo $text['description-contact_setting_category']."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; - echo " ".$text['label-contact_subcategory'].":\n"; + echo " ".$text['label-contact_setting_subcategory']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo $text['description-contact_subcategory']."\n"; + echo $text['description-contact_setting_subcategory']."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; - echo " ".$text['label-contact_name'].":\n"; + echo " ".$text['label-contact_setting_type']."\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; - echo $text['description-contact_name']."\n"; + echo $text['description-contact_setting_type']."\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; - echo " ".$text['label-contact_value'].":\n"; + echo " ".$text['label-contact_setting_value']."\n"; echo "\n"; echo "\n"; $category = $row['contact_setting_category']; @@ -256,7 +256,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { $name = $row['contact_setting_name']; echo " \n"; echo "
\n"; - echo $text['description-contact_value']."\n"; + echo $text['description-contact_setting_value']."\n"; echo "\n"; echo "\n"; @@ -290,7 +290,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; - echo " ".$text['label-enabled'].":\n"; + echo " ".$text['label-enabled']."\n"; echo "\n"; echo "\n"; echo " \n"; @@ -325,11 +325,12 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; echo " \n"; - echo " \n"; + echo "
"; + echo " \n"; if ($action == "update") { - echo " \n"; + echo " \n"; } - echo " \n"; + echo " \n"; echo " \n"; echo " "; echo ""; diff --git a/app/contacts/contact_settings.php b/app/contacts/contact_settings.php index 1a84cdbe89..c0dda303b6 100644 --- a/app/contacts/contact_settings.php +++ b/app/contacts/contact_settings.php @@ -96,10 +96,10 @@ require_once "resources/paging.php"; echo " \n"; echo "\n"; echo "\n"; - echo "".$text['label-contact_category'].""; - echo "".$text['label-contact_subcategory'].""; - echo "".$text['label-contact_name'].""; - echo "".$text['label-contact_value'].""; + echo "".$text['label-contact_setting_category'].""; + echo "".$text['label-contact_setting_subcategory'].""; + echo "".$text['label-contact_setting_type'].""; + echo "".$text['label-contact_setting_value'].""; echo "".$text['label-enabled'].""; echo "".$text['label-description'].""; echo ""; diff --git a/app/contacts/contact_urls.php b/app/contacts/contact_urls.php index 1e1a612f3a..6c7999ccc2 100644 --- a/app/contacts/contact_urls.php +++ b/app/contacts/contact_urls.php @@ -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 "\n"; echo " ".$row['url_label']." \n"; - echo " ".$row['url_address']." \n"; + echo " ".str_replace("http://", "", str_replace("https://", "", $row['url_address']))." \n"; echo " ".$row['address_description']." \n"; echo " "; echo "$v_link_label_edit"; diff --git a/app/contacts/contacts.php b/app/contacts/contacts.php index 284faf299c..b589312597 100644 --- a/app/contacts/contacts.php +++ b/app/contacts/contacts.php @@ -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 " \n"; echo ""; echo "$v_link_label_add"; echo "\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 "\n"; echo " ".ucwords($row['contact_type'])." \n"; - echo " ".$row['contact_organization']." \n"; - echo " ".$row['contact_name_given']." \n"; - echo " ".$row['contact_name_family']." \n"; - echo " ".$row['contact_nickname']." \n"; - echo " ".$row['contact_title']." \n"; - //echo " ".$row['contact_category']." \n"; - echo " ".$row['contact_role']." \n"; - //echo " ".$row['contact_email']." \n"; - //echo " ".$row['contact_url']." \n"; - //echo " ".$row['contact_time_zone']." \n"; - //echo " ".$row['contact_note']." \n"; + echo " ".$row['contact_organization']." \n"; + echo " ".$row['contact_name_given']." \n"; + echo " ".$row['contact_name_family']." \n"; + echo " ".$row['contact_nickname']." \n"; + echo " ".$row['contact_title']." \n"; + echo " ".$row['contact_role']." \n"; + echo " "; + 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 "".$text["; break; + } + } + } + else { echo " "; } + echo " \n"; echo " "; echo "$v_link_label_edit"; echo "$v_link_label_delete"; diff --git a/app/contacts/resources/functions/google_get_contacts.php b/app/contacts/resources/functions/google_get_contacts.php new file mode 100644 index 0000000000..d54dab08e6 --- /dev/null +++ b/app/contacts/resources/functions/google_get_contacts.php @@ -0,0 +1,114 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2013 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +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; +} +?> \ No newline at end of file diff --git a/app/contacts/resources/functions/google_get_groups.php b/app/contacts/resources/functions/google_get_groups.php new file mode 100644 index 0000000000..2af9182f3c --- /dev/null +++ b/app/contacts/resources/functions/google_get_groups.php @@ -0,0 +1,54 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2013 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +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; +} +?> \ No newline at end of file diff --git a/app/contacts/resources/images/icon_gcontacts.png b/app/contacts/resources/images/icon_gcontacts.png new file mode 100644 index 0000000000000000000000000000000000000000..b5cde24f9cd179ae2686ffc8fd3eb77794905f7f GIT binary patch literal 2261 zcmV;`2rBo9P)^^v?$=sVZGcI}@%o)rVEE~4x z_-2GZKa-EkE!+6!rzl;7au>~|z5H~Q9)(v6e|B(3CfpECZOC1?KZ2o$bJiHp1csgywlv0ve(X z4Neqm^Z_322mX2la8(UVQldTmW{X_k1IaKp#Q>MI5H|D>Zn;up`6UEL7E%{xydqoR zzGngpsbD)s*#yZb=J%*}b={tX`1uhJNw0v>oS#|tT+<($JZpcVF? zP}p^d@W4jGm6uWgmH{%jll=-0|Jk^V%Rt{BAp^2T`lzaFux0aggdc1y`XJ?c7@ zu;j}GU!Big&9M}i@!)$3lLa<+0%XJpv&_u?`yGY7hgB)a!hUzJ1gyP`Fg=@)uM|_1N(xlLKYd2YQXdg^ zTcN{L8k>j**0Fz{7!P#ToX+xvsd8Ru^%s-AFvs+sM8>&Sy((@5En>K z+}a4#Iikyy3L>H^a5BQ5Y@p%Q*(&lvrU*$)>K7Z_hl$?;kbhQ(DmJ()) zL20H@D#K!f$$*oLCRxd5@c3XxfKV2j@jm5bDaEMxril3My;6LHzG{z)qCf0kpW}q! z2J*pU&rSj_os8O&i^qXe6}gJHI4a>#x2`7iE;GRr184=7d@U9Umv@-l9^%>g8sXH3 zCXJ>|9tnKPH#7Vou4bGsWJvU2rYTQ+chwcj{Em<}a4u3;_w;TH%k4Z!%c@kJ@!W|_r_Y4RD{dK<91(~NoT zZQy&)5~d1PT8%l4WsPc)UZy6LB`jx$!wmmL53G zk~2Im34yDqhDeT{ev$CwJyIJ;Eow29%xvLS2XQT?j7X<=hj93)E5a>Xhv$z1udtt8 z&&=Mi9O&*a3`tsDx{#B>C05#FU~irRe(|>eq+?e?6dZ{<$fwygx_GpRSI9Zk?Yr)u>OpL)EOYl7N#j*O@nqS zm0?m~6gZt8em_3Y&tg3CyPFig{b|KIY-&)I;gd0$qHGc zYv*qd5Qff1`=l^Ah{?Zpv%-!$9dtBvK~lJQkjeWn6+5QJB){T0KSP+DHfY-mjk{{c1NrG6{qwvcu4z5^=V0^lUEnhg7*HF7&aK*Hed6q2TjPy~FCxz9Q zDs;AS5!{@fNac))Nk@|k*vl3xJbHHy+n)CD`a8jPxt!ckmWIYno-Ary0d&X56gKoK zENP9#4U7UW93i}WhH#p9p2HLHcb>9s{^~k~mCQ19G?#$wV7>j(mvi{~<3+qTVydXQ zfXu2()tPgXBW=y_Ax^L^{^hX7?n7Kx4iH8s%^qDMPIQ%mgi|!Z zwwZz6|JfWG^N3DP9P{k1M~gW4E+JnRNf2R9Abp^YM91zo3HLs!(Z?)GhLXu02XR%k zltIpzq|fhOB7E}+4?|-Vot!Ycb!_tMyOq(`iwEi7JN+Y^B6oRy)XVV>N^&0uNAaDs zf082Ub6=mv_Gdgy%|z9gT-}S5uYEKJkeU1X=Z|O%a^T2WQ+PU3`Xs=G4?@Y2cBxqp z949>S4;|C4aK6-{)tH2Rd>%!=(|^_+7*M5C0*aW)>L<~?_mIX+A=)i`IG!!$)j+09 zAFS)dQc{dDim_Vp?2>00og|zYr&3bx>$f62`I6<#O_Y+T@Xqy5?&fmdYVC)lW^Jfb zXv!NpM<--^qWxVeQ4Opn0w>Flo$d}bEKy7s0#L_UmveyLPKB06)8$Y9@^EUHe03<7 zyDNfBybRwDJ8QbsV^YC;UIkzQxDr6?v83R32Ds%WgX--e!msyxzC2w7 z^q9MNp?c)1We)8=sJF7OwaKAgrkOG>(MfTghwgCEvy3-^Z1M;HFpI&lc&^V%k2RQE jc3~s@*Z&W({|PVvW6IZkvg3+s00000NkvXXu0mjfY{Xw0 literal 0 HcmV?d00001