diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 28e3a4a22f8..f5910e3b921 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -378,6 +378,7 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f $nbko++; } } elseif (!empty($feature) && ($feature != 'user' && $feature != 'usergroup')) { // This is permissions on 1 level + var_dump($user->rights); if (empty($user->rights->$feature->lire) && empty($user->rights->$feature->read) && empty($user->rights->$feature->run)) { diff --git a/htdocs/ticket/index.php b/htdocs/ticket/index.php index 8e6e09f3fcf..8071d222748 100644 --- a/htdocs/ticket/index.php +++ b/htdocs/ticket/index.php @@ -52,9 +52,6 @@ if ($user->socid) { } $userid = $user->id; -// Security check -$result = restrictedArea($user, 'ticket', 0, '', '', '', ''); - $nowarray = dol_getdate(dol_now(), true); $nowyear = $nowarray['year']; $year = GETPOST('year', 'int') > 0 ? GETPOST('year', 'int') : $nowyear; @@ -63,6 +60,12 @@ $endyear = $year; $object = new Ticket($db); +// Security check +//$result = restrictedArea($user, 'ticket|knowledgemanagement', 0, '', '', '', ''); +if (empty($user->rights->ticket->read) && empty($user->rights->knowledgemanagement->knowledgerecord->read)) { + accessforbidden('Not enought permissions'); +} + /* * Actions @@ -240,63 +243,67 @@ $stringtoshow .= ''; -print ''; -print ''; +if (!empty($user->rights->ticket->read)) { + print '
'; + print '
'.$langs->trans("Statistics").' '.$endyear.' '.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_by_status" class="linkobject"').'
'; + print ''; -print ''; + + print '
'.$langs->trans("Statistics").' '.$endyear.' '.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_by_status" class="linkobject"').'
'; -print $stringtoshow; + print '
'; + print $stringtoshow; -// don't display graph if no series -if (!empty($dataseries) && count($dataseries) > 1) { - $totalnb = 0; - foreach ($dataseries as $key => $value) { - $totalnb += $value['data']; - } - - $data = array(); - foreach ($dataseries as $key => $value) { - $data[] = array($value['label'], $value['data']); - } - $px1 = new DolGraph(); - $mesg = $px1->isGraphKo(); - if (!$mesg) { - $px1->SetData($data); - $px1->SetDataColor(array_values($colorseries)); - - unset($data1); - $i = $startyear; - $legend = array(); - while ($i <= $endyear) { - $legend[] = $i; - $i++; + // don't display graph if no series + if (!empty($dataseries) && count($dataseries) > 1) { + $totalnb = 0; + foreach ($dataseries as $key => $value) { + $totalnb += $value['data']; } - $px1->setShowLegend(2); - $px1->SetType(array('pie')); - $px1->SetLegend($legend); - $px1->SetMaxValue($px1->GetCeilMaxValue()); - //$px1->SetWidth($WIDTH); - $px1->SetHeight($HEIGHT); - $px1->SetYLabel($langs->trans("TicketStatByStatus")); - $px1->SetShading(3); - $px1->SetHorizTickIncrement(1); - $px1->SetCssPrefix("cssboxes"); - $px1->mode = 'depth'; - //$px1->SetTitle($langs->trans("TicketStatByStatus")); - $px1->draw($filenamenb, $fileurlnb); - print $px1->show($totalnb ? 0 : 1); + $data = array(); + foreach ($dataseries as $key => $value) { + $data[] = array($value['label'], $value['data']); + } + $px1 = new DolGraph(); + $mesg = $px1->isGraphKo(); + if (!$mesg) { + $px1->SetData($data); + $px1->SetDataColor(array_values($colorseries)); + + unset($data1); + $i = $startyear; + $legend = array(); + while ($i <= $endyear) { + $legend[] = $i; + $i++; + } + $px1->setShowLegend(2); + $px1->SetType(array('pie')); + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + //$px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("TicketStatByStatus")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->SetCssPrefix("cssboxes"); + $px1->mode = 'depth'; + //$px1->SetTitle($langs->trans("TicketStatByStatus")); + + $px1->draw($filenamenb, $fileurlnb); + print $px1->show($totalnb ? 0 : 1); + } } + print '
'; + print ''; } -print ''; -print ''; -print ''; +if (!empty($user->rights->ticket->read)) { + // Build graphic number of object + $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear); -// Build graphic number of object -$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear); - -print '
'."\n"; + print '
'."\n"; +} print $resultboxes['boxlista']; @@ -304,127 +311,128 @@ print ''."\n"; print '
'; -/* - * Latest unread tickets - */ +if (!empty($user->rights->ticket->read)) { + /* + * Latest unread tickets + */ -$max = 10; + $max = 10; -$sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut, t.progress,"; -$sql .= " type.code as type_code, type.label as type_label,"; -$sql .= " category.code as category_code, category.label as category_label,"; -$sql .= " severity.code as severity_code, severity.label as severity_label"; -$sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; -$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; -if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; -} - -$sql .= ' WHERE t.entity IN ('.getEntity('ticket').')'; -$sql .= " AND t.fk_statut=0"; -if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); -} - -if ($user->socid > 0) { - $sql .= " AND t.fk_soc= ".((int) $user->socid); -} else { - // Restricted to assigned user only - if (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && !$user->rights->ticket->manage) { - $sql .= " AND t.fk_user_assign = ".((int) $user->id); + $sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut, t.progress,"; + $sql .= " type.code as type_code, type.label as type_label,"; + $sql .= " category.code as category_code, category.label as category_label,"; + $sql .= " severity.code as severity_code, severity.label as severity_label"; + $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } -} -$sql .= $db->order("t.datec", "DESC"); -$sql .= $db->plimit($max, 0); -//print $sql; -$result = $db->query($sql); -if ($result) { - $num = $db->num_rows($result); + $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')'; + $sql .= " AND t.fk_statut=0"; + if (empty($user->rights->societe->client->voir) && !$socid) { + $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + } - $i = 0; + if ($user->socid > 0) { + $sql .= " AND t.fk_soc= ".((int) $user->socid); + } else { + // Restricted to assigned user only + if (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && !$user->rights->ticket->manage) { + $sql .= " AND t.fk_user_assign = ".((int) $user->id); + } + } + $sql .= $db->order("t.datec", "DESC"); + $sql .= $db->plimit($max, 0); - $transRecordedType = $langs->trans("LatestNewTickets", $max); + //print $sql; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); - print '
'; - print ''; - print ''; - print ''; - print ''; - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); + $i = 0; - $object->id = $objp->rowid; - $object->ref = $objp->ref; - $object->track_id = $objp->track_id; - $object->fk_statut = $objp->fk_statut; - $object->progress = $objp->progress; - $object->subject = $objp->subject; + $transRecordedType = $langs->trans("LatestNewTickets", $max); - print ''; + print '
'; + print '
'.$transRecordedType.''.$langs->trans("FullList").'
'; + print ''; + print ''; + print ''; + if ($num > 0) { + while ($i < $num) { + $objp = $db->fetch_object($result); - // Ref - print '\n"; + $object->id = $objp->rowid; + $object->ref = $objp->ref; + $object->track_id = $objp->track_id; + $object->fk_statut = $objp->fk_statut; + $object->progress = $objp->progress; + $object->subject = $objp->subject; - // Creation date - print '"; + print ''; - // Subject - print '\n"; + // Ref + print '\n"; - // Type - print ''; + // Creation date + print '"; - // Category - print '\n"; + + // Type + print ''; + + // Category + print '"; + + // Severity + print '"; + + print '"; + + print "\n"; + $i++; } - //print $objp->category_label; - print ""; - // Severity - print '"; - - print '"; - - print "\n"; - $i++; + $db->free($result); + } else { + print ''; } - $db->free($result); + print "
'.$transRecordedType.''.$langs->trans("FullList").'
'; - print $object->getNomUrl(1); - print "'; - print dol_print_date($db->jdate($objp->datec), 'dayhour'); - print "
'; - print ''.dol_trunc($objp->subject, 30).''; - print "'; + print $object->getNomUrl(1); + print "'; - $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code); - print ''.$s.''; - print ''; + print dol_print_date($db->jdate($objp->datec), 'dayhour'); + print "'; - if (!empty($obp->category_code)) { - $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code); + // Subject + print ''; + print ''.dol_trunc($objp->subject, 30).''; + print "'; + $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code); print ''.$s.''; + print ''; + if (!empty($obp->category_code)) { + $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code); + print ''.$s.''; + } + //print $objp->category_label; + print "'; + $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code); + print ''.$s.''; + //print $objp->severity_label; + print "'; + print $object->getLibStatut(5); + print "
'; - $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code); - print ''.$s.''; - //print $objp->severity_label; - print "'; - print $object->getLibStatut(5); - print "
'.$langs->trans('NoUnreadTicketsFound').'
"; + print '
'; + + print '
'; } else { - print ''.$langs->trans('NoUnreadTicketsFound').''; + dol_print_error($db); } - - print ""; - print '
'; - - print '
'; -} else { - dol_print_error($db); } - print $resultboxes['boxlistb']; print '';