Monday, August 25, 2014

Desktop Notification - chrome



<!DOCTYPE html>
<html>
<head><title>Data Notifications</title>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.css">
<script>
var oTable;
var rowcount = 0;
$(document).ready(function() {
oTable = $("#upd").dataTable({
"bServerSide": true,
"sAjaxSource": "cgi-bin/load.cgi",
} );
rowcount = oTable.fnSettings().fnRecordsTotal();
} );


setInterval(function() {
oTable.fnDraw();
var cur_count = oTable.fnSettings().fnRecordsTotal();
if(cur_count != rowcount){
notifyMe();
rowcount = cur_count;
}
}, 1000);
</script>

<script>
function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  }

  // Let's check if the user is okay to get some notification
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Data Updated!");
  }

  // Otherwise, we need to ask the user for permission
  // Note, Chrome does not implement the permission static property
  // So we have to check for NOT 'denied' instead of 'default'
  else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {

      // Whatever the user answers, we make sure we store the information
      if(!('permission' in Notification)) {
        Notification.permission = permission;
      }

      // If the user is okay, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Data Updated");
      }
    });
  }

  // At last, if the user already denied any notification, and you
  // want to be respectful there is no need to bother him any more.
}
</script>




</head>
<body>

<table id="upd" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Slno</th>
                <th>Name</th>
            </tr>
        </thead>

    </table>


<form method='GET' onclick = "notifyMe();">
<input type ="submit" name ="sub" value ="LoadTable">
</form>
</body>
</html>

Data Notifications





------------------------------------------------------

#!C:/perl/bin/perl.exe
use strict;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use CGI;
use JSON;
use DBI;
use Data::Dumper;
my $cgi = new CGI;
print $cgi-&gt;header();#'application/json');
#print $cgi-&gt;header(
#  -Cache-Control =&gt; 'no-cache',
# );
#print $cgi-&gt;start_html();-title=&gt;'Table Updates');
#open my $out, "&gt;", "hhaha";
my $sech = $cgi-&gt;param("sEcho");
#print $out $sech; exit;
my $dbh = DBI-&gt;connect('dbi:mysql:medicines', 'root');
my $sql = q/select slno, name from med_stock/;
my $sth = $dbh-&gt;prepare($sql);
$sth-&gt;execute;
#print $cgi-&gt;table({border=&gt;1});

# table headings are SQL column names
my %hash;
$hash{'draw'} =1;
$hash{'aaData'} = ();
$hash{'sEcho'} = $sech;


my $i =0;
#print "
$sth-&gt;{NAME}-&gt;[0]
$sth-&gt;{NAME}-&gt;[1]
";
while (my @row = $sth-&gt;fetchrow_array) {
    #print "
$row[0]
$row[1]
\n";
$hash{'aaData'}-&gt;[$i]-&gt;[0] =$row[0];
$hash{'aaData'}-&gt;[$i]-&gt;[1] =$row[1]; $i++;
}
#print Dumper(%hash);
$hash{"recordsTotal"}=$i;
$hash{"recordsFiltered"}=$i;
$hash{'iTotalRecords'} = $i;
$hash{'iTotalDisplayRecords'} = $i;
print encode_json(\%hash);
#print $cgi-&gt;end_table;
#print $cgi-&gt;end_html;







No comments: