Readonly module

  1. <?php
  2. // $Id$
  3. function readonly_menu() {
  4.   $items = array();
  5.   $items['admin/settings/readonly'] = array(
  6.     'title' => t('Read Only'),
  7.     'description' => t('Which profile fields'),
  8.     'page callback' => 'drupal_get_form',
  9.     'page arguments' => array('readonly_admin_settings'),
  10.     'access arguments' => array('access administration pages'),
  11.     'type' => MENU_NORMAL_ITEM,
  12.    );
  13.      return $items;
  14. }
  15.  
  16. function readonly_perm(){
  17. return array('edit read only profile fields');
  18. }
  19.  
  20. function readonly_admin_settings() {
  21. $form = array();
  22.   $form['fields'] = array(
  23.     '#type' => 'fieldset',
  24.     '#title' => t('Fields'),
  25.     '#collapsible' => FALSE,
  26.     '#collapsed' => FALSE,
  27.   );
  28.        
  29. $result = db_query("SELECT pf.name, pf.title, pf.category FROM {profile_fields} pf");
  30.  
  31.  
  32. while ($row = db_fetch_object($result)) {
  33.   $name = $row->name;
  34.   $title = $row->title;
  35.   $category = $row->category;
  36.  
  37.     $form['fields'][$category]['set_' . $name . ''] = array(
  38.     '#type' => 'checkbox',
  39.     '#title' => $title,
  40.     '#default_value' => variable_get('set_'. $name .'', 0),
  41.   );
  42. }  
  43.   return system_settings_form($form);
  44. }
  45.  
  46. function readonly_form_alter(&$form, $form_state, $form_id) {
  47.         if (!user_access('edit read only profile fields')) {
  48.         if ($form_id != 'user_register') {
  49. $result = db_query("SELECT pf.name, pf.category FROM {profile_fields} pf");
  50. while ($row = db_fetch_object($result)) {
  51.   $name = $row->name;
  52.   $category = $row->category;
  53.  
  54.     if(variable_get('set_'. $name .'', 0) == '1'){
  55.         $form[$category][$name]['#disabled'] = TRUE;
  56.     }
  57.    
  58. }  
  59.         }
  60.         }
  61. }