Location: PHPKode > projects > Gnew > Gnew-2013.1/polls/index.php
<?php
// -----------------------------------------------------------------------------
// $Id: index.php 642 2013-03-22 11:52:04Z 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['POLLS_INDEX']);

// Create pages list
if (empty($_GET['page']) || !string_is_int($_GET['page']))
{
    $_GET['page'] = 1;
}
$questions_per_page = $settings['questions_per_page'];
$polls_offset = ($_GET['page'] - 1) * $questions_per_page;
$sql->query('SELECT question_id
             FROM ' . TABLE_QUESTIONS);
$num_polls = $sql->num_rows();
$num_pages = ceil($num_polls / $questions_per_page);
$pages_list = get_pages_list('./../polls/index.php?', $num_pages);

$template->set_file('index', 'polls/index.htpl');
$template->set_block('index', 'QUESTIONS_BLOCK', 'questions');
$sql->query('SELECT question_id, question_text, question_votes
             FROM ' . TABLE_QUESTIONS . '
             ORDER BY ' . $settings['questions_sorting'] . ' ' . $settings['questions_order'] . '
             LIMIT ' . $questions_per_page . ' OFFSET ' . $polls_offset);
while ($table_questions = $sql->fetch())
{
    $template->set_var(array('QUESTION_ID' => $table_questions['question_id'],
                             'QUESTION_TEXT' => $table_questions['question_text'],
                             'QUESTION_VOTES' => sprintf($lang['VOTES'], $table_questions['question_votes'])));
    $template->parse('QUESTIONS_BLOCK', 'questions', true);
    $questions_exist = true;
}
if (isset($questions_exist))
{
    $template->set_var('PAGES', sprintf($lang['PAGES'], $pages_list));
    $template->parse('index', null, false, TABLE_QUESTIONS);
}
else
{
    error_template($lang['ERROR_NO_POLL']);
}

page_footer();

?>
Return current item: Gnew