Jump to content

Hooks to display Announcements and Network Issues


stormy

Recommended Posts

I have a couple of old clunky pieces of code, using {php} inside the templates, that allow me to display announcements and network issues in the client area.

 

Can someone help me convert these to Action Hooks, so I don't need to enable PHP in the templates? This will make for less clunky code and allow more display flexibility.

 

Here's one that displays recent announcements (1 week):

 

<!-- announcements -->
{php}
$query = "SELECT * from tblannouncements WHERE published != '0' AND DATE_SUB(CURDATE(),INTERVAL 1 WEEK) <= date ORDER BY date DESC";
$result=mysql_query($query);

$num_rows = mysql_num_rows($result);
if ($num_rows == 0 ) {
echo "<!-- No recent announcements -->";
} else {
echo "<div class='alert alert-info'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<h4>Recent news</h4>";
}

$num=0;
while($data = mysql_fetch_array($result) and $num<2  ) {
$num = $num +1;

$id = $data["id"];
$date = $data["date"];
$title = $data["title"];
$announcement = $data["announcement"];
$date = fromMySQLDate($date);
echo("<h4> <span style='font-size:0.9em;font-weight: normal'> $date -</span> ");
echo("$title </h4>");
echo("$announcement");
echo("</div>");
}
{/php}
<!-- /announcements -->

 

And here's one that displays network issues, color-coded by severity, with a link for more details.

 

<!-- network issues -->
{php}
$query = "SELECT * from tblnetworkissues WHERE status != 'Resolved'";
$result=mysql_query($query);

$num_rows = mysql_num_rows($result);
if ($num_rows == 0 ) {
echo "<!-- No recent issues -->";
} else {

$num=0;
while($data = mysql_fetch_array($result) and $num<2  ) {
$num = $num +1;

$id = $data["id"];
$date = $data["lastupdate"];
$title = $data["title"];
$announcement = $data["description"];
$priority = $data["priority"];
$date = fromMySQLDate($date, true);

if ($priority == 'Critical') {
$color = "danger" ;
} elseif ($priority == 'Low') {
$color = "success" ;
} elseif ($priority == 'High') {
$color = "warning" ;
} else  {
$color = "info" ;
}
echo "<div class='alert alert-$color'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<h4>Network Status</h4>";

echo("<h4> <span style='font-size:0.9em;font-weight: normal'> $date -</span> ");
echo("$title </h4>");
//echo("$announcement");
echo("<a href='serverstatus.php'>More info</a>");
echo("</div>");
}
}
{/php}
<!-- /network issues -->

Link to comment
Share on other sites

if you take Network Issues as a basic example, you could convert your {php} code into an action hook and Smarty code in the following way...

 

firstly, the hook that queries the database and passes the result back to the template....

 

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

function homepage_network_issues_hook($vars) {

   $networkissues = Capsule::table('tblnetworkissues')
                       ->where('status','<>','Resolved')
                       ->orderby('lastupdate','desc')
                       ->take(2)
                       ->get();

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

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

secondly, in the homepage.tpl template, you can output the array using Smarty...

 

{foreach $networkissues as $issue}
   <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>{$LANG.networkissuestitle}</h4>
       <h4> <span style='font-size:0.9em;font-weight: normal'> {$issue.lastupdate|date_format:"%d/%m/%Y %H:%M "} -</span>  {$issue.title} </h4> {$issue.description} <a href='serverstatus.php'>{$LANG.domainmoreinfo}</a>
   </div>
{/foreach}

you may need to tweak the date_format output to suit your own needs if you don't use the dd/mm/yyyy format...

Link to comment
Share on other sites

  • 6 years later...

Hi Brian,

If the incident is on a particular server, is it possible that the notice is still shown to all clients with this hook?

Is it possible to filter the notice only to clients that have services on the server selected in the incident?

 

Thanks

Diego

 

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.

×
×
  • 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