Location: PHPKode > projects > Gnew > Gnew-2013.1/posts/index.php
<?php
// -----------------------------------------------------------------------------
// $Id: index.php 673 2013-03-26 08:24:50Z raoul $
//
// Copyright (C) 2013 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.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

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

page_header($lang['POSTS_INDEX']);

$folder_image_tmp = $last_creation_tmp = $last_id_tmp = $last_name_tmp = array();
$sql->query('SELECT t1.category_id, t1.user_id, t1.post_creation, t3.category_level, t4.user_name
             FROM ' . TABLE_POSTS . ' AS t1
             INNER JOIN (SELECT category_id, MAX(post_creation) AS last_post
                         FROM ' . TABLE_POSTS . '
                         GROUP BY category_id
                         ORDER BY category_id) AS t2
                         ON (t2.category_id = t1.category_id AND t2.last_post = t1.post_creation)
             INNER JOIN ' . TABLE_CATEGORIES . ' AS t3
                         ON (t3.category_id = t1.category_id AND t3.category_level IN (\'0\', \'3\', \'4\'))
             INNER JOIN ' . TABLE_USERS . ' AS t4
                         ON (t4.user_id = t1.user_id)');
while ($table_posts = $sql->fetch())
{
    // Last ids, names and creations are allocated to categories
    $last_creation_tmp[$table_posts['category_id']] = $table_posts['post_creation'];
    $last_id_tmp[$table_posts['category_id']] = $table_posts['user_id'];
    $last_name_tmp[$table_posts['category_id']] = $table_posts['user_name'];

    // Images are allocated to categories
    if ($table_posts['category_level'] == 0)
    {
        if ($_SESSION['user_id'] > 0 && ($table_posts['post_creation'] > $users['user_last_visit']))
        {
            $folder_image_tmp[$table_posts['category_id']] = './../images/posts/private_new.png';
        }
        else
        {
            $folder_image_tmp[$table_posts['category_id']] = './../images/posts/private.png';
        }
    }
    else
    {
        if ($_SESSION['user_id'] > 0 && ($table_posts['post_creation'] > $users['user_last_visit']))
        {
            $folder_image_tmp[$table_posts['category_id']] = './../images/posts/folder_new.png';
        }
        else
        {
            $folder_image_tmp[$table_posts['category_id']] = './../images/posts/folder.png';
        }
    }
}

$template->set_file('index', 'posts/index.htpl');
$template->set_block('index', 'CATEGORIES_BLOCK', 'categories');
$sql->query('SELECT category_id, category_description, category_name, category_posts, category_threads
             FROM ' . TABLE_CATEGORIES . '
             WHERE category_level IN (\'0\', \'3\', \'4\')
             ORDER BY ' . $settings['categories_sorting'] . ' ' . $settings['categories_order']);
while ($table_categories = $sql->fetch())
{
    // Post(s) in category?
    if (array_key_exists($table_categories['category_id'], $last_creation_tmp))
    {
        $last_creation = format_date($last_creation_tmp[$table_categories['category_id']]);
        $last_id = $last_id_tmp[$table_categories['category_id']];
        $last_name = $last_name_tmp[$table_categories['category_id']];
        $folder_image = $folder_image_tmp[$table_categories['category_id']];
    }
    else
    {
        $last_creation = $last_id = $last_name = '';
        $folder_image = './../images/posts/folder.png';
    }
    // Description in category?
    if (!empty($table_categories['category_description']))
    {
        $category_description = $table_categories['category_description'];
    }
    else
    {
        $category_description = '';
    }
    $template->set_var(array('CATEGORY_DESCRIPTION' => $category_description,
                             'CATEGORY_ID' => $table_categories['category_id'],
                             'CATEGORY_NAME' => $table_categories['category_name'],
                             'CATEGORY_POSTS' => $table_categories['category_posts'],
                             'CATEGORY_THREADS' => $table_categories['category_threads'],
                             'FOLDER_IMAGE' => $folder_image,
                             'LAST_CREATION' => $last_creation,
                             'LAST_ID' => $last_id,
                             'LAST_NAME' => $last_name));
    $template->parse('CATEGORIES_BLOCK', 'categories', true);
    $categories_exist = true;
}

if (isset($categories_exist))
{
    $template->parse('index', null, false, array(TABLE_CATEGORIES, TABLE_POSTS, TABLE_USERS));
}
else
{
    error_template($lang['ERROR_NO_CATEGORY']);
}

page_footer();

?>
Return current item: Gnew