-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycorrectfilemismatches.php
282 lines (263 loc) · 16.2 KB
/
mycorrectfilemismatches.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
define('WT_SCRIPT_NAME', 'mycorrectfilemismatches.php');
define('FILE_MISMATCH_PAGE_URL', 'mycorrectfilemismatchesserver.php');
define('GALLERY_PATH_PREFIX', "gallery");
require 'mysession.php';
if (!$canadmin) {
echo '*** ERROR: You must be an administrator to enter this area of the site ***<br>';
echo '*** Click the BACK button in your browser to return to the previous page ***<br>';
exit;
}
$submit = safe_POST('update');
// ************************ BEGIN = 'Build the folderlist array' ************************
$folderlist = array();
buildfolderlist('', GALLERY_PATH_PREFIX);
function buildfolderlist($indexpath, $indexfolder) { // Recursively parses through folders to get pertinent folder names
global $folderlist;
$indexpath = ($indexpath) ? ($indexpath . '/') : '';
$filelist = scandir($indexpath . $indexfolder);
foreach ($filelist as $key => $onefile) {
if (is_dir($indexpath . $indexfolder . '/'. $onefile)) {
if (!in_array(basename($onefile), array('.', '..', 'full', 'large', 'medium', 'small', 'thumb', 'resources'))) { // File is not parent or current dir
$folder_to_add = $indexpath . $indexfolder . '/' . $onefile;
array_push($folderlist, $folder_to_add);
buildfolderlist($indexpath . $indexfolder, $onefile);
}
}
}
}
if (!empty($folderlist)) {
$folders_to_remove = array();
foreach ($folderlist as $key => $onefile) { // Now remove any residual folders that do not contain image folders in the path
if (!strpos($onefile, 'images')) { // Folder does not contain images of interest
array_push($folders_to_remove, $onefile);
}
}
$folderlist = array_diff($folderlist, $folders_to_remove); // Remove non-image folders from the list
}
$ct = count($folderlist);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="themes/olivegreen/style.css"/>
<script type="text/javascript" src="js/myDivPopupImage.js"></script>
<script type="text/javascript">
var tselection = false;
var tmatches = false;
var serverResponded = false;
function toggleSelections() {
tselection = !tselection;
var tableelem = document.getElementById("dlfilematrixtable");
var rowelems = tableelem.getElementsByTagName("tr");
for (var i = 2; i < rowelems.length; i++) {
if (rowelems[i].style.display !== "none") {
rowelems[i].getElementsByTagName("input")[0].checked = tselection;
}
}
}
function toggleMatches() {
tmatches = !tmatches;
var tableelem = document.getElementById("dlfilematrixtable");
var rowelems = tableelem.getElementsByTagName("tr");
for (var i = 2; i < rowelems.length; i++) {
var tdelems = rowelems[i].getElementsByTagName("td");
for (var j = 0; j < tdelems.length; j++) {
if ((tdelems[j].id === "mismatchedcell") && (tdelems[j].innerHTML > 0)) {
rowelems[i].style.display = "table-row";
break;
} else {
rowelems[i].style.display = ((tmatches) ? "none" : "table-row");
}
}
}
}
function makeHTTPrequest(event, to_server_file_url) {
if (event.preventDefault) event.preventDefault(); else event.returnValue = false; // event.preventDefault() not available in MSIE
var folderlist = Array();
var tableele = document.getElementById("dlfilematrixtable");
var roweles = tableele.getElementsByTagName("tr");
for (var i = 2; i < roweles.length; i++) {
if (roweles[i].getElementsByTagName("input")[0].checked) {
folderlist.push(roweles[i].getElementsByTagName("td")[1].innerHTML);
}
}
var str_json = "json_string=" + JSON.stringify(folderlist);
request = new XMLHttpRequest();
serverResponded = false;
request.open("POST", to_server_file_url);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded", true);
request.send(str_json);
setTimeout(function() {if (!serverResponded) alert("No Response From Server"); return false;}, 4000);
request.onreadystatechange = function() {
var tablecaption = document.getElementById("tablecaption");
switch (request.readyState) {
case 1 : tablecaption.innerHTML = "HTTP Request OPENED"; break;
case 2 : tablecaption.innerHTML = "HTTP Request HEADERS_RECEIVED"; serverResponded = true; break;
case 3 : tablecaption.innerHTML = "HTTP Request LOADING"; serverResponded = true; break;
case 4 : tablecaption.innerHTML = "HTTP Request DONE"; alert(request.responseText); serverResponded = true; break;
default: alert("Unknown Response");
}
};
}
</script>
<style type="text/css">
h2 {
font-family: tahoma,arial,helvetica,sans-serif;
font-size: 18px;
font-weight: bold;
}
.table {
display: table;
width: 80%;
background-color: #9D9248;
}
.tableRow {
display: table-row;
height: 16px;
}
.tableCell {
text-align: center;
font-size: 12px;
white-space: normal;
color: black;
border: 1px solid white;
}
.tableCell.head
{
font-weight: bold;
background-color: #86815F;
}
.auto-style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: xx-large;
color: #000000;
text-align: left;
text-decoration: none;
}
.auto-style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
color: #000000;
text-align: right;
text-decoration: none;
}
</style>
</head>
<body style="background-color: #3C391B; margin: 8px; margin-top: 2px">
<div id="outerframe" style="border: 3px solid #86815F; background-color:white; position: relative; margin:auto; width: 100%; top: 6px; left: 0px; color: #FFFFFF; visibility: visible;">
<div id="fullhead" style="display: block; margin:auto; width: 99%; height: 52px; padding-left: 0px; padding-right: 0px; padding-top: 4px; padding-bottom: 4px; color: #36341A; background-color: #86815F; visibility: visible; position: relative; top: 4px; left: 0px">
<div style="float: left; padding-left: 12px; margin-top: 12px;" >
<?php echo '<a class="auto-style4" href="' . FILE_PATH_PREFIX . 'myportal.php?userid=' . $uid . '"><strong>Bashkoff Family Web Site</strong></a>'; ?>
</div>
<div style="float: right; height: 100%; padding-right: 12px;">
<div style="height: 100%; vertical_align: bottom;">
<span class="auto-style5" style="float: right; text-align: right; position: relative; bottom: -30px;">
<?php
$fltempstr = substr(dirname(__FILE__), strrpos(dirname(__FILE__), 'gallery'));
if ($uid != 0) {
echo 'Logged in as: <a href="' . FILE_PATH_PREFIX . 'edituser.php" class="auto-style5">' . $realusername . '</a>',
' | <a href="' . FILE_PATH_PREFIX . 'myportal.php?userid=' . $uid . '" class="auto-style5">Home</a>',
' | <a href="' . FILE_PATH_PREFIX . 'index.php?logout=1" class="auto-style5">Logout</a>';
}
?>
</span>
</div>
</div>
</div>
<div id="limebar" style="margin:auto; height: 12px; width: 99%; text-align: center; padding-left: 0px; padding-right: 0px; padding-top: 0px; color: #36341A; background-color: #9D9248; visibility: visible; position: relative; top: 0px; left: 0px">
</div>
<div id="medialist-page" style="margin:auto; width: 99%; text-align: center; padding-bottom: 6px; color: #36341A; background-color: #FFFFFF; visibility: visible; position: relative; top: 0px; left: 0px">
<div id="medialist-page-border" style="border: 3px solid #9D9248; margin:auto; visibility: visible; position: relative">
<h2>Image File Upload Process</h2>
<!--************************ BEGIN = Build the input form ************************-->
<form name="dlform" action="" method="POST" onsubmit="makeHTTPrequest(event, '<?php echo FILE_MISMATCH_PAGE_URL . '?userid=' . $uid ?>')">
<input type="hidden" name="userid" value="<?php echo $uid; ?>">
<table width="400px" align="center" >
<tr>
<td class="descriptionbox wrap width25">Show Only Mismatches<br></td>
<td class="optionbox wrap width25" >
<input type="checkbox" id="displaymismatches" onclick="toggleMatches()">
</td>
</tr><tr>
<td class="descriptionbox wrap width25">Toggle Select All/None<br></td>
<td class="optionbox wrap width25">
<input type="checkbox" id="checkall" onclick="toggleSelections()">
</td>
</tr><tr>
<td class="descriptionbox wrap width25">Correct File Mismatches</td>
<td class="optionbox wrap width25">
<input type="submit" name="update" value="Submit">
</td>
</tr></table>
<?php
// ************************ END = 'Build the input form' ************************
// ************************ BEGIN = 'Print the medialist array' ************************
echo '<div align="center" style="color: black; padding-top: 10px;">';
echo '<span id="tablecaption">Total image folders found: ' . count($folderlist) . '</span><br><br>';
$i = 0;
if ($ct > 0) {
echo '<table class="table" id="dlfilematrixtable" style="cellpadding:0px; cellspacing: 0px;">',
'<tr class="tableRow">',
'<td class="head tableCell" style="width: 35px" rowspan="2">#</td>',
'<td class="head tableCell" style="width: 600px" rowspan="2">Folder Name</td>',
'<td class="head tableCell" style="width: 350px" rowspan="2">Album Name</td>',
'<td class="head tableCell" style="width: 175px;" colspan="5">Number of Images</th>',
'<td class="head tableCell" style="width: 140px;" colspan="4">Number of Mismatches</td>',
'<td class="head tableCell" style="width: 40px" rowspan="2">Select</td>',
'</tr>',
'<tr class="tableRow">',
'<td class="head tableCell" style="width: 35px">F</td>',
'<td class="head tableCell" style="width: 35px">L</td>',
'<td class="head tableCell" style="width: 35px">M</td>',
'<td class="head tableCell" style="width: 35px">S</td>',
'<td class="head tableCell" style="width: 35px">T</td>',
'<td class="head tableCell" style="width: 35px">L</td>',
'<td class="head tableCell" style="width: 35px">M</td>',
'<td class="head tableCell" style="width: 35px">S</td>',
'<td class="head tableCell" style="width: 35px">T</td>',
'</tr>';
$image_matrix = Array();
$numfiles = Array();
foreach ($folderlist as $onefile) { // Begin looping through the media
$resourcefile = str_replace('/images', '', $onefile) . '/resources/mediaGroupData/group.xml'; // Get Adode Lightroom Flash Player album description and title
if (file_exists($resourcefile)) {
$resourcedoc = new DOMDocument();
@$resourcedoc->load($resourcefile);
$albumtitle = @$resourcedoc->getElementsByTagName('groupTitle')->item(0)->nodeValue;
} else {
$albumtitle = '';
}
echo '<tr class="tableRow">'; // Open matrix row
echo '<td class="tableCell">' . ($i + 1) . '</td>';
echo '<td class="tableCell" style="text-align: left; padding-left: 4px;">' . $onefile . '</td>';
echo '<td class="tableCell" style="text-align: left; padding-left: 4px;">' . $albumtitle . '</td>';
foreach (array('full', 'large', 'medium', 'small', 'thumb') as $subfolder) { // Get the individual images in each size folder
$image_matrix[$subfolder] = array_filter(scandir($onefile . '/'. $subfolder), 'test_if_img_file'); // Just get the images from the folder
$numfiles[$subfolder] = count($image_matrix[$subfolder]);
echo '<td class="tableCell">' . $numfiles[$subfolder] . '</td>';
}
foreach (array('large', 'medium', 'small', 'thumb') as $subfolder) { // Get the individual images in each size folder
$num_files_mismatched = $numfiles['full'] - count(array_intersect($image_matrix['full'], $image_matrix[$subfolder]));
echo '<td class="tableCell" id="mismatchedcell">' . $num_files_mismatched . '</td>';
}
echo '<td class="tableCell"><input type="checkbox"></td>';
echo '</tr>'; // Close row
$i++;
} // end media loop
echo '</table><br>'; // Close table
}
echo '</div>'; // close div containing total size and file matrix
?>
</form> <!--close form containing top selector table and file matrix-->
</div> <!--close medialist-page-border div-->
</div> <!--close medialist-page div-->
</div> <!--close outerframe div-->
</body>
</html>
<?php
function test_if_img_file($flnm) {
return in_array(strtolower(pathinfo($flnm, PATHINFO_EXTENSION)), array('jpg', 'bmp', 'tiff', 'gif'));
}
?>