summaryrefslogtreecommitdiff
path: root/module_admin.php
blob: 1e0da6567790cb8d92d96f9fcd0b8164fee9301a (plain)
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
<?php
/**
 * Module Administration User Interface.
 *
 * webtrees: Web based Family History software
 * Copyright (C) 2010 webtrees development team.
 *
 * Derived from PhpGedView
 * Copyright (C) 2002 to 2009  PGV Development Team
 *
 * 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
 *
 * @package webtrees
 * @subpackage Module
 * @version $Id: admin.php 5151 2009-03-04 18:51:04Z canajun2eh $
 */

define('WT_SCRIPT_NAME', 'module_admin.php');

require_once 'includes/session.php';
require_once WT_ROOT.'includes/classes/class_module.php';


if (!WT_USER_GEDCOM_ADMIN) {
	header("Location: login.php?url=module_admin.php");
	exit;
}

function write_access_option_numeric($checkVar) {
	echo "<option value=\"".WT_PRIV_PUBLIC."\"";
	echo ($checkVar==WT_PRIV_PUBLIC) ? " selected=\"selected\"" : '';
	echo ">".i18n::translate('Show to public')."</option>\n";

	echo "<option value=\"".WT_PRIV_USER."\"";
	echo ($checkVar==WT_PRIV_USER) ? " selected=\"selected\"" : '';
	echo ">".i18n::translate('Show only to authenticated users')."</option>\n";

	echo "<option value=\"".WT_PRIV_NONE."\"";
	echo ($checkVar==WT_PRIV_NONE) ? " selected=\"selected\"" : '';
	echo ">".i18n::translate('Show only to admin users')."</option>\n";

	echo "<option value=\"".WT_PRIV_HIDE."\"";
	echo ($checkVar==WT_PRIV_HIDE) ? " selected=\"selected\"" : '';
	echo ">".i18n::translate('Hide even from admin users')."</option>\n";
}

$action = safe_POST('action');

if ($action=='update_mods') {
	foreach (WT_Module::getInstalledModules() as $module) {
		$module_name=$module->getName();
		foreach (get_all_gedcoms() as $ged_id=>$ged_name) {
			WT_DB::prepare("INSERT IGNORE INTO {$TBLPREFIX}module (module_name) VALUES (?)")->execute(array($module_name));

			$value = safe_POST("menuaccess-{$module_name}-{$ged_id}");
			if ($value!==null) {
				WT_DB::prepare(
					"REPLACE INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'menu', ?)"
				)->execute(array($module_name, $ged_id, $value));
			}

			$value = safe_POST("sidebaraccess-{$module_name}-{$ged_id}");
			if ($value!==null) {
				WT_DB::prepare(
					"REPLACE INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'sidebar', ?)"
				)->execute(array($module_name, $ged_id, $value));
			}

			$value = safe_POST("tabaccess-{$module_name}-{$ged_id}");
			if ($value!==null) {
				WT_DB::prepare(
					"REPLACE INTO {$TBLPREFIX}module_privacy (module_name, gedcom_id, component, access_level) VALUES (?, ?, 'tab', ?)"
				)->execute(array($module_name, $ged_id, $value));
			}
			
    }

		$value = safe_POST_integer('menuorder-'.$module_name, 1, 127, 0);
		if ($value) {
			WT_DB::prepare(
				"UPDATE {$TBLPREFIX}module SET menu_order=? WHERE module_name=?"
			)->execute(array($value, $module_name));
		}

		$value = safe_POST_integer('taborder-'.$module_name, 1, 127, 0);
		if ($value) {
			WT_DB::prepare(
				"UPDATE {$TBLPREFIX}module SET tab_order=? WHERE module_name=?"
			)->execute(array($value, $module_name));
		}

		$value = safe_POST_integer('sidebarorder-'.$module_name, 1, 127, 0);
		if ($value) {
			WT_DB::prepare(
				"UPDATE {$TBLPREFIX}module SET sidebar_order=? WHERE module_name=?"
			)->execute(array($value, $module_name));
		}
  }
}

