NEW #18046 Add ticket categories views

This commit is contained in:
Théo David 2021-07-01 19:30:00 +02:00
parent aec4d6016c
commit 110b0fecf5
3 changed files with 108 additions and 2 deletions

View File

@ -142,6 +142,11 @@ if ($id > 0 && $removeelem > 0) {
$tmpobject = new User($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'user';
} elseif ($type == Categorie::TYPE_TICKET && $user->rights->ticket->write) {
require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
$tmpobject = new Ticket($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'ticket';
}
$result = $object->del_type($tmpobject, $elementtype);
@ -167,7 +172,8 @@ if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confi
if ($elemid && $action == 'addintocategory' &&
(($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) ||
($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) ||
($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer)
($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) ||
($type == Categorie::TYPE_TICKET && $user->rights->ticket->write)
)) {
if ($type == Categorie::TYPE_PRODUCT) {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
@ -181,6 +187,10 @@ if ($elemid && $action == 'addintocategory' &&
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$newobject = new Societe($db);
$elementtype = 'supplier';
} elseif ($type == Categorie::TYPE_TICKET) {
require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
$newobject = new Ticket($db);
$elementtype = 'ticket';
}
$result = $newobject->fetch($elemid);
@ -1024,6 +1034,84 @@ if ($type == Categorie::TYPE_WAREHOUSE) {
}
}
if ($type == Categorie::TYPE_TICKET)
{
$permission = ($user->rights->categorie->creer || $user->rights->categorie->creer);
$tickets = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($tickets < 0)
{
dol_print_error($db, $object->error, $object->errors);
} else {
// Form to add record into a category
$showclassifyform = 1;
if ($showclassifyform)
{
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
print '<input type="hidden" name="type" value="'.$typeid.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="addintocategory">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>';
print $langs->trans("AddTicketIntoCategory").' &nbsp;';
$form->select_tickets('', 'elemid');
print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
print '</tr>';
print '</table>';
print '</form>';
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
print '<input type="hidden" name="type" value="'.$typeid.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="list">';
print '<br>';
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($tickets); $nbtotalofrecords = ''; $newcardbutton = '';
print_barre_liste($langs->trans("Ticket"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'ticket', 0, $newcardbutton, '', $limit);
print '<table class="noborder centpercent">'."\n";
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Ref").'</td></tr>'."\n";
if (count($tickets) > 0)
{
$i = 0;
foreach ($tickets as $ticket)
{
$i++;
if ($i > $limit) break;
print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">';
print $ticket->getNomUrl(1);
print "</td>\n";
print '<td class="tdtop">'.$ticket->label."</td>\n";
// Link to delete from category
print '<td class="right">';
if ($permission)
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$ticket->id."'>";
print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
print "</a>";
}
print '</td>';
print "</tr>\n";
}
} else {
print '<tr class="oddeven"><td colspan="2" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</td></tr>';
}
print "</table>\n";
print '</form>'."\n";
}
}
// End of page
llxFooter();

View File

@ -17,6 +17,7 @@ ContactsCategoriesArea=Espace tags/catégories de contacts
AccountsCategoriesArea=Espace des tags/categories de comptes bancaires
ProjectsCategoriesArea=Espace des tags/catégories des projets
UsersCategoriesArea=Espace des tags/catégories des utilisateurs
TicketsCategoriesArea=Espace tags/catégories des tickets
SubCats=Sous-catégories
CatList=Liste des tags/catégories
CatListAll=Liste de toutes les catégories (de tous types)
@ -90,6 +91,7 @@ CategorieRecursivHelp=Si l'option est activé, quand un produit est ajouté dans
AddProductServiceIntoCategory=Ajouter le produit/service suivant
AddCustomerIntoCategory=Assigner cette catégorie au client
AddSupplierIntoCategory=Assigner cette catégorie au fournisseur
AddTicketIntoCategory=Assigner cette catégorie au ticket
ShowCategory=Afficher tag/catégorie
ByDefaultInList=Par défaut dans la liste
ChooseCategory=Choisissez une catégorie

View File

@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if (!empty($conf->projet->enabled)) {
include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
@ -202,6 +203,10 @@ if (empty($reshook)) {
$contactid = GETPOST('contactid', 'int');
$type_contact = GETPOST("type", 'alpha');
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
if ($contactid > 0 && $type_contact) {
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
$result = $object->add_contact($contactid, $typeid, 'external');
@ -312,7 +317,11 @@ if (empty($reshook)) {
$object->severity_code = GETPOST('severity_code', 'alpha');
$ret = $object->update($user);
if ($ret <= 0) {
if ($ret > 0) {
// Category association
$categories = GETPOST('categories', 'array');
$object->setCategories($categories);
} else {
$error++;
}
@ -1054,6 +1063,13 @@ if ($action == 'create' || $action == 'presend') {
print '</td></tr>';
}
// Categories
if ($conf->categorie->enabled) {
print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1);
print "</td></tr>";
}
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';