/[drupal]/contributions/modules/simple_access/simple_access.admin.inc
ViewVC logotype

Contents of /contributions/modules/simple_access/simple_access.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Tue Nov 3 12:33:09 2009 UTC (3 weeks, 3 days ago) by gordon
Branch: MAIN
CVS Tags: DRUPAL-7--2-0-ALPHA1, HEAD
Changes since 1.5: +9 -4 lines
File MIME type: text/x-php
* Fix up the profiles administration section
1 <?php
2 // $Id: simple_access.admin.inc,v 1.5 2009/11/02 03:55:41 gordon Exp $
3
4 /**
5 * @file
6 * House all the admin functions in inc to make the foot print a lot
7 * smaller.
8 */
9
10 function simple_access_page_overview() {
11 if (count($groups = simple_access_get_groups())) {
12 drupal_set_title(t('Access groups'));
13 $roles = user_roles();
14 $form['groups'] = array(
15 '#tree' => TRUE,
16 '#theme' => 'simple_access_page_overview_list',
17 );
18 foreach ($groups as $group) {
19 $gid = $group['gid'];
20 $form['groups'][$gid]['name'] = array(
21 '#markup' => $group['name'],
22 );
23 $r = array();
24 foreach ($group['roles'] as $rid) {
25 $r[] = $roles[$rid];
26 }
27 $form['groups'][$gid]['roles'] = array(
28 '#markup' => implode(', ', $r),
29 );
30 $form['groups'][$gid]['weight'] = array(
31 '#type' => 'weight',
32 '#default_value' => $group['weight'],
33 '#attributes' => array('class' => array('sa-group-weight')),
34 );
35 $form['groups'][$gid]['ops'] = array(
36 '#markup' => l(t('edit'), 'admin/config/simple-access/groups/' . $gid . '/edit/') . '&nbsp;' . l(t('delete'), 'admin/config/simple-access/groups/' . $gid . '/delete'),
37 );
38 }
39 $form['submit'] = array(
40 '#type' => 'submit',
41 '#value' => t('Update'),
42 );
43 return $form;
44 }
45 else {
46 drupal_set_message(t('You have not yet defined any access groups.'));
47 drupal_goto('admin/config/simple-access/groups/add');
48 }
49 }
50
51 function simple_access_page_overview_submit($form, &$form_state) {
52 foreach ($form_state['values']['groups'] as $gid => $group) {
53 db_update('simple_access_groups')
54 ->condition('gid', $gid)
55 ->fields(array(
56 'weight' => $group['weight'],
57 ))
58 ->execute();
59 }
60 }
61
62 function simple_access_group_form(&$form, &$form_state, $group = array()) {
63 $roles = array();
64 if (!empty($group)) {
65 drupal_set_title(t('Edit Access Group'));
66 $form['gid'] = array(
67 '#type' => 'value',
68 '#value' => $group['gid'],
69 );
70 }
71 else {
72 drupal_set_title(t('Create Access Group'));
73 }
74 $group += array('name' => '', 'roles' => array(), 'weight' => 0);
75
76 $form['name'] = array(
77 '#type' => 'textfield',
78 '#title' => t('Name'),
79 '#default_value' => $group['name'],
80 '#size' => 40,
81 '#maxlength' => 80,
82 '#description' => t('The name for the access group as it will appear on the content editing form.'),
83 '#required' => TRUE,
84 );
85 $form['roles'] = array(
86 '#type' => 'checkboxes',
87 '#title' => t('Roles'),
88 '#default_value' => $group['roles'],
89 '#options' => user_roles(),
90 '#description' => t('Roles that can view'),
91 );
92 $form['weight'] = array(
93 '#type' => 'weight',
94 '#title' => 'Weight',
95 '#default_value' => $group['weight'],
96 '#delta' => 10,
97 '#description' => t('When setting permissions, heavier names will sink and lighter names will be positioned nearer the top.'),
98 );
99 $form[] = array(
100 '#type' => 'submit',
101 '#value' => t('Submit'),
102 );
103 return $form;
104 }
105
106 function simple_access_group_form_submit($form, &$form_state) {
107 simple_access_save_group($form_state['values']);
108 $form_state['redirect'] = 'admin/config/simple-access/groups';
109 }
110
111 function simple_access_delete_group_confirm($form, $form_state, $group) {
112 $form['gid'] = array(
113 '#type' => 'value',
114 '#value' => $group['gid'],
115 );
116 return confirm_form($form,
117 t('Are you sure you want to delete this group?'),
118 'admin/config/simple-access/groups',
119 t('This action cannot be undone.'), t('Delete'), t('Cancel')
120 );
121 }
122
123 function simple_access_delete_group_confirm_submit($form, &$form_state) {
124 simple_access_delete_group($form_state['values']['gid']);
125 $form_state['redirect'] = 'admin/config/simple-access/groups';
126 }
127
128 function simple_access_profile_list() {
129 $form = array();
130 $result = db_select('simple_access_profiles', 'p')
131 ->fields('p', array('pid', 'name', 'weight'))
132 ->orderBy('weight', 'ASC')
133 ->orderBy('name', 'ASC')
134 ->execute();
135
136 $profiles = $result->fetchAllAssoc('pid', PDO::FETCH_ASSOC);
137 if (empty($profiles)) {
138 drupal_set_message(t('You have not yet defined any access profiles.'));
139 drupal_goto('admin/config/simple-access/profiles/add');
140 }
141
142 $form['profiles'] = array(
143 '#tree' => TRUE,
144 );
145 foreach ($profiles as $row) {
146 $form['profiles'][$row['pid']]['name'] = array(
147 '#markup' => $row['name'],
148 );
149 $form['profiles'][$row['pid']]['weight'] = array(
150 '#type' => 'weight',
151 '#default_value' => $row['weight'],
152 '#attributes' => array('class' => array('sa-profile-weight')),
153 );
154 $form['profiles'][$row['pid']]['operations'] = array(
155 '#markup' => l(t('edit'), 'admin/config/simple-access/profiles/' . $row['pid'] . '/edit') . ' ' . l(t('delete'), 'admin/config/simple-access/profiles/' . $row['pid'] . '/delete'),
156 );
157 }
158
159 $form['submit'] = array(
160 '#type' => 'submit',
161 '#value' => t('Update'),
162 );
163
164 return $form;
165 }
166
167 function simple_access_profile_list_submit($form, $form_state) {
168 foreach ($form_state['values']['profiles'] as $pid => $profile) {
169 $profile['pid'] = $pid;
170 drupal_write_record('simple_access_profiles', $profile, array('pid'));
171 }
172 }
173
174 function simple_access_profile_form($form, $form_state, $profile = array()) {
175 $profile += array('access' => FALSE);
176
177 if (!empty($profile['pid'])) {
178 $form['pid'] = array(
179 '#type' => 'value',
180 '#value' => $profile['pid'],
181 );
182 }
183
184 $form['name'] = array(
185 '#type' => 'textfield',
186 '#title' => t('Name'),
187 '#default_value' => isset($profile['name']) ? $profile['name'] : '',
188 '#required' => TRUE,
189 );
190
191 $form['access'] = array(
192 '#tree' => TRUE,
193 '#theme' => 'simple_access_form',
194 );
195
196 $groups = simple_access_group_select();
197 foreach ($groups as $gid => $group) {
198 $form['access'][$gid] = simple_access_form_row($gid, $group, $profile['access']);
199 }
200
201 $form['submit'] = array(
202 '#type' => 'submit',
203 '#value' => empty($pid) ? t('Submit') : t('Update'),
204 );
205
206 return $form;
207 }
208
209 function simple_access_profile_form_submit($form, &$form_state) {
210 if (!empty($form_state['values']['pid'])) {
211 drupal_write_record('simple_access_profiles', $form_state['values'], array('pid'));
212 }
213 else {
214 drupal_write_record('simple_access_profiles', $form_state['values']);
215 }
216
217 db_delete('simple_access_profiles_access')
218 ->condition('pid', $form_state['values']['pid'])
219 ->execute();
220 if (isset($form_state['values']['access'])) {
221 foreach ($form_state['values']['access'] as $gid => $access) {
222 if ($access['sa_view'] || $access['sa_update'] || $access['sa_delete']) {
223 $access['pid'] = $form_state['values']['pid'];
224 $access['gid'] = $gid;
225 drupal_write_record('simple_access_profiles_access', $access);
226 }
227 }
228 }
229
230 $form_state['redirect'] = 'admin/config/simple-access/profiles';
231 }
232
233 function simple_access_settings_page() {
234 drupal_set_title(t('Simple Access Settings'));
235 $options = array(
236 'view' => t('<strong>View</strong>: Displays viewability selections at top of node form. Selected access groups will be the only users who can view the node. All unselected = normal node behavior (viewable by all).<br />'),
237 'update' => t('<strong>Edit</strong>: Displays editability selections at top of node form. Users who are part of selected access groups will be able to edit this node. All unselected = "normal" node behavior (only author and admins may edit).<br />'),
238 'delete' => t('<strong>Delete</strong>: Displays deleteability selections at top of node form. Users who are part of selected access groups will be able to delete this node. All unselected = "normal" node behavior (only author and admins may delete).<br />')
239 );
240 $form['sa_display'] = array(
241 '#type' => 'checkboxes',
242 '#title' => t('Display'),
243 '#default_value' => variable_get('sa_display', array('view')),
244 '#options' => $options,
245 '#description' => t('Which options should appear on node add/edit pages for administrators? Select at least one.'),
246 '#required' => TRUE
247 );
248 $form['sa_showgroups'] = array(
249 '#type' => 'checkbox',
250 '#title' => 'Show groups even when user is not a member.',
251 '#default_value' => variable_get('sa_showgroups', 0),
252 '#description' => 'This is useful when you want to have a user be able to make content viewable by themselves and a higher privileged group (e.g. students sharing work with faculty)',
253 );
254 return system_settings_form($form);
255 }
256
257 function simple_access_profile_delete_confirm($form, &$form_state, $profile) {
258 $form['pid'] = array(
259 '#type' => 'value',
260 '#value' => $profile['pid'],
261 );
262 return confirm_form($form,
263 t('Are you sure you want to delete this profile?'),
264 'admin/config/simple-access/profiles',
265 t('This action cannot be undone.'), t('Delete'), t('Cancel')
266 );
267 }
268
269 function simple_access_profile_delete_confirm_submit($form, &$form_state) {
270 simple_access_delete_profile($form_state['values']['pid']);
271 $form_state['redirect'] = 'admin/config/simple-access/profiles';
272 }
273

  ViewVC Help
Powered by ViewVC 1.1.2