print_header(i18n::translate('Module Administration'));
?>
<style type="text/css">
<!--
.sortme {
	cursor: move;
}
.sortme img {
	cursor: pointer;
}
//-->
</style>
<script type="text/javascript">
//<![CDATA[
           
  function reindexMods(id) {
	  jQuery('#'+id+' input').each(
	  	function (index, value) {
	    	value.value = index+1;
	  	});
  }
  
  jQuery(document).ready(function(){
	//-- tabs
    jQuery("#tabs").tabs();

    //-- sortable menus and tabs tables
    jQuery("#menus_table, #tabs_table, #sidebars_table").sortable({items: '.sortme', forceHelperSize: true, forcePlaceholderSize: true, opacity: 0.7, cursor: 'move', axis: 'y'});

    //-- update the order numbers after drag-n-drop sorting is complete
    jQuery('#menus_table').bind('sortupdate', function(event, ui) {
			var id = jQuery(this).attr('id');
			reindexMods(id);  		
  	  });

    jQuery('#tabs_table').bind('sortupdate', function(event, ui) {
		var id = jQuery(this).attr('id');
		reindexMods(id);  		
	  });

    jQuery('#sidebars_table').bind('sortupdate', function(event, ui) {
		var id = jQuery(this).attr('id');
		reindexMods(id);  		
	  });
    
    //-- enable the arrows buttons
    jQuery(".uarrow").click(function() {
        var curr = jQuery(this).parent().parent().get(0);
        var prev = jQuery(curr).prev();
        if (prev) jQuery(prev).insertAfter(curr);
        reindexMods('menus_table');
        reindexMods('tabs_table');
        reindexMods('sidebars_table');
    });

    jQuery(".udarrow").click(function() {
        var curr = jQuery(this).parent().parent().get(0);
        var prev = jQuery(curr).parent().children().get(0);
        if (prev) jQuery(curr).insertBefore(prev);
        reindexMods('menus_table');
        reindexMods('tabs_table');
        reindexMods('sidebars_table');
    });

    jQuery(".darrow").click(function() {
        var curr = jQuery(this).parent().parent().get(0);
        var next = jQuery(curr).next();
        if (next) jQuery(next).insertBefore(curr);
        reindexMods('menus_table');
        reindexMods('tabs_table');
        reindexMods('sidebars_table');
    });

    jQuery(".ddarrow").click(function() {
	    var curr = jQuery(this).parent().parent().get(0);
	    var prev = jQuery(curr).parent().children(":last").get(0);
	    if (prev) jQuery(curr).insertAfter(prev);
	    reindexMods('menus_table');
	    reindexMods('tabs_table');
	    reindexMods('sidebars_table');
	});
  });
//]]>
  </script>
<div align="center">
<div class="width75">

<p><?php echo "<h2>".i18n::translate('Module Administration')."</h2>"; ?></p>
<p><?php echo i18n::translate('Below is the list of all the modules installed in this instance of webtrees.  Modules are installed by placing them in the <i>modules</i> directory.  Here you can set the access level per GEDCOM for each module.  If a module includes tabs for the individual page or menus for the menu bar, you can also set the access level and order of each of them.')?></p>
<p><input TYPE="button" VALUE="<?php echo i18n::translate('Return to Administration page');?>" onclick="javascript:window.location='admin.php'" /></p>

<form method="post" action="module_admin.php"> 
	<input type="hidden" name="action" value="update_mods" />

<div id="tabs">
<ul>
	<li><a href="#installed_tab"><span><?php echo i18n::translate('Installed Modules')?></span></a></li>
	<li><a href="#menus_tab"><span><?php echo i18n::translate('Manage Menus')?></span></a></li>
	<li><a href="#tabs_tab"><span><?php echo i18n::translate('Manage Tabs')?></span></a></li>
	<li><a href="#sidebars_tab"><span><?php echo i18n::translate('Manage Sidebars')?></span></a></li>
