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) { |
18 | global $error_mat, $error_key, $globals; | |
19 | ||
8f60459a SJ |
20 | // Password verification. |
21 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) { | |
22 | return false; | |
23 | } | |
24 | // If address == -1, we do not retrieve any address. | |
25 | if(isset($params[2]) && ($params[2] == -1)) { | |
26 | unset($params[2]); | |
27 | } | |
0337d704 | 28 | |
8f60459a SJ |
29 | // We check we actually have an identification number. |
30 | if(!empty($params[1])) { | |
31 | // We only retrieve addresses when required. | |
32 | if(!isset($params[2])) { | |
9e319def SJ |
33 | $res = XDB::iterRow("SELECT pp.display_tel AS cell, p.birthdate AS age |
34 | FROM profiles AS p | |
35 | LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = 'user' | |
36 | AND pp.tel_type = 'mobile') | |
37 | WHERE p.xorg_id = {?} LIMIT 1", | |
38 | $params[1]); | |
79a5acea | 39 | $array = $res->next(); |
8f60459a | 40 | } else { |
9e319def SJ |
41 | $res = XDB::iterRow("SELECT p.birthdate, pa.text, pa.postalCode |
42 | gl.name, pa.countryId, p.pid, pa.id | |
43 | FROM profiles AS p | |
44 | LEFT JOIN profile_addresses AS pa ON (pa.pid = p.pid) | |
45 | LEFT JOIN geoloc_localities AS gl ON (pl.id = pa.localityId) | |
46 | WHERE p.xorg_id = {?} AND NOT FIND_IN_SET('job', pa.flags) | |
47 | ORDER BY NOT FIND_IN_SET('current', pa.flags), | |
48 | FIND_IN_SET('secondary', pa.flags), | |
49 | NOT FIND_IN_SET('mail', pa.flags)", | |
50 | $params[1]); | |
8f60459a SJ |
51 | // Process the addresses we got. |
52 | if(list($age, $text, $adr['cp'], $adr['ville'], | |
9e319def | 53 | $adr['pays'], $pid, $adr['adrid']) = $res->next()) { |
8f60459a SJ |
54 | list($adr['adr1'], $adr['adr2'], $adr['adr3']) = |
55 | explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); | |
56 | $sql = XDB::query("SELECT display_tel | |
57 | FROM profile_phones | |
ce0b2c6f | 58 | WHERE pid = {?} AND link_type = 'user' AND tel_type = 'mobile' |
9e319def | 59 | LIMIT 1", $pid); |
8f60459a | 60 | if ($sql->numRows() > 0) { |
b235d980 GB |
61 | $array['cell'] = $sql->fetchOneCell(); |
62 | } else { | |
63 | $array['cell'] =''; | |
64 | } | |
0337d704 | 65 | $array['age'] = $age; |
66 | $array['adresse'][] = $adr; | |
67 | ||
79a5acea | 68 | |
8f60459a | 69 | // We limit the address number by the number of available addresses. |
0337d704 | 70 | $adresse = min((int) $params[2], $res->total()); |
71 | ||
8f60459a | 72 | if ($adresse != 1) { // We don't want the first address. |
0337d704 | 73 | $i = 2; |
8f60459a SJ |
74 | while(list($age, $text, $adr['cp'], $adr['ville'], |
75 | $adr['pays'], , $adr['adrid']) = $res->next()) { | |
76 | list($adr['adr1'], $adr['adr2'], $adr['adr3']) = | |
77 | explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); | |
78 | if ($adresse == $i) { | |
79 | // If we want this particular address. | |
0337d704 | 80 | $array['adresse'][0] = $adr; |
81 | //$res->free(); | |
82 | break; | |
8f60459a SJ |
83 | } elseif ($adresse == 0) { |
84 | // If we want every address. | |
0337d704 | 85 | $array['adresse'][] = $adr; |
86 | } | |
87 | $i++; | |
88 | } | |
89 | } | |
eaf30d86 | 90 | |
8f60459a | 91 | // We add the phone numbers. |
79a5acea | 92 | $adrid_index = array(); |
8f60459a SJ |
93 | foreach ($array['adresse'] as $i => $a) { |
94 | $adrid_index[$a['adrid']] = $i; | |
95 | } | |
9e319def SJ |
96 | $restel = XDB::iterator("SELECT pp.display_tel AS tel, pp..tel_type, pp.link_id as adrid |
97 | FROM profile_phones AS pp | |
98 | INNER JOIN profile_addresses AS pa ON (pp.link_id = pa.id AND pp.pid = pa.pid) | |
99 | WHERE pp.pid = {?} AND pp.link_type = 'address' | |
100 | AND NOT FIND_IN_SET('pro', pa.statut)", | |
101 | $pid); | |
8f60459a SJ |
102 | while ($tel = $restel->next()) { |
103 | $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel; | |
104 | } | |
79a5acea | 105 | foreach ($array['adresse'] as $i => $adr) { |
106 | unset($lasttel); | |
8f60459a SJ |
107 | foreach ($adr['tels'] as $j => $t) { |
108 | if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) { | |
109 | $array['adresse'][$i]['tel'] = $t['tel']; | |
110 | } elseif (!isset($array['adresse'][$i]['fax']) | |
111 | && (strpos($t['tel_type'], 'Fax') === 0)) { | |
112 | $array['adresse'][$i]['fax'] = $t['tel']; | |
113 | } else { | |
114 | $lasttel = $t['tel']; | |
115 | } | |
116 | if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) { | |
117 | break; | |
118 | } | |
79a5acea | 119 | } |
8f60459a | 120 | if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) { |
79a5acea | 121 | $array['adresse'][$i]['tel'] = $lasttel; |
8f60459a | 122 | } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) { |
79a5acea | 123 | $array['adresse'][$i]['fax'] = $lasttel; |
8f60459a | 124 | } |
79a5acea | 125 | unset($array['adresse'][$i]['adrid']); |
126 | unset($array['adresse'][$i]['tels']); | |
127 | } | |
8f60459a | 128 | } else { |
0337d704 | 129 | $array = false; |
130 | } | |
131 | } | |
0337d704 | 132 | |
8f60459a | 133 | if ($array) { // We did get a result: the identification number was rigth. |
0337d704 | 134 | |
8f60459a SJ |
135 | // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89. |
136 | $year = (int) substr($array['age'], 0, 4); | |
137 | $month = (int) substr($array['age'], 5, 2); | |
138 | $day = (int) substr($array['age'], 8, 2); | |
0337d704 | 139 | $age = (int) date('Y') - $year - 1; |
140 | if(( $month < (int)date('m')) || | |
8f60459a | 141 | (($month == (int)date('m')) && ($day >= (int)date('d')))) { |
0337d704 | 142 | $age += 1; |
143 | } | |
144 | $array['age'] = $age; | |
145 | ||
8f60459a SJ |
146 | // We start the encryption of the data. |
147 | if (manageurs_encrypt_init($params[1]) == 1) { | |
148 | // We did not find the key to encryptthe data. | |
0337d704 | 149 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
150 | $reply = xmlrpc_encode_request(NULL,$args); | |
151 | } else { | |
152 | $reply = manageurs_encrypt_array($array); | |
153 | manageurs_encrypt_close(); | |
154 | } | |
8f60459a SJ |
155 | } else { |
156 | // The identification number was not valid. | |
0337d704 | 157 | $args = array("erreur" => 2, "erreurstring" => $erreur_mat); |
158 | $reply = xmlrpc_encode_request(NULL,$args); | |
159 | } | |
8f60459a SJ |
160 | } else { |
161 | // The identification number was not in argument. | |
0337d704 | 162 | $args = array("erreur" => 1, "erreurstring" => $error_mat); |
8f60459a | 163 | $reply = xmlrpc_encode_request(NULL, $args); |
436e5ff3 | 164 | } |
eaf30d86 PH |
165 | |
166 | return $reply; | |
167 | } | |
0337d704 | 168 | |
436e5ff3 | 169 | function get_nouveau_infos($method, $params) { |
170 | global $error_mat, $error_key, $globals; | |
8f60459a SJ |
171 | // Password verification. |
172 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) { | |
173 | return false; | |
174 | } | |
175 | // We check we actually have an identification number. | |
176 | if(!empty($params[1])) { | |
9e319def SJ |
177 | $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES); |
178 | $nameTypes = array_flip($nameTypes); | |
179 | ||
180 | $res = XDB::query("SELECT pnl.name AS nom, pnu.name AS nom_usage, pnf.name AS prenom, | |
181 | p.sex = 'female' AS femme, p.deathdate IS NOT NULL AS decede, | |
182 | p.birthdate, pd.promo, CONCAT(a.alias, '@m4x.org') AS mail | |
183 | FROM profiles AS p | |
184 | INNER JOIN account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms) | |
185 | INNER JOIN aliases AS a ON (a.uid = ap.uid) | |
186 | INNER JOIN profile_display AS pd PN (p.pid = pd.pid) | |
187 | INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?}) | |
188 | INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?}) | |
189 | INNER JOIN profile_name AS pnu ON (p.pid = pnu.pid AND pnu.typeid = {?}) | |
190 | WHERE a.flags = 'bestalias' AND p.xorg_id = {?}", | |
191 | $nameTypes['name_ini'], $nameTypes['lastname_ordinary'], | |
192 | $nameTypes['firstname_ini'], $params[1]); | |
193 | // $data['mail'] .= '@polytechnique.org'; | |
436e5ff3 | 194 | |
eaf30d86 | 195 | |
8f60459a SJ |
196 | // We start the encryption of the data. |
197 | if (manageurs_encrypt_init($params[1]) == 1) { | |
198 | // We did not find the key to encryptthe data. | |
436e5ff3 | 199 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
8f60459a | 200 | $reply = xmlrpc_encode_request(NULL, $args); |
436e5ff3 | 201 | } else { |
202 | $reply = manageurs_encrypt_array($data); | |
203 | manageurs_encrypt_close(); | |
204 | } | |
205 | ||
8f60459a SJ |
206 | } else { |
207 | $reply = false; | |
436e5ff3 | 208 | } |
8f60459a | 209 | return $reply; |
436e5ff3 | 210 | } |
211 | ||
a7de4ef7 | 212 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 213 | ?> |