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

Annotation of /trunk/gen/genetat.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (hide annotations)
Thu Feb 10 20:46:18 2011 UTC (13 years, 11 months ago) by fraynaud
File size: 4995 byte(s)
version initiale


1 fraynaud 3 <?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     }
52    
53     $res1 = $f -> db -> query ($sql);
54     if (database::isError($res1))
55     $res1->getDebugInfo(); //$this->erreur_db($res1->getDebugInfo(),$res1->getMessage(),$table);
56     else{
57     $k=0;
58     while ($row=& $res1->fetchRow()){
59     if(substr($row[0],-3,3)!= "seq" ){
60     $k++;
61     array_push($tab, $f->tablebase[$k]= $row[0]);
62     }
63     }
64     }// while
65     asort($tab);
66     echo "\n<div id=\"form-choice-import\" class=\"formulaire\">\n";
67     echo "<form action=\"../gen/genetat.php\" method=\"post\">\n";
68     echo "<fieldset>\n";
69     echo "\t<legend>"._("Choix table :")."</legend>\n";
70     echo "\t<div class=\"field\">";
71     echo "<label>"._("fichier")."</label>";
72     echo "<select onchange=\"submit()\" name=\"choice-import\" class=\"champFormulaire\">";
73     echo "<option>---</option>";
74     foreach ($tab as $elem) {
75     echo "<option value=\"".$elem."\"";
76     if ($obj == $elem) {
77     echo " selected=\"selected\" ";
78     }
79     echo ">".$elem."</option>";
80     }
81     echo "</select>";
82     echo "</div>\n";
83     echo "</fieldset>\n";
84     echo "</form>\n";
85     echo "</div>\n";
86     /**
87     * choix des champs
88     */
89     if ($obj != "" and $field=='') {
90     //
91     echo "\n<br>&nbsp;<div id=\"form-csv-import\" class=\"formulaire\">\n";
92     echo "<form action=\"../gen/genetat.php?obj=".$obj."&validation=1\" method=\"post\" name=\"f1\">\n";
93     echo "<fieldset>\n";
94     echo "\t<legend>"._("choix des champs")."</legend>";
95     echo "Utilisez ctrl key pour choix multiple<br><br>";
96     $sql= "select * from ".DB_PREFIXE.$obj;
97     $res2 = $f -> db -> query ($sql);
98     $info=$res2->tableInfo();
99     echo "<select multiple name=\"choice-field[]\" class=\"champFormulaire\">";
100     foreach($info as $elem){
101     echo "<option>".$obj.".".$elem['name']."</option>";
102     }
103     echo "</select>";
104     echo "<br><br>";
105     echo "<input type=\"submit\" name=\"submit-csv-import\" value=\""._("Import")." ".
106     $obj." "._("dans la base")."\" class=\"boutonFormulaire\" />";
107     echo "</div>";
108     echo "</fieldset>";
109     echo "</form>";
110     echo "</div>\n";
111     }
112     /**
113     * transfert dans la base
114     */
115     if ($obj != "" and $field!='') {
116     echo "\n<br>&nbsp";
117     echo "<fieldset>\n";
118     echo "\t<legend> Insertion dans la table etat</legend>";
119     // sql
120     $temp='';
121     $temp1='';
122     if($field!=array()){
123     for ($i = 0; $i < sizeof($field); $i++) {
124     $temp2=explode(".",$field[$i]);
125     $temp3=$temp2[1];
126     $temp.=$field[$i].' as '.$temp3.',';
127     $temp1.="[".$temp3.']'.chr(13).chr(10);
128     }
129     $temp=substr($temp, 0, strlen($temp)-1);
130     }
131     if (file_exists ("dyn/standard/etat.inc"))
132     include("dyn/standard/etat.inc");
133     if (file_exists ("dyn/custom/etat.inc"))
134     include("dyn/custom/etat.inc");
135    
136    
137     $etat['om_sql']="select ".$temp." from &DB_PREFIXE".$obj." where ".$obj.".".$obj."='".$variable."idx'";
138     $etat['titre']="le ".$variable."aujourdhui";
139     $etat['corps']=$temp1;
140     // id
141     $etat['id']= $obj;
142     $etat['libelle']= $obj." gen le ".date('d/m/Y');
143     $etat['actif']=''; // contrainte null pgsql
144     $etat['sousetat']=''; // contrainte null pgsql
145     // om_collectivite
146     $etat['om_collectivite']= $_SESSION['collectivite'];
147     // parametre standard / custom
148    
149     // next Id
150     $etat['om_etat']=$f-> db -> nextId(DB_PREFIXE.'om_etat');
151     $res= $f-> db -> autoExecute(DB_PREFIXE.'om_etat',$etat,DB_AUTOQUERY_INSERT);
152     if (database::isError($res))
153     die($res->getDebugInfo()." => echec requete insertion etat");
154     else
155     echo $obj." "._("enregistre");
156     echo "</fieldset>";
157     }
158     ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26