Typo.
[platal.git] / modules / carnet / outlook.inc.php
CommitLineData
b3ad574d
PC
1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 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
28 private static function add_address(&$adr, &$contact, $adr_type = 'autre') {
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
45 private static function profile_to_contact(&$p) {
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()) {
57 Outlook::add_address(&$adr, &$contact, 'domicile');
58 }
59 if ($adr = $adrs->next()) {
60 Outlook::add_address(&$adr, &$contact, 'autre');
61 }
62 // Pro
63 $adrs = $p->iterAddresses(Profile::ADDRESS_PRO);
64 if ($adr = $adrs->next()) {
65 Outlook::add_address(&$adr, &$contact, 'bureau');
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.'>';
94 $contact['Adresse de messagerie 2'] = $user->bestalias_alternate;
95 $contact['Nom complet de l\'adresse de messagerie 2'] = $p->fullName().' <'.$user->bestalias_alternate.'>';
96 if ($user->bestalias != $user->forlife) {
97 $contact['Adresse de messagerie 3'] = $user->forlife;
98 $contact['Nom complet de l\'adresse de messagerie 3'] = $p->fullName().' <'.$user->forlife.'>';
99 }
100 $groups = $user->groups();
101 if (count($groups)) {
102 $gn = DirEnum::getOptions(DirEnum::GROUPESX);
103 $gns = array();
104 foreach (array_keys($groups) as $gid) if (!empty($gn[$gid])) {
105 $gns[$gid] = $gn[$gid];
106 }
107 if (count($gns) > 0) {
108 $contact['Utilisateur 1'] = 'Groupes X : '. join(', ', $gns);
109 }
110 }
111 }
112 return $contact;
113 }
114
56721636 115 private static function protect(&$t) {
b3ad574d
PC
116 if (empty($t)) {
117 return '""';
118 }
119 $t = preg_replace("/\r?\n/", ", ", $t);
120 return '"'.strtr(utf8_decode($t),'"', '\\"').'"';
121 }
122
56721636 123 public static function output_profiles($profiles, $lang) {
e5ef8615 124 pl_content_headers("text/plain", "iso8859-15");
b3ad574d
PC
125 $fields =& Outlook::$contact_fields[$lang];
126 foreach ($fields as $i => $k) {
127 if ($i != 0) {
128 echo ',';
129 }
130 echo Outlook::protect($k);
131 }
132 echo "\r\n";
133 foreach ($profiles as &$p) {
134 $values = Outlook::profile_to_contact(&$p);
135 foreach ($fields as $i => $k) {
136 if ($i != 0) {
137 echo ',';
138 echo Outlook::protect($values[$k]);
139 } else {
140 // HACK to fix fullname
56721636
PC
141 $fullname = $p->firstName()." ".$p->lastName();
142 echo Outlook::protect($fullname);
b3ad574d
PC
143 }
144 }
145 echo "\r\n";
146 }
147 }
148}
149// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
150?>