FIX Filter on status, closing opening status

This commit is contained in:
Laurent Destailleur 2020-06-26 19:35:09 +02:00
parent d6346522b8
commit ee0bdde8c1
4 changed files with 123 additions and 17 deletions

View File

@ -1153,8 +1153,6 @@ if (!$error && $massaction == 'validate' && $permissiontoadd)
$result = $objecttmp->fetch($toselectid);
if ($result > 0)
{
//if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
//else
$result = $objecttmp->validate($user);
if ($result == 0)
{

View File

@ -491,7 +491,7 @@ if (empty($reshook)) {
if ($action == 'confirm_reopen' && $user->rights->ticket->manage && !GETPOST('cancel')) {
if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
// prevent browser refresh from reopening ticket several times
if ($object->fk_statut == Ticket::STATUS_CLOSED) {
if ($object->fk_statut == Ticket::STATUS_CLOSED || $object->fk_statut == Ticket::STATUS_CANCELED) {
$res = $object->setStatut(Ticket::STATUS_ASSIGNED);
if ($res) {
// Log action in ticket logs table

View File

@ -108,7 +108,8 @@ class Ticket extends CommonObject
/**
* @var int Ticket statut
*/
public $fk_statut;
public $fk_statut; // deprecated
public $status;
/**
* @var string State resolution
@ -463,7 +464,7 @@ class Ticket extends CommonObject
$sql .= " t.fk_user_assign,";
$sql .= " t.subject,";
$sql .= " t.message,";
$sql .= " t.fk_statut,";
$sql .= " t.fk_statut as status,";
$sql .= " t.resolution,";
$sql .= " t.progress,";
$sql .= " t.timing,";
@ -509,7 +510,10 @@ class Ticket extends CommonObject
$this->fk_user_assign = $obj->fk_user_assign;
$this->subject = $obj->subject;
$this->message = $obj->message;
$this->fk_statut = $obj->fk_statut;
$this->status = $obj->status;
$this->fk_statut = $this->status; // For backward compatibility
$this->resolution = $obj->resolution;
$this->progress = $obj->progress;
$this->timing = $obj->timing;

View File

@ -3,7 +3,7 @@
* Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
* Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -38,7 +38,6 @@ include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
// Load translation files required by the page
$langs->loadLangs(array("ticket", "companies", "other", "projects"));
// Get parameters
$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
@ -145,6 +144,12 @@ if ($project_ref)
$search_fk_project = $projectid;
}
$permissiontoread = $user->rights->ticket->read;
$permissiontoadd = $user->rights->ticket->write;
$permissiontodelete = $user->rights->ticket->delete;
$error = 0;
/*
* Actions
@ -183,10 +188,95 @@ if (empty($reshook))
// Mass actions
$objectclass = 'Ticket';
$objectlabel = 'Ticket';
$permissiontoread = $user->rights->ticket->read;
$permissiontodelete = $user->rights->ticket->delete;
$uploaddir = $conf->ticket->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
// Close records
if (!$error && $massaction == 'close' && $permissiontoadd)
{
$objecttmp = new $objectclass($db);
if (!$error)
{
$db->begin();
$nbok = 0;
foreach ($toselect as $toselectid)
{
$result = $objecttmp->fetch($toselectid);
if ($result > 0)
{
$result = $objecttmp->close($user);
if ($result < 0)
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
} else $nbok++;
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
if (!$error)
{
if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
$db->commit();
} else {
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
}
// Reopen records
if (!$error && $massaction == 'reopen' && $permissiontoadd)
{
$objecttmp = new $objectclass($db);
if (!$error)
{
$db->begin();
$nbok = 0;
foreach ($toselect as $toselectid)
{
$result = $objecttmp->fetch($toselectid);
if ($result > 0)
{
if ($objecttmp->status == Ticket::STATUS_CLOSED || $objecttmp->status == Ticket::STATUS_CANCELED) {
$result = $objecttmp->setStatut(Ticket::STATUS_ASSIGNED);
if ($result < 0)
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
} else $nbok++;
} else {
$langs->load("errors");
setEventMessages($langs->trans("ErrorObjectMustHaveStatusClosedToBeReOpened", $objecttmp->ref), null, 'errors');
$error++;
break;
}
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
if (!$error)
{
if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
$db->commit();
} else {
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
}
}
@ -236,11 +326,23 @@ foreach ($search as $key => $val)
{
if ($key == 'fk_statut')
{
$tmpstatus = '';
if ($search['fk_statut'] == 'openall' || in_array('openall', $search['fk_statut'])) $tmpstatus .= ($tmpstatus ? ',' : '')."'".Ticket::STATUS_NOT_READ."', '".Ticket::STATUS_READ."', '".Ticket::STATUS_ASSIGNED."', '".Ticket::STATUS_IN_PROGRESS."', '".Ticket::STATUS_NEED_MORE_INFO."', '".Ticket::STATUS_WAITING."'";
if ($search['fk_statut'] == 'closeall' || in_array('closeall', $search['fk_statut'])) $tmpstatus .= ($tmpstatus ? ',' : '')."'".Ticket::STATUS_CLOSED."', '".Ticket::STATUS_CANCELED."'";
if ($tmpstatus) $sql .= " AND fk_statut IN (".$tmpstatus.")";
elseif (is_array($search[$key]) && count($search[$key])) $sql .= natural_search($key, join(',', $search[$key]), 2);
$newarrayofstatus = array();
foreach($search['fk_statut'] as $key2 => $val2) {
if (in_array($val2, array('openall', 'closeall'))) continue;
$newarrayofstatus[] = $val2;
}
if ($search['fk_statut'] == 'openall' || in_array('openall', $search['fk_statut'])) {
$newarrayofstatus[] = Ticket::STATUS_NOT_READ;
$newarrayofstatus[] = Ticket::STATUS_ASSIGNED;
$newarrayofstatus[] = Ticket::STATUS_IN_PROGRESS;
$newarrayofstatus[] = Ticket::STATUS_NEED_MORE_INFO;
$newarrayofstatus[] = Ticket::STATUS_WAITING;
}
if ($search['fk_statut'] == 'closeall' || in_array('closeall', $search['fk_statut'])) {
$newarrayofstatus[] = Ticket::STATUS_CLOSED;
$newarrayofstatus[] = Ticket::STATUS_CANCELED;
}
if (count($newarrayofstatus)) $sql .= natural_search($key, join(',', $newarrayofstatus), 2);
continue;
}
if ($key == 'fk_user_assign')
@ -452,6 +554,8 @@ $arrayofmassactions = array(
//'presend'=>$langs->trans("SendByMail"),
//'builddoc'=>$langs->trans("PDFMerge"),
);
if ($user->rights->ticket->write) $arrayofmassactions['close'] = $langs->trans("Close");
if ($user->rights->ticket->write) $arrayofmassactions['reopen'] = $langs->trans("ReOpen");
if ($user->rights->ticket->delete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@ -549,8 +653,8 @@ foreach ($object->fields as $key => $val)
$arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
foreach ($object->statuts_short as $key2 => $val2)
{
$arrayofstatus[$key2] = $val2;
if ($key2 == '6') $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
if ($key2 == Ticket::STATUS_CLOSED) $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
$arrayofstatus[$key2] = $val2;
}
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
//var_dump($arrayofstatus);var_dump($search['fk_statut']);var_dump(array_values($search[$key]));