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
|
<?php
/**
* Customizable FAQ page
*
* webtrees: Web based Family History software
* Copyright (C) 2010 webtrees development team.
*
* Derived from PhpGedView
* Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This Page Is Valid XHTML 1.0 Transitional! > 01 September 2005
*
* @package webtrees
* @subpackage Charts
* @version $Id$
*/
define('WT_SCRIPT_NAME', 'faq.php');
require './includes/session.php';
global $WT_IMAGES, $faqs;
// -- print html header information
print_header(i18n::translate('FAQ List'));
// -- Get all of the _POST variables we're interested in
$action = safe_REQUEST($_REQUEST, 'action', WT_REGEX_UNSAFE, 'show');
$adminedit = safe_REQUEST($_REQUEST, 'adminedit', WT_REGEX_UNSAFE, WT_USER_GEDCOM_ADMIN);
$type = safe_REQUEST($_REQUEST, 'type', WT_REGEX_UNSAFE);
$oldGEDCOM = safe_REQUEST($_REQUEST, 'oldGEDCOM', WT_REGEX_UNSAFE);
$whichGEDCOM= safe_REQUEST($_REQUEST, 'whichGEDCOM', WT_REGEX_UNSAFE);
$oldOrder = safe_REQUEST($_REQUEST, 'oldOrder', WT_REGEX_UNSAFE);
$order = safe_REQUEST($_REQUEST, 'order', WT_REGEX_UNSAFE);
$header = safe_REQUEST($_POST, 'header', WT_REGEX_UNSAFE);
$body = safe_REQUEST($_POST, 'body', WT_REGEX_UNSAFE);
$pidh = safe_REQUEST($_REQUEST, 'pidh', WT_REGEX_UNSAFE);
$pidb = safe_REQUEST($_REQUEST, 'pidb', WT_REGEX_UNSAFE);
$id = safe_REQUEST($_REQUEST, 'id', WT_REGEX_UNSAFE);
// NOTE: Commit the faq data to the DB
if ($action=="commit") {
if (empty($whichGEDCOM)) $whichGEDCOM = $GEDCOM;
if (empty($oldGEDCOM)) $oldGEDCOM = $whichGEDCOM;
if (empty($order)) $order = 0;
switch ($type) {
case 'update':
$faqs = get_faq_data();
if (isset($faqs[$order]) && $order!=$oldOrder) {
// New position number is already in use: find next higher one that isn't used
while (true) {
$order++;
if (!isset($faqs[$order])) break;
if ($order==$oldOrder) break;
}
}
$header = str_replace(array('<', '>'), array('<', '>'), $header);
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=?, b_username=?, b_config=? WHERE b_id=? and b_username=? and b_location=?")
->execute(array($order, $whichGEDCOM, serialize($header), $pidh, $oldGEDCOM, 'header'));
$body = str_replace(array('<', '>'), array('<', '>'), $body);
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=?, b_username=?, b_config=? WHERE b_id=? and b_username=? and b_location=?")
->execute(array($order, $whichGEDCOM, serialize($body), $pidb, $oldGEDCOM, 'body'));
AddToChangeLog("FAQ item has been edited.<br />Header ID: ".$pidh.".<br />Body ID: ".$pidb, get_id_from_gedcom($GEDCOM));
break;
case 'delete':
WT_DB::prepare("DELETE FROM {$TBLPREFIX}blocks WHERE b_order=? AND b_name=? AND b_username=?")
->execute(array($id, 'faq', $oldGEDCOM));
AddToChangeLog("FAQ item has been deleted.<br />Header ID: ".$pidh.".<br />Body ID: ".$pidb, get_id_from_gedcom($oldGEDCOM));
break;
case 'add':
$faqs = get_faq_data();
if (isset($faqs[$order])) {
// New position number is already in use: find next higher one that isn't used
while (true) {
$order++;
if (!isset($faqs[$order])) break;
}
}
$newid = get_next_id("blocks", "b_id");
$header = str_replace(array('<', '>'), array('<', '>'), $header);
WT_DB::prepare("INSERT INTO {$TBLPREFIX}blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)")
->execute(array($newid, $whichGEDCOM, 'header', $order, 'faq', serialize($header)));
$body = str_replace(array('<', '>'), array('<', '>'), $body);
WT_DB::prepare("INSERT INTO {$TBLPREFIX}blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)")
->execute(array($newid+1, $whichGEDCOM, 'body', $order, 'faq', serialize($body)));
AddToChangeLog("FAQ item has been added.<br />Header ID: ".$newid.".<br />Body ID: ".($newid+1), get_id_from_gedcom($whichGEDCOM));
break;
case 'moveup':
$faqs = get_faq_data();
if (isset($faqs[$id-1])) {
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id, $faqs[$id-1]["header"]["pid"], 'header'));
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id, $faqs[$id-1]["body"]["pid"], 'body'));
}
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id-1, $pidh, 'header'));
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id-1, $pidb, 'body'));
AddToChangeLog("FAQ item has been moved up.<br />Header ID: ".$pidh.".<br />Body ID: ".$pidb, get_id_from_gedcom($oldGEDCOM));
break;
case 'movedown':
$faqs = get_faq_data();
if (isset($faqs[$id+1])) {
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id, $faqs[$id+1]["header"]["pid"], 'header'));
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id, $faqs[$id+1]["body"]["pid"], 'body'));
}
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id+1, $pidh, 'header'));
WT_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")
->execute(array($id+1, $pidb, 'body'));
AddToChangeLog("FAQ item has been moved down.<br />Header ID: ".$pidh.".<br />Body ID: ".$pidb, get_id_from_gedcom($GEDCOM));
break;
}
$action = "show";
}
if ($action=="add") {
$i=1;
echo '<form name="addfaq" method="post" action="faq.php">';
echo '<input type="hidden" name="action" value="commit" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="oldGEDCOM" value="" />';
echo '<input type="hidden" name="oldOrder" value="" />';
echo '<table class="center list_table ', $TEXT_DIRECTION, '">';
echo '<tr><td class="topbottombar" colspan="2">';
echo i18n::translate('Add FAQ item'), help_link('add_faq_item');
echo '</td></tr><tr><td class="descriptionbox" colspan="2">';
echo i18n::translate('FAQ Header'), help_link('add_faq_header');
echo '</td></tr><tr><td class="optionbox" colspan="2"><input type="text" name="header" size="90" tabindex="', $i++, '" /></td></tr>';
echo '<tr><td class="descriptionbox" colspan="2">';
echo i18n::translate('FAQ Body'), help_link("add_faq_body","qm","add_faq_body");
echo '</td></tr><tr><td class="optionbox" colspan="2"><textarea name="body" rows="10" cols="90" tabindex="', $i++, '"></textarea></td></tr>';
echo '<tr><td class="descriptionbox">';
echo i18n::translate('FAQ Position'), help_link('add_faq_order');
echo '</td><td class="descriptionbox">';
echo i18n::translate('FAQ Visibility'), help_link('add_faq_visibility');
echo '</td></tr><tr><td class="optionbox"><input type="text" name="order" size="3" tabindex="', $i++, '" /></td>';
echo '<td class="optionbox">';
echo '<select name="whichGEDCOM" tabindex="', $i++, '" />';
echo '<option value="*all*">', i18n::translate('ALL'), '</option>';
echo '<option value="', $GEDCOM, '" selected="selected">', $GEDCOM, '</option';
echo '</select>';
echo '</td></tr>';
echo '<tr><td class="topbottombar" colspan="2"><input type="submit" value="', i18n::translate('Save'), '" tabindex="', $i++, '" />';
echo ' <input type="button" value="', i18n::translate('Cancel'), '" onclick="window.location=\'faq.php\'"; tabindex="', $i++, '" /></td></tr>';
echo '</table>';
echo '</form>';
}
if ($action == "edit") {
if ($id == NULL) {
$error = true;
$error_message = i18n::translate('No FAQ ID has been specified !');
$action = "show";
} else {
$faqs = get_faq_data($id);
$i=1;
echo '<form name="editfaq" method="post" action="faq.php">';
echo '<input type="hidden" name="action" value="commit" />';
echo '<input type="hidden" name="type" value="update" />';
echo '<input type="hidden" name="id" value="', $id, '" />';
echo '<table class="center list_table ', $TEXT_DIRECTION, '">';
echo '<tr><td class="topbottombar" colspan="2">';
echo i18n::translate('Edit FAQ item'), help_link('edit_faq_item');
echo '</td></tr>';
foreach ($faqs as $id => $data) {
echo '<input type="hidden" name="pidh" value="', htmlspecialchars($data["header"]["pid"]), '" />';
echo '<input type="hidden" name="pidb" value="', htmlspecialchars($data["body"]["pid"]), '" />';
echo '<input type="hidden" name="oldGEDCOM" value="', htmlspecialchars($data["header"]["gedcom"]), '" />';
echo '<input type="hidden" name="oldOrder" value="', htmlspecialchars($id), '" />';
echo '<tr><td class="descriptionbox" colspan="2">';
echo i18n::translate('FAQ Header'), help_link('add_faq_header');
echo '</td></tr><tr><td class="optionbox" colspan="2"><input type="text" name="header" size="90" tabindex="', $i++, '" value="', htmlspecialchars($data["header"]["text"]), '" /></td></tr>';
echo '<tr><td class="descriptionbox" colspan="2">';
echo i18n::translate('FAQ Body'), help_link('add_faq_body');
echo '</td></tr><tr><td class="optionbox" colspan="2"><textarea name="body" rows="10" cols="90" tabindex="', $i++, '">', htmlspecialchars($data["body"]["text"]), '</textarea></td></tr>';
echo '<tr><td class="descriptionbox">';
echo i18n::translate('FAQ Position'), help_link('add_faq_order');
echo '</td><td class="descriptionbox">';
echo i18n::translate('FAQ Visibility'), help_link('add_faq_visibility');
echo '</td></tr><tr><td class="optionbox"><input type="text" name="order" size="3" tabindex="', $i++, '" value="', $id, '" /></td>';
echo '<td class="optionbox">';
echo '<select name="whichGEDCOM" tabindex="', $i++, '" />';
echo '<option value="*all*"';if ($data["header"]["gedcom"]=="*all*") echo ' selected="selected"';echo '>', i18n::translate('ALL'), '</option>';
echo '<option value="', $GEDCOM, '"';
if ($data["header"]["gedcom"]==$GEDCOM) echo ' selected="selected"';
echo '>', $GEDCOM, '</option';
echo '</select>';
echo '</td></tr>';
}
echo '<tr><td class="topbottombar" colspan="2"><input type="submit" value="', i18n::translate('Save'), '" tabindex="', $i++, '" />';
echo ' <input type="button" value="', i18n::translate('Cancel'), '" onclick=window.location="faq.php"; tabindex="', $i++, '" /></td></tr>';
echo '</table>';
echo '</form>';
}
}
if ($action == "show") {
$faqs = get_faq_data();
echo '<table class="list_table width100">';
if (count($faqs) == 0) {
if (WT_USER_GEDCOM_ADMIN) {
echo '<tr><td class="width20 list_label">';
echo '<a href="faq.php?action=add">', i18n::translate('Add FAQ item'), '</a>';
echo help_link('add_faq_item');
echo '</td></tr>';
} else {
echo '<tr><td class="error center">', i18n::translate('The FAQ list is empty.'), '</td></tr>';
}
} else {
// NOTE: Add a preview link
if (WT_USER_GEDCOM_ADMIN) {
echo '<tr>';
if ($adminedit) {
echo '<td class="descriptionbox center" colspan="2">';
echo '<a href="faq.php?action=add">', i18n::translate('Add'), '</a>';
echo help_link('add_faq_item');
echo '</td>';
}
echo '<td class="descriptionbox center" colspan="2">';
if ($adminedit) {
echo '<a href="faq.php?adminedit=0">', i18n::translate('Preview'), '</a>';
echo help_link('preview_faq_item');
} else {
echo '<a href="faq.php?adminedit=1">', i18n::translate('Edit'), '</a>';
echo help_link('restore_faq_edits');
}
echo '</td>';
if ($adminedit) {
if (isset($error)) echo '<td class="topbottombar red">', $error_message, '</td>';
else echo '<td class="topbottombar"> </td>';
}
echo '</tr>';
}
foreach($faqs as $id => $data) {
if ($data["header"] && $data["body"]) {
echo '<tr>';
// NOTE: Print the position of the current item
if ($adminedit) {
echo '<td class="descriptionbox width20 $TEXT_DIRECTION" colspan="4">';
echo i18n::translate('Position item'), ': ', $id, ', ';
if ($data["header"]["gedcom"]=="*all*") echo i18n::translate('ALL');
else echo PrintReady($data["header"]["gedcom"]);
echo '</td>';
}
// NOTE: Print the header of the current item
$header = str_replace(array('<', '>'), array('<', '>'), embed_globals($data["header"]["text"]));
echo '<td class="list_label wrap">', $header, '</td></tr>';
$body = str_replace(array('<', '>'), array('<', '>'), embed_globals($data["body"]["text"]));
echo '<tr>';
// NOTE: Print the edit options of the current item
if (WT_USER_GEDCOM_ADMIN && $adminedit) {
echo '<td class="optionbox center">';
echo '<a href="', encode_url('faq.php?action=commit&type=moveup&id='.$id.'&pidh='.$data["header"]["pid"].'&pidb='.$data["body"]["pid"]), '"><img src="', $WT_IMAGE_DIR, '/', $WT_IMAGES["uarrow"]["other"], '" border="0" alt="" /></a>';
echo help_link('moveup_faq_item');
echo '</td><td class="optionbox center">';
echo '<a href="', encode_url('faq.php?action=commit&type=movedown&id='.$id.'&pidh='.$data["header"]["pid"].'&pidb='.$data["body"]["pid"]), '"><img src="', $WT_IMAGE_DIR, '/', $WT_IMAGES["darrow"]["other"], '" border="0" alt="" /></a>';
echo help_link('movedown_faq_item');
echo '</td><td class="optionbox center">';
echo '<a href="', encode_url('faq.php?action=edit&id='.$id), '">', i18n::translate('Edit'), '</a>';
echo help_link('edit_faq_item');
echo '</td><td class="optionbox center">';
echo '<a href="', encode_url('faq.php?action=commit&type=delete&id='.$id.'&pidh='.$data["header"]["pid"].'&pidb='.$data["body"]["pid"].'&oldGEDCOM='.$data["header"]["gedcom"]), '" onclick="return confirm(\'', i18n::translate('Are you sure you want to delete this FAQ entry?'), '\');">', i18n::translate('Delete'), '</a>';
echo help_link('delete_faq_item');
echo '</td>';
}
// NOTE: Print the body text of the current item
echo '<td class="list_value_wrap">', nl2br($body), '</td></tr>';
}
}
}
echo '</table>';
}
if ($action != "show") {
?>
<script language="JavaScript" type="text/javascript">
<!--
document.<?php print $action;?>faq.header.focus();
//-->
</script>
<?php
}
print_footer();
?>
|