X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fwebservices%2Fmanageurs.server.inc.php;h=fa56a3ca5db870d9c9a414807b782d4ef856d87b;hb=a9cdd5fcff66066ec76c944411d44c492a566662;hp=cd91bede06cb798ced2d327dc89ae244d6571b58;hpb=0337d704b62718d7c77106c0e4c4e26fb02beacf;p=platal.git diff --git a/include/webservices/manageurs.server.inc.php b/include/webservices/manageurs.server.inc.php index cd91bed..fa56a3c 100644 --- a/include/webservices/manageurs.server.inc.php +++ b/include/webservices/manageurs.server.inc.php @@ -5,118 +5,210 @@ require_once('webservices/manageurs.inc.php'); $error_mat = "You didn't provide me with a valid matricule number..."; $error_key = "You didn't provide me with a valid cipher key..."; -/** - le premier parametre doit etre le matricule - le second parametre facultatif doit etre le numero de l'adresse voulue : - -1 => on ne veut pas d'adresse - 0 => on veut toutes les adresses - n => on veut l'adresse numero n -*/ +// The first parameter has to be the identification number (matricule). +// The second parameter facultative has to be the number of the desired address: +// -1 => we do not want any address; +// 0 => we want all the addresses; +// n => we want the address number n. +// +// DO NOT CHANGE THE NAMES OF THE ADDRESSES' FIELDS. +// IF YOU HAVE TO MAKE SOME MODIFICATION, FIRST CONTACT: +// admin@manageurs.com function get_annuaire_infos($method, $params) { global $error_mat, $error_key, $globals; - //verif du mdp - if(!isset($params[0]) || ($params[0] != $globals->manageurs->pass)){return false;} - - //si on a adresse == -1 => on ne recupère aucune adresse - if(isset($params[2]) && ($params[2] == -1)) unset($params[2]); - - - if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule - - //on ne recupere pas les adresses inutilement - if(!isset($params[2])){ - $res = $globals->xdb->iterRow( - "SELECT q.profile_mobile AS cell, a.naissance AS age - FROM auth_user_md5 AS a - INNER JOIN auth_user_quick AS q USING (user_id) - WHERE a.matricule = {?}", $params[1]); - } - else{ - $res = $globals->xdb->iterRow( - "SELECT q.profile_mobile AS cell, a.naissance AS age, - adr.adr1, adr.adr2, adr.adr3, - adr.postcode, adr.city, adr.country, - adr.tel, adr.fax - FROM auth_user_md5 AS a - INNER JOIN auth_user_quick AS q USING (user_id) - LEFT JOIN adresses AS adr ON(adr.uid = a.user_id) - WHERE a.matricule = {?} AND - NOT FIND_IN_SET('pro', adr.statut) - ORDER BY NOT FIND_IN_SET('active', adr.statut), - FIND_IN_SET('res-secondaire', adr.statut), - NOT FIND_IN_SET('courrier', adr.statut)", $params[1]); - - } - - //traitement des adresss si necessaire - if (isset($params[2])) { - if(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], - $adr['country'], $adr['tel'], $adr['fax']) = $res->next()) - { - $array['cell'] = $cell; + // Password verification. + if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) { + return false; + } + // If address == -1, we do not retrieve any address. + if(isset($params[2]) && ($params[2] == -1)) { + unset($params[2]); + } + + // We check we actually have an identification number. + if(!empty($params[1])) { + // We only retrieve addresses when required. + if(!isset($params[2])) { + $res = XDB::iterRow("SELECT pp.display_tel AS cell, p.birthdate AS age + FROM profiles AS p + LEFT JOIN profile_phones AS pp ON (pp.pid = p.pid AND pp.link_type = 'user' + AND pp.tel_type = 'mobile') + WHERE p.xorg_id = {?} LIMIT 1", + $params[1]); + $array = $res->next(); + } else { + $res = XDB::iterRow("SELECT p.birthdate, pa.text, pa.postalCode + gl.name, pa.countryId, p.pid, pa.id + FROM profiles AS p + LEFT JOIN profile_addresses AS pa ON (pa.pid = p.pid) + LEFT JOIN geoloc_localities AS gl ON (pl.id = pa.localityId) + WHERE p.xorg_id = {?} AND NOT FIND_IN_SET('job', pa.flags) + ORDER BY NOT FIND_IN_SET('current', pa.flags), + FIND_IN_SET('secondary', pa.flags), + NOT FIND_IN_SET('mail', pa.flags)", + $params[1]); + // Process the addresses we got. + if(list($age, $text, $adr['cp'], $adr['ville'], + $adr['pays'], $pid, $adr['adrid']) = $res->next()) { + list($adr['adr1'], $adr['adr2'], $adr['adr3']) = + explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); + $sql = XDB::query("SELECT display_tel + FROM profile_phones + WHERE pid = {?} AND link_type = 'user' AND tel_type = 'mobile' + LIMIT 1", $pid); + if ($sql->numRows() > 0) { + $array['cell'] = $sql->fetchOneCell(); + } else { + $array['cell'] =''; + } $array['age'] = $age; $array['adresse'][] = $adr; - //on clamp le numero au nombre d'adresses dispo + + // We limit the address number by the number of available addresses. $adresse = min((int) $params[2], $res->total()); - if ($adresse != 1) { //on ne veut pas la premiere adresse + if ($adresse != 1) { // We don't want the first address. $i = 2; - while(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'], - $adr['country'], $adr['tel'], $adr['fax']) = $res->next()) - { - if($adresse == $i){//si on veut cette adresse en particulier + while(list($age, $text, $adr['cp'], $adr['ville'], + $adr['pays'], , $adr['adrid']) = $res->next()) { + list($adr['adr1'], $adr['adr2'], $adr['adr3']) = + explode("\n", Geocoder::getFirstLines($text, $adr['cp'], 3)); + if ($adresse == $i) { + // If we want this particular address. $array['adresse'][0] = $adr; //$res->free(); break; - } - elseif($adresse == 0){//si on veut toutes les adresses + } elseif ($adresse == 0) { + // If we want every address. $array['adresse'][] = $adr; } $i++; } } - } - else{ + + // We add the phone numbers. + $adrid_index = array(); + foreach ($array['adresse'] as $i => $a) { + $adrid_index[$a['adrid']] = $i; + } + $restel = XDB::iterator("SELECT pp.display_tel AS tel, pp..tel_type, pp.link_id as adrid + FROM profile_phones AS pp + INNER JOIN profile_addresses AS pa ON (pp.link_id = pa.id AND pp.pid = pa.pid) + WHERE pp.pid = {?} AND pp.link_type = 'address' + AND NOT FIND_IN_SET('pro', pa.statut)", + $pid); + while ($tel = $restel->next()) { + $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel; + } + foreach ($array['adresse'] as $i => $adr) { + unset($lasttel); + foreach ($adr['tels'] as $j => $t) { + if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) { + $array['adresse'][$i]['tel'] = $t['tel']; + } elseif (!isset($array['adresse'][$i]['fax']) + && (strpos($t['tel_type'], 'Fax') === 0)) { + $array['adresse'][$i]['fax'] = $t['tel']; + } else { + $lasttel = $t['tel']; + } + if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) { + break; + } + } + if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) { + $array['adresse'][$i]['tel'] = $lasttel; + } elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) { + $array['adresse'][$i]['fax'] = $lasttel; + } + unset($array['adresse'][$i]['adrid']); + unset($array['adresse'][$i]['tels']); + } + } else { $array = false; } } - else { //cas où on ne veut pas d'adresse - $array = $res->next(); - } - if ($array) { // on a bien eu un résultat : le matricule etait bon + if ($array) { // We did get a result: the identification number was rigth. - //on n'envoit que l'age à manageurs le format est YYYY-MM-DD 0123-56-89 - $year = (int) substr($array['age'],0,4); - $month = (int) substr($array['age'],5,2); - $day = (int) substr($array['age'],8,2); + // We only send the age to manageurs.com; the format is YYYY-MM-DD 0123-56-89. + $year = (int) substr($array['age'], 0, 4); + $month = (int) substr($array['age'], 5, 2); + $day = (int) substr($array['age'], 8, 2); $age = (int) date('Y') - $year - 1; if(( $month < (int)date('m')) || - (($month == (int)date('m')) && ($day >= (int)date('d')))) - { + (($month == (int)date('m')) && ($day >= (int)date('d')))) { $age += 1; } $array['age'] = $age; - //on commence le cryptage des donnees - if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter + // We start the encryption of the data. + if (manageurs_encrypt_init($params[1]) == 1) { + // We did not find the key to encryptthe data. $args = array("erreur" => 3, "erreurstring" => $error_key); $reply = xmlrpc_encode_request(NULL,$args); } else { $reply = manageurs_encrypt_array($array); manageurs_encrypt_close(); } - } else {//le matricule n'etait pas valide + } else { + // The identification number was not valid. $args = array("erreur" => 2, "erreurstring" => $erreur_mat); $reply = xmlrpc_encode_request(NULL,$args); } - } else {//le matricule n'etait pas en argument + } else { + // The identification number was not in argument. $args = array("erreur" => 1, "erreurstring" => $error_mat); - $reply = xmlrpc_encode_request(NULL,$args); - } - return $reply; -} + $reply = xmlrpc_encode_request(NULL, $args); + } + + return $reply; +} + +function get_nouveau_infos($method, $params) { + global $error_mat, $error_key, $globals; + // Password verification. + if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)) { + return false; + } + // We check we actually have an identification number. + if(!empty($params[1])) { + $nameTypes = DirEnum::getOptions(DirEnum::NAMETYPES); + $nameTypes = array_flip($nameTypes); + + $res = XDB::query("SELECT pnl.name AS nom, pnu.name AS nom_usage, pnf.name AS prenom, + p.sex = 'female' AS femme, p.deathdate IS NOT NULL AS decede, + p.birthdate, pd.promo, CONCAT(e.email, '@', d.name) AS mail + FROM profiles AS p + INNER JOIN account_profiles AS ap ON (p.pid = ap.pid AND FIND_IN_SET('owner', perms) + INNER JOIN email_source_account AS s ON (s.uid = ap.uid AND FIND_IN_SET('bestalias', s.flags)) + INNER JOIN email_virtual_domains AS d ON (s.domain = s.id) + INNER JOIN profile_display AS pd PN (p.pid = pd.pid) + INNER JOIN profile_name AS pnl ON (p.pid = pnl.pid AND pnl.typeid = {?}) + INNER JOIN profile_name AS pnf ON (p.pid = pnf.pid AND pnf.typeid = {?}) + INNER JOIN profile_name AS pnu ON (p.pid = pnu.pid AND pnu.typeid = {?}) + WHERE a.flags = 'bestalias' AND p.xorg_id = {?}", + $nameTypes['name_ini'], $nameTypes['lastname_ordinary'], + $nameTypes['firstname_ini'], $params[1]); + // $data['mail'] .= '@polytechnique.org'; + + + // We start the encryption of the data. + if (manageurs_encrypt_init($params[1]) == 1) { + // We did not find the key to encryptthe data. + $args = array("erreur" => 3, "erreurstring" => $error_key); + $reply = xmlrpc_encode_request(NULL, $args); + } else { + $reply = manageurs_encrypt_array($data); + manageurs_encrypt_close(); + } + + } else { + $reply = false; + } + return $reply; +} +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>