| 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 | le premier parametre doit etre le matricule |
| 9 | le second parametre facultatif doit etre le numero de l'adresse voulue : |
| 10 | -1 => on ne veut pas d'adresse |
| 11 | 0 => on veut toutes les adresses |
| 12 | n => on veut l'adresse numero n |
| 13 | |
| 14 | IL NE FAUT PAS CHANGER LES NOMS DES CHAMPS DE ADRESSES |
| 15 | S'IL Y A DES MODIFS A FAIRE VOIR AVEC MANAGEURS admin@manageurs.com |
| 16 | */ |
| 17 | function get_annuaire_infos($method, $params) { |
| 18 | global $error_mat, $error_key, $globals; |
| 19 | |
| 20 | //verif du mdp |
| 21 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;} |
| 22 | //si on a adresse == -1 => on ne recupère aucune adresse |
| 23 | if(isset($params[2]) && ($params[2] == -1)) unset($params[2]); |
| 24 | |
| 25 | if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule |
| 26 | |
| 27 | //on ne recupere pas les adresses inutilement |
| 28 | if(!isset($params[2])){ |
| 29 | $res = XDB::iterRow( |
| 30 | "SELECT ph.display_tel AS cell, a.naissance AS age |
| 31 | FROM auth_user_md5 AS a |
| 32 | INNER JOIN auth_user_quick AS q USING (user_id) |
| 33 | LEFT JOIN profile_phones AS ph ON (ph.uid = a.user_id AND link_type='user' AND tel_type = 'mobile') |
| 34 | WHERE a.matricule = {?} LIMIT 1", $params[1]); |
| 35 | $array = $res->next(); |
| 36 | } |
| 37 | else{ |
| 38 | $res = XDB::iterRow( |
| 39 | "SELECT a.naissance AS age, |
| 40 | adr.adr1, adr.adr2, adr.adr3, |
| 41 | adr.postcode, adr.city, adr.country, |
| 42 | adr.uid, adr.adrid |
| 43 | FROM auth_user_md5 AS a |
| 44 | INNER JOIN auth_user_quick AS q USING (user_id) |
| 45 | LEFT JOIN adresses AS adr ON(adr.uid = a.user_id) |
| 46 | WHERE a.matricule = {?} AND |
| 47 | NOT FIND_IN_SET('pro', adr.statut) |
| 48 | ORDER BY NOT FIND_IN_SET('active', adr.statut), |
| 49 | FIND_IN_SET('res-secondaire', adr.statut), |
| 50 | NOT FIND_IN_SET('courrier', adr.statut)", $params[1]); |
| 51 | //traitement des adresses si necessaire |
| 52 | if(list($age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'], |
| 53 | $adr['pays'], $uid, $adr['adrid']) = $res->next()) |
| 54 | { |
| 55 | $sql = XDB::query("SELECT display_tel |
| 56 | FROM profile_phones |
| 57 | WHERE uid ={?} AND link_type = 'user' AND tel_type = 'mobile' |
| 58 | LIMIT 1", $uid); |
| 59 | if ($sql->numRows()>0) { |
| 60 | $array['cell'] = $sql->fetchOneCell(); |
| 61 | } else { |
| 62 | $array['cell'] =''; |
| 63 | } |
| 64 | $array['age'] = $age; |
| 65 | $array['adresse'][] = $adr; |
| 66 | |
| 67 | |
| 68 | //on clamp le numero au nombre d'adresses dispo |
| 69 | $adresse = min((int) $params[2], $res->total()); |
| 70 | |
| 71 | if ($adresse != 1) { //on ne veut pas la premiere adresse |
| 72 | $i = 2; |
| 73 | while(list($age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['cp'], $adr['ville'], |
| 74 | $adr['pays'], , $adr['adrid']) = $res->next()) |
| 75 | { |
| 76 | if($adresse == $i){//si on veut cette adresse en particulier |
| 77 | $array['adresse'][0] = $adr; |
| 78 | //$res->free(); |
| 79 | break; |
| 80 | } |
| 81 | elseif($adresse == 0){//si on veut toutes les adresses |
| 82 | $array['adresse'][] = $adr; |
| 83 | } |
| 84 | $i++; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // on rajoute les numéros de tél |
| 89 | $adrid_index = array(); |
| 90 | foreach ($array['adresse'] as $i => $a) $adrid_index[$a['adrid']] = $i; |
| 91 | // on rajoute les numéros de tels |
| 92 | $restel = XDB::iterator( |
| 93 | "SELECT t.display_tel AS tel, t.tel_type, t.link_id as adrid |
| 94 | FROM profile_phones AS t |
| 95 | INNER JOIN adresses AS a ON (t.link_id = a.adrid AND t.uid = a.uid) |
| 96 | WHERE t.uid = {?} AND t.link_type = 'address' AND NOT FIND_IN_SET('pro', a.statut)", $uid); |
| 97 | while ($tel = $restel->next()) $array['adresse'][$adrid_index[$tel['adrid']]]['tels'][] = $tel; |
| 98 | foreach ($array['adresse'] as $i => $adr) { |
| 99 | unset($lasttel); |
| 100 | foreach($adr['tels'] as $j => $t){ |
| 101 | if (!isset($array['adresse'][$i]['tel']) && (strpos($t['tel_type'], 'Tél') === 0)) $array['adresse'][$i]['tel'] = $t['tel']; |
| 102 | elseif (!isset($array['adresse'][$i]['fax']) && (strpos($t['tel_type'], 'Fax') === 0)) $array['adresse'][$i]['fax'] = $t['tel']; |
| 103 | else $lasttel = $t['tel']; |
| 104 | if (isset($array['adresse'][$i]['tel']) && isset($array['adresse'][$i]['fax'])) break; |
| 105 | } |
| 106 | if (!isset($array['adresse'][$i]['tel']) && isset($lasttel)) |
| 107 | $array['adresse'][$i]['tel'] = $lasttel; |
| 108 | elseif (!isset($array['adresse'][$i]['fax']) && isset($lasttel)) |
| 109 | $array['adresse'][$i]['fax'] = $lasttel; |
| 110 | unset($array['adresse'][$i]['adrid']); |
| 111 | unset($array['adresse'][$i]['tels']); |
| 112 | } |
| 113 | } |
| 114 | else{ |
| 115 | $array = false; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | if ($array) { // on a bien eu un résultat : le matricule etait bon |
| 120 | |
| 121 | //on n'envoit que l'age à manageurs le format est YYYY-MM-DD 0123-56-89 |
| 122 | $year = (int) substr($array['age'],0,4); |
| 123 | $month = (int) substr($array['age'],5,2); |
| 124 | $day = (int) substr($array['age'],8,2); |
| 125 | $age = (int) date('Y') - $year - 1; |
| 126 | if(( $month < (int)date('m')) || |
| 127 | (($month == (int)date('m')) && ($day >= (int)date('d')))) |
| 128 | { |
| 129 | $age += 1; |
| 130 | } |
| 131 | $array['age'] = $age; |
| 132 | |
| 133 | //on commence le cryptage des donnees |
| 134 | if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter |
| 135 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
| 136 | $reply = xmlrpc_encode_request(NULL,$args); |
| 137 | } else { |
| 138 | $reply = manageurs_encrypt_array($array); |
| 139 | manageurs_encrypt_close(); |
| 140 | } |
| 141 | } else {//le matricule n'etait pas valide |
| 142 | $args = array("erreur" => 2, "erreurstring" => $erreur_mat); |
| 143 | $reply = xmlrpc_encode_request(NULL,$args); |
| 144 | } |
| 145 | } else {//le matricule n'etait pas en argument |
| 146 | $args = array("erreur" => 1, "erreurstring" => $error_mat); |
| 147 | $reply = xmlrpc_encode_request(NULL,$args); |
| 148 | } |
| 149 | |
| 150 | return $reply; |
| 151 | } |
| 152 | |
| 153 | function get_nouveau_infos($method, $params) { |
| 154 | global $error_mat, $error_key, $globals; |
| 155 | //verif du mdp |
| 156 | if(!isset($params[0]) || ($params[0] != $globals->manageurs->manageurs_pass)){return false;} |
| 157 | if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule |
| 158 | |
| 159 | $res = XDB::query( |
| 160 | "SELECT a.nom, a.nom_usage,a.prenom, FIND_IN_SET('femme', a.flags) as femme ,a.deces!= 0 as decede , |
| 161 | a.naissance, a.promo, concat(al.alias, '@m4x.org') as mail |
| 162 | FROM auth_user_md5 AS a |
| 163 | INNER JOIN aliases as al ON a.user_id=al.id |
| 164 | WHERE al.flags='bestalias' and a.matricule = {?}",$params[1]); |
| 165 | $data=$res->fetchOneAssoc(); |
| 166 | //$data['mail'].='@polytechnique.org'; |
| 167 | |
| 168 | |
| 169 | //on commence le cryptage des donnees |
| 170 | if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter |
| 171 | $args = array("erreur" => 3, "erreurstring" => $error_key); |
| 172 | $reply = xmlrpc_encode_request(NULL,$args); |
| 173 | } else { |
| 174 | $reply = manageurs_encrypt_array($data); |
| 175 | manageurs_encrypt_close(); |
| 176 | } |
| 177 | |
| 178 | } |
| 179 | else{ |
| 180 | $reply=false; |
| 181 | } |
| 182 | return $reply; |
| 183 | |
| 184 | } |
| 185 | |
| 186 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 187 | ?> |