Mise en route du suivi.
[aidenligne_francais_universite.git] / plugins / forms_1_9_1 / base / forms_temporaire.php
1 <?php
2 /*
3 * forms
4 * version plug-in de spip_form
5 *
6 * Auteur :
7 * Antoine Pitrou
8 * adaptation en 182e puis plugin par cedric.morin@yterium.com
9 * © 2005,2006 - Distribue sous licence GNU/GPL
10 *
11 */
12 // Definition des tables temporaires pour permettre la squeletisation des formulaires
13 //
14
15 // Boucle FORMS_CHAMPS
16 $formschamp_field = array(
17 "id_form" => "bigint(21) NOT NULL",
18 "cle" => "bigint(21) NOT NULL",
19 "champ" => "varchar(100)",
20 "titre" => "text",
21 "type" => "varchar(100)",
22 "obligatoire" => "varchar(3)",
23 "id_groupe" => "bigint(21) NOT NULL",
24 );
25 $formschamp_key = array(
26 "PRIMARY KEY" => "id_form, cle"
27 );
28
29 $GLOBALS['tables_principales']['spip_forms_champs'] =
30 array('field' => &$formschamp_field, 'key' => &$formschamp_key);
31 $GLOBALS['table_des_tables']['forms_champs'] = 'forms_champs';
32
33 // Boucle FORMS_CHAMPS_CHOIX
34 $formschampchoix_field = array(
35 "id_form" => "bigint(21) NOT NULL",
36 "cle" => "bigint(21) NOT NULL",
37 "choix" => "varchar(100) NOT NULL DEFAULT ''",
38 "titre" => "text"
39 );
40 $formschampchoix_key = array(
41 "PRIMARY KEY" => "id_form, cle, choix",
42 "KEY" => "choix"
43 );
44
45 $GLOBALS['tables_principales']['spip_forms_champs_choix'] =
46 array('field' => &$formschampchoix_field, 'key' => &$formschampchoix_key);
47 $GLOBALS['table_des_tables']['forms_champs_choix'] = 'forms_champs_choix';
48
49
50 function forms_structure2table($row,$clean=false){
51 $id_form=$row[id_form];
52 // netoyer la structure precedente en table
53 if ($clean){
54 spip_query("DELETE FROM spip_forms_champs WHERE id_form=".spip_abstract_quote($id_form));
55 spip_query("DELETE FROM spip_forms_champs_choix WHERE id_form=".spip_abstract_quote($id_form));
56 }
57
58 $structure = unserialize($row['structure']);
59 foreach($structure as $cle=>$val){
60 $champ = $val['code'];
61 $titre = $val['nom'];
62 $type = $val['type'];
63 $obligatoire = $val['obligatoire'];
64 $type_ext = $val['type_ext'];
65 $id_groupe= isset($type_ext['id_groupe']) ? $type_ext['id_groupe']:0;
66 $obligatoire = $val['obligatoire'];
67 spip_query("INSERT INTO spip_forms_champs (id_form,cle,champ,titre,type,obligatoire,id_groupe)
68 VALUES(".spip_abstract_quote($id_form).",".spip_abstract_quote($cle).",".spip_abstract_quote($champ).",".spip_abstract_quote($titre).",".spip_abstract_quote($type).",".spip_abstract_quote($obligatoire).",".spip_abstract_quote($id_groupe).")");
69 if ($type=='select' OR $type=='multiple'){
70 foreach($type_ext as $choix=>$titre){
71 spip_query("INSERT INTO spip_forms_champs_choix (id_form,cle,choix,titre)
72 VALUES(".spip_abstract_quote($id_form).",".spip_abstract_quote($cle).",".spip_abstract_quote($choix).",".spip_abstract_quote($titre).")");
73 }
74 }
75 }
76 }
77 function forms_allstructure2table($clean=false){
78 $res = spip_query("SELECT * FROM spip_forms");
79 while ($row=spip_fetch_array($res))
80 forms_structure2table($row,$clean);
81 }
82
83 function forms_creer_tables_temporaires($temporaires=true){
84 static $ok=NULL;
85 if ($ok==NULL){
86 include_spip('base/create');
87 include_spip('base/abstract_sql');
88 $ok=true;
89 $nom = 'spip_forms_champs';
90 $champs = $GLOBALS['tables_principales'][$nom]['field'];
91 $cles = $GLOBALS['tables_principales'][$nom]['key'];
92 spip_create_table($nom, $champs, $cles, false, $temporaires);
93
94 $nom = 'spip_forms_champs_choix';
95 $champs = $GLOBALS['tables_principales'][$nom]['field'];
96 $cles = $GLOBALS['tables_principales'][$nom]['key'];
97 spip_create_table($nom, $champs, $cles, false, $temporaires);
98
99 forms_allstructure2table($temporaires==false);
100 }
101 }
102 ?>