| 1 |
<?php |
<?php |
| 2 |
// $Id: tac_lite.module,v 1.8 2008/06/07 01:42:06 yogadex Exp $ |
// $Id: tac_lite.module,v 1.9 2008/07/22 15:55:23 yogadex Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Control access to site content based on taxonomy, roles and users. |
* Control access to site content based on taxonomy, roles and users. |
| 171 |
function tac_lite_admin_scheme_form($form_state, $i) { |
function tac_lite_admin_scheme_form($form_state, $i) { |
| 172 |
$vids = variable_get('tac_lite_categories', null); |
$vids = variable_get('tac_lite_categories', null); |
| 173 |
$roles = user_roles(); |
$roles = user_roles(); |
| 174 |
|
|
| 175 |
if (count($vids)) { |
if (count($vids)) { |
| 176 |
$config = _tac_lite_config($i); |
$config = _tac_lite_config($i); |
| 177 |
|
|
| 178 |
$form['tac_lite_config_scheme_' . $i] = |
$form['tac_lite_config_scheme_' . $i] = |
| 179 |
array('#tree' => TRUE); |
array('#tree' => TRUE); |
| 180 |
$form['tac_lite_config_scheme_' . $i]['name'] = |
$form['tac_lite_config_scheme_' . $i]['name'] = |
| 183 |
'#description' => t('A human-readable name for administrators to see. For example, \'read\' or \'read and write\'.'), |
'#description' => t('A human-readable name for administrators to see. For example, \'read\' or \'read and write\'.'), |
| 184 |
'#default_value' => $config['name'], |
'#default_value' => $config['name'], |
| 185 |
'#required' => TRUE, |
'#required' => TRUE, |
| 186 |
); |
); |
| 187 |
// Currently, only view, update and delete are supported by node_access |
// Currently, only view, update and delete are supported by node_access |
| 188 |
$options = array('grant_view' => 'view', |
$options = array('grant_view' => 'view', |
| 189 |
'grant_update' => 'update', |
'grant_update' => 'update', |
| 200 |
|
|
| 201 |
$form['helptext'] = array('#type' => 'markup', |
$form['helptext'] = array('#type' => 'markup', |
| 202 |
'#value' => t('You may grant these permissions by role, below. To grant permission to an individual user, visit the tac_lite tab on the user edit page.')); |
'#value' => t('You may grant these permissions by role, below. To grant permission to an individual user, visit the tac_lite tab on the user edit page.')); |
|
|
|
|
|
|
|
$all_defaults = variable_get('tac_lite_grants_scheme_' . $i, array()); |
|
|
$form['tac_lite_grants_scheme_' . $i] = |
|
|
array('#tree' => true); |
|
|
foreach ($roles as $rid => $role_name) { |
|
|
$form['tac_lite_grants_scheme_' . $i][$rid] = |
|
|
array('#type' => 'fieldset', |
|
|
'#tree' => true, |
|
|
'#title' => t('Access for %role', array('%role' => $role_name)), |
|
|
'#description' => t(''), |
|
|
); |
|
|
$defaults = $all_defaults[$rid]; |
|
|
foreach ($vids as $vid) { |
|
|
$v = taxonomy_get_vocabularies($vid); |
|
|
$form['tac_lite_grants_scheme_' . $i][$rid][$vid] = |
|
|
_taxonomy_term_select($v->name, |
|
|
null, // name no longer used in new form api |
|
|
$defaults[$vid], |
|
|
$vid, |
|
|
'', |
|
|
true, |
|
|
'<'.t('none').'>'); |
|
|
} |
|
|
} |
|
| 203 |
|
|
| 204 |
return system_settings_form($form); |
$vocabularies = taxonomy_get_vocabularies(); |
| 205 |
|
$all_defaults = variable_get('tac_lite_grants_scheme_' . $i, array()); |
| 206 |
|
$form['tac_lite_grants_scheme_' . $i] = |
| 207 |
|
array('#tree' => true); |
| 208 |
|
foreach ($roles as $rid => $role_name) { |
| 209 |
|
$form['tac_lite_grants_scheme_' . $i][$rid] = |
| 210 |
|
array('#type' => 'fieldset', |
| 211 |
|
'#tree' => true, |
| 212 |
|
'#title' => t('Access for %role', array('%role' => $role_name)), |
| 213 |
|
'#description' => t(''), |
| 214 |
|
); |
| 215 |
|
$defaults = count($all_defaults) ? $all_defaults[$rid] : NULL; |
| 216 |
|
foreach ($vids as $vid) { |
| 217 |
|
$v = $vocabularies[$vid]; |
| 218 |
|
$form['tac_lite_grants_scheme_' . $i][$rid][$vid] = |
| 219 |
|
_taxonomy_term_select($v->name, |
| 220 |
|
null, // name no longer used in new form api |
| 221 |
|
$defaults ? $defaults[$vid] : NULL, |
| 222 |
|
$vid, |
| 223 |
|
'', |
| 224 |
|
true, |
| 225 |
|
'<'.t('none').'>'); |
| 226 |
|
} |
| 227 |
|
} |
| 228 |
|
|
| 229 |
|
return system_settings_form($form); |
| 230 |
} |
} |
| 231 |
else { |
else { |
| 232 |
return (array('body' => array('#type' => 'markup', |
return (array('body' => array('#type' => 'markup', |
| 410 |
// grant id 0 is reserved for nodes which were not given a grant id when they were created. By adding 0 to the grant id, we let the user view those nodes. |
// grant id 0 is reserved for nodes which were not given a grant id when they were created. By adding 0 to the grant id, we let the user view those nodes. |
| 411 |
$grants = array(0); |
$grants = array(0); |
| 412 |
$config = _tac_lite_config($scheme); |
$config = _tac_lite_config($scheme); |
| 413 |
if (count($account->$config['realm'])) { |
$realm = $config['realm']; |
| 414 |
// $account->$config['realm'] is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access |
if (isset($account->$realm) && count($account->$realm)) { |
| 415 |
foreach ($account->$config['realm'] as $tids) { |
// $account->$realm is array. Keys are vids, values are array of tids within that vocabulary, to which the user has access |
| 416 |
if (count($tids)) { |
foreach ($account->$realm as $tids) { |
| 417 |
$grants = array_merge($grants, $tids); |
if (count($tids)) { |
| 418 |
|
$grants = array_merge($grants, $tids); |
| 419 |
} |
} |
| 420 |
} |
} |
| 421 |
} |
} |
| 422 |
|
|
| 423 |
// add per-role grants in addition to per-user grants |
// add per-role grants in addition to per-user grants |