| 1 |
<?php |
<?php |
| 2 |
// $Id: simple_access.module,v 1.40.2.11 2008/09/29 08:05:10 gordon Exp $ |
// $Id: simple_access.module,v 1.40.2.12 2008/09/29 08:06:41 gordon Exp $ |
| 3 |
|
|
| 4 |
|
|
| 5 |
/** |
/** |
| 23 |
'title' => 'Access groups', |
'title' => 'Access groups', |
| 24 |
'access callback' => 'user_access', |
'access callback' => 'user_access', |
| 25 |
'access arguments' => array('manage simple access'), |
'access arguments' => array('manage simple access'), |
| 26 |
'page callback' => 'simple_access_page_overview', |
'page callback' => 'drupal_get_form', |
| 27 |
|
'page arguments' => array('simple_access_page_overview'), |
| 28 |
'type' => MENU_NORMAL_ITEM, |
'type' => MENU_NORMAL_ITEM, |
| 29 |
'description' => 'Manage groups of users for node-specific access control.', |
'description' => 'Manage groups of users for node-specific access control.', |
| 30 |
); |
); |
| 344 |
'simple_access_form' => array( |
'simple_access_form' => array( |
| 345 |
'arguments' => array('form' => NULL), |
'arguments' => array('form' => NULL), |
| 346 |
), |
), |
| 347 |
|
'simple_access_page_overview' => array( |
| 348 |
|
'arguments' => array('form' => NULL), |
| 349 |
|
), |
| 350 |
|
'simple_access_profile_list' => array( |
| 351 |
|
'arguments' => array('form' => NULL), |
| 352 |
|
), |
| 353 |
); |
); |
| 354 |
} |
} |
| 355 |
|
|
| 509 |
} |
} |
| 510 |
|
|
| 511 |
function simple_access_page_overview() { |
function simple_access_page_overview() { |
| 512 |
if (count($rg = simple_access_get_groups())) { |
if (count($groups = simple_access_get_groups())) { |
| 513 |
drupal_set_title(t('Access groups')); |
drupal_set_title(t('Access groups')); |
|
$header = array(t('Group'), t('Roles'), t('Operations')); |
|
| 514 |
$roles = user_roles(); |
$roles = user_roles(); |
| 515 |
foreach ($rg as $g) { |
$form['groups'] = array( |
| 516 |
$gid = $g['gid']; |
'#tree' => TRUE, |
| 517 |
$rows[$gid]['group'] = $g['name']; |
); |
| 518 |
|
foreach ($groups as $group) { |
| 519 |
|
$gid = $group['gid']; |
| 520 |
|
$form['groups'][$gid]['name'] = array( |
| 521 |
|
'#value' => $group['name'], |
| 522 |
|
); |
| 523 |
$r = array(); |
$r = array(); |
| 524 |
foreach ($g['roles'] as $rid) { |
foreach ($group['roles'] as $rid) { |
| 525 |
$r[] = $roles[$rid]; |
$r[] = $roles[$rid]; |
| 526 |
} |
} |
| 527 |
$rows[$gid]['roles'] = "<span style='font-size:xx-small'>". implode(', ', $r) ."</span>"; |
$form['groups'][$gid]['roles'] = array( |
| 528 |
$rows[$gid]['ops'] = l('edit', 'admin/user/simple_access/edit/'. $gid) .' '. l('delete', 'admin/user/simple_access/delete/'. $gid); |
'#value' => implode(', ', $r), |
| 529 |
|
); |
| 530 |
|
$form['groups'][$gid]['weight'] = array( |
| 531 |
|
'#type' => 'weight', |
| 532 |
|
'#default_value' => $group['weight'], |
| 533 |
|
'#attributes' => array('class' => 'sa-group-weight'), |
| 534 |
|
); |
| 535 |
|
$form['groups'][$gid]['ops'] = array( |
| 536 |
|
'#value' => l('edit', 'admin/user/simple_access/edit/'. $gid) .' '. l('delete', 'admin/user/simple_access/delete/'. $gid), |
| 537 |
|
); |
| 538 |
} |
} |
| 539 |
$output .= theme('table', $header, $rows, array('style' => 'width:100%')); |
$form['submit'] = array( |
| 540 |
$output .= '<br />'. l(t('add another access group'), 'admin/user/simple_access/add'); |
'#type' => 'submit', |
| 541 |
return $output; |
'#value' => t('Update'), |
| 542 |
|
); |
| 543 |
|
return $form; |
| 544 |
} |
} |
| 545 |
else { |
else { |
| 546 |
drupal_set_message(t('You have not yet defined any access groups.')); |
drupal_set_message(t('You have not yet defined any access groups.')); |
| 548 |
} |
} |
| 549 |
} |
} |
| 550 |
|
|
| 551 |
|
function theme_simple_access_page_overview($form) { |
| 552 |
|
drupal_add_tabledrag('sa-group-list', 'order', 'sibling', 'sa-group-weight'); |
| 553 |
|
$header = array(t('Group'), t('Roles'), t('Weight'), t('Operations')); |
| 554 |
|
foreach (element_children($form['groups']) as $gid) { |
| 555 |
|
$rows[] = array( |
| 556 |
|
'data' => array( |
| 557 |
|
drupal_render($form['groups'][$gid]['name']), |
| 558 |
|
array('data' => drupal_render($form['groups'][$gid]['roles']), 'class' => 'sa-group-roles'), |
| 559 |
|
drupal_render($form['groups'][$gid]['weight']), |
| 560 |
|
drupal_render($form['groups'][$gid]['ops']), |
| 561 |
|
), |
| 562 |
|
'class' => 'draggable', |
| 563 |
|
); |
| 564 |
|
} |
| 565 |
|
$output .= theme('table', $header, $rows, array('id' => 'sa-group-list')); |
| 566 |
|
$output .= drupal_render($form); |
| 567 |
|
|
| 568 |
|
return $output; |
| 569 |
|
} |
| 570 |
|
|
| 571 |
|
function simple_access_page_overview_submit($form, &$form_state) { |
| 572 |
|
foreach ($form_state['values']['groups'] as $gid => $group) { |
| 573 |
|
$group['gid'] = $gid; |
| 574 |
|
drupal_write_record('simple_access_groups', $group, array('gid')); |
| 575 |
|
} |
| 576 |
|
} |
| 577 |
|
|
| 578 |
function simple_access_profile_list() { |
function simple_access_profile_list() { |
| 579 |
$form = array(); |
$form = array(); |
| 580 |
$result = db_query('SELECT * FROM {simple_access_profiles} ORDER BY weight ASC, name ASC'); |
$result = db_query('SELECT * FROM {simple_access_profiles} ORDER BY weight ASC, name ASC'); |
| 589 |
$form['profiles'][$row['pid']]['weight'] = array( |
$form['profiles'][$row['pid']]['weight'] = array( |
| 590 |
'#type' => 'weight', |
'#type' => 'weight', |
| 591 |
'#default_value' => $row['weight'], |
'#default_value' => $row['weight'], |
| 592 |
|
'#attributes' => array('class' => 'sa-profile-weight'), |
| 593 |
); |
); |
| 594 |
$form['profiles'][$row['pid']]['operations'] = array( |
$form['profiles'][$row['pid']]['operations'] = array( |
| 595 |
'#value' => l(t('edit'), 'admin/user/sa_profiles/'. $row['pid'] .'/edit') .' '. l(t('delete'), 'admin/user/sa_profiles/'. $row['pid'] .'/delete'), |
'#value' => l(t('edit'), 'admin/user/sa_profiles/'. $row['pid'] .'/edit') .' '. l(t('delete'), 'admin/user/sa_profiles/'. $row['pid'] .'/delete'), |
| 605 |
} |
} |
| 606 |
|
|
| 607 |
function theme_simple_access_profile_list($form) { |
function theme_simple_access_profile_list($form) { |
| 608 |
|
drupal_add_tabledrag('sa-profile-list', 'order', 'sibling', 'sa-profile-weight'); |
| 609 |
$head = array(t('Name'), t('Weight'), t('Operations')); |
$head = array(t('Name'), t('Weight'), t('Operations')); |
| 610 |
$rows = array(); |
$rows = array(); |
| 611 |
|
|
| 612 |
foreach (element_children($form['profiles']) as $id) { |
foreach (element_children($form['profiles']) as $id) { |
| 613 |
$rows[] = array( |
$rows[] = array( |
| 614 |
drupal_render($form['profiles'][$id]['name']), |
'data' => array( |
| 615 |
drupal_render($form['profiles'][$id]['weight']), |
array('data' => drupal_render($form['profiles'][$id]['name'])), |
| 616 |
drupal_render($form['profiles'][$id]['operations']), |
array('data' => drupal_render($form['profiles'][$id]['weight'])), |
| 617 |
|
array('data' => drupal_render($form['profiles'][$id]['operations'])), |
| 618 |
|
), |
| 619 |
|
'class' => 'draggable', |
| 620 |
); |
); |
| 621 |
} |
} |
| 622 |
|
|
| 629 |
), |
), |
| 630 |
); |
); |
| 631 |
} |
} |
| 632 |
$output .= theme('table', $head, $rows); |
$output .= theme('table', $head, $rows, array('id' => 'sa-profile-list')); |
| 633 |
$output .= drupal_render($form); |
$output .= drupal_render($form); |
| 634 |
|
|
| 635 |
return $output; |
return $output; |
| 636 |
} |
} |
| 637 |
|
|
| 638 |
|
function simple_access_profile_list_submit($form, $form_state) { |
| 639 |
|
foreach ($form_state['values']['profiles'] as $pid => $profile) { |
| 640 |
|
$profile['pid'] = $pid; |
| 641 |
|
drupal_write_record('simple_access_profiles', $profile, array('pid')); |
| 642 |
|
} |
| 643 |
|
} |
| 644 |
|
|
| 645 |
function simple_access_profile_form($form_state, $pid = NULL) { |
function simple_access_profile_form($form_state, $pid = NULL) { |
| 646 |
$form = array(); |
$form = array(); |
| 647 |
$access_profile = array(); |
$access_profile = array(); |
| 844 |
|
|
| 845 |
function simple_access_get_groups() { |
function simple_access_get_groups() { |
| 846 |
$groups = array(); |
$groups = array(); |
| 847 |
$result = db_query('SELECT gid, name FROM {simple_access_groups} ORDER BY weight, name'); |
$result = db_query('SELECT gid, name, weight FROM {simple_access_groups} ORDER BY weight, name'); |
| 848 |
while ($g = db_fetch_array($result)) { |
while ($g = db_fetch_array($result)) { |
| 849 |
$groups[$g['gid']]['name'] = $g['name']; |
$groups[$g['gid']]['name'] = $g['name']; |
| 850 |
$groups[$g['gid']]['gid'] = $g['gid']; |
$groups[$g['gid']]['gid'] = $g['gid']; |
| 851 |
|
$groups[$g['gid']]['weight'] = $g['weight']; |
| 852 |
$groups[$g['gid']]['roles'] = simple_access_get_roles($g['gid']); |
$groups[$g['gid']]['roles'] = simple_access_get_roles($g['gid']); |
| 853 |
} |
} |
| 854 |
return $groups; |
return $groups; |