c561dc42b6025bdceee398d888602cf236a399f1
[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 // The first parameter has to be the identification number (matricule).
9 // The second parameter facultative has to be the number of the desired address:
10 // -1 => we do not want any address;
11 // 0 => we want all the addresses;
12 // n => we want the address number n.
13 //
14 // DO NOT CHANGE THE NAMES OF THE ADDRESSES' FIELDS.
15 // IF YOU HAVE TO MAKE SOME MODIFICATION, FIRST CONTACT:
16 // admin@manageurs.com
17 function get_annuaire_infos($method, $params) {
18 require "geocoding.inc.php";
19 global $error_mat, $error_key, $globals;
20
21 // Password verification.
22 if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) {
23 return false;
24 }
25 // If address == -1, we do not retrieve any address.
26 if(isset($params[2]) && ($params[2] == -1)) {
27 unset($params[2]);
28 }
29
30 // We check we actually have an identification number.
31 if(!empty($params[1])) {
32 // We only retrieve addresses when required.
33 if(!isset($params[2])) {
34 $res = XDB::iterRow(
35 "SELECT ph.display_tel AS cell, a.naissance AS age
36 FROM auth_user_md5 AS a
37 INNER JOIN auth_user_quick AS q USING (user_id)
38 LEFT JOIN profile_phones AS ph ON (ph.pid = a.user_id AND link_type='user' AND tel_type = 'mobile')
39 WHERE a.matricule = {?} LIMIT 1", $params[1]);
40 $array = $res->next();
41 } else {
42 $res = XDB::iterRow(
43 "SELECT a.naissance, addr.text, addr.postalCode,
44 l.name, addr.countryId, addr.pid, addr.id
45 FROM auth_user_md5 AS a
46 INNER JOIN auth_user_quick AS q USING (user_id)
47 LEFT JOIN profile_addresses AS addr ON(adr.pid = a.user_id)
48 LEFT JOIN geoloc_localities AS l ON (l.id = addr.localityId)
49 WHERE a.matricule = {?} AND
50 NOT FIND_IN_SET('pro', adr.statut)
51 ORDER BY NOT FIND_IN_SET('active', adr.statut),
52 FIND_IN_SET('res-secondaire', adr.statut),
53 NOT FIND_IN_SET('courrier', adr.statut)", $params[1]);
54 // Process the addresses we got.
55 if(list($age, $text, $adr['cp'], $adr['ville'],
56 $adr['pays'], $uid, $adr['adrid']) = $res->next()) {
57 list($adr['adr1'], $adr['adr2'], $adr['adr3']) =
58 explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3));
59 $sql = XDB::query("SELECT display_tel
60 FROM profile_phones
61 WHERE pid = {?} AND link_type = 'user' AND tel_type = 'mobile'
62 LIMIT 1", $uid);
63 if ($sql->numRows() > 0) {
64 $array['cell'] = $sql->fetchOneCell();
65 } else {
66 $array['cell'] ='';
67 }
68 $array['age'] = $age;
69 $array['adresse'][] = $adr;
70
71
72 // We limit the address number by the number of available addresses.
73 $adresse = min((int) $params[2], $res->total());
74
75 if ($adresse != 1) { // We don't want the first address.
76 $i = 2;
77 while(list($age, $text, $adr['cp'], $adr['ville'],
78 $adr['pays'], , $adr['adrid']) = $res->next()) {
79 list($adr['adr1'], $adr['adr2'], $adr['adr3']) =
80 explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3));
81 if ($adresse == $i) {
82 // If we want this particular address.
83 $array['adresse'][0] = $adr;
84 //$res->free();
85 break;
86 } elseif ($adresse == 0) {
87 // If we want every address.
88 $array['adresse'][] = $adr;
89 }
90 $i++;
91 }
92 }
93
94 // We add the phone numbers.
95 $adrid_index = array();
96 foreach ($array['adresse'] as $i => $a) {
97 $adrid_index[$a['adrid']] = $i;
98 }
99 $restel = XDB::iterator(
100 "SELECT t.display_tel AS tel, t.tel_type, t.link_id as adrid
101 FROM profile_phones AS t
102 INNER JOIN profile_addresses AS a ON (t.link_id = a.id AND t.uid = a.pid)
103 WHERE t.u
104 $res = XDB::query(
105 "SELECT email
106 FROM profile_job
107 WHERE pid = {?}", $user->id());
108 $res = $res->fetchAllAssoc();
109 $pro = array();
110 foreach ($res as $res_it) {
111 if ($res_it['email'] != '') {
112 $pro[] = $res_it['email'];
113 if ($email_directory == $res_it['email']) {
114 $email_type = "pro";
115 }
116 }
117 }
118 $page->assign('list_email_pro', $pro);
119 id = {?} AND t.link_type = 'address'
120 AND NOT FIND_IN_SET('pro', a.statut)", $uid);
121 while ($tel = $restel->next()) {
122 $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel;
123 }
124 foreach ($array['adresse'] as $i => $adr) {
125 unset($lasttel);
126 foreach ($adr['tels'] as $j => $t) {
127 if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) {
128 $array['adresse'][$i]['tel'] = $t['tel'];
129 } elseif (!isset($array['adresse'][$i]['fax'])
130 && (strpos($t['tel_type'], 'Fax') === 0)) {
131 $array['adresse'][$i]['fax'] = $t['tel'];
132 } else {
133 $lasttel = $t['tel'];
134 }
135 if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) {
136 break;
137 }
138 }
139 if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) {
140 $array['adresse'][$i]['tel'] = $lasttel;
141 } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) {
142 $array['adresse'][$i]['fax'] = $lasttel;
143 }
144 unset($array['adresse'][$i]['adrid']);
145 unset($array['adresse'][$i]['tels']);
146 }
147 } else {
148 $array = false;
149 }
150 }
151
152 if ($array) { // We did get a result: the identification number was rigth.
153
154 // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89.
155 $year = (int) substr($array['age'], 0, 4);
156 $month = (int) substr($array['age'], 5, 2);
157 $day = (int) substr($array['age'], 8, 2);
158 $age = (int) date('Y') - $year - 1;
159 if(( $month < (int)date('m')) ||
160 (($month == (int)date('m')) && ($day >= (int)date('d')))) {
161 $age += 1;
162 }
163 $array['age'] = $age;
164
165 // We start the encryption of the data.
166 if (manageurs_encrypt_init($params[1]) == 1) {
167 // We did not find the key to encryptthe data.
168 $args = array("erreur" => 3, "erreurstring" => $error_key);
169 $reply = xmlrpc_encode_request(NULL,$args);
170 } else {
171 $reply = manageurs_encrypt_array($array);
172 manageurs_encrypt_close();
173 }
174 } else {
175 // The identification number was not valid.
176 $args = array("erreur" => 2, "erreurstring" => $erreur_mat);
177 $reply = xmlrpc_encode_request(NULL,$args);
178 }
179 } else {
180 // The identification number was not in argument.
181 $args = array("erreur" => 1, "erreurstring" => $error_mat);
182 $reply = xmlrpc_encode_request(NULL, $args);
183 }
184
185 return $reply;
186 }
187
188 function get_nouveau_infos($method, $params) {
189 global $error_mat, $error_key, $globals;
190 // Password verification.
191 if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) {
192 return false;
193 }
194 // We check we actually have an identification number.
195 if(!empty($params[1])) {
196 $res = XDB::query(
197 "SELECT a.nom, a.nom_usage,a.prenom, FIND_IN_SET('femme', a.flags) as femme,
198 a.deces!= 0 as decede, a.naissance, a.promo, concat(al.alias, '@m4x.org') as mail
199 FROM auth_user_md5 AS a
200 INNER JOIN aliases AS al ON (a.user_id = al.id)
201 WHERE al.flags = 'bestalias' AND a.matricule = {?}",$params[1]);
202 $data=$res->fetchOneAssoc();
203 //$data['mail'].='@polytechnique.org';
204
205
206 // We start the encryption of the data.
207 if (manageurs_encrypt_init($params[1]) == 1) {
208 // We did not find the key to encryptthe data.
209 $args = array("erreur" => 3, "erreurstring" => $error_key);
210 $reply = xmlrpc_encode_request(NULL, $args);
211 } else {
212 $reply = manageurs_encrypt_array($data);
213 manageurs_encrypt_close();
214 }
215
216 } else {
217 $reply = false;
218 }
219 return $reply;
220 }
221
222 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
223 ?>