</ul>
<div id="installed_tab">
<!-- installed -->
  <table id="installed_table" class="list_table">
    <thead>
      <tr>
      <th class="list_label"><?php echo i18n::translate('Enabled')?></th>
      <th class="list_label"><?php echo i18n::translate('Configuration')?></th>
      <th class="list_label"><?php echo i18n::translate('Module Name')?></th>
      <th class="list_label"><?php echo i18n::translate('Description')?></th>
      <th class="list_label"><?php echo i18n::translate('Tab')?></th>
      <th class="list_label"><?php echo i18n::translate('Menu')?></th>
      <th class="list_label"><?php echo i18n::translate('Sidebar')?></th>
      </tr>
    </thead>
    <tbody>
<?php
foreach (WT_Module::getInstalledModules() as $module) {
	?><tr>
	<td class="list_value"><?php if (true) echo i18n::translate('Yes'); else echo i18n::translate('No'); ?></td>
	<td class="list_value"><?php if ($module instanceof WT_Module_Config) echo '<a href="', $module->getConfigLink(), '"><img class="adminicon" src="', $WT_IMAGE_DIR, '/', $WT_IMAGES["admin"]["small"], '" border="0" alt="', $module->getName(), '" /></a>'; ?></td>
	<td class="list_value"><?php echo $module->getTitle()?></td>
	<td class="list_value_wrap"><?php echo $module->getDescription()?></td>
	<td class="list_value"><?php if ($module instanceof WT_Module_Tab) echo i18n::translate('Yes'); else echo i18n::translate('No');?></td>
	<td class="list_value"><?php if ($module instanceof WT_Module_Menu) echo i18n::translate('Yes'); else echo i18n::translate('No');?></td>
	<td class="list_value"><?php if ($module instanceof WT_Module_Sidebar) echo i18n::translate('Yes'); else echo i18n::translate('No');?></td>
	</tr>
	<?php 
}
?>
    </tbody>
  </table>
</div>
<div id="menus_tab">
<!-- menus -->
<table id="menus_table" class="list_table">
    <thead>
      <tr>
      <th class="list_label"><?php echo i18n::translate('Module Name')?></th>
      <th class="list_label"><?php echo i18n::translate('Order')?></th>
      <th class="list_label"><?php echo i18n::translate('Access Level')?></th>
      </tr>
    </thead>
    <tbody>
<?php
$order = 1;
foreach(WT_Module::getInstalledMenus() as $module) {
	?><tr class="sortme">
	<td class="list_value"><?php echo $module->getTitle()?></td>
	<td class="list_value"><input type="text" size="5" value="<?php echo $order; ?>" name="menuorder-<?php echo $module->getName() ?>" />
		<br />
		<img class="uarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["uarrow"]["other"];?>" border="0" title="move up" />
		<img class="udarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["udarrow"]["other"];?>" border="0" title="move to top" />
		<img class="darrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["darrow"]["other"];?>" border="0" title="move down" />
		<img class="ddarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["ddarrow"]["other"];?>" border="0" title="move to bottom" />
	</td>
	<td class="list_value_wrap">
	  <table>
	<?php
		foreach (get_all_gedcoms() as $ged_id=>$ged_name) {
			$varname = 'menuaccess-'.$module->getName().'-'.$ged_id;
			$access_level=WT_DB::prepare(
				"SELECT access_level FROM {$TBLPREFIX}module_privacy WHERE gedcom_id=? AND module_name=? AND component='menu'"
			)->execute(array($ged_id, $module->getName()))->fetchOne();
			?>
			<tr><td><?php echo $ged_name ?></td><td>
			<select id="<?php echo $varname?>" name="<?php echo $varname?>">
				<?php write_access_option_numeric($access_level) ?>
			</select></td></tr>
			<?php 
		} 
	?>
	  </table>
	</td>
	</tr>
	<?php
$order++; 
}
?>
    </tbody>
  </table>
