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 | |
436e5ff3 |
20 | |
21 | |
0337d704 |
22 | //verif du mdp |
ff43561f |
23 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;} |
0337d704 |
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 = $globals->xdb->iterRow( |
33 | "SELECT q.profile_mobile AS cell, a.naissance AS age |
ff43561f |
34 | FROM auth_user_md5 AS a |
35 | INNER JOIN auth_user_quick AS q USING (user_id) |
36 | WHERE a.matricule = {?}", $params[1]); |
0337d704 |
37 | } |
38 | else{ |
39 | $res = $globals->xdb->iterRow( |
40 | "SELECT q.profile_mobile AS cell, a.naissance AS age, |
41 | adr.adr1, adr.adr2, adr.adr3, |
42 | adr.postcode, adr.city, adr.country, |
43 | adr.tel, adr.fax |
44 | FROM auth_user_md5 AS a |
45 | INNER JOIN auth_user_quick AS q USING (user_id) |
46 | LEFT JOIN adresses AS adr ON(adr.uid = a.user_id) |
47 | WHERE a.matricule = {?} AND |
48 | NOT FIND_IN_SET('pro', adr.statut) |
49 | ORDER BY NOT FIND_IN_SET('active', adr.statut), |
50 | FIND_IN_SET('res-secondaire', adr.statut), |
51 | NOT FIND_IN_SET('courrier', adr.statut)", $params[1]); |
52 | |
ff43561f |
53 | } |
0337d704 |
54 | |
436e5ff3 |
55 | //traitement des adresses si necessaire |
0337d704 |
56 | if (isset($params[2])) { |
ff43561f |
57 | if(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'], |
58 | $adr['pays'], $adr['tel'], $adr['fax']) = $res->next()) |
0337d704 |
59 | { |
60 | $array['cell'] = $cell; |
61 | $array['age'] = $age; |
62 | $array['adresse'][] = $adr; |
63 | |
64 | //on clamp le numero au nombre d'adresses dispo |
65 | $adresse = min((int) $params[2], $res->total()); |
66 | |
67 | if ($adresse != 1) { //on ne veut pas la premiere adresse |
68 | $i = 2; |
ff43561f |
69 | while(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'], |
70 | $adr['pays'], $adr['tel'], $adr['fax']) = $res->next()) |
0337d704 |
71 | { |
72 | if($adresse == $i){//si on veut cette adresse en particulier |
73 | $array['adresse'][0] = $adr; |
74 | //$res->free(); |
75 | break; |
76 | } |
77 | elseif($adresse == 0){//si on veut toutes les adresses |
78 | $array['adresse'][] = $adr; |
79 | } |
80 | $i++; |
81 | } |
82 | } |
83 | } |
84 | else{ |
85 | $array = false; |
86 | } |
87 | } |
88 | else { //cas où on ne veut pas d'adresse |
89 | $array = $res->next(); |
90 | } |
ff43561f |
91 | |
0337d704 |
92 | |
93 | if ($array) { // on a bien eu un résultat : le matricule etait bon |
94 | |
95 | //on n'envoit que l'age à manageurs le format est YYYY-MM-DD 0123-56-89 |
96 | $year = (int) substr($array['age'],0,4); |
97 | $month = (int) substr($array['age'],5,2); |
98 | $day = (int) substr($array['age'],8,2); |
99 | $age = (int) date('Y') - $year - 1; |
100 | if(( $month < (int)date('m')) || |
101 | (($month == (int)date('m')) && ($day >= (int)date('d')))) |
102 | { |
103 | $age += 1; |
104 | } |
105 | $array['age'] = $age; |
106 | |
107 | //on commence le cryptage des donnees |
108 | if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter |
109 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
110 | $reply = xmlrpc_encode_request(NULL,$args); |
111 | } else { |
112 | $reply = manageurs_encrypt_array($array); |
113 | manageurs_encrypt_close(); |
114 | } |
115 | } else {//le matricule n'etait pas valide |
116 | $args = array("erreur" => 2, "erreurstring" => $erreur_mat); |
117 | $reply = xmlrpc_encode_request(NULL,$args); |
118 | } |
119 | } else {//le matricule n'etait pas en argument |
120 | $args = array("erreur" => 1, "erreurstring" => $error_mat); |
121 | $reply = xmlrpc_encode_request(NULL,$args); |
436e5ff3 |
122 | } |
123 | |
0337d704 |
124 | return $reply; |
125 | } |
126 | |
436e5ff3 |
127 | function get_nouveau_infos($method, $params) { |
128 | global $error_mat, $error_key, $globals; |
129 | //verif du mdp |
130 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;} |
131 | if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule |
132 | |
133 | $res = $globals->xdb->query( |
134 | "SELECT a.nom, a.nom_usage,a.prenom,a.flags='femme' as femme ,a.deces!= 0 as decede ,a.naissance,a.promo,al.alias as mail |
135 | FROM auth_user_md5 AS a |
136 | INNER JOIN aliases as al ON a.user_id=al.id |
137 | WHERE al.flags='bestalias' and a.matricule = {?}",$params[1]); |
138 | $data=$res->fetchOneAssoc(); |
139 | //$data['mail'].='@polytechnique.org'; |
140 | |
141 | |
142 | //on commence le cryptage des donnees |
143 | if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter |
144 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
145 | $reply = xmlrpc_encode_request(NULL,$args); |
146 | } else { |
147 | $reply = manageurs_encrypt_array($data); |
148 | manageurs_encrypt_close(); |
149 | } |
150 | |
151 | } |
152 | else{ |
153 | $reply=false; |
154 | } |
155 | return $reply; |
156 | |
157 | } |
158 | |
0337d704 |
159 | ?> |