<?PHP
/* 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 as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 */
/* Adapted by Bergware International (May 2012) */
?>
<?
$notify = &$sf_ini['notify'];
$sn = '/plugins/notifications';
$icon = "$sf/icons/archived_notifications.png";
?>
<link href="<?=$sn?>/include/jquery.dataTables.css" rel="stylesheet" />
<script type="text/javascript" src="<?=$sn?>/include/jquery.dataTables.min.js"></script>

<script>
$(document).ready(function() {
  $('#notify').dataTable( {
  "bPaginate": true,
  "sPaginationType": "full_numbers",
  "bProcessing": true,
  "bFilter": true,
  "bSort": true,
  "aaSorting": [[1,'desc']],
  "bInfo": true,
  "iDisplayLength": 10,
  "sDom": '<"top"<"clear">f<"clear">>rt<"bottom"lp>'
  });
});

function resetNotify(form) {
  form.date.selectedIndex = 0;
  form.time.selectedIndex = 0;
  form.path.value = "/boot/config/plugins/Notifications";
  form.position.selectedIndex = 1;
}
</script>

<form name="notify" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="section" value="notify">
<table class="settings">
  <tr>
  <td>Date format:</td>
  <td><select name="date" size="1">
  <?=mk_option($notify['date'], "d/m/Y", "DD-MM-YYYY")?>
  <?=mk_option($notify['date'], "m/d/Y", "MM-DD-YYYY")?>
  </select></td>
  </tr>
  <tr>
  <td>Time format:</td>
  <td><select name="time" size="1">
  <?=mk_option($notify['time'], "h:i A", "12 hours")?>
  <?=mk_option($notify['time'], "H:i", "24 hours")?>
  </select></td>
  </tr>
  <tr>
  <td>Storage path:</td>
  <td><input type="text" name="path" value="<?=$notify['path']?>"></td>
  </tr>
  <tr>
  <td>Display position:</td>
  <td><select name="position" size="1">
  <?=mk_option($notify['position'], "top-left", "top-left")?>
  <?=mk_option($notify['position'], "top-right", "top-right")?>
  <?=mk_option($notify['position'], "bottom-left", "bottom-left")?>
  <?=mk_option($notify['position'], "bottom-right", "bottom-right")?>
  <?=mk_option($notify['position'], "center", "center")?>
  </select></td>
  </tr>
  <td><button type="button" onclick="resetNotify(this.form);">Default</button></td>
  <td><input type="submit" name="notify" value="Apply"><button type="button" onclick="done();">Done</button></td>
  </tr>
</table>
</form>

<div id="title"><span class="left"><img src='<?=$icon?>' class='icon'>Archived Notifications</span></div>
<table border="0" cellpadding="5" cellspacing="0" id="notify">
<thead>
<tr height="35px">
<th><strong>Importance</strong></th>
<th><strong>Time</strong></th>
<th><strong>Plugin</strong></th>
<th><strong>Title</strong></th>
<th><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<?
$path = $notify['path'];
$files = glob("$path/archive/*.notify");
$datetime = $notify['date'].' '.$notify['time'];

if (!empty($files)) {
foreach($files as $file) {
  $ini_array[$i] = parse_ini_file($file);
  $ini_array[$i][timestamp] = date($datetime, $ini_array[$i][timestamp]);
  echo '<tr>';
  echo '<td>'.$ini_array[$i][importance].'</td>';
  echo '<td>'.$ini_array[$i][timestamp].'</td>';
  echo '<td>'.$ini_array[$i][plugin].'</td>';
  echo '<td>'.$ini_array[$i][subject].'</td>';
  echo '<td>'.$ini_array[$i][description].'</td>';
  echo '</tr>';
  $i++;
}}
?>
</tbody>
</table>