4 if (!defined("_ECRIRE_INC_VERSION")) return;
6 // Importation d'un formulaire forms&table
8 function echanger_formulaire_forms_importer_dist($fichier){
9 include_spip('inc/xml');
10 $arbre = spip_xml_load($fichier, false);
12 if ($arbre and is_array($arbre) and isset($arbre['forms'])){
13 foreach($arbre['forms'] as $forms){
14 foreach ($forms['form'] as $form){
15 $formulaire = array();
18 $titre = trim(spip_xml_aplatit($form['titre']));
19 $formulaire['titre'] = $titre ?
$titre : _T('info_sans_titre');
21 // L'identifiant il faut le générer
22 $formulaire['identifiant'] = 'form_'.time();
25 $descriptif = trim(spip_xml_aplatit($form['descriptif']));
26 $formulaire['descriptif'] = $descriptif ?
$descriptif : '';
28 // Le message de retour si ok
29 $message_retour = trim(spip_xml_aplatit($form['texte']));
30 $formulaire['message_retour'] = $message_retour ?
$message_retour : '';
33 $formulaire['saisies'] = array();
34 foreach($form['fields'] as $fields){
35 foreach($fields['field'] as $field){
39 'options' => array('size'=>40)
42 // On essaye de traduire tous les types de champs
43 $type = trim(spip_xml_aplatit($field['type']));
46 $saisie['saisie'] = 'textarea';
47 unset($saisie['options']['size']);
48 $saisie['options']['rows'] = 5;
49 $saisie['options']['cols'] = 40;
52 $saisie['options']['type'] = 'password';
55 $saisie['saisie'] = 'date';
56 $saisie['verifier'] = array(
62 $saisie['verifier'] = array(
65 if ($taille = trim(spip_xml_aplatit($field['taille'])))
66 $saisie['verifier']['options'] = array('max' => (pow(10, $taille)-1));
69 $saisie['verifier'] = array(
74 $saisie['verifier'] = array(
79 unset($saisie['options']['size']);
80 $liste = trim(spip_xml_aplatit($field['extra_info']));
81 if ($liste == 'radio')
82 $saisie['saisie'] = 'radio';
84 $saisie['saisie'] = 'selection';
87 $saisie['saisie'] = 'checkbox';
88 unset($saisie['options']['size']);
95 // On continue seulement si on a toujours une saisie
97 // Les choix pour les types select et multiple
98 if(isset($field['les_choix']) and is_array($field['les_choix'])){
99 $saisie['options']['datas'] = array();
100 foreach($field['les_choix'] as $les_choix){
101 foreach($les_choix['un_choix'] as $un_choix){
102 $choix = trim(spip_xml_aplatit($un_choix['choix']));
103 $titre = trim(spip_xml_aplatit($un_choix['titre']));
104 $saisie['options']['datas'][$choix] = $titre;
110 $saisie['options']['nom'] = trim(spip_xml_aplatit($field['champ']));
113 $saisie['options']['label'] = trim(spip_xml_aplatit($field['titre']));
116 if (trim(spip_xml_aplatit($field['obligatoire'])) == 'oui')
117 $saisie['options']['obligatoire'] = 'on';
119 // Explication éventuelle
120 if ($explication = trim(spip_xml_aplatit($field['aide'])))
121 $saisie['options']['explication'] = $explication;
123 // On ajoute enfin la saisie
124 $formulaire['saisies'][] = $saisie;
130 $formulaire['traitements'] = array();
132 // Le traitement email
133 $config_email = unserialize(trim(spip_xml_aplatit($form['email'])));
134 if (is_array($config_email)){
135 if ($email_defaut = $config_email['defaut'])
136 $formulaire['traitements']['email'] = array(
137 'destinataires_plus' => $email_defaut
141 // Le traitement enregistrement
142 $formulaire['traitements']['enregistrement'] = array(
143 'moderation' => (trim(spip_xml_aplatit($form['moderation'])) == 'priori') ?
'priori' : 'posteriori',
144 'modifiable' => (trim(spip_xml_aplatit($form['modifiable'])) == 'oui') ?
'on' : '',
145 'multiple' => (trim(spip_xml_aplatit($form['multiple'])) == 'non') ?
'' : 'on'
148 include_spip('action/editer_formulaire');
149 // On insère un nouveau formulaire
150 $id_formulaire = insert_formulaire();
151 // Si ça a marché on modifie les champs de base
152 if ($id_formulaire > 0 and !($erreur = formulaire_set($id_formulaire, $formulaire))){
153 // Et ensuite les saisies et les traitements
157 'saisies' => serialize($formulaire['saisies']),
158 'traitements' => serialize($formulaire['traitements'])
160 'id_formulaire = '.$id_formulaire
167 if ($id_formulaire and $ok){
168 return $id_formulaire;
171 return _T('formidable:erreur_importer_forms');