first reimport from platal
[platal.git] / include / webservices / manageurs.server.inc.php
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 /**
9 le premier parametre doit etre le matricule
10 le second parametre facultatif doit etre le numero de l'adresse voulue :
11 -1 => on ne veut pas d'adresse
12 0 => on veut toutes les adresses
13 n => on veut l'adresse numero n
14 */
15 function get_annuaire_infos($method, $params) {
16 global $error_mat, $error_key, $globals;
17
18 //verif du mdp
19 if(!isset($params[0]) || ($params[0] != $globals->manageurs->pass)){return false;}
20
21 //si on a adresse == -1 => on ne recupère aucune adresse
22 if(isset($params[2]) && ($params[2] == -1)) unset($params[2]);
23
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 = $globals->xdb->iterRow(
30 "SELECT q.profile_mobile 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 WHERE a.matricule = {?}", $params[1]);
34 }
35 else{
36 $res = $globals->xdb->iterRow(
37 "SELECT q.profile_mobile AS cell, a.naissance AS age,
38 adr.adr1, adr.adr2, adr.adr3,
39 adr.postcode, adr.city, adr.country,
40 adr.tel, adr.fax
41 FROM auth_user_md5 AS a
42 INNER JOIN auth_user_quick AS q USING (user_id)
43 LEFT JOIN adresses AS adr ON(adr.uid = a.user_id)
44 WHERE a.matricule = {?} AND
45 NOT FIND_IN_SET('pro', adr.statut)
46 ORDER BY NOT FIND_IN_SET('active', adr.statut),
47 FIND_IN_SET('res-secondaire', adr.statut),
48 NOT FIND_IN_SET('courrier', adr.statut)", $params[1]);
49
50 }
51
52 //traitement des adresss si necessaire
53 if (isset($params[2])) {
54 if(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'],
55 $adr['country'], $adr['tel'], $adr['fax']) = $res->next())
56 {
57 $array['cell'] = $cell;
58 $array['age'] = $age;
59 $array['adresse'][] = $adr;
60
61 //on clamp le numero au nombre d'adresses dispo
62 $adresse = min((int) $params[2], $res->total());
63
64 if ($adresse != 1) { //on ne veut pas la premiere adresse
65 $i = 2;
66 while(list($cell, $age, $adr['adr1'], $adr['adr2'], $adr['adr3'], $adr['postcode'], $adr['city'],
67 $adr['country'], $adr['tel'], $adr['fax']) = $res->next())
68 {
69 if($adresse == $i){//si on veut cette adresse en particulier
70 $array['adresse'][0] = $adr;
71 //$res->free();
72 break;
73 }
74 elseif($adresse == 0){//si on veut toutes les adresses
75 $array['adresse'][] = $adr;
76 }
77 $i++;
78 }
79 }
80 }
81 else{
82 $array = false;
83 }
84 }
85 else { //cas où on ne veut pas d'adresse
86 $array = $res->next();
87 }
88
89 if ($array) { // on a bien eu un résultat : le matricule etait bon
90
91 //on n'envoit que l'age à manageurs le format est YYYY-MM-DD 0123-56-89
92 $year = (int) substr($array['age'],0,4);
93 $month = (int) substr($array['age'],5,2);
94 $day = (int) substr($array['age'],8,2);
95 $age = (int) date('Y') - $year - 1;
96 if(( $month < (int)date('m')) ||
97 (($month == (int)date('m')) && ($day >= (int)date('d'))))
98 {
99 $age += 1;
100 }
101 $array['age'] = $age;
102
103 //on commence le cryptage des donnees
104 if (manageurs_encrypt_init($params[1]) == 1) {//on a pas trouve la cle pour crypter
105 $args = array("erreur" => 3, "erreurstring" => $error_key);
106 $reply = xmlrpc_encode_request(NULL,$args);
107 } else {
108 $reply = manageurs_encrypt_array($array);
109 manageurs_encrypt_close();
110 }
111 } else {//le matricule n'etait pas valide
112 $args = array("erreur" => 2, "erreurstring" => $erreur_mat);
113 $reply = xmlrpc_encode_request(NULL,$args);
114 }
115 } else {//le matricule n'etait pas en argument
116 $args = array("erreur" => 1, "erreurstring" => $error_mat);
117 $reply = xmlrpc_encode_request(NULL,$args);
118 }
119 return $reply;
120 }
121
122 ?>