|
| 1 | +#!/usr/bin/perl |
| 2 | +# |
| 3 | +=head1 NAME |
| 4 | +
|
| 5 | +formVEHICLES.pl |
| 6 | +
|
| 7 | +=head1 SYNOPSIS |
| 8 | +
|
| 9 | +http://..../formVEHICLES?[id=] |
| 10 | +
|
| 11 | +=head1 DESCRIPTION |
| 12 | +
|
| 13 | +Ce script permet l'affichage du formulaire d'édition d'un enregistrement des donnéeses journaux de bord |
| 14 | +des vehicules de l'OVPF |
| 15 | + |
| 16 | +=head1 Configuration VEHICLES |
| 17 | +
|
| 18 | +Voir 'showVEHICLES.pl' pour un exemple de fichier de configuration 'VEHICLES.conf' |
| 19 | +
|
| 20 | +=head1 Query string parameter |
| 21 | +
|
| 22 | +=over |
| 23 | +
|
| 24 | +=item B<id=> |
| 25 | +
|
| 26 | +numéro d'enregistrement à éditer. Si non fourni, on suppose la création d'un nouvel enregistrement. |
| 27 | +
|
| 28 | +=back |
| 29 | +
|
| 30 | +=cut |
| 31 | + |
| 32 | +use strict; |
| 33 | +use warnings; |
| 34 | +use Time::Local; |
| 35 | +use POSIX qw/strftime/; |
| 36 | +use File::Basename; |
| 37 | +use CGI; |
| 38 | +my $cgi = new CGI; |
| 39 | +use CGI::Carp qw(fatalsToBrowser set_message); |
| 40 | +set_message(\&webobs_cgi_msg); |
| 41 | + |
| 42 | +# ---- webobs stuff |
| 43 | +use WebObs::Config; |
| 44 | +use WebObs::Users qw($CLIENT %USERS clientHasRead clientHasEdit clientHasAdm); |
| 45 | +use WebObs::Grids; |
| 46 | +use WebObs::Utils; |
| 47 | +use WebObs::i18n; |
| 48 | +use Locale::TextDomain('webobs'); |
| 49 | +use WebObs::Form; |
| 50 | + |
| 51 | +# ---- standard FORMS inits ---------------------------------- |
| 52 | + |
| 53 | +die "You can't edit VEHICLES reports." if (!clientHasEdit(type=>"authforms",name=>"VEHICLES")); |
| 54 | + |
| 55 | +my $FORM = new WebObs::Form('VEHICLES'); |
| 56 | +my %Ns; |
| 57 | +my @NODESSelList; |
| 58 | +my %Ps = $FORM->procs; |
| 59 | +for my $p (keys(%Ps)) { |
| 60 | + my %N = $FORM->nodes($p); |
| 61 | + for my $n (keys(%N)) { |
| 62 | + push(@NODESSelList,"$n|$N{$n}{ALIAS}: $N{$n}{NAME}"); |
| 63 | + } |
| 64 | + %Ns = (%Ns, %N); |
| 65 | +} |
| 66 | + |
| 67 | +my $titrePage = "Édition - ".$FORM->conf('TITLE'); |
| 68 | + |
| 69 | +my $QryParm = $cgi->Vars; |
| 70 | + |
| 71 | +# --- DateTime inits ------------------------------------- |
| 72 | +my $Ctod = time(); my @tod = localtime($Ctod); |
| 73 | +my $sel_jour = strftime('%d',@tod); |
| 74 | +my $sel_mois = strftime('%m',@tod); |
| 75 | +my $sel_annee = strftime('%Y',@tod); |
| 76 | +my $anneeActuelle = strftime('%Y',@tod); |
| 77 | +my $sel_hr = ""; |
| 78 | +my $sel_mn = ""; |
| 79 | +my $today = strftime('%F',@tod); |
| 80 | + |
| 81 | +# ---- specific FORM inits ----------------------------------- |
| 82 | +my @html; |
| 83 | +my $affiche; |
| 84 | +my $s; |
| 85 | + |
| 86 | +my @types = readCfgFile($FORM->path."/".$FORM->conf('FILE_TYPE')); |
| 87 | + |
| 88 | +$ENV{LANG} = $WEBOBS{LOCALE}; |
| 89 | + |
| 90 | +# ---- |
| 91 | +my $sel_type = "PRO"; |
| 92 | +my ($sel_vehicle,$sel_mileage,$sel_site,$sel_driver,$sel_oil); |
| 93 | +$sel_vehicle = $sel_mileage = $sel_site = $sel_driver = $sel_oil = ""; |
| 94 | + |
| 95 | +# ---- Variables des menus |
| 96 | +my @anneeListe = ($FORM->conf('BANG')..$anneeActuelle); |
| 97 | +my @moisListe = ('01'..'12'); |
| 98 | +my @jourListe = ('01'..'31'); |
| 99 | +my @heureListe = ("",'00'..'23'); |
| 100 | +my @minuteListe= ("",'00'..'59'); |
| 101 | + |
| 102 | +# ---- Debut de l'affichage HTML |
| 103 | +# |
| 104 | +print "Content-type: text/html\n\n"; |
| 105 | +print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', "\n"; |
| 106 | + |
| 107 | +print "<html><head> |
| 108 | +<title>$titrePage</title>\n |
| 109 | +<link rel=\"stylesheet\" type=\"text/css\" href=\"/$WEBOBS{FILE_HTML_CSS}\">\n</head>\n |
| 110 | +<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">\n |
| 111 | +<script language=\"javascript\" type=\"text/javascript\" src=\"/js/jquery.js\"></script> |
| 112 | +<script type=\"text/javascript\"> |
| 113 | +<!-- |
| 114 | +
|
| 115 | +function verif_formulaire() |
| 116 | +{ |
| 117 | + if(document.formulaire.site.value == \"\") { |
| 118 | + alert(\"Veuillez spécifier le site de prélèvement!\"); |
| 119 | + document.formulaire.site.focus(); |
| 120 | + return false; |
| 121 | + } |
| 122 | + if(document.formulaire.type.value == \"\") { |
| 123 | + alert(\"Veuillez entrer un type d'ampoule!\"); |
| 124 | + document.formulaire.type.focus(); |
| 125 | + return false; |
| 126 | + } |
| 127 | + \$.post(\"/cgi-bin/".$FORM->conf('CGI_POST')."\", \$(\"#theform\").serialize(), function(data) { |
| 128 | + //var contents = \$( data ).find( '#contents' ).text(); |
| 129 | + alert(data); |
| 130 | + document.location=\"/cgi-bin/".$FORM->conf('CGI_SHOW')."\"; |
| 131 | + } |
| 132 | + ); |
| 133 | +} |
| 134 | +
|
| 135 | +function calc() |
| 136 | +{ |
| 137 | +} |
| 138 | +window.captureEvents(Event.KEYDOWN); |
| 139 | +window.onkeydown = nicb(); |
| 140 | +//--> |
| 141 | +</script> |
| 142 | +
|
| 143 | +</head> |
| 144 | +<body style=\"background-color:#E0E0E0\" onLoad=\"calc()\">"; |
| 145 | + |
| 146 | +print <<"FIN"; |
| 147 | +<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div> |
| 148 | +<script language="JavaScript" src="/js/overlib/overlib.js"></script> |
| 149 | +<!-- overLIB (c) Erik Bosrup --> |
| 150 | +<DIV ID="helpBox"></DIV> |
| 151 | +<!-- Pour empêcher que la touche ENTER valide le formulaire --> |
| 152 | +<script type="text/javascript"> |
| 153 | +function stopRKey(evt) { |
| 154 | + var evt = (evt) ? evt : ((event) ? event : null); |
| 155 | + var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); |
| 156 | + if ((evt.keyCode == 13) && (node.type=="text")) {return false;} |
| 157 | +} |
| 158 | +document.onkeypress = stopRKey; |
| 159 | +</script> |
| 160 | +FIN |
| 161 | + |
| 162 | +# ---- read data file |
| 163 | +# |
| 164 | +my $message = "Saisie de nouvelles données"; |
| 165 | +my @ligne; |
| 166 | +my $ptr=''; |
| 167 | +my $fts-1; |
| 168 | +my ($id,$date,$heure,$vehicle,$mileage,$type,$site,$driver,$oil) = split(/\|/,$_); |
| 169 | +if (defined($QryParm->{id})) { |
| 170 | + ($ptr, $fts) = $FORM->data($QryParm->{id}); |
| 171 | + @ligne = @$ptr; |
| 172 | + if (scalar(@ligne) == 1) { |
| 173 | + chomp(@ligne); |
| 174 | + ($id,$date,$heure,$vehicle,$mileage,$type,$site,$driver,$oil) = split (/\|/,l2u($ligne[0])); |
| 175 | + if ($QryParm->{id} eq $id) { |
| 176 | + ($sel_annee,$sel_mois,$sel_jour) = split (/-/,$date); |
| 177 | + ($sel_hr,$sel_mn) = split (/:/,$heure); |
| 178 | + $sel_vehicle = $vehicle; |
| 179 | + $sel_mileage = $mileage; |
| 180 | + $sel_type = $type; |
| 181 | + $sel_site = $site; |
| 182 | + $sel_driver = $driver; |
| 183 | + $sel_oil = $oil; |
| 184 | + $message = "Modification donnée n° $QryParm->{id}"; |
| 185 | + } else { $QryParm->{id} = ""; } |
| 186 | + } else { $QryParm->{id} = ""; } |
| 187 | +} |
| 188 | + |
| 189 | +print "<TABLE width=\"100%\"><TR><TD style=\"border:0\"> |
| 190 | +<H1>$titrePage</H1>\n<H2>$message</H2> |
| 191 | +</TD><TD style=\"border:0; text-align:right\">"; |
| 192 | +print "</TD></TR></TABLE>"; |
| 193 | + |
| 194 | +print "<FORM name=formulaire id=\"theform\" action=\"\">"; |
| 195 | +if ($QryParm->{id} ne "") { |
| 196 | + print "<input type=\"hidden\" name=\"id\" value=\"$QryParm->{id}\">"; |
| 197 | +} |
| 198 | + |
| 199 | +print "<input type=\"hidden\" name=\"oper\" value=\"$CLIENT\">\n"; |
| 200 | + |
| 201 | +print "<TABLE style=border:0 onMouseOver=\"calc()\">"; |
| 202 | +print "<TR>"; |
| 203 | +print "<TD style=border:0 valign=top> |
| 204 | + <fieldset><legend>Date et lieu du déplacement</legend> |
| 205 | + <P class=parform> |
| 206 | + <B>Date: </b><select name=annee size=\"1\">"; |
| 207 | + for (@anneeListe) { |
| 208 | + if ($_ == $sel_annee) { print "<option selected value=$_>$_</option>"; } else { print "<option value=$_>$_</option>"; } |
| 209 | + } |
| 210 | + print "</select>"; |
| 211 | + print " <select name=mois size=\"1\">"; |
| 212 | + for (@moisListe) { |
| 213 | + if ($_ == $sel_mois) { print "<option selected value=$_>$_</option>"; } else { print "<option value=$_>$_</option>"; } |
| 214 | + } |
| 215 | + print "</select>"; |
| 216 | + print " <select name=jour size=\"1\">"; |
| 217 | + for (@jourListe) { |
| 218 | + if ($_ == $sel_jour) { print "<option selected value=$_>$_</option>"; } else { print "<option value=$_>$_</option>"; } |
| 219 | + } |
| 220 | + print "</select>"; |
| 221 | + |
| 222 | + print " <b>Heure: </b><select name=hr size=\"1\">"; |
| 223 | + for (@heureListe) { |
| 224 | + if ($_ eq $sel_hr) { print "<option selected value=$_>$_</option>"; } else { print "<option value=$_>$_</option>"; } |
| 225 | + } |
| 226 | + print "</select>"; |
| 227 | + print " <select name=mn size=\"1\">"; |
| 228 | + for (@minuteListe) { |
| 229 | + if ($_ eq $sel_mn) { |
| 230 | + print "<option selected value=$_>$_</option>"; |
| 231 | + } else { |
| 232 | + print "<option value=$_>$_</option>"; |
| 233 | + } |
| 234 | + } |
| 235 | + print "</select><BR>"; |
| 236 | + |
| 237 | + print "<B>Véhicule: </B><select onMouseOut=\"nd()\" onmouseover=\"overlib('Selectionner le vehicule')\" name=\"vehicle\" size=\"1\"><option value=\"\"></option>"; |
| 238 | + for (@NODESSelList) { |
| 239 | + my @cle = split(/\|/,$_); |
| 240 | + if ($cle[0] eq $sel_site) { |
| 241 | + print "<option selected value=$cle[0]>$cle[1]</option>"; |
| 242 | + } else { |
| 243 | + print "<option value=$cle[0]>$cle[1]</option>"; |
| 244 | + } |
| 245 | + } |
| 246 | + print "</select><BR>\n"; |
| 247 | + |
| 248 | + print "<B>Lieu: </B><input size=30 name=\"site\" value=\"$sel_site\" onMouseOut=\"nd()\" onmouseover=\"overlib('Entrer le lieu du déplacement')\"><BR>\n"; |
| 249 | + print "</P>"; |
| 250 | + print "</fieldset>"; |
| 251 | + |
| 252 | + print "<fieldset><legend>Informations sur le déplacement</legend>\n |
| 253 | + <P class=parform>"; |
| 254 | + print "<B>Type de déplacement: </B><select onMouseOut=\"nd()\" onmouseover=\"overlib('Sélectionner le type e déplacement')\" name=\"type\" size=\"1\"><option value=\"\"></option>"; |
| 255 | + for (@types) { |
| 256 | + my @cle = split(/\|/,$_); |
| 257 | + print "<option"; |
| 258 | + if ($cle[0] eq $sel_type) { |
| 259 | + print " selected"; |
| 260 | + } |
| 261 | + print " value=$cle[0]>$cle[1]</option>"; |
| 262 | + } |
| 263 | + print "</select><BR/>"; |
| 264 | + print " <B>Conducteur: <input size=30 name=\"driver\" value=\"$driver\" onMouseOut=\"nd()\" onmouseover=\"overlib('Entrer le nom du conducteur')\"><BR>\n |
| 265 | + <B>Kilomètre au compteur</B> = <input size=10 class=inputNum name=\"mileage\" value=\"$mileage\" onKeyUp=\"nicb()\" onChange=\"nicb()\" onMouseOut=\"nd()\" onmouseover=\"overlib('Entrer la valeur du compteur')\"> km<BR>\n |
| 266 | + <B>Carburant</B> = <input size=5 class=inputNum name=\"oil\" value=\"$oil\" onKeyUp=\"nicb()\" onChange=\"nicb()\" onMouseOut=\"nd()\" onmouseover=\"overlib('Entrer la valeur du plein')\">€<BR>\n"; |
| 267 | +# print "<B>Débit </B> (qualitatif) = <select onMouseOut=\"nd()\" onmouseover=\"overlib('Sélectionner le débit')\" name=\"debit\" size=\"1\"><option value=\"\"></option>"; |
| 268 | +# print "</select>\n"; |
| 269 | + print "</fieldset>"; |
| 270 | +print "</TD>"; |
| 271 | +#print "<TR>"; |
| 272 | +#print "<TD style=border:0 colspan=2>"; |
| 273 | +# print "<B>Observations</B> : <BR><input size=80 name=rem value=\"$sel_rem\" onMouseOut=\"nd()\" onmouseover=\"overlib('Noter la phénoménologie (dépôts, couleur, etc...)')\"><BR>"; |
| 274 | +# if ($val ne "") { |
| 275 | +# print "<BR><B>Information de saisie:</B> $val |
| 276 | +# <INPUT type=hidden name=val value=\"$val\"></P>"; |
| 277 | +# } |
| 278 | +print "</TR><TR>"; |
| 279 | +print "<TD style=border:0 colspan=2>"; |
| 280 | +print "<P style=\"margin-top:20px;text-align:center\">"; |
| 281 | +print "<input type=\"button\" name=lien value=\"Annuler\" onClick=\"document.location='/cgi-bin/".$FORM->conf('CGI_SHOW')."'\" style=\"font-weight:normal\">"; |
| 282 | +print "<input type=\"button\" value=\"Soumettre\" onClick=\"verif_formulaire();\">"; |
| 283 | +print "</P></TABLE>"; |
| 284 | +print "</FORM>"; |
| 285 | + |
| 286 | +# Fin de la page |
| 287 | +# |
| 288 | +print "\n</BODY>\n</HTML>\n"; |
| 289 | + |
| 290 | +__END__ |
| 291 | +
|
| 292 | +=pod |
| 293 | +
|
| 294 | +=head1 AUTHOR(S) |
| 295 | +
|
| 296 | +Francois Beauducel, Didier Lafon, Patrice Boissier |
| 297 | +
|
| 298 | +=head1 COPYRIGHT |
| 299 | +
|
| 300 | +Webobs - 2012-2014 - Institut de Physique du Globe Paris |
| 301 | +
|
| 302 | +This program is free software: you can redistribute it and/or modify |
| 303 | +it under the terms of the GNU General Public License as published by |
| 304 | +the Free Software Foundation, either version 3 of the License, or |
| 305 | +(at your option) any later version. |
| 306 | +
|
| 307 | +This program is distributed in the hope that it will be useful, |
| 308 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 309 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 310 | +GNU General Public License for more details. |
| 311 | +
|
| 312 | +You should have received a copy of the GNU General Public License |
| 313 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 314 | +
|
| 315 | +=cut |
| 316 | +
|
0 commit comments