Newer
Older
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
Laurent Destailleur
committed
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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.
*/
Laurent Destailleur
committed
/**
* \file htdocs/adherents/options.php
* \brief Page de configuratin des champs optionnels
* \version $Id$
Laurent Destailleur
committed
require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
Laurent Destailleur
committed
$langs->load("members");
Laurent Destailleur
committed
$langs->load("admin");
Laurent Destailleur
committed
$extrafields = new ExtraFields($db);
Jean-Louis Bergamo
committed
$form = new Form($db);
Laurent Destailleur
committed
// List of supported format
$type2label=array(
'varchar'=>$langs->trans('String'),
'text'=>$langs->trans('Text'),
'int'=>$langs->trans('Int'),
'date'=>$langs->trans('Date'),
'datetime'=>$langs->trans('DateAndTime')
);
$action=GETPOST("action");
$elementtype='member';
Laurent Destailleur
committed
if ($action == 'add' && $user->rights->adherent->configurer)
Laurent Destailleur
committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Check values
if (GETPOST('type')=='varchar' && GETPOST('size') > 255)
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForVarcharType");
$action = 'create';
}
if (! $error)
{
// Type et taille non encore pris en compte => varchar(255)
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
$result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],$elementtype);
if ($result > 0)
{
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$error++;
$mesg=$extrafields->error;
}
}
else
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
$action = 'create';
}
}
Laurent Destailleur
committed
if ($action == 'update' && $user->rights->adherent->configurer)
Laurent Destailleur
committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Check values
if (GETPOST('type')=='varchar' && GETPOST('size') > 255)
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorSizeTooLongForVarcharType");
$action = 'edit';
}
if (! $error)
{
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
{
$result=$extrafields->update($_POST['attrname'],$_POST['type'],$_POST['size'],$elementtype);
if ($result > 0)
{
if (isset($_POST['label']))
{
$extrafields->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size'],$elementtype);
}
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
$error++;
$mesg=$extrafields->error;
}
}
else
{
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
}
Laurent Destailleur
committed
# Suppression attribut
Laurent Destailleur
committed
if ($action == 'delete' && $user->rights->adherent->configurer)
if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
{
Laurent Destailleur
committed
$extrafields->delete($_GET["attrname"],$elementtype);
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
Laurent Destailleur
committed
$error++;
$langs->load("errors");
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
}
/*
* View
*/
Laurent Destailleur
committed
$textobject=$langs->transnoentitiesnoconv("Members");
$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
llxHeader('',$langs->trans("OptionalFieldsSetup"),$help_url);
Laurent Destailleur
committed
print_fiche_titre($langs->trans("OptionalFieldsSetup"));
Laurent Destailleur
committed
Laurent Destailleur
committed
print $langs->trans("DefineHereComplementaryAttributes",$textobject).'<br>'."\n";
print '<br>';
dol_htmloutput_errors($mesg);
Laurent Destailleur
committed
Laurent Destailleur
committed
$extrafields->fetch_name_optionals_label();
Laurent Destailleur
committed
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
Laurent Destailleur
committed
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Label").'</td>';
Laurent Destailleur
committed
print '<td>'.$langs->trans("AttributeCode").'</td>';
print '<td>'.$langs->trans("Type").'</td>';
print '<td align="right">'.$langs->trans("Size").'</td>';
print '<td width="80"> </td>';
Laurent Destailleur
committed
print "</tr>\n";
Laurent Destailleur
committed
foreach($extrafields->attribute_type as $key => $value)
Laurent Destailleur
committed
print "<td>".$extrafields->attribute_label[$key]."</td>\n";
print "<td>".$key."</td>\n";
Laurent Destailleur
committed
print "<td>".$type2label[$extrafields->attribute_type[$key]]."</td>\n";
print '<td align="right">'.$extrafields->attribute_size[$key]."</td>\n";
print '<td align="right"><a href="options.php?action=edit&attrname='.$key.'">'.img_edit().'</a>';
print " <a href=\"options.php?action=delete&attrname=$key\">".img_delete()."</a></td>\n";
print "</tr>";
// $i++;
Laurent Destailleur
committed
}
print "</table>";
/*
* Barre d'actions
*
*/
Laurent Destailleur
committed
if ($action != 'create' && $action != 'edit')
{
print '<div class="tabsAction">';
print "<a class=\"butAction\" href=\"options.php?action=create\">".$langs->trans("NewAttribute")."</a>";
Laurent Destailleur
committed
/* ************************************************************************** */
/* */
/* ************************************************************************** */
Laurent Destailleur
committed
if ($action == 'create')
Regis Houssin
committed
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table summary="listofattributes" class="border" width="100%">';
print '<input type="hidden" name="action" value="add">';
Laurent Destailleur
committed
// Label
print '<tr><td class="fieldrequired" required>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.GETPOST('label').'"></td></tr>';
// Code
print '<tr><td class="fieldrequired" required>'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')</td><td class="valeur"><input type="text" name="attrname" size="10" value"'.GETPOST('attrname').'"></td></tr>';
// Type
print '<tr><td class="fieldrequired" required>'.$langs->trans("Type").'</td><td class="valeur">';
print $form->selectarray('type',$type2label,GETPOST('type'));
Laurent Destailleur
committed
// Size
print '<tr><td class="fieldrequired" required>'.$langs->trans("Size").'</td><td><input type="text" name="size" size="5" value="'.(GETPOST('size')?GETPOST('size'):'255').'"></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" name="button" class="button" value="'.$langs->trans("Save").'"> ';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'"></td></tr>';
print "</form>\n";
print "</table>\n";
/* ************************************************************************** */
/* */
Jean-Louis Bergamo
committed
/* Edition d'un champ optionnel */
/* */
/* ************************************************************************** */
Laurent Destailleur
committed
if ($_GET["attrname"] && $action == 'edit')
print_titre($langs->trans("FieldEdition",$_GET["attrname"]));
/*
* formulaire d'edition
*/
print '<form method="post" action="options.php?attrname='.$_GET["attrname"].'">';
Regis Houssin
committed
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="attrname" value="'.$_GET["attrname"].'">';
print '<input type="hidden" name="action" value="update">';
print '<table summary="listofattributes" class="border" width="100%">';
Laurent Destailleur
committed
// Label
print '<tr>';
print '<td class="fieldrequired" required>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.$extrafields->attribute_label[$_GET["attrname"]].'"></td>';
print '</tr>';
Laurent Destailleur
committed
print '<td class="fieldrequired" required>'.$langs->trans("AttributeCode").'</td>';
print '<td class="valeur">'.$_GET["attrname"].' </td>';
print '</tr>';
Laurent Destailleur
committed
// Type
$type=$extrafields->attribute_type[$_GET["attrname"]];
$size=$extrafields->attribute_size[$_GET["attrname"]];
print '<tr><td class="fieldrequired" required>'.$langs->trans("Type").'</td>';
print '<td class="valeur">';
print $type2label[$type];
print '<input type="hidden" name="type" value="'.$type.'">';
Laurent Destailleur
committed
// Size
print '<tr><td class="fieldrequired" required>'.$langs->trans("Size").'</td><td class="valeur"><input type="text" name="size" size="5" value="'.$size.'"></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"> ';
print '<input type="submit" name="button" class="button" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print "</form>";
llxFooter('$Date$ - $Revision$');