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