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..."; | |
8f60459a SJ |
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 | |
0337d704 | 17 | function get_annuaire_infos($method, $params) { |
8f60459a | 18 | require "geocoding.inc.php"; |
0337d704 | 19 | global $error_mat, $error_key, $globals; |
20 | ||
8f60459a SJ |
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 | } | |
0337d704 | 29 | |
8f60459a SJ |
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])) { | |
08cce2ff | 34 | $res = XDB::iterRow( |
b235d980 GB |
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]); | |
79a5acea | 40 | $array = $res->next(); |
8f60459a | 41 | } else { |
08cce2ff | 42 | $res = XDB::iterRow( |
8f60459a SJ |
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) | |
0337d704 | 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]); | |
8f60459a SJ |
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 uid = {?} AND link_type = 'user' AND tel_type = 'mobile' | |
62 | LIMIT 1", $uid); | |
63 | if ($sql->numRows() > 0) { | |
b235d980 GB |
64 | $array['cell'] = $sql->fetchOneCell(); |
65 | } else { | |
66 | $array['cell'] =''; | |
67 | } | |
0337d704 | 68 | $array['age'] = $age; |
69 | $array['adresse'][] = $adr; | |
70 | ||
79a5acea | 71 | |
8f60459a | 72 | // We limit the address number by the number of available addresses. |
0337d704 | 73 | $adresse = min((int) $params[2], $res->total()); |
74 | ||
8f60459a | 75 | if ($adresse != 1) { // We don't want the first address. |
0337d704 | 76 | $i = 2; |
8f60459a SJ |
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. | |
0337d704 | 83 | $array['adresse'][0] = $adr; |
84 | //$res->free(); | |
85 | break; | |
8f60459a SJ |
86 | } elseif ($adresse == 0) { |
87 | // If we want every address. | |
0337d704 | 88 | $array['adresse'][] = $adr; |
89 | } | |
90 | $i++; | |
91 | } | |
92 | } | |
eaf30d86 | 93 | |
8f60459a | 94 | // We add the phone numbers. |
79a5acea | 95 | $adrid_index = array(); |
8f60459a SJ |
96 | foreach ($array['adresse'] as $i => $a) { |
97 | $adrid_index[$a['adrid']] = $i; | |
98 | } | |
08cce2ff | 99 | $restel = XDB::iterator( |
8f60459a SJ |
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; | |
107 | } | |
79a5acea | 108 | foreach ($array['adresse'] as $i => $adr) { |
109 | unset($lasttel); | |
8f60459a SJ |
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']; | |
116 | } else { | |
117 | $lasttel = $t['tel']; | |
118 | } | |
119 | if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) { | |
120 | break; | |
121 | } | |
79a5acea | 122 | } |
8f60459a | 123 | if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) { |
79a5acea | 124 | $array['adresse'][$i]['tel'] = $lasttel; |
8f60459a | 125 | } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) { |
79a5acea | 126 | $array['adresse'][$i]['fax'] = $lasttel; |
8f60459a | 127 | } |
79a5acea | 128 | unset($array['adresse'][$i]['adrid']); |
129 | unset($array['adresse'][$i]['tels']); | |
130 | } | |
8f60459a | 131 | } else { |
0337d704 | 132 | $array = false; |
133 | } | |
134 | } | |
0337d704 | 135 | |
8f60459a | 136 | if ($array) { // We did get a result: the identification number was rigth. |
0337d704 | 137 | |
8f60459a SJ |
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); | |
0337d704 | 142 | $age = (int) date('Y') - $year - 1; |
143 | if(( $month < (int)date('m')) || | |
8f60459a | 144 | (($month == (int)date('m')) && ($day >= (int)date('d')))) { |
0337d704 | 145 | $age += 1; |
146 | } | |
147 | $array['age'] = $age; | |
148 | ||
8f60459a SJ |
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. | |
0337d704 | 152 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
153 | $reply = xmlrpc_encode_request(NULL,$args); | |
154 | } else { | |
155 | $reply = manageurs_encrypt_array($array); | |
156 | manageurs_encrypt_close(); | |
157 | } | |
8f60459a SJ |
158 | } else { |
159 | // The identification number was not valid. | |
0337d704 | 160 | $args = array("erreur" => 2, "erreurstring" => $erreur_mat); |
161 | $reply = xmlrpc_encode_request(NULL,$args); | |
162 | } | |
8f60459a SJ |
163 | } else { |
164 | // The identification number was not in argument. | |
0337d704 | 165 | $args = array("erreur" => 1, "erreurstring" => $error_mat); |
8f60459a | 166 | $reply = xmlrpc_encode_request(NULL, $args); |
436e5ff3 | 167 | } |
eaf30d86 PH |
168 | |
169 | return $reply; | |
170 | } | |
0337d704 | 171 | |
436e5ff3 | 172 | function get_nouveau_infos($method, $params) { |
173 | global $error_mat, $error_key, $globals; | |
8f60459a SJ |
174 | // Password verification. |
175 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) { | |
176 | return false; | |
177 | } | |
178 | // We check we actually have an identification number. | |
179 | if(!empty($params[1])) { | |
08cce2ff | 180 | $res = XDB::query( |
8f60459a SJ |
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]); | |
436e5ff3 | 186 | $data=$res->fetchOneAssoc(); |
187 | //$data['mail'].='@polytechnique.org'; | |
188 | ||
eaf30d86 | 189 | |
8f60459a SJ |
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. | |
436e5ff3 | 193 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
8f60459a | 194 | $reply = xmlrpc_encode_request(NULL, $args); |
436e5ff3 | 195 | } else { |
196 | $reply = manageurs_encrypt_array($data); | |
197 | manageurs_encrypt_close(); | |
198 | } | |
199 | ||
8f60459a SJ |
200 | } else { |
201 | $reply = false; | |
436e5ff3 | 202 | } |
8f60459a | 203 | return $reply; |
436e5ff3 | 204 | } |
205 | ||
a7de4ef7 | 206 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 207 | ?> |