2004-02-16 13:22:32 +01:00
< ? PHP
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-21 00:40:13 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2004-06-25 02:12:13 +02:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2004-02-16 13:22:32 +01:00
*
* This program 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 .
*
* This program 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 this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
* $Id $
* $Source $
*/
require ( " ./pre.inc.php " );
$acts [ 0 ] = " add " ;
$acts [ 1 ] = " delete " ;
2004-06-09 20:37:17 +02:00
$actl [ 0 ] = " Activer " ;
$actl [ 1 ] = " D<EFBFBD> sactiver " ;
2004-02-16 13:22:32 +01:00
2004-06-09 20:37:17 +02:00
$active = 1 ;
// Mettre ici tous les caract<63> ristiques des dictionnaires editables
2004-06-26 19:13:30 +02:00
// Nom des tables des dictionnaires
2004-02-16 13:22:32 +01:00
$tabid [ 1 ] = " llx_c_forme_juridique " ;
$tabid [ 2 ] = " llx_c_departements " ;
$tabid [ 3 ] = " llx_c_regions " ;
2004-06-09 20:37:17 +02:00
$tabid [ 4 ] = " llx_c_pays " ;
2004-06-17 18:48:41 +02:00
$tabid [ 5 ] = " llx_c_civilite " ;
2004-02-16 13:22:32 +01:00
2004-06-26 19:13:30 +02:00
// Libell<6C> des dictionnaires
2004-06-09 20:37:17 +02:00
$tabnom [ 1 ] = " Formes juridiques " ;
2004-06-11 01:38:00 +02:00
$tabnom [ 2 ] = " D<EFBFBD> partements/Provinces/Cantons " ;
2004-06-09 20:37:17 +02:00
$tabnom [ 3 ] = " R<EFBFBD> gions " ;
$tabnom [ 4 ] = " Pays " ;
2004-06-25 02:12:13 +02:00
$tabnom [ 5 ] = " Titres de civilit<69> " ;
2004-02-16 13:22:32 +01:00
2004-06-26 19:13:30 +02:00
// Requete pour extraction des donn<6E> es des dictionnaires
$tabsql [ 1 ] = " SELECT f.code, f.libelle, p.libelle as pays, f.active FROM llx_c_forme_juridique as f, llx_c_pays as p WHERE f.fk_pays=p.rowid " ;
$tabsql [ 2 ] = " SELECT d.rowid as rowid, d.code_departement as code , d.nom as libelle, p.libelle as pays, d.active FROM llx_c_departements as d, llx_c_regions as r, llx_c_pays as p WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid " ;
$tabsql [ 3 ] = " SELECT r.rowid as rowid, code_region as code , nom as libelle, p.libelle as pays, r.active FROM llx_c_regions as r, llx_c_pays as p WHERE r.fk_pays=p.rowid " ;
$tabsql [ 4 ] = " SELECT rowid, code, libelle, active FROM llx_c_pays " ;
$tabsql [ 5 ] = " SELECT c.rowid AS rowid, c.civilite AS libelle, c.active FROM llx_c_civilite AS c, llx_c_pays AS p WHERE c.fk_pays = p.rowid " ;
// Tri par defaut
$tabsqlsort [ 1 ] = " p.rowid, code ASC " ;
$tabsqlsort [ 2 ] = " p.rowid, code ASC " ;
$tabsqlsort [ 3 ] = " p.rowid, code ASC " ;
$tabsqlsort [ 4 ] = " code ASC " ;
$tabsqlsort [ 5 ] = " libelle ASC " ;
2004-06-09 20:37:17 +02:00
// Champs <20> afficher
2004-06-11 02:13:15 +02:00
$tabfield [ 1 ] = " code,libelle,pays " ;
$tabfield [ 2 ] = " code,libelle,pays " ;
2004-06-09 20:37:17 +02:00
$tabfield [ 3 ] = " code,libelle,pays " ;
$tabfield [ 4 ] = " code,libelle " ;
2004-06-17 18:48:41 +02:00
$tabfield [ 5 ] = " libelle " ;
2004-02-16 13:22:32 +01:00
2004-06-26 19:13:30 +02:00
2004-06-09 20:37:17 +02:00
if ( ! $user -> admin )
2004-06-26 19:13:30 +02:00
accessforbidden ();
2004-02-21 00:37:42 +01:00
2004-02-16 13:22:32 +01:00
2004-06-09 20:37:17 +02:00
if ( $_GET [ " action " ] == 'delete' )
{
2004-06-26 19:13:30 +02:00
if ( $_GET [ " rowid " ] > 0 ) {
$sql = " UPDATE " . $tabid [ $_GET [ " id " ]] . " SET active = 0 WHERE rowid= " . $_GET [ " rowid " ];
}
elseif ( $_GET [ " code " ] > 0 ) {
$sql = " UPDATE " . $tabid [ $_GET [ " id " ]] . " SET active = 0 WHERE code= " . $_GET [ " code " ];
}
$result = $db -> query ( $sql );
if ( ! $result )
{
print $db -> error ();
}
2004-06-09 20:37:17 +02:00
}
if ( $_GET [ " action " ] == 'add' )
2004-02-16 13:22:32 +01:00
{
2004-06-26 19:13:30 +02:00
$sql = " UPDATE " . $tabid [ $_GET [ " id " ]] . " SET active = 1 WHERE rowid= " . $_GET [ " rowid " ];
$result = $db -> query ( $sql );
if ( ! $result )
2004-06-09 20:37:17 +02:00
{
2004-06-26 19:13:30 +02:00
print $db -> error ();
2004-06-09 20:37:17 +02:00
}
2004-02-16 13:22:32 +01:00
}
2004-06-09 20:37:17 +02:00
llxHeader ();
2004-02-16 13:22:32 +01:00
2004-06-09 20:37:17 +02:00
if ( $_GET [ " id " ])
2004-02-16 13:22:32 +01:00
{
2004-06-26 19:13:30 +02:00
print_titre ( " Configuration des dictionnaires de donn<6E> es " );
2004-06-09 20:37:17 +02:00
print '<br>' ;
2004-02-16 13:22:32 +01:00
2004-06-26 19:13:30 +02:00
// Compl<70> te requete recherche valeurs avec critere de tri
$sql = $tabsql [ $_GET [ " id " ]];
if ( $_GET [ " sortfield " ]) {
$sql .= " ORDER BY " . $_GET [ " sortfield " ];
if ( $_GET [ " sortorder " ]) {
$sql .= " " . $_GET [ " sortorder " ];
}
$sql .= " , " ;
}
else {
$sql .= " ORDER BY " ;
}
$sql .= $tabsqlsort [ $_GET [ " id " ]];
$fieldlist = split ( ',' , $tabfield [ $_GET [ " id " ]]);
print '<table class="noborder" cellpadding="3" cellspacing="0" width="100%">' ;
// Ligne d'ajout
if ( $tabid [ $_GET [ " id " ]]) {
print_titre ( $tabnom [ $_GET [ " id " ]]);
$var = False ;
$fieldlist = split ( ',' , $tabfield [ $_GET [ " id " ]]);
print '<table class="noborder" cellpadding="3" cellspacing="0" width="100%">' ;
print '<tr class="liste_titre">' ;
foreach ( $fieldlist as $field => $value ) {
print '<td>' ;
print ucfirst ( $fieldlist [ $field ]);
print '</td>' ;
}
print '<td> </td>' ;
print '</td>' ;
print " <tr $bc[$var] class= \" value \" > " ;
foreach ( $fieldlist as $field => $value ) {
if ( $fieldlist [ $field ] == 'pays' ) {
$html = new Form ( $db );
print '<td>' ;
$html -> select_pays ();
print '</td>' ;
}
else {
print '<td><input type="text" value="" name="' . $fieldlist [ $field ] . '"></td>' ;
}
}
print '<td colspan=2><input type="submit" name="Ajouter" value="Ajouter"></td>' ;
print " </tr> " ;
print '<tr><td colspan="' . ( count ( $fieldlist ) + 2 ) . '"></td></tr>' ;
}
2004-06-09 20:37:17 +02:00
// Affiche table des valeurs
2004-06-26 19:13:30 +02:00
if ( $db -> query ( $sql ))
2004-02-16 13:22:32 +01:00
{
2004-06-26 19:13:30 +02:00
$num = $db -> num_rows ();
$i = 0 ;
$var = False ;
if ( $num )
{
print '<tr class="liste_titre">' ;
foreach ( $fieldlist as $field => $value ) {
print '<td>' ;
print_liste_field_titre ( ucfirst ( $fieldlist [ $field ]), $PHP_SELF , $fieldlist [ $field ], " &id= " . $_GET [ " id " ]);
print '</td>' ;
}
print '<td>' ;
print_liste_field_titre ( " Activer/D<> sactiver " , $PHP_SELF , " active " , " &id= " . $_GET [ " id " ]);
print '</td>' ;
print '</tr>' ;
while ( $i < $num )
{
$obj = $db -> fetch_object ( $i );
$var =! $var ;
print " <tr $bc[$var] class= \" value \" > " ;
foreach ( $fieldlist as $field => $value ) {
print '<td>' . $obj -> $fieldlist [ $field ] . '</td>' ;
}
print '<td>' ;
if ( $obj -> code ) {
print '<a href="' . $PHP_SELF . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder . '&rowid=' . $obj -> rowid . '&code=' . $obj -> code . '&id=' . $_GET [ " id " ] . '&action=' . $acts [ $obj -> active ] . '">' . $actl [ $obj -> active ] . '</a>' ;
} else {
print '<a href="' . $PHP_SELF . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder . '&rowid=' . $obj -> rowid . '&code=' . $obj -> code . '&id=' . $_GET [ " id " ] . '&action=' . $acts [ $obj -> active ] . '">' . $actl [ $obj -> active ] . '</a>' ;
}
print " </td> " ;
print " </tr> \n " ;
$i ++ ;
}
}
}
else {
print " Erreur : $sql : " . $db -> error ();
2004-02-16 13:22:32 +01:00
}
2004-06-26 19:13:30 +02:00
print '</table>' ;
2004-02-16 13:22:32 +01:00
}
2004-06-09 20:37:17 +02:00
else
{
print_titre ( " Configuration des dictionnaires de donn<6E> es " );
print '<br>' ;
2004-06-26 19:13:30 +02:00
2004-06-09 20:37:17 +02:00
foreach ( $tabid as $i => $value ) {
print '<a href="dict.php?id=' . $i . '">' . $tabnom [ $i ] . '</a> (Table ' . $tabid [ $i ] . ')<br>' ;
}
}
print '<br>' ;
$db -> close ();
llxFooter ();
2004-02-16 13:22:32 +01:00
?>