Uniformize interface for tickets

This commit is contained in:
Laurent Destailleur 2018-10-01 03:19:21 +02:00
parent fdd6c8d6bf
commit 873f43db94
3 changed files with 202 additions and 190 deletions

View File

@ -4506,21 +4506,23 @@ class Form
* @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $nooutput No print output. Return it only.
* @return void * @return void
*/ */
function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array()) function form_thirdparty($page, $selected='', $htmlname='socid', $filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $nooutput=0)
{ {
// phpcs:enable // phpcs:enable
global $langs; global $langs;
$out = '';
if ($htmlname != "none") if ($htmlname != "none")
{ {
print '<form method="post" action="'.$page.'">'; $out.='<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="set_thirdparty">'; $out.= '<input type="hidden" name="action" value="set_thirdparty">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $out.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); $out.= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events);
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; $out.= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
print '</form>'; $out.= '</form>';
} }
else else
{ {
@ -4529,13 +4531,16 @@ class Form
require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($selected); $soc->fetch($selected);
print $soc->getNomUrl($langs); $out.= $soc->getNomUrl($langs);
} }
else else
{ {
print "&nbsp;"; $out.= "&nbsp;";
} }
} }
if ($nooutput) return $out;
else print $out;
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps

View File

@ -93,14 +93,13 @@ foreach($object->fields as $key => $val)
if (empty($action) && empty($id) && empty($ref)) $action='view'; if (empty($action) && empty($id) && empty($ref)) $action='view';
// Security check - Protection if external user
//if ($user->societe_id > 0) access_forbidden();
//if ($user->societe_id > 0) $socid = $user->societe_id;
//$result = restrictedArea($user, 'mymodule', $id);
// Load object // Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
// Security check - Protection if external user
//if ($user->societe_id > 0) access_forbidden();
//if ($user->societe_id > 0) $socid = $user->societe_id;
//$result = restrictedArea($user, 'mymodule', $object->id);
/* /*
@ -126,6 +125,9 @@ if (empty($reshook))
// Actions cancel, add, update, delete or clone // Actions cancel, add, update, delete or clone
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
// Actions when linking object each other
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
// Actions when printing a doc from card // Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
@ -316,9 +318,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (! empty($object->fk_project)) { if (! empty($object->fk_project)) {
$proj = new Project($db); $proj = new Project($db);
$proj->fetch($object->fk_project); $proj->fetch($object->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; $morehtmlref.=$proj->getNomUrl();
$morehtmlref.=$proj->ref;
$morehtmlref.='</a>';
} else { } else {
$morehtmlref.=''; $morehtmlref.='';
} }

View File

@ -55,26 +55,43 @@ $action = GETPOST('action', 'alpha', 3);
$hookmanager->initHooks(array('ticketcard','globalcard')); $hookmanager->initHooks(array('ticketcard','globalcard'));
$object = new Ticket($db); $object = new Ticket($db);
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// Fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
if (!$action) { // Initialize array of search criterias
$action = 'view'; $search_all=trim(GETPOST("search_all",'alpha'));
$search=array();
foreach($object->fields as $key => $val)
{
if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
} }
if (empty($action) && empty($id) && empty($ref)) $action='view';
//Select mail models is same action as add_message //Select mail models is same action as add_message
if (GETPOST('modelselected','alpha')) { if (GETPOST('modelselected','alpha')) {
$action = 'add_message'; $action = 'add_message';
} }
// Load object
//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
if ($id || $track_id || $ref) {
$res = $object->fetch($id, $ref, $track_id);
if ($res >= 0)
{
$id = $object->id;
$track_id = $object->track_id;
}
}
// Store current page url // Store current page url
$url_page_current = DOL_URL_ROOT.'/ticket/card.php'; $url_page_current = DOL_URL_ROOT.'/ticket/card.php';
if ($id || $track_id || $ref) { // Security check - Protection if external user
$res = $object->fetch($id, $ref, $track_id); //if ($user->societe_id > 0) access_forbidden();
} //if ($user->societe_id > 0) $socid = $user->societe_id;
// Security check
$result = restrictedArea($user, 'ticket', $object->id); $result = restrictedArea($user, 'ticket', $object->id);
$triggermodname = 'TICKETSUP_MODIFY'; $triggermodname = 'TICKETSUP_MODIFY';
@ -89,7 +106,9 @@ $now = dol_now();
* Actions * Actions
*/ */
// TODO Replace actions with common includes actions_addupdatedelete.inc.php $parameters=array();
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if ($cancel) if ($cancel)
{ {
@ -98,7 +117,7 @@ if ($cancel)
header("Location: ".$backtopage); header("Location: ".$backtopage);
exit; exit;
} }
$action=''; $action='view';
} }
// Do action // Do action
@ -157,26 +176,25 @@ include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be inc
$userstat = new User($db); $userstat = new User($db);
$form = new Form($db); $form = new Form($db);
$formticket = new FormTicket($db); $formticket = new FormTicket($db);
if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db);
if (! empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
}
if ($action == 'view' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen'
|| $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink')
{
if ($res > 0) {
// or for unauthorized internals users
if (!$user->societe_id && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
accessforbidden('', 0);
}
$help_url = 'FR:DocumentationModuleTicket'; $help_url = 'FR:DocumentationModuleTicket';
$page_title = $actionobject->getTitle($action); $page_title = $actionobject->getTitle($action);
llxHeader('', $page_title, $help_url); llxHeader('', $page_title, $help_url);
if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen'
|| $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink')
{
if ($res > 0)
{
// or for unauthorized internals users
if (!$user->societe_id && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
accessforbidden('', 0);
}
// Confirmation close // Confirmation close
if ($action == 'close') { if ($action == 'close') {
print $form->formconfirm($url_page_current . "?track_id=" . $object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", '', '', 1); print $form->formconfirm($url_page_current . "?track_id=" . $object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", '', '', 1);
@ -287,7 +305,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
$morehtmlref.= $object->subject; $morehtmlref.= $object->subject;
// Author // Author
if ($object->fk_user_create > 0) { if ($object->fk_user_create > 0) {
$morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' '; $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' : ';
$langs->load("users"); $langs->load("users");
$fuser = new User($db); $fuser = new User($db);
@ -295,10 +313,24 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
$morehtmlref .= $fuser->getNomUrl(0); $morehtmlref .= $fuser->getNomUrl(0);
} }
if (!empty($object->origin_email)) { if (!empty($object->origin_email)) {
$morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' '; $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' : ';
$morehtmlref .= $object->origin_email . ' <small>(' . $langs->trans("TicketEmailOriginIssuer") . ')</small>'; $morehtmlref .= $object->origin_email . ' <small>(' . $langs->trans("TicketEmailOriginIssuer") . ')</small>';
} }
// Thirdparty
if (! empty($conf->societe->enabled))
{
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' ';
if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) {
$morehtmlref.='<a href="' . $url_page_current . '?action=editcustomer&amp;track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a> : ';
}
if ($action == 'editcustomer') {
$morehtmlref.=$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
} else {
$morehtmlref.=$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
}
}
// Project // Project
if (! empty($conf->projet->enabled)) if (! empty($conf->projet->enabled))
{ {
@ -323,9 +355,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
if (! empty($object->fk_project)) { if (! empty($object->fk_project)) {
$proj = new Project($db); $proj = new Project($db);
$proj->fetch($object->fk_project); $proj->fetch($object->fk_project);
$morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">'; $morehtmlref.=$proj->getNomUrl(1);
$morehtmlref.=$proj->ref;
$morehtmlref.='</a>';
} else { } else {
$morehtmlref.=''; $morehtmlref.='';
} }
@ -385,24 +415,6 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
} }
print '</td></tr>'; print '</td></tr>';
// Thirdparty
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('ThirdParty');
print '</td>';
if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) {
print '<td align="right"><a href="' . $url_page_current . '?action=editcustomer&amp;track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a></td>';
}
print '</tr></table>';
print '</td><td colspan="3">';
if ($action == 'editcustomer') {
$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->fk_soc, 'editcustomer', ($object->fk_soc ? 's.rowid <> ' . $object->fk_soc : ''), 1);
} else {
$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->fk_soc, 'none', 's.rowid <> ' . $object->fk_soc, 1);
}
print '</td></tr>';
// User assigned // User assigned
print '<tr><td>' . $langs->trans("AssignedTo") . '</td><td>'; print '<tr><td>' . $langs->trans("AssignedTo") . '</td><td>';
if ($object->fk_user_assign > 0) { if ($object->fk_user_assign > 0) {
@ -692,31 +704,21 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
print '</div>'; print '</div>';
} }
// Contract
if ($action == 'sel_contract') {
if (!empty($conf->contrat->enabled)) {
$langs->load('contrats');
print load_fiche_titre($langs->trans('LinkToAContract'), '', 'title_commercial.png');
$form_contract = new FormContract($db);
$form_contract->formSelectContract(
$url_page_current.'?track_id='.$object->track_id,
$object->fk_soc,
GETPOST('contractid'),
'contractid'
);
}
}
print '</div></div></div>'; print '</div></div></div>';
print '<div style="clear:both"></div>'; print '<div style="clear:both"></div>';
print dol_fiche_end(); dol_fiche_end();
/* ActionBar */ // Buttons for actions
print '<div class="tabsAction">'; if ($action != 'presend' && $action != 'editline') {
print '<div class="tabsAction">'."\n";
$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 (empty($reshook))
{
// Show link to add a message (if read and not closed) // Show link to add a message (if read and not closed)
if ($object->fk_statut < 8 && $action != "add_message") { if ($object->fk_statut < 8 && $action != "add_message") {
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=add_message">' . $langs->trans('TicketAddMessage') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=add_message">' . $langs->trans('TicketAddMessage') . '</a></div>';
@ -731,11 +733,6 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
print '<div class="inline-block divButAction"><a class="butAction" href="' . dol_buildpath('/fichinter/card.php', 1) . '?action=create&socid=' . $object->fk_soc . '&origin=ticket_ticket&originid=' . $object->id . '">' . $langs->trans('TicketAddIntervention') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="' . dol_buildpath('/fichinter/card.php', 1) . '?action=create&socid=' . $object->fk_soc . '&origin=ticket_ticket&originid=' . $object->id . '">' . $langs->trans('TicketAddIntervention') . '</a></div>';
} }
// Button to link to a contract
if ($user->rights->ticket->write && $object->fk_statut < 5 && $user->rights->contrat->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=sel_contract">' . $langs->trans('LinkToAContract') . '</a></div>';
}
// Close ticket if statut is read // Close ticket if statut is read
if ($object->fk_statut > 0 && $object->fk_statut < 8 && $user->rights->ticket->write) { if ($object->fk_statut > 0 && $object->fk_statut < 8 && $user->rights->ticket->write) {
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=close">' . $langs->trans('CloseTicket') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=close">' . $langs->trans('CloseTicket') . '</a></div>';
@ -750,21 +747,38 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
if ($user->rights->ticket->delete && !$user->societe_id) { if ($user->rights->ticket->delete && !$user->societe_id) {
print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?track_id=' . $object->track_id . '&action=delete">' . $langs->trans('Delete') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?track_id=' . $object->track_id . '&action=delete">' . $langs->trans('Delete') . '</a></div>';
} }
print '</div>'; }
print '</div>'."\n";
}
if ($action == 'view' || $action == 'edit_message_init') {
print '<div class="fichecenter"><div class="">';
//print '<div style="float: left; width:49%; margin-right: 1%;">'; // Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'edit_message_init')
{
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
// Message list // Message list
print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket'); print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket');
$show_private_message = ($user->societe_id ? 0 : 1); $show_private_message = ($user->societe_id ? 0 : 1);
$actionobject->viewTicketTimelineMessages($show_private_message, true, $object); $actionobject->viewTicketTimelineMessages($show_private_message, true, $object);
print '</div><!-- fichehalfleft --> '; print '</div></div>';
print '</div><!-- fichecenter -->'; print '</div><!-- fichecenter -->';
print '<br style="clear: both">'; print '<br style="clear: both">';
} elseif ($action == 'add_message') { }
elseif ($action == 'add_message')
{
$action='new_message'; $action='new_message';
$modelmail='ticket_send'; $modelmail='ticket_send';
@ -828,15 +842,8 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
print '</div>'; print '</div>';
} }
} }
} // End action view }
/***************************************************
* LINKED OBJECT BLOCK
*
* Put here code to view linked object
****************************************************/
$somethingshown = $form->showLinkedObjectBlock($object);
// End of page // End of page
llxFooter(''); llxFooter();
$db->close(); $db->close();