This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_readonly.module
70 lines (63 loc) · 2.25 KB
/
user_readonly.module
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
<?php
/**
* Implementation of hook_form_alter().
*/
function user_readonly_form_alter(&$form, $form_state, $form_id) {
global $user;
$readonly_list = variable_get('user_readonly_list', array());
if (array_key_exists($user->uid, $readonly_list)) {
$form['#validate'][] = 'user_readonly_form_validate';
}
return $form;
}
/**
* Implementation of hook_form_FORM_ID_validate().
*/
function user_readonly_form_validate(&$form, $form_state) {
form_set_error('readonlymode', t("You are not allowed to change any data."));
}
function user_readonly_settings() {
if (function_exists("jquery_ui_get_version")) {
$ver = jquery_ui_get_version();
if (strstr($ver, '1.7.')) {
drupal_add_css(drupal_get_path('module', 'jquery_ui') . '/jquery.ui/themes/base/ui.all.css');
drupal_add_css(drupal_get_path('module', 'user_readonly') . '/css/ui.multiselect.css');
jquery_ui_add('ui.sortable');
drupal_add_js(drupal_get_path('module', 'user_readonly') . '/js/ui.multiselect.js');
drupal_add_js('$(document).ready(function (context) {
$(".multiselect").multiselect();
});', 'inline');
}
}
$choice = new stdClass();
$choice->option = array(0 => t('Anonymous'));
$options[] = $choice;
$result = db_query('SELECT uid, name FROM {users} WHERE uid > 1');
while ($user = db_fetch_array($result)) {
$choice = new stdClass();
$choice->option = array($user['uid'] => $user['name']);
$options[] = $choice;
}
$form['user_readonly_list'] = array(
'#attributes' => array('class' => 'multiselect'),
'#type' => 'select',
'#title' => t('Read-only users'),
'#default_value' => variable_get('user_readonly_list', array()),
'#options' => $options,
'#size' => 20,
'#multiple' => TRUE,
'#description' => t('Select which users have read-only access.'),
);
return system_settings_form($form);
}
function user_readonly_menu() {
$items['admin/user/user_readonly'] = array(
'title' => 'ReadOnly user',
'description' => t('Select which users have read-only access.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('user_readonly_settings'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}