1 | <?php |
---|
2 | /* |
---|
3 | * forms |
---|
4 | * Gestion de formulaires editables dynamiques |
---|
5 | * |
---|
6 | * Auteurs : |
---|
7 | * Antoine Pitrou |
---|
8 | * Renato |
---|
9 | * 2005,2006 - Distribue sous licence GNU/GPL |
---|
10 | * |
---|
11 | */ |
---|
12 | // compatibilite trans 1.9.1-1.9.2 |
---|
13 | // Cadre formulaires |
---|
14 | // http://doc.spip.org/@debut_cadre_formulaire |
---|
15 | function Forms_debut_cadre_formulaire($style='', $return=false){ |
---|
16 | $x = "\n<div class='cadre-formulaire'" . |
---|
17 | (!$style ? "" : " style='$style'") . |
---|
18 | ">"; |
---|
19 | if ($return) return $x; else echo $x; |
---|
20 | } |
---|
21 | |
---|
22 | // http://doc.spip.org/@fin_cadre_formulaire |
---|
23 | function Forms_fin_cadre_formulaire($return=false){ |
---|
24 | if ($return) return "</div>\n"; else echo "</div>\n"; |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | function Forms_nouveau_champ($id_form,$type){ |
---|
29 | $res = spip_query("SELECT champ FROM spip_forms_champs WHERE id_form="._q($id_form)." AND type="._q($type)); |
---|
30 | $n = 1; |
---|
31 | $champ = $type.'_'.strval($n); |
---|
32 | while ($row = spip_fetch_array($res)){ |
---|
33 | $lenumero = split('_', $row['champ'] ); |
---|
34 | $lenumero = intval(end($lenumero)); |
---|
35 | if ($lenumero>= $n) $n=$lenumero+1; |
---|
36 | } |
---|
37 | $champ = $type.'_'.strval($n); |
---|
38 | return $champ; |
---|
39 | } |
---|
40 | function Forms_insere_nouveau_champ($id_form,$type,$titre,$champ=""){ |
---|
41 | if (!strlen($champ)) |
---|
42 | $champ = Forms_nouveau_champ($id_form,$type); |
---|
43 | $rang = 0; |
---|
44 | $res = spip_query("SELECT max(rang) AS rangmax FROM spip_forms_champs WHERE id_form="._q($id_form)); |
---|
45 | if ($row = spip_fetch_array($res)) |
---|
46 | $rang = $row['rangmax']; |
---|
47 | $rang++; |
---|
48 | include_spip('base/abstract_sql'); |
---|
49 | spip_abstract_insert( |
---|
50 | 'spip_forms_champs', |
---|
51 | '(id_form,champ,rang,titre,type,obligatoire,extra_info)', |
---|
52 | '('._q($id_form).','._q($champ).','._q($rang).','._q($titre).','._q($type).",'non','')"); |
---|
53 | return $champ; |
---|
54 | } |
---|
55 | function Forms_nouveau_choix($id_form,$champ){ |
---|
56 | $n = 1; |
---|
57 | $res = spip_query("SELECT choix FROM spip_forms_champs_choix WHERE id_form="._q($id_form)." AND champ="._q($champ)); |
---|
58 | while ($row = spip_fetch_array($res)){ |
---|
59 | $lenumero = split('_', $row['choix']); |
---|
60 | $lenumero = intval(end($lenumero)); |
---|
61 | if ($lenumero>= $n) $n=$lenumero+1; |
---|
62 | } |
---|
63 | $choix = $champ.'_'.$n; |
---|
64 | return $choix; |
---|
65 | } |
---|
66 | function Forms_insere_nouveau_choix($id_form,$champ,$titre){ |
---|
67 | $choix = Forms_nouveau_choix($id_form,$champ); |
---|
68 | $rang = 0; |
---|
69 | $res = spip_query("SELECT max(rang) AS rangmax FROM spip_forms_champs_choix WHERE id_form="._q($id_form)." AND champ="._q($champ)); |
---|
70 | if ($row = spip_fetch_array($res)) |
---|
71 | $rang = $row['rangmax']; |
---|
72 | $rang++; |
---|
73 | include_spip('base/abstract_sql'); |
---|
74 | spip_abstract_insert("spip_forms_champs_choix","(id_form,champ,choix,titre,rang)","("._q($id_form).","._q($champ).","._q($choix).","._q($titre).","._q($rang).")"); |
---|
75 | return $choix; |
---|
76 | } |
---|
77 | |
---|
78 | function Forms_bloc_routage_mail($id_form,$email){ |
---|
79 | $out = ""; |
---|
80 | // Routage facultatif des emails en fonction d'un champ select |
---|
81 | $defaut = true; |
---|
82 | $s = ""; |
---|
83 | $options = ""; |
---|
84 | $res2 = spip_query("SELECT * FROM spip_forms_champs WHERE type='select' AND id_form="._q($id_form)." ORDER BY rang"); |
---|
85 | while ($row2 = spip_fetch_array($res2)) { |
---|
86 | $display = 'none'; |
---|
87 | $code = $row2['champ']; |
---|
88 | $options .= "<option value='$code'"; |
---|
89 | if ($email['route'] == $code){ |
---|
90 | $options .= " selected='selected'";$display='block';$defaut=false; |
---|
91 | } |
---|
92 | $options .= ">" . $row2['titre'] . "</option>\n"; |
---|
93 | $s .= "<div id='block_email_route_$code' class='block_email_route' style='display:$display'>"; |
---|
94 | |
---|
95 | $s .= "<table id ='email_route_$code'>\n"; |
---|
96 | $s .= "<tr><th>".$row2['titre']."</th><th>"; |
---|
97 | $s .= "<strong><label for='email_route_$code'>"._T('email_2')."</label></strong>"; |
---|
98 | $s .= "</th></tr>\n"; |
---|
99 | |
---|
100 | $res3 = spip_query("SELECT * FROM spip_forms_champs_choix WHERE id_form="._q($id_form)." AND champ="._q($row2['champ'])." ORDER BY rang"); |
---|
101 | while($row3 = spip_fetch_array($res3)){ |
---|
102 | $s .= "<tr><td>".$row3['titre']."</td><td>"; |
---|
103 | $s .= "<input type='text' name='email[".$row3['choix']."]' value=\""; |
---|
104 | $s .= isset($email[$row3['choix']])?entites_html($email[$row3['choix']]):""; |
---|
105 | $s .= "\" class='fondl verdana2' size='20' />"; |
---|
106 | $s .= "</td></tr>"; |
---|
107 | } |
---|
108 | $s .="</table>"; |
---|
109 | $s .= "</div>"; |
---|
110 | } |
---|
111 | if (strlen($s)){ |
---|
112 | $out .= "<strong><label for='email_route_form'>"._T('forms:choisir_email')."</label></strong> "; |
---|
113 | $out .= "<br />"; |
---|
114 | $out .= "<select name='email[route]' id='email_route_form' class='forml'"; |
---|
115 | $out .= "onchange=\"$('.block_email_route').hide();$('#block_email_route_'+options[selectedIndex].value).show();\" "; |
---|
116 | $out .= ">\n"; |
---|
117 | $out .= "<option value=''>"._T('forms:email_independant')."</option>\n"; |
---|
118 | $out .= $options; |
---|
119 | $out .= "</select><br />\n"; |
---|
120 | } |
---|
121 | $display = $defaut?'block':'none'; |
---|
122 | $out .= "<div id='block_email_route_' class='block_email_route' style='display:$display'>"; |
---|
123 | $out .= "<strong><label for='email_form'>"._T('email_2')."</label></strong> "; |
---|
124 | $out .= "<br />"; |
---|
125 | $out .= "<input type='text' name=\"email[defaut]\" id='email_form' class='forml' ". |
---|
126 | "value=\"".entites_html($email['defaut'])."\" size='40' />\n"; |
---|
127 | $out .= "</div>"; |
---|
128 | $out .= $s; |
---|
129 | $out .= "<br/>"; |
---|
130 | return $out; |
---|
131 | } |
---|
132 | |
---|
133 | function Forms_bloc_edition_champ($row, $action_link, $redirect, $idbloc) { |
---|
134 | global $couleur_claire; |
---|
135 | |
---|
136 | $id_form = $row['id_form']; |
---|
137 | $champ = $row['champ']; |
---|
138 | $type = $row['type']; |
---|
139 | $titre = $row['titre']; |
---|
140 | $obligatoire = $row['obligatoire']; |
---|
141 | $extra_info = $row['extra_info']; |
---|
142 | $specifiant = $row['specifiant']; |
---|
143 | $listable_admin = $row['listable_admin']; |
---|
144 | $listable = $row['listable']; |
---|
145 | $public = $row['public']; |
---|
146 | $saisie = $row['saisie']; |
---|
147 | $aide = $row['aide']; |
---|
148 | $html_wrap = $row['html_wrap']; |
---|
149 | |
---|
150 | $out = ""; |
---|
151 | |
---|
152 | if ($type != 'separateur'){ |
---|
153 | $checked = ($obligatoire == 'oui') ? " checked='checked'" : ""; |
---|
154 | $out .= " <input type='checkbox' name='champ_obligatoire' value='oui' id='obli_$champ'$checked> "; |
---|
155 | $out .= "<label for='obli_$champ'>"._T("forms:edit_champ_obligatoire")."</label>"; |
---|
156 | $out .= "<br />\n"; |
---|
157 | |
---|
158 | $checked = ($specifiant == 'oui') ? " checked='checked'" : ""; |
---|
159 | $out .= " <input type='checkbox' name='champ_specifiant' value='oui' id='spec_$champ'$checked> "; |
---|
160 | $out .= "<label for='spec_$champ'>"._T("forms:champ_specifiant")."</label>"; |
---|
161 | $out .= "<br />\n"; |
---|
162 | |
---|
163 | $checked = ($listable_admin == 'oui') ? " checked='checked'" : ""; |
---|
164 | $out .= " <input type='checkbox' name='champ_listable_admin' value='oui' id='listadm_$champ'$checked> "; |
---|
165 | $out .= "<label for='listadm_$champ'>"._T("forms:champ_listable_admin")."</label>"; |
---|
166 | $out .= "<br />\n"; |
---|
167 | |
---|
168 | $checked = ($listable == 'oui') ? " checked='checked'" : ""; |
---|
169 | $out .= " <input type='checkbox' name='champ_listable' value='oui' id='list_$champ'$checked> "; |
---|
170 | $out .= "<label for='list_$champ'>"._T("forms:champ_listable_publique")."</label>"; |
---|
171 | $out .= "<br />\n"; |
---|
172 | |
---|
173 | $checked = ($saisie == 'non') ? " checked='checked'" : ""; |
---|
174 | $out .= " <input type='checkbox' name='champ_saisie' value='non' id='saisie_$champ'$checked> "; |
---|
175 | $out .= "<label for='saisie_$champ'>"._T("forms:champ_saisie_desactivee")."</label>"; |
---|
176 | $out .= "<br />\n"; |
---|
177 | |
---|
178 | $checked = ($public == 'oui') ? " checked='checked'" : ""; |
---|
179 | $out .= " <input type='checkbox' name='champ_public' value='oui' id='public_$champ'$checked> "; |
---|
180 | $out .= "<label for='public_$champ'>"._T("forms:champ_public")."</label>"; |
---|
181 | $out .= "<br />\n"; |
---|
182 | } |
---|
183 | if ($type == 'separateur' || $type=='textestatique'){ |
---|
184 | $out = "<input type='hidden' name='champ_public' value='oui' />"; |
---|
185 | } |
---|
186 | |
---|
187 | if ($type == 'texte') { |
---|
188 | $checked = ($extra_info == 'oui') ? " checked='checked'" : ""; |
---|
189 | $out .= " <input type='checkbox' name='champ_barre_typo' value='oui' id='barre_typo_$champ'$checked> "; |
---|
190 | $out .= "<label for='barre_typo_$champ'>"._T("forms:activer_barre_typo")."</label>"; |
---|
191 | $out .= "<br />\n"; |
---|
192 | } |
---|
193 | if ($type == 'monnaie') { |
---|
194 | $unite = $row['extra_info']; |
---|
195 | $out .= "<label for='unite_monetaire_$champ'>"._T("forms:unite_monetaire")."</label> :"; |
---|
196 | $out .= " <select name='unite_monetaire' id='unite_monetaire_$champ' class='fondo verdana2'>\n"; |
---|
197 | $out .= "<option value='euro'".($unite=='euro'?"selected='selected'":"").">"._T("forms:monnaie_euro")."</option>\n"; |
---|
198 | $out .= "</select>"; |
---|
199 | $out .= "<br />\n"; |
---|
200 | } |
---|
201 | if (($type == 'num')||($type == 'monnaie')) { |
---|
202 | $deci = $row['taille']; |
---|
203 | if (!$deci) $deci = 0; |
---|
204 | $out .= "<label for='decimales_$champ'>"._T("forms:nb_decimales")."</label> : "; |
---|
205 | $out .= "<input type='text' name='taille_champ' value='$deci' id='decimales_$champ' class='fondo verdana2'>\n"; |
---|
206 | $out .= "<br />\n"; |
---|
207 | } |
---|
208 | if ($type == 'url') { |
---|
209 | $checked = ($extra_info == 'oui') ? " checked='checked'" : ""; |
---|
210 | $out .= " <input type='checkbox' name='champ_verif' value='oui' id='verif_$champ'$checked> "; |
---|
211 | $out .= "<label for='verif_$champ'>"._T("forms:verif_web")."</label>"; |
---|
212 | $out .= "<br />\n"; |
---|
213 | } |
---|
214 | if ($type == 'select') { |
---|
215 | $out .= "<label for='format_liste_$champ'>"._T("forms:format_liste_ou_radio")."</label> :"; |
---|
216 | $out .= " <select name='format_liste' id='format_liste_$champ' class='fondo verdana2'>\n"; |
---|
217 | $out .= "<option value='liste'".($row['extra_info']=='liste'?"selected='selected'":"").">"._T("forms:format_liste")."</option>\n"; |
---|
218 | $out .= "<option value='radio'".($row['extra_info']=='radio'?"selected='selected'":"").">"._T("forms:format_radio")."</option>\n"; |
---|
219 | $out .= "</select>"; |
---|
220 | $out .= "<br />\n"; |
---|
221 | } |
---|
222 | if ($type == 'select' || $type == 'multiple') { |
---|
223 | $ajout_choix = _request('ajout_choix'); |
---|
224 | |
---|
225 | $out .= "<div style='margin: 5px; padding: 5px; border: 1px dashed $couleur_claire;'>"; |
---|
226 | $out .= _T("forms:liste_choix")." :<br />\n"; |
---|
227 | $out .= "<div class='sortableChoix' id='ordre_choix_$champ' >"; |
---|
228 | $res2 = spip_query("SELECT * FROM spip_forms_champs_choix WHERE id_form="._q($id_form)." AND champ="._q($champ)." ORDER BY rang"); |
---|
229 | while ($row2 = spip_fetch_array($res2)){ |
---|
230 | $choix = $row2['choix']; |
---|
231 | $focus=''; |
---|
232 | if ($ajout_choix == $choix) $focus='antifocus'; |
---|
233 | $out .= "<div class='sortableChoixItem' id='$champ-$choix'>"; |
---|
234 | $out .= "<img src='"._DIR_PLUGIN_FORMS."img_pack/choix-handle-16.png' class ='sortableChoixHandle' />"; |
---|
235 | $out .= "<input type='text' id='nom_$choix' name='$choix' value=\"".entites_html($row2['titre'])."\" ". |
---|
236 | "class='fondl verdana2 $focus' size='20' />"; |
---|
237 | |
---|
238 | $supp_link = parametre_url($action_link,'supp_choix', $choix); |
---|
239 | $out .= " <span class='verdana1'>[<a href='$supp_link#$idbloc' class='ajaxAction' rel ='$redirect' >". |
---|
240 | _T("forms:supprimer_choix")."</a>]</span>"; |
---|
241 | $out .= "</div>\n"; |
---|
242 | } |
---|
243 | $out .= "</div><input type='hidden' name='ordre' value='' />"; |
---|
244 | $ajout_choix = parametre_url($action_link,'ajout_choix', '1'); |
---|
245 | $out .= "<br /><input type='submit' name='ajout_choix' value=\""._T("forms:ajouter_choix")."\" class='fondo verdana2'>"; |
---|
246 | _T("forms:ajouter_choix")."</a>]</div>"; |
---|
247 | $out .= "</div>"; |
---|
248 | |
---|
249 | $switch_link = parametre_url($action_link,'switch_select_multi', '1'); |
---|
250 | $switch_link = parametre_url($switch_link,'modif_champ', $champ); |
---|
251 | $out .= "<br /><span class='verdana1'>[<a href='$switch_link#champs' class='ajaxAction' rel ='$redirect' >". |
---|
252 | (($type=='select')?_T("forms:changer_choix_multiple"):_T("forms:changer_choix_unique")) . |
---|
253 | "</a>]</span>"; |
---|
254 | |
---|
255 | $out .= "<br />\n"; |
---|
256 | } |
---|
257 | if ($type == 'mot') { |
---|
258 | $out .= "<label for='groupe_$champ'>"._T("forms:champ_nom_groupe")."</label> :"; |
---|
259 | $out .= " <select name='groupe_$champ' value='0' id='groupe_$champ' class='fondo verdana2'>\n"; |
---|
260 | $res2 = spip_query("SELECT * FROM spip_groupes_mots ORDER BY titre"); |
---|
261 | while ($row2 = spip_fetch_array($res2)) { |
---|
262 | $id_groupe = $row2['id_groupe']; |
---|
263 | $titre_groupe = supprimer_tags(typo($row2['titre'])); |
---|
264 | $selected = ($id_groupe == $row['extra_info']) ? " selected='selected'": ""; |
---|
265 | $out .= "<option value='$id_groupe'$selected>$titre_groupe</option>\n"; |
---|
266 | } |
---|
267 | $out .= "</select>"; |
---|
268 | $out .= "<br />\n"; |
---|
269 | } |
---|
270 | if ($type == 'joint') { |
---|
271 | $out .= "<label for='type_table_$champ'>"._T("forms:champ_table_jointure_type")."</label> :"; |
---|
272 | $out .= " <select name='type_table' value='' id='type_table_$champ' class='fondo verdana2'>\n"; |
---|
273 | $res2 = spip_query("SELECT type_form FROM spip_forms WHERE type_form NOT IN ('sondage','') GROUP BY type_form ORDER BY type_form"); |
---|
274 | while ($row2 = spip_fetch_array($res2)) { |
---|
275 | $type_form = $row2['type_form']; |
---|
276 | $prefixei18n = forms_prefixi18n($type_form); |
---|
277 | $titre_type = supprimer_tags((($t=_T("$prefixei18n:type_des_tables"))!='type des tables')?$t:$type_form); |
---|
278 | $selected = ($type_form == $row['extra_info']) ? " selected='selected'": ""; |
---|
279 | $out .= "<option value='$type_form'$selected>$titre_type</option>\n"; |
---|
280 | } |
---|
281 | $out .= "</select>"; |
---|
282 | $out .= "<br />\n"; |
---|
283 | } |
---|
284 | if ($type == 'fichier') { |
---|
285 | $taille = intval($row['extra_info']); |
---|
286 | if (!$taille) $taille = ''; |
---|
287 | $out .= "<label for='taille_$champ'>"._T("forms:taille_max")."</label> : "; |
---|
288 | $out .= "<input type='text' name='taille_champ' value='$taille' id='taille_$champ' class='fondo verdana2'>\n"; |
---|
289 | $out .= "<br />\n"; |
---|
290 | } |
---|
291 | if ($type == 'password') { |
---|
292 | $out .= "<label for='confirmer_pass_$champ'>"._T("forms:confirmer_champ_password")."</label> : "; |
---|
293 | $out .= "<input type='text' name='champ_confirmer_pass' value='$extra_info' id='confirmer_pass_$champ' class='fondo verdana2'>\n"; |
---|
294 | $out .= "<br />\n"; |
---|
295 | } |
---|
296 | |
---|
297 | return pipeline('forms_bloc_edition_champ', |
---|
298 | array( |
---|
299 | 'args'=>array('row'=>$row,'action_link'=>$action_link, 'redirect'=>$redirect, 'idbloc'=>$idbloc), |
---|
300 | 'data'=>$out |
---|
301 | )); |
---|
302 | } |
---|
303 | |
---|
304 | function Forms_zone_edition_champs($id_form, $champ_visible, $nouveau_champ, $redirect,$ajax=false){ |
---|
305 | global $spip_lang_right,$couleur_claire,$spip_lang_left; |
---|
306 | $res = spip_query("SELECT type_form FROM spip_forms WHERE id_form="._q($id_form)); |
---|
307 | $row = spip_fetch_array($res); |
---|
308 | $prefixei18n = forms_prefixi18n($row['type_form']); |
---|
309 | $is_form = $prefixei18n=='form'; |
---|
310 | |
---|
311 | $out = ""; |
---|
312 | if (!$id_form) return $out; |
---|
313 | $out .= "<p>"; |
---|
314 | $out .= Forms_debut_cadre_formulaire('',true); |
---|
315 | $out .= "<div class='verdana3'>"; |
---|
316 | $out .= "<strong>"._T("$prefixei18n:champs_formulaire")."</strong><br />\n"; |
---|
317 | $out .= _T("forms:info_champs_formulaire"); |
---|
318 | $out .= "</div>\n"; |
---|
319 | $out .= "<div id='forms_lang'></div>"; |
---|
320 | $out .= "<div id='sortableChamps'>"; |
---|
321 | |
---|
322 | if ($row = spip_fetch_array(spip_query("SELECT MAX(rang) AS rangmax, MIN(rang) AS rangmin FROM spip_forms_champs WHERE id_form="._q($id_form)))){ |
---|
323 | $index_min = $row['rangmin']; |
---|
324 | $index_max = $row['rangmax']; |
---|
325 | } |
---|
326 | |
---|
327 | $res = spip_query("SELECT * FROM spip_forms_champs WHERE id_form="._q($id_form).($ajax?" AND champ="._q($ajax):"")." ORDER BY rang"); |
---|
328 | while ($row = spip_fetch_array($res)) { |
---|
329 | $champ = $row['champ']; |
---|
330 | $visible = ($champ == $champ_visible)||($champ == $nouveau_champ); |
---|
331 | $nouveau = ($champ == $nouveau_champ); |
---|
332 | $obligatoire = $row['obligatoire']; |
---|
333 | $rang = $row['rang']; |
---|
334 | $aff_min = $rang > $index_min; |
---|
335 | $aff_max = $rang < $index_max; |
---|
336 | $type = $row['type']; |
---|
337 | $id_bloc = "champs-$id_form-$champ"; |
---|
338 | |
---|
339 | $redirect = ancre_url(parametre_url($redirect,'champ_visible',$champ),'champ_visible'); |
---|
340 | $action_link = generer_action_auteur("forms_edit","$id_form",urlencode($redirect)); |
---|
341 | $action_link_noredir = parametre_url($action_link,'redirect',''); |
---|
342 | |
---|
343 | $out .= "<div id='order_$id_bloc' class='sortableChampsItem'>"; |
---|
344 | if ($nouveau) $out .= "<a name='nouveau_champ'></a>"; |
---|
345 | else if ($visible) $out .= "<a name='champ_visible'></a>"; |
---|
346 | if (!in_array($type,array('separateur','textestatique'))) |
---|
347 | $out .= debut_cadre_relief("", true); |
---|
348 | else |
---|
349 | $out .= debut_cadre_enfonce("", true); |
---|
350 | |
---|
351 | $out .= "<img src='"._DIR_PLUGIN_FORMS."img_pack/choix-handle-24.png' class ='sortableChampsHandle' style='float:$spip_lang_left;position:relative;'/>"; |
---|
352 | $out .= "<div class='verdana1' style='float: $spip_lang_right; font-weight: bold;position:relative;display:inline;'>"; |
---|
353 | $out .= "<span class='boutons_ordonne'>"; |
---|
354 | if ($aff_min) { |
---|
355 | $link = generer_action_auteur('forms_champs_deplace',"$id_form-$champ-monter",urlencode($redirect)); |
---|
356 | $link = parametre_url($link,"time",time()); // pour avoir une url differente de l'actuelle |
---|
357 | $out .= "<a href='$link#champs' class='ajaxAction' rel='$redirect'><img src='"._DIR_IMG_PACK."monter-16.png' style='border:0' alt='"._T("forms:champ_monter")."'></a>"; |
---|
358 | if ($aff_max) |
---|
359 | $out .= " | "; |
---|
360 | } |
---|
361 | if ($aff_max) { |
---|
362 | $link = generer_action_auteur('forms_champs_deplace',"$id_form-$champ-descendre",urlencode($redirect)); |
---|
363 | $link = parametre_url($link,"time",time()); // pour avoir une url differente de l'actuelle |
---|
364 | $out .= "<a href='$link#champs' class='ajaxAction' rel='$redirect'><img src='"._DIR_IMG_PACK."descendre-16.png' style='border:0' alt='"._T("forms:champ_descendre")."'></a>"; |
---|
365 | } |
---|
366 | $out .= "</span>"; |
---|
367 | // Supprimer un champ |
---|
368 | $message = unicode_to_javascript(addslashes(html2unicode(_T("forms:confirm_supprimer_champ",array('champ'=>$row['titre']))))); |
---|
369 | $link = parametre_url($action_link,'supp_champ', $champ); |
---|
370 | $out .= "<a href='$link#champs' class='ajaxAction confirmer' rel='$redirect' " |
---|
371 | . "onclick=\"return confirmAction('$message')\">" |
---|
372 | . "<img src='"._DIR_IMG_PACK."supprimer.gif' style='border:0' alt='"._T("forms:supprimer_champ")."'></a>"; |
---|
373 | $out .= "</div>\n"; |
---|
374 | |
---|
375 | // Modifier un champ |
---|
376 | $formulaire = ""; |
---|
377 | $formulaire .= "<div id='forms_lang_nom_$champ'></div>"; |
---|
378 | |
---|
379 | $formulaire .= "<form class='ajaxAction' method='POST' action='$action_link_noredir'" . |
---|
380 | " style='border: 0px; margin: 0px;'>" . |
---|
381 | form_hidden($action_link_noredir) . |
---|
382 | "<input type='hidden' name='redirect' value='$redirect' />" . // form_hidden ne desencode par redirect ... |
---|
383 | "<input type='hidden' name='idtarget' value='$id_bloc' />" . |
---|
384 | "<input type='hidden' name='modif_champ' value='$champ' />"; |
---|
385 | |
---|
386 | $formulaire .= "<div class='verdana2'>"; |
---|
387 | $focus=""; |
---|
388 | if ($nouveau) $focus='antifocus'; |
---|
389 | |
---|
390 | if ($type=='separateur'){ |
---|
391 | $formulaire .= "<label for='nom_$champ'>"._T("forms:champ_nom_bloc")."</label> :"; |
---|
392 | $formulaire .= " <input type='text' name='nom_champ' id='nom_$champ' value=\"". |
---|
393 | entites_html($row['titre'])."\" class='fondo verdana2 $focus' size='30' /><br />\n"; |
---|
394 | $formulaire .= Forms_bloc_edition_champ($row, $action_link, $redirect, $id_bloc); |
---|
395 | } |
---|
396 | else if ($type=='textestatique'){ |
---|
397 | $formulaire .= "<label for='nom_$champ'>"._T("forms:champ_nom_texte")."</label> :<br/>"; |
---|
398 | $formulaire .= " <textarea name='nom_champ' id='nom_$champ' class='verdana2 $focus' style='width:100%;height:5em;' />". |
---|
399 | entites_html($row['titre'])."</textarea><br />\n"; |
---|
400 | $formulaire .= Forms_bloc_edition_champ($row, $action_link, $redirect, $id_bloc); |
---|
401 | } |
---|
402 | else{ |
---|
403 | $formulaire .= "<label for='nom_$champ'>"._T("forms:champ_nom")."</label> :"; |
---|
404 | $formulaire .= " <input type='text' name='nom_champ' id='nom_$champ' value=\"". |
---|
405 | entites_html($row['titre'])."\" class='fondo verdana2 $focus' size='30' /><br />\n"; |
---|
406 | $formulaire .= Forms_bloc_edition_champ($row, $action_link, $redirect, $id_bloc); |
---|
407 | |
---|
408 | $formulaire .= "<label for='aide_$champ'>"._T("forms:aide_contextuelle")."</label> :"; |
---|
409 | $formulaire .= " <textarea name='aide_champ' id='aide_$champ' class='verdana2' style='width:90%;height:3em;' >". |
---|
410 | entites_html($row['aide'])."</textarea><br />\n"; |
---|
411 | |
---|
412 | } |
---|
413 | $formulaire .= "<label for='wrap_$champ'>"._T("forms:html_wrapper")."</label> :"; |
---|
414 | $formulaire .= " <textarea name='wrap_champ' id='wrap_$champ' class='verdana2' style='width:90%;height:3em;' >". |
---|
415 | entites_html($row['html_wrap'])."</textarea><br />\n"; |
---|
416 | |
---|
417 | $formulaire .= "<div style='text-align:$spip_lang_right'>"; |
---|
418 | $formulaire .= "<input type='submit' name='Valider' value='"._T('bouton_valider')."' class='fondo verdana2'>\n"; |
---|
419 | $formulaire .= "</div>\n"; |
---|
420 | |
---|
421 | $args_redir=parametre_url($redirect,'exec','','&'); |
---|
422 | $args_redir=explode("#",$args_redir); |
---|
423 | $args_redir=explode("?",$args_redir[0]); |
---|
424 | $args_redir="&".$args_redir[1]; |
---|
425 | |
---|
426 | $formulaire .= "</div>"; |
---|
427 | $formulaire .= "</form>"; |
---|
428 | if (version_compare($GLOBALS['spip_version_code'],'1.9250','>')){ |
---|
429 | $formulaire = |
---|
430 | bouton_block_depliable(typo($row['titre'])." (".typo(Forms_nom_type_champ($row['type'])).")",$visible,"champ_$champ") |
---|
431 | . debut_block_depliable($visible,"champ_$champ") |
---|
432 | . $formulaire |
---|
433 | . fin_block(); |
---|
434 | } |
---|
435 | else { |
---|
436 | $formulaire = |
---|
437 | "<div style='padding: 2px; background-color: $couleur_claire; color: black;'> " |
---|
438 | . ($visible ? bouton_block_visible("champ_$champ") : bouton_block_invisible("champ_$champ")) |
---|
439 | . "<strong id='titre_nom_$champ'>".typo($row['titre'])."</strong>" |
---|
440 | . "<br /></div>" |
---|
441 | . "(".typo(Forms_nom_type_champ($row['type'])).")\n" |
---|
442 | . ($visible ? debut_block_visible("champ_$champ") : debut_block_invisible("champ_$champ")) |
---|
443 | . $formulaire |
---|
444 | . fin_block(); |
---|
445 | } |
---|
446 | |
---|
447 | if ($ajax && ($champ == $ajax)) |
---|
448 | return $formulaire; |
---|
449 | $out .= "<div id='$id_bloc' class='forms_champs'>$formulaire</div>"; |
---|
450 | if (!in_array($type,array('separateur','textestatique'))) |
---|
451 | $out .= fin_cadre_relief(true); |
---|
452 | else |
---|
453 | $out .= fin_cadre_enfonce(true); |
---|
454 | $out .= '</div>'; |
---|
455 | } |
---|
456 | if ($ajax) |
---|
457 | return "Champ $ajax introuvable"; // erreur si l'on est encore ici |
---|
458 | $out .= "</div>"; |
---|
459 | // Reordonner les champs ------------------------------------------------------------ |
---|
460 | $action_link = generer_action_auteur("forms_edit","$id_form",urlencode($redirect)); |
---|
461 | $action_link_noredir = parametre_url($action_link,'redirect',''); |
---|
462 | $out .= "<form class='ajaxAction sortableChamps' method='POST' action='$action_link_noredir' style='display:none;'>" . |
---|
463 | form_hidden($action_link_noredir) . |
---|
464 | "<input type='hidden' name='redirect' value='$redirect' />" . // form_hidden ne desencode par redirect ... |
---|
465 | "<input type='hidden' name='idtarget' value='dummy' />". // on target un div vide |
---|
466 | "<input type='hidden' name='ordonne_champs' value='$id_form' />"; |
---|
467 | $out .= "<input type='text' name='ordre' value='' />"; |
---|
468 | $out .= " <input type='submit' name='valider' value='"._T('bouton_valider')."' class='fondo'>"; |
---|
469 | $out .= "<div id='dummy'></div>"; |
---|
470 | $out .= "</form>\n"; |
---|
471 | |
---|
472 | // Ajouter un champ ------------------------------------------------------------------ |
---|
473 | $redirect = ancre_url(parametre_url($redirect,'champ_visible',''),''); |
---|
474 | $action_link = generer_action_auteur("forms_edit","$id_form",urlencode($redirect)); |
---|
475 | $action_link_noredir = parametre_url($action_link,'redirect',''); |
---|
476 | $out .= "<p>"; |
---|
477 | $out .= debut_cadre_enfonce("", true); |
---|
478 | $out .= "<form class='ajaxAction' method='POST' action='$action_link_noredir' style='border: 0px; margin: 0px;'>" . |
---|
479 | form_hidden($action_link_noredir) . |
---|
480 | "<input type='hidden' name='redirect' value='$redirect' />" . // form_hidden ne desencode par redirect ... |
---|
481 | "<input type='hidden' name='idtarget' value='champs' />"; // on target toute la boite, pas juste le div parent |
---|
482 | $out .= "<strong>"._T("forms:ajouter_champ")."</strong><br />\n"; |
---|
483 | $out .= _T("forms:ajouter_champ_type"); |
---|
484 | $out .= " \n"; |
---|
485 | |
---|
486 | $types = Forms_liste_types_champs(); |
---|
487 | $out .= "<select name='ajout_champ' value='' class='fondo'>\n"; |
---|
488 | foreach ($types as $type) { |
---|
489 | $out .= "<option value='$type'>".typo(Forms_nom_type_champ($type))."</option>\n"; |
---|
490 | } |
---|
491 | $out .= "</select>\n"; |
---|
492 | $out .= " <input type='submit' name='valider' id='ajout_champ' value='"._T('bouton_ajouter')."' class='fondo'>"; |
---|
493 | $out .= "</form>\n"; |
---|
494 | $out .= fin_cadre_enfonce(true); |
---|
495 | $out .= "</p>"; |
---|
496 | $out .= Forms_fin_cadre_formulaire(true); |
---|
497 | $out .= "</p>"; |
---|
498 | |
---|
499 | return $out; |
---|
500 | } |
---|
501 | |
---|
502 | |
---|
503 | // |
---|
504 | // Edition des donnees du formulaire |
---|
505 | // |
---|
506 | function boite_proprietes($id_form, $row, $focus, $action_link, $redirect) { |
---|
507 | $prefixei18n = forms_prefixi18n($row['type_form']); |
---|
508 | $is_form = $prefixei18n=='form'; |
---|
509 | |
---|
510 | $out = ""; |
---|
511 | $out .= "<p>"; |
---|
512 | $out .= Forms_debut_cadre_formulaire('',true); |
---|
513 | |
---|
514 | $action_link_noredir = parametre_url($action_link,'redirect',''); |
---|
515 | $out .= "<div class='verdana2'>"; |
---|
516 | //$out .= "<form method='POST' action='$action_link' style='border: 0px; margin: 0px;'>"; |
---|
517 | //$out .= form_hidden($action_link); |
---|
518 | $out .= "<form class='ajaxAction' method='POST' action='$action_link_noredir'" . |
---|
519 | " style='border: 0px; margin: 0px;'>" . |
---|
520 | form_hidden($action_link_noredir) . |
---|
521 | "<input type='hidden' name='redirect' value='$redirect' />" . // form_hidden ne desencode par redirect ... |
---|
522 | "<input type='hidden' name='idtarget' value='proprietes' />" ; |
---|
523 | |
---|
524 | $titre = entites_html($row['titre']); |
---|
525 | $descriptif = entites_html($row['descriptif']); |
---|
526 | $texte = entites_html($row['texte']); |
---|
527 | $email = unserialize($row['email']); |
---|
528 | |
---|
529 | $out .= "<strong><label for='titre_form'>"._T("$prefixei18n:titre_formulaire")."</label></strong> "._T('info_obligatoire_02'); |
---|
530 | $out .= "<br />"; |
---|
531 | $out .= "<input type='text' name='titre' id='titre_form' class='formo $focus' ". |
---|
532 | "value=\"".$titre."\" size='40' /><br />\n"; |
---|
533 | |
---|
534 | $out .= "<strong><label for='desc_form'>"._T('info_descriptif')."</label></strong>"; |
---|
535 | $out .= "<br />"; |
---|
536 | $out .= "<textarea name='descriptif' id='desc_form' class='forml' rows='4' cols='40' wrap='soft'>"; |
---|
537 | $out .= $descriptif; |
---|
538 | $out .= "</textarea><br />\n"; |
---|
539 | |
---|
540 | $out .= Forms_bloc_routage_mail($id_form,$email); |
---|
541 | |
---|
542 | $out .= "<strong><label for='confirm_form'>"._T('forms:confirmer_reponse')."</label></strong> "; |
---|
543 | $out .= "<br />"; |
---|
544 | $out .= "<select name='champconfirm' id='confirm_form' class='forml'"; |
---|
545 | $out .= "onchange=\"if (options[selectedIndex].value=='') $('#texte_confirm').hide(); else $('#texte_confirm').show();\" "; |
---|
546 | $out .= ">\n"; |
---|
547 | $out .= "<option value=''>"._T('forms:pas_mail_confirmation')."</option>\n"; |
---|
548 | $champconfirm_known = false; |
---|
549 | $res2 = spip_query("SELECT * FROM spip_forms_champs WHERE type='email' AND id_form="._q($id_form)); |
---|
550 | while ($row2 = spip_fetch_array($res2)) { |
---|
551 | $out .= "<option value='" . $row2['champ'] . "'"; |
---|
552 | if ($row['champconfirm'] == $row2['champ']){ |
---|
553 | $out .= " selected='selected'"; |
---|
554 | $champconfirm_known = true; |
---|
555 | } |
---|
556 | $out .= ">" . $row2['titre'] . "</option>\n"; |
---|
557 | } |
---|
558 | $out .= "</select><br />\n"; |
---|
559 | $display = $champconfirm_known?"block":"none"; |
---|
560 | $out .= "<div id='texte_confirm' style='display:$display'>"; |
---|
561 | $out .= "<strong><label for='texte_form'>"._T('info_texte')."</label></strong>"; |
---|
562 | $out .= "<br />"; |
---|
563 | $out .= "<textarea name='texte' id='texte_form' class='formo' rows='4' cols='40' wrap='soft'>"; |
---|
564 | $out .= $texte; |
---|
565 | $out .= "</textarea><br />\n"; |
---|
566 | $out .= "</div>"; |
---|
567 | |
---|
568 | if ($is_form){ |
---|
569 | $out .= debut_cadre_enfonce("../"._DIR_PLUGIN_FORMS."img_pack/sondage-24.png",true); |
---|
570 | $out .= "<strong>"._T("forms:type_form")."</strong> : "; |
---|
571 | $out .= _T("forms:info_sondage"); |
---|
572 | $out .= "<br /><br />"; |
---|
573 | $out .= bouton_radio('type_form', '', _T("forms:sondage_non"), $row['type_form'] == '').'<br />'; |
---|
574 | $out .= bouton_radio('type_form', 'sondage', _T("forms:sondage_oui"), $row['type_form'] == 'sondage').'<br />'; |
---|
575 | $out .= fin_cadre_enfonce(true); |
---|
576 | } |
---|
577 | else |
---|
578 | $out .= "<input type='hidden' name='type_form' value='".$row['type_form']."' />"; |
---|
579 | |
---|
580 | $out .= debut_cadre_enfonce("",true); |
---|
581 | $out .= "<strong><label for='modifiable'>"._T('forms:modifiable_donnees')."</label></strong>"; |
---|
582 | $out .= "<br />"; |
---|
583 | $out .= bouton_radio("modifiable", "oui", _T('forms:donnees_modifiable'), $row['modifiable'] == "oui", ""); |
---|
584 | $out .= "<br />"; |
---|
585 | $out .= bouton_radio("modifiable", "non", _T('forms:donnees_nonmodifiable'), $row['modifiable'] != "oui", ""); |
---|
586 | $out .= "<br />"; |
---|
587 | $out .= fin_cadre_enfonce(true); |
---|
588 | |
---|
589 | $out .= debut_cadre_enfonce("",true); |
---|
590 | $out .= "<strong><label for='multiple'>"._T('forms:multiple_donnees')."</label></strong>"; |
---|
591 | $out .= "<br />"; |
---|
592 | $out .= bouton_radio("multiple", "oui", _T('forms:donnees_multiple'), $row['multiple'] == "oui", ""); |
---|
593 | $out .= "<br />"; |
---|
594 | $out .= bouton_radio("multiple", "non", _T('forms:donnees_nonmultiple'), $row['multiple'] != "oui", ""); |
---|
595 | $out .= "<br />"; |
---|
596 | $out .= fin_cadre_enfonce(true); |
---|
597 | if ($is_form){ |
---|
598 | $out .= debut_cadre_enfonce("",true); |
---|
599 | $out .= "<strong><label for='forms_obligatoires'>"._T('forms:forms_obligatoires')."</label></strong>"; |
---|
600 | $out .= "<br />"; |
---|
601 | $out .= "<input type='text' name='forms_obligatoires' id='forms_obligatoires_form' class='formo $focus' ". |
---|
602 | "value=\"".$row['forms_obligatoires']."\" size='40' /><br />\n"; |
---|
603 | $out .= "<br />"; |
---|
604 | $out .= fin_cadre_enfonce(true); |
---|
605 | } |
---|
606 | |
---|
607 | $out .= debut_cadre_enfonce("",true); |
---|
608 | $out .= "<strong><label for='moderation'>"._T('forms:publication_donnees')."</label></strong>"; |
---|
609 | $out .= "<br />"; |
---|
610 | $out .= bouton_radio("public", "oui", _T('forms:donnees_pub'), $row['public'] == "oui", ""); |
---|
611 | $out .= "<br />"; |
---|
612 | $out .= bouton_radio("public", "non", _T('forms:donnees_prot'), $row['public'] != "oui", ""); |
---|
613 | $out .= "<br />"; |
---|
614 | $out .= fin_cadre_enfonce(true); |
---|
615 | |
---|
616 | $out .= debut_cadre_enfonce("",true); |
---|
617 | $out .= "<strong><label for='moderation'>"._T('forms:moderation_donnees')."</label></strong>"; |
---|
618 | $out .= "<br />"; |
---|
619 | $out .= bouton_radio("moderation", "posteriori", _T('bouton_radio_publication_immediate'), $row['moderation'] != "priori", ""); |
---|
620 | $out .= "<br />"; |
---|
621 | $out .= bouton_radio("moderation", "priori", _T('bouton_radio_moderation_priori'), $row['moderation'] == "priori", ""); |
---|
622 | $out .= "<br />"; |
---|
623 | $out .= fin_cadre_enfonce(true); |
---|
624 | |
---|
625 | $out .= debut_cadre_enfonce("",true); |
---|
626 | $out .= "<input type='checkbox' name='linkable' id='linkable' value='oui'"; |
---|
627 | if ($row['linkable']=='oui') $out .= "checked='checked' /><label for='linkable'><b>"; |
---|
628 | else $out .=" /><label for='linkable'>"; |
---|
629 | $out .= _T("forms:lier_articles"); |
---|
630 | if ($row['linkable']=='oui') $out .= "</b>"; |
---|
631 | $out .= "</label><br />"; |
---|
632 | $out .= "<input type='checkbox' name='documents' id='documents' value='oui'"; |
---|
633 | if ($row['documents']=='oui') $out .= "checked='checked' /><label for='documents'><b>"; |
---|
634 | else $out .=" /><label for='documents'>"; |
---|
635 | $out .= _T("forms:lier_documents"); |
---|
636 | if ($row['documents']=='oui') $out .= "</b>"; |
---|
637 | $out .= "</label><br />"; |
---|
638 | $out .= "<input type='checkbox' name='documents_mail' id='documents_mail' value='oui'"; |
---|
639 | if ($row['documents_mail']=='oui') $out .= "checked='checked' /><label for='documents_mail'><b>"; |
---|
640 | else $out .=" /><label for='documents_mail'>"; |
---|
641 | $out .= _T("forms:lier_documents_mail"); |
---|
642 | if ($row['documents_mail']=='oui') $out .= "</b>"; |
---|
643 | $out .= "</label><br />"; |
---|
644 | $out .= fin_cadre_enfonce(true); |
---|
645 | |
---|
646 | $out .= "<label for='wrap'>"._T("forms:html_wrapper")."</label> :"; |
---|
647 | $out .= " <textarea name='html_wrap' id='wrap' class='verdana2' style='width:90%;height:3em;' >". |
---|
648 | entites_html($row['html_wrap'])."</textarea><br />\n"; |
---|
649 | |
---|
650 | $out .= "<div style='text-align:right'>"; |
---|
651 | $out .= "<input type='submit' name='Valider' value='"._T('bouton_valider')."' class='fondo'></div>\n"; |
---|
652 | |
---|
653 | $out .= "</form>"; |
---|
654 | $out .= "</div>"; |
---|
655 | $out .= Forms_fin_cadre_formulaire(true); |
---|
656 | $out .= "</p>"; |
---|
657 | return $out; |
---|
658 | } |
---|
659 | ?> |
---|