3 require_once('webservices/manageurs.inc.php');
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...";
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.
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;
21 // Password verification.
22 if(!isset($params[0]) ||
($params[0] != $globals->manageurs
->manageurs_pass
)) {
25 // If address == -1, we do not retrieve any address.
26 if(isset($params[2]) && ($params[2] == -1)) {
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])) {
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.uid = a.user_id AND link_type='user' AND tel_type = 'mobile')
39 WHERE a.matricule = {?} LIMIT 1", $params[1]);
40 $array = $res->next();
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
61 WHERE uid = {?} AND link_type = 'user' AND tel_type = 'mobile'
63 if ($sql->numRows() > 0) {
64 $array['cell'] = $sql->fetchOneCell();
69 $array['adresse'][] = $adr;
72 // We limit the address number by the number of available addresses.
73 $adresse = min((int) $params[2], $res->total());
75 if ($adresse != 1) { // We don't want the first address.
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));
82 // If we want this particular address.
83 $array['adresse'][0] = $adr;
86 } elseif ($adresse == 0) {
87 // If we want every address.
88 $array['adresse'][] = $adr;
94 // We add the phone numbers.
95 $adrid_index = array();
96 foreach ($array['adresse'] as $i => $a) {
97 $adrid_index[$a['adrid']] = $i;
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.uid = {?} AND t.link_type = 'address'
104 AND NOT FIND_IN_SET('pro', a.statut)", $uid);
105 while ($tel = $restel->next()) {
106 $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel;
108 foreach ($array['adresse'] as $i => $adr) {
110 foreach ($adr['tels'] as $j => $t) {
111 if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) {
112 $array['adresse'][$i]['tel'] = $t['tel'];
113 } elseif (!isset($array['adresse'][$i]['fax'])
114 && (strpos($t['tel_type'], 'Fax') === 0)) {
115 $array['adresse'][$i]['fax'] = $t['tel'];
117 $lasttel = $t['tel'];
119 if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) {
123 if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) {
124 $array['adresse'][$i]['tel'] = $lasttel;
125 } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) {
126 $array['adresse'][$i]['fax'] = $lasttel;
128 unset($array['adresse'][$i]['adrid']);
129 unset($array['adresse'][$i]['tels']);
136 if ($array) { // We did get a result: the identification number was rigth.
138 // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89.
139 $year = (int) substr($array['age'], 0, 4);
140 $month = (int) substr($array['age'], 5, 2);
141 $day = (int) substr($array['age'], 8, 2);
142 $age = (int) date('Y') - $year - 1;
143 if(( $month < (int)date('m')) ||
144 (($month == (int)date('m')) && ($day >= (int)date('d')))) {
147 $array['age'] = $age;
149 // We start the encryption of the data.
150 if (manageurs_encrypt_init($params[1]) == 1) {
151 // We did not find the key to encryptthe data.
152 $args = array("erreur" => 3, "erreurstring" => $error_key);
153 $reply = xmlrpc_encode_request(NULL
,$args);
155 $reply = manageurs_encrypt_array($array);
156 manageurs_encrypt_close();
159 // The identification number was not valid.
160 $args = array("erreur" => 2, "erreurstring" => $erreur_mat);
161 $reply = xmlrpc_encode_request(NULL
,$args);
164 // The identification number was not in argument.
165 $args = array("erreur" => 1, "erreurstring" => $error_mat);
166 $reply = xmlrpc_encode_request(NULL
, $args);
172 function get_nouveau_infos($method, $params) {
173 global $error_mat, $error_key, $globals;
174 // Password verification.
175 if(!isset($params[0]) ||
($params[0] != $globals->manageurs
->manageurs_pass
)) {
178 // We check we actually have an identification number.
179 if(!empty($params[1])) {
181 "SELECT a.nom, a.nom_usage,a.prenom, FIND_IN_SET('femme', a.flags) as femme,
182 a.deces!= 0 as decede, a.naissance, a.promo, concat(al.alias, '@m4x.org') as mail
183 FROM auth_user_md5 AS a
184 INNER JOIN aliases AS al ON (a.user_id = al.id)
185 WHERE al.flags = 'bestalias' AND a.matricule = {?}",$params[1]);
186 $data=$res->fetchOneAssoc();
187 //$data['mail'].='@polytechnique.org';
190 // We start the encryption of the data.
191 if (manageurs_encrypt_init($params[1]) == 1) {
192 // We did not find the key to encryptthe data.
193 $args = array("erreur" => 3, "erreurstring" => $error_key);
194 $reply = xmlrpc_encode_request(NULL
, $args);
196 $reply = manageurs_encrypt_array($data);
197 manageurs_encrypt_close();
206 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: