-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditbibleurl.php
executable file
·395 lines (328 loc) · 13.1 KB
/
editbibleurl.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<?php
// Copyright (c) Claus Tondering. E-mail: [email protected].
//
// 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 'findref.inc.php';
require_once 'csvreader.inc.php';
require_once 'dataexception.inc.php';
must_be_user();
$icons = array(
'u' => 'images/u.png',
'v' => 'images/v.png',
'd' => 'images/d.png'
);
function verifyPOST($arg) {
if (!isset($_POST[$arg]))
throw new DataException("System error: Missing POST data '$id'");
return my_escape_string(trim($_POST[$arg]));
}
class DeleteAction {
private $url;
private $type;
function __construct($urlname, $typename) {
$this->url = verifyPOST($urlname);
$this->type = verifyPOST($typename);
}
function execute() {
global $db_prefix;
exec_sql("DELETE FROM {$db_prefix}bibleurl WHERE url='$this->url' AND type='$this->type'");
}
}
class InsertAction {
private $url;
private $type;
private $refs;
private $sql;
function __construct($urlname, $typename, $refsname) {
$this->url = verifyPOST($urlname);
$this->type = verifyPOST($typename);
$this->refs = verifyPOST($refsname);
$this->refs = str_replace(utf8_encode(chr(0xa0)), ' ', $this->refs); // Replace by regular space
findref("'$this->url','$this->type'", $this->refs, $this->sql, $brefs); // $brefs is not used
if (empty($this->sql))
throw new DataException("No references found in '$this->refs'");
$this->sql = substr($this->sql,1); // Strip initial comma
}
function execute() {
global $db_prefix;
exec_sql("INSERT INTO {$db_prefix}bibleurl (bookid,chapter,verse_low,verse_high,url,type) VALUES $this->sql");
}
}
if (isset($_POST['action'])) {
try {
switch ($_POST['action']) {
case 'delete':
$deleteaction = new DeleteAction('url','type');
$deleteaction->execute();
break;
case 'update':
$deleteaction = new DeleteAction('oldurl','oldtype');
$insertaction = new InsertAction('url','type','refs');
$deleteaction->execute();
$insertaction->execute();
break;
case 'add':
$insertaction = new InsertAction('url','type','refs');
$insertaction->execute();
break;
}
}
catch (DataException $e) {
$error_post = $e->getMessage();
}
}
function iconstring($type) {
global $icons;
if (array_key_exists($type,$icons))
return sprintf('<img src="%s" alt="%s" />', $icons[$type], $type);
else
return $type;
}
$allurls = array();
$res = exec_sql("SELECT DISTINCT url,type FROM {$db_prefix}bibleurl ORDER BY url");
while ($row = mysqli_fetch_object($res)) {
$allurls[] = $row;
assert(strlen($row->type)==1);
}
$allrefs = array();
foreach ($allurls as $url) {
$res = exec_sql("SELECT internal,chapter,verse_low FROM {$db_prefix}bibleurl, {$db_prefix}biblebooks as bb "
. "WHERE url='$url->url' AND type='$url->type' AND bookid=bb.id "
. "ORDER BY bookid,chapter,verse_low");
$values = array();
while ($row = mysqli_fetch_object($res))
$values[] = str_replace(' ', ' ', toEnglish($row->internal, $row->chapter, $row->verse_low)); // Use to prevent line breaks in references
$allrefs[$url->type . $url->url] = implode('; ', $values);
}
?>
<?php
/////////////////////////////////////////////////////////////////////////////
// Start help text
/////////////////////////////////////////////////////////////////////////////
ob_start();
?>
<p>This feature does not relate directly to the picture database. It is used by PLOTLearner to
assign hyperlinks to specific Bible verses.</p>
<p>The system maintains a set of URLs and associated icons and Bible verses. The icons can be used
to identify the URL type. For example, a “V” icon identifies a video clip, a
“D” icon identifies a document, and a “U” icon identifies a generic URL
(that is, anything that does not fit into the other categories).</p>
<p>Use this page to add, edit, or delete the URLs and icons associated with specific Bible
verses.</p>
<p>The Bible verses should be written in the format “Gen. 3:8” to identify
Genesis chapter 3 verse 8. 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”) is also
accepted.</p>
<?php
$doctext = ob_get_clean();
/////////////////////////////////////////////////////////////////////////////
// End help text
/////////////////////////////////////////////////////////////////////////////
?>
<?php
/////////////////////////////////////////////////////////////////////////////
// Start body text
/////////////////////////////////////////////////////////////////////////////
ob_start();
?>
<h1>Edit Bible Reference URLs </h1>
<?php if (isset($error_post)): ?>
<p class="error">Error when updating data: <?=$error_post?></p>
<?php endif; ?>
<?php if (isset($error)): ?>
<p class="error">Error: <?=$error?></p>
<?php endif; ?>
<table class="type1">
<tr><th>URL</th><th>Icon</th><th>References</th><th></th></tr>
<?php foreach ($allrefs as $ref => $bib): ?>
<?php $escapedref = htmlspecialchars(substr($ref,1)); ?>
<tr>
<td class="left"><a href="<?= $escapedref ?>" target="_blank"><?= $escapedref ?></a></td>
<td><?= iconstring($ref[0]) ?></td>
<td class="left"><?= $bib ?></td>
<td>
<!-- Note: The href="#" will normally cause the browser window to scroll to the top
when the link is pressed. By making the onclick functions return false, this is
avoided. -->
<a onclick="editVal(<?= sprintf("'%s','%s','%s'",$escapedref,$ref[0],$bib) ?>);return false;" href="#">Edit</a>
<a onclick="deleteVal(<?= sprintf("'%s','%s'",$escapedref,$ref[0]) ?>);return false;" href="#">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<p><input class="makebutton" onclick="addVal()" type="button" value="Add an item" /></p>
<!-- Dialogs for this page follow -->
<div id="dialog-update-form" style="display:none" title="Edit Bible Reference URL">
<form id="update-form" action="editbibleurl.php" method="post">
<table>
<tr>
<td>URL</td>
<td><input type="text" name="url" id="update-url" size="65" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td>Icon</td>
<td>
<?php foreach ($icons as $t => $i): ?>
<input type="radio" name="type" id="update-type-<?= $t ?>" value="<?= $t ?>" /><?= iconstring($t) ?>
<?php endforeach; ?>
</td>
</tr>
<tr>
<td>References</td>
<td><input type="text" name="refs" id="update-refs" size="65" class="text ui-widget-content ui-corner-all" /></td>
</tr>
</table>
<input type="hidden" name="oldurl" id="update-old-url" />
<input type="hidden" name="oldtype" id="update-old-type" />
<input type="hidden" name="action" value="update"/>
</form>
</div>
<div id="dialog-add-form" style="display:none" title="Add Bible Reference URL">
<form id="add-form" action="editbibleurl.php" method="post">
<table>
<tr>
<td>URL</td>
<td><input type="text" name="url" id="add-url" size="65" class="text ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td>Icon</td>
<td>
<?php foreach ($icons as $t => $i): ?>
<input type="radio" name="type" id="add-type-<?= $t ?>" value="<?= $t ?>" /><?= iconstring($t) ?>
<?php endforeach; ?>
</td>
</tr>
<tr>
<td>References</td>
<td><input type="text" name="refs" id="add-refs" size="65" class="text ui-widget-content ui-corner-all" /></td>
</tr>
</table>
<input type="hidden" name="action" value="add"/>
</form>
</div>
<div id="dialog-confirm" style="display:none" title="Delete Bible Reference URL">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
Do you want to delete these references to<br/><span id="dialog-confirm-value"></span>?
</p>
<form id="delete-form" action="editbibleurl.php" method="post">
<input type="hidden" name="url" id="delete-url" />
<input type="hidden" name="type" id="delete-type" />
<input type="hidden" name="action" value="delete"/>
</form>
</div>
<?php
$bodytext = ob_get_clean();
/////////////////////////////////////////////////////////////////////////////
// End body text
/////////////////////////////////////////////////////////////////////////////
?>
<?php
/////////////////////////////////////////////////////////////////////////////
// Start header script
/////////////////////////////////////////////////////////////////////////////
ob_start();
?>
function editVal(url,type,refs) {
$('#update-url').attr('value',url);
$('#update-type-' + type).attr('checked','checked');
$('#update-refs').attr('value',refs);
$('#update-old-url').attr('value',url);
$('#update-old-type').attr('value',type);
$('#dialog-update-form').dialog('open');
}
function addVal() {
$('#add-type-u').attr('checked','checked');
$('#dialog-add-form').dialog('open');
}
function deleteVal(url,type) {
$('#delete-url').attr('value',url);
$('#delete-type').attr('value',type);
$('#dialog-confirm-value').text(url);
$('#dialog-confirm').dialog('open');
}
$(function() {
$( '#dialog-update-form' ).dialog({
autoOpen: false,
width: 700,
modal: true,
buttons: {
'Update references': function() {
$('#update-form').submit();
$( this ).dialog( 'close' );
},
Cancel: function() {
$( this ).dialog( 'close' );
}
},
close: function() {
allFields.val( '' ).removeClass( 'ui-state-error' );
}
});
$( '#dialog-add-form' ).dialog({
autoOpen: false,
width: 700,
modal: true,
buttons: {
'Add references': function() {
$('#add-form').submit();
$( this ).dialog( 'close' );
},
Cancel: function() {
$( this ).dialog( 'close' );
}
},
close: function() {
allFields.val( '' ).removeClass( 'ui-state-error' );
}
});
$( "#dialog-confirm" ).dialog({
autoOpen: false,
resizable: false,
width: 500,
modal: true,
buttons: {
"Yes": function() {
$('#delete-form').submit();
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
});
<?php
$headerscript = ob_get_clean();
/////////////////////////////////////////////////////////////////////////////
// End header script
/////////////////////////////////////////////////////////////////////////////
?>
<?php
wrapme('Edit Bible Reference URLs',
$headerscript,
null,
$bodytext);
?>