<?php
// *** b2 Archive file
require_once('./b2config.php');
require_once(
$b2inc.'/b2functions.php');
include(
'blog.header.php');
dbconnect();

// over-ride general date format with MySQL format.

// Date format from the DB
// See http://www.mysql.com/doc/en/Date_and_time_functions.html for full spec
$date_format '%d/%m/%y';      // like 30/09/02
//$date_format = '%D %M %Y';      // like 30th September 2002
//$date_format = '%Y-%m-%d';      // like 2002-09-30
//$date_format = '%W, %D %M, %Y'; // like Monday, 30th September, 2002

  
// display order choices
$ORDER_BY_CAT   'cat_name';
$ORDER_BY_DATE  'post_date';
$ORDER_BY_ID    'ID';
$ORDER_BY_TITLE 'post_title';

// What's the default list order?
$defaultorderby $ORDER_BY_CAT;
// Default to ascending to descending?
$defaultorder "ASC";
// What's the first year you started your b2?
$first_year "2002";


// --- //

$this_year date("Y");

if(!
$order_by)
    
$order_by $defaultorderby;
if(!
$asc_or_desc)
    
$asc_or_desc "ASC";
if(!
$year)
    
$year $this_year;

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- some layout credits goto http://bluerobot.com/web/layouts/layout2.html -->
<?php include('refererLib.php'); ?>
<?php logReferer
(); ?>
<head profile="http://geotags.com/geo">
<?php $extra_title=" :: Full Archives"; include('htmlhead.php'); ?>
  <style title="Main layout" type="text/css" media="screen">
    @import url( layout2b.css );
  </style>
  <link rel="stylesheet" type="text/css" media="print" href="print.css" />
<?php include_once("b2links.php"); ?>
</head>
<body>
  <div class="header">
<?php include('pageheader.php'); ?>
  </div> <!-- header -->
  <div id="centre">
<?php include_once('searchcheck.php'); ?>
    <div class="content">

      <form  action="<?=$PHP_SELF?>" method="post">
        Sort:
        <select class="form" name="order_by">
          <option value="<?=$ORDER_BY_ID?><?= ($order_by == $ORDER_BY_ID) ? ' selected' "" ?>>id</option>
          <option value="<?=$ORDER_BY_DATE?><?=($order_by == $ORDER_BY_DATE) ? ' selected' "" ?>>date</option>
          <option value="<?=$ORDER_BY_TITLE?><?=($order_by == $ORDER_BY_TITLE) ? ' selected' "" ?>>title</option>
          <option value="<?= $ORDER_BY_CAT?><?=($order_by == $ORDER_BY_CAT) ? ' selected' "" ?>>category</option>
        </select>
        &nbsp; date:
        <select name="order">
          <option value="DESC" <?= ($asc_or_desc == "DESC") ? " selected" "" ?>>Descending</option>
          <option value="ASC" <?= ($asc_or_desc == "ASC") ? " selected" "" ?>>Ascending</option>
        </select>
        &nbsp; year:
        <select class="form" name="year">
<?php for ($i $first_year$i <= $this_year$i++) {
  if (
$year == $i)
     echo 
"        <option value=\"$i\" selected>$i</option>";
   else
     echo 
"        <option value=\"$i\">$i</option>";
}
?>
        </select>
        <input type="submit" name="submit" value="sort" />
      </form>
<?php
  $request 
=
      
"SELECT $tableposts.*, DATE_FORMAT($tableposts.post_date, '$date_format') AS formatted_date, $tablecategories.cat_name as cat_name " .
      
" FROM $tableposts LEFT JOIN $tablecategories ON $tableposts.post_category = $tablecategories.cat_ID " .
      
" ORDER BY $order_by $asc_or_desc";
  
$result mysql_query($request) or die(mysql_error()."<br/>\n".$request);
  
$indiv false;
  while(
$row=mysql_fetch_object($result)) {

    
// are sorted by category?
    
if ($order_by == $ORDER_BY_CAT) {
      
$this_cat $row->cat_name;
      if (
$this_cat != $previous_cat) {
        echo 
"\n<br />\n<h4>" $row->cat_name;
        echo 
"</h4>\n";
      }
      
$previous_cat $this_cat;
    }
    
    
$postdata get_postdata2($row->ID);
    
$thismonth=mysql2date("Y\-m"$postdata['Date']);
    
$linkmonth=mysql2date('Ym'$postdata['Date']);
    
$i '/'.$thismonth.'/';

    
// don't do monthly stuff if we're doing by category/title
    
if (($order_by != $ORDER_BY_CAT) && ($order_by != $ORDER_BY_TITLE)) {
      if (
$thismonth != $previousmonth) { // change month?
        
if (preg_match($i,$postdata['Date'])) {
          echo 
"\n<h4><a href=\"".$siteurl.'/'.$blogfilename."?m=$linkmonth\">";
          echo 
$month[substr($thismonth,5,2)];
          echo 
'</a></h4>';
        }
      }
      
$previousmonth $thismonth;
    }
    
    
//$postdata = get_postdata2($row->ID);
    
$userinfo get_userdata ($postdata['Author_ID']);
    echo 
$row->formatted_date;
    echo 
" - <a href=\"".$siteurl.'/'.$blogfile.'?p='.$row->ID.'&c=1">';
    if (
$postdata['Title']) {
      
$postdata['Title'] = stripslashes($postdata['Title']);
      echo 
$postdata['Title'];
    } else {
      echo 
$postdata['ID'];
    }
    echo 
"</a><br />\n";
  }
?>
    </div> <!-- content -->
  </div> <!-- centre -->

  <div id="leftside">
<?php include_once('leftcolumn.php'); ?>
  </div>

  <div id="rightside">
<?php include_once("rightcolumn.php"); ?>
  </div>
</body>
</html>
<?php
?>