Exemplo n.º 1
0
 public function add_votes()
 {
     $ok = 1;
     global $current_user;
     get_currentuserinfo();
     $cheked = 0;
     global $message;
     $poll_total_votes = 0;
     if (isset($_POST['total_number_of_votes']) && $_POST['total_number_of_votes'] != 0) {
         $no_of_votes = $_REQUEST['total_number_of_votes'];
     }
     $add_to_results = "";
     $current_poll = new YOP_POLL_Poll_Model($_POST['poll_id']);
     if (current_user_can('add_yop_poll_votes')) {
         $index = 0;
         $i = 0;
         $message['append_row'] = "";
         $append_row = "";
         while ($ok == 1) {
             // yop_poll_dump($answer_details);
             $ok = 0;
             $i = 0;
             $details = "";
             $max = 100;
             $question_count = 0;
             foreach ($current_poll->questions as $question) {
                 $bulkanswers = $_POST['yoppollresultsanswerscheck'][$question->ID];
                 $details .= $question->question . ": ";
                 $answer_count = 0;
                 foreach ($question->answers as $answer) {
                     $answer_count++;
                     if (isset($bulkanswers)) {
                         foreach ($bulkanswers as $bulkanswer) {
                             if ($bulkanswer == $answer->ID) {
                                 $cheked = 1;
                                 if ($_POST['yop_poll_no_of_votes_' . $answer->ID . '_per_answer'] != "") {
                                     if ($_POST['yop_poll_no_of_votes_' . $answer->ID . '_per_answer'] != 0) {
                                         if ($_POST['yop_poll_no_of_votes_' . $answer->ID . '_per_answer'] > $index) {
                                             $answer_details["q-" . $question->ID]['question'] = $question->question . ": ";
                                             $answer_details["q-" . $question->ID]['id'] = $question->ID;
                                             $ok = 1;
                                             $details .= $answer->answer . ",";
                                             $add_to_results .= $answer->answer;
                                             $answer->votes = $answer->votes + 1;
                                             $answer_details["q-" . $question->ID]['a'][] = $answer->ID;
                                             $answer_details["q-" . $question->ID]['answers'][] = $answer->answer;
                                             $a = new YOP_POLL_Answer_Model($answer->ID);
                                             $a->votes++;
                                             $a->update();
                                             $poll_total_votes++;
                                         }
                                     } else {
                                         $message['error'] = "Answer input from answer " . $answer_count . " Question " . ($question_count + 1) . " is zero!";
                                         wp_die(json_encode($message));
                                     }
                                 } else {
                                     $message['error'] = "Answer input from answer " . $answer_count . " Question " . ($question_count + 1) . " is not set!";
                                     wp_die(json_encode($message));
                                 }
                             }
                         }
                     }
                 }
                 $details .= "<br>";
                 $question_count++;
             }
             if ($ok == 1) {
                 $current_poll->poll_total_votes += $poll_total_votes;
                 $poll_total_votes = 0;
                 $current_poll->update_no_votes();
                 $current_poll->save();
                 $result['vote_details'] = json_encode($answer_details);
                 $result['poll_id'] = $_POST['poll_id'];
                 $result['ip'] = yop_poll_get_ip();
                 $result['user_type'] = "admin";
                 $result['vote_id'] = uniqid('vote_id_');
                 $result['user_id'] = $current_user->ID;
                 $message = insert_result_in_db($result);
                 $index++;
                 $append_row[$i] .= " <tr valign=" . 'middle' . " class=" . 'alternate' . "\r\n                    id=" . 'yop-poll-log{{log.id}}' . ">\r\n                    <th class=" . 'check-column' . " scope=" . 'row' . ">\r\n                        <input type=" . 'checkbox' . " value=" . $message['insert_id'] . "\r\n                               name=" . 'yoppollresultscheck[]' . ">\r\n                    </th>\r\n                    <td><strong>" . $result['vote_id'] . "</strong>\r\n                        <br>\r\n                        <div class=" . 'row-actions' . ">\r\n                                                    <span class=" . 'delete' . ">\r\n                                                       <a\tonclick=" . 'return confirm( ' . ' "You are about to delete this result" ' . ') :  "Cancel"   "to stop" ,  "OK"  "to delete' . ')' . "\r\n\r\n                                                              href=" . '?page=yop-polls&action=delete_result&resultid=' . $message['insert_id'] . "\r\n\r\n                                                            class=" . 'submitdelete' . ">Delete</a></span>|<span class=" . 'delete' . ">\r\n                                                         <a\r\n                                                              onclick=" . 'show_pop_up_ban(' . ($max + 1) . ')' . "\r\n                                                            class=" . 'submitdelete' . ">Ban</a></span>\r\n                        </div></td>\r\n                    <td style=" . 'display:none;' . " class=" . 'hidden_tds' . "><input  id=" . 'yop-poll-results-ip_' . ($max + 1) . " value=" . $result['ip'] . "><input></td>\r\n                    <td style=" . 'display: none' . " class=" . 'hidden_tds' . "><input  id=" . 'yop-poll-results-userid_' . ($max + 1) . " value=" . $current_user->ID . "><input></td>\r\n                    <td>\r\n                        Admin\r\n                    </td>\r\n                    <td>\r\n                    </td>\r\n                    <td>\r\n                " . $result['ip'] . "\r\n                    </td>\r\n                    <td>\r\n                     " . current_time('mysql') . "\r\n                    </td>\r\n                    <td class=" . 'more_details' . " style=" . '"' . 'cursor:pointer;' . '"' . ">\r\n                    </td>\r\n                      <td class=" . 'less_details' . " style=" . '"' . 'cursor:pointer;' . '"' . " >\r\n                     </td>\r\n                </tr>\r\n                <tr  class=" . 'results_details' . " class=" . 'hidden_tds' . ">\r\n                    <td></td> <td></td>\r\n                    <td>  Questions<br><strong>" . $details . "</strong><br></td>\r\n                </tr>";
                 //   yop_poll_dump($i);
                 $i = $i + 1;
                 unset($answer_details);
             }
             if ($cheked == 0) {
                 $message['error'] = "You must select at least one answer!";
                 wp_die(json_encode($message));
             }
         }
     } else {
         $message['error'] = "You don't have enough permissions do add a vote!";
         wp_die(json_encode($message));
     }
     //yop_poll_dump($append_row);
     foreach ($append_row as $a) {
         $message['append_row'] .= $a;
     }
     wp_die(json_encode($message));
     // self::view_results_votes();
 }
