Ejemplo n.º 1
0
 public function view_templates()
 {
     wp_enqueue_script('yop-poll-admin-js', YOP_POLL_URL . '/js/polls/yop-poll-admin.js', array('jquery', 'jquery-ui-datepicker'), YOP_POLL_VERSION, true);
     wp_enqueue_style('yop-poll-slider-css', YOP_POLL_URL . 'css/yop-poll-slider.css', array(), YOP_POLL_VERSION);
     wp_enqueue_script('yop-poll-slider-js', YOP_POLL_URL . 'js/yop-poll-slider.js', array('jquery', 'jquery-ui-dialog'), YOP_POLL_VERSION, true);
     global $wpdb, $message;
     global $page, $action, $orderby, $order, $current_user;
     $orderby = empty($GLOBALS['orderby']) ? 'name' : $GLOBALS['orderby'];
     $order = empty($GLOBALS['order']) ? 'desc' : $GLOBALS['order'];
     $data['per_page'] = isset($_REQUEST['per_page']) ? intval($_REQUEST['per_page']) : 100;
     $data['page_no'] = isset($_REQUEST['page_no']) ? (int) $_REQUEST['page_no'] : 1;
     $order_fields = array('name', 'last_modified');
     $data['title'] = __yop_poll("Templates");
     $data['REQUEST'] = $_REQUEST;
     $data['poll_url'] = YOP_POLL_URL;
     $data['orderby'] = empty($data['REQUEST']['orderby']) ? 'name' : $data['REQUEST']['orderby'];
     $data['order'] = empty($data['REQUEST']['order']) ? 'desc' : $data['REQUEST']['order'];
     $data['order_direction'] = $this->make_order_array($order_fields, 'asc', $orderby, 'desc' == $order ? 'asc' : 'desc');
     $data['order_sortable'] = $this->make_order_array($order_fields, 'sortable', $orderby, 'sorted');
     $data['order_direction_reverse'] = $this->make_order_array($order_fields, 'desc', $orderby, 'desc' == $order ? 'desc' : 'asc');
     $data['search'] = array('fields' => array('name', 'last_modified'), 'value' => isset($_REQUEST['s']) ? $_REQUEST['s'] : '');
     $data['yop_poll_templates'] = Yop_Poll_Model::get_yop_poll_templates_search($data['orderby'], $data['order'], $data['search'], $data['page_no'] - 1, $data['per_page']);
     $data['total_templates'] = self::count_yop_poll_templates_search($data['orderby'], $data['order'], $data['search']);
     $data['message'] = array('error' => $message['error'], 'succes' => $message['success']);
     $data['templates'] = YOP_POLL_MODEL::get_yop_poll_templates_search('id', 'desc');
     $n = count($data['templates']);
     for ($i = 0; $i < $n; $i++) {
         $data['templates'][$i]['preview'] = YOP_POLL_Poll_Model::return_template_preview_html($data['templates'][$i]['id']);
     }
     if (intval($data['page_no']) > intval($data['total_templates'])) {
         $data['page_no'] = 1;
     }
     $args = array('base' => remove_query_arg('page_no', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&page_no=%#%', 'current' => max(1, $data['page_no']), 'total' => ceil($data['total_templates'] / $data['per_page']), 'prev_next' => true, 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'));
     $data['pagination'] = paginate_links($args);
     $_SERVER['REQUEST_URI'] = remove_query_arg(array('action'), $_SERVER['REQUEST_URI']);
     $data['request']['uri'] = $_SERVER["REQUEST_URI"];
     $this->display('templates.html', $data);
 }
Ejemplo n.º 2
0
    public function view_poll_results()
    {
        global $page, $action, $current_user;
        $poll_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
        $results_order_by = isset($_GET['results_order_by']) ? $_GET['results_order_by'] : 'id';
        $results_order = isset($_GET['results_order']) ? $_GET['results_order'] : 'ASC';
        $soav = isset($_GET['soav']) ? $_GET['soav'] : 'no';
        require_once $this->_config->plugin_inc_dir . '/yop_poll_model.php';
        $poll_author = Yop_Poll_Model::get_poll_field_from_database_by_id('poll_author', $poll_id);
        if ((!$this->current_user_can('view_own_polls_results') || $poll_author != $current_user->ID) && !$this->current_user_can('view_polls_results')) {
            wp_die(__('You are not allowed to view results for this item.', 'yop_poll'));
        }
        $poll_details = YOP_POLL_MODEL::get_poll_from_database_by_id($poll_id);
        if ('yes' == $soav) {
            $display_other_answers_values = true;
        } else {
            $display_other_answers_values = false;
        }
        $poll_answers = YOP_POLL_MODEL::get_poll_answers($poll_id, array('default', 'other'), $results_order_by, $results_order, $display_other_answers_values);
        $poll_other_answer = YOP_POLL_MODEL::get_poll_answers($poll_id, array('other'));
        // other-answers
        $oa_per_page = isset($_GET['oa_per_page']) ? intval($_GET['oa_per_page']) : 100;
        $oa_page_no = isset($_REQUEST['oa_page_no']) ? (int) $_REQUEST['oa_page_no'] : 1;
        $total_logs_other_answers = count(YOP_POLL_MODEL::get_other_answers_votes(isset($poll_other_answer[0]['id']) ? $poll_other_answer[0]['id'] : 0));
        $total_logs_other_answers_pages = ceil($total_logs_other_answers / $oa_per_page);
        if (intval($oa_page_no) > intval($total_logs_other_answers_pages)) {
            $oa_page_no = 1;
        }
        $logs_other_answers = YOP_POLL_MODEL::get_other_answers_votes(isset($poll_other_answer[0]['id']) ? $poll_other_answer[0]['id'] : 0, ($oa_page_no - 1) * $oa_per_page, $oa_per_page);
        $oa_args = array('base' => remove_query_arg('oa_page_no', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&oa_page_no=%#%', 'total' => $total_logs_other_answers_pages, 'current' => max(1, $oa_page_no), 'prev_next' => true, 'prev_text' => __('&laquo; Previous'), 'next_text' => __('Next &raquo;'));
        $oa_pagination = paginate_links($oa_args);
        // other-answers
        // custom-fields
        $cf_per_page = isset($_GET['cf_per_page']) ? intval($_GET['cf_per_page']) : 100;
        $cf_page_no = isset($_REQUEST['cf_page_no']) ? (int) $_REQUEST['cf_page_no'] : 1;
        $cf_sdate = isset($_GET['cf_sdate']) ? $_GET['cf_sdate'] : '';
        $cf_edate = isset($_GET['cf_edate']) ? $_GET['cf_edate'] : '';
        $poll_custom_fields = YOP_POLL_MODEL::get_poll_customfields($poll_id);
        $custom_fields_number = count($poll_custom_fields);
        $total_custom_fields_logs = YOP_POLL_MODEL::get_poll_total_customfields_logs($poll_id, $cf_sdate, $cf_edate);
        $total_custom_fields_logs_pages = ceil($total_custom_fields_logs / $cf_per_page);
        if (intval($cf_page_no) > intval($total_custom_fields_logs_pages)) {
            $cf_page_no = 1;
        }
        $custom_fields_logs = YOP_POLL_MODEL::get_poll_customfields_logs($poll_id, 'vote_id', 'asc', ($cf_page_no - 1) * $cf_per_page, $cf_per_page, $cf_sdate, $cf_edate);
        $column_custom_fields_ids = array();
        $cf_args = array('base' => remove_query_arg('cf_page_no', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&cf_page_no=%#%', 'total' => $total_custom_fields_logs_pages, 'current' => max(1, $cf_page_no), 'prev_next' => true, 'prev_text' => __('&laquo; Previous'), 'next_text' => __('Next &raquo;'));
        $cf_pagination = paginate_links($cf_args);
        // custom-fields
        ?>
        <div class="wrap">
        <div class="icon32 icon32-yop-poll">
            <br>

        </div>
        <h2><?php 
        _e('Yop Poll Results', 'yop_poll');
        ?>
<a class="add-new-h2"
                                                             href="<?php 
        echo esc_url(add_query_arg(array('page' => 'yop-polls'), remove_query_arg(array('action', 'id'), stripslashes($_SERVER['REQUEST_URI']))));
        ?>
"><?php 
        _e('All Polls', 'yop_poll');
        ?>
</a>
        </h2>
        <?php 
        if ($poll_details) {
            ?>
            <h3>Name: <?php 
            echo esc_html(stripslashes($poll_details['name']));
            ?>
</h3>
            <h4>Question: <?php 
            echo esc_html(stripslashes($poll_details['question']));
            ?>
</h4>
            <form method="get">
                <input type="hidden" name="page" value="yop-polls"/>
                <input type="hidden" name="action" value="results"/>
                <input type="hidden" name="id" value="<?php 
            echo $poll_id;
            ?>
"/>
                <input type="hidden" name="oa_page_no"
                       value="<?php 
            echo $oa_page_no;
            ?>
"/>
                <input type="hidden" name="cf_page_no"
                       value="<?php 
            echo $cf_page_no;
            ?>
"/>
                <input type="hidden" name="oa_per_page"
                       value="<?php 
            echo $oa_per_page;
            ?>
"/>

                <div class="tablenav top">
                    <div class="alignleft actions">
                        <div style="display:inline; float:left; margin:7px;"><?php 
            _e('Order By', 'yop_poll');
            ?>
</div>
                        <select name="results_order_by">
                            <option <?php 
            selected($results_order_by, 'id');
            ?>
 value="id"><?php 
            _e('Answer ID', 'yop_poll');
            ?>
</option>
                            <option <?php 
            selected($results_order_by, 'answer');
            ?>
 value="answer"><?php 
            _e('Answer Value', 'yop_poll');
            ?>
</option>
                            <option <?php 
            selected($results_order_by, 'votes');
            ?>
 value="votes"><?php 
            _e('Votes', 'yop_poll');
            ?>
</option>
                        </select>
                        <select name="results_order">
                            <option <?php 
            selected($results_order, 'ASC');
            ?>
 value="ASC"><?php 
            _e('ASC', 'yop_poll');
            ?>
</option>
                            <option <?php 
            selected($results_order, 'DESC');
            ?>
 value="DESC"><?php 
            _e('DESC', 'yop_poll');
            ?>
</option>
                        </select>
                        &nbsp;| &nbsp;
                        <input type="checkbox" value="yes" <?php 
            checked($soav, 'yes');
            ?>
 name="soav" id="yop-poll-show_other_answers_values"/>
                        <label for="yop-poll-show_other_answers_values"><?php 
            _e('Show Other Answers Values', 'yop_poll');
            ?>
</label>
                        <input type="submit"
                               value="<?php 
            _e('Filter', 'yop_poll');
            ?>
"
                               class="button-secondary action" id="doaction" name="a">
                    </div>
                    <br class="clear">
                </div>
            </form>
            <table class="wp-list-table widefat fixed" cellspacing="0">
                <thead>
                <tr>
                    <th id="" class="column-answer" style="width: 40%;" scope="col"><?php 
            _e('Answer', 'yop_poll');
            ?>
</th>
                    <th id="" class="column-votes" style="width: 5%;" scope="col"><?php 
            _e('Votes', 'yop_poll');
            ?>
</th>
                    <th id="" class="column-percent" style="width: 5%;" scope="col"><?php 
            _e('Percent', 'yop_poll');
            ?>
</th>
                    <th id="" class="column-bar" style="width: 45%;" scope="col"></th>
                </tr>
                </thead>
                <tbody>
                <?php 
            if (count($poll_answers) > 0) {
                foreach ($poll_answers as $answer) {
                    ?>
                        <tr>
                            <th><?php 
                    echo esc_html(stripslashes($answer['answer']));
                    ?>
</th>
                            <td><?php 
                    echo esc_html(stripslashes($answer['votes']));
                    ?>
</td>
                            <td><?php 
                    echo esc_html(stripslashes($answer['procentes']));
                    ?>
%</td>
                            <td><span class="yop-poll-admin-result-bar" style="width: <?php 
                    echo esc_html(stripslashes($answer['procentes']));
                    ?>
%;">
										</span></td>
                        </tr>
                    <?php 
                }
            } else {
                ?>
                    <tr>
                        <th colspan="4"><?php 
                _e('No answers defined!', 'yop_poll');
                ?>
</th>
                    </tr>
                <?php 
            }
            ?>
                </tbody>
            </table>
            <br> <br>
            <div style="width: 30%; float: left;">
                <h3><?php 
            _e('Poll Other Answers', 'yop_poll');
            ?>
</h3>
                <form method="get">
                    <input type="hidden" name="page" value="yop-polls"/>
                    <input type="hidden" name="action" value="results"/>
                    <input type="hidden" name="id" value="<?php 
            echo $poll_id;
            ?>
"/>
                    <input type="hidden" name="cf_page_no"
                           value="<?php 
            echo $cf_page_no;
            ?>
"/>
                    <input type="hidden" name="oa_page_no"
                           value="<?php 
            echo $oa_page_no;
            ?>
"/>
                    <input type="hidden" name="cf_per_page"
                           value="<?php 
            echo $cf_per_page;
            ?>
"/>
                    <input type="hidden" name="results_order_by" value="<?php 
            echo $results_order_by;
            ?>
"/>
                    <input type="hidden" name="results_order" value="<?php 
            echo $results_order;
            ?>
"/>
                    <input type="hidden" name="soav" value="<?php 
            echo $soav;
            ?>
"/>
                    <div class="tablenav top">
                        <div class="tablenav-pages one-page">
                            <label for="yop-poll-oa-items-per-page" class="displaying-num"><?php 
            _e('Items Per Page', 'yop_poll');
            ?>
                                :</label><input
                                id="yop-poll-oa-items-per-page" type="text" name="oa_per_page"
                                value="<?php 
            echo $oa_per_page;
            ?>
"/> <input name="a"
                                                                             value="<?php 
            _e('Set', 'yop_poll');
            ?>
" type="submit"/>&nbsp;&nbsp;<span
                                class="displaying-num"><?php 
            echo count($logs_other_answers);
            ?>
                                / <?php 
            echo $total_logs_other_answers;
            ?>
 items</span>
                            <?php 
            print $oa_pagination;
            ?>
                        </div>
                        <br class="clear">
                    </div>
                    <table class="wp-list-table widefat fixed" cellspacing="0">
                        <thead>
                        <tr>
                            <th id="" class="column-answer" style="width: 40%;" scope="col"><?php 
            _e('Other Answers', 'yop_poll');
            ?>
</th>
                            <th id="" class="column-votes" style="width: 5%;" scope="col"><?php 
            _e('Votes', 'yop_poll');
            ?>
</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php 
            if (count($logs_other_answers) > 0) {
                foreach ($logs_other_answers as $answer) {
                    ?>
                                <tr>
                                    <td><?php 
                    echo esc_html(stripslashes($answer['other_answer_value']));
                    ?>
</td>
                                    <td><?php 
                    echo esc_html(stripslashes($answer['votes']));
                    ?>
</td>
                                </tr>
                            <?php 
                }
            } else {
                ?>
                            <tr>
                                <td colspan="2"><?php 
                _e('No other answers defined!', 'yop_poll');
                ?>
</td>
                            </tr>
                        <?php 
            }
            ?>
                        </tbody>
                    </table>
                    <div class="tablenav top">
                        <div class="tablenav-pages one-page">
                            <?php 
            print $oa_pagination;
            ?>
                        </div>
                    </div>
                    <br class="clear">
                </form>
            </div>
            <div style="width: 69%; float: right;">
                <h3><?php 
            _e('Custom Fields', 'yop_poll');
            ?>
</h3>
                <form method="get">
                    <?php 
            wp_nonce_field('yop-poll-custom-fields');
            ?>
                    <input type="hidden" name="page" value="yop-polls"/>
                    <input type="hidden" name="action" value="results"/>
                    <input type="hidden" name="id" value="<?php 
            echo $poll_id;
            ?>
"/>
                    <input type="hidden" name="oa_page_no"
                           value="<?php 
            echo $oa_page_no;
            ?>
"/>
                    <input type="hidden" name="cf_page_no"
                           value="<?php 
            echo $cf_page_no;
            ?>
"/>
                    <input type="hidden" name="oa_per_page"
                           value="<?php 
            echo $oa_per_page;
            ?>
"/>
                    <input type="hidden" name="results_order_by" value="<?php 
            echo $results_order_by;
            ?>
"/>
                    <input type="hidden" name="results_order" value="<?php 
            echo $results_order;
            ?>
"/>
                    <input type="hidden" name="soav" value="<?php 
            echo $soav;
            ?>
"/>

                    <div class="tablenav top">
                        <div class="alignleft actions">
                            <select name="export">
                                <option value="page"><?php 
            _e('This Page', 'yop_poll');
            ?>
</option>
                                <option value="all"><?php 
            _e('All Pages', 'yop_poll');
            ?>
</option>
                            </select> <input type="submit"
                                             value="<?php 
            _e('Export', 'yop_poll');
            ?>
"
                                             class="button-secondary action" id="doaction" name="a">
                            &nbsp;&nbsp;&nbsp; <label
                                for="yop-poll-custom-field-start-date-input"><?php 
            _e('Start Date', 'yop_poll');
            ?>
                                :</label>
                            <input id="yop-poll-custom-field-start-date-input" type="text"
                                   name="cf_sdate" value="<?php 
            echo $cf_sdate;
            ?>
"/>&nbsp;&nbsp; <label
                                for="yop-poll-custom-field-end-date-input"><?php 
            _e('End Date', 'yop_poll');
            ?>
                                :</label>
                            <input id="yop-poll-custom-field-end-date-input" type="text"
                                   name="cf_edate" value="<?php 
            echo $cf_edate;
            ?>
"/>&nbsp;&nbsp; <input
                                value="<?php 
            _e('Filter', 'yop_poll');
            ?>
" type="submit"
                                name="a"/>
                        </div>
                        <div class="tablenav-pages one-page">
                            <label for="yop-poll-items-per-page" class="displaying-num"><?php 
            _e('Items Per Page', 'yop_poll');
            ?>
                                :</label><input
                                id="yop-poll-items-per-page" type="text" name="cf_per_page"
                                value="<?php 
            echo $cf_per_page;
            ?>
"/> <input name="a"
                                                                             value="<?php 
            _e('Set', 'yop_poll');
            ?>
" type="submit"/>&nbsp;&nbsp;<span
                                class="displaying-num"><?php 
            echo count($custom_fields_logs);
            ?>
                                / <?php 
            echo $total_custom_fields_logs;
            ?>
 items</span>
                            <?php 
            print $cf_pagination;
            ?>
                        </div>
                        <br class="clear">
                    </div>
                    <table class="wp-list-table widefat fixed" cellspacing="0">
                        <thead>
                        <tr>
                            <th id="" class="column-answer" style="width: 5%" scope="col"><?php 
            _e('#', 'yop_poll');
            ?>
</th>
                            <?php 
            foreach ($poll_custom_fields as $custom_field) {
                $column_custom_fields_ids[] = $custom_field['id'];
                ?>
                                <th id="custom_field_<?php 
                echo $custom_field['id'];
                ?>
" class="column-custom-field" style="width:<?php 
                echo intval(80 / intval($custom_fields_number));
                ?>
%" scope="col"><?php 
                echo ucfirst($custom_field['custom_field']);
                ?>
</th>
                            <?php 
            }
            ?>
                            <th id="" class="column-vote-id" style="width:20%"
                                scope="col"><?php 
            _e('Vote ID', 'yop_poll');
            ?>
</th>
                            <th id="" class="column-tr-id" style="width:15%"
                                scope="col"><?php 
            _e('Tracking ID', 'yop_poll');
            ?>
</th>
                            <th id="" class="column-vote-date" style="width:15%"
                                scope="col"><?php 
            _e('Vote Date', 'yop_poll');
            ?>
</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php 
            if (count($custom_fields_logs) > 0) {
                $index = ($cf_page_no - 1) * $cf_per_page + 1;
                foreach ($custom_fields_logs as $logs) {
                    ?>
                                <tr>
                                    <td><?php 
                    echo $index;
                    ?>
</td>
                                    <?php 
                    foreach ($column_custom_fields_ids as $custom_field_id) {
                        $vote_log_values = array();
                        $vote_logs = explode('<#!,>', $logs['vote_log']);
                        if (count($vote_logs) > 0) {
                            foreach ($vote_logs as $vote_log) {
                                $temp = explode('<#!->', $vote_log);
                                $vote_log_values[$temp[1]] = stripslashes($temp[0]);
                            }
                        }
                        ?>
                                        <td><?php 
                        echo isset($vote_log_values[$custom_field_id]) ? $vote_log_values[$custom_field_id] : '';
                        ?>
</td>
                                    <?php 
                    }
                    ?>
                                    <td><?php 
                    echo $logs['vote_id'];
                    ?>
</td>
                                    <td><?php 
                    echo $logs['tr_id'];
                    ?>
</td>
                                    <td><?php 
                    echo $logs['vote_date'];
                    ?>
</td>
                                </tr>
                                <?php 
                    $index++;
                }
            }
            ?>
                        </tbody>
                    </table>
                    <div class="tablenav top">
                        <div class="tablenav-pages one-page">
                            <?php 
            print $cf_pagination;
            ?>
                        </div>
                        <br class="clear">
                    </div>
                </form>
            </div>
            <div style="clear: both;"></div>
            </div>
        <?php 
        } else {
            ?>
            <h3><?php 
            _e('Your poll doesn`t exist!', 'yop_poll');
            ?>
</h3>
        <?php 
        }
    }