Skip to content

Commit

Permalink
Update widgets
Browse files Browse the repository at this point in the history
Fix error when no group is define
  • Loading branch information
keha35 committed Dec 19, 2018
1 parent 201984f commit 681310c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 47 deletions.
44 changes: 23 additions & 21 deletions inc/alert.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,41 +1013,43 @@ function getWidgetContentForItem($widgetId, $opt = []) {
}
$datas[$i]["action"] = $action;


$ticketId = "<a href='" . $link_ticket . "?id=" . $data['tickets_id'] . "' target='_blank'>";
$ticketId .= sprintf(__('%1$s: %2$s'), __('ID'), $data['tickets_id']);
$ticketId .= $data['tickets_id'];
$ticketId .= "</a>";
$datas[$i]["id"] = $ticketId;

// Priorities
$priority = "<div class='center' style='background-color:$bgcolor; padding: 10px;color:white'>";
$priority .= "<span class='b'>".Ticket::getPriorityName($ticket->fields["priority"])."</span>";
$priority .= "<span class='b'>". $ticket->fields["priority"] . " - " .Ticket::getPriorityName($ticket->fields["priority"])."</span>";
$priority .= "</div>";
$datas[$i]["priority"] = $priority;




/***/
// Categories
$config = new PluginMydashboardConfig();
$config->getFromDB(1);
$itilCategory = new ITILCategory();
$itilCategory->getFromDB($ticket->fields["itilcategories_id"]);

$haystack = $itilCategory->getField('completename');
$needle = '>';
$offset = 0;
$allpos = [];

while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + 1;
$allpos[] = $pos;
}
if($itilCategory->getFromDB($ticket->fields["itilcategories_id"])){
$haystack = $itilCategory->getField('completename');
$needle = '>';
$offset = 0;
$allpos = [];

while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + 1;
$allpos[] = $pos;
}

if(isset($allpos[$config->getField('levelCat')-1])){
$pos = $allpos[$config->getField('levelCat')-1];
if(isset($allpos[$config->getField('levelCat')-1])){
$pos = $allpos[$config->getField('levelCat')-1];
} else{
$pos = strlen($haystack);
}
$datas[$i]["category"] = "<span class='b'>". substr($haystack,0,$pos) . "</span>";
} else{
$pos = strlen($haystack);
$datas[$i]["category"] = "<span></span>";
}
$datas[$i]["category"] = "<span class='b'>". substr($haystack,0,$pos) . "</span>";


$i++;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ static function getGroup($prefered_group, $opt,$params=false) {
&& count($opt) < 1){
$res = $group;
}
else{
else if(isset($opt['groups_id'])){
$res = $opt['groups_id'];
}
}else{
Expand Down
55 changes: 30 additions & 25 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,17 @@ static function showVeryShort($ID, $forcetab) {
$job = new Ticket();
$rand = mt_rand();
if ($job->getFromDBwithData($ID, 0)) {
$bgcolor = $_SESSION["glpipriority_" . $job->fields["priority"]];
$link = "<a id='ticket" . $job->fields["id"] . $rand . "' href='" . $CFG_GLPI["root_doc"] .
"/front/ticket.form.php?id=" . $job->fields["id"];
if ($forcetab != '') {
$link .= "&amp;forcetab=" . $forcetab;
}
$link .= "'>";

$bgcolor = $_SESSION["glpipriority_" . $job->fields["priority"]];
$output[$colnum] = "<div class='center' style='background-color:$bgcolor; padding: 10px;'>" .
sprintf(__('%1$s: %2$s'), __('ID'), $job->fields["id"]) . "</div>";
$link.
sprintf(__('%1$s: %2$s'), __('ID'), $job->fields["id"]) . "</a></div>";

$colnum++;
$output[$colnum] = '';
Expand Down Expand Up @@ -796,12 +803,7 @@ static function showVeryShort($ID, $forcetab) {
}

$colnum++;
$link = "<a id='ticket" . $job->fields["id"] . $rand . "' href='" . $CFG_GLPI["root_doc"] .
"/front/ticket.form.php?id=" . $job->fields["id"];
if ($forcetab != '') {
$link .= "&amp;forcetab=" . $forcetab;
}
$link .= "'>";

$link .= "<span class='b'>" . $job->getNameID() . "</span></a>";
$link = sprintf(__('%1$s (%2$s)'), $link,
sprintf(__('%1$s - %2$s'), $job->numberOfFollowups($showprivate),
Expand All @@ -827,31 +829,34 @@ static function showVeryShort($ID, $forcetab) {
$bgcolor = $_SESSION["glpipriority_" . $job->fields["priority"]];

$output[$colnum] = "<div class='center' style='background-color:$bgcolor; padding: 10px;color:white'>
<span class='b'>".Ticket::getPriorityName($job->fields["priority"])."</span>
<span>".$job->fields["priority"] . " - " . Ticket::getPriorityName($job->fields["priority"])."</span>
</div>";
//Categories
$colnum++;
$config = new PluginServicecatalogConfig();
$config = new PluginMydashboardConfig();
$config->getFromDB(1);
$itilCategory = new ITILCategory();
$itilCategory->getFromDB($job->fields['itilcategories_id']);

$haystack = $itilCategory->getField('completename');
$needle = '>';
$offset = 0;
$allpos = [];

while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + 1;
$allpos[] = $pos;
}
if($itilCategory->getFromDB($job->fields['itilcategories_id'])){
$haystack = $itilCategory->getField('completename');
$needle = '>';
$offset = 0;
$allpos = [];

while (($pos = strpos($haystack, $needle, $offset)) !== FALSE) {
$offset = $pos + 1;
$allpos[] = $pos;
}

if(isset($allpos[$config->getField('levelCat')-1])){
$pos = $allpos[$config->getField('levelCat')-1];
if(isset($allpos[$config->getField('levelCat')-1])){
$pos = $allpos[$config->getField('levelCat')-1];
} else{
$pos = strlen($haystack);
}
$output[$colnum] = "<span class='b'>". substr($haystack,0,$pos) . "</span>";
} else{
$pos = strlen($haystack);
$output[$colnum] = "<span></span>";
}
$output[$colnum] = "<span class='b'>". substr($haystack,0,$pos) . "</span>";


//status
$colnum++;
Expand Down

0 comments on commit 681310c

Please sign in to comment.