В.1 Листинг модуля "training_check_registration_right. php"
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="100%" valign="top" bgcolor="#F9FDFF">
<span class="textheader"> РЕГИСТРАЦИЯ </span>
</td>
</tr>
<tr>
<td>
<?
$submit = 1; // флаг передачи
$dataComplite= 1; // проверка данных
$err_note="2"; // сообщение об ошибке
$qs=""; // строка передачи данных
global $qs,$r_lastname,$r_firstname,$r_middlename,$r_login,$r_pass,$r_pass_c,$r_student_code,$r_sex,$r_n_group,$r_email;
functioncheck_email($str) {
//возвращает 1 если адрес допустим
if (ereg ("^. +@. +\. +$",$str)) {
return 1;
}
else {
return 0;
}
}
function check_form() {
global $qs,$err_note,$submit, $dataComplite,$r_lastname,$r_middlename,$r_firstname,$r_login,$r_pass,$r_pass_c,$r_student_code,$r_sex,$r_n_group,$r_email;
if ($dataComplite== 1) {
if(! $r_lastname) {
$err_note = "не введена фамилия";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_firstname) {
$err_note = "не введено имя";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_middlename) {
$err_note = "не введено отчество";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_login) {
$err_note = "не введен login";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if($r_pass<>$r_pass_c) {
$err_note = "введенные пароли не совпадают";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_pass) {
$err_note = "не введен пароль";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_pass_c) {
$err_note = "не введен проверочный пароль";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_student_code) {
$err_note = "не введен код студента";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_n_group) {
$err_note = "не введен номер группы";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
if(! $r_email) {
$err_note = "не введен адрес электронной почты";
$dataComplite= 0;
}
else {
if (check_email($r_email) ==0) {
$err_note = "не правильно введен адрес электронной почты";
$dataComplite= 0;
}
}
}
if ($dataComplite== 1) {
require "option. php";
mysql_connect($SERVER,$USER,$PASSWD) or die(mysql_error());
mysql_select_db($DB);
$sqlstr = "SELECT login FROM users WHERE login='". $r_login. "'; ";
$res=mysql_query($sqlstr);
if (mysql_fetch_row($res)) {
$err_note = "в системе уже используется данный login";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
require "option. php";
mysql_connect($SERVER,$USER,$PASSWD) or die(mysql_error());
mysql_select_db($DB);
$sqlstr = "SELECT student_code FROM users WHERE student_code='". $r_student_code. "'; ";
$res=mysql_query($sqlstr);
if (mysql_fetch_row($res)) {
$err_note = "в системе уже используется данный код студента";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
require "option. php";
mysql_connect($SERVER,$USER,$PASSWD) or die(mysql_error());
mysql_select_db($DB);
$sqlstr = "SELECT student_code FROM correct_codes WHERE student_code='". $r_student_code. "'; ";
$res=mysql_query($sqlstr);
if (! (mysql_fetch_row($res))) {
$err_note = "преподаватель запретил доступ к системе обучения";
$dataComplite= 0;
}
}
if ($dataComplite== 1) {
$qs = "? r_lastname=". urlencode($r_lastname).
"&r_firstname=". urlencode($r_firstname).
"&r_middlename=". urlencode($r_middlename).
"&r_login=". urlencode($r_login).
"&r_pass=". urlencode($r_pass).
"&r_student_code=". urlencode($r_student_code).
"&r_n_group=". urlencode($r_n_group).
"&r_email=". urlencode($r_email).
"&r_sex=". urlencode($r_sex).
"&r_registration_date=". urlencode(date("Y/m/d")).
"&user_login=0";
return 1;
}
}
include "body_list_header. php";
echo "Регистрационная форма | Проверка введенной информации ";
include "body_list_after_header. php";
$LoginScript = "training. php";
echo "<form name=\"form_reg\" style=\"margin: 0px\">";
echo "<span class=\"textonlightblue\"><b>Фамилия: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_lastname</b></span><br>";
echo "<span class=\"textonlightblue\"><b>Имя: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_firstname</b></span><br>";
echo "<span class=\"textonlightblue\"><b>Отчество: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_middlename</b></span><br>";
echo "<span class=\"textonlightblue\"><b>login: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_login</b></span><br>";
echo "<span class=\"textonlightblue\"><b>пароль: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_pass</b></span><br>";
echo "<span class=\"textonlightblue\"><b>Код студента: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_student_code</b></span><br>";
echo "<span class=\"textonlightblue\"><b>№ группы: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_n_group</b></span><br>";
echo "<span class=\"textonlightblue\"><b>Пол: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_sex</b></span><br>";
echo "<span class=\"textonlightblue\"><b>Почта: </b></span><br>";
echo "<span class=\"textonOrrange\"><b>$r_email</b></span><br>";
echo "</form>";
if (check_form() ==0) {
echo "<form name=\"form_err\" style=\"margin: 0px\">";
include "body_list_footer. php";
include "body_list_header. php";
echo "Возникла ошибка при вводе данных ";
include "body_list_after_header. php";
echo "<span class=\"textrederror\"> $err_note </span>";
echo "<hr class=hr_onlightblue_orange></hr>";
echo "<input type=\"button\" name=\"back\" style=\"height: 18\" class=\"buttonOrange\" value=\"возврат\" onClick=\"self. history. back(); \">";
include "body_list_footer. php";
}
else {
$surl= "training. php". $qs;
echo "<form method=post action=\"$surl \" name=\"form_but\" style=\"margin: 0px\">";
echo "<hr class=hr_onlightblue_orange></hr>";
echo "<input type=\"button\" name=\"back\" style=\"height: 18\" class=\"buttonOrange\" value=\"возврат\" onClick=\"self. history. back(); \">|";
echo "<input type=\"submit\" style=\"height: 18\" class=\"buttonOrange\" value=\"оК\">";
include "body_list_footer. php";
}
echo "</form>";
? >
</td>
<div id="error_input"
style="position: absolute;
width: 220px;
top: 45%;
left: 45%;
background: #8AD9FF;
font-size: 11px;
border: 1px solid #0094DE;
padding: 1px;
z-index: 1">
<form name="form_err" style="margin: 0px">
<span class="textonLightBlue"><b>Привводепроизошлаошибка: </b></span><br>
<div style="background: white; padding: 2px">
<span class="textrederror">$err_note</span><br>
<input type="button" align="middle" style="height: 18" class="buttonBlue" value="исправить" onClick="hiddeLayer()">
</form> </div>
</div>
</tr>
</table>
В.2 Листинг модуля " training_test_right. php"
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="100%" valign="top" bgcolor="#F9FDFF">
<span class="textheader"> ПРОХОЖДЕНИЕ ТЕСТОВ </span>
</td>
</tr>
<tr>
<td>
<?
include "body_list_header. php";
$TestScript="training_test. php";
require "option. php";
mysql_connect($SERVER,$USER,$PASSWD) or die(mysql_error());
mysql_select_db($DB);
if ($q_count>1 && $q_count<7) {
//проверка ответов на правильность
if ($q_count==6) {
echo "Информация по тестам";
}
else {
echo "Выберите ответ на вопрос №". $q_count;
}
include "body_list_after_header. php";
$str_answer ="SELECT * FROM answers WHERE n_question='";
if ($q_count==2) {
$str_answer = $str_answer. $q_1. "' AND id_answer='";
}
elseif ($q_count==3) {
$str_answer = $str_answer. $q_2. "' AND id_answer='";
}
elseif ($q_count==4) {
$str_answer = $str_answer. $q_3. "' AND id_answer='";
}
elseif ($q_count==5) {
$str_answer = $str_answer. $q_4. "' AND id_answer='";
}
else {
$str_answer = $str_answer. $q_5. "' AND id_answer='";
}
//проверка ответа 1
$str_answer_full = $str_answer. $id_a_1. "'";
$res_answer = mysql_query($str_answer_full);
$row_answer = mysql_fetch_row($res_answer);
if ($row_answer [3] =='y') {
if (isset($a_1)) {
$r_count_1=1;
}
else {
$r_count_1=0;
}
}
else {
if (! (isset($a_1))) {
$r_count_1=1;
}
else {
$r_count_1=0;
}
}
//проверка ответа 2
$str_answer_full = $str_answer. $id_a_2. "'";
$res_answer = mysql_query($str_answer_full);
$row_answer = mysql_fetch_row($res_answer);
if ($row_answer [3] =='y') {
if (isset($a_2)) {
$r_count_2=1;
}
else {
$r_count_2=0;
}
}
else {
if (! (isset($a_2))) {
$r_count_2=1;
}
else {
$r_count_2=0;
}
}
//проверка ответа 3
$str_answer_full = $str_answer. $id_a_3. "'";
$res_answer = mysql_query($str_answer_full);
$row_answer = mysql_fetch_row($res_answer);
if ($row_answer [3] =='y') {
if (isset($a_3)) {
$r_count_3=1;
}
else {
$r_count_3=0;
}
}
else {
if (! (isset($a_3))) {
$r_count_3=1;
}
else {
$r_count_3=0;
}
}
//проверка ответа 4
$str_answer_full = $str_answer. $id_a_4. "'";
$res_answer = mysql_query($str_answer_full);
$row_answer = mysql_fetch_row($res_answer);
if ($row_answer [3] =='y') {
if (isset($a_4)) {
$r_count_4=1;
}
else {
$r_count_4=0;
}
}
else {
if (! (isset($a_4))) {
$r_count_4=1;
}
else {
$r_count_4=0;
}
}
//проверка ответа 5
$str_answer_full = $str_answer. $id_a_5. "'";
$res_answer = mysql_query($str_answer_full);
$row_answer = mysql_fetch_row($res_answer);
if ($row_answer [3] =='y') {
if (isset($a_5)) {
$r_count_5=1;
}
else {
$r_count_5=0;
}
}
else {
if (! (isset($a_5))) {
$r_count_5=1;
}
else {
$r_count_5=0;
}
}
//проверка в общей сложности
$r_count_1=$r_count_1*$r_count_2*$r_count_3*$r_count_4*$r_count_5;
if ($r_count_1==1) {
echo "Вы правильно ответили на предыдущий вопрос <br>";
$r_count++;
}
else {
echo "Вы не правильно ответили на предыдущий вопрос <br>";
}
echo "<hr color=\"#FFDFBF\" size=\"1\" style=\"border-style: dotted\"></hr>";
$r_percent = $r_count/5*100;
if ($q_count==6) {
echo "Вы правильно ответили на ". $r_count. " из 5 вопросов. <br>Процент правильных ответов ". $r_percent. "%. <br><br>";
$res_user_tests=mysql_query("SELECT * FROM user_tests WHERE n_user_course='". $id_course. "' AND n_course_part='". $id_part. "'");
$row_user_tests = mysql_fetch_row($res_user_tests);
if ($row_user_tests [4] >$r_percent) {
$r_percent=$row_user_tests [4] ;
}
$user_tests_SQL = "UPDATE user_tests SET percent='". $r_percent. "', last_test_date='". date("Y/m/d"). "' WHERE n_user_course='". $id_course. "' AND n_course_part='". $id_part. "'";
mysql_query($user_tests_SQL);
if ($r_percent>=70) {
echo "Тест успешно пройден<br>";
$res_user_courses2=mysql_query("SELECT * FROM user_courses WHERE id_user_course='". $id_course. "'");
$row_user_courses2=mysql_fetch_row($res_user_courses2);
$res_course_parts2=mysql_query("SELECT * FROM course_parts WHERE n_course='". $row_user_courses2 [2]. "'");
$res_user_tests2=mysql_query("SELECT * FROM user_tests WHERE n_user_course='". $id_course. "'");
if (mysql_num_rows($res_course_parts2) == mysql_num_rows($res_user_tests2)) {
//$res_user_courses3=mysql_query("SELECT * FROM user_courses WHERE id_user_course='". $id_course. "'");
//$row_user_courses3 = mysql_fetch_row($res_user_tests3);
$user_courses_SQL = "UPDATE user_courses SET status='end', end_date='". date("Y/m/d"). "' WHERE id_user_course='". $id_course. "'";
mysql_query($user_courses_SQL);
};
}
else {
echo "Вы не прошли тест";
$res_user_tests = mysql_query("SELECT * FROM user_tests WHERE n_user_course='". $id_course. "' AND n_course_part='". $id_part. "'");