2003-02-14 18:14:29 +01:00
< ? PHP
/* Copyright ( C ) 2001 - 2002 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2003 Jean - Louis Bergamo < jlb @ j1b . org >
*
* 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 $
*
*/
2003-09-01 00:05:54 +02:00
require ( " ./pre.inc.php " );
require ( DOL_DOCUMENT_ROOT . " /adherents/adherent_options.class.php " );
2003-02-14 18:14:29 +01:00
$adho = new AdherentOptions ( $db );
2003-03-10 17:55:11 +01:00
$form = new Form ( $db );
2003-02-14 18:14:29 +01:00
if ( $HTTP_POST_VARS [ " action " ] == 'add' && $user -> admin )
{
2003-02-19 18:47:22 +01:00
// type et taille non encore pris en compte => varchar(255)
if ( isset ( $_POST [ " attrname " ]) && preg_match ( " /^ \ w[a-zA-Z0-9-]* $ / " , $_POST [ 'attrname' ])){
2003-03-10 17:55:11 +01:00
$adho -> create ( $_POST [ 'attrname' ], $_POST [ 'type' ], $_POST [ 'size' ]);
2003-02-14 18:14:29 +01:00
}
2003-02-19 18:47:22 +01:00
if ( isset ( $_POST [ 'label' ])){
$adho -> create_label ( $_POST [ 'attrname' ], $_POST [ 'label' ]);
}
2003-02-14 18:14:29 +01:00
Header ( " Location: $PHP_SELF " );
}
if ( $HTTP_POST_VARS [ " action " ] == 'update' && $user -> admin )
{
2003-02-19 18:47:22 +01:00
//if ($adho->update($user->id) )
2003-02-14 18:14:29 +01:00
// {
// }
2003-03-10 17:55:11 +01:00
if ( isset ( $_POST [ " attrname " ]) && preg_match ( " /^ \ w[a-zA-Z0-9-]* $ / " , $_POST [ 'attrname' ])){
$adho -> update ( $_POST [ 'attrname' ], $_POST [ 'type' ], $_POST [ 'size' ]);
}
2003-02-19 18:47:22 +01:00
if ( isset ( $_POST [ 'label' ])){
$adho -> update_label ( $_POST [ 'attrname' ], $_POST [ 'label' ]);
}
2003-02-14 18:14:29 +01:00
Header ( " Location: $PHP_SELF " );
}
2003-02-19 18:47:22 +01:00
if ( $action == 'delete' && $user -> admin )
2003-02-14 18:14:29 +01:00
{
2003-02-19 18:47:22 +01:00
if ( isset ( $attrname ) && preg_match ( " /^ \ w[a-zA-Z0-9-]* $ / " , $attrname )){
$adho -> delete ( $attrname );
2003-02-14 18:14:29 +01:00
}
Header ( " Location: $PHP_SELF " );
}
llxHeader ();
2003-02-19 18:47:22 +01:00
print_titre ( " Configuration des champs optionnels " );
2003-02-14 18:14:29 +01:00
/* ************************************************************************** */
/* */
/* */
/* */
/* ************************************************************************** */
$array_options = $adho -> fetch_name_optionals ();
2003-02-19 18:47:22 +01:00
$array_label = $adho -> fetch_name_optionals_label ();
2003-02-14 18:14:29 +01:00
if ( sizeof ( $array_options ) > 0 )
{
print " <TABLE border= \" 0 \" cellspacing= \" 0 \" cellpadding= \" 4 \" > " ;
print '<TR class="liste_titre">' ;
print " <td>Libelle</td> " ;
print " <td>Nom de l'attribut</td> " ;
2003-02-19 18:47:22 +01:00
print " <td>type</td><td> </td><td> </td> " ;
2003-02-14 18:14:29 +01:00
print " </TR> \n " ;
$var = True ;
foreach ( $adho -> attribute_name as $key => $value )
{
$var =! $var ;
print " <TR $bc[$var] > " ;
2003-02-19 18:47:22 +01:00
print " <TD> " . $adho -> attribute_label [ $key ] . " </td> \n " ;
2003-02-14 18:14:29 +01:00
print " <TD> $key </td> \n " ;
print " <TD> $value </TD> \n " ;
print " <TD><a href= \" $PHP_SELF ?action=edit&attrname= $key\ " > Editer </ TD > \n " ;
2003-02-19 18:47:22 +01:00
print " <TD><a href= \" $PHP_SELF ?action=delete&attrname= $key\ " > Supprimer </ TD > \n " ;
2003-02-14 18:14:29 +01:00
print " </tr> " ;
// $i++;
}
print " </table> " ;
}
2003-03-10 17:55:11 +01:00
print " <p><TABLE border= \" 1 \" width= \" 100% \" cellspacing= \" 0 \" cellpadding= \" 4 \" ><tr class= \" barreBouton \" > " ;
2003-02-14 18:14:29 +01:00
/*
* Case 1
*/
2003-03-10 17:55:11 +01:00
print " <td align= \" center \" width= \" 25% \" class= \" bouton \" >[<a href= \" $PHP_SELF ?action=create \" >Nouvel attribut</a>]</td> " ;
2003-02-14 18:14:29 +01:00
/*
* Case 2
*/
2003-03-10 17:55:11 +01:00
print " <td align= \" center \" width= \" 25% \" class= \" bouton \" >-</td> " ;
2003-02-14 18:14:29 +01:00
/*
* Case 3
*/
2003-03-10 17:55:11 +01:00
print " <td align= \" center \" width= \" 25% \" class= \" bouton \" >-</td> " ;
2003-02-14 18:14:29 +01:00
/*
* Case 4
*/
2003-03-10 17:55:11 +01:00
print " <td align= \" center \" width= \" 25% \" class= \" bouton \" >-</td> " ;
2003-02-14 18:14:29 +01:00
print " </tr></table></form><p> " ;
/* ************************************************************************** */
/* */
2003-02-19 18:47:22 +01:00
/* Cr<43> ation d'un champ optionnel */
2003-02-14 18:14:29 +01:00
/* */
/* ************************************************************************** */
if ( $action == 'create' ) {
print_titre ( " Nouvel attribut " );
print " <form action= \" $PHP_SELF\ " method = \ " post \" > " ;
print '<table cellspacing="0" border="1" width="100%" cellpadding="3">' ;
print '<input type="hidden" name="action" value="add">' ;
2003-03-10 17:55:11 +01:00
print '<tr><td>Libell<6C> </td><td class="valeur"><input type="text" name="label" size="40"></td></tr>' ;
print '<tr><td>Nom de l\'attribut (pas d\'espace et uniquement des carateres alphanumeriques)</td><td class="valeur"><input type="text" name="attrname" size="40"></td></tr>' ;
2003-02-14 18:14:29 +01:00
2003-03-10 17:55:11 +01:00
print '<tr><td>Type (non pris en compte)</td><td class="valeur">' ;
2003-02-14 18:14:29 +01:00
2003-03-10 17:55:11 +01:00
$form -> select_array ( 'type' , array ( 'varchar' => 'chaine' ,
'text' => 'texte' ,
'integer' => 'entier' ,
'date' => 'date' ,
'datetime' => 'date et heure' ));
/*
2003-02-14 18:14:29 +01:00
print '<select name="type">' ;
print '<option value="varchar">chaine</option>' ;
2003-03-10 17:55:11 +01:00
print '<option value="text">texte</option>' ;
2003-02-14 18:14:29 +01:00
print '<option value="integer">entier</option>' ;
print '<option value="date">date</option>' ;
print '<option value="datetime">date et heure</option>' ;
print '</select>' ;
2003-03-10 17:55:11 +01:00
*/
2003-02-14 18:14:29 +01:00
print '</td></tr>' ;
print '<tr><td>taille</td><td><input type="text" name="size" size="5" value="255"></td></tr>' ;
print '<tr><td colspan="2" align="center"><input type="submit" value="Enregistrer"></td></tr>' ;
print " </form> \n " ;
print " </table> \n " ;
}
/* ************************************************************************** */
/* */
2003-02-19 18:47:22 +01:00
/* Edition d'un champ optionnel */
2003-02-14 18:14:29 +01:00
/* */
/* ************************************************************************** */
if ( isset ( $attrname ) && $attrname != '' && $action == 'edit' )
{
print_titre ( " Edition du champ $attrname " );
print " <form action= \" $PHP_SELF\ " method = \ " post \" > " ;
print '<table cellspacing="0" border="1" width="100%" cellpadding="3">' ;
2003-02-19 18:47:22 +01:00
print '<tr><td>Libell<6C> </td><td class="valeur">' . $adho -> attribute_label [ $attrname ] . ' </td></tr>' ;
2003-02-14 18:14:29 +01:00
print '<tr><td>Nom de l\'attribut</td><td class="valeur">' . $attrname . ' </td></tr>' ;
print '<tr><td>Type</td><td class="valeur">' . $adho -> attribute_name [ $attrname ] . ' </td></tr>' ;
print " </table> \n " ;
/*
2003-02-19 18:47:22 +01:00
* formulaire d ' edition
2003-02-14 18:14:29 +01:00
*/
print '<form method="post" action="' . $PHP_SELF . '?attrname=' . $attrname . '">' ;
print '<input type="hidden" name="attrname" value="' . $attrname . '">' ;
print '<input type="hidden" name="action" value="update">' ;
print '<table cellspacing="0" border="1" width="100%" cellpadding="3">' ;
2003-02-19 18:47:22 +01:00
print '<tr><td>Libell<6C> </td><td class="valeur"><input type="text" name="label" size="40" value="' . $adho -> attribute_label [ $attrname ] . '"></td></tr>' ;
2003-02-14 18:14:29 +01:00
print '<tr><td>Nom de l\'attribut</td><td class="valeur">' . $attrname . ' </td></tr>' ;
2003-03-10 17:55:11 +01:00
list ( $type , $size ) = preg_split ( '/\(|\)/' , $adho -> attribute_name [ $attrname ]);
print '<tr><td>Type (non pris en compte)</td><td class="valeur">' ;
$form -> select_array ( 'type' , array ( 'varchar' => 'chaine' ,
'text' => 'texte' ,
'integer' => 'entier' ,
'date' => 'date' ,
'datetime' => 'date et heure' ), $type );
print '</td></tr>' ;
// print '<tr><td>Type (non pris en compte)</td><td class="valeur"><input type="text" name="type" size="40" value="'.$adho->attribute_name[$attrname].'"></td></tr>';
print '<tr><td>taille</td><td class="valeur"><input type="text" name="size" size="5" value="' . $size . '"></td></tr>' ;
2003-02-14 18:14:29 +01:00
print '<tr><td colspan="2" align="center"><input type="submit" value="Enregistrer"</td></tr>' ;
print '</table>' ;
print " </form> " ;
}
$db -> close ();
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
?>