Skip to content

Commit 4d69c67

Browse files
author
Pascal Dreissen
committed
Datalogstatus notification implementation (as discussed: https://www.howtoforge.com/community/threads/datalogstatus.73719/)
1 parent 89391e1 commit 4d69c67

File tree

7 files changed

+147
-6
lines changed

7 files changed

+147
-6
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ public function datalogStatus($login = '') {
740740
global $app;
741741

742742
$return = array('count' => 0, 'entries' => array());
743-
if($_SESSION['s']['user']['typ'] == 'admin') return $return; // these information should not be displayed to admin users
743+
//if($_SESSION['s']['user']['typ'] == 'admin') return $return; // these information should not be displayed to admin users
744+
// removed in favor of new non intrusive datalogstatus notification header
744745

745746
if($login == '' && isset($_SESSION['s']['user'])) {
746747
$login = $_SESSION['s']['user']['username'];

interface/web/datalogstatus.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
error_reporting(E_ALL|E_STRICT);
32+
33+
require_once '../lib/config.inc.php';
34+
require_once '../lib/app.inc.php';
35+
36+
// Check if we have an active users ession and redirect to login if thats not the case.
37+
if($_SESSION['s']['user']['active'] != 1) {
38+
header('Location: /login/');
39+
die();
40+
}
41+
$datalogstatus = json_encode($app->db->datalogStatus());
42+
echo ($datalogstatus);
43+
?>

interface/web/themes/default/assets/javascripts/ispconfig.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ var ISPConfig = {
346346

347347
ISPConfig.loadMenus();
348348
ISPConfig.keepalive();
349+
ISPConfig.datalognotification();
349350
setTimeout(function() {
350351
try {
351352
$('form#pageForm').find('input[name="username"]').focus();
@@ -493,7 +494,34 @@ var ISPConfig = {
493494
}
494495
});
495496
},
496-
497+
datalognotification: function() {
498+
var notificationContent = $.ajax({
499+
type: "GET",
500+
url: "datalogstatus.php",
501+
dataType: "json",
502+
success: function(data, textStatus, jqXHR) {
503+
var dataLogItems = [];
504+
$.each( data['entries'], function( key, val ) {
505+
dataLogItems.push('<li><strong>' + val['text'] + ':</strong> ' + val['count'] + '</li>');
506+
});
507+
if(data['count'] > 0) {
508+
$('.modal-body').html(dataLogItems.join(""));
509+
$('.notification_text').text(data['count']);
510+
$('.notification').css('display','');
511+
setTimeout( function() { ISPConfig.datalognotification(); }, 2000 );
512+
} else {
513+
$('.notification').css('display','none');
514+
$('.modal-body').html('');
515+
setTimeout( function() { ISPConfig.datalognotification(); }, 5000 );
516+
}
517+
},
518+
error: function() {
519+
ISPConfig.reportError('Notification not loading, aborting.');
520+
$('.notification').css('display','none');
521+
}
522+
});
523+
},
524+
497525
addAdditionalTemplate: function(){
498526
var tpl_add = $('#template_additional').val();
499527
var addTemplate = $('#tpl_add_select').val().split('|',2);
@@ -701,7 +729,6 @@ $(document).on("click", "[data-uncheck-fields] > input[type='checkbox']", functi
701729
}
702730
});
703731

704-
705732
$(document).on('ready', function () {
706733
$.fn.extend({
707734
insertAtCaret: function(myValue){
@@ -779,3 +806,4 @@ $(document).on('ready', function () {
779806
return iCaretPos;
780807
};
781808
});
809+

0 commit comments

Comments
 (0)