You are here

function flexiaccess_page in Flexi Access 7

Build form to handle ACLs for node.

1 string reference to 'flexiaccess_page'
flexiaccess_menu in ./flexiaccess.module
Implements hook_menu().

File

./flexiaccess.nodes.inc, line 11
Form handling for per node ACL.

Code

function flexiaccess_page($form, &$form_state, $node) {

  // Get active content types that have Flexi access managing their ACL.
  $types = variable_get('flexiaccess_types', array());
  $ntype = $node->type;
  if (isset($types[$ntype]) && $types[$ntype] && module_exists('acl')) {
    $cnt = _flexiaccess_acl_count($node->nid);
    $form_state['node'] = $node;
    if (0 == $cnt) {
      $form['createacl'] = array(
        '#type' => 'markup',
        '#markup' => t('<p><strong>Create ACL (Access Control List)</strong></p><p>Currently, there is no ACL for this node.  Press &#8220;Create ACL&#8221; if you want to create one.</p>'),
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Create ACL'),
        '#submit' => array(
          'flexiaccess_create_acl',
        ),
      );
      return $form;
    }
    else {
      $form['acl'] = array(
        '#type' => 'fieldset',
        '#title' => t('User based ACL'),
        '#description' => t("Manage individual users' access to this node. Remember to press &#8220;Commit updates&#8221; when done (otherwise, your changes will not be saved)."),
        '#collapsible' => TRUE,
        '#tree' => TRUE,
      );
      $ops = array();
      if (user_access('flexiaccess view')) {
        $ops[] = 'view';
      }
      if (user_access('flexiaccess update')) {
        $ops[] = 'update';
      }
      if (user_access('flexiaccess delete')) {
        $ops[] = 'delete';
      }
      foreach ($ops as $op) {
        $acl_id = acl_get_id_by_name('flexiaccess', $op . '_' . $node->nid);
        $foo = acl_edit_form($form_state, $acl_id, t('Manage !op permission', array(
          '!op' => $op,
        )));
        $form['acl'][$op] = acl_edit_form($form_state, $acl_id, t('!op permission', array(
          '!op' => $op,
        )));
        $form['acl'][$op]['#collapsed'] = !isset($_POST['acl_' . $acl_id]) && !unserialize($form['acl'][$op]['user_list']['#default_value']);
      }
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Commit updates'),
        '#weight' => 10,
      );
      if (user_access('flexiaccess create acl')) {
        $form['reset'] = array(
          '#type' => 'submit',
          '#value' => t('Remove ACLs for this node'),
          '#weight' => 11,
          '#submit' => array(
            'flexiaccess_page_reset',
          ),
        );
      }
      if (!$node->status) {
        drupal_set_message(t("Warning: Your content is not published, but users with permissions shown below have access to it."), 'error');
      }
      return $form;
    }
  }
  drupal_set_message(t('This content type is not managed by Flexi access.'), 'error');
}