cela anketa pozostava s tychto suborov:
anketa.js
Kód: Vybrať všetko
// JavaScript Document
function showPollResults(toDisplay){
document.getElementById('anketa').innerHTML=toDisplay; //HTML KOD KTORY VRATIL UKLADACI SKRIPT VYMENI ZA POVODNY KOD ANKETY... ANKETA MUSI BYT ULOZENA V <DIV> ALEBO PODOBNOM ELEMENTE S ID 'poll'
return true;
}
function votePoll(voteId){
var xmlHttp=null; // Defines that xmlHttp is a new variable.
document.getElementById('anketa').innerHTML="Prebieha ukladanie Vášho hlasu...<br />"+document.getElementById('anketa').innerHTML;
// Try to get the right object for different browser
try {
// Firefox, Opera 8.0+, Safari, IE7+
xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4)
try { // In some instances, status cannot be retrieved and will produce an error (e.g. Port is not responsive)
if (xmlHttp.status == 200) {
//Set the main HTML of the body to the info provided by the AJAX Request
response=xmlHttp.responseText; //PO UKONCENI ULOZENIA HLASU ZISKA SPATNE KOD A POSUNIE HO DALSEJ FUNKCII
showPollResults(response);
}
} catch (e) {
}
}
xmlHttp.open("get","http://www.navrchol.sk/anketa/"+"saveVote.php?vote="+voteId);// SEM ZADAT ADRESU SKRIPTU KTORY UKLADA HLASY A POTOM SPATNE VYGENERUJE KOD ANKETY...
xmlHttp.send(null); // Since there is no supplied form, null takes its place as a new form.
return false;
}
pollBar.php
Kód: Vybrať všetko
<?php
header ("Content-type: image/png"); //HLAVICKY OBRAZKA
header ("Expires: 1");
header ("cache-control: no-cache, must-revalidate");
header ("pragma: no-cache");
$fullwidth=80; //MAXIMALNA SIRKA OBRAZKA
$im = @imagecreatetruecolor($fullwidth+2, 5)//38,13
or die("Cannot Initialize new GD image stream");
$back_color=imagecolorallocate($im, 255, 255, 255);//ALOKOVANIE FARBY POZADIA
imagefill($im,0,0,$back_color);//VYPLNENIE POZADIA
$color=imagecolorallocate($im, 183, 192, 202);//FARBA
imagerectangle($im,0,0,$fullwidth+1,4,$color);//ORAMOVANIE
imageline($im,0,0,$fullwidth+1,0,imagecolorallocate($im,203,212,222));//TIENOVANIE
//$prevc=0;
//$prev=1;
$color=imagecolorallocate($im, 183, 192, 202);
$end=round($fullwidth*intval(@$_GET["p"])/intval(@$_GET["t"]),0);
imagefilledrectangle($im,0,1,$end,3,$color); //VYPLNIT POZADOVANU CAST
//$num=round(100*$_GET["v"]/$_GET["t"],1)."%";
//$text_color = imagecolorallocate($im, 200,200,200);
//imagestring($im, 1, 46, 2, $num , $text_color);
//$text_color = imagecolorallocate($im, 0,0,0);
//imagestring($im, 1, 45, 1, $num , $text_color);
imageline($im,0,0,0,9,imagecolorallocate($im,203,212,222));
imagepng($im);
imagedestroy($im);
?>
saveVote.php
Kód: Vybrať všetko
<?php
$entryPoint=true;
session_start();
include "shared/database.php"; //PRIPOJENIE DATABAZY
include "shared/functions.php"; //PRIPOJENIE SUBORU S FUNKCIAMI
$itemId=intval(@$_REQUEST["vote"]); //ZISKANIE ID ZVOLENEHO HLASU
$activePoll=mysql_query("select * from polls where active=1"); //ZISKANIE ID AKTIVNEJ ANKETY
if (mysql_num_rows($activePoll)==1){
$activeId=mysql_fetch_array($activePoll);
$activeId=$activeId["id"];
if (checkHistory(3600*24,"poll",$activeId)){ //OVERENIE Z HISTORIE CI UZIVATEL UZ NEHLASOVAL
if (mysql_num_rows(mysql_query("select * from answers where id=$itemId and owner=$activeId"))==1){
mysql_query("update answers set points=points+1 where id=$itemId"); //PRICITANIE HLASU AK JE TO MOZNE
insertHistory(3600*24,"poll",$activeId); //ZAZNAMENANIE HLASOVANIA DO HISTORIE - CAS DALSIEHO HLASU(24 HODIN), IDENTIFIKACIA TYPU ZAZNAMU, BLIZSIE INFO
} else {
}
} else {
}
}
echo getPollResults(); //PRIAMO NA VYSTUP VYPISE HTML KOD NOVO VYGENEROVANEJ ANKETY
?>
toto by malo byt umiestnene v template, (pripadne v css urcit umiestnenie):
+ sql v databaze:
1)
Kód: Vybrať všetko
CREATE TABLE IF NOT EXISTS `polls` (
`id` int(11) NOT NULL auto_increment,
`question` varchar(255) NOT NULL,
`active` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2)
Kód: Vybrať všetko
CREATE TABLE IF NOT EXISTS `answers` (
`id` int(11) NOT NULL auto_increment,
`owner` int(11) NOT NULL,
`answer` varchar(255) NOT NULL,
`points` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=85 ;
vytvorenie ankety:
no vlavo si musis kliknut na to polls a hore je potom vlozit, cez to... id nevyplnaj, question zadaj otazku, active zadaj 1. A klikni vykonaj.
vytvorenie odpovede:
no teraz si otvor answers, tam das zase vlozit, id nevyplnas, owner=1, answer (tvoja dpoved), points 0
das prvu odpoved, potvrdis
das druhu, zase potvrdis