-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploaddesc.php
More file actions
200 lines (165 loc) · 7.33 KB
/
uploaddesc.php
File metadata and controls
200 lines (165 loc) · 7.33 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
<?php
// Copyright (c) Claus Tondering. E-mail: claus@ezer.dk.
//
// This code is distributed under an MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require_once 'wrapper.inc.php';
require_once 'html.inc.php';
require_once 'database.inc.php';
require_once 'dataexception.inc.php';
require_once 'findref.inc.php';
require_once 'csvreader.inc.php';
must_be_user();
try {
if (isset($_FILES['file'])) {
// TODO: Handle character sets. Does UTF-8 always work. fgetcvs() uses locale.
if ($_FILES['file']['error'] > 0)
throw new DataException('Upload error: ' . $_FILES['file']['error']);
$cr = new CsvReader($_FILES['file']['tmp_name']);
$inserts = 0;
$updates = 0;
$missing = array();
$allrefs = array();
while ($data = $cr->read_csv(2,2)) {
$res = exec_sql("SELECT id,filename,description FROM {$db_prefix}photos WHERE filename='{$data[0]}'");
$found = false;
while ($row = mysqli_fetch_object($res)) { // There may be both a published and an unpublish picture
$found = true;
if ($row->description!=$data[1]) {
$desc = my_escape_string($data[1]);
exec_sql("UPDATE {$db_prefix}photos SET description='$desc' WHERE id=$row->id");
if (is_null($row->description))
++$inserts;
else
++$updates;
findref($row->id, $desc, $ref_sql, $refs);
exec_sql("DELETE FROM {$db_prefix}bibleref WHERE picid=$row->id");
if (!empty($ref_sql)) {
exec_sql("INSERT INTO {$db_prefix}bibleref (bookid,chapter,verse_low,verse_high,picid) VALUES "
. substr($ref_sql,1));
$allrefs[] = array($row->filename, $refs);
}
}
}
if (!$found)
$missing[] = $data[0];
}
$cr->close();
// unlink($_FILES['file']['tmp_name']); May not be necessary
}
}
catch (DataException $e) {
$error = $e->getMessage();
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////
// Start help text
/////////////////////////////////////////////////////////////////////////////
ob_start();
?>
<p>On this page you can upload a file containing descriptions for several pictures.</p>
<p>The file must be a plain text file. If it contains non-English characters, it must be in UTF-8
encoding. The content of the file must follow these rules:</p>
<ul>
<li>There must be one picture description per line. The format must be similar to this:</li>
<li style="list-style-type:none"><pre>
183_0_2_M.jpg,"Text for the first picture"
183_0_3_M.jpg,"Text for the second picture"
183_0_4_M.jpg,"Text for the third picture"
</pre></li>
<li style="list-style-type:none">The first item on each line is a file name, the second item is the
picture description in quotation marks.</li>
<li>There must be no space between the comma and the first quotation mark.</li>
<li>The description must not contain line breaks.</li>
<li>A few HTML formatting codes can be used: <b>Bold text<b> and <i>Italic text<i>.</li>
<li>If the description is to contain a quotation mark, it must be doubled:</li>
<li style="list-style-type:none"><pre>
183_0_2_M.jpg,"This is a ""strange"" text."
</pre></li>
<li>The description may contain Bible references, using a fixed set of abbreviations (for example, “Ex. 2:9-12” – see below). In that case, the database will associate the picture with that Bible reference.</li>
</ul>
<p>The Bible references should be written in the format “Gen. 3:8-10” to identify
Genesis chapter 3 verses 8 through 10. The legal Bible book abbreviations are:</p>
<blockquote>
<p><?= str_replace( array(" ", ","),
array(" ", ", "),
implode(",",$book2EnById) ) ?></p>
</blockquote>
<p>A Danish Bible reference format (for example, “1 Mos 3,8-10”) is also
accepted.</p>
<?php
$doctext = ob_get_clean();
/////////////////////////////////////////////////////////////////////////////
// End help text
/////////////////////////////////////////////////////////////////////////////
?>
<?php
/////////////////////////////////////////////////////////////////////////////
// Start body text
/////////////////////////////////////////////////////////////////////////////
ob_start();
?>
<?php if (isset($error)): ?>
<p class="error">Error: <?=$error?></p>
<?php endif; ?>
<?php if (isset($inserts)): ?>
<p><?=$inserts?> descriptions added, <?=$updates?> descriptions updated.</p>
<?php endif; ?>
<?php if (isset($missing) && count($missing)>0): ?>
<p>Missing files:</p>
<ul>
<?php foreach ($missing as $m): ?>
<li><?=$m?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php if (isset($allrefs) && count($allrefs)>0): ?>
<p>The following Bible references were found:</p>
<table class="type1">
<tr><th>Filename</th><th>References</th></tr>
<?php foreach ($allrefs as $ref): ?>
<tr>
<td class="left"><?= $ref[0] ?></td>
<td class="left"><?= substr($ref[1],2) ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="coloredbg">
<h1>Upload new image descriptions (comma separated list)</h1>
<form action="uploaddesc.php" method="post" enctype="multipart/form-data">
<p>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br/>
<input class="makebutton" type="submit" name="submit" value="Submit" />
</p>
</form>
</div>
<?php
$bodytext = ob_get_clean();
/////////////////////////////////////////////////////////////////////////////
// End body text
/////////////////////////////////////////////////////////////////////////////
?>
<?php
wrapme('Upload Descriptions',
null,
null,
$bodytext);
?>