! [Staff List plugin] Department support. Seems complete, any new issues please file ASAP. [Bug 611]
gruffen

gruffen commited on 2011-08-01 03:04:43
Showing 3 changed files, with 64 additions and 12 deletions.

... ...
@@ -35,4 +35,6 @@ $txt['shdp_staff_list_helpdesk_profile'] = 'View helpdesk profile';
35 35
 
36 36
 $txt['permissionname_shd_staff_list_view'] = 'View staff list';
37 37
 
38
+$txt['shdp_staff_list_sel_dept'] = 'Select a department...';
39
+$txt['shdp_staff_list_another_dept'] = 'View staff in another department...';
38 40
 ?>
39 41
\ No newline at end of file
... ...
@@ -17,10 +17,36 @@ function template_shd_staff_list()
17 17
 				<div class="cat_bar grid_header">
18 18
 					<h3 class="catbg">
19 19
 						<img src="', $settings['default_images_url'], '/simpledesk/staff.png" class="shd_icon_minihead" alt="" />
20
-						',$txt['shdp_staff_list_title'],'
20
+						', $txt['shdp_staff_list_title'], !empty($context['shd_dept_name']) ? ' - ' . $context['shd_dept_name'] : '', '
21 21
 					</h3>
22 22
 				</div>
23
-				<div class="description shd_no_margin shd_hide_bottom_border">
23
+				<div class="description shd_no_margin shd_hide_bottom_border">';
24
+
25
+	// Now to do the department list if that's what we're doing.
26
+	if (!empty($context['shd_department_list']))
27
+	{
28
+		echo '
29
+					<form action="', $scripturl, '?action=helpdesk;sa=stafflist" method="post">
30
+						<input type="submit" class="button_submit floatright" value="', $txt['shd_go'], '" />
31
+						<select class="floatright" name="dept">';
32
+
33
+		if (!empty($context['shd_department']))
34
+			echo '
35
+							<option value="', $context['shd_department'], '">', $txt['shdp_staff_list_another_dept'], '</option>';
36
+		else
37
+			echo '
38
+							<option value="0">', $txt['shdp_staff_list_sel_dept'], '</option>';
39
+		
40
+		foreach ($context['shd_department_list'] as $id => $dept)
41
+			echo '
42
+							<option value="', $id, '">', $dept, '</option>';
43
+
44
+		echo '
45
+						</select>
46
+					</form>';
47
+	}
48
+
49
+	echo '
24 50
 					', $txt['shdp_staff_list_welcome'], '
25 51
 				</div>
26 52
 				<table class="shd_ticketlist" cellspacing="0" width="100%">
... ...
@@ -37,11 +37,11 @@ function shd_staff_list_init(&$subactions)
37 37
 		return;
38 38
 
39 39
 	// Add the staff list button to the helpdesk navigation
40
-	$context['can_view_staff_list'] = shd_allowed_to('shd_staff_list_view');
40
+	$context['can_view_staff_list'] = shd_allowed_to('shd_staff_list_view', 0); // At least one department. Doesn't really matter too much which for this.
41 41
 	$context['navigation']['stafflist'] = array(
42 42
 		'text' => 'shdp_staff_list_title',
43 43
 		'lang' => true,
44
-		'url' => $scripturl . '?action=helpdesk;sa=stafflist',
44
+		'url' => $scripturl . '?action=helpdesk;sa=stafflist' . $context['shd_dept_link'],
45 45
 		'test' => 'can_view_staff_list'
46 46
 	);
47 47
 	
... ...
@@ -58,11 +58,11 @@ function shd_staff_list_main_menu(&$menu_buttons)
58 58
 {
59 59
 	global $context, $scripturl, $txt;
60 60
 
61
-	if (empty($modSettings['shd_hidemenu']) && isset($menu_buttons['helpdesk']))
61
+	if (empty($modSettings['shd_hidemenuitem']) && isset($menu_buttons['helpdesk']))
62 62
 		$menu_buttons['helpdesk']['sub_buttons']['staff_list'] = array(
63 63
 			'title' => $txt['shdp_staff_list_title'],
64 64
 			'href' => $scripturl . '?action=helpdesk;sa=stafflist',
65
-			'show' => SMF == 'SSI' ? false : shd_allowed_to('shd_staff_list_view')
65
+			'show' => SMF == 'SSI' ? false : shd_allowed_to('shd_staff_list_view', 0)
66 66
 		);
67 67
 }
68 68
 