Exemplo n.º 2
0
    public function activation_hook($default)
    {
        ini_set('max_execution_time', 700);
        $current_options = get_option('yop_poll_options');
        $polls = self::yop_poll_get_polls_from_db();
        $answers = self::yop_poll_get_answers_from_db();
        $logs = self::yop_poll_get_logs_from_db();
        $bans = self::yop_poll_get_bans_from_db();
        $custom_fields = self::yop_poll_get_custom_fields_from_db();
        $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
        $metas = self::yop_poll_get_polls_meta_from_db();
        $answers_meta = self::yop_poll_get_answers_meta_from_db();
        $templates = self::yop_poll_get_templates_from_db();
        foreach ($templates as $template) {
            $template['before_vote_template'] = "[QUESTION_CONTAINER]" . $template['before_vote_template'];
            $template['before_vote_template'] = str_replace('%POLL-ANSWER-LABEL%', '%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]', $template['before_vote_template']);
            $template['before_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['before_vote_template']);
            $template['before_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['before_vote_template']);
            $template['after_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_vote_template']);
            $template['after_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_vote_template']);
            $template['after_end_date_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_end_date_template']);
            $template['after_end_date_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_end_date_template']);
            $template['before_vote_template'] = preg_replace('/%POLL-ANSWER-RESULT-BAR%/', '%POLL-ANSWER-RESULT-BAR%  [/ANSWER_RESULT_CONTAINER]', $template['before_vote_template'], 1);
            $find = '[/ANSWER_RESULT_CONTAINER]';
            $replace = '';
            //   $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
            $template['after_vote_template'] = "[QUESTION_CONTAINER]" . $template['after_vote_template'];
            $template['after_end_date_template'] = "[QUESTION_CONTAINER]" . $template['after_end_date_template'];
            /*  if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
                    $template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
                else{
                    $template['before_vote_template']=str_replace('<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">','[/QUESTION_CONTAINER]<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">',$template['before_vote_template']);
                } */
            $template['before_vote_template'] = $template['before_vote_template'] . '[/QUESTION_CONTAINER]';
            if (strpos($template['before_vote_template'], "%POLL-QUESTION%") && strpos($template['before_vote_template'], '%POLL-NAME%')) {
                $template['before_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['before_vote_template']);
                $template['before_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['before_vote_template']);
            }
            if (strpos($template['after_vote_template'], "%POLL-QUESTION%") && strpos($template['after_vote_template'], '%POLL-NAME%')) {
                $template['after_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['after_vote_template']);
                $template['after_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['after_vote_template']);
            }
            $template['after_vote_template'] = $template['after_vote_template'] . '[/QUESTION_CONTAINER]';
            $template['after_end_date_template'] = $template['after_end_date_template'] . '[/QUESTION_CONTAINER]';
            $template['js'] = <<<NOWDOC
function stripBorder_%POLL-ID%(object) {
\tobject.each(function() {
\t\tif( parseInt(jQuery(this).width() ) > 0) {
\t\t\tjQuery(this).width(
\t\t\t\tparseInt(
\t\t\t\t\tjQuery(this).width() ) -
\t\t\t\t\tparseInt(jQuery(this).css("border-left-width")) -
\t\t\t\t\tparseInt(jQuery(this).css("border-right-width"))
\t\t\t);
\t\t\t}
\t\telse {
\t\tjQuery(this).css("border-left-width", "0px");
\t\tjQuery(this).css("border-right-width", "0px");
\t\t}
\t});
}
function stripPadding_%POLL-ID%(object) {
\tobject.each(function() {
\t\tjQuery(this).width(
\t\tparseInt( jQuery(this).width() ) -
\t\tparseInt(jQuery(this).css("padding-left")) -
\t\tparseInt(jQuery(this).css("padding-left"))
\t\t);
\t});
}

function strip_results_%POLL-ID%() {
\tstripPadding_%POLL-ID%( jQuery("#yop-poll-container-%POLL-ID% .yop_poll_li_result-%POLL-ID%") );
\tstripBorder_%POLL-ID%(  jQuery("#yop-poll-container-%POLL-ID% .yop-poll-result-bar-%POLL-ID%") );
}

jQuery(document).ready(function(e) {
   jQuery('.yop-poll-forms').removeClass('yop-poll-forms-display');
\tif(typeof window.strip_results_%POLL-ID% == "function")
\t\tstrip_results_%POLL-ID%();
\tif(typeof window.tabulate_answers_%POLL-ID% == "function")
\t\ttabulate_answers_%POLL-ID%();
\tif(typeof window.tabulate_results_%POLL-ID% == "function")
\t\ttabulate_results_%POLL-ID%();



});

function equalWidth_%POLL-ID%(obj, cols, findWidest ) {

    findWidest  = typeof findWidest  !== "undefined" ? findWidest  : false;
    var quest=0;
    if ( findWidest ) {
        obj.each(function() {
            var thisWidth = jQuery(this).width();
            width = parseInt(thisWidth / cols);
            jQuery(this).width(width);
            jQuery(this).css("float", "left");
        });
    }
    else {
        var widest = 0;
        var count  = 0;
        var poz_each_question=0;

        obj.each(function() {

            count++;
            cols[quest][2]=(jQuery('#yop-poll-answers-%POLL-ID%-'+ cols[quest][3] +' li').length);
            var thisWidth = jQuery(this).width();
            if(thisWidth > widest) {
                widest = thisWidth;
            }
            if(count<cols[quest][2])
            { width = parseInt( %POLL-WIDTH% / cols[quest][0]);
             if(cols[quest][0]==1)
                        jQuery(".yop-poll-li-answer-%POLL-ID%-"+cols[quest][3]).css("width","100%");
             else
                         jQuery(".yop-poll-li-answer-%POLL-ID%-"+cols[quest][3]).width(width-20);
             jQuery(".yop-poll-li-answer-%POLL-ID%-"+cols[quest][3]).css("float", "left");
            }
            else
            {
                count=0;


                width = parseInt( %POLL-WIDTH% / cols[quest][0]);
                jQuery(".yop-poll-li-answer-%POLL-ID%-"+cols[quest][3]).width(width-20);
                jQuery(".yop-poll-li-answer-%POLL-ID%-"+cols[quest][3]).css("float", "left");
                quest++;
            }

        });
}
}

function equalWidth2_%POLL-ID%(obj, cols, findWidest ) {
    findWidest  = typeof findWidest  !== "undefined" ? findWidest  : false;
    var quest=0;

    if ( findWidest ) {
        obj.each(function() {
            var thisWidth = jQuery(this).width();
            width = parseInt(thisWidth / cols);
            jQuery(this).width(width);
            jQuery(this).css("float", "left");
        });
    }
    else {
        var widest = 0;
        var count  = 0;
        var poz_each_question=0;

        obj.each(function() {
            count++;
            cols[quest][2]=(jQuery('#yop-poll-answers-%POLL-ID%-'+ cols[quest][3] +' li').length);
            var thisWidth = jQuery(this).width();
            if(thisWidth > widest) {
                widest = thisWidth;
            }
            if(count<cols[quest][2])
            { width = parseInt( %POLL-WIDTH% / cols[quest][1]);
             jQuery(".yop-poll-li-result-%POLL-ID%-"+cols[quest][3]).width(width-20);
             jQuery(".yop-poll-li-result-%POLL-ID%-"+cols[quest][3]).css("float", "left");
            }
            else
            {
                count=0;


                width = parseInt( %POLL-WIDTH% / cols[quest][1]);
                jQuery(".yop-poll-li-result-%POLL-ID%-"+cols[quest][3]).width(width-20);
                jQuery(".yop-poll-li-result-%POLL-ID%-"+cols[quest][3]).css("float", "left");
                quest++;
            }

        });
}
}
function tabulate_answers_%POLL-ID%() {

\tequalWidth_%POLL-ID%( jQuery("#yop-poll-container-%POLL-ID% .yop-poll-li-answer-%POLL-ID%"), %ANSWERS-TABULATED-COLS% );
\t//equalWidth_%POLL-ID%( jQuery("#yop-poll-container-%POLL-ID% .yop-poll-li-answer-%POLL-ID% .yop-poll-results-bar-%POLL-ID% div "), %ANSWERS-TABULATED-COLS%, true );
}

function tabulate_results_%POLL-ID%() {
\tequalWidth2_%POLL-ID%( jQuery("#yop-poll-container-%POLL-ID% .yop-poll-li-result-%POLL-ID%"), %RESULTS-TABULATED-COLS% );
\t//equalWidth_%POLL-ID%( jQuery("#yop-poll-container-%POLL-ID% .yop-poll-li-result-%POLL-ID% .yop-poll-results-bar-%POLL-ID% div "), %RESULTS-TABULATED-COLS%, true );
\t}

jQuery(document).ready(function(){
\trunOnPollStateChange_%POLL-ID%();
});

function runOnPollStateChange_%POLL-ID%() {

};

NOWDOC;
            $template['js'] = addslashes($template['js']);
            $templates_ids[$template['id']] = self::insert_template_in_databease($template);
        }
        foreach ($polls as $poll) {
            foreach ($answers as $answer) {
                if ($answer['poll_id'] == $poll['id']) {
                    $answers_ordonate[$poll['id']][] = (array) $answer;
                }
                if ($answer['poll_id'] > $poll['id']) {
                    break;
                }
                foreach ($logs as $log) {
                    if ($log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id']) {
                        $logs_ordonate[$poll['id']][] = (array) $log;
                        $logs_ordonate_details[$log['id']][] = $answer['answer'];
                    }
                }
                foreach ($answers_meta as $answer_meta) {
                    if ($answer_meta['yop_poll_answer_id'] == $answer['id']) {
                        $answer_meta_ordonate[$answer['id']][] = (array) $answer_meta;
                    }
                }
            }
            foreach ($bans as $ban) {
                if ($ban['poll_id'] == $poll['id']) {
                    $bans_ordonate[$poll['id']][] = (array) $ban;
                }
                if ($ban['poll_id'] > $poll['id']) {
                    break;
                }
            }
            foreach ($metas as $meta) {
                if ($meta['yop_poll_id'] == $poll['id']) {
                    $metas_ordonate[$poll['id']][] = (array) $meta;
                }
                if ($meta['yop_poll_id'] > $poll['id']) {
                    break;
                }
            }
            foreach ($custom_fields as $custom_field) {
                if ($custom_field['poll_id'] == $poll['id']) {
                    $custom_fields_ordonate[$poll['id']][] = (array) $custom_field;
                    if ($custom_field['poll_id'] > $poll['id']) {
                        break;
                    }
                    foreach ($custom_votes as $custom_vote) {
                        if ($custom_field['id'] == $custom_vote['custom_field_id']) {
                            $custom_votes_fields_ordonate[$custom_field['id']][] = (array) $custom_vote;
                        }
                    }
                }
            }
        }
        foreach ($polls as $poll) {
            $current_poll = new YOP_POLL_Poll_Model();
            $current_poll->poll_author = $poll['poll_author'];
            $current_poll->ID = $poll['id'];
            $current_poll->poll_title = $poll['name'];
            $current_poll->poll_name = $poll['name'];
            $current_poll->poll_date = $poll['date_added'];
            $current_poll->poll_modified = $poll['last_modified'];
            $current_poll->poll_status = $poll['status'];
            $current_poll->poll_type = "poll";
            $current_poll->poll_status = $poll['status'];
            $current_poll->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>

                                                            <p>Vote Details:</p>

                [QUESTION]

                                                            <p><b>Question:</b> %QUESTION_TEXT%</p>

                                                            <p><b>Answers:</b> <br />

                                                            [ANSWERS]

                                                            %ANSWER_VALUE%

                                                            [/ANSWERS]

                                                            </p>

                                                            <p><b>Custom Fields:</b> <br />

                                                            [CUSTOM_FIELDS]

                                                            %CUSTOM_FIELD_NAME% - %CUSTOM_FIELD_VALUE%

                                                            [/CUSTOM_FIELDS]

                                                            </p>

                [/QUESTION]

                                                            <p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
            if ($poll['end_date'] <= "2038-01-18 23:59:59") {
                $current_poll->poll_end_date = convert_date($poll['end_date'], 'd-m-Y H:i:s', 1);
            } else {
                $current_poll->poll_end_date = "01-01-2038 23:59:59";
            }
            if ($poll['start_date'] <= "2038-01-18 23:59:59") {
                $current_poll->poll_start_date = convert_date($poll['start_date'], 'd-m-Y H:i:s', 1);
            } else {
                $current_poll->poll_start_date = "01-01-2038 23:59:59";
            }
            $current_poll->poll_total_votes = $poll['total_votes'];
            $question = new YOP_POLL_Question_Model();
            $question->type = "text";
            $question->question = $poll['question'];
            $question->question_date = $current_poll->poll_date;
            $question->question_author = $current_poll->poll_author;
            $question->question_modified = $current_poll->poll_modified;
            $question->question_status = $current_poll->poll_status;
            $question->poll_order = 1;
            $i = 0;
            foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
                if ($answer_ordonate['type'] == "other") {
                    $current_poll->allow_other_answers = 'yes';
                    $question->allow_other_answers = 'yes';
                }
            }
            $q[] = $question;
            // yop_poll_dump($current_poll);
            $current_poll->questions = $q;
            $current_poll->auto_generate_poll_page = "no";
            $current_poll_id = $current_poll->insert();
            $current_poll_id = $current_poll->ID;
            // yop_poll_dump($current_poll->save())
            $no_modif = 0;
            $no_modif2 = 0;
            $current_poll_meta = $current_options;
            if (isset($metas_ordonate[$poll['id']])) {
                $poll_option = maybe_unserialize($metas_ordonate[$poll['id']][0]['meta_value']);
                foreach ($current_options as $key => $value) {
                    if (isset($poll_option[$key])) {
                        if ($key == 'view_results_permissions') {
                            list($g1, $d) = explode('-', $poll_option[$key]);
                            if ($g1 == "quest") {
                                $g1 = "guest";
                            }
                            $current_poll_meta[$key] = array($g1, $d);
                            $no_modif = 1;
                        } else {
                            if ($key == 'vote_permisions') {
                                list($g1, $d) = explode('-', $poll_option['vote_permisions']);
                                if ($g1 == "quest") {
                                    $g1 = "guest";
                                }
                                $no_modif2 = 1;
                                $current_poll_meta[$key] = array($g1, $d);
                            } else {
                                $current_poll_meta[$key] = $poll_option[$key];
                            }
                        }
                    } else {
                        $current_poll_meta[$key] = $default[$key];
                    }
                }
            }
            $current_poll_meta['view_results'] = array($poll_option['view_results']);
            $current_poll_meta['sorting_results'] = $default['sorting_answers'];
            if (!isset($poll_option['view_results_link'])) {
                $current_poll_meta['view_results_link'] = "yes";
            } else {
                $current_poll_meta['view_results_link'] = $poll_option['view_results_link'];
            }
            if ($poll_option['view_results'] == 'custom-date') {
                $current_poll_meta['view_results_start_date'] = $poll_option['view_results_start_date'];
            }
            if (empty($current_poll_meta['view_results'][0])) {
                $current_poll_meta['view_results'] = array('after');
            }
            if ($no_modif == 0 || empty($current_poll_meta['view_results'])) {
                $current_poll_meta['view_results_permissions'] = array('guest', 'registered');
            }
            if ($no_modif2 == 0 || empty($current_poll_meta['vote_permisions'])) {
                $current_poll_meta['vote_permisions'] = array('guest', 'registered');
            }
            if ($poll_option['blocking_voters'] == 'cookie-ip') {
                $current_poll_meta['blocking_voters'] = array("cookie", 'ip');
            } else {
                if ($poll_option['blocking_voters'] == 'username') {
                    $current_poll_meta['blocking_voters'] = array("user_id");
                } else {
                    $current_poll_meta['blocking_voters'] = array('dont-block');
                }
            }
            $current_poll_meta['facebook_share_after_vote'] = "no";
            $current_poll_meta['show_google_share_button'] = "no";
            $current_poll_meta['facebook_show_comments_widget'] = "no";
            $current_poll_meta['facebook_share_description'] = __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name');
            if (isset($poll_option['show_in_archive'])) {
                $current_poll_meta['show_poll_in_archive'] = $poll_option['show_in_archive'];
            }
            if (isset($poll_option['schedule_reset_poll_date'])) {
                $current_poll_meta['schedule_reset_poll_date'] = $poll_option['schedule_reset_poll_date'];
            }
            if (isset($poll_option['template'])) {
                $current_poll_meta['template'] = $templates_ids[$poll_option['template']];
            } else {
                $current_poll_meta['template'] = 1;
            }
            if (isset($poll_option['widget_template'])) {
                $current_poll_meta['widget_template'] = $templates_ids[$poll_option['widget_template']];
            } else {
                $current_poll_meta['widget_template'] = 1;
            }
            if (isset($poll_option['widget_template']) && isset($poll_option['template']) && $poll_option['template'] != $poll_option['widget_template']) {
                $current_poll_meta['use_the_same_template_for_widget'] = "no";
            }
            if (isset($poll_option['view_total_answers_label'])) {
                $current_poll_meta['view_total_answers_label'] = $default['view_total_answers_label'];
            }
            if (isset($poll_option['answer_result_label'])) {
                $current_poll_meta['answer_result_label'] = $default['answer_result_label'];
            }
            if ($current_poll_meta['vote_permisions_anonymous'] == "no" && $current_poll_meta['vote_permisions_wordpress'] == "no") {
                $current_poll_meta['vote_permisions_anonymous'] = "yes";
            }
            update_yop_poll_question_meta($current_poll_id, 'options', $current_poll_meta);
            update_yop_poll_meta($current_poll_id, 'options', $current_poll_meta);
            if ($poll['show_in_archive'] == "yes") {
                self::save_poll_order($current_poll_id, $poll['archive_order']);
            }
            if ($default['sorting_answers'] == "votes") {
                $answers_ordonate[$poll['id']] = self::get_answers_order_by_votes($poll['id'], $default['sorting_answers_direction']);
            }
            if ($default['sorting_answers'] == "alphabetical") {
                $answers_ordonate[$poll['id']] = self::get_answers_order_by_alph($poll['id'], $default['sorting_answers_direction']);
            }
            foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
                $ans = new YOP_POLL_Answer_Model();
                $ans->answer = $answer_ordonate['answer'];
                $ans->answer_author = $current_poll->poll_author;
                $ans->answer_date = $current_poll->poll_date;
                $ans->answer_modified = $poll['last_modified'];
                if ($answer_ordonate['type'] != "other") {
                    $ans->type = "text";
                } else {
                    $current_poll->allow_other_answers = 'yes';
                    $question->allow_other_answers = 'yes';
                    $ans->type = "other";
                }
                $ans->answer_status = $answer['status'];
                $ans->votes = $answer_ordonate['votes'];
                $ans->question_order = $i++;
                if ($answer_ordonate['type'] != "other") {
                    $answersa[] = $ans;
                    if (isset($answer_meta_ordonate[$answer_ordonate['id']])) {
                        $answer_option = maybe_unserialize($answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value']);
                        $answer_options = $ans->options;
                        foreach ($ans->options as $key => &$value) {
                            if (isset($answer_option[$key])) {
                                $ans->{$key} = $answer_option[$key];
                            }
                        }
                        $ans->options = $answer_options;
                    }
                    $question->addAnswer($ans);
                    $question->save_answers();
                    $answersids[$answer_ordonate['id']] = $ans->ID;
                }
            }
            if (!empty($custom_fields_ordonate[$poll['id']])) {
                foreach ($custom_fields_ordonate[$poll['id']] as $custom_ordonate) {
                    $oldid = $custom_ordonate['id'];
                    //   $question                       = $current_poll->questions;
                    $custom_ordonate['question_id'] = $current_poll_id;
                    $custom_ordonate['poll_id'] = $current_poll_id;
                    $newid = insert_custom_field_in_db($custom_ordonate);
                    foreach ($custom_votes_fields_ordonate[$oldid] as $votes) {
                        $votes['custom_field_id'] = $newid;
                        $votes['question_id'] = $current_poll_id;
                        $votes['poll_id'] = $current_poll_id;
                        $votes['id'] = insert_votes_custom_in_db($votes);
                        $custom_field_vote[$poll['id']][] = $votes;
                    }
                }
            }
            if (!empty($logs_ordonate[$poll['id']])) {
                foreach ($logs_ordonate[$poll['id']] as $log_ordonate) {
                    $log['poll_id'] = $current_poll_id;
                    $log['vote_id'] = $log_ordonate['vote_id'];
                    $log['ip'] = $log_ordonate['ip'];
                    $log['user_id'] = $log_ordonate['user_id'];
                    $log['user_type'] = $log_ordonate['user_type'];
                    $log['vote_date'] = $log_ordonate['vote_date'];
                    $log['tr_id'] = $log_ordonate['tr_id'];
                    $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
                    $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
                    $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
                    if ($log_ordonate['other_answer_value'] != "" && isset($log_ordonate['other_answer_value'])) {
                        $ans = new YOP_POLL_Answer_Model();
                        $ans->answer = $answer_ordonate['answer'];
                        $ans->answer_author = $current_poll->poll_author;
                        $ans->answer_date = $current_poll->poll_date;
                        $ans->answer_modified = $poll['last_modified'];
                        $ans->answer = $log_ordonate['other_answer_value'];
                        $ans->answer_status = 'active';
                        $ans->votes = 1;
                        $ans->type = 'other';
                        $ans->question_order = $i++;
                        $question->addAnswer($ans);
                        $question->save_answers();
                    }
                    if (!empty($custom_field_vote[$poll['id']])) {
                        foreach ($custom_field_vote[$poll['id']] as $vote) {
                            if ($vote['vote_id'] == $log_ordonate['vote_id']) {
                                $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
                            }
                        }
                    }
                    foreach ($logs_ordonate_details[$log_ordonate['id']] as $a) {
                        $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
                        $log['vote_details'] = json_encode($vote_details[1]);
                        $log['message'] = "Succes";
                        insert_result_in_db($log);
                        insert_log_in_db($log);
                        unset($vote_details[1]["q-" . $current_poll_id]['answers']);
                    }
                    unset($vote_details);
                }
            }
            if (!empty($bans_ordonate[$poll['id']])) {
                foreach ($bans_ordonate[$poll['id']] as $ban_ordonate) {
                    $ban = $ban_ordonate;
                    $ban['poll_id'] = $current_poll_id;
                    self::insert_ban_in_db($ban);
                }
            }
        }
    }
Exemplo n.º 3
0
 public function register_vote($request)
 {
     global $current_user;
     $poll_id = $this->id;
     $unique_id = strip_tags(xss_clean($this->unique_id));
     $location = strip_tags(xss_clean($request['location']));
     $vote_id = uniqid('vote_id_');
     $vote_type = $request['vote_type'];
     $SuperCookie = strip_tags(xss_clean($request['supercookie']));
     $tr_id = strip_tags(xss_clean($request['yop_poll_tr_id']));
     $votes = 0;
     $user_id = 0;
     $user_type = 'default';
     $user_details = '';
     if (wp_verify_nonce($request['yop-poll-nonce-' . $poll_id . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions')) {
         switch ($vote_type) {
             default:
                 $user_id = $current_user->ID != null ? $current_user->ID : 0;
                 $user_type = 'default';
                 break;
             case 'wordpress':
                 $user_id = $current_user->ID;
                 $user_type = 'wordpress';
                 break;
             case 'anonymous':
                 $user_type = 'anonymous';
                 break;
         }
         $log_to_add = array('poll_id' => $this->ID, 'vote_id' => $vote_id, 'ip' => yop_poll_get_ip(), 'user_id' => $user_id, 'user_type' => $user_type, 'user_details' => json_encode($user_details), 'tr_id' => $tr_id);
     } else {
         $this->error = __yop_poll('Bad Request!');
         $log_to_add['message'] = __yop_poll('Bad request');
         insert_log_in_db($log_to_add);
         return false;
     }
     if (wp_verify_nonce($request['yop-poll-nonce-' . $this->ID . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions')) {
         $tr_id = $request['yop_poll_tr_id'];
         $super_perm = true;
         if (in_array("supercookie", $this->blocking_voters)) {
             $super_perm = $this->is_voted_supercookie($SuperCookie);
         }
         if ($super_perm == true) {
             $current_date = yop_poll_get_mysql_curent_date();
             if ($this->is_allowed_to_vote($vote_type)) {
                 if ($current_date >= convert_date($this->poll_start_date, 'Y-m-d H:i:s')) {
                     if ($current_date <= convert_date($this->poll_end_date, 'Y-m-d H:i:s')) {
                         if ('closed' == $this->status) {
                             $this->error = __yop_poll('This poll is closed!');
                             $log_to_add['message'] = __yop_poll('Poll Closed');
                             insert_log_in_db($log_to_add);
                             return false;
                         } else {
                             if (!$this->is_voted($vote_type, $facebook_user_details, $google_user_details, true, $SuperCookie)) {
                                 $voter = array();
                                 $voter['poll_id'] = $poll_id;
                                 $voter['user_id'] = $current_user->ID;
                                 $voter['user_type'] = $vote_type;
                                 if ($this->user_have_votes_to_vote($voter, $SuperCookie)) {
                                     $i = 1;
                                     $cookie = '';
                                     $log = array();
                                     foreach ($this->questions as &$question) {
                                         $answers = array();
                                         if (isset($request['yop_poll_answer'][$question->ID])) {
                                             if ('yes' == $question->allow_multiple_answers) {
                                                 if (count($request['yop_poll_answer'][$question->ID]) <= intval($question->allow_multiple_answers_number)) {
                                                     if (count($request['yop_poll_answer'][$question->ID]) >= intval($question->allow_multiple_answers_min_number)) {
                                                         $answers = array();
                                                         foreach ($request['yop_poll_answer'][$question->ID] as $answer) {
                                                             $new_answer = array();
                                                             $new_answer['answer_id'] = $answer;
                                                             $new_answer['type'] = 'default';
                                                             if ('other' == $answer) {
                                                                 $a = new YOP_POLL_Answer_Model();
                                                                 if (isset($request['yop_poll_other_answer'][$question->ID]) && '' != strip_tags(trim($request['yop_poll_other_answer'][$question->ID]))) {
                                                                     $a->type = 'other';
                                                                     $a->poll_id = $poll_id;
                                                                     $a->question_id = $question->ID;
                                                                     $a->answer = strip_tags(trim($request['yop_poll_other_answer'][$question->ID]));
                                                                     $a->answer_date = current_time('mysql');
                                                                     $a->answer_modified = current_time('mysql');
                                                                     $a->status = 'active';
                                                                     $a->question_order = $question->countanswers() + 1;
                                                                     $a->answer_author = $current_user->ID;
                                                                     $a->save();
                                                                     if (!$a->id) {
                                                                         $this->error = __yop_poll('Other answer for question ') . $i . __yop_poll(' could not be inserted!');
                                                                         $log_to_add['message'] = __yop_poll('Other answer for question ') . $i . __yop_poll(' could not be inserted');
                                                                         insert_log_in_db($log_to_add);
                                                                         return false;
                                                                     }
                                                                 } else {
                                                                     $this->error = __yop_poll('Other answer from question ') . $i . __yop_poll(' is empty');
                                                                     $log_to_add['message'] = __yop_poll('Other answer from question ') . $i . __yop_poll(' is empty');
                                                                     insert_log_in_db($log_to_add);
                                                                     return false;
                                                                 }
                                                                 $question->addAnswer($a);
                                                                 $new_answer['answer_id'] = $a->id;
                                                                 $new_answer['type'] = 'other';
                                                                 unset($a);
                                                             }
                                                             $new_answer['poll_id'] = $poll_id;
                                                             $new_answer['vote_id'] = $vote_id;
                                                             $new_answer['ip'] = yop_poll_get_ip();
                                                             $new_answer['user_id'] = $current_user->ID;
                                                             $new_answer['user_type'] = 'default';
                                                             if ($vote_type == 'anonymous' || $vote_type == 'wordpress') {
                                                                 $new_answer['user_type'] = $vote_type;
                                                             }
                                                             $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
                                                             $new_answer['tr_id'] = $tr_id;
                                                             $new_answer['host'] = esc_attr(@gethostbyaddr(yop_poll_get_ip()));
                                                             $new_answer['other_answer_value'] = '';
                                                             $answers[] = $new_answer;
                                                         }
                                                     } else {
                                                         $this->error = __yop_poll("Too few answers selected for question ") . $i . __yop_poll("! Only more than ") . $question->allow_multiple_answers_min_number . __yop_poll(" answers allowed!");
                                                         $log_to_add['message'] = __yop_poll("Too few answers selected for question ") . $i;
                                                         insert_log_in_db($log_to_add);
                                                         return false;
                                                     }
                                                 } else {
                                                     $this->error = __yop_poll("Too many answers selected for question ") . $i . __yop_poll("! Only ") . $question->allow_multiple_answers_number . __yop_poll(" answers allowed!");
                                                     $log_to_add['message'] = __yop_poll("Too many answers selected for question ") . $i;
                                                     insert_log_in_db($log_to_add);
                                                     return false;
                                                 }
                                             } else {
                                                 $new_answer = array();
                                                 $new_answer['answer_id'] = $request['yop_poll_answer'][$question->ID];
                                                 $new_answer['type'] = 'default';
                                                 if ('other' == $request['yop_poll_answer'][$question->ID]) {
                                                     $a = new YOP_POLL_Answer_Model();
                                                     if (isset($request['yop_poll_other_answer'][$question->ID]) && '' != strip_tags(trim($request['yop_poll_other_answer'][$question->ID]))) {
                                                         $a->type = 'other';
                                                         $a->poll_id = $poll_id;
                                                         $a->question_id = $question->ID;
                                                         $a->answer = strip_tags(trim($request['yop_poll_other_answer'][$question->ID]));
                                                         $a->answer_date = current_time('mysql');
                                                         $a->question_order = $question->countanswers();
                                                         $a->answer_author = $current_user->ID;
                                                         $a->votes = 0;
                                                         $a->save();
                                                         if (!$a->id) {
                                                             $this->error = __yop_poll("Other answer for question ") . $i . __yop_poll(" could not be inserted!");
                                                             $log_to_add['message'] = __yop_poll("Other answer for question ") . $i . __yop_poll(" could not be inserted");
                                                             insert_log_in_db($log_to_add);
                                                             return false;
                                                         }
                                                     } else {
                                                         $this->error = __yop_poll("Other answer from question ") . $i . ' ' . __yop_poll('is empty');
                                                         $log_to_add['message'] = __yop_poll("Other answer from question ") . $i . ' ' . __yop_poll('empty');
                                                         insert_log_in_db($log_to_add);
                                                         return false;
                                                     }
                                                     $question->addAnswer($a);
                                                     $new_answer['answer_id'] = $a->id;
                                                     $new_answer['type'] = 'other';
                                                     unset($a);
                                                 }
                                                 $new_answer['poll_id'] = $poll_id;
                                                 $new_answer['vote_id'] = $vote_id;
                                                 $new_answer['ip'] = yop_poll_get_ip();
                                                 $new_answer['user_id'] = $current_user->ID;
                                                 $new_answer['user_type'] = 'default';
                                                 $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
                                                 $new_answer['tr_id'] = $tr_id;
                                                 $new_answer['host'] = esc_attr(@gethostbyaddr(yop_poll_get_ip()));
                                                 $new_answer['other_answer_value'] = '';
                                                 $answers[] = $new_answer;
                                             }
                                             if (count($answers) > 0) {
                                                 $custom_fields = array();
                                                 $poll_custom_fields = $question->custom_fields;
                                                 if (count($poll_custom_fields) > 0) {
                                                     if (isset($request['yop_poll_customfield'][$question->ID])) {
                                                         foreach ($poll_custom_fields as $custom_field) {
                                                             if (isset($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) {
                                                                 if ('' == trim(strip_tags($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) && 'yes' == $custom_field->required) {
                                                                     $this->error = __yop_poll("Custom field ") . $custom_field->custom_field . __yop_poll(" from question ") . $i . ' ' . __yop_poll("is required") . "!";
                                                                     $log_to_add['message'] = __yop_poll("Custom field ") . $custom_field->custom_field . __yop_poll(" from question ") . $i . ' ' . __yop_poll("required");
                                                                     insert_log_in_db($log_to_add);
                                                                     return false;
                                                                 } else {
                                                                     if (trim(strip_tags($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) != '') {
                                                                         $new_custom_field = array();
                                                                         $new_custom_field['poll_id'] = $poll_id;
                                                                         $new_custom_field['question_id'] = $question->ID;
                                                                         $new_custom_field['vote_id'] = $vote_id;
                                                                         $new_custom_field['custom_field_id'] = $custom_field->ID;
                                                                         $new_custom_field['user_id'] = $current_user->ID;
                                                                         $new_custom_field['user_type'] = 'default';
                                                                         if ($vote_type == 'wordpress' || $vote_type == 'anonymous') {
                                                                             $new_custom_field['user_type'] = $vote_type;
                                                                         }
                                                                         $new_custom_field['custom_field_value'] = strip_tags(trim($request['yop_poll_customfield'][$question->ID][$custom_field->ID]));
                                                                         $custom_fields[] = $new_custom_field;
                                                                     }
                                                                 }
                                                             } else {
                                                                 $this->error = __yop_poll("Custom field ") . '"' . $custom_field->custom_field . '"' . __yop_poll(" from question ") . $i . ' ' . __yop_poll("is missing ") . '!';
                                                                 $log_to_add['message'] = __yop_poll("Custom field ") . '"' . $custom_field->custom_field . '"' . __yop_poll(" from question ") . $i . ' ' . __yop_poll("missing");
                                                                 insert_log_in_db($log_to_add);
                                                                 return false;
                                                             }
                                                         }
                                                     } else {
                                                         $this->error = __yop_poll("Custom fields from question ") . $i . ' ' . __yop_poll("are missing") . '!';
                                                         $log_to_add['message'] = __yop_poll("Custom fields from question ") . $i . ' ' . __yop_poll("missing") . '!';
                                                         insert_log_in_db($log_to_add);
                                                         return false;
                                                     }
                                                 }
                                                 if ('yes' == $this->use_captcha) {
                                                     require_once YOP_POLL_INC . '/securimage.php';
                                                     $img = new Yop_Poll_Securimage();
                                                     $img->namespace = 'yop_poll_' . $poll_id . $unique_id;
                                                     if ($img->check($_REQUEST['yop_poll_captcha_input'][$poll_id])) {
                                                         $mail_notifications_answers[$question->ID] = array();
                                                         $add_to_log = $this->update_votes($question, $answers, $votes, $mail_notifications_answers[$question->ID], $facebook_user_details['id'], $google_user_details['id']);
                                                         $log["q-" . $question->ID]['question'] = $question->question;
                                                         $log["q-" . $question->ID]['a'] = $add_to_log['a'];
                                                         $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
                                                         $mail_notifications_answers[$question->ID] = trim($mail_notifications_answers[$question->ID], '<br>');
                                                         $mail_notifications_custom_fields[$question->ID] = '';
                                                         foreach ($custom_fields as $custom_field) {
                                                             if ('anonymous' == $vote_type) {
                                                                 $custom_field['user_id'] = 0;
                                                             }
                                                             $custom_field['tr_id'] = $tr_id;
                                                             self::insert_vote_custom_field_in_database($custom_field);
                                                             $cf = $question->getCustomFieldById($custom_field['custom_field_id']);
                                                             $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
                                                         }
                                                         if ('yes' == $this->number_of_votes_per_user) {
                                                             $this->success = str_replace('%USER-VOTES-LEFT%', intval($this->number_of_votes_per_user) - $this->get_voter_number_of_votes($voter), $poll_options['message_after_vote']);
                                                         } else {
                                                             $this->success = str_replace('%USER-VOTES-LEFT%', '', $this->message_after_vote);
                                                         }
                                                     } else {
                                                         $this->error = __yop_poll("Incorrect security code entered!");
                                                         $log_to_add['message'] = __yop_poll("Incorrect security code entered");
                                                         insert_log_in_db($log_to_add);
                                                         return false;
                                                     }
                                                 } else {
                                                     $mail_notifications_answers[$question->ID] = array();
                                                     $add_to_log = $this->update_votes($question, $answers, $votes, $mail_notifications_answers[$question->ID], $vote_type, $facebook_user_details['id'], $google_user_details['id']);
                                                     $log["q-" . $question->ID]['question'] = $question->question;
                                                     $log["q-" . $question->ID]['id'] = $question->ID;
                                                     $log["q-" . $question->ID]['a'] = $add_to_log['a'];
                                                     $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
                                                     $mail_notifications_custom_fields[$question->ID] = array();
                                                     $add_to_log = array();
                                                     foreach ($custom_fields as $custom_field) {
                                                         if ('google' == $vote_type) {
                                                             $custom_field['user_id'] = $google_user_details['id'];
                                                         }
                                                         if ('anonymous' == $vote_type) {
                                                             $custom_field['user_id'] = 0;
                                                         }
                                                         $custom_field['tr_id'] = $tr_id;
                                                         $cf_id = self::insert_vote_custom_field_in_database($custom_field);
                                                         $add_to_log[] = $cf_id;
                                                         $cf = $question->getCustomFieldById($custom_field['custom_field_id']);
                                                         $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
                                                     }
                                                     $log["q-" . $question->ID]['cf'] = $add_to_log;
                                                     if ('yes' == $this->number_of_votes_per_user) {
                                                         $this->success = str_replace('%USER-VOTES-LEFT%', intval($this->number_of_votes_per_user) - $this->get_voter_number_of_votes($voter), $this->message_after_vote);
                                                     } else {
                                                         $this->success = str_replace('%USER-VOTES-LEFT%', '', $this->message_after_vote);
                                                     }
                                                 }
                                             } else {
                                                 $this->error = __yop_poll("No vote registered!");
                                                 $log_to_add['message'] = __yop_poll("No vote registered");
                                                 insert_log_in_db($log_to_add);
                                                 return false;
                                             }
                                         } else {
                                             $this->error = __yop_poll("No answer selected for question ") . $i;
                                             $log_to_add['message'] = __yop_poll("No answer selected for question ") . $i;
                                             insert_log_in_db($log_to_add);
                                             return false;
                                         }
                                         $i++;
                                     }
                                 } else {
                                     $this->error = __yop_poll("You have run out of votes!");
                                     $log_to_add['message'] = __yop_poll("Run out of votes");
                                     insert_log_in_db($log_to_add);
                                     return false;
                                 }
                             } else {
                                 $this->error = __yop_poll("You Already voted!");
                                 $log_to_add['message'] = __yop_poll("Already Voted");
                                 insert_log_in_db($log_to_add);
                                 return false;
                             }
                         }
                     } else {
                         $this->error = __yop_poll("This poll is closed!");
                         $log_to_add['message'] = __yop_poll("Poll Closed");
                         insert_log_in_db($log_to_add);
                         return false;
                     }
                 } else {
                     $this->error = __yop_poll("You can vote once the poll starts!");
                     $log_to_add['message'] = __yop_poll("Poll not started");
                     insert_log_in_db($log_to_add);
                     return false;
                 }
             } else {
                 $this->error = __yop_poll("You are not allowed to vote!");
                 $log_to_add['message'] = __yop_poll("Not allowed to vote");
                 insert_log_in_db($log_to_add);
                 return false;
             }
         } else {
             $this->error = __yop_poll("You are not allowed to vote!");
             return false;
         }
     } else {
         $this->error = __yop_poll("Bad Request!");
         $log_to_add['message'] = __yop_poll("Bad request");
         insert_log_in_db($log_to_add);
         return false;
     }
     if ($this->send_email_notifications == "yes") {
         $this->sendMail($mail_notifications_answers, $mail_notifications_custom_fields, $vote_id);
     }
     $this->update_poll_total_votes(1);
     $log_to_add['message'] = __yop_poll('Success');
     $log_to_add['vote_details'] = json_encode($log);
     insert_log_in_db($log_to_add);
     $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $log_to_add['ip']));
     $log_to_add['country'] = $ip_data->geoplugin_countryName;
     insert_result_in_db($log_to_add);
     $this->set_vote_cookie(json_encode($log), $vote_type, $facebook_user_details, $google_user_details);
     $this->vote = true;
     $this->poll_total_votes += 1;
     return do_shortcode($this->return_poll_html(array('tr_id' => $tr_id, 'location' => $location)));
 }