Смекни!
smekni.com

Разработка модуля сайта преподавателя по дисциплине Интернет-технологии (стр. 26 из 30)

include 'all. php';

storeshopclient($_SESSION ['client'] ['name'], $_SESSION ['client'] ['sname'], $_SESSION ['client'] ['email'], $_SESSION ['client'] ['address'], $_SESSION ['client'] ['fhone']);

$idclienta=idclienta($_SESSION ['client'] ['name'], $_SESSION ['client'] ['sname'], $_SESSION ['client'] ['email']);

if(storezakaz($idclienta, $_SESSION ['client'] ['id'], $_SESSION ['client'] ['count']))

{

echo "<script> alert('Ваш заказ принят! ') </script>";

$idz=mes($_SESSION ['client'] ['id'], 'idc', 'cd');

$mess=$_SESSION ['client'] ['name']. " ". $_SESSION ['client'] ['sname']. " заказал(а)". $_SESSION ['client'] ['count']. " ". $idz ['title']. " на сумму: ". $_SESSION ['client'] ['count'] *$idz ['price']. "р. Заказ нужно доставить по адресу: ". $_SESSION ['client'] ['address']. ". Адрес электронной почты: ". $_SESSION ['client'] ['email']. ". ";

error_reporting(0);

if(! mail('kash@newmsk. tula. net', 'Поступил заказ', $mess, "Content-type: text/plain; charset=windows-1251", "Content-Transfer-Encoding: 8bit")) echo"Невозможно соединиться с почтовым сервером! "; //

error_reporting(E_ALL);

$_SESSION ['mode'] ='shop';

include 'InternetTechnology. php';

} else echo "<script> alert('Ваш заказ не принят! ') </script>";

}

else

{

$name=isset($_REQUEST ['name'])? $_REQUEST ['name']: '';

$sname=isset($_REQUEST ['sname'])? $_REQUEST ['sname']: '';

$email=isset($_REQUEST ['email'])? $_REQUEST ['email']: '';

$fhone=isset($_REQUEST ['fhone'])? $_REQUEST ['fhone']: '';

$id=isset($_REQUEST ['id'])? $_REQUEST ['id']: '';

$count=isset($_REQUEST ['count'])? $_REQUEST ['count']: '';

$address=isset($_REQUEST ['address'])? $_REQUEST ['address']: '';

if($id! =''&$address! =''&$count! =''&$name! =''&$sname! =''&$email! ='')

{

$_SESSION ['client'] ['name'] =$name;

$_SESSION ['client'] ['sname'] =$sname;

$_SESSION ['client'] ['fhone'] =$fhone;

$_SESSION ['client'] ['email'] =$email;

$_SESSION ['client'] ['address'] =$address;

$_SESSION ['client'] ['id'] =$id;

$_SESSION ['client'] ['count'] =$count;

$cd=mes($id, 'idc', 'cd');

echo '<font size=2>Уважаемый(ая) '. $name. ' '. $sname. '! Ваши данные: <br> Телефон: '. $fhone. '<br> Адрес электронной почты: '. $email. '<br> Адрес доставки: '. $address. '<br>';

echo 'Вы заказали '. $count. ' диск(а)"'. $cd ['title']. '" на сумму '. $cd ['price'] *$count. 'р. <br>Если все правильно, пожалуйста нажмите <a href=shopping. php? pod=true>Заказать</a>! </font><br><br><br>';

}

}

? >

Г.3 Листинг модуля "funcshop. php"

<?

function update_status($id)

{

$conn = db_connect();

$query = "update zakaz set flag_done = 'y' where idz = '$id'";

$result = mysql_query($query);

if(! $result) return false;

else return true;

}

function fdel($id, $idname, $table)

{

$conn = db_connect();

$query = "delete from $table where $idname=$id";

$result = mysql_query($query);

if(! $result) return false;

else return true;

}

function idclienta($name, $sname, $email)

{

$conn = db_connect();

$query = "select idclient from shopclients where name='$name' and sname='$sname' and email='$email'";

$result = mysql_query($query);

if(mysql_numrows($result) >0)

return mysql_result($result, 0, 0);

else return 0;

}

function reccd($cd)

{

$conn = db_connect();

$query = "insert into cd values (null, '". $cd ['title']. "', '". $cd ['description']. "', '". $cd ['price']. "')";

$result = mysql_query($query);

if(! $result) return false;

return true;

}

function storeshopclient($name, $sname, $email, $address, $fhone)

