Добавлено: Вс Авг 14, 2005 5:58 am Заголовок сообщения:
Захожу в созданный свой опрос, в папку админ, открываю index.
Нахожу свой опрос (уже созданный), нажимаю помощь.
Появляется окно – для установки голосования вставьте соответствующий код:
Цитата:
<?php
// Important! You have to include it before your html code
include_once "/home/axel/public_html/opros-0/poll_cookie.php";
?>
У меня опрос находиться в public_html и называется opros-0
В основных настройках я указал:
URL директории голосования - /public_html/opros-0/
URL директории с картинками - /public_html/opros-0/image
Это правильно?
А class_poll.php вот он, нашел в /public_html/opros-0/include
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 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 update_poll($poll_id,$option_id) {
$this->db->query("UPDATE ".$this->tbl['poll_data']." SET votes=votes+1 WHERE (poll_id='$poll_id') AND (option_id='$option_id')");
$row = $this->db->fetch_array($this->db->query("SELECT logging as logging FROM ".$this->tbl['poll_index']." WHERE (poll_id = '$poll_id')"));
$timestamp = time();
if ($this->pollvars['check_ip'] == 2) {
$this->db->query("INSERT INTO ".$this->tbl['poll_ip']." (poll_id,ip_addr,timestamp) VALUES ('$poll_id','$this->ip','$timestamp')");
}
if ($row['logging'] == 1) {
$host = @gethostbyaddr($this->ip);
$agent = getenv("HTTP_USER_AGENT");
$this->db->query("INSERT INTO ".$this->tbl['poll_log']." (poll_id,option_id,timestamp,ip_addr,host,agent) VALUES ('$poll_id','$option_id','$timestamp','$this->ip','$host','$agent')");
}
}
function get_latest_poll_id() {
$this->db->query("SELECT poll_id FROM ".$this->tbl['poll_index']." WHERE (status < '2') ORDER BY TIMESTAMP DESC LIMIT 1");
$this->db->fetch_array($this->db->result);
return (!isset($this->db->record['poll_id'])) ? 0 : $this->db->record['poll_id'];
}
function get_random_poll_id() {
$timestamp = time();
$this->db->query("SELECT poll_id FROM ".$this->tbl['poll_index']." WHERE (status=1 AND exp_time>$timestamp) OR (status=1 AND expire=0)");
while ($this->db->fetch_array($this->db->result)) {
$poll_id_arr[] = $this->db->record['poll_id'];
}
if (!isset($poll_id_arr)) {
return 0;
}
$available = sizeof($poll_id_arr)-1;
srand((double) microtime() * 1000000);
$random_id = ($available>0) ? rand(0,$available) : 0;
return $poll_id_arr[$random_id];
}
function is_active_poll_id($poll_id) {
$this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_index']." WHERE (poll_id='$poll_id' AND status=1)"));
if (!$this->db->record) {
return false;
} elseif ($this->db->record['expire']==0) {
return true;
}
return ($this->db->record['exp_time']<time()) ? false : true;
}
function is_valid_poll_id($poll_id) {
if ($poll_id>0) {
$this->db->fetch_array($this->db->query("SELECT poll_id FROM ".$this->tbl['poll_index']." WHERE poll_id=$poll_id AND status<'2'"));
return ($this->db->record['poll_id']) ? true : false;
} else {
return false;
}
}
function has_voted($poll_id) {
global $HTTP_COOKIE_VARS;
$pollcookie = "AdvancedPoll".$poll_id;
if (isset($HTTP_COOKIE_VARS[$pollcookie])) {
return true;
}
if ($this->pollvars['check_ip']==2) {
$today = time()-$this->pollvars['lock_timeout']*3600;
$this->db->query("DELETE FROM ".$this->tbl['poll_ip']." WHERE (timestamp < $today)");
$this->db->fetch_array($this->db->query("SELECT * FROM ".$this->tbl['poll_ip']." WHERE (ip_addr = '$this->ip' and poll_id='$poll_id')"));
return ($this->db->record) ? true : false;
}
}
function get_query_strg($self) {
global $HTTP_SERVER_VARS;
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && !empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (ereg("($self=[0-9]+)",$HTTP_SERVER_VARS['QUERY_STRING'],$regs)) {
$HTTP_SERVER_VARS['QUERY_STRING'] = str_replace($regs[1], "", $HTTP_SERVER_VARS['QUERY_STRING']);
}
$HTTP_SERVER_VARS['QUERY_STRING'] = str_replace("$self=", "", $HTTP_SERVER_VARS['QUERY_STRING']);
if (empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$append = $HTTP_SERVER_VARS['PHP_SELF']."?";
} else {
$query_vars = explode("&",$HTTP_SERVER_VARS['QUERY_STRING']);
$append = $HTTP_SERVER_VARS['PHP_SELF']."?";
for ($i=0; $i<sizeof($query_vars); $i++) {
if (!empty($query_vars[$i])) {
$append .= $query_vars[$i]."&";
}
}
}
} else {
$append = $HTTP_SERVER_VARS['PHP_SELF']."?";
}
return $append;
}
function poll_process($poll_id='') {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
$poll_ident = (isset($HTTP_POST_VARS['poll_ident'])) ? intval($HTTP_POST_VARS['poll_ident']) : "";
if ($poll_ident == "") {
if (isset($HTTP_GET_VARS['poll_ident'])) {
$poll_ident = intval($HTTP_GET_VARS['poll_ident']);
}
}
$option_id = (isset($HTTP_POST_VARS['option_id'])) ? intval($HTTP_POST_VARS['option_id']) : "";
if ($option_id == "") {
if (isset($HTTP_GET_VARS['option_id'])) {
$option_id = intval($HTTP_GET_VARS['option_id']);
}
}
$action = (isset($HTTP_POST_VARS['action'])) ? trim($HTTP_POST_VARS['action']) : "";
if ($action == "") {
if (isset($HTTP_GET_VARS['action'])) {
$action = trim($HTTP_GET_VARS['action']);
}
}
Вы не можете начинать темы Вы не можете отвечать на сообщения Вы не можете редактировать свои сообщения Вы не можете удалять свои сообщения Вы не можете голосовать в опросах