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

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

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


Revision 1.3 - (show annotations) (download) (as text)
Sun Oct 18 23:37:41 2009 UTC (5 weeks, 3 days ago) by salvis
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +5 -7 lines
File MIME type: text/x-php
Clean up some minor coder issues (no functional changes).
1 <?php
2 // $Id: acl.admin.inc,v 1.2 2009/01/27 01:21:22 salvis Exp $
3
4 /**
5 * @file
6 * Implementations of administration functions for the acl module.
7 */
8
9 /**
10 * Implementation of acl_edit_form().
11 */
12 function _acl_edit_form($acl_id, $label = NULL, $new_acl = FALSE) {
13 $users = array();
14 if (!$new_acl) {
15 // Ensure the ACL in question even exists.
16 if (!$acl_name = db_result(db_query("SELECT name FROM {acl} WHERE acl_id = %d", $acl_id))) {
17 return array();
18 }
19 $result = db_query("SELECT u.uid, u.name FROM {users} u LEFT JOIN {acl_user} aclu ON aclu.uid = u.uid WHERE acl_id = %d", $acl_id);
20 while ($user = db_fetch_object($result)) {
21 $users[$user->uid] = $user->name;
22 }
23 }
24 if (!isset($label)) {
25 $label = (empty($acl_name) ? $acl_id : $acl_name);
26 }
27
28 $form = array(
29 '#type' => 'fieldset',
30 '#collapsible' => TRUE,
31 '#title' => $label,
32 '#tree' => TRUE,
33 );
34
35 $form['acl_id'] = array('#type' => 'value', '#value' => $acl_id);
36
37 $form['deletions'] = array('#type' => 'checkboxes', '#options' => array()); // placeholder
38 $form['delete_button'] = array(
39 '#type' => 'button',
40 '#name' => 'acl_'. $acl_id,
41 '#value' => t('Remove Checked'),
42 '#submit' => FALSE,
43 );
44
45 $form['add'] = array(
46 '#type' => 'textfield',
47 '#title' => t('Add user'),
48 '#maxlength' => 60,
49 '#size' => 40,
50 '#autocomplete_path' => 'user/autocomplete',
51 );
52 $form['add_button'] = array(
53 '#type' => 'button',
54 '#name' => 'acl_'. $acl_id,
55 '#value' => t('Add User'),
56 '#submit' => FALSE,
57 );
58
59 $form['user_list'] = array(
60 '#type' => 'hidden',
61 '#default_value' => serialize($users),
62 );
63
64 $form['#after_build'] = array('_acl_edit_form_after_build');
65
66 return $form;
67 }
68
69 /**
70 * Process a form that had our buttons on it.
71 */
72 function _acl_edit_form_after_build($form, $form_state) {
73 // We can't use the form values because it's the entire structure
74 // and we have no clue where our values actually are. That's
75 // ok tho cause #value still works for us.
76 $user_list = unserialize($form['user_list']['#value']);
77 $button_name = 'acl_'. $form['acl_id']['#value'];
78
79 if (isset($form['#post'][$button_name]) && $form['#post'][$button_name] == $form['delete_button']['#value']) {
80 $deletions = $form['deletions']['#value'];
81 foreach ($deletions as $uid) {
82 unset($user_list[$uid]);
83 unset($form['deletions']['#value'][$uid]);
84 }
85 }
86 elseif (isset($form['#post'][$button_name]) && $form['#post'][$button_name] == $form['add_button']['#value']) {
87
88 $user = db_fetch_object(db_query("SELECT uid, name FROM {users} WHERE name = '%s'", $form['add']['#value']));
89 if (!$user || !$user->uid) {
90 form_error($form['add'], t("Invalid user specified."));
91 }
92 else {
93 $user_list[$user->uid] = $user->name;
94 $form['add']['#value'] = NULL;
95 }
96 }
97
98 if (count($user_list) != 0) {
99 $form['deletions']['#type'] = 'checkboxes';
100 $form['deletions']['#title'] = t("Current users");
101 $form['deletions']['#options'] = $user_list;
102 $form['deletions']['#value'] = array(); // don't carry value through.
103 $form['deletions'] = form_builder(!empty($form['#post']) ? $form['#post']['form_id'] : 'acl_form', $form['deletions'], $form_state);
104 }
105 else {
106 $form['delete_button']['#type'] = 'value';
107 }
108 $form['user_list']['#value'] = serialize($user_list);
109
110 return $form;
111 }
112
113 /**
114 * Write the results of a form.
115 *
116 * The module that embedded our form must call this function!
117 */
118 function acl_save_form($form, $priority = NULL) {
119 $users = unserialize($form['user_list']);
120 db_query('DELETE FROM {acl_user} WHERE acl_id = %d', $form['acl_id']);
121 foreach ($users as $uid => $name) {
122 db_query('INSERT INTO {acl_user} (acl_id, uid) VALUES (%d, %d)', $form['acl_id'], $uid);
123 }
124 if (isset($priority)) {
125 db_query('UPDATE {acl_node} SET priority = %d where acl_id = %d', $priority, $form['acl_id']);
126 }
127 }
128

  ViewVC Help
Powered by ViewVC 1.1.2