1 | <?php |
---|
2 | |
---|
3 | // Sécurité |
---|
4 | if (!defined('_ECRIRE_INC_VERSION')) return; |
---|
5 | |
---|
6 | function formulaires_editer_client_saisies_dist($id_auteur, $retour=''){ |
---|
7 | return array( |
---|
8 | array( |
---|
9 | 'saisie' => 'input', |
---|
10 | 'options' => array( |
---|
11 | 'nom' => 'prenom', |
---|
12 | 'label' => _T('contacts:label_prenom'), |
---|
13 | 'obligatoire' => 'oui' |
---|
14 | ) |
---|
15 | ), |
---|
16 | array( |
---|
17 | 'saisie' => 'input', |
---|
18 | 'options' => array( |
---|
19 | 'nom' => 'nom', |
---|
20 | 'label' => _T('contacts:label_nom'), |
---|
21 | 'obligatoire' => 'oui' |
---|
22 | ) |
---|
23 | ), |
---|
24 | array( |
---|
25 | 'saisie' => 'input', |
---|
26 | 'options' => array( |
---|
27 | 'nom' => 'email_rien', |
---|
28 | 'label' => _T('contacts:label_email'), |
---|
29 | 'disable' => 'oui', |
---|
30 | ), |
---|
31 | 'verifier' => array( |
---|
32 | 'type' => 'email' |
---|
33 | ) |
---|
34 | ), |
---|
35 | array( |
---|
36 | 'saisie' => 'input', |
---|
37 | 'options' => array( |
---|
38 | 'nom' => 'voie', |
---|
39 | 'label' => _T('coordonnees:label_voie'), |
---|
40 | 'obligatoire' => 'oui' |
---|
41 | ) |
---|
42 | ), |
---|
43 | array( |
---|
44 | 'saisie' => 'input', |
---|
45 | 'options' => array( |
---|
46 | 'nom' => 'complement', |
---|
47 | 'label' => _T('coordonnees:label_complement'), |
---|
48 | ) |
---|
49 | ), |
---|
50 | array( |
---|
51 | 'saisie' => 'input', |
---|
52 | 'options' => array( |
---|
53 | 'nom' => 'code_postal', |
---|
54 | 'label' => _T('coordonnees:label_code_postal'), |
---|
55 | 'obligatoire' => 'oui' |
---|
56 | ) |
---|
57 | ), |
---|
58 | array( |
---|
59 | 'saisie' => 'input', |
---|
60 | 'options' => array( |
---|
61 | 'nom' => 'ville', |
---|
62 | 'label' => _T('coordonnees:label_ville'), |
---|
63 | 'obligatoire' => 'oui' |
---|
64 | ) |
---|
65 | ), |
---|
66 | array( |
---|
67 | 'saisie' => 'pays', |
---|
68 | 'options' => array( |
---|
69 | 'nom' => 'pays', |
---|
70 | 'code_pays' => 'oui', |
---|
71 | 'label' => _T('coordonnees:label_pays'), |
---|
72 | 'obligatoire' => 'oui' |
---|
73 | ) |
---|
74 | ), |
---|
75 | ); |
---|
76 | } |
---|
77 | |
---|
78 | function formulaires_editer_client_charger_dist($id_auteur, $retour=''){ |
---|
79 | include_spip('inc/session'); |
---|
80 | $contexte = array(); |
---|
81 | |
---|
82 | // On vérifie qu'il y a un client correct (auteur+contact+adresse) quelque part |
---|
83 | if ( |
---|
84 | $id_auteur > 0 |
---|
85 | and $email = sql_getfetsel('email', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)) |
---|
86 | and $contact = sql_fetsel( |
---|
87 | '*', |
---|
88 | 'spip_contacts_liens LEFT JOIN spip_contacts USING(id_contact)', |
---|
89 | array( |
---|
90 | 'objet = '.sql_quote('auteur'), |
---|
91 | 'id_objet = '.intval($id_auteur) |
---|
92 | ) |
---|
93 | ) |
---|
94 | ){ |
---|
95 | $contexte['email_rien'] = $email; |
---|
96 | foreach ($contact as $cle=>$valeur) { |
---|
97 | $contexte[$cle] = $valeur; |
---|
98 | } |
---|
99 | |
---|
100 | // S'il y a une adresse principale, on charge les infos |
---|
101 | if ($adresse = sql_fetsel( |
---|
102 | '*', |
---|
103 | 'spip_adresses_liens LEFT JOIN spip_adresses USING(id_adresse)', |
---|
104 | array( |
---|
105 | 'objet = '.sql_quote('auteur'), |
---|
106 | 'id_objet = '.intval($id_auteur), |
---|
107 | 'type = '.sql_quote('principale') |
---|
108 | ) |
---|
109 | )) |
---|
110 | $contexte = array_merge($contexte, $adresse); |
---|
111 | } |
---|
112 | // Sinon rien |
---|
113 | else{ |
---|
114 | $contexte['editable'] = false; |
---|
115 | } |
---|
116 | |
---|
117 | return $contexte; |
---|
118 | } |
---|
119 | |
---|
120 | function formulaires_editer_client_verifier_dist($id_auteur, $retour=''){ |
---|
121 | $erreurs = array(); |
---|
122 | |
---|
123 | return $erreurs; |
---|
124 | } |
---|
125 | |
---|
126 | function formulaires_editer_client_traiter_dist($id_auteur, $retour=''){ |
---|
127 | // Si redirection demandée, on refuse le traitement en ajax |
---|
128 | if ($retour) refuser_traiter_formulaire_ajax(); |
---|
129 | |
---|
130 | $retours = array(); |
---|
131 | |
---|
132 | // On modifie le contact |
---|
133 | $id_contact = sql_getfetsel( |
---|
134 | 'id_contact', |
---|
135 | 'spip_contacts_liens', |
---|
136 | 'objet = '.sql_quote('auteur').' and id_objet = '.$id_auteur |
---|
137 | ); |
---|
138 | $editer_contact = charger_fonction('editer_contact', 'action/'); |
---|
139 | $editer_contact($id_contact); |
---|
140 | |
---|
141 | // Le pseudo SPIP est construit |
---|
142 | set_request('nom', _request('prenom').' '._request('nom')); |
---|
143 | |
---|
144 | // On modifie l'auteur |
---|
145 | $editer_auteur = charger_fonction('editer_auteur', 'action/'); |
---|
146 | $editer_auteur($id_auteur); |
---|
147 | |
---|
148 | // On modifie l'adresse |
---|
149 | $id_adresse = sql_getfetsel( |
---|
150 | 'id_adresse', |
---|
151 | 'spip_adresses_liens', |
---|
152 | array( |
---|
153 | 'objet = '.sql_quote('auteur'), |
---|
154 | 'id_objet = '.$id_auteur, |
---|
155 | 'type = '.sql_quote('principale') |
---|
156 | ) |
---|
157 | ); |
---|
158 | // S'il n'y a pas d'adresse principale, on la crée |
---|
159 | if (!$id_adresse){ |
---|
160 | $id_adresse = 'oui'; |
---|
161 | set_request('objet', 'auteur'); |
---|
162 | set_request('id_objet', $id_auteur); |
---|
163 | set_request('type', 'principale'); |
---|
164 | } |
---|
165 | |
---|
166 | $editer_adresse = charger_fonction('editer_adresse', 'action/'); |
---|
167 | $editer_adresse($id_adresse); |
---|
168 | |
---|
169 | // Quand on reste sur la même page, on peut toujours éditer après |
---|
170 | $retours['editable'] = true; |
---|
171 | |
---|
172 | // Si on demande une redirection |
---|
173 | if ($retour) $retours['redirect'] = $retour; |
---|
174 | |
---|
175 | return $retours; |
---|
176 | } |
---|
177 | |
---|
178 | ?> |
---|