read()){ if(strstr($dir_entry,"poll")){ $id = str_replace($delete, "", $dir_entry); $ids[$id] = $id; $polls[$id] = $dir_entry; $sheduler = 0; $sheduler = check_shedule($id).'
'; if($sheduler == 1){ $shedules[] = $id; } $i++; } } asort($ids); ///////// FOR SELECT THE LATEST POLL if(is_array($shedules)){ $count_shedules = count($shedules); $shedules_index = rand(0,$count_shedules-1); $sheduled = $shedules[$shedules_index]; }else{ $sheduled = end($ids); } if($i == 0){ $err_not_exist .= "$nopoll"; if($_GET['out']==1){ //echo "document.write(\"".trim($err_not_exist)."\");"; }else{ $showpoll = $_GET['showpoll']; $poll_result =show_archive($showpoll); $archive_list =show_archive_list(); } } else{ if($random_display){ srand((double)microtime()*1000000); $pollid = rand(0,count($polls)-1); } else{ if(!isset($_POST['pollid'])){ if(isset($sheduled)){ $pollid = $sheduled; }else{ $pollid = current($ids); } } else{ $pollid = intval($_POST['pollid']);} } if($polls[$pollid] == ''){ $pollid = end($ids); } ///// END SELECT LATEST POLL $pollfile = $path."/polldata/".$polls[$pollid]; $ipfile = $path."/polldata/ips_".$ids[$pollid].".php"; if(!file_exists($pollfile) && !is_dir($pollfile)){ $err_not_exist = "There are no polls active"; } //////// FOR SUBMIT VOTE if(isset($_POST['vote'])){ include("submit_vote.php"); $msg= submitVote(html_entity_decode($_POST['vote'],ENT_QUOTES)); } //////// END SUBMIT VOTE ////////// FOR SHOW POLL RESULTS if(isset($_POST['vote'])){ $showpoll = $_POST['pollid']; if(empty($polls[$showpoll])) $showpoll = $pollid; $poll_result = show_result($polls[$showpoll]); $archive_list =show_archive_list(); }elseif(isset($_GET['showpoll'])){ $showpoll = $_GET['showpoll']; $poll_result =show_archive($showpoll); $archive_list =show_archive_list(); }elseif(!isset($_GET['out'])){ $showpoll = $pollid; $poll_result =show_result($polls[$showpoll]); $archive_list =show_archive_list(); } //////////// END SHOW POLL RESULTS if($err_not_exist ==''){ include($pollfile); } $fp=fopen('polldata/test.txt','w+'); fwrite($fp,'somethings'); fclose($fp); $fp=fopen($path.'/polldata/test.txt','r'); @fread($fp, filesize($path.'/test.txt')); if($err_not_exist ==''){ $fp = fopen($ipfile, "r"); $contents = @fread($fp, filesize($ipfile)); fclose($fp); $uip = $_SERVER['REMOTE_ADDR']; //if(stristr($contents,$uip) == false || (int)$urls_out != 1){ if(stristr($contents,$uip) == false){ $ask = stripslashes($ask); $polls_ques .= "$ask
"; $querystring=($_SERVER['QUERY_STRING'] == "out=1")?"":$_SERVER['QUERY_STRING']; $polls_ques .= "
"; $polls_ques .= ""; for($i = 0;$i< count($a);$i++){ $a[$i] = stripslashes($a[$i]); if($a[$i] != ""){ $polls_ques .= " "; $polls_ques .= " "; $polls_ques .= " "; $polls_ques .= " "; } } $polls_ques .= "
"; $polls_ques .= " "; $polls_ques .= " "; $polls_ques .= "$a[$i]"; $polls_ques .= "
"; $polls_ques .= ""; $polls_ques .= ""; $polls_ques .= (stristr($contents,$uip) == false)? "":""; $polls_ques .= "
"; }else{ $polls_ques="
Already Voted. Click here to view the results.

"; } //if(!$random_display && !isset($sheduled)) $polls_ques .= printNextPoll($pollid); }else{ $polls_ques = $err_not_exist; } } $polls_ques = ($polls_ques == '')?$err_not_exist:$polls_ques; if((int)$urls_out == 1){ echo "document.write(\"".trim($polls_ques)."\");"; }else{ include('poll_template.php'); } function printNextPoll($ids){ global $path; if(is_array($ids)){ $nextpoll =next($ids);; $prevpoll = prev($ids); } $dir = dir($path."/polldata"); //Create a directory object to the current directory $polls = array(); $i = 0; while($dir_entry = $dir->read()){ if(strstr($dir_entry,"poll")){ $polls[$i] = $dir_entry; $i++; } } if(file_exists($dir.'/poll_'.$prevpoll.'.txt')) $tmp .= "<< Prev  "; if(file_exists($dir.'/poll_'.$nextpoll.'.txt')) $tmp .= "Next >>"; //return $tmp; } function check_shedule($id) { include("polldata/poll_".$id.'.txt'); switch($sheduletype) { case '1': $start = explode('/',$startdate); $mktime1 = mktime(0,0,0,$start[0],$start[1],$start[2]); $end = explode('/',$enddate); $mktime2 = mktime(0,0,0,$end[0],$end[1],$end[2]); $nowdate = date('Y-m-d'); $now = explode('-',$nowdate); $todaytime = mktime(0,0,0,$now[1],$now[2],$now[0]); if($mktime1 <= $todaytime && $mktime2 >= $todaytime) { $sheduled = 1; }elseif($mktime2 < $todaytime){ make_archive($id); $sheduled = 0; }else{ $sheduled = 0; } break; case '2': $shedule = explode('-',$time); $month = $shedule[1]; $todaymonth = date('M'); $sheduled = ($month == $todaymonth)?1:0; break; case '3': $shedule = explode('-',$time); $day = $shedule[2]; $today = date('D'); $sheduled = ($day == $today)?1:0; break; default:$sheduled = 0;break; } return $sheduled; } function random_shedule($shedules) { $count_shedules = count($shedules); echo $shedule_index = random(current($shedules),end($shedules)); print_r ($shedules); } function check_shedule_expire() { $dir = dir("polldata"); //Create a directory object to the current directory $polls = array(); $shedules = array(); $i = 0; $shedule_count = 0; while($dir_entry = $dir->read()){ if(strstr($dir_entry,"poll")){ $polls[$i] = $dir_entry; include("polldata/".$polls[$i]); $delete = array("poll_",".txt"); if($sheduletype == 1){ $id = str_replace($delete, "", $dir_entry); $start = explode('/',$startdate); $mktime1 = mktime(0,0,0,$start[0],$start[1],$start[2]); $end = explode('/',$enddate); $mktime2 = mktime(0,0,0,$end[0],$end[1],$end[2]); $nowdate = date('Y-m-d'); $now = explode('-',$nowdate); $todaytime = mktime(0,0,0,$now[1],$now[2],$now[0]); if($mktime1 <= $todaytime && $mktime2 >= $todaytime) { $sheduled = 1; }elseif($mktime2 < $todaytime){ make_archive($id,$mktime2); $sheduled = 0; }else{ $sheduled = 0; } } $i++; } } } function make_archive($id,$mktime2) { //$now = time(); $now = $mktime2; if (!@copy("polldata/poll_".$id.".txt", "archivedata/archived_".$id."_".$now.".txt")) { $copied = false; } else{ $copied = true; } if($copied){ if(!@unlink("polldata/poll_".$id.".txt")){ } @unlink("polldata/ips_".$id.".php"); } return $copied; } ?>