Location: PHPKode > projects > GENU > GENU-2012.3/articles/index.php
<?php
// -----------------------------------------------------------------------
//
// $Id: index.php 170 2012-03-30 09:55:18Z raoul $
//
// Copyright (C) 2003-2012 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
//
// -----------------------------------------------------------------------
//
// 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 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// -----------------------------------------------------------------------

include('./../includes/common.php');

page_header($lang['ARTICLES_INDEX_TITLE']);

// Create pages list
if (empty($_GET['page']))
{
    $_GET['page'] = 1;
}
$articles_per_page = $settings['articles_per_page'];
$articles_offset = ($_GET['page'] - 1) * $articles_per_page;
$sql->query('SELECT article_id
             FROM ' . TABLE_ARTICLES);
$num_articles = $sql->num_rows();
$num_pages = ceil($num_articles / $articles_per_page);
$pages_list = get_pages_list('./../articles/index.php?', $num_pages);

$date_format = get_date_format();
$date_offset = get_date_offset();
$template->set_file('index', 'articles/index.htpl');
$template->set_block('index', 'ARTICLES_BLOCK', 'articles');
$sql->query('SELECT ' . TABLE_ARTICLES . '.article_date, ' . TABLE_ARTICLES . '.article_id, ' . TABLE_ARTICLES . '.article_subject, ' . TABLE_USERS . '.user_id, ' . TABLE_USERS . '.user_name
             FROM ' . TABLE_ARTICLES . ', ' . TABLE_USERS . '
             WHERE ' . TABLE_ARTICLES . '.user_id = ' . TABLE_USERS . '.user_id
             ORDER BY ' . TABLE_ARTICLES . '.article_date DESC
             LIMIT ' . $articles_offset . ', ' . $articles_per_page);
while ($table_articles = $sql->fetch())
{
    $article_date = date($date_format, ($table_articles['article_date'] + $date_offset));
    $template->set_var(array('ARTICLE_ID' => $table_articles['article_id'],
                             'ARTICLE_RELEASE' => sprintf($lang['ARTICLES_INDEX_RELEASE'], $table_articles['user_id'], $table_articles['user_name'], $article_date),
                             'ARTICLE_SUBJECT' => $table_articles['article_subject']));
    $template->parse('ARTICLES_BLOCK', 'articles', true);
    $articles_exist = true;
}
if (isset($articles_exist))
{
    $template->set_var(array('ARTICLES_INDEX_HEADER' => $lang['ARTICLES_INDEX_HEADER'],
                             'ARTICLES_INDEX_PAGES' => sprintf($lang['ARTICLES_INDEX_PAGES'], $pages_list),
                             'BACK_HOME' => $lang['BACK_HOME']));
    $template->parse('index');
}
else
{
    error_template($lang['ARTICLES_INDEX_ERROR']);
}

page_footer();

?>
Return current item: GENU