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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
<?php
// Classes and libraries for module system
//
// webtrees: Web based Family History software
// Copyright (C) 2014 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2010 John Finlay
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class stories_WT_Module extends WT_Module implements WT_Module_Block, WT_Module_Tab, WT_Module_Config, WT_Module_Menu {
// Extend class WT_Module
public function getTitle() {
return /* I18N: Name of a module */ WT_I18N::translate('Stories');
}
// Extend class WT_Module
public function getDescription() {
return /* I18N: Description of the “Stories” module */ WT_I18N::translate('Add narrative stories to individuals in the family tree.');
}
// Extend WT_Module
public function modAction($mod_action) {
switch($mod_action) {
case 'admin_edit':
$this->edit();
break;
case 'admin_delete':
$this->delete();
$this->config();
break;
case 'admin_config':
$this->config();
break;
case 'show_list':
$this->show_list();
break;
default:
header('HTTP/1.0 404 Not Found');
}
}
// Implement WT_Module_Config
public function getConfigLink() {
return 'module.php?mod='.$this->getName().'&mod_action=admin_config';
}
// Implement class WT_Module_Block
public function getBlock($block_id, $template=true, $cfg=null) {
}
// Implement class WT_Module_Block
public function loadAjax() {
return false;
}
// Implement class WT_Module_Block
public function isUserBlock() {
return false;
}
// Implement class WT_Module_Block
public function isGedcomBlock() {
return false;
}
// Implement class WT_Module_Block
public function configureBlock($block_id) {
}
// Implement class WT_Module_Tab
public function defaultTabOrder() {
return 55;
}
// Implement class WT_Module_Tab
public function getTabContent() {
global $controller;
$block_ids=
WT_DB::prepare(
"SELECT block_id".
" FROM `##block`".
" WHERE module_name=?".
" AND xref=?".
" AND gedcom_id=?"
)->execute(array(
$this->getName(),
$controller->record->getXref(),
WT_GED_ID
))->fetchOneColumn();
$html='';
foreach ($block_ids as $block_id) {
// Only show this block for certain languages
$languages=get_block_setting($block_id, 'languages');
if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
$html.='<div class="story_title descriptionbox center rela">'.get_block_setting($block_id, 'title').'</div>';
$html.='<div class="story_body optionbox">'.get_block_setting($block_id, 'story_body').'</div>';
if (WT_USER_CAN_EDIT) {
$html.='<div class="story_edit"><a href="module.php?mod='.$this->getName().'&mod_action=admin_edit&block_id='.$block_id.'">';
$html.=WT_I18N::translate('Edit story').'</a></div>';
}
}
}
if (WT_USER_GEDCOM_ADMIN && !$html) {
$html.='<div class="news_title center">'.$this->getTitle().'</div>';
$html.='<div><a href="module.php?mod='.$this->getName().'&mod_action=admin_edit&xref='.$controller->record->getXref().'">';
$html.=WT_I18N::translate('Add a story').'</a></div><br>';
}
return $html;
}
// Implement class WT_Module_Tab
public function hasTabContent() {
return $this->getTabContent() <> '';
}
// Implement WT_Module_Tab
public function isGrayedOut() {
global $controller;
$count_of_stories=
WT_DB::prepare(
"SELECT COUNT(block_id)".
" FROM `##block`".
" WHERE module_name=?".
" AND xref=?".
" AND gedcom_id=?"
)->execute(array(
$this->getName(),
$controller->record->getXref(),
WT_GED_ID
))->fetchOne();
return $count_of_stories==0;
}
// Implement class WT_Module_Tab
public function canLoadAjax() {
return false;
}
// Implement class WT_Module_Tab
public function getPreLoadContent() {
return '';
}
// Action from the configuration page
private function edit() {
require_once WT_ROOT.'includes/functions/functions_edit.php';
if (WT_USER_CAN_EDIT) {
if (WT_Filter::postBool('save') && WT_Filter::checkCsrf()) {
$block_id=WT_Filter::postInteger('block_id');
if ($block_id) {
WT_DB::prepare(
"UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?"
)->execute(array(WT_Filter::postInteger('gedcom_id'), WT_Filter::post('xref', WT_REGEX_XREF), $block_id));
} else {
WT_DB::prepare(
"INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)"
)->execute(array(
WT_Filter::postInteger('gedcom_id'),
WT_Filter::post('xref', WT_REGEX_XREF),
$this->getName(),
0
));
$block_id=WT_DB::getInstance()->lastInsertId();
}
set_block_setting($block_id, 'title', WT_Filter::post('title'));
set_block_setting($block_id, 'story_body', WT_Filter::post('story_body'));
$languages=array();
foreach (WT_I18N::installed_languages() as $code=>$name) {
if (WT_Filter::postBool('lang_'.$code)) {
$languages[]=$code;
}
}
set_block_setting($block_id, 'languages', implode(',', $languages));
$this->config();
} else {
$block_id=WT_Filter::getInteger('block_id');
$controller = new WT_Controller_Page();
if ($block_id) {
$controller->setPageTitle(WT_I18N::translate('Edit story'));
$title = get_block_setting($block_id, 'title');
$story_body = get_block_setting($block_id, 'story_body');
$xref = WT_DB::prepare(
"SELECT xref FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
} else {
$controller->setPageTitle(WT_I18N::translate('Add a story'));
$title = '';
$story_body = '';
$xref = WT_Filter::get('xref', WT_REGEX_XREF);
}
$controller
->pageHeader()
->addExternalJavascript(WT_STATIC_URL . 'js/autocomplete.js')
->addInlineJavascript('autocomplete();');
if (array_key_exists('ckeditor', WT_Module::getActiveModules())) {
ckeditor_WT_Module::enableEditor($controller);
}
echo '<form name="story" method="post" action="module.php?mod=', $this->getName(), '&mod_action=admin_edit">';
echo WT_Filter::getCsrf();
echo '<input type="hidden" name="save" value="1">';
echo '<input type="hidden" name="block_id" value="', $block_id, '">';
echo '<input type="hidden" name="gedcom_id" value="', WT_GED_ID, '">';
echo '<table id="story_module">';
echo '<tr><th>';
echo WT_I18N::translate('Story title');
echo '</th></tr><tr><td><textarea name="title" rows="1" cols="90" tabindex="2">', WT_Filter::escapeHtml($title), '</textarea></td></tr>';
echo '<tr><th>';
echo WT_I18N::translate('Story');
echo '</th></tr><tr><td>';
echo '<textarea name="story_body" class="html-edit" rows="10" cols="90" tabindex="2">', WT_Filter::escapeHtml($story_body), '</textarea>';
echo '</td></tr>';
echo '</table><table id="story_module2">';
echo '<tr>';
echo '<th>', WT_I18N::translate('Individual'), '</th>';
echo '<th>', WT_I18N::translate('Show this block for which languages?'), '</th>';
echo '</tr>';
echo '<tr>';
echo '<td class="optionbox">';
echo '<input data-autocomplete-type="INDI" type="text" name="xref" id="pid" size="4" value="'.$xref.'">';
echo print_findindi_link('pid');
if ($xref) {
$person = WT_Individual::getInstance($xref);
if ($person) {
echo ' ', $person->format_list('span');
}
}
echo '</td>';
$languages = get_block_setting($block_id, 'languages');
echo '<td class="optionbox">';
echo edit_language_checkboxes('lang_', $languages);
echo '</td></tr></table>';
echo '<p><input type="submit" value="', WT_I18N::translate('save'), '" tabindex="5">';
echo '</p>';
echo '</form>';
exit;
}
} else {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
}
private function delete() {
if (WT_USER_CAN_EDIT) {
$block_id = WT_Filter::getInteger('block_id');
WT_DB::prepare(
"DELETE FROM `##block_setting` WHERE block_id=?"
)->execute(array($block_id));
WT_DB::prepare(
"DELETE FROM `##block` WHERE block_id=?"
)->execute(array($block_id));
} else {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
}
private function config() {
require_once WT_ROOT.'includes/functions/functions_edit.php';
if (WT_USER_GEDCOM_ADMIN) {
$controller = new WT_Controller_Page();
$controller
->setPageTitle($this->getTitle())
->pageHeader()
->addExternalJavascript(WT_JQUERY_DATATABLES_URL)
->addInlineJavascript('
jQuery("#story_table").dataTable({
dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
'.WT_I18N::datatablesI18N().',
autoWidth: false,
paging: true,
pagingType: "full_numbers",
lengthChange: true,
filter: true,
info: true,
jQueryUI: true,
sorting: [[0,"asc"]],
columns: [
/* 0-name */ null,
/* 1-NAME */ null,
/* 2-NAME */ { sortable:false },
/* 3-NAME */ { sortable:false }
]
});
');
$stories = WT_DB::prepare(
"SELECT block_id, xref".
" FROM `##block` b".
" WHERE module_name=?".
" AND gedcom_id=?".
" ORDER BY xref"
)->execute(array($this->getName(), WT_GED_ID))->fetchAll();
echo
'<form method="get" action="', WT_SCRIPT_NAME ,'">',
WT_I18N::translate('Family tree'), ' ',
'<input type="hidden" name="mod" value="', $this->getName(), '">',
'<input type="hidden" name="mod_action" value="admin_config">',
select_edit_control('ged', WT_Tree::getNameList(), null, WT_GEDCOM),
'<input type="submit" value="', WT_I18N::translate('show'), '">',
'</form>';
echo '<h3><a href="module.php?mod=', $this->getName(), '&mod_action=admin_edit">', WT_I18N::translate('Add a story'), '</a></h3>';
if (count($stories)>0) {
echo '<table id="story_table">';
echo '<thead><tr>
<th>', WT_I18N::translate('Story title'), '</th>
<th>', WT_I18N::translate('Individual'), '</th>
<th> </th>
<th> </th>
</tr></thead>';
}
echo '<tbody>';
foreach ($stories as $story) {
$story_title = get_block_setting($story->block_id, 'title');
$indi=WT_Individual::getInstance($story->xref);
if ($indi) {
echo '<tr><td><a href="', $indi->getHtmlUrl().'#stories">', $story_title, '</a></td>
<td><a href="', $indi->getHtmlUrl().'#stories">'.$indi->getFullName(), '</a></td>';
} else {
echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td>';
}
echo '<td><a href="module.php?mod=', $this->getName(), '&mod_action=admin_edit&block_id=', $story->block_id, '"><div class="icon-edit"> </div></a></td>
<td><a href="module.php?mod=', $this->getName(), '&mod_action=admin_delete&block_id=', $story->block_id, '" onclick="return confirm(\'', WT_I18N::translate('Are you sure you want to delete this story?'), '\');"><div class="icon-delete"> </div></a></td>
</tr>';
}
echo '</tbody></table>';
} else {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
}
private function show_list() {
global $controller;
$controller = new WT_Controller_Page();
$controller
->setPageTitle($this->getTitle())
->pageHeader()
->addExternalJavascript(WT_JQUERY_DATATABLES_URL)
->addInlineJavascript('
jQuery("#story_table").dataTable({
dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
'.WT_I18N::datatablesI18N().',
autoWidth: false,
paging: true,
pagingType: "full_numbers",
lengthChange: true,
filter: true,
info: true,
jQueryUI: true,
sorting: [[0,"asc"]],
columns: [
/* 0-name */ null,
/* 1-NAME */ null
]
});
');
$stories = WT_DB::prepare(
"SELECT block_id, xref".
" FROM `##block` b".
" WHERE module_name=?".
" AND gedcom_id=?".
" ORDER BY xref"
)->execute(array($this->getName(), WT_GED_ID))->fetchAll();
echo '<h2 class="center">', WT_I18N::translate('Stories'), '</h2>';
if (count($stories)>0) {
echo '<table id="story_table" class="width100">';
echo '<thead><tr>
<th>', WT_I18N::translate('Story title'), '</th>
<th>', WT_I18N::translate('Individual'), '</th>
</tr></thead>
<tbody>';
foreach ($stories as $story) {
$indi=WT_Individual::getInstance($story->xref);
$story_title = get_block_setting($story->block_id, 'title');
$languages=get_block_setting($story->block_id, 'languages');
if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
if ($indi) {
if ($indi->canShow()) {
echo '<tr><td><a href="'.$indi->getHtmlUrl().'#stories">'.$story_title.'</a></td><td><a href="'.$indi->getHtmlUrl().'#stories">'.$indi->getFullName().'</a></td></tr>';
}
} else {
echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>';
}
}
}
echo '</tbody></table>';
}
}
// Implement WT_Module_Menu
public function defaultMenuOrder() {
return 30;
}
// Extend class WT_Module
public function defaultAccessLevel() {
return WT_PRIV_HIDE;
}
// Implement WT_Module_Menu
public function getMenu() {
global $SEARCH_SPIDER;
if ($SEARCH_SPIDER) {
return null;
}
//-- Stories menu item
$menu = new WT_Menu($this->getTitle(), 'module.php?mod='.$this->getName().'&mod_action=show_list', 'menu-story');
return $menu;
}
}
|