ahmed19
03-05-2010, 10:09 AM
Hello everyone. I need little help because i don't know how to create script. I wont to display quiz results on one of my vbulletin templates (quiz_thanks). I know that it is very simple but i don't know php language so i have big problem with this.
I have function to create results
// Assume Your Usergroup Has Access To Participate In A Quiz
$Your_ID = $vbulletin->userinfo['usergroupid'];
$Perms = unserialize($Quiz['q_perms']);
if(!in_array($Your_ID,$Perms['Participate'])){
RunError("Your usergroup does not have access to participate in this particular quiz.");
}
$Questions = $DB->query("select * from ".TABLE_PREFIX."quiz_questions where q_forquiz='{$Quiz['qid']}' order by qqid");
while($Question = $DB->fetch_array($Questions)){
$Q[$Question['qqid']] = $Question;
}
$Answers = $_POST['question'];
$Report = "Here are your quiz results for '".str_replace('"','"',$Quiz['q_name'])."' {$vbulletin->userinfo['username']}.\n\n";
$Count = 1;
$Score = 0;
if(is_array($Q)){
foreach($Q as $id => $Quest){
$Result = $Engine->Compile_Answer($Quest,$Answers[$id]);
$Report .= " Question {$Count}: ".str_replace('"','"',$Quest['q_question'])."\n";
$Report .= " You Answered: ".implode(', ',$Result[2])."\n";
$Report .= " This was {$Result[0]}% Correct. (Actual Answer(s): ".iif($Quiz['q_viewanswer'],$Result[1],"Hidden").")\n";
$Score += $Result[0];
$Count++;
}
}
$Overall = floor($Score / ($Count - 1));
$Report .= "\n\nYour overall score was: {$Overall}%";
// Send PM
SendPM($Report,"Quiz Results",$vbulletin->userinfo['userid'],$vbulletin->userinfo['userid']);
}
In that function script make result and send them by PM function (DataManager_PM). But i don't wont to send them like that. I just wont to show them on quiz_thanks template.
SendPM function
//////////////////
function SendPM($message,$title,$to,$from = 0){
global $vbulletin, $DB;
$to = $DB->query_first("select username, userid from ".TABLE_PREFIX."user where userid='{$to}'");
$DataManager_PM =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$DataManager_PM->set('fromuserid', $to['userid']);
$DataManager_PM->set('fromusername', $to['username']);
$DataManager_PM->set('title', $title);
$DataManager_PM->set('message', $message);
$DataManager_PM->set_recipients($to['username'],$to['permissions']);
$DataManager_PM->set('dateline', TIMENOW);
$DataManager_PM->save();
}
//////////////////
How to do that? How to print that results on quiz_thanks template. I know that i need to make plugin and put it in quiz_thanks template. But i don't know how to do that. Please help me.
After user submits quiz his redirected to quiz_thanks template by that function
if($_GET['done']){
eval('$quiz_page .= "' . fetch_template('quiz_thanks') . '";');
}
Please give me some hint.
I have function to create results
// Assume Your Usergroup Has Access To Participate In A Quiz
$Your_ID = $vbulletin->userinfo['usergroupid'];
$Perms = unserialize($Quiz['q_perms']);
if(!in_array($Your_ID,$Perms['Participate'])){
RunError("Your usergroup does not have access to participate in this particular quiz.");
}
$Questions = $DB->query("select * from ".TABLE_PREFIX."quiz_questions where q_forquiz='{$Quiz['qid']}' order by qqid");
while($Question = $DB->fetch_array($Questions)){
$Q[$Question['qqid']] = $Question;
}
$Answers = $_POST['question'];
$Report = "Here are your quiz results for '".str_replace('"','"',$Quiz['q_name'])."' {$vbulletin->userinfo['username']}.\n\n";
$Count = 1;
$Score = 0;
if(is_array($Q)){
foreach($Q as $id => $Quest){
$Result = $Engine->Compile_Answer($Quest,$Answers[$id]);
$Report .= " Question {$Count}: ".str_replace('"','"',$Quest['q_question'])."\n";
$Report .= " You Answered: ".implode(', ',$Result[2])."\n";
$Report .= " This was {$Result[0]}% Correct. (Actual Answer(s): ".iif($Quiz['q_viewanswer'],$Result[1],"Hidden").")\n";
$Score += $Result[0];
$Count++;
}
}
$Overall = floor($Score / ($Count - 1));
$Report .= "\n\nYour overall score was: {$Overall}%";
// Send PM
SendPM($Report,"Quiz Results",$vbulletin->userinfo['userid'],$vbulletin->userinfo['userid']);
}
In that function script make result and send them by PM function (DataManager_PM). But i don't wont to send them like that. I just wont to show them on quiz_thanks template.
SendPM function
//////////////////
function SendPM($message,$title,$to,$from = 0){
global $vbulletin, $DB;
$to = $DB->query_first("select username, userid from ".TABLE_PREFIX."user where userid='{$to}'");
$DataManager_PM =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$DataManager_PM->set('fromuserid', $to['userid']);
$DataManager_PM->set('fromusername', $to['username']);
$DataManager_PM->set('title', $title);
$DataManager_PM->set('message', $message);
$DataManager_PM->set_recipients($to['username'],$to['permissions']);
$DataManager_PM->set('dateline', TIMENOW);
$DataManager_PM->save();
}
//////////////////
How to do that? How to print that results on quiz_thanks template. I know that i need to make plugin and put it in quiz_thanks template. But i don't know how to do that. Please help me.
After user submits quiz his redirected to quiz_thanks template by that function
if($_GET['done']){
eval('$quiz_page .= "' . fetch_template('quiz_thanks') . '";');
}
Please give me some hint.