-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsecurity.php
More file actions
executable file
·210 lines (185 loc) · 6 KB
/
security.php
File metadata and controls
executable file
·210 lines (185 loc) · 6 KB
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
<?php
$photoFolder="/home/technik7/public_html/house";
$photoFolderHistory="/home/technik7/public_html/house_history";
$photoExtension=".jpg";
?>
<!DOCTYPE html>
<html>
<head>
<title>Security house</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<!-- jQuery -->
<script src="js/jquery-1.10.2.min.js"></script>
<!-- Fotorama -->
<link href="js/fotorama.css" rel="stylesheet">
<script src="js/fotorama.js"></script>
<script src="js/moment.min.js"></script>
<style media="screen">
.time_positive {
color:green;
font-family:verdana;
font-size:300%;
}
.time_negative {
color:red;
font-family:verdana;
font-size:300%;
}
</style>
<!-- Just don’t want to repeat this prefix in every img[src] -->
<script>
var pathToApp="";
/** extension of the name of images */
var imageExtension=<?php echo "\"".$photoExtension."\"" ?>;
/** length of time stamp of image */
var timeStampLength=14;
/** additional prefix of the name of the file*/
var timeStampLengthMess=2;
/** name of the last image, which was shown on fotorama */
var lastActivatedImage="";
function onChangeImageOnFotorama(newImageName){
printDifference(lastActivatedImage, newImageName);
lastActivatedImage=newImageName;
printDate(newImageName);
}
var DATETIME_FORMAT="YYYYMMDDHHmmss";
function printDate(newImage){
var newTimestamp=getTimeStamp(newImage);
var time=newTimestamp.substring(8,14);
$("#display").html(time.substring(0,2)+":"+time.substring(2,4)+":"+time.substring(4,6));
}
/** calculate difference and print it on the page */
function printDifference(previousImage, newImage){
var previousTimestamp=getTimeStamp(previousImage);
var newTimestamp=getTimeStamp(newImage);
var previousDate=moment().format(previousTimestamp, DATETIME_FORMAT);
var newDate=moment().format(newTimestamp, DATETIME_FORMAT);
var ms;
if(newDate>previousDate){
ms = moment(newTimestamp,DATETIME_FORMAT).diff(moment(previousTimestamp,DATETIME_FORMAT));
}else {
ms = moment(previousTimestamp,DATETIME_FORMAT).diff(moment(newTimestamp,DATETIME_FORMAT));
}
var d = moment.duration(ms);
var s = Math.floor(d.asHours()) + moment.utc(ms).format(":mm:ss");
// console.log("s: "+s);
displayTime(s, newDate>previousDate);
}
function displayTime(message, isPositive){
$("#diff").text(message);
$("#diff").removeAttr('class');
if(isPositive){
$("#diff").attr('class', 'time_positive');
}else{
$("#diff").attr('class', 'time_negative');
}
}
/** read time stamp from file like: house2015101323010801.jpg */
function getTimeStamp(imageName){
var imageNameWithoutExtension=imageName.substring(1, imageName.length-imageExtension.length-timeStampLengthMess);
return imageNameWithoutExtension.substring(imageNameWithoutExtension.length-timeStampLength, imageNameWithoutExtension.length);
}
// read active image which shown right now
function getActiveImage(){
var image=$(".fotorama__active");
return image.children(0).children(0);
}
// change listener
$(function () {
$('.fotorama')
// Listen to the events
.on('fotorama:showend ',
function (e, fotorama, extra) {
onChangeImageOnFotorama(fotorama.activeFrame.img);
}
)
// Initialize fotorama manually
.fotorama();
});
function getActiveImageName(){
var imagePath=getActiveImage().attr("src");
if(imagePath.indexOf('/')<0){
return imagePath;
}else{
return imagePath.substring(imagePath.lastIndexOf('/')+1,imagePath.length);
}
}
// control functions
/**
remove single file
*/
function removeImage(){
// get request "remove"
var fileName=getActiveImageName();
$.get(pathToApp+"remove.php?file="+fileName,
function( data ) {
location.reload();
});
}
function removeImageBeforeCurrent(){
// get request "remove"
var fileName=getActiveImageName();
$.get(pathToApp+"removeEarlier.php?file="+fileName,
function( data ) {
location.reload();
});
}
function copyActiveImageToHistory(){
// get request "move to history"
$( "#lastMovedToHistory" ).src="";
var filePath=getActiveImage().attr("src");
var fileName=getActiveImageName();
$.get(pathToApp+"movedToHistory.php?file="+fileName,
function( data ) {
$( "#lastMovedToHistory" ).attr("src",filePath);
})
}
</script>
</head>
<body>
<!-- history block -->
<button onclick="copyActiveImageToHistory()">move to history:</button>
Last added to History:
<img id="lastMovedToHistory" width="125" />
<br />
<div id="display" ></div>
<!-- Fotorama -->
<div class="fotorama"
data-keyboard="true"
data-nav="thumbs"
data-width="500"
data-ratio="500/367"
data-transition="crossfade"
data-max-width="100%"
data-thumbheight="120px"
data-thumbwidth="120px"
>
<?php
$dir = opendir($photoFolder);
$files = array();
while ($files[] = readdir($dir));
sort($files);
closedir($dir);
function endsWith($haystack, $needle) {
// search forward starting from end minus needle length characters
return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== FALSE);
}
foreach ($files as $file){
if(endsWith($file, ".jpg")){
echo "<img src=\"../house/$file\" >\n";
}
}
?>
</div>
<!-- time difference between two images -->
<div id="diff">
</div>
<button onclick="removeImage()">remove</button>
<button onclick="removeImageBeforeCurrent()">REMOVE EARLIER</button>
</body>
</html>