Happy New Year!
[platal.git] / modules / carnet / outlook.inc.php
CommitLineData
b3ad574d
PC
1<?php
2/***************************************************************************
c441aabe 3 * Copyright (C) 2003-2014 Polytechnique.org *
b3ad574d
PC
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class Outlook {
23
24 static $contact_fields = array(
25 'fr' => array("Nom","Titre","Prénom","Deuxième prénom","Nom","Suffixe","Surnom","Société ","Service ","Titre","Rue (bureau)","Rue (bureau) 2","Rue (bureau) 3","Ville (bureau)","Dép/Région (bureau)","Code postal (bureau)","Pays (bureau)","Rue (domicile)","Rue (domicile) 2","Rue (domicile) 3","Ville (domicile)","Dép/Région (domicile)","Code postal (domicile)","Pays (domicile)","Rue (autre)","Rue (autre) 2","Rue (autre) 3","Ville (autre)","Dép/Région (autre)","Code postal (autre)","Pays (autre)","Téléphone de l'assistant(e)","Télécopie (bureau)","Téléphone (bureau)","Téléphone 2 (bureau)","Rappel","Téléphone (voiture)","Téléphone société","Télécopie (domicile)","Téléphone (domicile)","Téléphone 2 (domicile)","RNIS","Tél. mobile","Télécopie (autre)","Téléphone (autre)","Récepteur de radiomessagerie","Téléphone principal","Radio téléphone","Téléphone TDD/TTY","Télex","Adresse de messagerie","Type de messagerie","Nom complet de l'adresse de messagerie","Adresse de messagerie 2","Type de messagerie 2","Nom complet de l'adresse de messagerie 2","Adresse de messagerie 3","Type de messagerie 3","Nom complet de l'adresse de messagerie 3","Anniversaire","Anniversaire de mariage ou fête","Autre boîte postale","B.P. professionnelle","Boîte postale du domicile","Bureau","Catégories","Code gouvernement","Compte","Conjoint(e)","Critère de diffusion","Disponibilité Internet","Emplacement","Enfants","Informations facturation","Initiales","Kilométrage","Langue","Mots clés","Nom de l'assistant(e)","Notes","Numéro d'identification de l'organisation","Page Web","Passe-temps","Priorité","Privé","Profession","Recommandé par","Responsable","Serveur d'annuaire","Sexe","Utilisateur 1","Utilisateur 2","Utilisateur 3","Utilisateur 4"),
26 );
27
26ba053e 28 private static function add_address($adr, $contact, $adr_type = 'autre') {
b3ad574d
PC
29 $contact['Rue ('.$adr_type.')'] = $adr->text;
30 $contact['Code postal ('.$adr_type.')'] = $adr->postalCode;
31 $contact['Ville ('.$adr_type.')'] = $adr->locality;
32 $contact['Dép/Région ('.$adr_type.')'] = $adr->administrativeArea;
33 $contact['Pays ('.$adr_type.')'] = $adr->country;
56721636
PC
34 $phones = $adr->phones();
35 foreach ($phones as $p) {
36 if ($p->hasType(Profile::PHONE_TYPE_FIXED)) {
37 $contact['Téléphone ('.$adr_type.')'] = $p->display;
38 }
39 if ($p->hasType(Profile::PHONE_TYPE_FAX)) {
40 $contact['Télécopie ('.$adr_type.')'] = $p->display;
41 }
42 }
b3ad574d
PC
43 }
44
26ba053e 45 private static function profile_to_contact($p) {
b3ad574d
PC
46 $contact = array(
47 'Prénom' => $p->firstName(),
48 'Nom' => $p->lastName(),
49 'Notes' => '('.$p->promo.')',
50 'Tél. mobile' => $p->mobile,
51 'Anniversaire' => $p->birthdate,
52 'Surnom' => $p->nickname,
53 );
54 // Homes
55 $adrs = $p->iterAddresses(Profile::ADDRESS_PERSO);
56 if ($adr = $adrs->next()) {
26ba053e 57 Outlook::add_address($adr, $contact, 'domicile');
b3ad574d
PC
58 }
59 if ($adr = $adrs->next()) {
26ba053e 60 Outlook::add_address($adr, $contact, 'autre');
b3ad574d
PC
61 }
62 // Pro
63 $adrs = $p->iterAddresses(Profile::ADDRESS_PRO);
64 if ($adr = $adrs->next()) {
26ba053e 65 Outlook::add_address($adr, $contact, 'bureau');
b3ad574d
PC
66 }
67 $mainjob = $p->getMainJob();
68 if ($mainjob && $mainjob->company) {
69 $contact['Société '] = $mainjob->company->name;
70 }
71 if (!empty($p->section)) {
72 $contact['Utilisateur 2'] = 'Section : '. $p->section;
73 }
74 if ($p->isFemale()) {
75 $contact['Sexe'] = 'Féminin';
76 } else {
77 $contact['Sexe'] = 'Masculin';
78 }
79 $binets = $p->getBinets();
80 if (count($binets)) {
81 $bn = DirEnum::getOptions(DirEnum::BINETS);
82 $bns = array();
83 foreach (array_keys($binets) as $bid) if (!empty($bn[$bid])) {
84 $bns[$bid] = $bn[$bid];
85 }
86 if (count($bns) > 0) {
87 $contact['Utilisateur 3'] = 'Binets : '.join(', ', $bns);
88 }
89 }
90 $user = $p->owner();
91 if ($user) {
92 $contact['Adresse de messagerie'] = $user->bestalias;
93 $contact['Nom complet de l\'adresse de messagerie'] = $p->fullName().' <'.$user->bestalias.'>';
b3ad574d
PC
94 if ($user->bestalias != $user->forlife) {
95 $contact['Adresse de messagerie 3'] = $user->forlife;
96 $contact['Nom complet de l\'adresse de messagerie 3'] = $p->fullName().' <'.$user->forlife.'>';
97 }
98 $groups = $user->groups();
99 if (count($groups)) {
100 $gn = DirEnum::getOptions(DirEnum::GROUPESX);
101 $gns = array();
102 foreach (array_keys($groups) as $gid) if (!empty($gn[$gid])) {
103 $gns[$gid] = $gn[$gid];
104 }
105 if (count($gns) > 0) {
106 $contact['Utilisateur 1'] = 'Groupes X : '. join(', ', $gns);
107 }
108 }
109 }
110 return $contact;
111 }
112
56721636 113 private static function protect(&$t) {
b3ad574d
PC
114 if (empty($t)) {
115 return '""';
116 }
117 $t = preg_replace("/\r?\n/", ", ", $t);
118 return '"'.strtr(utf8_decode($t),'"', '\\"').'"';
119 }
120
56721636 121 public static function output_profiles($profiles, $lang) {
e5ef8615 122 pl_content_headers("text/plain", "iso8859-15");
b3ad574d
PC
123 $fields =& Outlook::$contact_fields[$lang];
124 foreach ($fields as $i => $k) {
125 if ($i != 0) {
126 echo ',';
127 }
128 echo Outlook::protect($k);
129 }
130 echo "\r\n";
131 foreach ($profiles as &$p) {
26ba053e 132 $values = Outlook::profile_to_contact($p);
b3ad574d
PC
133 foreach ($fields as $i => $k) {
134 if ($i != 0) {
135 echo ',';
136 echo Outlook::protect($values[$k]);
137 } else {
138 // HACK to fix fullname
56721636
PC
139 $fullname = $p->firstName()." ".$p->lastName();
140 echo Outlook::protect($fullname);
b3ad574d
PC
141 }
142 }
143 echo "\r\n";
144 }
145 }
146}
147// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
148?>