/trunk/api/formulaire/FORM_formulaire.class.php |
---|
New file |
0,0 → 1,348 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of API - Formulaire. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: FORM_formulaire.class.php,v 1.4 2005/04/06 13:22:17 jpm Exp $ |
/** |
* Classe form |
* |
* Classe permettant l'édition d'une base donnée MySQL de façon |
* simplifié. |
* |
*@package Formulaire |
//Auteur original : |
*@author Alexandre GRANIER <alexandre@tela-botanica.org> |
//Autres auteurs : |
*@author Jean-Pascal MILCENT <jpm@clapas.org> |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.4 $ $Date: 2005/04/06 13:22:17 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
class form { |
// propriétés |
var $link; |
var $style_general; |
var $style_label; |
var $style_champ; |
var $style_button; |
var $style_radiocheckbox; |
var $style_commentaire; |
// constructeur |
function form($identifiant_de_connection) |
{ |
$this->link = $identifiant_de_connection; |
} |
function select_db($db) |
{ |
mysql_select_db($db, $this->link) or die (BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $db)); |
} |
function selectFromEnum($table, $champs_enum, $selected = '') |
{ |
// recup des différentes occurences |
$query = 'DESCRIBE '.$table; |
$result = mysql_query($query) or die (BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
while ($row = mysql_fetch_object($result)) { |
if ($row->Field == $champs_enum) { |
break; |
} |
} |
$tableau_enum = form::_extraction('enum', $row->Type); |
// construction du select |
$res = '<select name="'.$champs_enum.'" '; |
if ($this->style_general != '') { |
$res .= 'class="'.$this->style_general.'"'; |
} |
$res .= '>'."\n"; |
for ($i = 0 ; $i < count ($tableau_enum) ; $i++) { |
$res .= "\t".'<option value="'.$tableau_enum[$i].'"'; |
if ($selected != '') { |
if ($tableau_enum[$i] == $selected) { |
$res .= 'selected'; |
} |
} |
$res .= '>'.$tableau_enum[$i].'</option>'."\n"; |
} |
$res .= '</select>'."\n"; |
mysql_free_result($result); |
return $res; |
} |
// Pour une table ne comportant que 2 champs ID et Label |
function selectFromTable($table, $selected = '',$champs1 = '',$champs2 = '', $autre = '') |
{ |
// la requete, sur la table |
if ($champs1 != '') { |
$query = 'SELECT '.$table.'.'.$champs1.', '.$table.'.'.$champs2.' '. |
'FROM '.$table; |
} else { |
$query = 'SELECT * '. |
'FROM '.$table; |
} |
if (!($result = mysql_query($query))) { |
return false ; |
} |
$res = '<select name="'.$table.'" '; |
if ($this->style_general != '') { |
$res .= 'class="'.$this->style_general.'"'; |
} |
if ($autre != '') { |
$res .= ' '.$autre; |
} |
$res .= '>'."\n"; |
while ($row = mysql_fetch_row($result)) { |
$res .= "\t".'<option value="'.$row[0].'"'; |
if ($row[0] == $selected) { |
$res .= ' selected="selected"'; |
} |
$res .= '>'.$row[1].'</option>'."\n"; |
} |
$res .= '</select>'."\n"; |
mysql_free_result($result) ; |
return $res ; |
} |
// Génère un <select> avec les elements d'un tableau |
function selectFromTableau($nom, $tableau, $selected = '', $javascript = array()) |
{ |
$res = '<select name="'.$nom.'" '; |
if ($this->style_general != '') { |
$res .= 'class="'.$this->style_general.'" '; |
} |
if (! empty($javascript)) { |
$res .= $javascript['nom_evenement'].'="'.$javascript['valeur_evenement'].'"'; |
} |
$res .= '>'."\n"; |
for ($i = 0 ; $i < count ($tableau) ; $i++) { |
$res .= "\t".'<option value="'.$tableau[$i].'" '; |
if ($tableau[$i] == $selected) { |
$res .= 'selected="selected"'; |
} |
$i++; |
$res .= '>'.$tableau[$i].'</option>'."\n"; |
} |
$res .= '</select>'."\n"; |
return $res; |
} |
function radioFromEnum($table, $champs_enum, $enum_checked = '') |
{ |
// Récupération des différentes occurences |
$query = 'DESCRIBE '.$table; |
$result = mysql_query($query) or die (BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
while ($row = mysql_fetch_object($result)) { |
if ($row->Field == $champs_enum) { |
break; |
} |
} |
$tableau_enum = form::_extraction('enum', $row->Type); |
// Construction du select |
$res = ''; |
for ($i = 0 ; $i < count ($tableau_enum) ; $i++) { |
$res .= '<input '; |
if ($this->style_radiocheckbox != '') { |
$res .= 'class="'.$this->style_radiocheckbox.'" '; |
} |
$res .= 'type="radio" name="'.$champs_enum.'" value="'.$tableau_enum[$i].'" '; |
if ($tableau_enum[$i] == $enum_checked) { |
$res .= ' checked="checked"'; |
} |
$res .= ' />'."\n"; |
$res .= "\t\t".$tableau_enum[$i]."\n"; |
$res .= "\t".' '."\n"; |
} |
mysql_free_result($result); |
return $res; |
} |
// pour une table ne comportant que 2 champs ID et Label |
function radioFromTable($table, $idChecked = '', $champs1 = '', $champs2 = '', $name = '') |
{ |
// La requete, sur la table |
$requete = 'SELECT * '. |
'FROM '.$table; |
$resultat = mysql_query($requete) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $requete)); |
if (!($resultat)) { |
return false; |
} |
$retour = ''; |
while ($ligne = mysql_fetch_row($resultat)) { |
$retour .= '<input '; |
if ($this->style_radiocheckbox != '') { |
$retour .= 'class="'.$this->style_radiocheckbox.'" '; |
} |
$retour .= 'type="radio" name="'; |
if ($name != '') { |
$retour .= $name; |
} else { |
$retour .= $table; |
} |
$retour .= '" value="'.$ligne[0].'" '; |
if ($ligne[0]== $idChecked) { |
$retour .= 'checked="checked" '; |
} |
$retour .= ' />'."\n"; |
$retour .= "\t".' '."\t".$ligne[1]."\n"; |
$retour .= "\t".' <br />'."\n"; |
} |
mysql_free_result($resultat); |
return $retour; |
} |
function checkboxFromTable($table_jointure, $table_label, $idChecked, $presentation = 'LIGNE') |
{ |
// la requete sur les tables |
if (empty($idChecked)) { |
$idChecked = array(); |
} |
$query = 'SELECT * '. |
'FROM '.$table_label; |
$result = mysql_query($query) or die (BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
if (!($result)) { |
return false; |
} |
$res = ''; |
while ($row = mysql_fetch_row($result)) { |
$res .= "\n".'<input type="checkbox" name="'.$table_label.$row[0].'" value="'.$row[0].'"'; |
if (in_array($row[0], $idChecked)) { |
$res .= ' checked="checked"'; |
} |
$res .= ' />'.$row[1]; |
if ($presentation == 'LIGNE') { |
$res .= '<br />'; |
} |
} |
return $res; |
} |
function checkboxFromSet($table, $champs, $set_checked = '') |
{ |
if (empty($set_checked)) { |
$set_checked = array(); |
} |
// Récupération des différentes occurences |
$query = 'DESCRIBE '.$table; |
$result = mysql_query($query) or die (BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
while ($row = mysql_fetch_object($result)) { |
if ($row->Field == $champs) { |
break; |
} |
} |
$tableau_enum = form::_extraction('set', $row->Type); |
for ($i = 0 ; $i < count($tableau_enum) ; $i++) { |
// Construction du des checkbox |
$res = '<input type="checkbox" name="'.$champs.'" '; |
if ($this->style_general != '') { |
$res .= 'class="'.$this->style_general.'" '; |
} |
$res .= 'value="'.$tableau_enum[$i].'" '; |
if (in_array($tableau_enum[$i], $set_checked)) { |
$res .= 'selected="selected"'; |
} |
$res .= ' />'.$tableau_enum[$i].' '; |
} |
mysql_free_result($result); |
return $res; |
} |
function submit($value, $name = '', $autre = '') |
{ |
$res = '<input '; |
if ($name != '') { |
$res .= 'name="'.$name.'" '; |
} |
$res .= 'type="submit" value="'.$value.'" class="'.$this->style_button.'" '; |
if ($autre != '') { |
$res .= $autre; |
} |
$res .= ' />'."\n"; |
return $res; |
} |
function bouton($label, $style = '', $name = 'bouton', $autre = '') |
{ |
$res = "\t".'<input type="submit" name="'.$name.'" value="'.$label.'" '; |
if ($style != '') { |
$res .= 'class="'.$style.'"'; |
} |
if ($autre != '') { |
$res .= ' '.$autre; |
} |
$res .= ' />'."\n"; |
return $res; |
} |
function _extraction($action, $chaine) |
{ |
$regexp = '^'.$action.'\('; |
$chaine = ereg_replace($regexp, '', $chaine); |
$chaine = ereg_replace("\)$", '', $chaine); |
$chaine = ereg_replace("'", '', $chaine); |
$tableau_enum = explode(',', $chaine); |
return $tableau_enum; |
} |
} |
// +------------------------------------------------------------------------------------------------------+ |
// | PIED du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: FORM_formulaire.class.php,v $ |
* Revision 1.4 2005/04/06 13:22:17 jpm |
* Corrections et ajout d'id aux champs des formulaires. |
* |
* Revision 1.3 2005/03/30 09:06:26 jpm |
* Mise en conformité du code. |
* |
* Revision 1.2 2005/03/08 11:29:51 jpm |
* Amélioration du code. |
* |
* Revision 1.1 2005/03/03 17:44:44 jpm |
* Ajout des fichiers anciennement contenu dans le fichier lib.form.php. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |
/trunk/api/formulaire/formulaire.class.inc.php |
---|
23,7 → 23,7 |
/** |
* Formulaire |
* |
* Classe générique pour créer des formulaires |
* Classe générique pour créer des formulaires |
* |
*@package Formulaire |
//Auteur original : |
67,7 → 67,7 |
* Constructeur |
* |
* @param string formName Le nom du formulaire |
* @param string method Méthode post ou get |
* @param string method Méthode post ou get |
* @param string action L'action du formulaire. |
* @param int target La cible. |
* @param Array attributes Les attributs HTML en plus. |
/trunk/api/formulaire/FORM_formulaire_table.class.php |
---|
New file |
0,0 → 1,740 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2005 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of API - Formulaire. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// | GNU General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: FORM_formulaire_table.class.php,v 1.4 2005/06/29 16:59:05 jpm Exp $ |
/** |
* Classe formFromTable étendant form |
* |
* Classe permettant l'édition d'une table d'une base donnée MySQL de façon |
* simplifié. |
* |
*@package Formulaire |
//Auteur original : |
*@author Alexandre GRANIER <alexandre@tela-botanica.org> |
//Autres auteurs : |
*@author Jean-Pascal MILCENT <jpm@clapas.org> |
*@copyright Tela-Botanica 2000-2005 |
*@version $Revision: 1.4 $ $Date: 2005/06/29 16:59:05 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
// +------------------------------------------------------------------------------------------------------+ |
// | ENTETE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
define ('NOUVELLE_LIGNE', 1); |
define ('MEME_LIGNE', 2); |
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
class formFromTable extends form { |
// Le nom de la table |
var $table; |
var $tableau_type; |
var $ligne; |
var $champs; |
var $mode; |
// L'identifiant de la ligne en cas de modification |
var $id; |
var $cle; |
// Les valeurs par defaut |
var $default_value; |
// Tableau contenant les jointures |
var $jointure; |
var $champs1; |
var $champs2; |
var $champs3; |
// Un compteur pour différencier les jointures portant sur une meme table |
var $compteur; |
function formFromTable($link, $table, $mode = 'NOUV', $id = '', $cle = '') |
{ |
$this->link = $link; |
$this->table = $table; |
$this->form = ''; |
$this->ligne = array(); |
$this->champs = array(); |
$this->jointure = array(); |
$this->mode = $mode; |
$this->id = $id; |
$this->cle = $cle; |
$this->default_value = array(); |
$this->champs1 = array(); |
$this->champs2 = array(); |
$this->champs3 = array(); |
$this->compteur = 0; |
// Style |
$this->style_general = 'formulaire'; |
$this->style_label = 'label'; |
$this->style_champ = 'champ'; |
$this->style_button = 'bouton'; |
$this->style_commentaire = 'commentaire'; |
$this->style_radiocheckbox = 'radio'; |
// requete pour recuperer les types de champs dans le tableau ; |
$query = 'DESCRIBE '.$this->table; |
if (!($result = mysql_query($query))) { |
return false ; |
} |
while ($row = mysql_fetch_object($result)) { |
$this->tableau_type[$row->Field] = $row->Type; |
// on definit les index pour eviter les notices... |
$this->default_value[$row->Field] = $row->Default; |
$this->jointure[$row->Field] = ''; |
} |
foreach ($this->tableau_type as $key => $value) { |
$radical = $this->_extraitRadical($value); |
switch ($radical) { |
case 'char' : |
case 'varchar' : |
case 'smallint' : |
case 'int' : |
$this->tableau_type[$key] = $this->_estimation_taille($this->_extraitTaille($value)); |
break; |
case 'text' : |
$this->tableau_type[$key] = 'text'; |
break; |
case 'enum' : |
$this->tableau_type[$key] = 'enum'; |
break; |
case 'date' : |
$this->tableau_type[$key] = 'date'; |
break; |
case 'set' : |
$this->tableau_type[$key] = 'set'; |
break; |
} |
} |
// on recupere les infos dans le cas d'une modification |
// notons que les valeurs par défaut initialisé plus haut à partir de la table SQL |
// sont écrasées. |
if ($this->mode == 'MOD') { |
$query = 'SELECT * '. |
'FROM '.$this->table.' '. |
'WHERE '.$this->cle.' = "'.$this->id.'"'; |
$result = mysql_query($query) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
$this->default_value = mysql_fetch_array($result); |
} |
} |
// Ajouter un champ pour le formumaire nom_du_champs, label_a_mettre_devant |
function addChamps($name, $label, $default = '', $type = 'text', $presentation = NOUVELLE_LIGNE) |
{ |
array_push($this->ligne, $label); |
array_push($this->champs, $name); |
switch($this->tableau_type[$name]) { |
case 'text' : |
$this->textarea($name); |
break; |
case 'enum' : |
$this->enum($name); |
break; |
case 'date' : |
$this->date($name, $presentation); |
break; |
case 'set' : |
$this->set($name); |
break; |
default : |
$this->input($name, $default, $type, $presentation); |
} |
} |
function textarea($name) |
{ |
$code = '<textarea id="'.$name.'" name="'.$name.'" class="'.$this->style_general.'" cols="60" rows="5">'; |
$code .= $this->default_value[$name]; |
$code .= '</textarea>'."\n"; |
array_push($this->ligne, $code); |
} |
function input($name,$default, $type = 'text', $presentation = NOUVELLE_LIGNE) { |
if (!empty($default) and $this->mode != 'MOD') { |
$this->default_value[$name] = $default; |
} |
$code = '<input type="'.$type.'" id="'.$name.'" name="'.$name.'" size="'.$this->tableau_type[$name].'" class="'.$this->style_general.'" '; |
$code .= 'value="'; |
if ($this->mode == 'MOD' and $type == 'password') { |
} else { |
$code .= htmlentities($this->default_value[$name]); |
} |
$code .= '" />'."\n"; |
if ($presentation == MEME_LIGNE) { |
// cette feinte ajoute le ! au début de la chaine du dernier élément du tableau $this->ligne |
array_push($this->ligne, '!'.array_pop($this->ligne)); |
} |
array_push($this->ligne, $code); |
} |
function date($name, $presentation = NOUVELLE_LIGNE) { |
if ($this->default_value[$name] != '') { |
$this->default_value[$name] = preg_replace("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", "\\3-\\2-\\1", $this->default_value[$name]); |
} |
$code = '<input type="text" id="'.$name.'" name="'.$name.'" size="12" class="'.$this->style_general.'" '; |
$code .= 'value="'.$this->default_value[$name].'" />'; |
if ($presentation == MEME_LIGNE) { |
// cette feinte ajoute le ! au début de la chaine du dernier élément du tableau $this->ligne |
array_push($this->ligne, '!'.array_pop($this->ligne)); |
} |
array_push($this->ligne, $code); |
} |
function submit($label,$name = '', $autre = '') |
{ |
array_push($this->ligne, form::submit($label, $name, $autre)) ; |
} |
function annuler($label, $fonction = '') |
{ |
$code = '<input type="button" id="annu" name="annu" class="'.$this->style_button.'" value="'.$label.'" '; |
$code .= 'onclick="javascript:window.location.href=\''.$fonction.'\';" />'."\n"; |
array_push($this->ligne, $code) ; |
} |
function printForm($action, $autre = '', $format = 'table') |
{ |
//Création du formulaire et de sa structure |
$res = '<form id="'.$this->table.'" action="'.$action.'" method="post" '; |
if ($autre != '') { |
$res .= ' '.$autre; |
} |
$res .= '>'."\n"; |
if ($format == 'table') { |
$res .= '<table class="'.$this->style_general.'">'."\n"; |
$colspan = $this->getMaxColonne() * 2; |
} elseif ($format == 'liste') { |
$res .= '<ul class="'.$this->style_general.'">'."\n"; |
} |
// Ajout des champs du formulaire |
for ($i = 0; $i < count($this->ligne); $i = $i + 2) { |
// Ajout du bouton de validation du formulaire |
if (ereg('submit', $this->ligne[$i])) { |
if ($format == 'table') { |
$res .= '<tr><td> </td><td>'; |
} elseif ($format == 'liste') { |
$res .= '<li>'; |
} |
$res .= $this->ligne[$i]."\n"; |
if (isset($this->ligne[$i+1])) { |
$res .= $this->ligne[$i+1]; |
} |
if ($format == 'table') { |
$res .= '</td></tr>'; |
} elseif ($format == 'liste') { |
$res .= '</li>'."\n"; |
} |
$i--; |
break; |
} |
// Ajout de commentaire |
if (ereg('^#', $this->ligne[$i])) { |
if ($format == 'table') { |
$res .= '<tr><td colspan="'.($colspan + 2).'" '; |
} elseif ($format == 'liste') { |
$res .= '<li '; |
} |
// Suppression du premier # |
$this->ligne[$i] = ereg_replace('^#', '', $this->ligne[$i]); |
if (ereg('#', $this->ligne[$i])) { |
$tableau = explode('#', $this->ligne[$i]); |
$style = $tableau[1]; |
$this->ligne[$i] = $tableau[0]; |
} else { |
$style = $this->style_commentaire; |
} |
$res .= 'class="'.$style.'">'; |
$res .= $this->ligne[$i]; |
if ($format == 'table') { |
$res .= '</td></tr>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '</li>'."\n"; |
} |
$i--; |
continue; |
} |
if (ereg('^!', $this->ligne[$i])) { |
if ($format == 'table') { |
$res .= '<tr>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '<li>'."\n"; |
} |
do { |
if ($format == 'table') { |
$res .= '<td class="'.$this->style_label.'">'.ereg_replace("^!", '', $this->ligne[$i]).'</td>'."\n"; |
$res .= '<td class="'.$this->style_commentaire.'">'.$this->ligne[$i + 1].'</td>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '<td class="'.$this->style_label.'">'.ereg_replace("^!", '', $this->ligne[$i]).'</td>'."\n"; |
$res .= '<td class="'.$this->style_commentaire.'">'.$this->ligne[$i + 1].'</td>'."\n"; |
} |
$i += 2; |
} while (ereg('^!', $this->ligne[$i - 2])); |
if ($format == 'table') { |
$res .= '</tr>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '</li>'."\n"; |
} |
$i -= 2;// on est allé trop loin donc un revient sur nos pas |
continue; |
} |
// Ajout du label |
if ($format == 'table') { |
$res .= '<tr><td '; |
if (isset($this->ligne[$i + 1])) { |
if (ereg('textarea', $this->ligne[$i + 1])) { |
$res .= 'valign="top" '; |
} |
} |
$res .= 'class="'.$this->style_label.'">'; |
} elseif ($format == 'liste') { |
$res .= '<li>'."\n"; |
} |
$res .= '<label>'.$this->ligne[$i].'</label>'; |
// Ajout champ |
if ($format == 'table') { |
$res .= '</td>'."\n"; |
$res .= '<td class="'.$this->style_radiocheckbox.'" colspan="'; |
$res .= $colspan + 1; |
$res .= '">'; |
} |
if (isset($this->ligne[$i + 1])) { |
$res .= $this->ligne[$i + 1]; |
} |
if ($format == 'table') { |
$res .= '</td>'."\n".'</tr>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '</li>'."\n"; |
} |
} |
// Affichage du champ caché contenant l'objet Form |
if ($format == 'table') { |
$res .= '<tr>'."\n".'<td> </td><td>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '<li>'."\n"; |
} |
$res .= $this->finalise($this->table); |
if ($format == 'table') { |
$res .= '</td>'."\n".'</tr>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '</li>'."\n"; |
} |
// Fin de la structure du formulaire |
if ($format == 'table') { |
$res .= '</table>'."\n"; |
} elseif ($format == 'liste') { |
$res .= '</ul>'."\n"; |
} |
$res .= '</form>'."\n"; |
return $res; |
} |
function addCommentaire($Commentaire, $style = '') |
{ |
$ligne = '#'.$Commentaire; |
if ($style != '') { |
$ligne .= '#'.$style; |
} |
array_push($this->ligne, $ligne); |
} |
function enum($name) |
{ |
array_push($this->ligne, form::selectFromEnum($this->table, $name, $this->default_value[$name])); |
} |
function set($name) |
{ |
array_push($this->ligne, form::checkboxFromSet($this->table, $name, explode(',', $this->default_value[$name]))); |
} |
function radio($name, $tableau, $label, $checked = '') |
{ |
array_push($this->ligne, $label); |
array_push($this->champs, $name); |
$code = ''; |
for ($i = 0; $i < count($tableau); $i = $i + 2) { |
$code .= '<input type="radio" id="'.$name.'" name="'.$name.'" value="'.$tableau[$i].'"'; |
if ($tableau[$i] == $this->default_value[$name]) { |
$code .= ' checked'; |
} |
$code .= ' />'; |
$code .= ' '.$tableau[$i + 1]; |
} |
array_push($this->ligne, $code); |
} |
function radioEnum($name, $label, $checked = '') |
{ |
array_push($this->ligne, $label); |
array_push($this->champs, $name); |
$code = form::radioFromEnum($this->table, $name, $this->default_value[$name]); |
array_push($this->ligne, $code); |
} |
function selectFromTable($table, $selected = '',$champs1 = '',$champs2 = '', $commentaire = '') |
{ |
if (ereg('(.*) par (.*)', $table, $str)) { |
$this->jointure[$str[2]] = $str[1]; |
$table = $str[2]; |
} |
if ($this->default_value[$str[1]] != '' and $selected == '') { |
$selected = $this->default_value[$str[1]]; |
} |
array_push($this->ligne, $commentaire); |
array_push($this->champs, $table); |
array_push($this->ligne,form::selectFromTable($table, $selected, $champs1, $champs2)); |
} |
function radioFromTable($table, $selected="", $commentaire="", $presentation = NOUVELLE_LIGNE) |
{ |
if (ereg('(.*) par (.*)', $table, $str)) { |
$this->jointure[$str[2].$this->compteur] = $str[1]; |
$table = $str[2]; |
} |
if ($this->default_value[$str[1]] != '') { |
$selected = $this->default_value[$str[1]]; |
} |
array_push($this->ligne, $commentaire); |
array_push($this->champs, $table.$this->compteur); |
if ($presentation == MEME_LIGNE) { |
// Cette feinte ajoute le ! au début de la chaine du dernier élément du tableau $this->ligne |
array_push($this->ligne, '!'.array_pop($this->ligne)); |
} |
array_push($this->ligne, form::radioFromTable($table, $selected, '', '', $table.$this->compteur)); |
$this->compteur++; |
} |
function checkboxFromTable($table, $commentaire, $idcheck, $presentation = 'LIGNE', $champs1 = '', $champs2 = '', $champs3 = '') |
{ |
if (ereg("(.*) par ((.*) et (.*))", $table, $str)) { |
$table = $str[1] ; |
$table_label = $str[4] ; |
$table_jointure = $str[3] ; |
$this->jointure[$table_label] = $str[2] ; |
$this->champs1[$table_label] = $champs1 ; |
$this->champs2[$table_label] = $champs2 ; |
$this->champs3[$table_label] = $champs3 ; |
} |
// tableau des valeurs par default |
if ($this->mode == 'MOD') { |
$idcheck = array() ; |
$query = 'SELECT * '. |
'FROM '.$table_jointure.' '. |
'WHERE '.$champs1.' = "'.$this->id.'"'; |
$result = mysql_query($query) or die ("Echec de la requête sur $table_jointure"); |
while ($row = mysql_fetch_array($result)) { |
array_push($idcheck, $row[$champs2]) ; |
} |
} |
array_push($this->ligne, $commentaire); |
array_push($this->ligne, form::checkboxFromTable('', $table_label, $idcheck, $presentation)); |
array_push($this->champs, $table_label) ; |
} |
// Cette methode serialize l'objet et l'ecrit dans un fichier temporaire |
function finalise($nom) |
{ |
$retour = '<input type="hidden" id="'.$nom.'" name="'.$nom.'" value="'.urlencode(serialize($this)).'" />'."\n"; |
return $retour; |
} |
function acquerir($nom) |
{ |
$retour = unserialize(urldecode($_POST[$nom])); |
return $retour; |
} |
/** Fonction insertMySQL () Insere les données d'un objet formFromTable dans la base associée |
* |
* @param string le fin d'une requete SQL d'insertion, du type CHAMPS="valeur",.... |
* @return integer L'identifiant d'insertion renvoyé par mysql_insert_id() |
*/ |
function insertMySQL($sql = '') |
{ |
$jointure_multiple = array(); |
$query = 'INSERT INTO '.$this->table.' '. |
'SET '; |
for($i = 0 ; $i < count($this->champs) ; $i++) { |
// Traitement des jointures |
if ($this->jointure[$this->champs[$i]] != '') { |
// Traitement des jointures a forte cardinalite |
if (ereg('(.*) et (.*)', $this->jointure[$this->champs[$i]], $str)) { |
array_push($jointure_multiple, $str[0]); |
// Suppression de la virgule finale |
//$query = ereg_replace (",$", "", $query) ; |
continue; |
} else { |
$val = $_POST[$this->champs[$i]]; |
$this->champs[$i] = $this->jointure[$this->champs[$i]]; |
$_POST[$this->champs[$i]] = $val; |
} |
} |
// Cas des dates |
if ($this->tableau_type[$this->champs[$i]] == 'date') { |
$_POST[$this->champs[$i]] = preg_replace("/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/", "\\3-\\2-\\1", $_POST[$this->champs[$i]]); |
} |
// Cas simple |
$champs = $this->champs[$i]; |
$query .= $this->champs[$i]; |
$query .= ' = '; |
if (empty($_POST[$champs])) { |
$_POST[$champs] = ''; |
} |
$query .= ' "'.$_POST[$champs].'" '; |
if ($i < (count($this->champs) - 1)) { |
$query .= ','; |
} |
} |
if ($sql != '') { |
$query .= ', '.$sql; |
} |
$query = ereg_replace(',,', ',', $query); |
mysql_query($query) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
$insert_id = mysql_insert_id(); |
// Traitement des jointures multiples |
if (count($jointure_multiple) > 0) { |
for ($i = 0 ; $i < count($jointure_multiple) ; $i++) { |
ereg('(.*) et (.*)', $jointure_multiple[$i], $str); |
$table_jointure = $str[1]; |
$table_label = $str[2]; |
$queryN = 'SELECT COUNT('.$this->champs3[$table_label].') AS nombre '. |
'FROM '.$table_label; |
$resultN = mysql_query($queryN) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $queryN)); |
$rowN = mysql_fetch_object($resultN); |
for ($j = 0 ; $j < $rowN->nombre ; $j++) { |
$nom = $table_label.$j; |
if (isset($_POST[$nom]) && $_POST[$nom] != '') { |
$queryM = 'INSERT INTO '.$table_jointure.' '. |
'SET '.$this->champs1[$table_label].' = '.$insert_id.', '.$this->champs2[$table_label].' = "'.$_POST[$nom].'"'; |
mysql_query($queryM) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $queryM)); |
} |
} |
} |
} |
return $insert_id; |
} |
/** Fonction updateMySQL() - Met à jour une table sélectionné dans l'objet formFromTable |
* |
* |
* @access public |
* @param string le nom du champs identifiant de la ligne à modifier. |
* @param integer l'identifiant numérique de la ligne à modifier. |
* @param string code SQL à rajouter à la fin de la requete, avant le WHERE |
* @return boolean retourne true si l'opération réussi. |
*/ |
function updateMySQL($champs_key, $id, $sql = '') |
{ |
$jointure_multiple = array(); |
$query = 'UPDATE '.$this->table.' SET '; |
for($i = 0 ; $i < count($this->champs) ; $i++) { |
// Traitement des jointures |
if ($this->jointure[$this->champs[$i]] != '') { |
// Traitement des jointures a forte cardinalite |
if (ereg('(.*) et (.*)', $this->jointure[$this->champs[$i]], $str)) { |
array_push($jointure_multiple, $str[0]); |
// on enleve la virgule finale |
//$query = ereg_replace ("", "", $query) ; |
continue; |
} else { |
$val = $_POST[$this->champs[$i]]; |
$this->champs[$i] = $this->jointure[$this->champs[$i]]; |
$_POST[$this->champs[$i]] = $val; |
} |
} |
// Cas des dates |
if ($this->tableau_type[$this->champs[$i]] == 'date') { |
$_POST[$this->champs[$i]] = preg_replace("/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/", "\\3-\\2-\\1", $_POST[$this->champs[$i]]); |
} |
// Cas simple |
$champs = $this->champs[$i]; |
$query .= $this->champs[$i]; |
$query .= ' = '; |
if (empty($_POST[$champs])) { |
$_POST[$champs] = ''; |
} |
$query .= '"'.$_POST[$champs].'"'; |
if ($i < (count($this->champs) - 1)) { |
$query .= ', '; |
} |
} |
// Avant d'ajouter la clause WHERE, on vérifie qu'il ne reste pas une virgule à la fin |
// si tel est le cas, on la supprime |
// signifie 'remplace une virgule à la fin de la chaine par rien.' |
$query = preg_replace("/(.*),$/", "\\1", $query); |
if ($sql != '') { |
$query .= ', '.$sql; |
} |
$query .= ' WHERE '.$champs_key.' = '.$id; |
$query = ereg_replace(', ,', ',', $query); |
mysql_query($query) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $query)); |
// Traitement des jointures multiples |
if (count($jointure_multiple) > 0) { |
for ($i = 0 ; $i < count($jointure_multiple) ; $i++) { |
ereg('(.*) et (.*)', $jointure_multiple[$i], $str); |
$table_jointure = $str[1]; |
$table_label = $str[2]; |
// Pour la mise a jour, on supprime puis on réinsère |
$queryDel = 'DELETE FROM '.$table_jointure.' '. |
'WHERE '.$this->champs1[$table_label].' = '.$id; |
mysql_query($queryDel) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $queryDel)); |
$queryN = 'SELECT COUNT('.$this->champs3[$table_label].') AS nombre '. |
'FROM '.$table_label; |
$resultN = mysql_query($queryN) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $queryN)); |
$rowN = mysql_fetch_object($resultN) ; |
// Il faut trouver le premier index. |
$requete_index = 'SELECT '.$this->champs3[$table_label].' AS _index '. |
'FROM '.$table_label; |
$resultat_index = mysql_query($requete_index) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $requete_index)); |
$ligne_index = mysql_fetch_object($resultat_index); |
for ($j = $ligne_index->_index ; $j <= $rowN->nombre ; $j++) { |
$nom = $table_label.$j; |
if (empty($_POST[$nom])) { |
$_POST[$nom] = ''; |
} |
if ($_POST[$nom] != '') { |
$queryM = 'INSERT INTO '.$table_jointure.' '. |
'SET '.$this->champs1[$table_label].' = '.$id.', '.$this->champs2[$table_label].' = "'.$_POST[$nom].'"'; |
mysql_query($queryM) or die(BOG_afficherErreurSql(__FILE__, __LINE__, mysql_error(), $queryM)); |
} |
} |
} |
} |
return true; |
} |
// reprend les intitules avec les valeurs |
function ConfirmResult() |
{ |
} |
function setSize($champs, $size) |
{ |
$this->tableau_type[$champs] = $size; |
} |
function getMaxColonne() |
{ |
$maxCol = 0; |
$currentMax = 0; |
for ($i = 0; $i < count ($this->ligne); ) { |
if (ereg("^!", $this->ligne[$i])) { |
$start = true; |
if ($start) $currentMax++; |
$i += 2; |
} else { |
$start = false ; |
if ($currentMax > $maxCol) $maxCol = $currentMax; |
$currentMax = 0; |
$i++; |
} |
} |
return $maxCol; |
} |
// ajouter un formulaire sans lien avec un champs |
function addFormOnly($string, $label, $presentation = NOUVELLE_LIGNE) |
{ |
array_push ($this->ligne, $label); |
array_push ($this->ligne, $string); |
if ($presentation == MEME_LIGNE) { |
// cette feinte ajoute le ! au début de la chaine du dernier élément du tableau $this->ligne |
array_push($this->ligne, '!'.array_pop($this->ligne)); |
} |
} |
// fonctions utiles a la classe formFromTable |
function _extraitTaille($type) |
{ |
return eregi_replace('[^[0-9]]*', '', $type); |
} |
function _extraitRadical($type) |
{ |
ereg('^[a-zA-Z]*', $type, $tableau_retour); |
return $tableau_retour[0]; |
} |
function _estimation_taille($taille) |
{ |
if ($taille < 8) { |
return $taille + 2; |
} |
if ($taille <= 16) { |
return 20; |
} |
if ($taille <= 64) { |
return 32; |
} |
return 60; |
} |
} |
// +------------------------------------------------------------------------------------------------------+ |
// | PIED du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: FORM_formulaire_table.class.php,v $ |
* Revision 1.4 2005/06/29 16:59:05 jpm |
* Correction d'un bogue. |
* |
* Revision 1.3 2005/04/06 13:22:17 jpm |
* Corrections et ajout d'id aux champs des formulaires. |
* |
* Revision 1.2 2005/03/30 09:06:26 jpm |
* Mise en conformité du code. |
* |
* Revision 1.1 2005/03/03 17:44:44 jpm |
* Ajout des fichiers anciennement contenu dans le fichier lib.form.php. |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |
/trunk/api/formulaire/formulaire.fonct.inc.php |
---|
639,9 → 639,8 |
$formtemplate->setDefaults(array('latitude' => $defaut['latitude'], 'longitude' => $defaut['longitude'])); |
} |
//GEN_stockerFichierScript('googleMapScript', $url_google_script); |
GEN_stockerFichierScript('googleMapScript', "http://maps.googleapis.com/maps/api/js?sensor=false&key=".BAZ_GOOGLE_KEY); |
GEN_AttributsBody('onload', 'load()'); |
//GEN_stockerFichierScript('googleMapScript', $url_google_script);// fout la merde avec google maps v2 |
GEN_stockerFichierScript('googleMapScript', "http://maps.googleapis.com/maps/api/js?sensor=false&key=".BAZ_GOOGLE_KEY); |
$html_bouton = '<tr> |
<td style="text-align:left;padding:5px;" colspan="2"> |
<input onclick="showAddress();" name="chercher_sur_carte" value="'.VERIFIER_MON_ADRESSE.'" type="button" /><span class="symbole_obligatoire"> *</span></td> |
/trunk/api/formulaire/formulaire.fonct.google.php |
---|
1,156 → 1,151 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This library is free software; you can redistribute it and/or | |
// | modify it under the terms of the GNU Lesser General Public | |
// | License as published by the Free Software Foundation; either | |
// | version 2.1 of the License, or (at your option) any later version. | |
// | | |
// | This library is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
// | Lesser General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU Lesser General Public | |
// | License along with this library; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: formulaire.fonct.google.php,v 1.3 2007-08-27 12:20:06 alexandre_tb Exp $ |
/** |
* Formulaire |
* |
* Les fonctions et script specifique a un carto google |
* |
*@package api/formulaire |
//Auteur original : |
*@author Aleandre GRANIER <alexandre@tela-botanica.org> |
*@copyright Tela-Botanica 2000-2007 |
*@version $Revision: 1.3 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
$script = ' |
// Variables globales |
var map = null; |
var geocoder = null; |
var marker = null; |
var flat = null; |
var flon = null; |
function load() { |
flat = document.getElementById("latitude"); |
flon = document.getElementById("longitude"); |
var optionsGoogleMapsv3 = { |
// On centre la carte sur le languedoc roussillon |
center: new google.maps.LatLng(43.84245116699036, 3.768310546875), |
zoom: 7, |
mapTypeId: google.maps.MapTypeId.G_HYBRID_MAP, |
mapTypeControl: true, |
scaleControl: true |
}; |
map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3); |
google.maps.event.addListener(map, "click", function(event) { |
if (marker != null) { |
marker.setMap(null); |
marker = null; |
} |
// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude |
marker = event.overlay; |
marker = new google.maps.Marker({ |
position: event.latLng, |
draggable: true, |
map: map |
}); |
google.maps.event.addListener(marker, "dragend", function () { |
coordMarker = marker.getPosition() ; |
flat.value = coordMarker.lat(); |
flon.value = coordMarker.lng(); |
}); |
setLatLonForm(marker); |
});'; |
if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') { |
$script .= ' |
point = new google.maps.LatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').'); |
marker = new google.maps.Marker({ |
position: point, |
draggable: true, |
map: map |
}); |
google.maps.event.addListener(marker, "dragend", function () { |
coordMarker = marker.getPosition() ; |
flat.value = coordMarker.lat(); |
flon.value = coordMarker.lng(); |
}); |
map.setCenter(point); |
' ; |
} |
$script .= 'geocoder = new google.maps.Geocoder(); |
}; |
function showAddress() { |
var adresse = document.getElementById("bf_adresse").value; |
var ville = ""; |
if (document.getElementById("bf_ville")) { |
ville = document.getElementById("bf_ville").value ; |
} |
var cp = document.getElementById("bf_cp_lieu_evenement").value ; |
var pays; |
if (document.getElementById("liste30")) { |
var selectIndex = document.getElementById("liste30").selectedIndex; |
pays = document.getElementById("liste30").options[selectIndex].text ; |
} else { |
pays = document.getElementById("bf_pays").value; |
} |
var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ; |
if (geocoder) { |
geocoder.geocode({ |
address: address |
}, function(result, status) { |
if (status != google.maps.GeocoderStatus.OK) { |
alert(address + " not found"); |
} else { |
marker.setMap(null); |
marker = null; |
//map.setCenter(point, 13); |
map.fitBounds(result[0].geometry.viewport); |
marker = new google.maps.Marker({ |
position: result[0].geometry.location, |
draggable: true, |
map: map |
}); |
google.maps.event.addListener(marker, "dragend", function () { |
coordMarker = marker.getPosition() ; |
flat.value = coordMarker.lat(); |
flon.value = coordMarker.lng(); |
}); |
setLatLonForm(marker); |
//marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'"); |
} |
}); |
} |
} |
function setLatLonForm(marker) { |
coordMarker = marker.getPosition() ; |
flat.value = coordMarker.lat(); |
flon.value = coordMarker.lng(); |
} |
'; |
/* |
* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: not supported by cvs2svn $ |
* Revision 1.2 2007-07-04 11:52:55 alexandre_tb |
* fonctionne mais en cours de développement |
* |
* Revision 1.1 2007-06-25 09:52:36 alexandre_tb |
* version intiale -- en cours |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 4.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This library is free software; you can redistribute it and/or | |
// | modify it under the terms of the GNU Lesser General Public | |
// | License as published by the Free Software Foundation; either | |
// | version 2.1 of the License, or (at your option) any later version. | |
// | | |
// | This library is distributed in the hope that it will be useful, | |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
// | Lesser General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU Lesser General Public | |
// | License along with this library; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: formulaire.fonct.google.php,v 1.3 2007-08-27 12:20:06 alexandre_tb Exp $ |
/** |
* Formulaire |
* |
* Les fonctions et script specifique a un carto google |
* |
*@package api/formulaire |
//Auteur original : |
*@author Aleandre GRANIER <alexandre@tela-botanica.org> |
*@copyright Tela-Botanica 2000-2007 |
*@version $Revision: 1.3 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
$script = ' |
// Variables globales |
var map = null; |
var geocoder = null; |
var lat = document.getElementById("latitude"); |
var lon = document.getElementById("longitude"); |
function load() { |
if (GBrowserIsCompatible()) { |
map = new GMap2(document.getElementById("map"), G_HYBRID_MAP); |
map.addControl(new GSmallMapControl()); |
map.addControl(new GMapTypeControl()); |
map.addControl(new GScaleControl()); |
map.enableContinuousZoom(); |
// On centre la carte sur le languedoc roussillon |
center = new GLatLng(47.0828920, 2.2565788); |
map.setCenter(center, 6);map.setMapType(G_HYBRID_MAP); |
//marker = new GMarker(center, {draggable: true}) ; |
GEvent.addListener(map, "click", function(marker, point) { |
if (marker) { |
map.removeOverlay(marker); |
var lat = document.getElementById("latitude"); |
var lon = document.getElementById("longitude"); |
lat.value = ""; |
lon.value = ""; |
} else { |
// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude |
marker = new GMarker(point, {draggable: true}) ; |
GEvent.addListener(marker, "dragend", function () { |
coordMarker = marker.getPoint() ; |
var lat = document.getElementById("latitude"); |
var lon = document.getElementById("longitude"); |
lat.value = coordMarker.lat(); |
lon.value = coordMarker.lng(); |
}); |
map.addOverlay(marker); |
setLatLonForm(marker); |
} |
});' ; |
if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') { |
$script .= ' |
point = new GLatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').'); |
marker = new GMarker(point, {draggable: true}); |
map.addOverlay(marker);' ; |
} |
$script .= 'geocoder = new GClientGeocoder(); |
} |
}; |
function showAddress() { |
var adresse = document.getElementById("bf_adresse").value ; |
if (document.getElementById("bf_ville")) { |
var ville = document.getElementById("bf_ville").value ; |
} else { |
var ville = ""; |
} |
var cp = document.getElementById("bf_cp_lieu_evenement").value ; |
if (document.getElementById("liste30")) { |
var selectIndex = document.getElementById("liste30").selectedIndex; |
var pays = document.getElementById("liste30").options[selectIndex].text ; |
} else { |
var pays = document.getElementById("bf_pays").value; |
} |
var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ; |
if (geocoder) { |
geocoder.getLatLng( |
address, |
function(point) { |
if (!point) { |
alert(address + " not found"); |
} else { |
map.setCenter(point, 13); |
var marker = new GMarker(point, {draggable: true}); |
GEvent.addListener(marker, "dragend", function () { |
coordMarker = marker.getPoint() ; |
var lat = document.getElementById("latitude"); |
var lon = document.getElementById("longitude"); |
lat.value = coordMarker.lat(); |
lon.value = coordMarker.lng(); |
}); |
map.addOverlay(marker); |
setLatLonForm(marker) |
marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'"); |
} |
} |
); |
} |
} |
function setLatLonForm(marker) { |
coordMarker = marker.getPoint() ; |
var lat = document.getElementById("latitude"); |
var lon = document.getElementById("longitude"); |
lat.value = coordMarker.lat(); |
lon.value = coordMarker.lng(); |
} |
'; |
/* |
* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: formulaire.fonct.google.php,v $ |
* Revision 1.3 2007-08-27 12:20:06 alexandre_tb |
* ajout d un test sur la ville |
* |
* Revision 1.2 2007-07-04 11:52:55 alexandre_tb |
* fonctionne mais en cours de développement |
* |
* Revision 1.1 2007-06-25 09:52:36 alexandre_tb |
* version intiale -- en cours |
* |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |