aboutsummaryrefslogtreecommitdiffstats
path: root/view/acl_selectors.php
blob: 7a69fdd5ad6c446695880c9a6163fa18881ad860 (plain) (blame)
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
<?php


function group_select($selname,$selclass,$preselected = false) {

	$o = '';

	$o .= "<select name=\"{$selname}[]\" class=\"$selclass\" multiple=\"multiple\" size=\"4\" />\r\n";

	$r = q("SELECT * FROM `group` WHERE `uid` = %d",
		$_SESSION['uid']
	);

	if(count($r)) {
		foreach($r as $rr) {
			if((is_array($preselected)) && $in_array($rr['name'], $preselected))
				$selected = " selected=\"selected\" ";
			else
				$selected = '';
			$o .= "<option value=\"{$rr['name']}\" $selected >{$rr['name']}</option>\r\n";
		}
	
	}
	$o .= "</select>\r\n";


	return $o;
}



function contact_select($selname,$selclass,$preselected = false) {

	$o = '';

	$o .= "<select name=\"{$selname}[]\" class=\"$selclass\" multiple=\"multiple\" size=\"4\" />\r\n";

	$r = q("SELECT `name` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 ",
		$_SESSION['uid']
	);

	if(count($r)) {
		foreach($r as $rr) {
			if((is_array($preselected)) && $in_array($rr['name'], $preselected))
				$selected = " selected=\"selected\" ";
			else
				$selected = '';
			$o .= "<option value=\"{$rr['name']}\" $selected >{$rr['name']}</option>\r\n";
		}
	
	}
	$o .= "</select>\r\n";


	return $o;
}


function populate_acl() {

	$o = '';

	$o .= "Allow Groups: " . group_select('group_allow','group_allow');
	$o .= "Allow Contacts: " . contact_select('contact_allow','contact_allow');
	$o .= "<br />\r\n";
	$o .= "Except Groups: " . group_select('group_deny','group_deny');
	$o .= "Except Contacts: " . contact_select('contact_deny','contact_deny');
	return $o;

}