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

Diff of /contributions/modules/adminrole/adminrole.module

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

revision 1.2.2.2 by jacobsingh, Sun Apr 1 01:33:01 2007 UTC revision 1.2.2.3 by jacobsingh, Sat Jun 23 04:57:13 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // $Id$
3    
4  /**  /** @file
  *  
5   * adminrole:   * adminrole:
6   * This module simply gives a designated role all permissions every time to the modules page is submitted.   * This module simply gives a designated role all permissions every time the
7   *   * modules page is submitted.
8   */   */
9    
10  /**  /**
11   * Implementation of hook_help().   * Implementation of hook_help().
12   */   */
13  function adminrole_help($section) {  function adminrole_help($section) {
14    switch ($section) {    switch ($section) {
15      case 'admin/settings/adminrole':      case 'admin/settings/adminrole':
16        return '<p>'. t('Change which role is a "admin" Role with full perms') . '</p>';        return t('Change which role is a "admin" Role with full perms');
17    }    }
18  }  }
19    
# Line 23  function adminrole_menu($may_cache) { Line 24  function adminrole_menu($may_cache) {
24    $items = array();    $items = array();
25    
26    if ($may_cache) {    if ($may_cache) {
   
27      $items[] = array(      $items[] = array(
28      'path' => 'admin/settings/adminrole',        'path' => 'admin/settings/adminrole',
29      'title' => t('adminrole'),        'title' => t('adminrole'),
30      'callback' => 'drupal_get_form',        'callback' => 'drupal_get_form',
31      'callback arguments' => array('adminrole_admin_settings'),        'callback arguments' => array('adminrole_admin_settings'),
32      'access' => user_access('administer site configuration'),        'access' => user_access('administer site configuration'),
33      'type' => MENU_NORMAL_ITEM        'type' => MENU_NORMAL_ITEM
34      );      );
35      $items[] = array(      $items[] = array(
36      'path' => 'admin/adminrole/update',        'path' => 'admin/adminrole/update',
37      'title' => t('adminrole'),        'title' => t('adminrole'),
38      'callback' => 'adminrole_update_perms',        'callback' => 'adminrole_update_perms',
39      'access' => user_access('administer site configuration'),        'access' => user_access('administer site configuration'),
40      'type' => MENU_SUGGESTED_ITEM        'type' => MENU_SUGGESTED_ITEM
41      );      );
   
42    }    }
43    return $items;    return $items;
44  }  }
45    
46  function adminrole_update_perms() {  function adminrole_update_perms() {
47    watchdog("","DOER!");    if ($admin_role = variable_get('adminrole_adminrole', 0)) {
   _adminrole_update_perms();  
 }  
 function _adminrole_update_perms() {  
   
   if($admin_role = variable_get('adminrole_adminrole', 0)) {  
48      $perms = array();      $perms = array();
49      foreach (module_list(FALSE, FALSE, TRUE) as $module) {      foreach (module_list(FALSE, FALSE, TRUE) as $module) {
50        if ($permissions = module_invoke($module, 'perm')) {        if ($permissions = module_invoke($module, 'perm')) {
51          $perms = array_merge($perms,$permissions);          $perms = array_merge($perms, $permissions);
         continue;  
52        }        }
53      }      }
54      db_query('DELETE FROM {permission} WHERE rid = %d', $admin_role);      db_query('DELETE FROM {permission} WHERE rid = %d', $admin_role);
55      if (count($perms)) {      if (count($perms)) {
56        db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $admin_role, implode(', ', $perms));        db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $admin_role, implode(', ', $perms));
57      }      }
58        drupal_set_message(t('Admin Permissions Set'));
59    }    }
   drupal_set_message(implode('<br/>',drupal_get_messages()) . "<br/>" . t("Admin Permissions Set"));  
 }  
 function adminrole_system_modules_form_submit($form_id,$form_values) {  
   dpr($form_values);  
   die();  
60  }  }
61    
   
62  function adminrole_admin_settings() {  function adminrole_admin_settings() {
63    $form = array();    $form = array();
64    $form['adminrole_adminrole'] = array('#type' => 'select',    $form['adminrole_adminrole'] = array(
65    '#title' => t('Admin Roles'),      '#type' => 'select',
66    '#default_value' => variable_get('adminrole_adminrole', 0),      '#title' => t('Admin Roles'),
67    '#description' => t("Which Role is Admin?"),      '#default_value' => variable_get('adminrole_adminrole', 0),
68    '#options' => user_roles());      '#description' => t("Which Role is Admin?"),
69        '#options' => array_merge(array(0 => t('-- Please Select One --')), user_roles()),
70      );
71    return system_settings_form($form);    return system_settings_form($form);
72  }  }
73    
   
74  function adminrole_form_alter($form_id, &$form) {  function adminrole_form_alter($form_id, &$form) {
75    if($form_id != 'system_modules') {    if ($form_id == 'system_modules') {
76      return;      $form['#submit']["adminrole_update_perms"] = array();
77    }    }
   $form['#submit']["adminrole_update_perms"] = array();  
   return;  
   
78  }  }
79    
80    

Legend:
Removed from v.1.2.2.2  
changed lines
  Added in v.1.2.2.3

  ViewVC Help
Powered by ViewVC 1.1.3