/[openfoncier]/trunk/scr/genetat.php
ViewVC logotype

Contents of /trunk/scr/genetat.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 71 - (show annotations)
Fri Aug 19 14:04:56 2011 UTC (13 years, 5 months ago) by fraynaud
File size: 5091 byte(s)
om 4.1.0 sig et gen


1 <?php
2 /**
3 * ce script a pour objet de fabriquer des etats
4 * @package openmairie_exemple
5 * @version SVN : $Id: import.php 110 2010-09-30 14:00:43Z jbastide $
6 */
7 $DEBUG=0;
8 //echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
9 //echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" lang=\"fr\">\n";
10
11 require_once "../obj/utils.class.php";
12 $f = new utils(NULL, "genetat_script", _("etat"), "ico_import.png",
13 "etat_script");
14 /**
15 * Description de la page
16 */
17 $description = _("cet assistant vous permet de creer des etats ".
18 "directement a partir de vos tables ");
19 $f->displayDescription($description);
20 /**
21 *
22 */
23 set_time_limit(3600);
24 if (isset($_POST['choice-import']) and $_POST['choice-import'] != "---") {
25 $obj = $_POST['choice-import'];
26 } elseif(isset($_GET['obj'])) {
27 $obj = $_GET['obj'];
28 } else {
29 $obj = "";
30 }
31 if(isset($_GET['validation'])) {
32 $validation = $_GET['validation'];
33 } else {
34 $validation = 0;
35 }
36 if (isset($_POST['choice-field'])){
37 $field=$_POST['choice-field'];
38 }else{
39 $field='';
40 }
41 /**
42 * On liste les tables
43 */
44 // tab
45 $tab = array();
46 if ($f -> phptype == 'mysql')
47 $sql = "SHOW TABLES FROM ".$f->database[$_SESSION['coll']]["database"];
48
49 if($f -> phptype == 'pgsql'){ //***pgsql
50 $sql ="select tablename from pg_tables where schemaname='".$f -> schema.
51 "' UNION select (viewname||' [vue]') from pg_views where schemaname='".$f -> schema."'"; // ***
52 }
53
54 $res1 = $f -> db -> query ($sql);
55 if (database::isError($res1))
56 $res1->getDebugInfo(); //$this->erreur_db($res1->getDebugInfo(),$res1->getMessage(),$table);
57 else{
58 $k=0;
59 while ($row=& $res1->fetchRow()){
60 if(substr($row[0],-3,3)!= "seq" ){
61 $k++;
62 array_push($tab, $f->tablebase[$k]= $row[0]);
63 }
64 }
65 }// while
66 asort($tab);
67 echo "\n<div id=\"form-choice-import\" class=\"formulaire\">\n";
68 echo "<form action=\"../gen/genetat.php\" method=\"post\">\n";
69 echo "<fieldset>\n";
70 echo "\t<legend>"._("Choix table :")."</legend>\n";
71 echo "\t<div class=\"field\">";
72 echo "<label>"._("fichier")."</label>";
73 echo "<select onchange=\"submit()\" name=\"choice-import\" class=\"champFormulaire\">";
74 echo "<option>---</option>";
75 foreach ($tab as $elem) {
76 echo "<option value=\"".$elem."\"";
77 if ($obj == $elem) {
78 echo " selected=\"selected\" ";
79 }
80 echo ">".$elem."</option>";
81 }
82 echo "</select>";
83 echo "</div>\n";
84 echo "</fieldset>\n";
85 echo "</form>\n";
86 echo "</div>\n";
87 /**
88 * choix des champs
89 */
90 if ($obj != "" and $field=='') {
91 //
92 echo "\n<br>&nbsp;<div id=\"form-csv-import\" class=\"formulaire\">\n";
93 echo "<form action=\"../gen/genetat.php?obj=".$obj."&validation=1\" method=\"post\" name=\"f1\">\n";
94 echo "<fieldset>\n";
95 echo "\t<legend>"._("choix des champs")."</legend>";
96 echo "Utilisez ctrl key pour choix multiple<br><br>";
97 $sql= "select * from ".DB_PREFIXE.$obj;
98 $res2 = $f -> db -> query ($sql);
99 $info=$res2->tableInfo();
100 echo "<select multiple name=\"choice-field[]\" class=\"champFormulaire\">";
101 foreach($info as $elem){
102 echo "<option>".$obj.".".$elem['name']."</option>";
103 }
104 echo "</select>";
105 echo "<br><br>";
106 echo "<input type=\"submit\" name=\"submit-csv-import\" value=\""._("Import")." ".
107 $obj." "._("dans la base")."\" class=\"boutonFormulaire\" />";
108 echo "</div>";
109 echo "</fieldset>";
110 echo "</form>";
111 echo "</div>\n";
112 }
113 /**
114 * transfert dans la base
115 */
116 if ($obj != "" and $field!='') {
117 echo "\n<br>&nbsp";
118 echo "<fieldset>\n";
119 echo "\t<legend> Insertion dans la table etat</legend>";
120 // sql
121 $temp='';
122 $temp1='';
123 if($field!=array()){
124 for ($i = 0; $i < sizeof($field); $i++) {
125 $temp2=explode(".",$field[$i]);
126 $temp3=$temp2[1];
127 $temp.=$field[$i].' as '.$temp3.',';
128 $temp1.="[".$temp3.']'.chr(13).chr(10);
129 }
130 $temp=substr($temp, 0, strlen($temp)-1);
131 }
132 if (file_exists ("dyn/standard/etat.inc"))
133 include("dyn/standard/etat.inc");
134 if (file_exists ("dyn/custom/etat.inc"))
135 include("dyn/custom/etat.inc");
136
137
138 $etat['om_sql']="select ".$temp." from &DB_PREFIXE".$obj." where ".$obj.".".$obj."='".$variable."idx'";
139 $etat['titre']="le ".$variable."aujourdhui";
140 $etat['corps']=$temp1;
141 // id
142 $etat['id']= $obj;
143 $etat['libelle']= $obj." gen le ".date('d/m/Y');
144 $etat['actif']=''; // contrainte null pgsql
145 $etat['sousetat']=''; // contrainte null pgsql
146 // om_collectivite
147 $etat['om_collectivite']= $_SESSION['collectivite'];
148 // parametre standard / custom
149
150 // next Id
151 $etat['om_etat']=$f-> db -> nextId(DB_PREFIXE.'om_etat');
152 $res= $f-> db -> autoExecute(DB_PREFIXE.'om_etat',$etat,DB_AUTOQUERY_INSERT);
153 if (database::isError($res))
154 die($res->getDebugInfo()." => echec requete insertion etat");
155 else
156 echo $obj." "._("enregistre");
157 echo "</fieldset>";
158 }
159 ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26