⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_poll.php

📁 具有多種面版可以選擇的"投票程式" 多國語言版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/**
 * ----------------------------------------------
 * Advanced Poll 2.0.3 (PHP/MySQL)
 * Copyright (c)2001 Chi Kien Uong
 * URL: http://www.proxy2.de
 * ----------------------------------------------
 */

class poll {

    var $db;
    var $tbl;
    var $pollvars;
    var $poll_view_html;
    var $poll_result_html;
    var $options;
    var $options_text;
    var $poll_question;
    var $form_forward;
    var $template_set;
    var $ip;

    function poll() {
        global $POLLTBL, $CLASS, $HTTP_SERVER_VARS;
        $this->tbl = $POLLTBL;
        $this->poll_view_html = array();
        $this->poll_result_html = array();
        $this->options = array();
        $this->options_text = array();
        $this->poll_question = array();
        $this->form_forward = '';
        $this->template_set = '';

        if (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) && eregi("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$",$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) {
            $this->ip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
        } else {
            $this->ip = getenv("REMOTE_ADDR");
        }
        $this->db = $CLASS["db"];
        $this->pollvars = $this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_config']));
        $this->template_set = "default";
        $this->form_forward = basename($HTTP_SERVER_VARS['PHP_SELF']);
        if ($this->pollvars['result_order'] == "asc") {
            $this->pollvars['result_order'] = "ORDER BY votes ASC";
        } elseif ($this->pollvars['result_order'] == "desc") {
            $this->pollvars['result_order'] = "ORDER BY votes DESC";
        } else {
            $this->pollvars['result_order'] = '';
        }
    }

    function set_template_set($template_set='') {
        if (!empty($template_set)) {
            $this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_tplset']." WHERE tplset_name='$template_set'"));
            if ($this->db->record) {
                $this->template_set = $template_set;
            } else {
                $this->template_set = "default";
            }
        } else {
            $this->template_set = "default";
        }
        return $this->template_set;
    }

    function set_display_order($order='') {
        switch ($order) {
            case "asc":
                $this->pollvars['result_order'] = "ORDER BY votes ASC";
                break;
            case "desc":
                $this->pollvars['result_order'] = "ORDER BY votes DESC";
                break;
            default:
                $this->pollvars['result_order'] = "";
                return false;
        }
        return true;
    }

    function set_display_result($result='') {
        switch ($result) {
            case "votes":
                $this->pollvars['type'] = "votes";
                break;
            case "percent":
                $this->pollvars['type'] = "percent";
                break;
            default:
                return false;
        }
        return true;
    }

    function set_max_bar_length($max_bar_length='') {
        if ($max_bar_length && $max_bar_length>0) {
            $this->pollvars['img_length'] = $max_bar_length;
            return true;
        } else {
            return false;
        }
    }

    function set_max_bar_height($max_bar_height='') {
        if ($max_bar_height && $max_bar_height>0) {
            $this->pollvars['img_height'] = $max_bar_height;
            return true;
        } else {
            return false;
        }
    }

    function get_poll_tpl($tpl) {
        $this->db->fetch_array($this->db->query("SELECT x.*, y.* from ".$this->tbl['poll_tplset']." x, ".$this->tbl['poll_tpl']." y where x.tplset_name='$this->template_set' and x.tplset_id=y.tplset_id AND y.title='$tpl'"));
        if ($this->db->record['template']) {
            $this->db->record['template'] = ereg_replace("\"", "\\\"", $this->db->record['template']);
            return $this->db->record['template'];
        } else {
            return false;
        }
    }

    function get_poll_data($poll_id) {
        if (!isset($this->options[$poll_id])) {
            $this->db->query("SELECT SUM(votes) as total FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id')");
            $this->db->fetch_array($this->db->result);
            $this->options[$poll_id]['total'] = $this->db->record['total'];
            $this->db->query("SELECT * FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id') ".$this->pollvars['result_order']);
            while ($this->db->fetch_array($this->db->result)) {
                $option_id_arr[] = $this->db->record['option_id'];
                $option_text_arr[] = $this->db->record['option_text'];
                $option_votes_arr[] = $this->db->record['votes'];
                $option_color_arr[] = $this->db->record['color'];
            }
            $this->options[$poll_id]['option_id'] = $option_id_arr;
            $this->options[$poll_id]['option_text'] = $option_text_arr;
            $this->options[$poll_id]['votes'] = $option_votes_arr;
            $this->options[$poll_id]['color'] = $option_color_arr;
            for ($i=0,$maxvote=0; $i<sizeof($option_votes_arr); $i++) {
                $maxvote = ($option_votes_arr[$i]>$maxvote) ? $option_votes_arr[$i] : $maxvote;
            }
            $this->options[$poll_id]['maxvote'] = $maxvote;
        }
        return $this->options[$poll_id];
    }

    function get_poll_option($poll_id) {
        if (!isset($this->options_text[$poll_id])) {
            $query = $this->db->query("SELECT option_id, option_text FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id') order by option_id asc");
            while ($data = $this->db->fetch_array($query)) {
                $option_id_arr[] = $this->db->record['option_id'];
                $option_text_arr[] = $this->db->record['option_text'];
            }
            $this->options_text[$poll_id]['option_id'] = $option_id_arr;
            $this->options_text[$poll_id]['option_text'] = $option_text_arr;
        }
        return $this->options_text[$poll_id];
    }

    function get_poll_question($poll_id) {
        if (!isset($this->poll_question[$poll_id])) {
            $row = $this->db->fetch_array($this->db->query("SELECT question FROM ".$this->tbl['poll_index']." WHERE (poll_id = '$poll_id')"));
            $this->poll_question[$poll_id] = htmlspecialchars($row['question']);
        }
        return $this->poll_question[$poll_id];
    }

    function display_poll($poll_id) {
        if (!isset($this->poll_view_html[$poll_id]) || !isset($this->poll_view_html[$poll_id][$this->template_set])) {
            $pollvars = $this->pollvars;
            if (!isset($this->options_text[$poll_id])) {
                $this->get_poll_option($poll_id);
            }
            $question = $this->get_poll_question($poll_id);
            eval("\$display_html = \"".$this->get_poll_tpl("display_head")."\";");
            $loop_html = $this->get_poll_tpl("display_loop");
            for ($i=0;$i<sizeof($this->options_text[$poll_id]['option_id']);$i++) {
                $data['option_text'] = $this->options_text[$poll_id]['option_text'][$i];
                $data['option_id'] = $this->options_text[$poll_id]['option_id'][$i];
                eval("\$display_html .= \"$loop_html\";");
            }
            eval("\$display_html .= \"".$this->get_poll_tpl("display_foot")."\";");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -