<?php
    //-------------------------------------------------------------------
    // m_archives
    // display blog entry archives by year and months
    //-------------------------------------------------------------------
    
    drawMenuTop('Archives');
     
    global $siteSettings;
    //
    //TODO: probably a lot of optimization can be done to the whole 'archives' system
    //
    $dates = mysql_query("SELECT date FROM blog where threadID=0 ORDER BY date DESC") or die(mysql_error() );
    $cursor = 0;
    $date_array = NULL;
     
    while ($date = mysql_fetch_array($dates) )
    {
        $date_array[$cursor] = date("F Y", $date['date']);
        $cursor++;
        //print( date("F Y", $date['date'] ) . "<br />");
    }
     
    if (count($date_array ) > 0 )
    {
        $unique_dates = array_unique($date_array );
        foreach($unique_dates as $u )
        {
            $parts = explode(' ' , $u );
            $month = $parts[0];
            $year = $parts[1];
             
             
            if ($siteSettings['slickurls'] == TRUE )
                print("<a href='" . $siteSettings['siteurl'] . "/archived/$year/$month'>" . $u . "</a><br />");
            else
                print("<a href='index.php?shard=blog&amp;action=g_archived&amp;year=$year&amp;month=$month'>" .$u . "</a><br />");
        }
    }
    else
    {
        print("The archives are empty");
    }
     
     
    drawMenuBottom();
     
     
?>
