Enhance extrafields feature. Input and output fields can be personalised according to their format/size.
This commit is contained in:
parent
bf38ea15ba
commit
c7ba210a9d
@ -29,82 +29,125 @@ require("../main.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php");
|
||||
|
||||
$langs->load("members");
|
||||
$langs->load("admin");
|
||||
|
||||
$adho = new ExtraFields($db);
|
||||
$extrafields = new ExtraFields($db);
|
||||
$form = new Form($db);
|
||||
|
||||
// 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';
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($_POST["action"] == 'add' && $user->rights->adherent->configurer)
|
||||
if ($action == 'add' && $user->rights->adherent->configurer)
|
||||
{
|
||||
if ($_POST["button"] != $langs->trans("Cancel"))
|
||||
{
|
||||
// Type et taille non encore pris en compte => varchar(255)
|
||||
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
|
||||
{
|
||||
$result=$adho->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$_POST['size'],'member');
|
||||
if ($result > 0)
|
||||
{
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$adho->error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
|
||||
$_GET["action"] = 'create';
|
||||
}
|
||||
// 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rename field
|
||||
if ($_POST["action"] == 'update' && $user->rights->adherent->configurer)
|
||||
if ($action == 'update' && $user->rights->adherent->configurer)
|
||||
{
|
||||
if ($_POST["button"] != $langs->trans("Cancel"))
|
||||
{
|
||||
if (isset($_POST["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_POST['attrname']))
|
||||
{
|
||||
$result=$adho->update($_POST['attrname'],$_POST['type'],$_POST['size']);
|
||||
if ($result > 0)
|
||||
{
|
||||
if (isset($_POST['label']))
|
||||
{
|
||||
$adho->update_label($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['size']);
|
||||
}
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg=$adho->error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
|
||||
}
|
||||
// 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Suppression attribut
|
||||
if ($_GET["action"] == 'delete' && $user->rights->adherent->configurer)
|
||||
if ($action == 'delete' && $user->rights->adherent->configurer)
|
||||
{
|
||||
if(isset($_GET["attrname"]) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$_GET["attrname"]))
|
||||
{
|
||||
$adho->delete($_GET["attrname"]);
|
||||
$extrafields->delete($_GET["attrname"],$elementtype);
|
||||
Header("Location: ".$_SERVER["PHP_SELF"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
$mesg=$langs->trans("ErrorFieldCanNotContainSpecialCharacters",$langs->transnoentities("AttributeCode"));
|
||||
}
|
||||
@ -116,35 +159,41 @@ if ($_GET["action"] == 'delete' && $user->rights->adherent->configurer)
|
||||
* View
|
||||
*/
|
||||
|
||||
llxHeader('',$langs->trans("OptionalFieldsSetup"),'EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros');
|
||||
$textobject=$langs->transnoentitiesnoconv("Members");
|
||||
|
||||
$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
|
||||
llxHeader('',$langs->trans("OptionalFieldsSetup"),$help_url);
|
||||
|
||||
|
||||
print_fiche_titre($langs->trans("OptionalFieldsSetup"));
|
||||
|
||||
if ($mesg) print '<div class="error">'.$mesg.'</div><br>';
|
||||
print $langs->trans("DefineHereComplementaryAttributes",$textobject).'<br>'."\n";
|
||||
print '<br>';
|
||||
|
||||
dol_htmloutput_errors($mesg);
|
||||
|
||||
// Load attribute_label
|
||||
$adho->fetch_name_optionals_label();
|
||||
$extrafields->fetch_name_optionals_label();
|
||||
|
||||
print "<table summary=\"listofattributes\" class=\"noborder\" width=\"100%\">";
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("AttributeCode").'</td>';
|
||||
print '<td>'.$langs->trans("Label").'</td>';
|
||||
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>';
|
||||
print "</tr>\n";
|
||||
|
||||
$var=True;
|
||||
foreach($adho->attribute_type as $key => $value)
|
||||
foreach($extrafields->attribute_type as $key => $value)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
print "<td>".$extrafields->attribute_label[$key]."</td>\n";
|
||||
print "<td>".$key."</td>\n";
|
||||
print "<td>".$adho->attribute_label[$key]."</td>\n";
|
||||
print "<td>".$adho->attribute_type[$key]."</td>\n";
|
||||
print '<td align="right">'.$adho->attribute_size[$key]."</td>\n";
|
||||
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>";
|
||||
@ -157,7 +206,7 @@ print "</table>";
|
||||
* Barre d'actions
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] != 'create' && $_GET["action"] != 'edit')
|
||||
if ($action != 'create' && $action != 'edit')
|
||||
{
|
||||
print '<div class="tabsAction">';
|
||||
print "<a class=\"butAction\" href=\"options.php?action=create\">".$langs->trans("NewAttribute")."</a>";
|
||||
@ -171,7 +220,7 @@ if ($_GET["action"] != 'create' && $_GET["action"] != 'edit')
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
if ($_GET["action"] == 'create')
|
||||
if ($action == 'create')
|
||||
{
|
||||
print "<br>";
|
||||
print_titre($langs->trans('NewAttribute'));
|
||||
@ -182,16 +231,16 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40"></td></tr>';
|
||||
print '<tr><td>'.$langs->trans("AttributeCode").' ('.$langs->trans("AlphaNumOnlyCharsAndNoSpace").')</td><td class="valeur"><input type="text" name="attrname" size="10"></td></tr>';
|
||||
print '<tr><td>'.$langs->trans("Type").'</td><td class="valeur">';
|
||||
print $form->selectarray('type',array('varchar'=>$langs->trans('String'),
|
||||
'text'=>$langs->trans('Text'),
|
||||
'int'=>$langs->trans('Int'),
|
||||
'date'=>$langs->trans('Date'),
|
||||
'datetime'=>$langs->trans('DateAndTime')));
|
||||
// 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'));
|
||||
print '</td></tr>';
|
||||
print '<tr><td>Taille</td><td><input type="text" name="size" size="5" value="255"></td></tr>';
|
||||
// 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>';
|
||||
@ -204,7 +253,7 @@ if ($_GET["action"] == 'create')
|
||||
/* Edition d'un champ optionnel */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
if ($_GET["attrname"] && $_GET["action"] == 'edit')
|
||||
if ($_GET["attrname"] && $action == 'edit')
|
||||
{
|
||||
print "<br>";
|
||||
print_titre($langs->trans("FieldEdition",$_GET["attrname"]));
|
||||
@ -218,30 +267,25 @@ if ($_GET["attrname"] && $_GET["action"] == 'edit')
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
print '<table summary="listofattributes" class="border" width="100%">';
|
||||
|
||||
// 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>';
|
||||
// Code
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans("AttributeCode").'</td>';
|
||||
print '<td class="fieldrequired" required>'.$langs->trans("AttributeCode").'</td>';
|
||||
print '<td class="valeur">'.$_GET["attrname"].' </td>';
|
||||
print '</tr>';
|
||||
// Label
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans("Label").'</td><td class="valeur"><input type="text" name="label" size="40" value="'.$adho->attribute_label[$_GET["attrname"]].'"></td>';
|
||||
print '</tr>';
|
||||
$type=$adho->attribute_type[$_GET["attrname"]];
|
||||
$size=$adho->attribute_size[$_GET["attrname"]];
|
||||
print '<tr><td>'.$langs->trans("Type").'</td>';
|
||||
// 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">';
|
||||
$type2label=array('varchar'=>$langs->trans('String'),
|
||||
'text'=>$langs->trans('Text'),
|
||||
'int'=>$langs->trans('Int'),
|
||||
'date'=>$langs->trans('Date'),
|
||||
'datetime'=>$langs->trans('DateAndTime'));
|
||||
//print $form->selectarray('type',$type2label,$type);
|
||||
print $type2label[$type];
|
||||
print '<input type="hidden" name="type" value="'.$type.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Size").'</td><td class="valeur"><input type="text" name="size" size="5" value="'.$size.'"></td></tr>';
|
||||
// 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>';
|
||||
|
||||
@ -414,6 +414,10 @@ class ExtraFields
|
||||
{
|
||||
$showsize=10;
|
||||
}
|
||||
elseif ($type == 'datetime')
|
||||
{
|
||||
$showsize=19;
|
||||
}
|
||||
elseif ($type == 'int')
|
||||
{
|
||||
$showsize=10;
|
||||
@ -426,7 +430,8 @@ class ExtraFields
|
||||
//print $type.'-'.$size;
|
||||
$out='<input type="text" name="options_'.$key.'" size="'.$showsize.'" maxlength="'.$size.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>';
|
||||
if ($type == 'date') $out.=' (YYYY-MM-DD)';
|
||||
return $out;
|
||||
if ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,6 +449,10 @@ class ExtraFields
|
||||
{
|
||||
$showsize=10;
|
||||
}
|
||||
elseif ($type == 'datetime')
|
||||
{
|
||||
$showsize=19;
|
||||
}
|
||||
elseif ($type == 'int')
|
||||
{
|
||||
$showsize=10;
|
||||
|
||||
@ -840,6 +840,7 @@ MAIN_PROXY_HOST=Name/Address of proxy server
|
||||
MAIN_PROXY_PORT=Port of proxy server
|
||||
MAIN_PROXY_USER=Login to use the proxy server
|
||||
MAIN_PROXY_PASS=Password to use the proxy server
|
||||
DefineHereComplementaryAttributes=Define here all atributes, not already available by default, and that you want to be supported for %s.
|
||||
|
||||
##### Module password generation
|
||||
PasswordGenerationStandard=Return a password generated according to internal Dolibarr algorithm: 8 characters containing shared numbers and characters in lowercase.
|
||||
|
||||
@ -852,6 +852,8 @@ MAIN_PROXY_HOST=Nom/Adresse du serveur proxy mandataire
|
||||
MAIN_PROXY_PORT=Port du serveur proxy mandataire
|
||||
MAIN_PROXY_USER=Login pour passer le serveur proxy mandataire
|
||||
MAIN_PROXY_PASS=Mot de passe pour passer le serveur proxy mandataire
|
||||
DefineHereComplementaryAttributes=Definissez ici la liste des attributs supplémentaire, non disponible en standard, et que vous voulez voir gérez sur les %s.
|
||||
|
||||
##### Module password generation= undefined
|
||||
PasswordGenerationStandard= Renvoie un mot de passe généré selon algorithme interne Dolibarr: 8 caractères, chiffres et caractères en minuscules mélangés.
|
||||
PasswordGenerationNone= Ne propose pas de mots de passe générés. Le mot de passe est à saisir manuellement.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user