-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
246 lines (198 loc) · 8.05 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="es">
<?php
$webTitle = "Home Page - Picturesque";
require_once 'head.php';
$cookie_name = 'authenticated';
if(isset($_GET["signout"])){
$_SESSION = array();
if(isset($_COOKIE[$cookie_name])) {
setcookie($cookie_name, '', time() - 42000, '/');
}
session_destroy();
echo "
<script> closePopUpAlbum(); </script>
";
}
if(isset($_GET["signin"])){
$_SESSION["authenticated"] = $_COOKIE[$cookie_name];
echo "
<script> closePopUpAlbum(); </script>
";
}
?>
<body>
<div id="popUpLogin">
<?php
if (!isset($_COOKIE['authenticated']) && !isset($_SESSION['authenticated'])) include 'login.php';
else if(isset($_COOKIE['authenticated']) && !isset($_SESSION['authenticated'])) include 'rememberlogin.php';
?>
</div>
<div id="overlay-back"></div>
<header>
<a href="index.php">
<img class="logoBox" src="Resources/Images/logo.png" alt="Logo"/>
</a>
<?php if (isset($_SESSION['authenticated'])) include 'logged.html'; ?>
<?php if (!isset($_SESSION['authenticated']))
echo "<button id=\"loginPopUp\" onClick=\"showLogin();\"><i class=\"fa fa-sign-in\"></i> Sign in! </button>" ?>
<div class="currentAccesibleStyle">
<p> Pick the Style: </p>
<button class="btn btn-login btnStyle" id="principalA" onclick="getStringFromObject(this)" >Principal </button>
<button class="btn btn-login btnStyle" id="accesibleA" onclick="getStringFromObject(this)" >Accesible </button>
</div>
<div class="padding headerContent">
<h1>DISCOVER & SHARE </h1>
<form enctype="multipart/form-data" method="get" action="searchresults.php">
<div class="searchContainer">
<img class="lupa" src="Resources/Images/search-icon.png" alt="search icon" />
<input required="" class="search" type="text" name="searchInput" id="searchInput" placeholder="Search..." />
<input class="btn btn-login" type="submit" value="Go!"/>
<a class= "btn btn-login searchAdvanced" href="searchpro.php">
<img src="Resources/Images/gear.png" alt="gear icon" />
</a>
</div>
</form>
</div>
<div class="currentStyle">
<button class="btn btn-login btnStyle" id="cangestyle">Style</button>
<ul id="webstyle">
<li id="principal" onclick="getStringFromObject(this)"> <p>Principal</p></li>
<li id="accesible" onclick="getStringFromObject(this)"> <p>Accesible</p></li>
</ul>
</div>
</header>
<section>
<div class="boxPics"> <h2>Last pics <i class="fa fa-camera-retro"></i></h2> </div>
<?php
$identificador = @mysqli_connect('localhost',$MYSQL_USER,$MYSQL_PASS,$MYSQL_DB);
$i=0;
if(!$identificador){
echo "<p>Error al conectar con la base de datos: ". mysqli_connect_errno();
echo "</p>";
exit;
}
$sentencia= "select * from fotos, paises where fotos.pais=paises.idPais order by fRegistro desc limit 4";
if(!($resultado = @mysqli_query($identificador,$sentencia))){
echo "<p>Error al ejecutar la sentencia <b>$sentencia</b>: ". mysqli_error($identificador);
echo "</p>";
exit;
}
$count=mysqli_num_rows($resultado);
if($count > 0){
echo "<ul>";
while ($fila = @mysqli_fetch_assoc($resultado)){
echo "<li>";
echo "<img src='$fila[Fichero]' alt='$fila[Fichero]'/> ";
echo "<a class='titleImage' href='detailpicture.php?id=$fila[idFoto]'><span class='titleImage'>Title: $fila[Titulo]</span></a> ";
echo "<p><b class='titlePrint'><a href='detailpicture.php?id=$i'>Title: $fila[Titulo]</a></b>made on the $fila[Fecha] in $fila[NombrePais] </p>";
echo "</li>";
}
echo "</ul>";
}
else{
echo "<span class='noPhotos'>No pictures to show...</span>";
}
?>
<div class="boxSelectedPics"> <h2>Selected pic <i class="fa fa-trophy"></i></h2><div class="specialLine"></div> </div>
<?php
if(($fichero = @file("Resources/seleccion.txt")) == false){
echo "<span class='noPhotos'>No selection to show...</span>";
}
else{
$random = mt_rand(0,sizeof($fichero)-1);
$linea = $fichero[$random];
$attElemento = split(';;', $linea);
$imagenSeleccionada = "select * FROM fotos f LEFT JOIN paises p ON f.Pais = p.idPais WHERE f.idFoto = '$attElemento[0]'";
if(!($resultadoSelec = @mysqli_query($identificador,$imagenSeleccionada))){
echo "<p>Error al ejecutar la sentencia <b>$imagenSeleccionada</b>: ". mysqli_error($identificador);
echo "</p>";
exit;
}
if(mysqli_num_rows($resultadoSelec) > 0){
$filaSelec = @mysqli_fetch_assoc($resultadoSelec);
$idSelecFoto = $filaSelec['idFoto'];
$titulo = $filaSelec['Titulo'];
$fecha = $filaSelec['Fecha'];
$pais = $filaSelec['NombrePais'];
$img = $filaSelec['Fichero'];
}
echo "<div class='selectedPhoto'>
<img src='$img' alt='$img'/>
<h2>$titulo</h2> <a class='selectedRef' href='detailpicture.php?id=$idSelecFoto'>(see in detail)</a><br>
<span>$fecha - $pais</span><br>
<span>Selected by <b>$attElemento[1]</b></span><br>
<span class='selectedComment'>'$attElemento[2]'</span>
</div>";
}
?>
<div class="boxSelectedPics2"> <h2>Pictures uploaded </h2><div class="specialLine2"></div> </div>
<?php
//2015-01-03 16:32:18
date_default_timezone_set('Europe/Madrid');
$now = date('Y/m/d H:i:s ', time());
$lweek = new Datetime($now);
$week = new Datetime($now);
$lweek->modify('-7 days');
$ago=$lweek->format('Y/m/d H:i:s ');
$sentencia= "select FRegistro,Fichero,count(*) as nfotos from fotos where FRegistro>='".$ago."' && FRegistro<='".$now."' group by FRegistro;";
if(!($resultado = @mysqli_query($identificador,$sentencia))){
echo "<p>Error al ejecutar la sentencia <b>$sentencia</b>: ". mysqli_error($identificador);
echo "</p>";
exit;
}
$count=mysqli_num_rows($resultado);
$totalPhotos=0;
$dateArrayProv=array();
if($count > 0){
echo "<br>";
$array=array();
$lastdate=$lweek->format('Y-m-d ');
while ($fila = @mysqli_fetch_assoc($resultado)){
//Revisar para insertar todas las fechas intermedias
$photodate = date("Y-m-d", strtotime($fila["FRegistro"]));
$array[]=array($photodate,$fila["nfotos"]);
}
for($i=0;$i<count($array);$i++){
if($array[$i][0] != $lastdate){
$lastdate=$array[$i][0];
for($j=0;$j<count($array);$j++){
if($lastdate == $array[$j][0]) $totalPhotos+=$array[$j][1];
}
$dateArrayProv[]=array($lastdate,$totalPhotos);
$totalPhotos=0;
}
}
$lastdate=$lweek->format('Y-m-d ');
$finaldateArray=array();
for($i=0;$i<=7;$i++){
$finaldateArray[]=array($lastdate,0);
$lweek->modify('+1 days');
$lastdate=$lweek->format('Y-m-d ');
}
for($i=0;$i<count($dateArrayProv);$i++){
for($j=0;$j<count($finaldateArray);$j++){
if(strtotime($dateArrayProv[$i][0]) == strtotime($finaldateArray[$j][0]))
$finaldateArray[$j][1]=$dateArrayProv[$i][1];
}
}
}
else{
echo "<span class='noPhotos'>No pictures to show...</span>";
}
include 'diagram.php';
?>
<div id="imgDiagram">
<img id="diagrama" src="<?php echo $img_src; ?>" />
</div>
</section>
<span class="rights printIn">Made for an awesome subject in the University of Alicante. All Copyright reserved to Alberto Martínez Martínez and Roxanne López van Dooren</span>
<?php
mysqli_free_result($resultado);
mysqli_close($identificador);
require_once("footer.php");
?>
<script src="js/login.js"></script>
</body>
</html>