summaryrefslogtreecommitdiff
path: root/includes/pages/admin_free.php
blob: d5e3bd365e417903b98ccaad0da98a31c11e6e70 (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
<?php
function admin_free() {
	global $privileges;

	$search = "";
	if (isset ($_REQUEST['search']))
		$search = strip_request_item('search');

	$users = sql_select("SELECT `User`.* FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` LEFT JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID` AND `Shifts`.`start` < " . sql_escape(time()) . " AND `Shifts`.`end` > " . sql_escape(time()) . ") WHERE `User`.`Gekommen` = 1 AND `Shifts`.`SID` IS NULL GROUP BY `User`.`UID` ORDER BY `Nick`");

	$table = "";
	if ($search == "")
		$tokens = array ();
	else
		$tokens = explode(" ", $search);
	foreach ($users as $usr) {
		if (count($tokens) > 0) {
			$match = false;
			$index = join("", $usr);
			foreach ($tokens as $t)
				if (strstr($index, trim($t))) {
					$match = true;
					break;
				}
			if (!$match)
				continue;
		}
		$table .= '<tr>';
		if (in_array('user_shifts_admin', $privileges))
			$table .= '<td><a href="' . page_link_to('user_myshifts') . '&amp;id=' . $usr['UID'] . '">' . $usr['Nick'] . '</a></td>';
		else
			$table .= '<td>' . $usr['Nick'] . '</td>';
		$table .= '<td>' . $usr['DECT'] . '</td>';
		$table .= '<td>' . $usr['jabber'] . '</td>';
		if (in_array('admin_user', $privileges))
			$table .= '<td><a href="' . page_link_to('admin_user') . '&amp;id=' . $usr['UID'] . '">edit</a></td>';
		else
			$table .= '<td>' . $usr['Nick'] . '</td>';

		$table .= '</tr>';
	}
	return template_render('../templates/admin_free.html', array (
		'search' => $search,
		'table' => $table,
		'link' => page_link_to('admin_free')
	));
}
?>