header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//ini_set("display_errors",1);
include("config.php");
include("./lib/template.inc.php");
include("./lib/quiz_lib.php");
//var_dump($_COOKIE["quiz"]);
$dbh = Connect_Database();
$query = "select * from quizes where start<=CURDATE() and end>=CURDATE() order by id desc";
$dbc = mysql_query($query);
//check widget
if(isset($_GET["quizid"])){
$_GET["quizid"]=cleanup($_GET["quizid"]);
$qy = "select * from quizes where id=".$_GET["quizid"];
$resource = mysql_query($qy);
$rw=@mysql_fetch_assoc($resource);
$q2= "select * from quizes where start<=CURDATE() and end>=CURDATE() order by id desc";
$res2 = mysql_query($q2);
$row1 = @mysql_fetch_array($res2);
//var_dump($rw);
$quiz_id = $rw["id"];
if(isset($_COOKIE["quiz"][$quiz_id]) and $_COOKIE["quiz"][$quiz_id]==$quiz_id){
//grafic
$graficsondaj="";
//constructie grafic sondaj
$graficq1="select count(*) as count, `vote` from `qvotes` where `quiz_id`=$quiz_id group by `vote`";
$resg=@mysql_query($graficq1);
while($resultgraf = @mysql_fetch_assoc($resg)){$graf[]=$resultgraf;}
//var_dump($graf);
$total=0;
foreach($graf as $vot){$total+=$vot["count"];}
foreach($graf as $vot){
$newkey=$vot["vote"];
$procente[$newkey]=round($vot["count"]/$total,2)*100;
}
$data=base64_encode(json_encode($procente));
//var_dump($row1);
for($j=1;$j<5;$j++){
$keyname="answer".$j;
if($row1[$keyname]!=""){$answ[]=$row1[$keyname];}
}
//var_dump($answ);
$raspunsuri="";
$intrebare=$row1["question"];
foreach($answ as $answer){
//$answer=textTruncate($answer,50);
$raspunsuri.="
$answer";
}
$raspunsuri="$raspunsuri
";
$intrebare="$intrebare
";
$graficsondaj="$intrebare
$raspunsuri
";
if($row1["tip"]=='concurs'){$graficsondaj='Ati participat deja la concurs, va multumim!';}
print $graficsondaj;
}else{
if($row1[0]==$quiz_id){
print thehtml($rw);
}else {
//grafic
$graficsondaj="";
//constructie grafic sondaj
$graficq1="select count(*) as count, `vote` from `qvotes` where `quiz_id`=$quiz_id group by `vote`";
$resg=@mysql_query($graficq1);
while($resultgraf = @mysql_fetch_assoc($resg)){$graf[]=$resultgraf;}
$total=0;
foreach($graf as $vot){$total+=$vot["count"];}
foreach($graf as $vot){
$newkey=$vot["vote"];
$procente[$newkey]=round($vot["count"]/$total,2)*100;
}
$data=base64_encode(json_encode($procente));
$row = @mysql_fetch_array($dbc);
//var_dump($row);
for($j=1;$j<5;$j++){
$keyname="answer".$j;
$answ=array();
if($row[$keyname]!=""){$answ[]=$row[$keyname];}
}
//var_dump($answ);
$raspunsuri="";
$intrebare=$row["question"];
if(!empty($answ)){
foreach($answ as $answer){
$answer=textTruncate($answer,50);
$raspunsuri.="$answer";
}}
$raspunsuri="$raspunsuri
";
$intrebare="$intrebare
";
$graficsondaj="$intrebare
$raspunsuri
";
if($row["tip"]=='concurs'){$graficsondaj='Ati participat deja la concurs, va multumim!';}
print $graficsondaj;
}
}
exit;
}
if($row = @mysql_fetch_array($dbc) ){
$quiz_id = $row[0];
if(isset($_COOKIE["quiz"][$quiz_id]) and $_COOKIE["quiz"][$quiz_id]==$quiz_id){
$graficsondaj="";
//constructie grafic sondaj
$graficq1="select count(*) as count, `vote` from `qvotes` where `quiz_id`=$quiz_id group by `vote`";
$resg=@mysql_query($graficq1);
while($resultgraf = @mysql_fetch_assoc($resg)){$graf[]=$resultgraf;}
$total=0;
foreach($graf as $vot){$total+=$vot["count"];}
foreach($graf as $vot){
$newkey=$vot["vote"];
$procente[$newkey]=round($vot["count"]/$total,2)*100;
}
foreach($procente as $intrebare=>$procent){
$graficsondaj.="intrebarea $intrebare:
$procent%
";
}
$data=base64_encode(json_encode($procente));
//var_dump($row);
for($j=1;$j<5;$j++){
$keyname="answer".$j;
if($row[$keyname]!=""){$answ[]=$row[$keyname];}
}
//var_dump($answ);
$raspunsuri="";
$intrebare=$row["question"];
foreach($answ as $answer){
$answer=textTruncate($answer,50);
$raspunsuri.="$answer";
}
$raspunsuri="$raspunsuri
";
$intrebare="$intrebare
";
$graficsondaj="$intrebare
$raspunsuri
";
if($row["tip"]=='concurs'){$graficsondaj='Ati participat deja la concurs, va multumim!';}
print $graficsondaj;
} else {
//print HTML_Code($quiz_id, "");
print thehtml($row);
}
}
else {
print "Ne pare rau, pentru azi nu este definit nici un chestionar sau sondaj!";
}
function thehtml($row){
$html="";
$tip=$row["tip"];
switch($tip){
case "intrebare":
$html="
";
break;
case "concurs":
$html="
";
break;
case "sondaj":
$html="
";
break;
default:
$html="
";
break;
}
return $html;
}
function textTruncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) {
if ($length == 0)
return '';
if (is_callable('mb_strlen')) {
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
}
} else {
return $string;
}
}
}
// $string has no utf-8 encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}
?>