{

if(idclienta($name, $sname, $email) ==0)

{

$conn = db_connect();

$query = "insert into shopclients values (null, '". $name. "', '". $sname. "', '". $email. "', '". $address. "', '". $fhone. "', now())";

$result = mysql_query($query);

if(! $result) return false;

return true;

}}

function storezakaz($idclienta, $idcd, $count)

{

$conn = db_connect();

$query = "insert into zakaz values (null, '". $idclienta. "', '". $idcd. "', '". $count. "', now(), 'n')";

$result = mysql_query($query);

if(! $result) return false;

return true;

}

? >

Приложение Д. Листинги модулей формирования тестирования

Д.1 Листинг модуля "exam. php"

<?

session_start();

echo"<html><title>Страница тестирования</title>

<meta http-equiv='Content-Type' content='text/html; charset=Windows-1251'>

<body leftmargin='0' rightmargin='0' topmargin='0'>";

include("all. php");

if(! isset($_SESSION ['student']))

{

$_SESSION ['error_fill'] ['bool'] ='true';

$_SESSION ['error_fill'] ['message'] ='<b>Чтобы войти в экзаменатор нужно зарегистрироваться! </b>';

include 'InternetTechnology. php';

}

else

{

doheader('Интернет технологии',' - Тестирование');

do_buttons();

if(isset($_REQUEST ['sub'])) $sub=$_REQUEST ['sub'] ; else $sub='';

$massq=ids('subjects', 'idsub'); // массив id всех предметов

$subnum=idss($sub); // Номер выбранного предмета

$color2='#cbdff7';

$color1='#e5e5e5';

$row=0;

$idstud=$_SESSION ['student'] ['group'] ;

echo "<table width=100% background='images/blocks_bg. gif'><tr><td width=20% valign=top>";

echo"<center><table width=160 border=1 bgcolor=$color1 bordercolor=darkblue cellpadding=6><tr>

<td align=left><font color=blue><b>Предметы: </b><center><hr color=#ff9900 width=98%></center>";

for($i=0; $i<sizeof($massq); $i++)

{

$subj=mes($massq [$i], 'idsub', 'subjects');

$ntry=2-count_try($massq [$i], $idstud);

if($ntry>0)

{

$tit='У вас осталось попыток: '. $ntry;

echo "<a href=exam. php? sub=". $subj ['subject']. " title='$tit'>

<font color=blue><b>". $subj ['subject']. "</font></a></b><br>";

}

else

{

$tit='У вас не осталось попыток! ';

echo "<a href=exam. php? nt=false title='$tit'><font color=blue><b>". $subj ['subject']. "</font></a></b><br>";

}

}

echo"</td></tr></table><br></td><td class='body' width=80% valign=top>";

if(! $sub)

{

$idstud=$_SESSION ['student'] ['group'] ;

echo "<b>". $_SESSION ['student'] ['group']. " ". $_SESSION ['student'] ['name']. " ". $_SESSION ['student'] ['family']. " ". $_SESSION ['student'] ['faculty']. "<br></b>";

echo"<br><b>Для тестирования по каждой теме у вас есть 2 попытки. Выберите тему тестирования. <b><br>

<b>Перед повторным тестирование рекомендуется повторить тему еще раз<b>";

}

else

{

echo"<form action=score. php method=post>";

$mass=idsq($subnum);

$n=sizeof($mass);

echo"<center><table cellpadding=6 cellspacing=1 border=0 width=100% bgcolor=$color1>

<tr><td><font size='+1'>Тест состоит из $n вопросов. </font></td></tr></table> ";

if(sizeof($mass) >1) shuffle($mass);

for($i=0; $i<sizeof($mass); $i++)

{

if ($row%2) $col=$color1; else $col=$color2;

$message=mes($mass [$i], 'idques', 'questions');

echo "<table width=100% cellpadding=6 cellspacing=0 border=0><tr><td bgcolor=". $col. " ><strong>". ($i+1). ". ". $message ['quesmes']. "</strong><ol>";

$res=outans($mass [$i]); if($res>1) shuffle($res);

for($j=0; $j<sizeof($res); $j++)

{

$val=mes($res [$j], 'idans', 'answers');

echo "<li><input type=radio name=q". ($i+1). " value=". $val ['rightanswer']. ">". $val ['ansmes']. "<br>";

}

echo "</ol></td></tr></table>";

$row++;

}

if ($row%2) $col=$color1; else $col=$color2;

echo "<table cellpadding=10 cellspacing=0 border=0 bgcolor=". $col. " width=100% >

<tr><td align=center><font size=+1>$sub</font><br><br>

<input type=hidden name=subnum value=". $subnum. "><input type=hidden name=subject value=". $sub. ">

<input type=submit name=submit value=Готово></td></tr>

</table>";

}

echo"</td></tr></table></center></form>";

doout('');

} // not registered

