forked from wooc/wooc_menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.php
900 lines (846 loc) · 30.8 KB
/
module.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
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
<?php
// webtrees - Custom menu module
//
// webtrees: Web based Family History software
// Copyright (C) 2015 £ukasz Wileñski.
//
// 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
//
namespace Wooc\WebtreesAddon\WoocMenuModule;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Controller\PageController;
use Fisharebest\Webtrees\Database;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\Functions\FunctionsEdit;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Menu;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleBlockInterface;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleMenuInterface;
use Fisharebest\Webtrees\Theme;
use Fisharebest\Webtrees\Tree;
class WoocMenuModule extends AbstractModule implements ModuleBlockInterface, ModuleConfigInterface, ModuleMenuInterface {
public function __construct() {
parent::__construct('wooc_menu');
}
// Extend class Module
public function getTitle() {
return I18N::translate('Wooc Menu');
}
public function getMenuTitle() {
return I18N::translate('Menu');
}
// Extend class Module
public function getDescription() {
return I18N::translate('Provides access to custom defined pages.');
}
// Implement Module_Menu
public function defaultMenuOrder() {
return 50;
}
// Extend class Module
public function defaultAccessLevel() {
return Auth::PRIV_NONE;
}
// Implement Module_Config
public function getConfigLink() {
return 'module.php?mod=' . $this->getName() . '&mod_action=admin_config';
}
// Implement class Module_Block
public function getBlock($block_id, $template=true, $cfg=null) {
}
// Implement class Module_Block
public function loadAjax() {
return false;
}
// Implement class Module_Block
public function isUserBlock() {
return false;
}
// Implement class Module_Block
public function isGedcomBlock() {
return false;
}
// Implement class Module_Block
public function configureBlock($block_id) {
}
// Implement Module_Menu
public function getMenu() {
global $controller, $WT_TREE;
$menu_titles = $this->getMenuList();
$lang = '';
$min_block = Database::prepare(
"SELECT MIN(block_order) FROM `##block` WHERE module_name=?"
)->execute(array($this->getName()))->fetchOne();
foreach ($menu_titles as $items) {
$languages = $this->getBlockSetting($items->block_id, 'languages');
if (in_array(WT_LOCALE, explode(',', $languages))) {
$lang = WT_LOCALE;
} else {
$lang = '';
}
}
$default_block = Database::prepare(
"SELECT ##block.block_id FROM `##block`, `##block_setting` WHERE block_order=? AND module_name=? AND ##block.block_id = ##block_setting.block_id AND ##block_setting.setting_value LIKE ?"
)->execute(array($min_block, $this->getName(), '%' . $lang . '%'))->fetchOne();
if (Auth::isSearchEngine()) {
return null;
}
$main_menu_title = $this->getSetting('MM_MENU_TITL', I18N::translate('Custom menu'));
$main_menu_address = $this->getSetting('MM_MENU_ADDR', '#');
$main_menu_icon = $this->getSetting('MM_MENU_ICON', 'menu');
$theme = WT_MODULES_DIR . $this->getName() . '/themes/' . Theme::theme()->themeId() . '/';
if (file_exists($theme)) {
echo '<link rel="stylesheet" href="' . $theme . 'style.css" type="text/css">';
$header = 'jQuery("head").append(\'<style type="text/css">li.' . $this->getName() . '{background:url(' . $theme . $main_menu_icon . '.png) no-repeat 50% 50%;} ';
} else {
echo '<link rel="stylesheet" href="' . WT_MODULES_DIR . $this->getName() . '/themes/webtrees/style.css" type="text/css">';
$header = 'jQuery("head").append(\'<style type="text/css"> ';
}
//-- main menu item
$menu = new Menu(I18N::translate($main_menu_title), $main_menu_address, $this->getName());
$menu->addClass('menuitem', 'menuitem_hover', '');
foreach ($menu_titles as $items) {
if (count($menu_titles)>1) {
$languages = $this->getBlockSetting($items->block_id, 'languages');
if ((!$languages || in_array(LOCALE, explode(',', $languages))) && $items->menu_access >= Auth::accessLevel($WT_TREE)) {
$submenu = new Menu(I18N::translate($items->menu_title), $items->menu_address, $this->getName() . '-' . $items->block_id);
$menu->addSubmenu($submenu);
$header.='li.' . $this->getName() . ' ul li.' . $this->getName() . '-' . $items->block_id . '{background:url(' . $theme . $items->menu_icon . '.png) no-repeat left 0;} ';
}
}
}
if (Auth::isAdmin()) {
$submenu = new Menu(I18N::translate('Edit menus'), $this->getConfigLink(), $this->getName() . '-edit');
$menu->addSubmenu($submenu);
}
$header .= '</style>\');';
$controller->addInlineJavascript($header);
return $menu;
}
// Extend Module
public function modAction($mod_action) {
switch($mod_action) {
case 'show':
$this->show();
break;
case 'admin_config':
if (Filter::post('action') == 'update' && Filter::checkCsrf()) {
$this->setSetting('MM_MENU_TITL', Filter::post('NEW_MM_MENU_TITL'));
$this->setSetting('MM_MENU_ADDR', Filter::post('NEW_MM_MENU_ADDR'));
$this->setSetting('MM_MENU_ICON', Filter::post('NEW_MM_MENU_ICON'));
}
$this->config();
break;
case 'admin_delete':
$this->delete();
$this->config();
break;
case 'admin_edit':
$this->edit();
break;
case 'admin_movedown':
$this->moveDown();
$this->config();
break;
case 'admin_moveup':
$this->moveUp();
$this->config();
break;
default:
http_response_code(404);
}
}
// Action from the configuration page
private function edit() {
global $WT_TREE;
if (Filter::postBool('save') && Filter::checkCsrf()) {
$block_id = Filter::post('block_id');
if ($block_id) {
Database::prepare(
"UPDATE `##block` SET gedcom_id=NULLIF(?, ''), block_order=? WHERE block_id=?"
)->execute(array(
Filter::post('gedcom_id'),
(int)Filter::post('block_order'),
$block_id
));
} else {
Database::prepare(
"INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(?, ''), ?, ?)"
)->execute(array(
Filter::post('gedcom_id'),
$this->getName(),
(int)Filter::post('block_order')
));
$block_id = Database::getInstance()->lastInsertId();
}
$this->setBlockSetting($block_id, 'menu_title', Filter::post('menu_title'));
$this->setBlockSetting($block_id, 'menu_description', Filter::post('menu_description'));
$this->setBlockSetting($block_id, 'menu_address', Filter::post('menu_address'));
$this->setBlockSetting($block_id, 'menu_icon', Filter::post('menu_icon'));
$this->setBlockSetting($block_id, 'menu_access', Filter::post('menu_access'));
$languages = array();
foreach (I18N::activeLocales() as $locale) {
if (Filter::postBool('lang_' . $locale->languageTag())) {
$languages[] = $locale->languageTag();
}
}
$this->setBlockSetting($block_id, 'languages', implode(',', $languages));
$this->config();
} else {
$block_id = Filter::get('block_id');
$controller = new PageController();
$controller->restrictAccess(Auth::isEditor($WT_TREE));
if ($block_id) {
$controller->setPageTitle(I18N::translate('Edit menu'));
$menu_title = $this->getBlockSetting($block_id, 'menu_title');
$menu_description = $this->getBlockSetting($block_id, 'menu_description');
$menu_address = $this->getBlockSetting($block_id, 'menu_address');
$menu_icon = $this->getBlockSetting($block_id, 'menu_icon');
$menu_access = $this->getBlockSetting($block_id, 'menu_access');
$block_order = Database::prepare(
"SELECT block_order FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
$gedcom_id = Database::prepare(
"SELECT gedcom_id FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
} else {
$controller->setPageTitle(I18N::translate('Add menu'));
$menu_title = '';
$menu_description = '';
$menu_icon = '';
$menu_address = '';
$menu_access = 1;
$block_order = Database::prepare(
"SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name=?"
)->execute(array($this->getName()))->fetchOne();
$gedcom_id = $WT_TREE->getTreeId();
}
$THEME_DIR = $WT_TREE->getPreference('THEME_DIR');
$header='jQuery(document).ready(function(e) {
try {jQuery("#menu_icon").ddslick({
height: 200,
imagePosition: "left",
selectText: "'.I18N::translate('Choose from %s theme icons', $THEME_DIR).'",
});}
catch(e) {alert(e.message);}
});';
$controller
->pageHeader()
->addInlineJavascript($header)
->addExternalJavascript(WT_STATIC_URL.WT_MODULES_DIR.$this->getName().'/js/jquery.ddslick.min.js');
?>
<ol class="breadcrumb small">
<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
<li><a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config"><?php echo I18N::translate($this->getTitle()); ?></a></li>
<li class="active"><?php echo $controller->getPageTitle(); ?></li>
</ol>
<form class="form-horizontal" method="POST" action="#" name="menu" id="menuForm">
<?php echo Filter::getCsrf(); ?>
<input type="hidden" name="save" value="1">
<input type="hidden" name="block_id" value="<?php echo $block_id; ?>">
<h3><?php echo I18N::translate('General'); ?></h3>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_title">
<?php echo I18N::translate('Title'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="menu_title"
size="90"
name="menu_title"
required
type="text"
value="<?php echo Filter::escapeHtml($menu_title); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Add your menu title here'); ?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_description">
<?php echo I18N::translate('Description'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="menu_description"
size="90"
name="menu_description"
required
type="text"
value="<?php echo Filter::escapeHtml($menu_description); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Add your menu description here'); ?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_address">
<?php echo I18N::translate('Menu address'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="menu_address"
size="90"
name="menu_address"
required
type="text"
value="<?php echo Filter::escapeHtml($menu_address); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Add your menu address here'); ?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_icon">
<?php echo I18N::translate('Menu icon'); ?>
</label>
<div class="col-sm-9">
<?php
$icons = array();
$rep = opendir(WT_ROOT . WT_MODULES_DIR . $this->getName() . '/themes/' . $THEME_DIR . '/');
while ($file = readdir($rep)) {
if (stristr($file, '.png')) {
$icons[] = substr($file, 0, strlen($file) - 4);
}
}
closedir($rep);
sort($icons);
echo '<select id="menu_icon" name="menu_icon" class="form-control">';
echo '<option value="other">', I18N::translate('Choose from %s theme icons', $THEME_DIR), '</option>';
foreach ($icons as $icon) {
if ($icon == '') {
$icon = '/';
}
echo '<option data-imagesrc="', WT_MODULES_DIR . $this->getName() . '/themes/' . $THEME_DIR . '/' . $icon . '.png" value="', $icon, '"';
if ($icon == $menu_icon) {
echo ' selected="selected" ';
}
echo '>', $icon, '</option>';
}
echo '</select>';
?>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Icons should be placed in the proper theme folder'); ?>
</span>
</div>
<h3><?php echo I18N::translate('Languages'); ?></h3>
<div class="form-group">
<label class="control-label col-sm-3" for="lang_*">
<?php echo I18N::translate('Show this menu for which languages?'); ?>
</label>
<div class="col-sm-9">
<?php
$accepted_languages=explode(',', $this->getBlockSetting($block_id, 'languages'));
foreach (I18N::activeLocales() as $locale) {
?>
<div class="checkbox">
<label title="<?php echo $locale->languageTag(); ?>">
<input type="checkbox" name="lang_<?php echo $locale->languageTag(); ?>" <?php echo in_array($locale->languageTag(), $accepted_languages) ? 'checked' : ''; ?> ><?php echo $locale->endonym(); ?>
</label>
</div>
<?php
}
?>
</div>
</div>
<h3><?php echo I18N::translate('Visibility and Access'); ?></h3>
<div class="form-group">
<label class="control-label col-sm-3" for="block_order">
<?php echo I18N::translate('Menu position'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="position"
name="block_order"
size="3"
required
type="number"
value="<?php echo Filter::escapeHtml($block_order); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php
echo I18N::translate('This field controls the order in which the menu items are displayed.'),
'<br><br>',
I18N::translate('You do not have to enter the numbers sequentially. If you leave holes in the numbering scheme, you can insert other menu items later. For example, if you use the numbers 1, 6, 11, 16, you can later insert menu items with the missing sequence numbers. Negative numbers and zero are allowed, and can be used to insert menu items in front of the first one.'),
'<br><br>',
I18N::translate('When more than one menu item has the same position number, only one of these menu items will be visible.');
?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="block_order">
<?php echo I18N::translate('Menu visibility'); ?>
</label>
<div class="col-sm-9">
<?php echo FunctionsEdit::selectEditControl('gedcom_id', Tree::getIdList(), I18N::translate('All'), $WT_TREE->getTreeId(), 'class="form-control"'); ?>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php
echo I18N::translate('You can determine whether this menu item will be visible regardless of family tree, or whether it will be visible only to the current family tree.');
?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_access">
<?php echo I18N::translate('Access level'); ?>
</label>
<div class="col-sm-9">
<?php echo FunctionsEdit::editFieldAccessLevel('menu_access', $menu_access, 'class="form-control"'); ?>
</div>
</div>
<div class="row col-sm-9 col-sm-offset-3">
<button class="btn btn-primary" type="submit">
<i class="fa fa-check"></i>
<?php echo I18N::translate('save'); ?>
</button>
<button class="btn" type="button" onclick="window.location='<?php echo $this->getConfigLink(); ?>';">
<i class="fa fa-close"></i>
<?php echo I18N::translate('cancel'); ?>
</button>
</div>
</form>
<?php
}
}
private function delete() {
global $WT_TREE;
if (Auth::isManager($WT_TREE)) {
$block_id = Filter::get('block_id');
Database::prepare(
"DELETE FROM `##block_setting` WHERE block_id=?"
)->execute(array($block_id));
Database::prepare(
"DELETE FROM `##block` WHERE block_id=?"
)->execute(array($block_id));
} else {
header('Location: ' . BASE_URL);
exit;
}
}
private function moveUp() {
global $WT_TREE;
if (Auth::isManager($WT_TREE)) {
$block_id = Filter::get('block_id');
$block_order = Database::prepare(
"SELECT block_order FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
$swap_block = Database::prepare(
"SELECT block_order, block_id".
" FROM `##block`".
" WHERE block_order=(".
" SELECT MAX(block_order) FROM `##block` WHERE block_order < ? AND module_name=?".
" ) AND module_name=?".
" LIMIT 1"
)->execute(array($block_order, $this->getName(), $this->getName()))->fetchOneRow();
if ($swap_block) {
Database::prepare(
"UPDATE `##block` SET block_order=? WHERE block_id=?"
)->execute(array($swap_block->block_order, $block_id));
Database::prepare(
"UPDATE `##block` SET block_order=? WHERE block_id=?"
)->execute(array($block_order, $swap_block->block_id));
}
} else {
header('Location: ' . BASE_URL);
exit;
}
}
private function moveDown() {
global $WT_TREE;
if (Auth::isManager($WT_TREE)) {
$block_id = Filter::get('block_id');
$block_order = Database::prepare(
"SELECT block_order FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
$swap_block = Database::prepare(
"SELECT block_order, block_id".
" FROM `##block`".
" WHERE block_order=(".
" SELECT MIN(block_order) FROM `##block` WHERE block_order>? AND module_name=?".
" ) AND module_name=?".
" LIMIT 1"
)->execute(array($block_order, $this->getName(), $this->getName()))->fetchOneRow();
if ($swap_block) {
Database::prepare(
"UPDATE `##block` SET block_order=? WHERE block_id=?"
)->execute(array($swap_block->block_order, $block_id));
Database::prepare(
"UPDATE `##block` SET block_order=? WHERE block_id=?"
)->execute(array($block_order, $swap_block->block_id));
}
} else {
header('Location: ' . BASE_URL);
exit;
}
}
private function config() {
global $WT_TREE;
$THEME_DIR = $WT_TREE->getPreference('THEME_DIR');
$header='jQuery(document).ready(function(e) {
try {jQuery("#menu_icon").ddslick({
height: 200,
imagePosition: "left",
selectText: "'.I18N::translate('Choose from %s theme icons', $THEME_DIR).'",
});}
catch(e) {alert(e.message);}
});';
$controller = new PageController();
$controller
->restrictAccess(Auth::isManager($WT_TREE))
->setPageTitle($this->getTitle())
->pageHeader()
->addInlineJavascript($header)
->addExternalJavascript(WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/jquery.ddslick.min.js');
$MM_MENU_TITL = $this->getSetting('MM_MENU_TITL', I18N::translate('Custom menu'));
$MM_MENU_ADDR = $this->getSetting('MM_MENU_ADDR', '');
$MM_MENU_ICON = $this->getSetting('MM_MENU_ICON', 'menu.png');
$args = array();
$args['module_name'] = $this->getName();
$args['tree_id'] = $WT_TREE->getTreeId();
$items = Database::prepare(
"SELECT block_id, block_order, gedcom_id, bs1.setting_value AS menu_title, bs2.setting_value AS menu_address, bs3.setting_value AS menu_icon".
" FROM `##block` b".
" JOIN `##block_setting` bs1 USING (block_id)".
" JOIN `##block_setting` bs2 USING (block_id)".
" JOIN `##block_setting` bs3 USING (block_id)".
" WHERE module_name = :module_name".
" AND bs1.setting_name = 'menu_title'".
" AND bs2.setting_name = 'menu_address'".
" AND bs3.setting_name = 'menu_icon'".
" AND IFNULL(gedcom_id, :tree_id) = :tree_id".
" ORDER BY block_order"
)->execute($args)->fetchAll();
unset($args['tree_id']);
$min_block_order = Database::prepare(
"SELECT MIN(block_order) FROM `##block` WHERE module_name = :module_name"
)->execute($args)->fetchOne();
$max_block_order = Database::prepare(
"SELECT MAX(block_order) FROM `##block` WHERE module_name = :module_name"
)->execute($args)->fetchOne();
?>
<style>
.text-left-not-xs, .text-left-not-sm, .text-left-not-md, .text-left-not-lg {
text-align: left;
}
.text-center-not-xs, .text-center-not-sm, .text-center-not-md, .text-center-not-lg {
text-align: center;
}
.text-right-not-xs, .text-right-not-sm, .text-right-not-md, .text-right-not-lg {
text-align: right;
}
.text-justify-not-xs, .text-justify-not-sm, .text-justify-not-md, .text-justify-not-lg {
text-align: justify;
}
@media (max-width: 767px) {
.text-left-not-xs, .text-center-not-xs, .text-right-not-xs, .text-justify-not-xs {
text-align: inherit;
}
.text-left-xs {
text-align: left;
}
.text-center-xs {
text-align: center;
}
.text-right-xs {
text-align: right;
}
.text-justify-xs {
text-align: justify;
}
}
@media (min-width: 768px) and (max-width: 991px) {
.text-left-not-sm, .text-center-not-sm, .text-right-not-sm, .text-justify-not-sm {
text-align: inherit;
}
.text-left-sm {
text-align: left;
}
.text-center-sm {
text-align: center;
}
.text-right-sm {
text-align: right;
}
.text-justify-sm {
text-align: justify;
}
}
@media (min-width: 992px) and (max-width: 1199px) {
.text-left-not-md, .text-center-not-md, .text-right-not-md, .text-justify-not-md {
text-align: inherit;
}
.text-left-md {
text-align: left;
}
.text-center-md {
text-align: center;
}
.text-right-md {
text-align: right;
}
.text-justify-md {
text-align: justify;
}
}
@media (min-width: 1200px) {
.text-left-not-lg, .text-center-not-lg, .text-right-not-lg, .text-justify-not-lg {
text-align: inherit;
}
.text-left-lg {
text-align: left;
}
.text-center-lg {
text-align: center;
}
.text-right-lg {
text-align: right;
}
.text-justify-lg {
text-align: justify;
}
}
</style>
<ol class="breadcrumb small">
<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
<li class="active"><?php echo $controller->getPageTitle(); ?></li>
</ol>
<div class="row">
<div class="col-sm-12 text-right text-left-xs col-xs-12">
<?php // TODO: Move to internal item/page
if (file_exists(WT_MODULES_DIR . $this->getName() . '/readme.html')) { ?>
<a href="<?php echo WT_MODULES_DIR . $this->getName(); ?>/readme.html" class="btn btn-info">
<i class="fa fa-newspaper-o"></i>
<?php echo I18N::translate('ReadMe'); ?>
</a>
<?php } ?>
</div>
</div>
<div class="row">
<form method="post" name="configform" action="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config" class="form">
<input type="hidden" name="action" value="update">
<div class="form-group">
<label class="control-label col-sm-3" for="NEW_MM_MENU_TITL">
<?php echo I18N::translate('Custom menu title'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="NEW_MM_MENU_TITL"
size="90"
name="NEW_MM_MENU_TITL"
required
type="text"
value="<?php echo Filter::escapeHtml($MM_MENU_TITL); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Add your menu title here'); ?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="NEW_MM_MENU_ADDR">
<?php echo I18N::translate('Custom menu address'); ?>
</label>
<div class="col-sm-9">
<input
class="form-control"
id="NEW_MM_MENU_ADDR"
size="90"
name="NEW_MM_MENU_ADDR"
required
type="text"
value="<?php echo Filter::escapeHtml($MM_MENU_ADDR); ?>"
>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Add your menu address here'); ?>
</span>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="menu_icon">
<?php echo I18N::translate('Menu icon'); ?>
</label>
<div class="col-sm-9">
<?php
$icons = array();
$rep = opendir(WT_ROOT . WT_MODULES_DIR . $this->getName() . '/themes/' . $THEME_DIR . '/');
while ($file = readdir($rep)) {
if (stristr($file, '.png')) {
$icons[] = substr($file, 0, strlen($file) - 4);
}
}
closedir($rep);
sort($icons);
echo '<select id="menu_icon" name="NEW_MM_MENU_ICON" class="form-control">';
echo '<option value="other">', I18N::translate('Choose from %s theme icons', $THEME_DIR), '</option>';
foreach ($icons as $icon) {
if ($icon == '') {
$icon = '/';
}
echo '<option data-imagesrc="', WT_MODULES_DIR . $this->getName() . '/themes/' . $THEME_DIR . '/' . $icon . '.png" value="', $icon, '"';
if ($icon == $MM_MENU_ICON) {
echo ' selected="selected" ';
}
echo '>', $icon, '</option>';
}
echo '</select>';
?>
</div>
<span class="help-block col-sm-9 col-sm-offset-3 small text-muted">
<?php echo I18N::translate('Icons should be placed in the proper theme folder'); ?>
</span>
</div>
<div class="row col-sm-9 col-sm-offset-3">
<button class="btn btn-primary" type="submit">
<i class="fa fa-check"></i>
<?php echo I18N::translate('save'); ?>
</button>
<button class="btn btn-primary" type="reset" onclick="window.location='<?php echo $this->getConfigLink(); ?>';">
<i class="fa fa-recycle"></i>
<?php echo I18N::translate('cancel'); ?>
</button>
</div>
</form>
</div>
<hr>
<div class="row" style="margin-top:15px;">
<div class="col-sm-4 col-xs-12">
<form class="form">
<label for="ged" class="sr-only">
<?php echo I18N::translate('Family tree'); ?>
</label>
<input type="hidden" name="mod" value="<?php echo $this->getName(); ?>">
<input type="hidden" name="mod_action" value="admin_config">
<div class="col-sm-9 col-xs-9" style="padding:0;">
<?php echo FunctionsEdit::selectEditControl('ged', Tree::getNameList(), null, $WT_TREE->getName(), 'class="form-control"'); ?>
</div>
<div class="col-sm-3" style="padding:3px;">
<input type="submit" class="btn btn-primary" value="<?php echo I18N::translate('show'); ?>">
</div>
</form>
</div>
<span class="visible-xs hidden-sm hidden-md hidden-lg" style="display:block;"></br></br></span>
<div class="col-sm-4 text-center text-left-xs col-xs-12">
<p>
<a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_edit" class="btn btn-primary">
<i class="fa fa-plus"></i>
<?php echo I18N::translate('Add menu item'); ?>
</a>
</p>
</div>
</div>
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th class="col-sm-2"><?php echo I18N::translate('Position'); ?></th>
<th class="col-sm-4"><?php echo I18N::translate('Menu title'); ?></th>
<th class="col-sm-4"><?php echo I18N::translate('Menu address'); ?></th>
<th class="col-sm-2" colspan=4><?php echo I18N::translate('Controls'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td>
<?php echo $item->block_order, ', ';
if ($item->gedcom_id == null) {
echo I18N::translate('All');
} else {
echo Tree::findById($item->gedcom_id)->getTitleHtml();
} ?>
</td>
<td>
<?php
if ($item->menu_icon) {
echo '<img class="icon" src="', WT_MODULES_DIR . $this->getName() . '/themes/' . $THEME_DIR . '/' . $item->menu_icon . '.png', '"/> ';
}
echo Filter::escapeHtml(I18N::translate($item->menu_title)); ?>
</td>
<td>
<?php echo Filter::escapeHtml(substr(I18N::translate($item->menu_address), 0, 1)=='<' ? I18N::translate($item->menu_address) : nl2br(I18N::translate($item->menu_address))); ?>
</td>
<td class="text-center">
<a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_edit&block_id=<?php echo $item->block_id; ?>">
<div class="icon-edit"> </div>
</a>
</td>
<td class="text-center">
<a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_moveup&block_id=<?php echo $item->block_id; ?>">
<?php
if ($item->block_order == $min_block_order) {
echo ' ';
} else {
echo '<div class="icon-uarrow"> </div>';
}
?>
</a>
</td>
<td class="text-center">
<a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_movedown&block_id=<?php echo $item->block_id; ?>">
<?php
if ($item->block_order == $max_block_order) {
echo ' ';
} else {
echo '<div class="icon-darrow"> </div>';
}
?>
</a>
</td>
<td class="text-center">
<a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_delete&block_id=<?php echo $item->block_id; ?>"
onclick="return confirm('<?php echo I18N::translate('Are you sure you want to delete this menu?'); ?>');">
<div class="icon-delete"> </div>
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
// Return the list of menus
private function getMenuList() {
global $WT_TREE;
return Database::prepare(
"SELECT block_id, bs1.setting_value AS menu_title, bs2.setting_value AS menu_access, bs3.setting_value AS menu_address, bs4.setting_value AS menu_icon".
" FROM `##block` b".
" JOIN `##block_setting` bs1 USING (block_id)".
" JOIN `##block_setting` bs2 USING (block_id)".
" JOIN `##block_setting` bs3 USING (block_id)".
" JOIN `##block_setting` bs4 USING (block_id)".
" WHERE module_name=?".
" AND bs1.setting_name='menu_title'".
" AND bs2.setting_name='menu_access'".
" AND bs3.setting_name='menu_address'".
" AND bs4.setting_name='menu_icon'".
" AND (gedcom_id IS NULL OR gedcom_id=?)".
" ORDER BY block_order"
)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
}
}
return new WoocMenuModule;