Menu="UNRAID-OS"
Title="Archived Notifications"
Tag="list"
---
<?PHP
/* Copyright 2005-2017, Lime Technology
 * Copyright 2012-2017, Bergware International.
 * Copyright 2012, Andrew Hamer-Adams, http://www.pixeleyes.co.nz.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>
<?
$files = count(glob("{$notify['path']}/archive/*.notify", GLOB_NOSORT));
?>
<script>
var rows = [];
Array.prototype.remove = function() {
  var val, a = arguments, L = a.length, ax;
  while (L && this.length) {
    val = a[--L];
    while ((ax = this.indexOf(val)) !== -1) this.splice(ax, 1);
  }
  return this;
};
<?if ($display['resize']):?>
function resize(bind) {
  var width = [];
  var h = $('#archive_list').height();
  var s = Math.max(window.innerHeight-300,370);
  if (h>s || bind) {
    $('#archive_list').height(s);
    $('#archive_table tbody tr:first-child td').each(function(){width.push($(this).width());});
    $('#archive_table thead tr th').each(function(i){$(this).width(width[i]);});
    if (!bind) $('#archive_table thead,#archive_table tbody').addClass('fixed');
  }
}
<?endif;?>
function archiveList(init) {
  $.get('/webGui/include/NotificationsArchive.php',{filter:'<?=addslashes(htmlspecialchars($_GET['filter']))?>'},function(data) {
    if (data) $('#archive_list').html(data);
    if (init) {
<?if ($display['resize']):?>
      resize();
<?endif;?>
      $('#archive_table').tablesorter({headers:{5:{sorter:false}},textExtraction:function(n,t,i){return $(n).attr('data')||$(n).text();}});
    } else {
      $('#archive_table').trigger('update');
    }
    $('#archive_list .tablesorter-childRow td').hide();
    for (var i = 0; i < rows.length; i++) $('#archive_list .tablesorter-childRow.row'+rows[i]+' td').show();
    setTimeout(archiveList,30000);
  });
}
function askConfirmation() {
  swal({title:"Are you sure?",text:"This will delete all notification files!",type:"warning",showCancelButton:true},function(){$.post('/webGui/include/DeleteLogFile.php',{log:'*.notify'},function(){archiveList();});});
}
function openClose(row) {
  var extra = '#archive_list .tablesorter-childRow.row'+row+' td';
  if ($(extra).is(":visible")) {
    $(extra).hide();
    rows.remove(row);
  } else {
    $(extra).show();
    rows.push(row);
  }
}
$(function(){
  archiveList(true);
<?if ($display['resize']):?>
  $(window).bind('resize',function(){resize(true);});
<?endif;?>
});

// Adjust the width of thead cells when window resizes
</script>
<table class="tablesorter left shift" id="archive_table">
<thead><tr><th>Time</th><th>Event</th><th>Subject</th><th>Description</th><th>Importance</th><th style="text-align:right"><?if ($files):?><a href="#" onclick="askConfirmation();return false" title="Delete all notifications"><i class="fa fa-trash"></i></a><?endif;?></th></tr></thead>
<tbody id="archive_list"><tr><td colspan="5" style="text-align:center;padding-top:12px"><i class='fa fa-spinner fa-spin icon'></i><em>Please wait, loading information ...</em></td></tr></tbody>
</table>
<input type="button" value="Done" onclick="done()">
