From 873f43db9470548e8ae5d818677913bb74f31ca7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 1 Oct 2018 03:19:21 +0200 Subject: [PATCH] Uniformize interface for tickets --- htdocs/core/class/html.form.class.php | 23 +- .../modulebuilder/template/myobject_card.php | 20 +- htdocs/ticket/card.php | 349 +++++++++--------- 3 files changed, 202 insertions(+), 190 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index cee64d930cc..10af8517a73 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4506,21 +4506,23 @@ class Form * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @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 int $nooutput No print output. Return it only. * @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 global $langs; + $out = ''; if ($htmlname != "none") { - print '
'; - print ''; - print ''; - print $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); - print ''; - print '
'; + $out.='
'; + $out.= ''; + $out.= ''; + $out.= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); + $out.= ''; + $out.= '
'; } else { @@ -4529,13 +4531,16 @@ class Form require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php'; $soc = new Societe($this->db); $soc->fetch($selected); - print $soc->getNomUrl($langs); + $out.= $soc->getNomUrl($langs); } else { - print " "; + $out.= " "; } } + + if ($nooutput) return $out; + else print $out; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 9ba0a5a4ad5..26643bd7c33 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -88,19 +88,18 @@ $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 (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); } 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 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 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 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)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; + $morehtmlref.=$proj->getNomUrl(); } else { $morehtmlref.=''; } @@ -410,7 +410,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Select mail models is same action as presend if (GETPOST('modelselected')) { - $action = 'presend'; + $action = 'presend'; } if ($action != 'presend') diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index b736b49646f..c4718c395b3 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -55,26 +55,43 @@ $action = GETPOST('action', 'alpha', 3); $hookmanager->initHooks(array('ticketcard','globalcard')); $object = new Ticket($db); - $extrafields = new ExtraFields($db); +// Fetch optionals attributes and labels $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); -if (!$action) { - $action = 'view'; +// Initialize array of search criterias +$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 if (GETPOST('modelselected','alpha')) { $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 $url_page_current = DOL_URL_ROOT.'/ticket/card.php'; -if ($id || $track_id || $ref) { - $res = $object->fetch($id, $ref, $track_id); -} - -// Security check +// 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, 'ticket', $object->id); $triggermodname = 'TICKETSUP_MODIFY'; @@ -89,7 +106,9 @@ $now = dol_now(); * 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) { @@ -98,7 +117,7 @@ if ($cancel) header("Location: ".$backtopage); exit; } - $action=''; + $action='view'; } // Do action @@ -157,26 +176,25 @@ include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be inc $userstat = new User($db); $form = new Form($db); $formticket = new FormTicket($db); +if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db); -if (! empty($conf->projet->enabled)) { - $formproject = new FormProjets($db); -} +$help_url = 'FR:DocumentationModuleTicket'; +$page_title = $actionobject->getTitle($action); -if ($action == 'view' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' +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) { + 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'; - $page_title = $actionobject->getTitle($action); - - llxHeader('', $page_title, $help_url); - // Confirmation close if ($action == 'close') { 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; // Author if ($object->fk_user_create > 0) { - $morehtmlref .= '
' . $langs->trans("CreatedBy") . ' '; + $morehtmlref .= '
' . $langs->trans("CreatedBy") . ' : '; $langs->load("users"); $fuser = new User($db); @@ -295,10 +313,24 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti $morehtmlref .= $fuser->getNomUrl(0); } if (!empty($object->origin_email)) { - $morehtmlref .= '
' . $langs->trans("CreatedBy") . ' '; + $morehtmlref .= '
' . $langs->trans("CreatedBy") . ' : '; $morehtmlref .= $object->origin_email . ' (' . $langs->trans("TicketEmailOriginIssuer") . ')'; } + // Thirdparty + if (! empty($conf->societe->enabled)) + { + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' '; + if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) { + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . ' : '; + } + 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 if (! empty($conf->projet->enabled)) { @@ -323,9 +355,7 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti if (! empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; + $morehtmlref.=$proj->getNomUrl(1); } else { $morehtmlref.=''; } @@ -385,24 +415,6 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti } print ''; - // Thirdparty - print ''; - print ''; - if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) { - print ''; - } - print '
'; - print $langs->trans('ThirdParty'); - print '' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '
'; - print ''; - - 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 ''; - // User assigned print '' . $langs->trans("AssignedTo") . ''; if ($object->fk_user_assign > 0) { @@ -692,151 +704,146 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti print ''; } - // 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 ''; print '
'; - print dol_fiche_end(); + dol_fiche_end(); - /* ActionBar */ - print '
'; + // Buttons for actions + if ($action != 'presend' && $action != 'editline') { + print '
'."\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'); - // Show link to add a message (if read and not closed) - if ($object->fk_statut < 8 && $action != "add_message") { - print ''; - } + if (empty($reshook)) + { + // Show link to add a message (if read and not closed) + if ($object->fk_statut < 8 && $action != "add_message") { + print ''; + } - // Link to create an intervention - // socid is needed otherwise fichinter ask it and forgot origin after form submit :\ - if (!$object->fk_soc && $user->rights->ficheinter->creer) { - print ''; - } - if ($object->fk_soc > 0 && $object->fk_statut < 8 && $user->rights->ficheinter->creer) { - print ''; - } + // Link to create an intervention + // socid is needed otherwise fichinter ask it and forgot origin after form submit :\ + if (!$object->fk_soc && $user->rights->ficheinter->creer) { + print ''; + } + if ($object->fk_soc > 0 && $object->fk_statut < 8 && $user->rights->ficheinter->creer) { + print ''; + } - // Button to link to a contract - if ($user->rights->ticket->write && $object->fk_statut < 5 && $user->rights->contrat->creer) { - print ''; - } + // Close ticket if statut is read + if ($object->fk_statut > 0 && $object->fk_statut < 8 && $user->rights->ticket->write) { + print ''; + } - // Close ticket if statut is read - if ($object->fk_statut > 0 && $object->fk_statut < 8 && $user->rights->ticket->write) { - print ''; - } + // Re-open ticket + if (!$user->socid && $object->fk_statut == 8 && !$user->societe_id) { + print ''; + } - // Re-open ticket - if (!$user->socid && $object->fk_statut == 8 && !$user->societe_id) { - print ''; - } - - // Delete ticket - if ($user->rights->ticket->delete && !$user->societe_id) { - print ''; - } - print '
'; - - if ($action == 'view' || $action == 'edit_message_init') { - print '
'; - - //print '
'; - // Message list - print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket'); - $show_private_message = ($user->societe_id ? 0 : 1); - $actionobject->viewTicketTimelineMessages($show_private_message, true, $object); - - print '
'; - print '
'; - print '
'; - } elseif ($action == 'add_message') { - $action='new_message'; - $modelmail='ticket_send'; - - print '
'; - print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticket'); - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) { - $newlang = $_REQUEST['lang_id']; - } - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { - $newlang = $object->default_lang; - } - - $formticket = new FormTicket($db); - - $formticket->action = $action; - $formticket->track_id = $object->track_id; - $formticket->id = $object->id; - - $formticket->withfile = 2; - $formticket->param = array('fk_user_create' => $user->id); - $formticket->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); - - // Tableau des parametres complementaires du post - $formticket->param['models']=$modelmail; - $formticket->param['models_id']=GETPOST('modelmailselected', 'int'); - //$formticket->param['socid']=$object->fk_soc; - $formticket->param['returnurl']=$_SERVER["PHP_SELF"].'?track_id='.$object->track_id; + // Delete ticket + if ($user->rights->ticket->delete && !$user->societe_id) { + print ''; + } + } + print '
'."\n"; + } - $formticket->withsubstit = 1; + // Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } - if ($object->fk_soc > 0) { - $object->fetch_thirdparty(); - $formticket->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; - } - $formticket->substit['__SIGNATURE__'] = $user->signature; - $formticket->substit['__TICKETSUP_TRACKID__'] = $object->track_id; - $formticket->substit['__TICKETSUP_REF__'] = $object->ref; - $formticket->substit['__TICKETSUP_SUBJECT__'] = $object->subject; - $formticket->substit['__TICKETSUP_TYPE__'] = $object->type_code; - $formticket->substit['__TICKETSUP_CATEGORY__'] = $object->category_code; - $formticket->substit['__TICKETSUP_SEVERITY__'] = $object->severity_code; - $formticket->substit['__TICKETSUP_MESSAGE__'] = $object->message; - $formticket->substit['__TICKETSUP_PROGRESSION__'] = $object->progress; - if ($object->fk_user_assign > 0) { - $userstat->fetch($object->fk_user_assign); - $formticket->substit['__TICKETSUP_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); - } + if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'edit_message_init') + { + print '
'; + print ''; // ancre - if ($object->fk_user_create > 0) { - $userstat->fetch($object->fk_user_create); - $formticket->substit['__TICKETSUP_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); - } + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket')); + $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + + print '
'; + + // Message list + print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket'); + $show_private_message = ($user->societe_id ? 0 : 1); + $actionobject->viewTicketTimelineMessages($show_private_message, true, $object); + + print '
'; + print '
'; + print '
'; + } + elseif ($action == 'add_message') + { + $action='new_message'; + $modelmail='ticket_send'; + + print '
'; + print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticket'); + + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) { + $newlang = $_REQUEST['lang_id']; + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->default_lang; + } + + $formticket = new FormTicket($db); + + $formticket->action = $action; + $formticket->track_id = $object->track_id; + $formticket->id = $object->id; + + $formticket->withfile = 2; + $formticket->param = array('fk_user_create' => $user->id); + $formticket->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); + + // Tableau des parametres complementaires du post + $formticket->param['models']=$modelmail; + $formticket->param['models_id']=GETPOST('modelmailselected', 'int'); + //$formticket->param['socid']=$object->fk_soc; + $formticket->param['returnurl']=$_SERVER["PHP_SELF"].'?track_id='.$object->track_id; - $formticket->showMessageForm('100%'); - print '
'; - } - } -} // End action view + $formticket->withsubstit = 1; -/*************************************************** - * LINKED OBJECT BLOCK - * - * Put here code to view linked object - ****************************************************/ -$somethingshown = $form->showLinkedObjectBlock($object); + if ($object->fk_soc > 0) { + $object->fetch_thirdparty(); + $formticket->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; + } + $formticket->substit['__SIGNATURE__'] = $user->signature; + $formticket->substit['__TICKETSUP_TRACKID__'] = $object->track_id; + $formticket->substit['__TICKETSUP_REF__'] = $object->ref; + $formticket->substit['__TICKETSUP_SUBJECT__'] = $object->subject; + $formticket->substit['__TICKETSUP_TYPE__'] = $object->type_code; + $formticket->substit['__TICKETSUP_CATEGORY__'] = $object->category_code; + $formticket->substit['__TICKETSUP_SEVERITY__'] = $object->severity_code; + $formticket->substit['__TICKETSUP_MESSAGE__'] = $object->message; + $formticket->substit['__TICKETSUP_PROGRESSION__'] = $object->progress; + if ($object->fk_user_assign > 0) { + $userstat->fetch($object->fk_user_assign); + $formticket->substit['__TICKETSUP_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + } + + if ($object->fk_user_create > 0) { + $userstat->fetch($object->fk_user_create); + $formticket->substit['__TICKETSUP_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname); + } + + + $formticket->showMessageForm('100%'); + print '
'; + } + } +} // End of page -llxFooter(''); +llxFooter(); $db->close();