3 Разработка программы
Скрипт состоит из нескольких файлов, каждый из которых отвечает за определённую функцию программы:
/banner/… – картинки баннера
/img/… – сервисные картинки
/00.txt– информация о баннерах для промежутка времени
/07.txt – информация о баннерах для промежутка времени
/13.txt – информация о баннерах для промежутка времени
/19.txt – информация о баннерах для промежутка времени
/add.php – добавление баннера
/edit.php – редактирование баннера
/del.php – удаление баннера
/index.php – главное страница
/head.php – шапка сайта
/add.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Добавить</title>
</head>
<body bgcolor="#FF99FF">
<table align="center">
<tr>
<td align="center">
<? include("head.php"); ?>
</td>
</tr>
<tr valign="top" align="center" height="500">
<td>
<?php
if(isset($_GET['t'])) {$t=$_GET['t']; if ($t =='') {unset($t);}}
if(isset($t)){
if($t==00 || $t==07 || $t==13 || $t==19){
if($_POST['submit'] != '') {
$url=$t.".txt";
$d= array();
$d['n'] = stripslashes(substr($_POST['data']['0'],0,20));
$d['m'] = stripslashes(substr($_POST['data']['1'],0,20));
$d['t'] = stripslashes(substr($_POST['data']['2'],0,20));
if($d['n'] != '') {
if($d['m'] !='') {
if($d['t'] != '') {
$data = implode("|",$d);
$handle = fopen($url,"a");
fwrite($handle,$data."\n");
fclose($handle);
echo "<a href=\"index.php\">посмотреть</a>";
}
else {echo "Введите картинку";}
}
else {echo "Введите название";}
}
else {echo "Введите адрес";
}
}
else {
print "<p><form name='form1' action='add.php?t=$t' method='post'> Адрес:<input name='data[0]' type='text'><br/>Название:<input name='data[1]' type='text'><br/>Картинка:<input name='data[2]' type='text'><br/><input type='submit' name='submit' value='добавить'><br/></form></p>";
}
}
else echo "<a href=\"index.php\">назад</a>"; //Нет такого файла
}
else echo "<a href=\"index.php\">назад</a>"; //нет перменной
?>
</td>
</tr>
</table>
</body>
</html>
/del.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Удалить</title>
</head>
<body bgcolor="#FF99FF">
<table align="center">
<tr>
<td align="center">
<? include("head.php"); ?>
</td>
</tr>
<tr valign="top" align="center" height="500">
<td>
<?
if(isset($_GET['t'])) {$t=$_GET['t']; if ($t =='') {unset($t);}}
if(isset($t)){
if($t==00 || $t==07 || $t==13 || $t==19){
$url = $t.".txt";
if($_GET['del']) {
$data = @file($url);
$data[$_GET['num']]="";
$f = fopen($url,"w");
for($i=0;$i<=sizeof($data);$i++)
{
fputs($f,$data[$i]);
}
fclose($f);
echo "Запись удалена<br/>";
echo "<a href=\"index.php\">назад</a>";
}
else {
$data = file($url);
for($i=0;$i<=count($data)-1;$i++) {
list($name,$text,$image) = explode("|",$data[$i]);
echo "";
echo "<img src='banner/$image' width='400' height='50'><a href=\"del.php?del=1&num=$i&t=$t\"><img border='0' src='img/d.gif' width='50' height='50'></a>";
echo "<br/><br>";
}
}
}
else echo "<a href=\"index.php\">назад</a>"; //Нет такого файла
}
else echo "<a href=\"index.php\">назад</a>"; //нет перменной
?>
</td>
</tr>
</table>
</body>
</html>
/edit.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Редактировать</title>
</head>
<body bgcolor="#FF99FF">
<table align="center">
<tr>
<td align="center">
<? include("head.php"); ?>
</td>
</tr>
<tr valign="top" align="center" height="500">
<td>
<?
if(isset($_GET['t'])) {$t=$_GET['t']; if ($t =='') {unset($t);}}
if(isset($t)){
if($t==00 || $t==07 || $t==13 || $t==19){
$url=$t.".txt";
if($_GET['edit']){
if($_POST['change']) {
$data = @file($url);
$name = $_POST['name'];
$text = $_POST['text'] ;
$image = $_POST['image'];
$data[$_POST['num']] = "$name|$text|$image\n";
$f = fopen($url,"w");
for($i=0;$i<=sizeof($data);$i++)
{
fputs($f,$data[$i]);
}
fclose($f);
echo "Запись изменена<br/>";
echo "<a href=\"index.php\">назад</a>";
}
else {
$data = @file($url);
list($name,$text,$image) = explode("|",$data[$_GET['num']]);
echo '<form action="edit.php?edit=1&t='.$t.'" method="post">';
echo 'Имя:<input type="text" name="name" value="'.$name.'"><br/>';
echo 'Эл.почта:<input type="text" name="text" value="'.$text.'"><br/>';
echo '<input type="text" name="image" value="'.$image.'"><br/>';
echo '<input type="hidden" name="num" value="'.$_GET['num'].'">';
echo '<input type="submit" name="change" value="изменить"><br/>';
echo '</form>';
}
}
else {
$data = @file($url);
for($i=0;$i<=count($data)-1;$i++) {
list($name,$text,$image) = explode("|",$data[$i]);
echo "<img src='banner/$image' width='400' height='50'><a href=\"edit.php?edit=1&num=$i&t=$t\"><img border='0' src='img/e.gif' width='50' height='50'></a>";
echo "<br/><br/>";
}
}
}
else echo "<a href=\"index.php\">назад</a>"; //Нет такого файла
}
else echo "<a href=\"index.php\">назад</a>"; //нет перменной
?>
</td>
</tr>
</table>
</body>
</html>
/head.php:
<table width="500">
<tr>
<td>Добавить</td>
<td><a href="add.php?t=00">0006</a></td>
<td><a href="add.php?t=07">0712</a></td>
<td><a href="add.php?t=13">1318</a></td>
<td><a href="add.php?t=19">1923</a></td>
</tr>
<tr>
<td>Редактировать</td>
<td><a href="edit.php?t=00">0006</a></td>
<td><a href="edit.php?t=07">0712</a></td>
<td><a href="edit.php?t=13">1318</a></td>
<td><a href="edit.php?t=19">1923</a></td>
</tr>
<tr>
<td>Удалить</td>
<td><a href="del.php?t=00">0006</a></td>
<td><a href="del.php?t=07">0712</a></td>
<td><a href="del.php?t=13">1318</a></td>
<td><a href="del.php?t=19">1923</a></td>
</tr>
</table>
<p><a href="index.php">Главная</a></p>
/index.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<meta http-equiv="refresh" content="5; url=index.php">
<title>Главная</title>
</head>
<body bgcolor="#FF99FF">
<table align="center">
<tr>
<td align="center">
<? include("head.php"); ?>
</td>
</tr>
<tr valign="middle" align="center" height="500">
<td>
<?
$time = date("H:i:s");
$timer = explode(":",$time);
if (00<=$timer[0] && 06>=$timer[0])
{
$info = file("00.txt");
$line = rand(0,count($info)-1);
$line = $info[$line];
}
if (07<=$timer[0] && 12>=$timer[0])
{
$info = file("07.txt");
$line = rand(0,count($info)-1);
$line = $info[$line];
}
if (13<=$timer[0] && 18>=$timer[0])
{
$info = file("13.txt");
$line = rand(0,count($info)-1);
$line = $info[$line];
}
if (19<=$timer[0] && 23>=$timer[0])
{
$info = file("19.txt");
$line = rand(0,count($info)-1);
$line = $info[$line];
}
list($url,$alt,$img)=explode("|", $line);
print "<a target=_blank href=$url><img src=banner/$img alt=\"$alt\" border=0 width=460 height=60></a>";
?>
</td>
</tr>
</table>
</body>
</html>
В скрипте применялись следующие операторы:
Echo
print
for
if
else
include