aboutsummaryrefslogtreecommitdiff
path: root/mod/ecml/views/default/ecml/admin/ecml_admin.php
blob: 0bd7793c8c189f19a5a14963d4f109161daee396 (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
<?php
/**
 * Configs granular access
 *
 * @package ECML
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd
 * @copyright Curverider Ltd 2008-2010
 * @link http://elgg.org/
 */

$views = $vars['config']->ecml_parse_views;
$keywords = $vars['config']->ecml_keywords;
$perms = $vars['config']->ecml_permissions;

ksort($views);
ksort($keywords);

echo elgg_view_title(elgg_echo('ecml:admin:admin'));
echo '<p class="margin_top">' . elgg_echo('ecml:admin:instruction') . '</p>';

// yes I'm using a table because this is table.
$form_body = <<<___END
<table class="ecml_admin_table">
	<tr>
		<th>&nbsp</th>
___END;

foreach ($views as $view => $view_desc) {
	$form_body .= "<th><acronym class=\"ecml_view ecml_check_all\" title=\"$view\">$view_desc</acronym></th>";
	$n++;
}
$form_body .= '</tr>';

$odd = 'odd';
foreach ($keywords as $keyword => $keyword_info) {
	$keyword_desc = $keyword_info['description'];
	$form_body .= "
	<tr class=\"ecml_row_$odd\">
		<td class=\"ecml_keyword_desc\"><acronym class=\"ecml_keyword ecml_check_all\" title=\"$keyword_desc\">$keyword</acronym></td>
";
	foreach ($views as $view => $view_info) {
		// if this is restricted and we're not on the specified view don't allow changes
		// since we don't save this, no need to pass a name
		if (isset($keyword_info['restricted']) && !in_array($view, $keyword_info['restricted'])) {
			$form_body .= "<td><input type=\"checkbox\" checked=\"checked\" disabled=\"disabled\"/></td>";
		} else {
			$checked = (in_array($keyword, $perms[$view])) ? 'checked="checked"' : '';

			// ooook. input/checkboxes isn't overly useful.
			// do it ourself.
			$form_body .= "<td><input type=\"checkbox\" name=\"perms[$view][]\" value=\"$keyword\" $checked /></td>";
		}
	}
	$form_body .= '</tr>';

	$odd = ($odd == 'odd') ? 'even' : 'odd';
}

$form_body .= '</table>';
$form_body .= elgg_view('input/submit', array('value' => elgg_echo('submit')));
$form_body .= elgg_view('input/reset', array('value' => elgg_echo('reset'), 'class' => 'cancel_button'));

echo elgg_view('input/form', array(
	'body' => $form_body,
	'action' => $vars['url'] . 'action/ecml/save_permissions'
));

?>
<script type="text/javascript">

$(document).ready(function() {
	// append check all link
	$('.ecml_check_all').before('<input type="checkbox" class="check_all">');

	$('input.check_all').click(function() {
		// yoinked from
		// http://stackoverflow.com/questions/788225/table-row-and-column-number-in-jquery
		var rowIndex = $(this).parent().parent().children().index($(this).parent());
		var check = $(this).attr('checked');

		// clicked on a keyword on the left, check all boxes in the tr
		if (rowIndex == 0) {
			$(this).parent().parent().find('input').each(function() {
				if (!$(this).attr('disabled')) {
					$(this).attr('checked', check);
				}
			});
		} else {
			boxes = $('.ecml_admin_table > tbody > tr td:nth-child(' + (rowIndex + 1) + ') input[type=checkbox]');
			boxes.each(function() {
				if (!$(this).attr('disabled')) {
					$(this).attr('checked', check);
				}
			});
		}
	});
});
</script>