<?php
/*
   The Index software may be freely distributed.
   See license.txt for details.
*/
define('ROOT', './');
include(ROOT . 'text.inc');
include(ROOT . 'counts/count.inc');
include(ROOT . 'layout.inc');
include(ROOT . 'list/list.inc');
include(ROOT . 'notes/notes.inc');


$periods = array('1 day', '1 week', '2 weeks', '1 month', '2 months',
        '6 months', '1 year');
function period_selector($varname, $restofline)
{
    global $periods;
    global $PHP_SELF;
    print "<p><small>View the last | ";
    reset($periods);
    while (list(, $per) = each($periods))
    {
        if ($GLOBALS[$varname] != $per)
            print "<a href=\"$PHP_SELF?$varname=$per$restofline\">$per</a> | ";
        else
            print "<b>$per</b> | ";
    }
    print "</small></p>";
}

function rsslink($ch, $maxage)
{
    print "<a href=\"rss.php?ch=$ch&ma=$maxage\">";
    print "<img src=\"xml.gif\" width=\"36\" height=\"14\" hspace=\"28\">";
    print "</a>\n";
}

ReadList();
start_page();

if ($et == "")
    $et = $periods[2];
$editedtime = strtotime("-$et");

if ($dt == "")
    $dt = $periods[2];
$deletedtime = strtotime("-$dt");

if ($vt == "")
    $vt = $periods[2];
$visitortime = strtotime("-$vt");

if ($nt == "")
    $nt = $periods[1];
$notetime = strtotime("-$nt");

SortList($list, 'date');
$found = false;
print "<h2>Items edited last $et";
rsslink("edited", $et);
print "</h2>";
period_selector("et", "&dt=$dt&vt=$vt&nt=$nt");
start_itemlist();
reset($list);
while (list($key, $value) = each($list)) 
{
    if ($value['date'] > $editedtime) 
    {
        $found = true;
        start_item();
        item($key, $value, 0, 1);
        end_item();
    }
}
end_itemlist();
if (!$found)
{
    ?><blockquote><b>None found.</b></blockquote><?php
}

SortList($deletedlist, 'date');
$found = false;
print "<h2>Items deleted last $dt";
rsslink("deleted", $dt);
print "</h2>";
period_selector("dt", "&et=$et&vt=$vt&nt=$nt");
start_itemlist();
reset($deletedlist);
while (list($key, $value) = each($deletedlist)) 
{
    if ($value['date'] > $deletedtime) 
    {
        $found = true;
        start_item();
        item($key, $value, 0, 1);
        end_item();
    }
}
end_itemlist();
if (!$found)
{
    ?><blockquote><b>None found.</b></blockquote><?php
}

SortList($visitorlist, 'date');
$found = false;
print "<h2>Visitor's items added last $vt";
rsslink("visitor", $vt);
print "</h2>";
period_selector("vt", "&dt=$dt&et=$et&nt=$nt");
start_itemlist();
if (is_array($visitorlist))
{
    reset($visitorlist);
    while (list($key, $value) = each($visitorlist))
    {
        if ($value['date'] > $visitortime) 
        {
            $found = true;
            start_item();
            item($key, $value, 0, 1);
            end_item();
        }
    }
}
end_itemlist();
if (!$found)
{
    ?><blockquote><b>None found.</b></blockquote><?php
}


ReadNotes();
SortList($combilist, 'date');
$found = false;
print "<h2>Items commented on last $nt";
rsslink("comments", $nt);
print "</h2>";
period_selector("nt", "&dt=$dt&et=$et&vt=$vt");
start_itemlist();
reset($combilist);
while (list($key, $value) = each($combilist))
{
    $itemnotes = $notes[$key];
    $last = count($itemnotes) - 1;
    if ($itemnotes[$last]['date'] > $notetime) 
    {
        $found = true;
        start_item();
        item($key, $value, 0, 1);
        end_item();
    }
}
end_itemlist();
if (!$found)
{
    ?><blockquote><b>None found.</b></blockquote><?php
}

end_page();
?>