Moderator
Dołączył: 17 Sty 2010
Posty: 28
Przeczytał: 0 tematów
Pomógł: 2 razy Ostrzeżeń: 0/5
|
Wysłany: Pon 6:17, 18 Sty 2010 Temat postu: tutor test |
|
|
|
TEST NA TUTORA :} PYTANIA I ODPOWIEDZI NA NIE WPISZ SE SAM.
-------------------------------------------------------------------------------------
DO BAZY DANYCH DAJ:
-------------------------------------------------------------------------------------
Kod: | ALTER TABLE `accounts` ADD `passed` INT( 11 ) NOT NULL ;
ALTER TABLE `accounts` ADD `blocked_short` INT( 11 ) NOT NULL ;
ALTER TABLE `accounts` ADD `blocked_normal` INT( 11 ) NOT NULL ;
ALTER TABLE `accounts` ADD `blocked_long` INT( 11 ) NOT NULL ;
CREATE TABLE `z_test_answers` (
`question_id` int(11) NOT NULL,
`answer_id` int(11) NOT NULL,
`answer` varchar(255) NOT NULL,
`true_or_false` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `z_test_questions` (
`question` varchar(255) NOT NULL,
`id` int(11) NOT NULL auto_increment,
`type` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; |
------------------------------------------------------------------------------------
W tabeli "z_test_Qestions" wpisz pytania jakie maja byc w tescie
a w "z_test_Answers" odpowiedzi nanie...
w HTDOCS zrob pusty plik test.php
i wklej doniego:
-------------------------------------------------------------------------------------
Kod: | <?php
/* forthehorde.servehalflife.com */
$link = "test";
if($logged)
{
$dark = $config['site']['darkborder'];
$light = $config['site']['lightborder'];
$group=2; //group id of tutor
$number_of_tutors=20;
$blocked_long_time = 14*24*60*60; // if answers are false.
$blocked_normal_time = 1*24*60*60; // on refresh site
$expired = time() + 15*60; // time to expired test
$level=20;
$premium = 7; // need days to pass test
$number_of_questions_radio = 0; // showed questions // change from 0 to your number(more than 1)!!!
$number_of_questions_checkbox = 0; // showed questions // change from 0 to your number(more than 1)!!!
$num = $SQL->query('SELECT COUNT(`group_id`) AS num FROM `players` WHERE `group_id` = '.$group.'')->fetch();
if(!function_exists('isPremium'))
{
function isPremium($premdays, $lastday)
{
return (int) $premdays - floor((time() - $lastday) / 86400);
}
}
if($account_logged->getCustomField("passed") == 1)
{
$blocked_long = 0;
$account_logged->setCustomField('blocked_long', $blocked_long);
$blocked_normal = 0;
$account_logged->setCustomField('blocked_normal', $blocked_normal);
$blocked_short = 0;
$account_logged->setCustomField('blocked_short', $blocked_short);
}
if($account_logged->getCustomField("blocked_short") > 0 and $account_logged->getCustomField("blocked_short") < time())
{
$problem = 'The time to complete the test expired.';
$expired=true;
}
else
{
$expired=false;
}
$blocked_short = 0;
$account_logged->setCustomField('blocked_short', $blocked_short);
if($num['num'] >= $number_of_tutors)
{
$errors[] = 'Too many tutors are now.';
}
if($account_logged->getCustomField("blocked_long") > time())
{
$errors[] = 'Your account is blocked, please try again later('.date("j.n.Y, H:i:s", $account_logged->getCustomField("blocked_long")).').';
}
if($account_logged->getCustomField("passed") == 1)
{
$errors[] = 'You have already passed the test.';
}
if(isPremium($account_logged->getCustomField("premdays"), $account_logged->getCustomField("lastday")) < $premium)
{
$errors[] = 'You do not have '.$premium.' days premium account.';
}
if(!empty($errors))
{
$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Informations</B></TD></TR>';
foreach($errors as $error)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<tr bgcolor='.$bgcolor.'><td>'.$error.'</td></tr>';
}
$main_content .= '</table>';
$deny=true;
}
if($number_of_questions_radio > 1)
{
$questions_radio = $SQL->query('SELECT * from `z_test_questions` where `type` = "radio"')->fetchAll();
$random_questions_radio = array_rand ($questions_radio, $number_of_questions_radio);
}
else
{
$random_questions_radio = 0;
}
if($number_of_questions_checkbox > 1)
{
$questions_checkbox = $SQL->query('SELECT * from `z_test_questions` where `type` = "checkbox"')->fetchAll();
$random_questions_checkbox = array_rand ($questions_checkbox, $number_of_questions_checkbox);
}
else
{
$random_questions_checkbox = 0;
}
$unique[0] = 564321;
$unique[1] = 574321;
$unique[2] = 584321;
if(!$expired)
{
if(!$deny)
{
if(isset($_POST['check']))
{
$player = $ots->createObject('Player');
$name = stripslashes(ucwords(strtolower(trim($_POST['f1']))));
$player->find($name);
if($player->isLoaded() and $player->getCustomField("online") == 0)
{
if($player->getCustomField("online") == 0)
{
for($i=0;$i < $number_of_questions_radio; $i++) //radio checking
{
$nie = $_POST[$unique[0]];
if(isset($_POST[$unique[0]]))
{
if(!empty($_POST[$nie]))
{
$check = $SQL->query('SELECT * from `z_test_answers` where `question_id` = '.addslashes(htmlspecialchars(trim($_POST[$unique[0]]))).' and `answer_id` = '.addslashes(htmlspecialchars(trim($_POST[$nie]))).'')->fetch();
if($check['true_or_false'] == 1)
$checked=true;
else
$checked=false;
if(!$checked)
{
//deny
$blocked_long = time()+$blocked_long_time;
$account_logged->setCustomField('blocked_long', $blocked_long);
header('Location: index.php?subtopic='.$link.'');
}
}
else
{
//deny
$blocked_long = time()+$blocked_long_time;
$account_logged->setCustomField('blocked_long', $blocked_long);
header('Location: index.php?subtopic='.$link.'');
}
$unique[0]++;
}
}
for($i=0;$i < $number_of_questions_checkbox; $i++)
{
if(isset($_POST[$unique[1]]))
{
$answers = $SQL->query('SELECT * from `z_test_answers` where `question_id` = '.addslashes(htmlspecialchars(trim($_POST[$unique[1]]))).'');
foreach($answers as $answer)
{
if(!empty($_POST[$unique[2]]))
{
$check = $SQL->query('SELECT * from `z_test_answers` where `question_id` = '.addslashes(htmlspecialchars(trim($_POST[$unique[1]]))).' and `answer_id` = '.addslashes(htmlspecialchars(trim($_POST[$unique[2]]))).'')->fetchAll();
if($answer['true_or_false'] == 1)
{
if($answer['true_or_false'] != $check[0]['true_or_false'])
{
//deny
$blocked_long = time()+$blocked_long_time;
$account_logged->setCustomField('blocked_long', $blocked_long);
header('Location: index.php?subtopic='.$link.'');
}
}
}
else
{
$check[0]['true_or_false'] = 0;
if($answer['true_or_false'] == 1)
{
if($answer['true_or_false'] != $check[0]['true_or_false'])
{
//deny
$blocked_long = time()+$blocked_long_time;
$account_logged->setCustomField('blocked_long', $blocked_long);
header('Location: index.php?subtopic='.$link.'');
}
}
}
$unique[2]++;
}
$unique[1]++;
}
}
}
else
{
header('Location: index.php?subtopic='.$link.'');
}
//PASSED
$main_content .= '<center><font size=3><b>Congratulations!</b></font></center>';
$account_logged->setCustomField('passed', 1);
$player->setCustomField("group_id", $group);
$account_logged->setCustomField('blocked_normal', 0);
$showed=true;
}
else
{
header('Location: index.php?subtopic='.$link.'');
}
}
}
}
else
{
$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Informations</B></TD></TR>';
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<tr bgcolor='.$bgcolor.'><td>'.$problem.'</td></tr>';
$main_content .= '</table>';
}
if($account_logged->getCustomField('blocked_normal') < time())
{
if(!$deny)
{
if(!$showed)
{
$main_content .= '<form method="post" action="">';
$account_players = $account_logged->getPlayers();
$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=2 CLASS=white height=20><B>Select Character</B></TD></TR>';
foreach($account_players as $player)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$players = $player->getName();
$player_lvl = $player->getLevel();
if($player_lvl >= $level)
$main_content .= "<TR BGCOLOR=\"$bgcolor\"><td width=8% height=20><center><input type=radio name=f1 value=\"$players\"></center></td><td height=20>$players</td></tr>";
else
$main_content .= "<TR BGCOLOR=\"$bgcolor\"><td width=8% height=20><center>Blocked</center></td><td height=20>$players</td></tr>";
}
$main_content .= '</table><br><br>';
$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD COLSPAN=2 CLASS=white height=20><B>Tutor Test</B></TD></TR>';
$uniques[0] = 564321;
for($i=0;$i < $number_of_questions_radio; $i++)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<TR BGCOLOR="'.$bgcolor.'"><td COLSPAN=2 height=20><b>'.$questions_radio[$random_questions_radio[$i]]['question'].'</b></td></tr>';
$answers_radio = $SQL->query('SELECT * from `z_test_answers` where `question_id` = '.$questions_radio[$random_questions_radio[$i]]['id'].'');
$main_content .= '<input type=hidden name='.$uniques[0].' value='.$questions_radio[$random_questions_radio[$i]]['id'].' />';
foreach($answers_radio as $answer)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<TR BGCOLOR="'.$bgcolor.'"><td width=5% height=20><center><input type=radio name='.$answer['question_id'].' value='.$answer['answer_id'].' /></center></td><td height=20>'.$answer['answer'].'</td></tr>';
}
$uniques[0]++;
}
$uniques[1] = 574321;
$uniques[2] = 584321;
for($i=0;$i < $number_of_questions_checkbox; $i++)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<TR BGCOLOR="'.$bgcolor.'"><td COLSPAN=2 height=20><b>'.$questions_checkbox[$random_questions_checkbox[$i]]['question'].'</b></td></tr>';
$answers_radio = $SQL->query('SELECT * from `z_test_answers` where `question_id` = '.$questions_checkbox[$random_questions_checkbox[$i]]['id'].'');
$main_content .= '<input type=hidden name='.$uniques[1].' value='.$questions_checkbox[$random_questions_checkbox[$i]]['id'].' />';
foreach($answers_radio as $answer)
{
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<TR BGCOLOR="'.$bgcolor.'"><td width=5% height=20><center><input type=checkbox name='.$uniques[2].' value='.$answer['answer_id'].' /></center></td><td height=20>'.$answer['answer'].'</td></tr>';
$uniques[2]++;
}
$uniques[1]++;
}
$main_content .= '</table>';
$main_content .= '<br><input type="submit" name="check" value="Submit" class="input2"/></form><br>';
$main_content .= '<br>You must fill out the form within 15 minutes.<br>';
$main_content .= 'Please choose a character that is <font color=red>offline</font>.<br>';
$blocked_short = $expired;
$blocked_normal = time() + $blocked_normal_time;
$account_logged->setCustomField('blocked_short', $blocked_short);
$account_logged->setCustomField('blocked_normal', $blocked_normal);
}
}
}
else
{
$main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Informations</B></TD></TR>';
if(is_int($number_of_rows / 2)) { $bgcolor = $light; } else { $bgcolor = $dark; } $number_of_rows++;
$main_content .= '<tr bgcolor='.$bgcolor.'><td>Your account is blocked, please try again later('.date("j.n.Y, H:i:s", $account_logged->getCustomField("blocked_normal")).').</td></tr>';
$main_content .= '</table>';
}
//Adding questions & answers
if($group_id_of_acc_logged >= $config['site']['access_admin_panel'] and $_REQUEST['control'] != "true")
{
$main_content .= '<br><a href="?subtopic='.$link.'&control=true"><b>Panel Control</b></a><br>';
$main_content .= '<a href="?subtopic='.$link.'&control=true&adm=clean"><b>Remove Old Tutors</b></a><br><br>';
}
if($group_id_of_acc_logged >= $config['site']['access_admin_panel'] and $_REQUEST['control'] == "true")
{
if(isset($_POST['next']))
{
$_SESSION['answers'] = $_POST['answers'];
if($_POST['type'] == 1)
{
$type = "checkbox";
$_SESSION['type'] = $type;
$main_content .= '<form method="post" action=""><b><font size=3>Adding</font></b><br><br>
<input type=text name=question value="" /> Question<br>In radio must be one true answer and only one answer!!!<br>';
for( $x = 1; $x <= $_SESSION['answers']; $x++ )
{
$a = $x+1000;
$main_content .= '<input type=text name='.$x.' value="" /> Answer no. '.$x.'';
$main_content .= '<input type=text name='.$a.' value="" /> false=0 || true=1<br>';
}
$main_content .= '<input type="submit" name="finish" value="Submit" class="input2"/></form><br><br>';
}
elseif($_POST['type'] == 2)
{
$type = "radio";
$_SESSION['type'] = $type;
$main_content .= '<form method="post" action=""><b><font size=3>Adding</font></b><br><br>
<input type=text name=question value="" /> Question<br>';
for( $x = 1; $x <= $_SESSION['answers']; $x++ )
{
$a = $x+1000;
$main_content .= '<input type=text name='.$x.' value="" /> Answer no. '.$x.' - ';
$main_content .= '<input type=text name='.$a.' value="" /> false=0 || true=1<br>';
}
$main_content .= '<input type="submit" name="finish" value="Submit" class="input2"/></form><br><br>';
}
$next=true;
}
if(isset($_POST['finish']))
{
$id = $SQL->query('SELECT MAX(id) FROM `z_test_questions`')->fetch();
$id_next = $id[0] + 1;
for( $x = 1; $x <= $_SESSION['answers']; $x++ )
{
$a = $x+1000;
$INSERT_answer = $SQL->query('INSERT INTO `z_test_answers` (`question_id`,`answer_id`,`answer`, `true_or_false`) VALUES ('.$SQL->quote($id_next).','.$SQL->quote($x).','.$SQL->quote($_POST[$x]).','.$SQL->quote($_POST[$a]).')');
}
$INSERT_question = $SQL->query('INSERT INTO `z_test_questions` (`id`,`question`,`type`) VALUES ('.$SQL->quote($id_next).','.$SQL->quote($_POST['question']).','.$SQL->quote($_SESSION['type']).')');
}
if(!$next)
{
$main_content .= '<form method="post" action=""><b><font size=3>Adding</font></b><br><br>
<input type=radio name=type value="1"/> Checkbox<br>
<input type=radio name=type value="2"/> Radio<br>
<input type=text name=answers value"" /> Number of Answers<br>
<input type="submit" name="next" value="Submit" class="input2"/></form><br><br>';
}
if($_REQUEST['adm'] == "clean")
{
$time = time();
$SQL = $SQL->query('SELECT * from `players` where `group_id` = '.$group.' and `online` = 0');
foreach($SQL as $players)
{
$player = $ots->createObject('Player');
$player->load($players['id']);
$account = $ots->createObject('Account');
$account->load($players['account_id']);
if(isPremium($account->getCustomField("premdays"), $account->getCustomField("lastday")) < $premium or $player->getCustomField("level") < $level)
{
$account->setCustomField("passed", 0);
$account->setCustomField('blocked_normal', time() + $blocked_long_time);
$player->setCustomField("group_id", 1);
$main_content .= 'deleted - '.$players['name'].'<br>';
}
elseif(($time - $player->getCustomField("lastlogin")) > 7*24*60*60)
{
$account->setCustomField("passed", 0);
$account->setCustomField('blocked_normal', time() + $blocked_long_time);
$player->setCustomField("group_id", 1);
$main_content .= 'deleted - '.$players['name'].'<br>';
}
}
}
}
}
else
{
$main_content .= 'Please enter your account number and your password.<br/><a href="?subtopic=createaccount" >Create an account</a> if you do not have one yet.<br/><br/><form action="?subtopic='.$link.'" method="post" ><div class="TableContainer" > <table class="Table1" cellpadding="0" cellspacing="0" > <div class="CaptionContainer" > <div class="CaptionInnerContainer" > <span class="CaptionEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionBorderTop" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <div class="Text" >Account Login</div> <span class="CaptionVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></span> <span class="CaptionBorderBottom" style="background-image:url('.$layout_name.'/images/content/table-headline-border.gif);" ></span> <span class="CaptionEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> <span class="CaptionEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></span> </div> </div> <tr> <td> <div class="InnerTableContainer" > <table style="width:100%;" ><tr><td class="LabelV" ><span >Account Number:</span></td><td style="width:100%;" ><input type="password" name="account_login" SIZE="10" maxlength="10" ></td></tr><tr><td class="LabelV" ><span >Password:</span></td><td><input type="password" name="password_login" size="30" maxlength="29" ></td></tr> </table> </div> </table></div></td></tr><br/><table width="100%" ><tr align="center" ><td><table border="0" cellspacing="0" cellpadding="0" ><tr><td style="border:0px;" ><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Submit" alt="Submit" src="'.$layout_name.'/images/buttons/_sbutton_submit.gif" ></div></div></td><tr></form></table></td><td><table border="0" cellspacing="0" cellpadding="0" ><form action="?subtopic=lostaccount" method="post" ><tr><td style="border:0px;" ><div class="BigButton" style="background-image:url('.$layout_name.'/images/buttons/sbutton.gif)" ><div onMouseOver="MouseOverBigButton(this);" onMouseOut="MouseOutBigButton(this);" ><div class="BigButtonOver" style="background-image:url('.$layout_name.'/images/buttons/sbutton_over.gif);" ></div><input class="ButtonText" type="image" name="Account lost?" alt="Account lost?" src="'.$layout_name.'/images/buttons/_sbutton_accountlost.gif" ></div></div></td></tr></form></table></td></tr></table>';
}
?> |
-------------------------------------------------------------------------------------
DO INDEX.PHP DODAJ:
-------------------------------------------------------------------------------------
Kod: | case "test";
$subtopic = "test";
$topic = "Tutor Test";
include("test.php");
break; |
-------------------------------------------------------------------------------------
I DO LAYOUT.PHP WPISZ SUBTOPIC:
-------------------------------------------------------------------------------------
Kod: | <li><a href="?subtopic=test"><b><font size="1">tutor test</font></b></a></li> |
-------------------------------------------------------------------------------------
jak cos niebedzie dzialac jak powinno to pisz
Post został pochwalony 1 raz
Ostatnio zmieniony przez Unknown dnia Pon 6:19, 18 Sty 2010, w całości zmieniany 1 raz |
|
|