Location: PHPKode > projects > Gnew > Gnew-2013.1/polls/view.php
<?php
// -----------------------------------------------------------------------------
// $Id: view.php 676 2013-03-27 13:38:34Z 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_VIEW']);

// Check query
if (!empty($_GET['question_id']) && string_is_int($_GET['question_id']))
{
    $sql->query('SELECT t1.user_id, t1.question_comment, t1.question_text, t1.question_votes, t1.question_creation, t1.question_edition, t1.edition_id, t1.edition_name, t2.user_name
                 FROM ' . TABLE_QUESTIONS . ' AS t1
                 INNER JOIN ' . TABLE_USERS . ' AS t2
                             ON (t2.user_id = t1.user_id)
                 WHERE t1.question_id = \'' . $_GET['question_id'] . '\'');
    $table_questions = $sql->fetch();
    // Check question
    if (!$table_questions['question_text'])
    {
        error_template($lang['ERROR_NO_DATA']);
    }
    else
    {
        $template->set_file('view', 'polls/view.htpl');
        $template->set_block('view', 'ANSWERS_BLOCK', 'answers');
        $sql->query('SELECT answer_text, answer_votes
                     FROM ' . TABLE_ANSWERS . '
                     WHERE question_id = \'' . $_GET['question_id'] . '\'
                     ORDER BY answer_id');
        while ($table_answers = $sql->fetch())
        {
            if ($table_questions['question_votes'] == 0)
            {
                $image_width = 0;
            }
            else
            {
                $image_width = round(($table_answers['answer_votes'] / $table_questions['question_votes']) * 100);
            }
            $template->set_var(array('ANSWER_TEXT' => $table_answers['answer_text'],
                                     'ANSWER_VOTES' => $table_answers['answer_votes'],
                                     'IMAGE_WIDTH' => $image_width));
            $template->parse('ANSWERS_BLOCK', 'answers', true);
        }
        if ($table_questions['question_edition'])
        {
            $question_edited = sprintf($lang['EDITED_BY'], $table_questions['edition_id'], $table_questions['edition_name'], format_date($table_questions['question_edition']));
        }
        else
        {
            $question_edited = '';
        }
        $template->set_var(array('QUESTION_COMMENT' => $table_questions['question_comment'],
                                 'QUESTION_EDITED' => $question_edited,
                                 'QUESTION_POSTED' => sprintf($lang['POSTED_BY'], $table_questions['user_id'], $table_questions['user_name'], format_date($table_questions['question_creation'])),
                                 'QUESTION_TEXT' => $table_questions['question_text'],
                                 'QUESTION_VOTES' => sprintf($lang['TOTAL_VOTES'], $table_questions['question_votes'])));
        $template->parse('view', null, false, array(TABLE_ANSWERS, TABLE_QUESTIONS));
    }
}
else
{
    error_template($lang['ERROR_NO_DATA']);
}

page_footer();

?>
Return current item: Gnew