</div>
<div id="tabs_tab">
<!-- tabs -->
<table id="tabs_table" class="list_table">
    <thead>
      <tr>
      <th class="list_label"><?php echo i18n::translate('Module Name')?></th>
      <th class="list_label"><?php echo i18n::translate('Order')?></th>
      <th class="list_label"><?php echo i18n::translate('Access Level')?></th>
      </tr>
    </thead>
    <tbody>
<?php
$order = 1;
foreach(WT_Module::getInstalledTabs() as $module) {
	?><tr class="sortme">
	<td class="list_value"><?php echo $module->getTitle()?></td>
	<td class="list_value"><input type="text" size="5" value="<?php echo $order; ?>" name="taborder-<?php echo $module->getName() ?>" />
		<br />
		<img class="uarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["uarrow"]["other"];?>" border="0" title="move up" />
		<img class="udarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["udarrow"]["other"];?>" border="0" title="move to top" />
		<img class="darrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["darrow"]["other"];?>" border="0" title="move down" />
		<img class="ddarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["ddarrow"]["other"];?>" border="0" title="move to bottom" />
	</td>
	<td class="list_value_wrap">
	<table>
	<?php
		foreach (get_all_gedcoms() as $ged_id=>$ged_name) {
			$varname = 'tabaccess-'.$module->getName().'-'.$ged_id;
			$access_level=WT_DB::prepare(
				"SELECT access_level FROM {$TBLPREFIX}module_privacy WHERE gedcom_id=? AND module_name=? AND component='tab'"
			)->execute(array($ged_id, $module->getName()))->fetchOne();
			?>
			<tr><td><?php echo $ged_name ?></td><td>
			<select id="<?php echo $varname?>" name="<?php echo $varname?>">
				<?php write_access_option_numeric($access_level) ?>
			</select></td></tr>
			<?php 
		} 
	?>
	</table>
	</td>
	</tr>
	<?php
$order++; 
}
?>
    </tbody>
  </table>
</div>
<div id="sidebars_tab">
<!-- sidebars -->
<table id="sidebars_table" class="list_table">
    <thead>
      <tr>
      <th class="list_label"><?php echo i18n::translate('Module Name')?></th>
      <th class="list_label"><?php echo i18n::translate('Order')?></th>
      <th class="list_label"><?php echo i18n::translate('Access Level')?></th>
      </tr>
    </thead>
    <tbody>
<?php
$order = 1;
foreach(WT_Module::getInstalledSidebars() as $module) {
	?><tr class="sortme">
	<td class="list_value"><?php echo $module->getTitle()?></td>
	<td class="list_value"><input type="text" size="5" value="<?php echo $order; ?>" name="sidebarorder-<?php echo $module->getName() ?>" />
		<br />
		<img class="uarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["uarrow"]["other"];?>" border="0" title="move up" />
		<img class="udarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["udarrow"]["other"];?>" border="0" title="move to top" />
		<img class="darrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["darrow"]["other"];?>" border="0" title="move down" />
		<img class="ddarrow" src="<?php echo $WT_IMAGE_DIR."/".$WT_IMAGES["ddarrow"]["other"];?>" border="0" title="move to bottom" />
	</td>
	<td class="list_value_wrap">
	<table>
	<?php
		foreach (get_all_gedcoms() as $ged_id=>$ged_name) {
			$varname = 'sidebaraccess-'.$module->getName().'-'.$ged_id;
			$access_level=WT_DB::prepare(
				"SELECT access_level FROM {$TBLPREFIX}module_privacy WHERE gedcom_id=? AND module_name=? AND component='sidebar'"
			)->execute(array($ged_id, $module->getName()))->fetchOne();
			?>
			<tr><td><?php echo $ged_name ?></td><td>
			<select id="<?php echo $varname?>" name="<?php echo $varname?>">
				<?php write_access_option_numeric($access_level) ?>
			</select></td></tr>
			<?php 
		} 
	?>
	</table>
	</td>
	</tr>
	<?php
$order++; 
}
?>
    </tbody>
  </table>
</div>
<input type="submit" value="<?php echo i18n::translate('Save')?>" />
</div>
</form>
</div>
</div>
<?php
print_footer();
?>