$idsq [$i] =mysql_result($result,$i,0);
deleteques($idsq [$i]);
}
$query = "select idres from results where idsubr='$delsub'";
$result = mysql_query($query);
if(! $result) return false;
$num=mysql_numrows($result);
for($i=0; $i<$num; $i++)
{
$idsq [$i] =mysql_result($result,$i,0);
delresult($idsq [$i]);
}
return true;
}
function idsq($id) // Количество вопросов
{
$conn = db_connect();
$query = "select idques from questions where idsubq='$id'";
$result = mysql_query($query);
if(! $result) return false;
$num=mysql_numrows($result);
for($i=0; $i<$num; $i++)
$idsq [$i] =mysql_result($result,$i,0);
return $idsq;
}
function idss($sub) // Количество предметов
{
$conn = db_connect();
$query = "select idsub from subjects where subject='$sub'";
$result = mysql_query($query);
if(! $result) return false;
if(mysql_numrows($result) ==1)
{
$idss=mysql_result($result,0,0);
return $idss;
} else return false;
}
function storebals($bal3, $bal4)
{
$conn = db_connect();
$query="delete from bals";
$result = mysql_query($query);
if(! $result) return false;
$query="insert into bals values (3, '". $bal3. "')";
$result = mysql_query($query);
if(! $result) return false;
$query="insert into bals values (4, '". $bal4. "')";
$result = mysql_query($query);
if(! $result) return false;
return true;
}
function percent($bal)
{
$conn = db_connect();
$query="select percent from bals where bal=$bal";
$result = mysql_query($query);
if(! $result) return false;
if(mysql_numrows($result) ! =0)
return mysql_result($result,0,0);
}
function delquestions() // Удаление всех вопросов
{
$conn = db_connect();
$query="delete from answers";
$result = mysql_query($query);
if(! $result) return false;
$query="delete from questions";
$result = mysql_query($query);
if(! $result) return false;
$query="delete from subjects";
$result = mysql_query($query);
if(! $result) return false;
return true;
}
function delresult($resid) // Удаление записи студента
{
if(! $resid) return false;
$conn = db_connect();
$query="delete from results where idres=$resid";
$result = mysql_query($query);
if(! $result) return false;
return true;
}
function studids($sort) // Массив студентов
{
$conn = db_connect();
$query = "select idstud from students order by $sort";
$result = mysql_query($query);
if(! $result) return false;
$num=mysql_numrows($result);
for($i=0; $i<$num; $i++)
$mess [$i] =mysql_result($result,$i,0);
return $mess;
}
function store_student($group, $name, $sname, $faculty, $login, $pass, $email) // Запись студента
{
$conn = db_connect();
$query = "select password from students where login='$login'";
$result = mysql_query($query);
if(mysql_numrows($result) ==1)
{
echo"<script> alert('Такой Ник уже существует! Пожалуйста выеберите другой. ') </script>";
return false;
}
elseif(mysql_numrows($result) ==0)
{
$query = "insert into students values ('". $group. "', '". $name. "', '". $sname. "', '". $faculty. "', '". $email. "', '". $login. "', '". $pass. "', now())";
$result = mysql_query($query);
if (! $result) return false;
}
return true;
}
function bal($score)
{
$conn = db_connect();
$query = "select percent from bals where bal=3";
$result = mysql_query($query);
if(! $result) return false;
$bal3=mysql_result($result,0,0);
$query = "select percent from bals where bal=4";
$result = mysql_query($query);
if(! $result) return false;
$bal4=mysql_result($result,0,0);
if($score<$bal3) $bal='2';
elseif($score>=$bal3 && $score<$bal4) $bal='3';
elseif($score>=$bal4) $bal='4';
if($score=='100') $bal='5';
return $bal;
}
function deleteques($idques) // Удаление вопроса
{
if(! $idques) return false;
$conn = db_connect();
$query="select idsubq from questions where idques=$idques";
$result = mysql_query($query);
if(! $result) return false;
if(mysql_numrows($result) ! =0) $iddelsub=mysql_result($result,0,0);
$query="delete from answers where parent=$idques";
$result = mysql_query($query);
if(! $result)
{ echo 'Dont deleted answers'; return false; }
$query="delete from questions where idques=$idques";
$result = mysql_query($query);
if(! $result)
{ echo 'Dont deleted questions'; return false; }
$query="select idsubq from questions where idsubq=$iddelsub";
$result = mysql_query($query);
if(! $result) return false;
if(mysql_numrows($result) ==0)
$query="delete from subjects where idsub=$iddelsub";
$result = mysql_query($query);
if(! $result) return false;
return true;
}
function outans($id) // Получение ответа
{
$conn = db_connect();
$query = "select idans from answers where parent=$id";
$result = mysql_query($query);
if(! $result) return false;
$num=mysql_numrows($result);
for($i=0; $i<$num; $i++)
$mes [$i] =mysql_result($result,$i,0);
return $mes;
}
function store($qest) // Запись вопроса и ответов
{
$sub=$qest ['subject'] ;
$conn = db_connect();
$query = "select idsub from subjects where subject = '$sub'";
$result = mysql_query($query);
if (mysql_numrows($result) ==0)
{
$query = "insert into subjects values (null, '". $qest ['subject']. "')";
$result = mysql_query($query);
if (! $result) return false;
}
$query = "select idsub from subjects where subject = '". $qest ["subject"]. "'";
$result = mysql_query($query);
if (! $result) return false;
$idsub=mysql_result($result,0,0);
$query = "insert into questions values (null, '". $idsub. "', '". $qest ["qes"]. "')";
$result = mysql_query($query);
if (! $result)
return false;
$query = "select idques from questions where idsubq='". $idsub. "' and quesmes = '". $qest ["qes"]. "'";
$result = mysql_query($query);
$parentid=mysql_result($result,0,0);
$query = "insert into answers values
(null,'". $parentid. "','". $qest ['rans']. "',1)";
$result = mysql_query($query);
if (! $result)
return false;
$j [0] =$qest ['ans1'] ; $j [1] =$qest ['ans2'] ;
$j [2] =$qest ['ans3'] ; $j [3] =$qest ['ans4'] ;
for($i=0; $i<4; $i++) if($j [$i] ! ='')
{
$query = "insert into answers values
(null, '". $parentid. "', '". $j [$i]. "',0)";
$result = mysql_query($query);
if (! $result) return false;
}
return true;
}
? >
Д.3 Листинг модуля "score. php"
<? session_start();
echo"<html><head><title>Станица результатов</title>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>
</head>
<body leftmargin='0' rightmargin='0' topmargin='0'>";
include("all. php");
doheader('Экзаменатор',' - Результаты');
do_buttons();
$color1='#e5e5e5';
$color2='#cbdff7';
$score=0;
$sub=$_REQUEST ['subnum'] ;
$subject=$_REQUEST ['subject'] ;
$group=$_SESSION ['student'] ['group'] ; $name=$_SESSION ['student'] ['name'] ;
$family=$_SESSION ['student'] ['family'] ; $faculty=$_SESSION ['student'] ['faculty'] ;
$num=idsq($sub); unset($student);
? >
<table width="100%" cellpadding="6" cellspacing="0" bgcolor=<? =$color1? >><tr>
<td><b>Имя: </b> <? =$name? > <b>Фамилия: </b> <? =$family? > <b>Шифр: </b> <? =$group? > <b>Факультет: </b> <? =$faculty? ><br></td></tr>
</tr><tr><td bgcolor="#cbdff7">
<?
for($i=1; $i<=sizeof($num); $i++)
{
if($_REQUEST ["q". $i] ==1)
echo "<b>". $i. ": </b>Верно   "; else echo "<b>". $i. ": </b>Неверно   ";
$score=$score+$_REQUEST ["q". $i] ;
} if($num! =0) { $score=($score/sizeof($num)) *100; $bal=bal($score); $score=(int) $score; }? >
</td></tr><tr><td>
<b>Результат: <? =$score? >% Оценка: <? =$bal? ></b>
</td></tr></table>
<?
if(! store_result($group, $score, $sub))
echo "<b>Ошибка записи студента</b>";
elseif($bal! =2)
{
echo"<form action = rtf1. php method = post>";
echo "<input type = hidden name = name value = '$name'>";
echo "<input type = hidden name = fam value = '$family'>";
echo "<input type = hidden name = group value = '$group'>";
echo "<input type = hidden name = facul value = '$faculty'>";
echo "<input type = hidden name = score value = '$score'>";
echo "<input type = hidden name = bal value = '$bal'>";
echo "<input type = hidden name = sub value = '$subject'>";
echo "<table width=100% cellpadding=6 cellspacing=0 bgcolor=$color2><tr>
<td width=20%><b>Распечатать сертификат: </b></td><td>
<input type=image src=images\certificate. gif value=post></td></table>";
echo "</form>";
}
doout('');
? >
</body>
</html>
Д.4 Листинг модуля "rtf1. php"
<?
header("Content-type: application/msword");
header("Content-Disposition: inline, filename=ITCertify. rtf");
$name=$_REQUEST ['name'] ;
$family=$_REQUEST ['fam'] ;
$faculty=$_REQUEST ['facul'] ;
$group=$_REQUEST ['group'] ;
$score=$_REQUEST ['score'] ;
$bal=$_REQUEST ['bal'] ;
$sub=$_REQUEST ['sub'] ;
$date = date("d. m. Y");
$filename = "Certification. rtf";
$fp = fopen ($filename, "r");
$output = fread($fp, filesize($filename));
fclose ($fp);
$output = str_replace("sub", $sub, $output);
$output = str_replace("name", $name, $output);
$output = str_replace("family", $family, $output);
$output = str_replace("group", $group, $output);
$output = str_replace("faculty", $faculty, $output);
$output = str_replace("score", $score, $output);
$output = str_replace("bal", $bal, $output);
$output = str_replace("data", $date, $output);
echo $output;
? >
Д.5 Листинг модуля "store. php"
<?
include ("all. php");
if(isset($_REQUEST ['bal3'])) $bal3=$_REQUEST ['bal3'] ; else $bal3='';
if(isset($_REQUEST ['bal4'])) $bal4=$_REQUEST ['bal4'] ; else $bal4='';
if($_REQUEST ['subject'] ==''&$_REQUEST ['qes'] ==''&$_REQUEST ['rans'] ==''&$_REQUEST ['ans1'] ==''&$_REQUEST ['ans2'] =='')
{
if(isset($_REQUEST ['rec']))
if($_REQUEST ['rec'] ==true)
if($bal3! =''&&$bal4! ='')
if(storebals($bal3, $bal4) ==true) $_REQUEST ['sb'] =true;
$_REQUEST ['errorcount'] =true;
include ("input. php");
} else
{
if(isset($_REQUEST ['rec']))
if($_REQUEST ['rec'] ==true)
if($bal3! =''&&$bal4! ='')
if(storebals($bal3, $bal4) ==true) $_REQUEST ['sb'] =true;
$_REQUEST ['errorcount'] =false;
if(store($_REQUEST) ==true) $_REQUEST ['error'] ='Done';
else $_REQUEST ['error'] ='No done';
include("input. php");
}
? >
Е.1 Листинг модуля "AdminInternetTechnology. php"
<html>
<head>
<title>Экзаменатор-администрирование</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<body leftmargin="0" rightmargin="0" topmargin="0">
<?
include('all. php');
doheader('Интернет технологии',' - Администрирование');
do_buttons();
$color2="#cbdff7";
$color1='#e5e5e5';
echo"
<table cellpadding=10 cellspacing=1 border=0 bgcolor='#cbdff7' background='images/blocks_bg. gif'><tr><td width=20%>";
include 'leftadmin. php';
echo"</td><td width=80%>";
? >
<table cellpadding=10 cellspacing=1 border='0'>
<tr bgcolor=<? =$color1? >><td width="20%"><b>Экзаменатор</b></td>
<td> - позволяет удалить некоторые вопросы из конкретного предмета или удалить весь предмет. </td></tr>
<tr bgcolor=<? =$color2? >><td width="20%"><b>Ввод новых вопросов</b></td>
<td> - позволяет ввести новые вопросы по существующему предмету или создать новый предмет. </td></tr>
<tr bgcolor=<? =$color1? >><td width="20%"><b>Студенты</b></td>
<td> - посзволяет просмотреть результаты тестирования по одному предмету, по одному студенту или весь спсок, а также удалить некоторые записи</td></tr>
<tr bgcolor=<? =$color2? >><td width="20%"><b>Гостевая книга</b></td>
<td> - позволяет просмотреть, ввести, удалить запрещенные адреса, удалить некоторые записи сообщений. </td></tr>
<tr bgcolor=<? =$color1? >><td width="20%"><b>Чат</b></td>
<td> - позволяет просмотреть, ввести, удалить запрещенные адреса. Просмотреть, удалить зарегистрированных участников, а также удалить записи сообщений. </td></tr>
<tr bgcolor=<? =$color2? >><td width="20%"><b>Магазин</b></td>