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