-
Notifications
You must be signed in to change notification settings - Fork 0
/
gallery_content.php
85 lines (85 loc) · 3.39 KB
/
gallery_content.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Текущая галлерея</title>
<meta charset='utf-8'>
<link rel="stylesheet" href="../Style/gallery_stylesheet.css">
<style>
input{
margin-left: 1.3em;
width: auto;
}
</style>
</head>
<body>
<?php
require_once("connect_db.php");
@$user = $_COOKIE['admin_flag'];
@$username = $_COOKIE['username'];
$query = "SELECT * FROM galleries"; //формируем запрос
$buff = $pdo->query($query);
$gallery_id = htmlspecialchars(@$_GET['gallery_id']);//вытягиваем id-шник, кинутый через header
$query = "SELECT * FROM pictures WHERE gallery_id='$gallery_id'";
$buff = $pdo->query($query);
try{
$catalog = $buff->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e){
echo "Ошибка выполнения запроса: ".$e->getMessage();
}
if (!isset($_REQUEST['Action']))
{?>
<header>
<h2 class="title" id="title">
<span>Изображеия в галерее:</span>
<?php if($username){ ?>
<div class="LogOut">
<input type="text" name="username" value="<?=" Выполнен вход как: ".$username?>" id="LogedAs"><br />
<input type="submit" name="Action" value="Log out" form="Pictures" style="float: right;">
<?php } else {?>
<input type="text" name="username" value="<?=" Вход не выполнен."?>" id="LogedAs" style="float: right;"><br />
<?php } ?>
</div>
</h2>
</header>
<form id="Pictures" action = "<?=$_SERVER['SCRIPT_NAME']?>" method="post">
<input type="submit" name="Action" value="Add new image" form="Pictures" >
<input type="submit" name="Action" value="Back" form="Pictures" >
<ul name="ImageList" form="Pictures">
<?php foreach($catalog as $log):?>
<li>
<a href="comment_picture.php?image_id=<?=$log['id']?>">
<img class="preview" src="<?=$log['image_path']?>" alt="<?=$log['title']?>">
</a>
</li>
<?php endforeach;?>
</ul><br />
<input type="hidden" name="gallery_id" value="<?=htmlspecialchars($_GET['gallery_id']) ?>" form="Pictures"> <!--Перекидываю id-шник из одной обасти видимости в другую. Без этого в коде ниже нельзя было получить значение -->
<a class="rewind_up" href="#title" title="Наверх"> ↑ </a>
</form>
<?php
}
else
{
switch($_REQUEST['Action'])
{
case 'Add new image':
$dir = dirname($_SERVER['SCRIPT_NAME']);
if ($dir=='\\') $dir='';
$id = $_REQUEST['gallery_id'];
header("Location: $dir/add_new_image.php?gallery_id=$id");
break;
case 'Back':
$dir = dirname($_SERVER['SCRIPT_NAME']);
if ($dir=='\\') $dir='';
header("Location: $dir/galleries_list.php");
break;
case 'Log out':
$dir = dirname($_SERVER['SCRIPT_NAME']);
if ($dir=='\\') $dir='';
header("Location: $dir/index.php");
break;
}
}
?>
</body>
</html>