... ...
@@ -71,12 +71,12 @@ function shd_staff_list()
71 71
 {
72 72
 	global $context, $txt, $modSettings, $smcFunc, $scripturl, $sourcedir, $memberContext, $settings, $options;
73 73
 	
74
-	shd_is_allowed_to('shd_staff_list_view');
74
+	shd_is_allowed_to('shd_staff_list_view', $context['shd_department']);
75 75
 
76 76
 	loadTemplate('sd_plugins_template/SDPluginStaffList');
77 77
 	$context['sub_template'] = 'shd_staff_list';
78 78
 	
79
-	$get_members = shd_members_allowed_to('shd_staff');
79
+	$get_members = shd_members_allowed_to('shd_staff', $context['shd_department']);
80 80
 	// Are site admins eligible for receiving tickets?
81 81
 	if (!empty($modSettings['shd_admins_not_assignable']))
82 82
 	{
... ...
@@ -99,12 +99,16 @@ function shd_staff_list()
99 99
 	$context['staff_members'] = array();
100 100
 	loadMemberData($get_members);
101 101
 
102
+	// Faster than evaluating it every member! Note that we explicitly don't want it on a given department, as the profile options are dept-agnostic.
103
+	$profile_view_any = shd_allowed_to('shd_view_profile_any', 0);
104
+	$profile_view_own = shd_allowed_to('shd_view_profile_own', 0);
105
+	
102 106
 	foreach ($get_members AS $member)
103 107
 	{
104 108
 		loadMemberContext($member);
105 109
 		if (!empty($modSettings['shd_helpdesk_only']) && !empty($modSettings['shd_disable_pm']))
106 110
 		{
107
-			if (shd_allowed_to('shd_view_profile_any') || ($member == $context['user']['id'] && shd_allowed_to('shd_view_profile_own')))
111
+			if ($profile_view_any || ($member == $context['user']['id'] && $profile_view_own))
108 112
 			{
109 113
 				$memberContext[$member]['online']['href'] = $scripturl . '?action=profile;u=' . $member;
110 114
 				$memberContext[$member]['online']['link'] = '<a href="' . $memberContext[$member]['online']['href'] . '">' . $memberContext[$member]['online']['text'] . '</a>';
... ...
@@ -115,7 +119,7 @@ function shd_staff_list()
115 119
 				$memberContext[$member]['online']['link'] = $memberContext[$member]['online']['text'];
116 120
 			}
117 121
 		}
118
-		$memberContext[$member]['view_hd_profile'] = shd_allowed_to('shd_view_profile_any') || ($member == $context['user']['id'] && shd_allowed_to('shd_view_profile_own'));
122
+		$memberContext[$member]['view_hd_profile'] = $profile_view_any || ($member == $context['user']['id'] && $profile_view_own);
119 123
 		$context['staff_members'][$member] = &$memberContext[$member];
120 124
 
121 125
 		// !!! Cookie Control
... ...
@@ -124,12 +128,32 @@ function shd_staff_list()
124 128
 	}
125 129
 
126 130
 	$context['page_title'] = $txt['shd_helpdesk'];
131
+
132
+	// Lastly, fetch all the other departments if that's what we're doing.
133
+	if (!empty($context['shd_multi_dept']))
134
+	{
135
+		$context['shd_department_list'] = array();
136
+		$dept_list = shd_allowed_to('access_helpdesk', false);
137
+
138
+		$query = $smcFunc['db_query']('', '
139
+			SELECT hdd.id_dept, hdd.dept_name
140
+			FROM {db_prefix}helpdesk_depts AS hdd
141
+			WHERE hdd.id_dept IN ({array_int:depts})
142
+			ORDER BY hdd.dept_order',
143
+			array(
144
+				'depts' => $dept_list,
145
+			)
146
+		);
147
+		while ($row = $smcFunc['db_fetch_assoc']($query))
148
+			$context['shd_department_list'][$row['id_dept']] = $row['dept_name'];
149
+		$smcFunc['db_free_result']($query);
150
+	}
127 151
 }
128 152
 
129 153
 // Add our custom permission to see the staff list
130 154
 function shd_staff_list_permissions()
131 155
 {
132
-	global $context, $txt, $modSettings;
156
+	global $context;
133 157
 
134 158
 	$context['shd_permissions']['permission_list']['shd_staff_list_view'] = array(false, 'general', 'staff.png');
135 159
 }
... ...
@@ -137,7 +161,7 @@ function shd_staff_list_permissions()
137 161
 // Add the permission to the role templates, too
138 162
 function shd_staff_list_roles()
139 163
 {
140
-	global $context, $txt, $modSettings;
164
+	global $context;
141 165
 
142 166
 	$context['shd_permissions']['roles'][ROLE_USER]['permissions']['shd_staff_list_view'] = ROLEPERM_ALLOW;
143 167
 	$context['shd_permissions']['roles'][ROLE_STAFF]['permissions']['shd_staff_list_view'] = ROLEPERM_ALLOW;
144 168