Exemplo n.º 1
0
<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
$return = array('error_code' => 1, 'error_description' => t('Не указан ID голосования'), 'resp' => '');
if (isset($_POST['q_id']) && is_numeric($_POST['q_id']) && $_POST['type']) {
    // Учесть голос
    if ('vote' == $_POST['type']) {
        $question = new sp_question($_POST['q_id']);
        // Получим данные о голосовании
        if ($question->get()) {
            // Проверим, можно ли голосовать
            if ($question->check_allow()) {
                if (isset($_POST['a_id'])) {
                    // Ставим кукис
                    if (1 == $question->data->q_protection) {
                        set_cookie(array('name' => 'sp_' . $question->id, 'value' => TRUE, 'expire' => 3600 * 24 * 30 * 3));
                    }
                    // Учитываем голоса
                    foreach ($_POST['a_id'] as $a_id) {
                        $answer = new sp_answer($a_id);
                        $answer->inc();
                    }
                    // Запишем логи
                    sp_write_logs();
                    $question->update(array('q_totalvoters' => $question->data->q_totalvoters + 1, 'q_totalvotes' => $question->data->q_totalvotes + count($_POST['a_id'])));
                    if ($question->get()) {
                        $return['error_code'] = 0;
                        $return['error_description'] = '';
                        $return['resp'] = $question->results();