New fields on usergroup object + card uses common tpl

This commit is contained in:
Maxime Kohlhaas 2020-04-13 15:38:50 +02:00
parent 2bf36bff6d
commit 26befa3b93
2 changed files with 70 additions and 75 deletions

View File

@ -100,6 +100,16 @@ class UserGroup extends CommonObject
public $oldcopy; // To contains a clone of this when we need to save old properties of object public $oldcopy; // To contains a clone of this when we need to save old properties of object
public $fields = array(
'rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>5),
'nom'=>array('type'=>'varchar(180)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Group name'),
'note' => array('type'=>'html', 'label'=>'Description', 'enabled'=>1, 'visible'=>1, 'position'=>20, 'notnull'=>-1,),
'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>50, 'notnull'=>1,),
'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>60, 'notnull'=>1,),
'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>100),
);
/** /**
* Constructor de la classe * Constructor de la classe

View File

@ -54,6 +54,7 @@ $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09'); $cancel = GETPOST('cancel', 'aZ09');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'groupcard'; // To manage different context of search $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'groupcard'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$userid = GETPOST('user', 'int'); $userid = GETPOST('user', 'int');
@ -91,19 +92,20 @@ $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) { if (empty($reshook)) {
$backurlforlist = DOL_URL_ROOT.'/user/group/list.php';
if (empty($backtopage) || ($cancel && empty($id))) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) $backtopage = $backurlforlist;
else $backtopage = dol_buildpath('/user/group/card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
}
}
if ($cancel) if ($cancel)
{ {
if (!empty($backtopage)) header("Location: ".$backtopage);
{ exit;
header("Location: ".$backtopage);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT.'/user/group/list.php');
exit;
}
$action = '';
} }
// Action remove group // Action remove group
@ -215,7 +217,7 @@ if (empty($reshook)) {
$object->oldcopy = clone $object; $object->oldcopy = clone $object;
$object->name = trim(GETPOST("group", 'nohtml')); $object->name = trim(GETPOST("nom", 'nohtml'));
$object->nom = $object->name; // For backward compatibility $object->nom = $object->name; // For backward compatibility
$object->note = dol_htmlcleanlastbr(trim(GETPOST("note", 'none'))); $object->note = dol_htmlcleanlastbr(trim(GETPOST("note", 'none')));
@ -273,14 +275,11 @@ if ($action == 'create')
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
dol_fiche_head('', '', '', 0, ''); dol_fiche_head('', '', '', 0, '');
print '<table class="border centpercent">'; print '<table class="border centpercent tableforfieldcreate">';
print "<tr>";
print '<td class="fieldrequired titlefield">'.$langs->trans("Name").'</td>';
print '<td><input type="text" id="nom" name="nom" value="'.dol_escape_htmltag(GETPOST('nom', 'nohtml')).'"></td></tr>';
// Multicompany // Multicompany
if (!empty($conf->multicompany->enabled) && is_object($mc)) if (!empty($conf->multicompany->enabled) && is_object($mc))
@ -297,27 +296,18 @@ if ($action == 'create')
} }
} }
print "<tr>".'<td class="tdtop">'.$langs->trans("Description").'</td><td>'; // Common attributes
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
$doleditor = new DolEditor('note', '', '', 240, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_8, '90%');
$doleditor->Create();
print "</td></tr>\n";
// Other attributes // Other attributes
$parameters = array('object' => $object); include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{
print $object->showOptionals($extrafields, 'edit');
}
print "</table>\n"; print "</table>\n";
dol_fiche_end(); dol_fiche_end();
print '<div class="center">'; print '<div class="center">';
print '<input class="button" value="'.$langs->trans("CreateGroup").'" type="submit">'; print '<input class="button" name="add" value="'.$langs->trans("CreateGroup").'" type="submit">';
print ' &nbsp; '; print ' &nbsp; ';
print '<input class="button" value="'.$langs->trans("Cancel").'" name="cancel" type="submit">'; print '<input class="button" value="'.$langs->trans("Cancel").'" name="cancel" type="submit">';
print '</div>'; print '</div>';
@ -359,6 +349,7 @@ else
dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin); dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
print '<div class="fichecenter">'; print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent tableforfield">'; print '<table class="border centpercent tableforfield">';
@ -384,19 +375,18 @@ else
print "</td></tr>\n"; print "</td></tr>\n";
} }
// Note // Common attributes
print '<tr><td class="titlefield tdtop">'.$langs->trans("Description").'</td>'; $keyforbreak = '';
print '<td class="valeur sensiblehtmlcontent"">'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
print dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note));
print '</td>';
print "</tr>\n";
// Other attributes // Other attributes
$parameters = array('colspan' => ' colspan="2"');
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
print "</table>\n"; print '</table>';
print '</div>'; print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
dol_fiche_end(); dol_fiche_end();
@ -407,6 +397,10 @@ else
print '<div class="tabsAction">'; print '<div class="tabsAction">';
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($caneditperms) if ($caneditperms)
{ {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
@ -421,7 +415,7 @@ else
// List users in group // List users in group
print load_fiche_titre($langs->trans("ListOfUsersInGroup"), '', ''); print load_fiche_titre($langs->trans("ListOfUsersInGroup"), '', 'user');
// On selectionne les users qui ne sont pas deja dans le groupe // On selectionne les users qui ne sont pas deja dans le groupe
$exclude = array(); $exclude = array();
@ -485,7 +479,7 @@ else
print '</td>'; print '</td>';
print '<td>'.$useringroup->lastname.'</td>'; print '<td>'.$useringroup->lastname.'</td>';
print '<td>'.$useringroup->firstname.'</td>'; print '<td>'.$useringroup->firstname.'</td>';
print '<td class="center">'.$useringroup->getLibStatut(3).'</td>'; print '<td class="center">'.$useringroup->getLibStatut(5).'</td>';
print '<td class="right">'; print '<td class="right">';
if (!empty($user->admin)) { if (!empty($user->admin)) {
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'">'; print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'">';
@ -542,53 +536,44 @@ else
if ($action == 'edit' && $caneditperms) if ($action == 'edit' && $caneditperms)
{ {
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post" name="updategroup" enctype="multipart/form-data">'; print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="updategroup" enctype="multipart/form-data">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update">'; print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
dol_fiche_head($head, 'group', $title, 0, 'group'); dol_fiche_head($head, 'group', $title, 0, 'group');
print '<table class="border centpercent">'; print '<table class="border centpercent tableforfieldedit">'."\n";
print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Name").'</td>';
print '<td class="valeur"><input class="minwidth300" type="text" name="group" value="'.dol_escape_htmltag($object->name).'">';
print "</td></tr>\n";
// Multicompany // Multicompany
if (!empty($conf->multicompany->enabled) && is_object($mc)) if (!empty($conf->multicompany->enabled) && is_object($mc))
{ {
if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity)
{ {
print "<tr>".'<td class="tdtop">'.$langs->trans("Entity").'</td>'; print "<tr>".'<td class="tdtop">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($object->entity); print "<td>".$mc->select_entities($object->entity);
print "</td></tr>\n"; print "</td></tr>\n";
} }
else else
{ {
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />'; print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
} }
} }
// Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
print '<td class="valeur">';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor('note', $object->note, '', 240, 'dolibarr_notes', '', true, false, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_8, '90%');
$doleditor->Create();
print '</td>';
print "</tr>\n";
// Other attributes // Other attributes
$parameters = array(); include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook))
{
print $object->showOptionals($extrafields, 'edit');
}
print "</table>\n"; print '</table>';
dol_fiche_end(); dol_fiche_end();
print '<div class="center"><input class="button" value="'.$langs->trans("Save").'" type="submit"></div>'; print '<div class="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print ' &nbsp; <input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>'; print '</form>';
} }