| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The Views UI permissions module let's you set permissions to what a
|
| 7 |
* user can edit on the views edit page.
|
| 8 |
*
|
| 9 |
* @author Kristof De Jaeger - http://drupal.org/user/107403 - http://realize.be
|
| 10 |
* @version this is the drupal 5.x version
|
| 11 |
*/
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Implementation of hook_perm().
|
| 15 |
*/
|
| 16 |
|
| 17 |
function views_ui_perm_perm() {
|
| 18 |
return array('administer restricted views ui', 'restricted views ui');
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_menu().
|
| 23 |
*/
|
| 24 |
function views_ui_perm_menu($may_cache) {
|
| 25 |
$items = array();
|
| 26 |
if ($may_cache) {
|
| 27 |
$items[] = array(
|
| 28 |
'path' => 'admin/settings/views_ui_perm',
|
| 29 |
'title' => t('Views UI Permissions'),
|
| 30 |
'callback' => 'drupal_get_form',
|
| 31 |
'callback arguments' => array('views_ui_perm_settings'),
|
| 32 |
'access' => user_access('administer restricted views ui'),
|
| 33 |
'type' => MENU_NORMAL_ITEM,
|
| 34 |
);
|
| 35 |
$items[] = array(
|
| 36 |
'path' => 'admin/build/views_ui_perm',
|
| 37 |
'title' => t('Views'),
|
| 38 |
'callback' => 'views_ui_perm_views_page',
|
| 39 |
'access' => user_access('restricted views ui') && !user_access('administer views'),
|
| 40 |
'type' => MENU_NORMAL_ITEM,
|
| 41 |
);
|
| 42 |
}
|
| 43 |
/*else {
|
| 44 |
// Add view / edit tabs
|
| 45 |
//drupal_set_message(print_r($GLOBALS, true));
|
| 46 |
if (isset($GLOBALS['current_view'])) {
|
| 47 |
$view = $GLOBALS['current_view'];
|
| 48 |
drupal_set_message(print_r($view, true));
|
| 49 |
$items[] = array(
|
| 50 |
'path' => url($view->url),
|
| 51 |
'title' => t('View'),
|
| 52 |
'callback' => 'views_ui_perm_views_page',
|
| 53 |
'access' => user_access('restricted views ui') && !user_access('administer views'),
|
| 54 |
'type' => MENU_LOCAL_TASK,
|
| 55 |
);
|
| 56 |
$items[] = array(
|
| 57 |
'path' => 'admin/build/views_ui_perm/'. $view->vid,
|
| 58 |
'title' => t('Edit'),
|
| 59 |
'callback' => 'views_ui_perm_views_page',
|
| 60 |
'access' => user_access('restricted views ui') && !user_access('administer views'),
|
| 61 |
'type' => MENU_LOCAL_TASK,
|
| 62 |
);
|
| 63 |
}
|
| 64 |
}*/
|
| 65 |
return $items;
|
| 66 |
}
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Implementation of hook_form_alter().
|
| 70 |
*/
|
| 71 |
function views_ui_perm_form_alter($form_id, &$form) {
|
| 72 |
if ($form_id == 'views_edit_view' && user_access('restricted views ui') && !user_access('administer views')) {
|
| 73 |
|
| 74 |
// set a global variable, so we can use this in the
|
| 75 |
// template override, this way, we are sure we will
|
| 76 |
// be hiding the right fieldset.
|
| 77 |
$GLOBALS['views_ui_edit_page'] = 1;
|
| 78 |
|
| 79 |
// hide fields/fieldsets
|
| 80 |
$available_fields = views_ui_perm_available_fields();
|
| 81 |
$ui_permissions = variable_get('views_ui_permissions', views_ui_perm_default_values($available_fields));
|
| 82 |
foreach ($available_fields as $field) {
|
| 83 |
if ($ui_permissions[$field['name']] == '0') {
|
| 84 |
if (!is_array($field['fields']))
|
| 85 |
$form[$field['fields']]['#access'] = FALSE;
|
| 86 |
else
|
| 87 |
$form[$field['fields'][0]][$field['fields'][1]]['#access'] = FALSE;
|
| 88 |
|
| 89 |
// Create global with the fieldsets in that are renderd in views_ui with theme('fieldset');
|
| 90 |
// The complete array's access might be false now, but the fieldset is still rendered.
|
| 91 |
if ($field['fieldset'] == 1)
|
| 92 |
$GLOBALS['views_fieldsets'][] = $field['name'];
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
// special cases, if block and page checkbox are not toggled, disable complete fieldset,
|
| 97 |
// hide those two checkboxes either way, even if fieldset is ok.
|
| 98 |
if ($form['page-info']['page']['#default_value'] == '0') $form['page-info']['#access'] = FALSE;
|
| 99 |
if ($form['block-info']['block']['#default_value'] == '0') $form['block-info']['#access'] = FALSE;
|
| 100 |
$form['page-info']['page']['#access'] = FALSE;
|
| 101 |
$form['block-info']['block']['#access'] = FALSE;
|
| 102 |
|
| 103 |
// Disable delete button
|
| 104 |
$form['delete']['#access'] = FALSE;
|
| 105 |
$form['cancel']['#access'] = FALSE;
|
| 106 |
}
|
| 107 |
}
|
| 108 |
|
| 109 |
/**
|
| 110 |
* Settings callback.
|
| 111 |
*/
|
| 112 |
function views_ui_perm_settings() {
|
| 113 |
|
| 114 |
$options = views_ui_perm_available_fields();
|
| 115 |
$ui_options = array();
|
| 116 |
foreach ($options as $option) {
|
| 117 |
$ui_options[] = $option['name'];
|
| 118 |
}
|
| 119 |
$form['views_ui_permissions'] = array(
|
| 120 |
'#type' => 'checkboxes',
|
| 121 |
'#options' => drupal_map_assoc($ui_options),
|
| 122 |
'#default_value' => variable_get('views_ui_permissions', views_ui_perm_default_values($options)),
|
| 123 |
);
|
| 124 |
|
| 125 |
return system_settings_form($form);
|
| 126 |
}
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Theme settings form.
|
| 130 |
*/
|
| 131 |
function theme_views_ui_perm_settings($form) {
|
| 132 |
|
| 133 |
$i = 0;
|
| 134 |
$options = views_ui_perm_available_fields();
|
| 135 |
|
| 136 |
$output = '<div>'. t('Views UI permissions lets you restrict access to users with the <em>restricted views permissions</em> to edit certain fields in the views interface. Toggle the checkbox of any views edit field to enable access. There are a few special cases:<ul><li>If there is no page or block view, the fieldset is disabled automatically. These two checkboxes are also disabled.</li><li>Access to any other views option is also disabled (add, delete, clone, export, import and tools).</li></ul>Consult the README.txt that comes with this module because you need to override a theming function.') .'</div>';
|
| 137 |
|
| 138 |
foreach (element_children($form['views_ui_permissions']) as $key) {
|
| 139 |
if ($options[$i]['div_open']) {
|
| 140 |
$output .= '<div style="float: left; border-left:1px solid #ccc; margin-top: 10px; padding: 10px 10px 0 10px;"><h3>'. $options[$i]['div_title'] .'</h3>';
|
| 141 |
if ($options[$i]['div_help'])
|
| 142 |
$output .= $options[$i]['div_help'];
|
| 143 |
}
|
| 144 |
$output .= drupal_render($form['views_ui_permissions'][$key]);
|
| 145 |
if ($options[$i]['div_close']) {
|
| 146 |
$output .= '</div>';
|
| 147 |
}
|
| 148 |
$i++;
|
| 149 |
}
|
| 150 |
|
| 151 |
$output .= '<div style="clear: both"></div>';
|
| 152 |
$output .= drupal_render($form);
|
| 153 |
return $output;
|
| 154 |
}
|
| 155 |
|
| 156 |
/**
|
| 157 |
* Available properties in views form to alter.
|
| 158 |
*/
|
| 159 |
function views_ui_perm_available_fields() {
|
| 160 |
$available_fields = array(
|
| 161 |
// page fieldset
|
| 162 |
array('enabled' => '1', 'name' => t('Page fieldset'), 'fields' => 'page-info', 'div_open' => 1, 'div_title' => t('Page permissions'), 'div_help' => t('Page fieldset must be enabled<br />if you want to give access to other fields'), 'fieldset' => 1),
|
| 163 |
array('enabled' => '0', 'name' => t('Page URL'), 'fields' => array('page-info', 'url'), 'render' => 1),
|
| 164 |
array('enabled' => '0', 'name' => t('Page Type'), 'fields' => array('page-info', 'page_type')),
|
| 165 |
array('enabled' => '0', 'name' => t('Page title'), 'fields' => array('page-info', 'page_title')),
|
| 166 |
array('enabled' => '0', 'name' => t('Page use pager'), 'fields' => array('page-info', 'use_pager')),
|
| 167 |
array('enabled' => '0', 'name' => t('Page breadcrumb'), 'fields' => array('page-info', 'breadcrumb_no_home')),
|
| 168 |
array('enabled' => '0', 'name' => t('Page nodes per page'), 'fields' => array('page-info', 'nodes_per_page')),
|
| 169 |
array('enabled' => '1', 'name' => t('Page header'), 'fields' => array('page-info', 'page_header_fieldset')),
|
| 170 |
array('enabled' => '1', 'name' => t('Page footer'), 'fields' => array('page-info', 'page_footer_fieldset')),
|
| 171 |
array('enabled' => '0', 'name' => t('Page empty text'), 'fields' => array('page-info', 'page_empty_fieldset')),
|
| 172 |
array('enabled' => '0', 'name' => t('Page menu'), 'fields' => array('page-info', 'menu-info'), 'div_close' => 1),
|
| 173 |
// block fieldset
|
| 174 |
array('enabled' => '1', 'name' => t('Block fieldset'), 'fields' => 'block-info', 'div_open' => 1, 'div_title' => t('Block permissions'), 'div_help' => t('Block fieldset must be enabled<br />if you want to give access to other fields'), 'fieldset' => 1),
|
| 175 |
array('enabled' => '0', 'name' => t('Block type'), 'fields' => array('block-info', 'block_type')),
|
| 176 |
array('enabled' => '0', 'name' => t('Block title'), 'fields' => array('block-info', 'block_title')),
|
| 177 |
array('enabled' => '0', 'name' => t('Block nodes per block'), 'fields' => array('block-info', 'nodes_per_block')),
|
| 178 |
array('enabled' => '0', 'name' => t('Block more'), 'fields' => array('block-info', 'block_more')),
|
| 179 |
array('enabled' => '1', 'name' => t('Block header'), 'fields' => array('block-info', 'block_header_fieldset')),
|
| 180 |
array('enabled' => '1', 'name' => t('Block footer'), 'fields' => array('block-info', 'block_footer_fieldset')),
|
| 181 |
array('enabled' => '0', 'name' => t('Block empty text'), 'fields' => array('block-info', 'block_empty_fieldset'), 'div_close' => 1),
|
| 182 |
// other fieldsets
|
| 183 |
array('enabled' => '0', 'name' => t('Basic Info'), 'fields' => 'basic-info', 'div_open' => 1, 'div_title' => t('Other permissions'), 'fieldset' => 1),
|
| 184 |
array('enabled' => '0', 'name' => t('Fields'), 'fields' => 'field', 'fieldset' => 1),
|
| 185 |
array('enabled' => '0', 'name' => t('Arguments'), 'fields' => 'argument', 'fieldset' => 1),
|
| 186 |
array('enabled' => '0', 'name' => t('Arguments handling code'), 'fields' => 'view_args_php_fieldset'),
|
| 187 |
array('enabled' => '0', 'name' => t('Filters'), 'fields' => 'filter', 'fieldset' => 1),
|
| 188 |
array('enabled' => '0', 'name' => t('Exposed Filters'), 'fields' => 'exposed_filter', 'fieldset' => 1),
|
| 189 |
array('enabled' => '0', 'name' => t('Sort Criteria'), 'fields' => 'sort', 'div_close' => 1, 'fieldset' => 1),
|
| 190 |
);
|
| 191 |
return $available_fields;
|
| 192 |
}
|
| 193 |
|
| 194 |
/**
|
| 195 |
* Return default values, used when views_ui_permissions doesn't exist in variable table.
|
| 196 |
*/
|
| 197 |
function views_ui_perm_default_values($available_fields) {
|
| 198 |
$default_enabled = array();
|
| 199 |
foreach ($available_fields as $field) {
|
| 200 |
$value = ($field['enabled'] == '1') ? $field['name'] : '0';
|
| 201 |
$default_enabled[$field['name']] = $value;
|
| 202 |
}
|
| 203 |
return $default_enabled;
|
| 204 |
}
|
| 205 |
|
| 206 |
/**
|
| 207 |
* We generate our own views overview page.
|
| 208 |
*/
|
| 209 |
function views_ui_perm_views_page($vid = NULL) {
|
| 210 |
|
| 211 |
if (!empty($vid)) {
|
| 212 |
return views_ui_admin_edit_page($vid);
|
| 213 |
}
|
| 214 |
else {
|
| 215 |
|
| 216 |
views_load_cache();
|
| 217 |
|
| 218 |
$num_views = 25;
|
| 219 |
|
| 220 |
drupal_set_title(t('Administer views'));
|
| 221 |
|
| 222 |
$result = pager_query("SELECT vid, name, description, menu_title, page_title, block_title, url, page, menu, block FROM {view_view} ORDER BY name", $num_views);
|
| 223 |
|
| 224 |
while ($view = db_fetch_object($result)) {
|
| 225 |
$url = ($view->page ? l($view->url, $view->url) : t('No Page View'));
|
| 226 |
|
| 227 |
$items[] = array(
|
| 228 |
$view->name,
|
| 229 |
filter_xss_admin(views_get_title($view, 'admin')),
|
| 230 |
$view->description,
|
| 231 |
$url,
|
| 232 |
theme('links', array(
|
| 233 |
array('title' => t('Edit'), 'href' => "admin/build/views_ui_perm/$view->vid"),
|
| 234 |
))
|
| 235 |
);
|
| 236 |
}
|
| 237 |
|
| 238 |
if ($items) {
|
| 239 |
$output = theme('table', array(t('View'), t('Title'), t('Description'), t('URL'), t('Actions')), $items);
|
| 240 |
$output .= theme('pager', NULL, $num_views);
|
| 241 |
}
|
| 242 |
else {
|
| 243 |
$output .= t('<p>No views have currently been defined.</p>');
|
| 244 |
}
|
| 245 |
return $output;
|
| 246 |
}
|
| 247 |
}
|