Jump to content

Network Announcement on Client Area


Atomic

Recommended Posts

I'd like to add a section for Network Issues on clientarea.php. So if a server a client is on they see the announcement when logging in without having to go to Network Issues. Is this possible?

how did you want the output - normal bootstrap or as a homepagepanel ?

 

if bootstrap, then I posted a hook & template code in the thread below that would output the NI on the homepage (normal or client)..

 

https://forum.whmcs.com/showthread.php?117106-Hooks-to-display-Announcements-and-Network-Issues&p=473026#post473026

dx6uoY4.png

 

you'd need to tweak the database query if you wanted to only show issues affecting servers used by that particular client.

 

alternatively, if you wanted a homepagepanel, you'd still need to query the database, but the hook would generate the output instead of needing to modify the template.

 

dHQsTGo.png

Link to comment
Share on other sites

Hi Brian,

 

Thanks for the reply. I added the hook and then the code in clientareahome.tpl. However, it shows to clients not on that server. Anyway to have it so it only displays if a client has a product on a particular server?

 

Also, I would prefer the homepagepanel. If you have time I would appreciate any insight into the code. I looked at the docs but couldn't work out how to integrate the db queries with the panel code.

Link to comment
Share on other sites

Thanks for the reply. I added the hook and then the code in clientareahome.tpl. However, it shows to clients not on that server. Anyway to have it so it only displays if a client has a product on a particular server?

as I suggested, you'll need to tweak the query... e.g if you were just interested in network issues that affected servers (and not system/other issues), and only shown to those clients using that server, then you would do something along the lines of...

 

    $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)
                       ->where('tblnetworkissues.status','<>','Resolved')
                       ->where('tblnetworkissues.type','Server')
                       ->orderby('tblnetworkissues.lastupdate','desc')
                       ->groupby('tblnetworkissues.id')
                       ->take(2)
                       ->get();

so this would show a maximum of 2 network issues, applicable to the client using an affected server that has NOT been resolved... e.g once the issue has been fixed, then it is no longer found by the query.

 

Also, I would prefer the homepagepanel. If you have time I would appreciate any insight into the code. I looked at the docs but couldn't work out how to integrate the db queries with the panel code.

there are a few ways to do it - but basically the database query is exactly the same; you then extract the content of the array and output it however you want - and finally create the homepage panel.

 

so to get a working Network Issues homepagepanel hook, that is only shown to affected clients, you would use...

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

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)
                       ->where('tblnetworkissues.status','<>','Resolved')
                       ->where('tblnetworkissues.type','Server')
                       ->orderby('tblnetworkissues.lastupdate','desc')
                       ->groupby('tblnetworkissues.id')
                       ->take(2)
                       ->get();

   $bodyhtml = '';
   $bodyhtml .= '<table class="table table-hover" style="margin-bottom: 0px;">';

   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';
       }

       $lastupdated = fromMySQLDate($issue->lastupdate, true, true);

       $bodyhtml .= '<tr><td><a href="serverstatus.php"><b>'.$issue->title.'</b></a> <small><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').' - '.$lastupdated.'</small></td></tr>';
   }

   $bodyhtml .= '</table>';

   if (count($networkissues) > 0) {
       $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,
                       ));
   }
}); 
;

a couple of things to note with this hook - i've tried to keep it as simple and flexible as possible (no really!), e.g instead of creating a custom css file and specifying the styles in that, i've used inline CSS in the hook... but if you have a customised theme and want to use external css, then it should be straightforward for you to remove the inline code and some old-fashioned html tags! :)

 

the hook should create a panel similar to...

FBhRUeD.png

 

by altering the number used in the 'order' value, it will move the location of the panel - as it's currently set at 3, it will be shown before any default panels and so should be top-left... if you wanted to show it after 'overdue/unpaid invoices', but before 'expiring domains', you could change the value to 20 - it will either be shown below or to the right, depending on which other panels are being shown to the client.

 

http://docs.whmcs.com/Working_With_Client_Area_Home_Page_Panels#Default_Panels

Link to comment
Share on other sites

This works perfectly - thanks!

 

However, I am considering which one to use. I still might go with the bootstrap. But I added the database query to the code and now it doesn't work at all:

 

 <?php

use Illuminate\Database\Capsule\Manager as Capsule;

function homepage_network_issues_hook($vars) {

  $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)
                       ->where('tblnetworkissues.status','<>','Resolved')
                       ->where('tblnetworkissues.type','Server')
                       ->orderby('tblnetworkissues.lastupdate','desc')
                       ->groupby('tblnetworkissues.id')
                       ->take(2)
                       ->get();  

   $encodedata = json_encode($networkissues);
   $decodedata = json_decode($encodedata, true);

   return array("networkissues" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "homepage_network_issues_hook");
?>

 

I didn't change any code in the template.

Link to comment
Share on other sites

you'll need the code to identify the client too - otherwise the query would never find any results!

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function homepage_network_issues_hook($vars) {

   $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)
                       ->where('tblnetworkissues.status','<>','Resolved')
                       ->where('tblnetworkissues.type','Server')
                       ->orderby('tblnetworkissues.lastupdate','desc')
                       ->groupby('tblnetworkissues.id')
                       ->take(2)
                       ->get();

   $encodedata = json_encode($networkissues);
   $decodedata = json_decode($encodedata, true);

   return array("networkissues" => $decodedata);
}
add_hook("ClientAreaPageHome", 1, "homepage_network_issues_hook");
?>

just tested this on the clientarehome and both panel and bootstrap are showing. :idea:

Link to comment
Share on other sites

  • 1 year later...
12 hours ago, sol2010 said:

Would it be possible to have a "scheduled" notification drop off after the scheduled date has passed?

yes... i've re-written the hook code for v7.4.2, but it should still work in previous versions...

<?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,
		));
	}
});

tsnd8Ww.png

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • 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