Convert source code to UTF-8
[platal.git] / include / webservices / manageurs.server.inc.php
1 <?php
2
3 require_once('webservices/manageurs.inc.php');
4
5 $error_mat = "You didn't provide me with a valid matricule number...";
6 $error_key = "You didn't provide me with a valid cipher key...";
7 /**
8 le premier parametre doit etre le matricule
9 le second parametre facultatif doit etre le numero de l'adresse voulue :
10 -1 => on ne veut pas d'adresse
11 0 => on veut toutes les adresses
12 n => on veut l'adresse numero n
13
14 IL NE FAUT PAS CHANGER LES NOMS DES CHAMPS DE ADRESSES
15 S'IL Y A DES MODIFS A FAIRE VOIR AVEC MANAGEURS admin@manageurs.com
16 */
17 function get_annuaire_infos($method, $params) {
18 global $error_mat, $error_key, $globals;
19
20
21
22 //verif du mdp
23 if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;}
24 //si on a adresse == -1 => on ne recupère aucune adresse
25 if(isset($params[2]) && ($params[2] == -1)) unset($params[2]);
26
27
28 if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule
29
30 //on ne recupere pas les adresses inutilement
31 if(!isset($params[2])){
32 $res = XDB::iterRow(
33 "SELECT q.profile_mobile AS cell, a.naissance AS age
34 FROM auth_user_md5 AS a
35 INNER JOIN auth_user_quick AS q USING (user_id)
36 WHERE a.matricule = {?}", $params[1]);
37 $array = $res->next();
38 }
39 else{
40 $res = XDB::iterRow(
41 "SELECT q.profile_mobile AS cell, a.naissance AS age,
42 adr.adr1, adr.adr2, adr.adr3,
43 adr.postcode, adr.city, adr.country,
44 adr.uid, adr.adrid
45 FROM auth_user_md5 AS a
46 INNER JOIN auth_user_quick AS q USING (user_id)
47 LEFT JOIN adresses AS adr ON(adr.uid = a.user_id)
48 WHERE a.matricule = {?} AND
49 NOT FIND_IN_SET('pro', adr.statut)
50 ORDER BY NOT FIND_IN_SET('active', adr.statut),
51 FIND_IN_SET('res-secondaire', adr.statut),
52 NOT FIND_IN_SET('courrier', adr.statut)", $params[1]);
53 //traitement des adresses si necessaire
54 if(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'],
55 $adr['pays'], $uid, $adr['adrid']) = $res->next())
56 {
57 $array['cell'] = $cell;
58 $array['age'] = $age;
59 $array['adresse'][] = $adr;
60
61
62 //on clamp le numero au nombre d'adresses dispo
63 $adresse = min((int) $params[2], $res->total());
64
65 if ($adresse != 1) { //on ne veut pas la premiere adresse
66 $i = 2;
67 while(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'],
68 $adr['pays'], , $adr['adrid']) = $res->next())
69 {
70 if($adresse == $i){//si on veut cette adresse en particulier
71 $array['adresse'][0] = $adr;
72 //$res->free();
73 break;
74 }
75 elseif($adresse == 0){//si on veut toutes les adresses
76 $array['adresse'][] = $adr;
77 }
78 $i++;
79 }
80 }
81
82 // on rajoute les numéros de tél
83 $adrid_index = array();
84 foreach ($array['adresse'] as $i => $a) $adrid_index[$a['adrid']] = $i;
85 // on rajoute les numéros de tels
86 $restel = XDB::iterator(
87 "SELECT t.tel, t.tel_type, t.adrid
88 FROM tels AS t
89 INNER JOIN adresses AS a ON (t.adrid = a.adrid AND t.uid = a.uid)
90 WHERE t.uid = {?} AND NOT FIND_IN_SET('pro', a.statut)", $uid);
91 while ($tel = $restel->next()) $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel;
92 foreach ($array['adresse'] as $i => $adr) {
93 unset($lasttel);
94 foreach($adr['tels'] as $j => $t){
95 if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) $array['adresse'][$i]['tel'] = $t['tel'];
96 elseif (!isset($array['adresse'][$i]['fax']) && (strpos($t['tel_type'], 'Fax') === 0)) $array['adresse'][$i]['fax'] = $t['tel'];
97 else $lasttel = $t['tel'];
98 if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) break;
99 }
100 if (!isset($array['adresse'][$i]['tel']) && isset($lasttel))
101 $array['adresse'][$i]['tel'] = $lasttel;
102 elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel))
103 $array['adresse'][$i]['fax'] = $lasttel;
104 unset($array['adresse'][$i]['adrid']);
105 unset($array['adresse'][$i]['tels']);
106 }
107 }
108 else{
109 $array = false;
110 }
111 }
112
113 if ($array) { // on a bien eu un résultat : le matricule etait bon
114
115 //on n'envoit que l'age à manageurs le format est YYYY-MM-DD 0123-56-89
116 $year = (int) substr($array['age'],0,4);
117 $month = (int) substr($array['age'],5,2);
118 $day = (int) substr($array['age'],8,2);
119 $age = (int) date('Y') - $year - 1;
120 if(( $month < (int)date('m')) ||
121 (($month == (int)date('m')) && ($day >= (int)date('d'))))
122 {
123 $age += 1;
124 }
125 $array['age'] = $age;
126
127 //on commence le cryptage des donnees
128 if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter
129 $args = array("erreur" => 3, "erreurstring" => $error_key);
130 $reply = xmlrpc_encode_request(NULL,$args);
131 } else {
132 $reply = manageurs_encrypt_array($array);
133 manageurs_encrypt_close();
134 }
135 } else {//le matricule n'etait pas valide
136 $args = array("erreur" => 2, "erreurstring" => $erreur_mat);
137 $reply = xmlrpc_encode_request(NULL,$args);
138 }
139 } else {//le matricule n'etait pas en argument
140 $args = array("erreur" => 1, "erreurstring" => $error_mat);
141 $reply = xmlrpc_encode_request(NULL,$args);
142 }
143
144 return $reply;
145 }
146
147 function get_nouveau_infos($method, $params) {
148 global $error_mat, $error_key, $globals;
149 //verif du mdp
150 if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;}
151 if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule
152
153 $res = XDB::query(
154 "SELECT a.nom, a.nom_usage,a.prenom,a.flags='femme' as femme ,a.deces!= 0 as decede ,
155 a.naissance, a.promo, concat(al.alias, '@m4x.org') as mail
156 FROM auth_user_md5 AS a
157 INNER JOIN aliases as al ON a.user_id=al.id
158 WHERE al.flags='bestalias' and a.matricule = {?}",$params[1]);
159 $data=$res->fetchOneAssoc();
160 //$data['mail'].='@polytechnique.org';
161
162
163 //on commence le cryptage des donnees
164 if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter
165 $args = array("erreur" => 3, "erreurstring" => $error_key);
166 $reply = xmlrpc_encode_request(NULL,$args);
167 } else {
168 $reply = manageurs_encrypt_array($data);
169 manageurs_encrypt_close();
170 }
171
172 }
173 else{
174 $reply=false;
175 }
176 return $reply;
177
178 }
179
180 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
181 ?>