'admin/settings/multi_logic_access', 'title' => t('Multi Logic Access'), 'callback' => 'drupal_get_form', 'callback arguments' => array('multi_logic_access_settings_form'), 'access' => user_access('administer site configuration'), ); $items[] = array( 'path' => 'admin/settings/multi_logic_access/settings', 'title' => t('Configure multi logic access'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); } return $items; } /** * Generate multi_logic access UI form. */ function multi_logic_access_settings_form($theme = NULL) { global $theme_key, $custom_theme, $user; $uid = $user->uid; // Get whatever is stored in multi_logic table. $existing = array(); $result = db_query("SELECT * FROM {multi_logic_access}"); while ($row = db_fetch_object($result)) { $existing[$row->realm] = $row; } // Get all rule realms from node_access table. $result = db_query("SELECT DISTINCT realm FROM {node_access}"); while ($row = db_fetch_object($result)) { $rules[] = $row->realm; } // Get all rule realms from modules. User doing this should have grants in all modules affected. $op = 'view'; $mrules = node_access_grants($op, $uid); foreach ($mrules as $realm => $grants) { $rules[] = $realm; } // Get only unique values $rules = array_unique($rules); // Sort the rule realms asort($rules); $form['#tree'] = TRUE; foreach ($rules as $realm) { $form[$realm]['checkbox'] = array('#type' => 'checkbox', '#default_value' => (isset($existing[$realm]->realm) ? 1 : 0)); $form[$realm]['realm'] = array('#type' => 'textfield', '#size' => 25, '#disabled' => TRUE, '#value' => check_plain($realm), '#default_value' => $realm); $form[$realm]['group'] = array('#type' => 'textfield', '#size' => 5, '#default_value' => (isset($existing[$realm]->groupname) ? $existing[$realm]->groupname : '') ); $form[$realm]['logic'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->logic) ? $existing[$realm]->logic : 'AND'), '#options' => array('AND' => 'AND', 'OR' => 'OR') ); $form[$realm]['weight'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->weight) ? $existing[$realm]->weight : '0'), '#options' => array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9') ); $form[$realm]['check'] = array('#type' => 'select', '#default_value' => (isset($existing[$realm]->checkstatus) ? $existing[$realm]->checkstatus : '0'), '#options' => array('0' => '0', '1' => '1') ); } $form['submit'] = array('#type' => 'submit', '#value' => t('Save changes')); return $form; } /** * Theme function to render the table for the multi_logic_access_roles_multi_logic * multi_logic access UI */ function theme_multi_logic_access_settings_form($form) { $output .= "\n
\n"; $output .= '
'. t('Here you can configure multi_logic access. To set realms using AND logic, first give them the same group name, then weight them (eg og_public 1 and content_access_rid 2), then set the first item to OR and the following item(s) to AND. This will create a block like this: OR (og_public AND content_access_rid) which will mean that if both/all the items inside the brackets resolve to TRUE, then the node will be accessible. Note that group names are purely arbitrary and do not have to correspond with anything in the module, except don\'t use \'all\'') ."
\n"; $header = array(t(''),t('Group'), t('Weight'), t('Logic'), t('Realm'), t('Check')); $rows = array(); foreach (element_children($form) as $i) { $block = &$form[$i]; $rows[] = array( drupal_render($block['checkbox']), drupal_render($block['group']), drupal_render($block['weight']), drupal_render($block['logic']), drupal_render($block['realm']), drupal_render($block['check']), ); } $output .= theme('table', $header, $rows, array('id' => 'multi_logic_access-table')); $output .= "
\n"; $output .= drupal_render($form); return $output; } /** * Process multi_logic form submission. */ function multi_logic_access_settings_form_submit($form_id, $form_values) { // Erase all existing settings db_query ("DELETE FROM {multi_logic_access}"); // Insert new settings foreach ($form_values as $block) { if ($block['checkbox'] == 1) { db_query("INSERT INTO {multi_logic_access} (realm, groupname, logic, weight, checkstatus) VALUES ('%s','%s','%s','%s',%d)", $block['realm'], $block['group'], $block['logic'], $block['weight'], $block['check']); } } drupal_set_message(t('The multi_logic access settings have been updated.')); cache_clear_all(); } ?>