/[drupal]/contributions/modules/simple_access/simple_access.module
ViewVC logotype

Diff of /contributions/modules/simple_access/simple_access.module

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

revision 1.38.2.10, Mon Sep 29 07:42:58 2008 UTC revision 1.38.2.11, Wed Oct 1 02:50:20 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: simple_access.module,v 1.38.2.9 2008/09/23 04:30:28 gordon Exp $  // $Id: simple_access.module,v 1.38.2.10 2008/09/29 07:42:58 gordon Exp $
3    
4    
5  /**  /**
# Line 32  function simple_access_menu($may_cache) Line 32  function simple_access_menu($may_cache)
32        'path' => 'admin/user/simple_access',        'path' => 'admin/user/simple_access',
33        'title' => t('Access groups'),        'title' => t('Access groups'),
34        'access' => $access,        'access' => $access,
35        'callback' => 'simple_access_page_overview',        'callback' => 'drupal_get_form',
36          'callback arguments' => array('simple_access_page_overview'),
37        'type' => MENU_NORMAL_ITEM,        'type' => MENU_NORMAL_ITEM,
38        'description' => t('Manage groups of users for node-specific access control.'),        'description' => t('Manage groups of users for node-specific access control.'),
39      );      );
# Line 509  function simple_access_delete_group_conf Line 510  function simple_access_delete_group_conf
510  }  }
511    
512  function simple_access_page_overview() {  function simple_access_page_overview() {
513    if (count($rg = simple_access_get_groups())) {    if (count($groups = simple_access_get_groups())) {
514      drupal_set_title(t('Access groups'));      drupal_set_title(t('Access groups'));
     $header = array(t('Group'), t('Roles'), t('Operations'));  
515      $roles = user_roles();      $roles = user_roles();
516      foreach ($rg as $g) {      $form['groups'] = array(
517        $gid = $g['gid'];        '#tree' => TRUE,
518        $rows[$gid]['group'] = $g['name'];      );
519        foreach ($groups as $group) {
520          $gid = $group['gid'];
521          $form['groups'][$gid]['name'] = array(
522            '#value' => $group['name'],
523          );
524        $r = array();        $r = array();
525        foreach ($g['roles'] as $rid) {        foreach ($group['roles'] as $rid) {
526          $r[] = $roles[$rid];          $r[] = $roles[$rid];
527        }        }
528        $rows[$gid]['roles'] = "<span style='font-size:xx-small'>". implode(', ', $r) ."</span>";        $form['groups'][$gid]['roles'] = array(
529        $rows[$gid]['ops'] = l('edit', 'admin/user/simple_access/edit/'. $gid) .'&nbsp;'. l('delete', 'admin/user/simple_access/delete/'. $gid);          '#value' => implode(', ', $r),
530          );
531          $form['groups'][$gid]['weight'] = array(
532            '#type' => 'weight',
533            '#default_value' => $group['weight'],
534            '#attributes' => array('class' => 'sa-group-weight'),
535          );
536          $form['groups'][$gid]['ops'] = array(
537            '#value' => l('edit', 'admin/user/simple_access/edit/'. $gid) .'&nbsp;'. l('delete', 'admin/user/simple_access/delete/'. $gid),
538          );
539      }      }
540      $output .= theme('table', $header, $rows, array('style' => 'width:100%'));      $form['submit'] = array(
541      $output .= '<br />'. l(t('add another access group'), 'admin/user/simple_access/add');        '#type' => 'submit',
542      return $output;        '#value' => t('Update'),
543        );
544        return $form;
545    }    }
546    else {    else {
547      drupal_set_message(t('You have not yet defined any access groups.'));      drupal_set_message(t('You have not yet defined any access groups.'));
# Line 533  function simple_access_page_overview() { Line 549  function simple_access_page_overview() {
549    }    }
550  }  }
551    
552    function theme_simple_access_page_overview($form) {
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        db_query('UPDATE simple_access_groups SET weight = %d WHERE gid = %d', $group['weight'], $gid);
574      }
575    }
576    
577  function simple_access_profile_list() {  function simple_access_profile_list() {
578    $form = array();    $form = array();
579    $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');
# Line 547  function simple_access_profile_list() { Line 588  function simple_access_profile_list() {
588      $form['profiles'][$row['pid']]['weight'] = array(      $form['profiles'][$row['pid']]['weight'] = array(
589        '#type' => 'weight',        '#type' => 'weight',
590        '#default_value' => $row['weight'],        '#default_value' => $row['weight'],
591          '#attributes' => array('class' => 'sa-profile-weight'),
592      );      );
593      $form['profiles'][$row['pid']]['operations'] = array(      $form['profiles'][$row['pid']]['operations'] = array(
594        '#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'),
# Line 567  function theme_simple_access_profile_lis Line 609  function theme_simple_access_profile_lis
609    
610    foreach (element_children($form['profiles']) as $id) {    foreach (element_children($form['profiles']) as $id) {
611      $rows[] = array(      $rows[] = array(
612        drupal_render($form['profiles'][$id]['name']),        'data' => array(
613        drupal_render($form['profiles'][$id]['weight']),          array('data' => drupal_render($form['profiles'][$id]['name'])),
614        drupal_render($form['profiles'][$id]['operations']),          array('data' => drupal_render($form['profiles'][$id]['weight'])),
615            array('data' => drupal_render($form['profiles'][$id]['operations'])),
616          ),
617          'class' => 'draggable',
618      );      );
619    }    }
620    
# Line 582  function theme_simple_access_profile_lis Line 627  function theme_simple_access_profile_lis
627        ),        ),
628      );      );
629    }    }
630    $output .= theme('table', $head, $rows);    $output .= theme('table', $head, $rows, array('id' => 'sa-profile-list'));
631    $output .= drupal_render($form);    $output .= drupal_render($form);
632    
633    return $output;    return $output;
634  }  }
635    
636    function simple_access_profile_list_submit($form, $form_state) {
637      foreach ($form_state['values']['profiles'] as $pid => $profile) {
638        db_query('UPDATE simple_access_profiles SET weight = %d WHERE pid = %d', $profile['weight'], $pid);
639      }
640    }
641    
642  function simple_access_profile_form($pid = NULL) {  function simple_access_profile_form($pid = NULL) {
643    $form = array();    $form = array();
644    $access_profile = array();    $access_profile = array();
# Line 788  function simple_access_get_profiles() { Line 839  function simple_access_get_profiles() {
839    
840  function simple_access_get_groups() {  function simple_access_get_groups() {
841    $groups = array();    $groups = array();
842    $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');
843    while ($g = db_fetch_array($result)) {    while ($g = db_fetch_array($result)) {
844      $groups[$g['gid']]['name']  = $g['name'];      $groups[$g['gid']]['name']   = $g['name'];
845      $groups[$g['gid']]['gid']   = $g['gid'];      $groups[$g['gid']]['gid']    = $g['gid'];
846        $groups[$g['gid']]['weight'] = $g['weight'];
847      $groups[$g['gid']]['roles'] = simple_access_get_roles($g['gid']);      $groups[$g['gid']]['roles'] = simple_access_get_roles($g['gid']);
848    }    }
849    return $groups;    return $groups;

Legend:
Removed from v.1.38.2.10  
changed lines
  Added in v.1.38.2.11

  ViewVC Help
Powered by ViewVC 1.1.2