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 global $error_mat, $error_key, $globals;
20 // Password verification.
21 if(!isset($params[0]) ||
($params[0] != $globals->manageurs
->manageurs_pass
)) {
24 // If address == -1, we do not retrieve any address.
25 if(isset($params[2]) && ($params[2] == -1)) {
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])) {
33 $res = XDB
::iterRow("SELECT pp.display_tel AS cell, p.birthdate AS age
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",
39 $array = $res->next();
41 $res = XDB
::iterRow("SELECT p.birthdate, pa.text, pace3.short_name, pace2.short_name, pace1.short_name, p.pid, pa.id
43 LEFT JOIN profile_addresses AS pa ON (pa.pid = p.pid)
44 LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET('country', pace1.types))
45 LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET('locality', pace2.types))
46 LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET('postal_code', pace3.types))
47 LEFT JOIN profile_addresses_components AS pac1 ON (pa.pid = pac1.pid AND pa.jobid = pac1.jobid AND pa.groupid = pac1.groupid
48 AND pa.id = pac1.id AND pa.type = pac1.type AND pace1.id = pac1.component_id)
49 LEFT JOIN profile_addresses_components AS pac2 ON (pa.pid = pac2.pid AND pa.jobid = pac2.jobid AND pa.groupid = pac2.groupid
50 AND pa.id = pac2.id AND pa.type = pac2.type AND pace2.id = pac2.component_id)
51 LEFT JOIN profile_addresses_components AS pac3 ON (pa.pid = pac3.pid AND pa.jobid = pac3.jobid AND pa.groupid = pac3.groupid
52 AND pa.id = pac3.id AND pa.type = pac3.type AND pace3.id = pac3.component_id)
53 WHERE p.xorg_id = {?} AND NOT FIND_IN_SET('job', pa.flags)
54 ORDER BY NOT FIND_IN_SET('current', pa.flags),
55 FIND_IN_SET('secondary', pa.flags),
56 NOT FIND_IN_SET('mail', pa.flags)
57 GROUP BY pa.pid, pa.jobid, pa.groupid, pa.id, pa.type",
59 // Process the addresses we got.
60 if(list($age, $text, $adr['cp'], $adr['ville'],
61 $adr['pays'], $pid, $adr['adrid']) = $res->next()) {
62 list($adr['adr1'], $adr['adr2'], $adr['adr3']) =
63 explode("\n", Geocoder
::getFirstLines($text, $adr['cp'], 3));
64 $sql = XDB
::query("SELECT display_tel
66 WHERE pid = {?} AND link_type = 'user' AND tel_type = 'mobile'
68 if ($sql->numRows() > 0) {
69 $array['cell'] = $sql->fetchOneCell();
74 $array['adresse'][] = $adr;
77 // We limit the address number by the number of available addresses.
78 $adresse = min((int) $params[2], $res->total());
80 if ($adresse != 1) { // We don't want the first address.
82 while(list($age, $text, $adr['cp'], $adr['ville'],
83 $adr['pays'], , $adr['adrid']) = $res->next()) {
84 list($adr['adr1'], $adr['adr2'], $adr['adr3']) =
85 explode("\n", Geocoder
::getFirstLines($text, $adr['cp'], 3));
87 // If we want this particular address.
88 $array['adresse'][0] = $adr;
91 } elseif ($adresse == 0) {
92 // If we want every address.
93 $array['adresse'][] = $adr;
99 // We add the phone numbers.
100 $adrid_index = array();
101 foreach ($array['adresse'] as $i => $a) {
102 $adrid_index[$a['adrid']] = $i;
104 $restel = XDB
::iterator("SELECT pp.display_tel AS tel, pp..tel_type, pp.link_id as adrid
105 FROM profile_phones AS pp
106 INNER JOIN profile_addresses AS pa ON (pp.link_id = pa.id AND pp.pid = pa.pid)
107 WHERE pp.pid = {?} AND pp.link_type = 'address'
108 AND NOT FIND_IN_SET('pro', pa.statut)",
110 while ($tel = $restel->next()) {
111 $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel;
113 foreach ($array['adresse'] as $i => $adr) {
115 foreach ($adr['tels'] as $j => $t) {
116 if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) {
117 $array['adresse'][$i]['tel'] = $t['tel'];
118 } elseif (!isset($array['adresse'][$i]['fax'])
119 && (strpos($t['tel_type'], 'Fax') === 0)) {
120 $array['adresse'][$i]['fax'] = $t['tel'];
122 $lasttel = $t['tel'];
124 if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) {
128 if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) {
129 $array['adresse'][$i]['tel'] = $lasttel;
130 } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) {
131 $array['adresse'][$i]['fax'] = $lasttel;
133 unset($array['adresse'][$i]['adrid']);
134 unset($array['adresse'][$i]['tels']);
141 if ($array) { // We did get a result: the identification number was rigth.
143 // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89.
144 $year = (int) substr($array['age'], 0, 4);
145 $month = (int) substr($array['age'], 5, 2);
146 $day = (int) substr($array['age'], 8, 2);
147 $age = (int) date('Y') - $year - 1;
148 if(( $month < (int)date('m')) ||
149 (($month == (int)date('m')) && ($day >= (int)date('d')))) {
152 $array['age'] = $age;
154 // We start the encryption of the data.
155 if (manageurs_encrypt_init($params[1]) == 1) {
156 // We did not find the key to encryptthe data.
157 $args = array("erreur" => 3, "erreurstring" => $error_key);
158 $reply = xmlrpc_encode_request(NULL
,$args);
160 $reply = manageurs_encrypt_array($array);
161 manageurs_encrypt_close();
164 // The identification number was not valid.
165 $args = array("erreur" => 2, "erreurstring" => $erreur_mat);
166 $reply = xmlrpc_encode_request(NULL
,$args);
169 // The identification number was not in argument.
170 $args = array("erreur" => 1, "erreurstring" => $error_mat);
171 $reply = xmlrpc_encode_request(NULL
, $args);
177 function get_nouveau_infos($method, $params) {
178 global $error_mat, $error_key, $globals;
179 // Password verification.
180 if(!isset($params[0]) ||
($params[0] != $globals->manageurs
->manageurs_pass
)) {
183 // We check we actually have an identification number.
184 if(!empty($params[1])) {
185 $nameTypes = DirEnum
::getOptions(DirEnum
::NAMETYPES
);
186 $nameTypes = array_flip($nameTypes);
188 $res = XDB
::query("SELECT pnl.name AS nom, pnu.name AS nom_usage, pnf.name AS prenom,
189 p.sex = 'female' AS femme, p.deathdate IS NOT NULL AS decede,
190 p.birthdate, pd.promo, CONCAT(e.email, '@', d.name) AS mail
192 INNER JOIN account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms)
193 INNER JOIN email_source_account AS s ON (s.uid = ap.uid AND FIND_IN_SET('bestalias', s.flags))
194 INNER JOIN email_virtual_domains AS d ON (s.domain = s.id)
195 INNER JOIN profile_display AS pd PN (p.pid = pd.pid)
196 INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?})
197 INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?})
198 INNER JOIN profile_name AS pnu ON (p.pid = pnu.pid AND pnu.typeid = {?})
199 WHERE a.flags = 'bestalias' AND p.xorg_id = {?}",
200 $nameTypes['name_ini'], $nameTypes['lastname_ordinary'],
201 $nameTypes['firstname_ini'], $params[1]);
202 // $data['mail'] .= '@polytechnique.org';
205 // We start the encryption of the data.
206 if (manageurs_encrypt_init($params[1]) == 1) {
207 // We did not find the key to encryptthe data.
208 $args = array("erreur" => 3, "erreurstring" => $error_key);
209 $reply = xmlrpc_encode_request(NULL
, $args);
211 $reply = manageurs_encrypt_array($data);
212 manageurs_encrypt_close();
221 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: