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