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