? >

</body>

</html>

Д.2 Листинг модуля "funcexam. php"

<?

function loginpass($log, $pass)

{

$conn = db_connect();

$query = "select* from students where login='$log' and password='$pass'";

$result = mysql_query($query);

if(mysql_numrows($result) ==0)

{

return false;

}

return mysql_fetch_array($result);

}

function fdelstud($id) // Oaaeaiea anao ioieoia

{

$conn = db_connect();

$query = "select idres from results where idstudr='$id'";

$result = mysql_query($query);

if(! $result) return false;

if(mysql_numrows($result) ==0)

{

$query="delete from students where idstud='$id'";

$result = mysql_query($query);

if(! $result) return false;

return true;

} else echo"<center><b>Не удается удалить участника, сначала удалите его сообщения! </b></center><br>";

}

function outstudents($nums, $mode)

{

$row=0;

$color2='#cbdff7';

$color1='#e5e5e5';

echo "<table width=100% bgcolor=$color1 cellpadding=3 cellspacing=0 border=0>

<tr><td width=22% align=center><b>Имя и фамилия</b></td>

<td width=6% align=center><b>Шифр</b></td>

<td width=10% align=center><b>Факультет</b></td>

<td width=17% align=center><b>Предмет</b></td>

<td width=10% align=center><b>Оценка</b></td>

<td width=9% align=center><b>Попытка</b></td>

<td width=12% align=center><b>Дата</b></td>

<td width=14% align=center><b>Удаление</b></td></tr></table>";

echo"<table width=100% cellpadding=5 cellspacing=0>";

for($i=0; $i<sizeof($nums); $i++)

{

$results=mes($nums [$i],'idres','results');

$student=mes($results ['idstudr'],'idstud','students');

$subject=mes($results ['idsubr'],'idsub','subjects');

if ($row%2) $col=$color1; else $col=$color2;

$date=reformat_date($results ['posted']);

echo "<tr bgcolor=". $col. ">

<td width=22% >". ($i+1). ". ". $student ['name']. "&nbsp; ". $student ['secondname']. "</td>

<td width=6%>". $student ['idstud']. "</td>

<td width=10%>". $student ['faculty']. "</td>

<td width=17% >". $subject ['subject']. "</td>

<td width=10%>". bal($results ['score']). " (". $results ['score']. "%) </td>

<td width=9% >". $results ['count']. "</td>

<td width=12%>". $date. "</td>

<td width=14%><a href=students. php? mode=". $mode. "&del=". $results ['idres']. ">Удалить запись</a></td>

</tr>";

$row++;

}echo "</table>";

}

function idsst($id, $idname) // Количество вопросов

{

$conn = db_connect();

$query = "select idres from results where $idname='$id'";

$result = mysql_query($query);

if(! $result) return false;

if(mysql_numrows($result) >0)

{

$num=mysql_numrows($result);

for($i=0; $i<$num; $i++)

$idsst [$i] =mysql_result($result,$i,0);

return $idsst;

}

}

function store_result($group, $score, $sub) // Запись студента

{

$conn = db_connect();

$count=count_try($sub, $group);

if($count==0)

{

$query = "insert into results values (null, '". $sub. "', '". $group. "', now(), '". $score. "',

1)";

$result = mysql_query($query);

if (! $result) return false;

} else

{

$count=$count+1;

$query = "delete from results where idstudr='$group' and idsubr='$sub'";

$result = mysql_query($query);

if (! $result) return false;

$query = "insert into results values (null, '". $sub. "', '". $group. "', now(), '". $score. "', '". $count. "')";

$result = mysql_query($query);

if (! $result) return false;

}

return true;

}

function count_try($idsub, $idstud)

{

$conn = db_connect();

$query = "select count from results where idsubr='$idsub' and idstudr='$idstud'";

$result = mysql_query($query);

if(mysql_numrows($result) ==0) return 0;

else return mysql_result($result,0,0);

}

function deletesubject($delsub) // Удаление предмета и его вопросов

{

$conn = db_connect();

$query = "select idques from questions where idsubq='$delsub'";

$result = mysql_query($query);

if(! $result) return false;

$num=mysql_numrows($result);

for($i=0; $i<$num; $i++)

{