Beispiel #1
0
 public static function reset_poll_stats_from_database($poll_id)
 {
     global $message;
     $current_poll = new YOP_POLL_Poll_Model($poll_id);
     $message = self::delete_result_from_db_by_poll_id($poll_id);
     $current_poll->poll_total_votes = 0;
     foreach ($current_poll->questions as &$question) {
         foreach ($question->answers as &$answer) {
             $answer->votes = 0;
         }
     }
     $current_poll->update_no_votes();
     $current_poll->save();
 }
Beispiel #2
0
 public static function save_poll($preview = false)
 {
     $new_poll = new YOP_POLL_Poll_Model($_POST['poll_id']);
     $new_poll->poll_title = stripslashes(trim($_POST['poll_title']));
     $new_poll->poll_name = sanitize_title($new_poll->poll_title);
     $new_poll->poll_author = $GLOBALS['current_user']->ID;
     $new_poll->poll_date = current_time('mysql');
     $new_poll->poll_status = 'active';
     $new_poll->poll_modified = current_time('mysql');
     $new_poll->poll_start_date = $_POST['poll_start_date'];
     $new_poll->poll_end_date = isset($_POST['poll_never_expire']) && 'yes' == $_POST['poll_never_expire'] ? '01-01-2038 23:59:59' : $_POST['poll_end_date'];
     $new_poll->poll_total_votes = 0;
     //poll options area
     if (isset($_POST['yop_poll_options']) && is_array($_POST['yop_poll_options']) && count($_POST['yop_poll_options']) > 0) {
         foreach ($_POST['yop_poll_options'] as $poll_option_field => $poll_option_value) {
             $new_poll->{$poll_option_field} = $poll_option_value;
         }
     }
     if (isset($_POST['yop_poll_options']['use_the_same_template_for_widget'])) {
         $new_poll->use_the_same_template_for_widget = 'yes';
         $new_poll->widget_template_width = $new_poll->template_width;
         $new_poll->widget_template = $new_poll->template;
     } else {
         $new_poll->use_the_same_template_for_widget = 'no';
     }
     $questions = array();
     if (isset($_POST['yop_poll_question']) && is_array($_POST['yop_poll_question']) && count($_POST['yop_poll_question']) > 0) {
         foreach ($_POST['yop_poll_question'] as $question_args) {
             $new_question = new YOP_POLL_Question_Model($question_args['question_id']);
             $new_question->question = trim($question_args['question']);
             $new_question->type = trim($question_args['type']);
             $new_question->question_modified = current_time('mysql');
             $new_question->poll_order = intval($question_args['poll_order']);
             if (!$new_question->exists()) {
                 //for insert
                 $new_question->question_author = $GLOBALS['current_user']->ID;
                 $new_question->question_date = current_time('mysql');
                 $new_question->question_status = 'active';
             }
             //question options area
             if (isset($question_args['options']) && is_array($question_args['options']) && count($question_args['options']) > 0) {
                 foreach ($question_args['options'] as $question_option_field => $question_option_value) {
                     $new_question->{$question_option_field} = $question_option_value;
                 }
             }
             $custom_fields = array();
             //question custom fields area
             if (isset($question_args['custom_fields']) && is_array($question_args['custom_fields']) && count($question_args['custom_fields']) > 0) {
                 foreach ($question_args['custom_fields'] as $question_custom_field) {
                     $cf_id = isset($question_custom_field['id']) ? trim($question_custom_field['id']) : 0;
                     $new_custom_field = new YOP_POLL_Custom_Field_Model($cf_id);
                     $new_custom_field->custom_field = trim($question_custom_field['custom_field']);
                     $new_custom_field->required = isset($question_custom_field['required']) ? trim($question_custom_field['required']) : 'no';
                     $new_custom_field->status = "active";
                     if ($new_custom_field->custom_field == "") {
                         $response['success'] = 0;
                         $response['id'] = -1;
                         $response['error'] = 1;
                         $response['message'] = __yop_poll('Custom Field') . ' ' . $question_custom_field['order'] . ' ' . __yop_poll('from Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                         wp_die(json_encode($response));
                     }
                     $custom_fields[] = $new_custom_field;
                 }
             }
             $new_question->custom_fields = $custom_fields;
             $answers = array();
             if (isset($_POST['yop_poll_answer'][$question_args['question_id']]) && is_array($_POST['yop_poll_answer'][$question_args['question_id']]) && count($_POST['yop_poll_answer'][$question_args['question_id']]) > 0) {
                 foreach ($_POST['yop_poll_answer'][$question_args['question_id']] as $answer_args) {
                     $new_answer = new YOP_POLL_Answer_Model($answer_args['answer_id']);
                     $new_answer->answer = trim($answer_args['answer']);
                     $new_answer->type = trim($answer_args['type']);
                     if (isset($answer_args['is_default_answer'])) {
                         $new_answer->is_default_answer = 'yes';
                     } else {
                         $new_answer->is_default_answer = 'no';
                     }
                     $new_answer->description = "";
                     if ($new_answer->type == 'video') {
                         $new_answer->description = trim($answer_args['description_video']);
                     } else {
                         if ($new_answer->type == 'image') {
                             $new_answer->description = trim($answer_args['description_image']);
                         }
                     }
                     $new_answer->question_order = trim($answer_args['question_order']);
                     $new_answer->answer_modified = current_time('mysql');
                     if (!$new_answer->exists()) {
                         //for insert
                         $new_answer->answer_author = $GLOBALS['current_user']->ID;
                         $new_answer->answer_date = current_time('mysql');
                         $new_answer->answer_status = 'active';
                     }
                     if ($new_answer->answer == '') {
                         $response['success'] = 0;
                         $response['id'] = -1;
                         $response['error'] = 1;
                         $response['message'] = __yop_poll('Answer') . ' ' . $new_answer->question_order . ' ' . __yop_poll('from Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                         wp_die(json_encode($response));
                     }
                     $answers[] = $new_answer;
                 }
             }
             $new_question->answers = $answers;
             if ($new_question->question == '') {
                 $response['success'] = 0;
                 $response['id'] = -1;
                 $response['error'] = 1;
                 $response['message'] = __yop_poll('Question') . ' ' . $new_question->poll_order . ' ' . __yop_poll('is empty!');
                 wp_die(json_encode($response));
             }
             $questions[] = $new_question;
         }
     }
     $new_poll->questions = $questions;
     if ($preview) {
         $new_poll->ID = 'preview';
         return $new_poll->return_poll_html(array('tr_id' => '', 'location' => 'page', 'load_css' => true, 'load_js' => false));
     } else {
         if (!$new_poll->exists() && YOP_POLL_Poll_Model::get_data_by('name', $new_poll->poll_name)) {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('This poll already exists! Please choose another name!');
             wp_die(json_encode($response));
         }
         if ($new_poll->exists() && YOP_POLL_Poll_Model::get_other_model_data_by('name', $new_poll->poll_name, $new_poll->id)) {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('This poll already exists! Please choose another name!');
             wp_die(json_encode($response));
         }
         if ($new_poll->save()) {
             self::save_poll_order($new_poll->get('ID'), $_POST['poll_archive_order']);
             $response['success'] = 1;
             $response['id'] = $new_poll->ID;
             $response['error'] = 0;
             $response['message'] = __yop_poll('Poll successfully saved!');
             wp_die(json_encode($response));
         } else {
             $response['success'] = 0;
             $response['id'] = -1;
             $response['error'] = 1;
             $response['message'] = __yop_poll('Poll couldn`t be saved!');
             wp_die(json_encode($response));
         }
     }
 }
Beispiel #3
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();
 }
Beispiel #4
0
    public function some_function($x = 0, $current_options = array())
    {
        $installed_version = get_option("yop_poll_version");
        global $wpdb;
        if (version_compare($installed_version, '4.9.3', '<=') || $x == 1) {
            if (!version_compare(phpversion(), '5.3', '<')) {
                ini_set("memory_limit", "1024M");
                require_once ABSPATH . 'wp-admin/includes/upgrade.php';
                require_once YOP_POLL_INC . 'db_schema.php';
                if (empty($current_options)) {
                    $current_options = get_option('yop_poll_options');
                    $default = get_option('yop_poll_options');
                }
                $capObj = YOP_POLL_Capabilities::get_instance();
                $capObj->install_capabilities();
                Yop_Poll_DbSchema::create_poll_database_tables();
                $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL ');
                $this->install_default_options();
                $new_options = array('user_interface_type' => 'beginner', 'is_default_answer' => $current_options['is_default_answer'], 'poll_start_date' => current_time('mysql'), 'poll_end_date' => '01-01-2038 23:59:59', 'view_results' => array($current_options['view_results']), 'view_results_start_date' => convert_date($current_options['view_results_start_date'], 'd-m-Y H:i:s', 1), 'view_results_permissions' => array('guest', 'registered'), 'view_results_type' => $current_options['view_results_type'], 'answer_result_label' => $current_options['answer_result_label'], 'vote_button_label' => $current_options['vote_button_label'], 'template_width' => $current_options['template_width'], 'widget_template_width' => $current_options['widget_template_width'], 'view_results_link' => $current_options['view_results_link'], 'view_results_link_label' => $current_options['view_results_link_label'], 'view_back_to_vote_link' => $current_options['view_back_to_vote_link'], 'view_back_to_vote_link_label' => $current_options['view_back_to_vote_link_label'], 'view_total_votes' => $current_options['view_total_votes'], 'view_total_votes_label' => $current_options['view_total_votes_label'], 'view_total_answers' => $current_options['view_total_answers'], 'view_total_answers_label' => $current_options['view_total_answers_label'], 'message_after_vote' => $current_options['message_after_vote'], 'vote_permisions' => array('guest', 'registered'), 'vote_permisions_wordpress' => $current_options['vote_permisions_wordpress'], 'vote_permisions_wordpress_label' => $current_options['vote_permisions_wordpress_label'], 'vote_permisions_anonymous' => $current_options['vote_permisions_anonymous'], 'vote_permisions_anonymous_label' => $current_options['vote_permisions_anonymous_label'], 'blocking_voters' => array($current_options['blocking_voters']), 'blocking_voters_interval_value' => $current_options['blocking_voters_interval_value'], 'blocking_voters_interval_unit' => $current_options['blocking_voters_interval_unit'], 'limit_number_of_votes_per_user' => $current_options['limit_number_of_votes_per_user'], 'number_of_votes_per_user' => $current_options['number_of_votes_per_user'], 'percentages_decimals' => $current_options['percentages_decimals'], 'use_default_loading_image' => $current_options['use_default_loading_image'], 'loading_image_url' => $current_options['loading_image_url'], 'redirect_after_vote' => $current_options['redirect_after_vote'], 'redirect_after_vote_url' => $current_options['redirect_after_vote_url'], 'date_format' => 'UE', 'view_poll_archive_link' => $current_options['view_poll_archive_link'], 'auto_generate_poll_page' => $current_options['auto_generate_poll_page'], 'has_auto_generate_poll_page' => $current_options['has_auto_generate_poll_page'], 'use_captcha' => $current_options['use_captcha'], 'send_email_notifications' => $current_options['send_email_notifications'], 'allow_other_answers' => $current_options['allow_other_answers'], 'other_answers_label' => $current_options['other_answers_label'], 'is_default_other_answer' => $current_options['is_default_other_answer'], 'add_other_answers_to_default_answers' => $current_options['add_other_answers_to_default_answers'], 'display_other_answers_values' => $current_options['display_other_answers_values'], 'allow_multiple_answers' => $current_options['allow_multiple_answers'], 'allow_multiple_answers_number' => $current_options['allow_multiple_answers_number'], 'allow_multiple_answers_min_number' => $current_options['allow_multiple_answers_min_number'], 'display_answers' => $current_options['display_answers'], 'display_answers_tabulated_cols' => $current_options['display_answers_tabulated_cols'], 'sorting_results' => 'as_defined', 'sorting_answers' => 'as_defined', 'sorting_results_direction' => $current_options['sorting_results_direction'], 'sorting_answers_direction' => $current_options['sorting_answers_direction'], 'singular_answer_result_votes_number_label' => $current_options['singular_answer_result_votes_number_label'], 'plural_answer_result_votes_number_label' => $current_options['plural_answer_result_votes_number_label'], 'display_results' => $current_options['display_results'], 'display_results_tabulated_cols' => $current_options['display_results_tabulated_cols'], 'bar_background' => $current_options['bar_background'], 'bar_height' => $current_options['bar_height'], 'bar_border_color' => $current_options['bar_border_color'], 'bar_border_width' => $current_options['bar_border_width'], 'bar_border_style' => $current_options['bar_border_style'], 'sorting_archive_polls' => 'votes', 'sorting_archive_polls_rule' => 'asc', 'archive_url' => $current_options['archive_url'], 'archive_link_label' => $current_options['view_poll_archive_link_label'], 'show_poll_in_archive' => $current_options['show_in_archive'], 'poll_archive_order' => $current_options['archive_order'], 'archive_polls_per_page' => $current_options['archive_polls_per_page'], 'email_notifications_from_name' => $current_options['email_notifications_from_name'], 'email_notifications_from_email' => $current_options['email_notifications_from_email'], 'email_notifications_recipients' => $current_options['email_notifications_recipients'], 'email_notifications_subject' => $current_options['email_notifications_subject'], '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>', 'schedule_reset_poll_stats' => $current_options['schedule_reset_poll_stats'], 'schedule_reset_poll_date' => current_time('mysql'), 'schedule_reset_poll_recurring_value' => $current_options['schedule_reset_poll_recurring_value'], 'schedule_reset_poll_recurring_unit' => $current_options['schedule_reset_poll_recurring_unit'], 'singular_answer_result_votes_number_label' => __yop_poll("vote"), 'plural_answer_result_votes_number_label' => __yop_poll("votes"), 'start_scheduler' => $current_options['start_scheduler'], 'use_the_same_template_for_widget' => 'yes', 'vote_permisions_facebook' => 'no', 'vote_permisions_facebook_label' => __yop_poll('Vote as Facebook User'), 'facebook_share_after_vote' => 'no', 'facebook_share_description' => __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name'), 'vote_permisions_google' => 'no', 'vote_permisions_google_label' => __yop_poll('Vote as G+ User'), 'show_google_share_button' => 'no', 'google_integration' => 'no', 'facebook_integration' => 'no', 'facebook_show_comments_widget' => "no");
                if ($current_options['blocking_voters'] == 'cookie-ip') {
                    $new_options['blocking_voters'] = array("cookie", 'ip');
                } else {
                    if ($current_options['blocking_voters'] == 'username') {
                        $new_options['blocking_voters'] = array('user_id');
                    }
                }
                list($g1, $d) = explode('-', $current_options['view_results_permissions']);
                $new_options['view_results_permissions'] = array($g1, $d);
                list($g1, $d) = explode('-', $current_options['view_results_link']);
                $new_options['view_results_link'] = array($g1, $d);
                update_option('yop_poll_options', $new_options);
                update_option("yop_poll_version", YOP_POLL_VERSION);
                YOP_POLL_Maintenance::activation_hook($default);
                $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ');
            }
        }
        $installed_version = get_option("yop_poll_version");
        if (version_compare($installed_version, '5.2', '<=')) {
            ini_set('max_execution_time', 700);
            ini_set("memory_limit", "512M");
            $default_poll_options = get_option('yop_poll_options');
            $default_poll_options['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>';
            update_option('yop_poll_options', $default_poll_options);
            $templates = self::yop_poll_get_templates_new_version_from_db();
            foreach ($templates as $template) {
                $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) {
\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 ) {
\tfindWidest  = typeof findWidest  !== "undefined" ? findWidest  : false;
\tif ( findWidest ) {
\t\tobj.each(function() {
\t\t\tvar thisWidth = jQuery(this).width();
\t\t\twidth = parseInt(thisWidth / cols);
\t\t\tjQuery(this).width(width);
\t\t\tjQuery(this).css("float", "left");
\t\t});
\t}
\telse {
\t\tvar widest = 0;
\t\tobj.each(function() {
\t\t\tvar thisWidth = jQuery(this).width();
\t\t\tif(thisWidth > widest) {
\t\t\t\twidest = thisWidth;
\t\t\t}
\t\t});
\t\twidth = parseInt( %POLL-WIDTH% / cols[0]);
\t\tobj.width(width-20);
\t\tobj.css("float", "left");
\t}
}

function equalWidth2_%POLL-ID%(obj, cols, findWidest ) {
\tfindWidest  = typeof findWidest  !== "undefined" ? findWidest  : false;
\tif ( findWidest ) {
\t\tobj.each(function() {
\t\t\tvar thisWidth = jQuery(this).width();
\t\t\twidth = parseInt(thisWidth / cols);
\t\t\tjQuery(this).width(width);
\t\t\tjQuery(this).css("float", "left");
\t\t});
\t}
\telse {
\t\tvar widest = 0;
\t\tobj.each(function() {
\t\t\tvar thisWidth = jQuery(this).width();
\t\t\tif(thisWidth > widest) {
\t\t\t\twidest = thisWidth;
\t\t\t}
\t\t});
\t\twidth = parseInt( %POLL-WIDTH% / cols[1]);
\t\tobj.width(width-20);
\t\tobj.css("float", "left");
\t}
}
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;
                self::update_poll_template_in_database($template);
            }
            $polls = self::yop_poll_get_polls_for_body_mail_update();
            foreach ($polls as $poll) {
                $current = new YOP_POLL_Poll_Model($poll['ID']);
                $current->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>';
                $current->save();
            }
            update_option("yop_poll_version", YOP_POLL_VERSION);
        }
        $installed_version = get_option("yop_poll_version");
        if (version_compare($installed_version, '5.3', '<=')) {
            update_option("yop_poll_version", YOP_POLL_VERSION);
        }
        $installed_version = get_option("yop_poll_version");
        if (version_compare($installed_version, '5.5', '<=')) {
            update_option("yop_poll_version", YOP_POLL_VERSION);
        }
        $installed_version = get_option("yop_poll_version");
        if (version_compare($installed_version, '5.6', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", YOP_POLL_VERSION);
            $default_poll_options = get_option('yop_poll_options');
            $default_poll_options['show_results_in'] = "bar";
            update_option('yop_poll_options', $default_poll_options);
            $wpdb->query('ALTER TABLE `' . $wpdb->yop_poll_templates . '` ADD `after_vote_template_chart` text');
            update_option("yop_poll_version", '5.7');
        }
        if (version_compare($installed_version, '5.7', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", YOP_POLL_VERSION);
            $templates = self::yop_poll_get_templates_new_version_from_db();
            foreach ($templates as $template) {
                $template['js'] = <<<NOWDOC
\tfunction 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['after_vote_template_chart'] = <<<NOWDOC
\t[QUESTION_CONTAINER]
\t<div id = "yop-poll-question-container-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-question-container-%POLL-ID%">
\t\t<div id = "yop-poll-question-%POLL-ID%-%QUESTION-ID%"
             class = "yop-poll-question-%POLL-ID%">%POLL-QUESTION%</div>
\t\t<div id = "yop-poll-answers-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-answers-%POLL-ID%">
                       <div id = "yop-poll-answers-chart-canvas-%POLL-ID%-%QUESTION-ID%" style="text-align:center;"  class="yop-poll-answers-container-chart-%POLL-ID% yop-poll-center-chart">
\t\t\t<canvas id="yop-poll-answers-chart-%POLL-ID%-%QUESTION-ID%" class="yop-poll-answers-chart"></canvas>
                       </div>
\t\t</div>
\t</div>
\t<div class = "yop-poll-clear-%POLL-ID%"></div>
\t[/QUESTION_CONTAINER]
<div id = "yop-poll-vote-%POLL-ID%" class = "yop-poll-footer">
\t<div>%POLL-TOTAL-ANSWERS-LABEL%</div>
\t<div>%POLL-TOTAL-VOTES-LABEL%</div>
\t<div id = "yop-poll-back-%POLL-ID%">%POLL-BACK-TO-VOTE-LINK%</div>
\t<div id = "yop-poll-archive-%POLL-ID%">%POLL-VIEW-ARCHIVE-LINK%</div>
\t%SHARE-BUTTON%
</div>
NOWDOC;
                self::update_poll_template_in_database2($template);
            }
            update_option("yop_poll_version", '5.7.1');
        }
        if (version_compare($installed_version, '5.7.1', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.2');
        }
        if (version_compare($installed_version, '5.7.2', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.3');
        }
        if (version_compare($installed_version, '5.7.3', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.4');
        }
        if (version_compare($installed_version, '5.7.4', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.5');
        }
        if (version_compare($installed_version, '5.7.5', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.6');
        }
        if (version_compare($installed_version, '5.7.6', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.7');
        }
        if (version_compare($installed_version, '5.7.7', '<=')) {
            global $wpdb;
            update_option("yop_poll_version", '5.7.8');
        }
    }
 private function import_wp_polls()
 {
     if (check_admin_referer('yop-poll-import', 'yop-poll-imports')) {
         if (current_user_can('import_wp_polls')) {
             $current_date = date('Y/m/d H:i:s');
             $wp_polls = self::get_wp_polls_from_db();
             foreach ($wp_polls as $wp_poll) {
                 $poll = new YOP_POLL_Poll_Model(0);
                 $answers = self::get_wp_poll_answers_from_db_by_id($wp_poll->pollq_id);
                 $poll->poll_title = $wp_poll->pollq_question;
                 $poll->poll_name = $wp_poll->pollq_question;
                 $poll->poll_author = get_current_user_id();
                 $poll->poll_start_date = date("Y-m-d H:i:s", $wp_poll['pollq_timestamp']);
                 if ($wp_poll['pollq_expiry'] != "") {
                     $poll->poll_end_date = date("Y-m-d H:i:s", $wp_poll['pollq_expiry']);
                 } else {
                     $poll->poll_end_date = "01-01-2038 23:59:59";
                 }
                 $poll->poll_status = "active";
                 $poll->poll_date = $current_date;
                 $poll->poll_modified = $current_date;
                 $poll->poll_total_votes = $wp_poll->pollq_totalvotes;
                 $question = new YOP_POLL_Question_Model();
                 $poll_id = $poll->save();
                 $question->poll_d = $poll_id;
                 $question->question = $wp_poll->pollq_question;
                 $question->question_status = "active";
                 $question->question_author = get_current_user_id();
                 $question->poll_order = 1;
                 $question->question_date = $current_date;
                 $question->question_modified = $current_date;
                 $question->save();
                 foreach ($answers as $answer) {
                     $poll_answer = new YOP_POLL_Answer_Model();
                     $poll_answer->poll_id = $poll_id;
                     $poll_answer->question_id = $question->ID;
                     $poll_answer->answer = $answer['polla_answers'];
                     $poll_answer->answer_status = "active";
                     $poll_answer->question_order = 1;
                     $poll_answer->answer_author = get_current_user_id();
                     $poll_answer->votes = $answer['polla_votes'];
                     $poll_answer->answer_date = $current_date;
                     $poll_answer->answer_modified = $current_date;
                     $poll_answer->save();
                     unset($log_details);
                     $log_details = self::get_log_from_db_by_poll_id($wp_poll->pollq_id, $answer['polla_aid']);
                     foreach ($log_details as $log) {
                         $arg['poll_id'] = $poll->ID;
                         $arg['ip'] = $log['pollip_ip'];
                         if ($log['pollip_user'] == 'Guest') {
                             $arg['user_type'] = 'anonymous';
                         } else {
                             $arg['user_type'] = "wordpress";
                         }
                         $arg['user_id'] = $log['pollip_userid'];
                         $arg['vote_date'] = $log['pollip_timestamp'];
                         $a = self::get_answer_from_db_by_id($log['pollip_aid']);
                         $arg[1]["q-" . $question->ID]['a'][0] = $poll_answer->ID;
                         $arg[1]["q-" . $question->ID]['answers'][0] = $a[0]['polla_answers'];
                         $q = self::get_question_from_db_by_id($log['pollip_qid']);
                         $arg[1]["q-" . $question->ID]['question'] = $q[0]['pollq_question'];
                         $arg['vote_details'] = json_encode($arg[1]);
                         $message = $this->insert_log_in_db($arg);
                         if ($message['error'] != "" || $message['success'] != "") {
                             $data['message'] = $message;
                         }
                         unset($arg);
                     }
                 }
             }
         } else {
             wp_die(__yop_poll('You do not have enough permission to import a Wp-poll'));
         }
     } else {
         wp_die(__yop_poll('You do not have enough permission to import a Wp-poll'));
     }
     $data['title'] = __yop_poll("Import Polls from Wp-Poll");
     $this->display('imports.html', $data);
 }