Debug usage of extrafields for ticket module

This commit is contained in:
Laurent Destailleur 2018-04-12 23:17:46 +02:00
parent 3cecfd02c7
commit ace55ba569
12 changed files with 117 additions and 139 deletions

View File

@ -23,7 +23,7 @@
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once DOL_DOCUMENT_ROOT."/ticketsup/class/ticketsup.class.php";
require_once DOL_DOCUMENT_ROOT."/core/lib/ticketsup.lib.php";
@ -172,12 +172,6 @@ if ($action == 'setvarother') {
$error++;
}
$param_extrafields_public = GETPOST('TICKETS_EXTRAFIELDS_PUBLIC', 'alpha');
$res = dolibarr_set_const($db, 'TICKETS_EXTRAFIELDS_PUBLIC', $param_extrafields_public, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
$error++;
}
$param_disable_email = GETPOST('TICKETS_DISABLE_ALL_MAILS', 'alpha');
$res = dolibarr_set_const($db, 'TICKETS_DISABLE_ALL_MAILS', $param_disable_email, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
@ -241,7 +235,7 @@ dol_fiche_head($head, 'settings', $langs->trans("Module56000Name"), -1, "tickets
print $langs->trans("TicketsupSetupDictionaries") . ' : <a href="' . dol_buildpath('/admin/dict.php', 1) . '" >' . dol_buildpath('/admin/dict.php', 2) . '</a><br>';
print $langs->trans("TicketsupPublicAccess") . ' : <a href="' . dol_buildpath('/ticketsup/public/index.php', 1) . '" target="_blank" >' . dol_buildpath('/ticketsup/public/index.php', 2) . '</a>';
print $langs->trans("TicketsupPublicAccess") . ' : <a href="' . dol_buildpath('/public/ticketsup/index.php', 1) . '" target="_blank" >' . dol_buildpath('/public/ticketsup/index.php', 2) . '</a>';
dol_fiche_end();
@ -416,21 +410,6 @@ print $form->textwithpicto('', $langs->trans("TicketsShowCompanyLogoHelp"), 1, '
print '</td>';
print '</tr>';
// Display extrafields into public interface
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowExtrafieldsIntoPublicArea") . '</td>';
print '<td align="left">';
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('TICKETS_EXTRAFIELDS_PUBLIC');
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("TICKETS_EXTRAFIELDS_PUBLIC", $arrval, $conf->global->TICKETS_EXTRAFIELDS_PUBLIC);
}
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsShowExtrafieldsIntoPublicAreaHelp"), 1, 'help');
print '</td>';
print '</tr>';
print '</table><br>';
print_titre($langs->trans("TicketParams"));

View File

@ -140,7 +140,7 @@ class FormTicketsup
print "\n<!-- Begin form TICKETSUP -->\n";
print '<form method="post" name="ticketsup" id="form_create_ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">';
print '<form method="POST" style="margin-bottom: 10px;" name="ticketsup" id="form_create_ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="' . $this->action . '">';
foreach ($this->param as $key => $value) {
@ -148,8 +148,8 @@ class FormTicketsup
}
print '<input type="hidden" name="fk_user_create" value="' . $this->fk_user_create . '">';
print '<div class="tabBar tabBarWithBottom">';
print '<table class="border" width="' . $width . '">';
print '<div class="">';
print '<table class="tableticket" width="' . $width . '">';
if ($this->withref) {
@ -385,11 +385,10 @@ class FormTicketsup
}
// Other attributes
if ($this->withextrafields == 1) {
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && !empty($extrafields->attribute_label)) {
print $ticketstat->showOptionals($extrafields, 'edit');
}
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $ticketstat, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && is_array($extrafields->attributes[$ticketstat->table_element]['label']))
{
print $ticketstat->showOptionals($extrafields, 'edit');
}
print '</table>';

View File

@ -236,14 +236,29 @@ class InterfaceTicketEmail extends DolibarrTriggers
$message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>';
$message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>';
$message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>';
// Extrafields
if ($conf->global->TICKETS_EXTRAFIELDS_PUBLIC) {
if (is_array($object->array_options) && count($object->array_options) > 0) {
foreach ($object->array_options as $key => $value) {
$message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>';
}
}
foreach ($this->attributes[$object->table_element]['label'] as $key => $value)
{
$enabled = 1;
if ($enabled && isset($this->attributes[$object->table_element]['list'][$key]))
{
$enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
}
$perms = 1;
if ($perms && isset($this->attributes[$object->table_element]['perms'][$key]))
{
$perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
}
$qualified = true;
if (empty($enabled)) $qualified = false;
if (empty($perms)) $qualified = false;
if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>';
}
$message_customer.='</ul>';
$message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>';
$url_public_ticket = ($conf->global->TICKETS_URL_PUBLIC_INTERFACE?$conf->global->TICKETS_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/ticketsup/public/view.php', 2)).'?track_id='.$object->track_id;

View File

@ -115,8 +115,6 @@ TicketsShowCompanyLogo=Display the logo of the company in the public interface
TicketsShowCompanyLogoHelp=Enable this option to hide the logo of the main company in the pages of the public interface
TicketsEmailAlsoSendToMainAddress=Also send notification to main email address
TicketsEmailAlsoSendToMainAddressHelp=Enable this option to send an email to "Notification email from" address (see setup below)
TicketsShowExtrafieldsIntoPublicArea=Show Extras fields in the public interface
TicketsShowExtrafieldsIntoPublicAreaHelp=When this option is enabled, additional attributes defined on the tickets will be shown in the public interface of ticket creation.
TicketsLimitViewAssignedOnly=Restrict the display to tickets assigned to the current user (not effective for external users, always be limited to the thirdparty they depend on)
TicketsLimitViewAssignedOnlyHelp=Only tickets assigned to the current user will be visible. Does not apply to a user with tickets management rights.
TicketsActivatePublicInterface=Activate public interface
@ -264,7 +262,7 @@ TicketNewEmailBodyInfosTrackId=Ticket tracking number : %s
TicketNewEmailBodyInfosTrackUrl=You can view the progress of the ticket by clicking the link above.
TicketNewEmailBodyInfosTrackUrlCustomer=You can view the progress of the ticket in the specific interface by clicking the following link
TicketEmailPleaseDoNotReplyToThisEmail=Please do not reply directly to this email! Use the link to reply into the interface.
TicketPublicInfoCreateTicket=This form allows you to record a trouble ticket in our management system.
TicketPublicInfoCreateTicket=This form allows you to record a support ticket in our management system.
TicketPublicPleaseBeAccuratelyDescribe=Please accurately describe the problem. Provide the most information possible to allow us to correctly identify your request.
TicketPublicMsgViewLogIn=Please enter ticket tracking ID
TicketTrackId=Tracking ID

View File

@ -1,7 +1,6 @@
<?php
/*
* Copyright (C) - 2013-2016 Jean-François FERRY <hello@librethic.io>
* 2016 Christophe Battarel <christophe@altairis.fr>
/* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
* Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
*
* 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
@ -18,9 +17,9 @@
*/
/**
* Display public form to add new ticket
* Display public form to add new ticket
*
* @package ticketsup
* \ingroup ticketsup
*/
if (!defined('NOREQUIREUSER')) {
define('NOREQUIREUSER', '1');
@ -47,8 +46,8 @@ define("NOCSRFCHECK", 1); // We accept to go on this page from external web site
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
@ -66,6 +65,10 @@ $action = GETPOST('action', 'alpha');
$object = new Ticketsup($db);
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
/*
* Add file in email form
*/
@ -165,11 +168,7 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) {
$usertoassign = $contacts[0]->id;
}
if (!empty($conf->global->TICKETS_EXTRAFIELDS_PUBLIC) && $conf->global->TICKETS_EXTRAFIELDS_PUBLIC == "1") {
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
}
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
// Generate new ref
$object->ref = $object->getDefaultRef();
@ -251,11 +250,26 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) {
$message_admin .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>';
$message_admin .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>';
$message_admin .= '<li>' . $langs->trans('From') . ' : ' . $object->origin_email . '</li>';
if (is_array($object->array_options) && count($object->array_options) > 0) {
foreach ($object->array_options as $key => $value) {
$message_admin .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>';
}
if (is_array($extrafields->attributes[$object->table_element]['label']))
{
foreach($extrafields->attributes[$object->table_element]['label'] as $key => $val)
{
$qualified = true;
if ($qualified && isset($this->attributes[$object->table_element]['list'][$key]))
{
$qualified = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
if (empty($result) || $result == 2) $qualified = false;
}
if ($qualified && isset($this->attributes[$object->table_element]['perms'][$key]))
{
$qualified = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
}
if ($qualified) $message_admin .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>';
}
}
$message_admin .= '</ul>';
$message_admin .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>';
$message_admin .= '<p><a href="' . dol_buildpath('/ticketsup/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>';
@ -303,13 +317,15 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) {
}
}
/***************************************************
* PAGE
*
****************************************************/
/*
* View
*/
$arrayofjs = array();
$arrayofcss = array('/opensurvey/css/style.css', '/ticketsup/css/styles.css', '/ticketsup/css/bg.css.php');
llxHeaderTicket($langs->trans("CreateTicket"), "", 0, 0, $arrayofjs, $arrayofcss);
$form = new Form($db);
@ -332,9 +348,6 @@ if ($action != "infos_success") {
$formticket->withemail = 1;
$formticket->ispublic = 1;
$formticket->withfile = 2;
if (!empty($conf->global->TICKETS_EXTRAFIELDS_PUBLIC)) {
$formticket->withextrafields = $conf->global->TICKETS_EXTRAFIELDS_PUBLIC;
}
$formticket->action = 'create_ticket';
$formticket->param = array('returnurl' => $_SERVER['PHP_SELF']);
@ -343,9 +356,9 @@ if ($action != "infos_success") {
$defaultref = '';
}
print load_fiche_titre($langs->trans('NewTicket'), '', 'ticketsup-32@ticketsup', 0);
print load_fiche_titre($langs->trans('NewTicket'), '', '', 0, 0, 'marginleftonly');
print '<div class="info">' . $langs->trans('TicketPublicInfoCreateTicket') . '</div>';
print '<div class="info marginleftonly marginrightonly">' . $langs->trans('TicketPublicInfoCreateTicket') . '</div>';
$formticket->showForm();
} else {
print '<div class="ok">' . $langs->trans('MesgInfosPublicTicketCreatedWithTrackId', '<strong>' . $object->track_id . '</strong>');
@ -354,13 +367,8 @@ if ($action != "infos_success") {
}
print '</div>';
/***************************************************
* LINKED OBJECT BLOCK
*
* Put here code to view linked object
****************************************************/
//$somethingshown=$object->showLinkedObjectBlock();
// End of page
$db->close();
llxFooter('');
$db->close();

View File

@ -44,8 +44,8 @@ if (!defined("NOLOGIN")) {
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
// Load traductions files requiredby by page

View File

@ -36,8 +36,8 @@ if (!defined("NOLOGIN")) {
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticketsup.lib.php';
// Load traductions files requiredby by page
$langs->load("companies");
@ -122,10 +122,11 @@ if ($action == "view_ticketlist") {
}
$object->doActions($action);
/***************************************************
* VIEW
*
****************************************************/
/*
* View
*/
$form = new Form($db);
$user_assign = new User($db);
@ -293,8 +294,8 @@ if ($action == "view_ticketlist") {
$sql .= " t.datec,";
$sql .= " t.date_read,";
$sql .= " t.date_close,";
$sql .= " t.tms";
$sql .= ", type.label as type_label, category.label as category_label, severity.label as severity_label";
$sql .= " t.tms,";
$sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
// Add fields for extrafields
foreach ($extrafields->attribute_list as $key => $val) {
$sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef." . $key . ' as options_' . $key : '');

View File

@ -36,8 +36,8 @@ if (!defined("NOLOGIN")) {
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/actions_ticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/ticketsup/lib/ticketsup.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticketsup.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticketsup.lib.php';
// Load traductions files requiredby by page
$langs->load("companies");

View File

@ -53,11 +53,11 @@ $action = GETPOST('action', 'alpha', 3);
// Initialize technical object to manage hooks of ticketsup. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('ticketsupcard','globalcard'));
$object = new Ticketsup($db);
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$object = new Ticketsup($db);
if (!$action) {
$action = 'view';
}
@ -85,6 +85,28 @@ $result = restrictedArea($user, 'ticketsup', $object->id);
$actionobject = new ActionsTicketsup($db);
$actionobject->doActions($action, $object);
if ($action == "update_extras" && $user->rights->ticketsup->write && !GETPOST('cancel','alpha'))
{
$triggermodname = 'TICKETSUP_MODIFY';
$res = $object->fetch(GETPOST('id','int'), '', GETPOST('track_id','alpha'));
$attributekey = GETPOST('attribute','alpha');
$attributekeylong = 'options_'.$attributekey;
$object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha');
$result = $object->updateExtraField($attributekey, $triggermodname, $user);
if ($result > 0)
{
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
$action = 'view';
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action = 'edit_extras';
}
}
$permissiondellink = $user->rights->ticketsup->write;
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
@ -100,7 +122,9 @@ $form = new Form($db);
$formticket = new FormTicketsup($db);
$formproject = new FormProjets($db);
if ($action == 'view' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen' || $action == 'editsubject' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') {
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
@ -412,29 +436,8 @@ if ($action == 'view' || $action == 'add_message' || $action == 'close' || $acti
print '</td></tr>';
// Other attributes
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && !empty($extrafields->attribute_label)) {
if ($action == "edit_extrafields") {
print '<form method="post" name="form_edit_extrafields" enctype="multipart/form-data" action="' . $url_page_current . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="set_extrafields">';
print '<input type="hidden" name="track_id" value="' . $object->track_id . '">';
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print $object->showOptionals($extrafields, 'edit');
print '<tr><td colspan="2" align="center">';
print ' <input class="button" type="submit" name="btn_edit_extrafields" value="' . $langs->trans("Modify") . '" />';
print ' <input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '" />';
print '</tr>';
print '</form>';
} else {
print $object->showOptionals($extrafields);
if ($user->rights->ticketsup->write) {
print '<tr><td colspan="2" align="center">';
print '<a href="' . $url_page_current . '?track_id=' . $object->track_id . '&action=edit_extrafields">' . img_picto('', 'edit') . ' ' . $langs->trans('Edit') . '</a>';
print '</tr>';
}
}
}
print '</table>';

View File

@ -292,7 +292,7 @@ class ActionsTicketsup
$object->description = GETPOST("description");
//...
$ret = $object->update(GETPOST('id'), $user);
$ret = $object->update($user);
if ($ret <= 0) {
$error++;
$this->errors = $object->error;
@ -523,24 +523,8 @@ class ActionsTicketsup
}
}
if ($action == "set_extrafields" && GETPOST('btn_edit_extrafields') && $user->rights->ticketsup->write && !GETPOST('cancel')) {
$res = $this->fetch('', '', GETPOST('track_id','alpha'));
$extrafields = new ExtraFields($this->db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
$ret = $object->update($user);
if ($ret > 0) {
setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
$url = 'card.php?action=view&track_id=' . $object->track_id;
header("Location: " . $url);
exit();
}
$action = 'view';
} // Reopen ticket
elseif ($action == 'confirm_reopen' && $user->rights->ticketsup->manage && !GETPOST('cancel')) {
if ($action == 'confirm_reopen' && $user->rights->ticketsup->manage && !GETPOST('cancel')) {
if ($this->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
// prevent browser refresh from reopening ticket several times
if ($object->fk_statut == 8) {

View File

@ -103,13 +103,3 @@ div.corps {
}
#form_create_ticket input.text,
#form_create_ticket textarea { width:450px;}
div.info {
background: none repeat scroll 0% 0% rgb(252, 245, 184);
padding: 2px 4px 2px 6px;
margin: 1.5em 1em;
border: 1px solid rgb(188, 169, 54);
font-weight: normal;
}
div.warning { color: #333333;}

View File

@ -194,7 +194,8 @@ foreach($object->fields as $key => $val)
$sql.='t.'.$key.', ';
}
// Add fields from extrafields
foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
if (! empty($extrafields->attributes[$object->table_element]['label']))
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.' as options_'.$key.', ' : '');
// Add fields from hooks
$parameters=array();
$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook