Jump to content

Network Issues Widget


sol2010

Recommended Posts

Hi @brian! 

Hope you're doing well.

The wonderful hook you wrote here: https://whmcs.community/topic/261921-network-announcement-on-client-area/  has stopped working in the recent version of WHMCS v 7.6

Does yours still work?

Just to clarify, I've added the following code into a hook page in the /hooks folder.  Do I also need to add additional code in the template?

 

<?php

# Network Issues HomePagePanel
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;
use Carbon\Carbon;

add_hook('ClientAreaHomepagePanels', 1, function($homePagePanels) {

	$client = Menu::context('client');
	$networkissues = Capsule::table('tblnetworkissues')
		->join('tblhosting', 'tblnetworkissues.server', '=', 'tblhosting.server')
		->leftjoin('tblservers','tblnetworkissues.server', '=', 'tblservers.id')
		->select('tblnetworkissues.*','tblservers.name')
		->where('tblhosting.userid', $client->id)
		->whereDate('tblnetworkissues.enddate', '>=', Carbon::today())
		->orwhereIn('tblnetworkissues.status',['Investigating','Reported','In Progress','Outage'])
		->where('tblnetworkissues.type','Server')
		->orderby('tblnetworkissues.lastupdate','desc')
		->groupby('tblnetworkissues.id')
		->take(3)
		->get();
						
	if (count($networkissues) > 0) {						

		$bodyhtml = '<div class="list-group">';

		foreach ($networkissues as $issue) {
			if ($issue->priority == "Critical") {$prioritycolor = 'red';}
			elseif ($issue->priority == "High") {$prioritycolor = 'magenta';}
			elseif ($issue->priority == "Medium") {$prioritycolor = 'orange';}
			elseif ($issue->priority == "Low") {$prioritycolor = 'green';}
			else {$prioritycolor = 'grey';}

			if ($issue->enddate) {
				$bodyhtml .= '<li class="list-group-item"><a href="serverstatus.php"><b>'.$issue->title.'</b></a> <label class="label" style="background-color: lightgrey; color: black">'.$issue->status.'</label> <label class="label" style="background-color: '.$prioritycolor.'">'.$issue->priority.'</label><br>'.Lang::trans('networkissuesaffecting').' '.$issue->type.' - '.$issue->affecting.' '.$issue->name.'<br><span style="color: black">'.$issue->description.'</span><br>'.Lang::trans('networkissuesstatusscheduled').': '.fromMySQLDate($issue->startdate, true, true).' - '.fromMySQLDate($issue->enddate, true, true).'</li>';
			}
			elseif ($issue->lastupdate) {
				$bodyhtml .= '<li class="list-group-item"><a href="serverstatus.php"><b>'.$issue->title.'</b></a> <label class="label" style="background-color: lightgrey; color: black">'.$issue->status.'</label> <label class="label" style="background-color: '.$prioritycolor.'">'.$issue->priority.'</label><br>'.Lang::trans('networkissuesaffecting').' '.$issue->type.' - '.$issue->affecting.' '.$issue->name.'<br><span style="color: black">'.$issue->description.'</span><br>'.Lang::trans('networkissueslastupdated').' - '.fromMySQLDate($issue->lastupdate, true, true).'</li>';
			}
		}
		$bodyhtml .= '</div>';
		
		$homePagePanels->addChild('networkissues', array(
			'label' => Lang::trans('networkissuestitle'),
			'icon' => 'fa-exclamation-triangle',
			'order' => 3,
			'extras' => array(
				'color' => 'red',
				'btn-link' => 'serverstatus.php',
				'btn-text' => Lang::trans('viewAll'),
				'btn-icon' => 'fa-plus',
			),
			'bodyHtml' => $bodyhtml,
		));
	}
});

 

Link to comment
Share on other sites

Opps - my bad  it is still working on the clientarea.php (clientareahome.tpl)

However, it's stopped working on the homepage.tpl - I was using the following code which no longer seems to work.  Any ideas?

{foreach $networkissues as $issue}
   <div id="homePage-Notification">
   <div class='alert alert-{if $issue.priority eq 'Critical'}danger{elseif $issue.priority eq 'Low'}success{elseif $issue.priority eq 'High'}warning{else}info{/if}'>
       <a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
       <h4 class="title">Network Status Notifications Affecting Your Services</h4>
       <a href='serverstatus.php'><h4 class="issue_title"> {$issue.title} <div class="posteddate">Last Updated: {$issue.lastupdate|date_format:"%d/%m/%Y %H:%M "}</div></h4> </a>
         
       {$issue.description} 
       <a href='serverstatus.php' class="readmore">Click to read more</a>
   </div>
    </div>
{/foreach}

 

Link to comment
Share on other sites

8 hours ago, sol2010 said:

However, it's stopped working on the homepage.tpl - I was using the following code which no longer seems to work.  Any ideas?

still works on my v7.6 dev - but don't forget, as the  hook is written, the client would need to be logged in for this to work (otherwise the array will always be empty).

0Lf9eSu.png

Link to comment
Share on other sites

Just now, sol2010 said:

I am using a custom theme template, not sure if that has any relevance. 

it shouldn't do - the hook needs a client ID to look for appropriate servers... if it's outputting nothing, that should mean the query result is empty and the resulting $networkissues array will be empty... it's also possible that the client you're testing with doesn't have any applicable servers with network issues... so you should probably check with multiple clients just to ensure that isn't the case.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated