FIX Filter on status, closing opening status

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
* Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr> * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
* Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com> * Copyright (C) 2018 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2019 Juanjo Menent <jmenent@2byte.es> * 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 * 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 * 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 // Load translation files required by the page
$langs->loadLangs(array("ticket", "companies", "other", "projects")); $langs->loadLangs(array("ticket", "companies", "other", "projects"));
// Get parameters // Get parameters
$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... $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) $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
@ -145,6 +144,12 @@ if ($project_ref)
$search_fk_project = $projectid; $search_fk_project = $projectid;
} }
$permissiontoread = $user->rights->ticket->read;
$permissiontoadd = $user->rights->ticket->write;
$permissiontodelete = $user->rights->ticket->delete;
$error = 0;
/* /*
* Actions * Actions
@ -183,10 +188,95 @@ if (empty($reshook))
// Mass actions // Mass actions
$objectclass = 'Ticket'; $objectclass = 'Ticket';
$objectlabel = 'Ticket'; $objectlabel = 'Ticket';
$permissiontoread = $user->rights->ticket->read;
$permissiontodelete = $user->rights->ticket->delete;
$uploaddir = $conf->ticket->dir_output; $uploaddir = $conf->ticket->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; 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') if ($key == 'fk_statut')
{ {
$tmpstatus = ''; $newarrayofstatus = array();
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."'"; foreach($search['fk_statut'] as $key2 => $val2) {
if ($search['fk_statut'] == 'closeall' || in_array('closeall', $search['fk_statut'])) $tmpstatus .= ($tmpstatus ? ',' : '')."'".Ticket::STATUS_CLOSED."', '".Ticket::STATUS_CANCELED."'"; if (in_array($val2, array('openall', 'closeall'))) continue;
if ($tmpstatus) $sql .= " AND fk_statut IN (".$tmpstatus.")"; $newarrayofstatus[] = $val2;
elseif (is_array($search[$key]) && count($search[$key])) $sql .= natural_search($key, join(',', $search[$key]), 2); }
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; continue;
} }
if ($key == 'fk_user_assign') if ($key == 'fk_user_assign')
@ -450,6 +552,8 @@ $arrayofmassactions = array(
//'presend'=>$langs->trans("SendByMail"), //'presend'=>$langs->trans("SendByMail"),
//'builddoc'=>$langs->trans("PDFMerge"), //'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 ($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(); if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
$massactionbutton = $form->selectMassAction('', $arrayofmassactions); $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
@ -547,8 +651,8 @@ foreach ($object->fields as $key => $val)
$arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --'; $arrayofstatus['openall'] = '-- '.$langs->trans('OpenAll').' --';
foreach ($object->statuts_short as $key2 => $val2) foreach ($object->statuts_short as $key2 => $val2)
{ {
$arrayofstatus[$key2] = $val2; if ($key2 == Ticket::STATUS_CLOSED) $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --';
if ($key2 == '6') $arrayofstatus['closeall'] = '-- '.$langs->trans('ClosedAll').' --'; $arrayofstatus[$key2] = $val2;
} }
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">'; print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
//var_dump($arrayofstatus);var_dump($search['fk_statut']);var_dump(array_values($search[$key])); //var_dump($arrayofstatus);var_dump($search['fk_statut']);var_dump(array_values($search[$key]));