You are here

function ad_owner_permissions_form in Advertisement 6.3

Same name and namespace in other branches
  1. 6 owners/ad_owners.module \ad_owner_permissions_form()
  2. 6.2 owners/ad_owners.module \ad_owner_permissions_form()
  3. 7 owners/ad_owners.module \ad_owner_permissions_form()

Display a form with all available permissions and their status for the selected ad and ad owner.

1 string reference to 'ad_owner_permissions_form'
ad_owners_menu in owners/ad_owners.module
Implementation of hook_menu().

File

owners/ad_owners.module, line 473
Enhances the ad module to support ad owners.

Code

function ad_owner_permissions_form($form_state, $node, $user) {
  drupal_set_title(t('Permissions'));
  $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $node->nid, $user->uid));
  $granted = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      t('permission'),
      t('granted'),
    ),
  );
  $rows = array();
  $permissions = module_invoke_all('adapi', 'permissions', $node);
  foreach ($permissions as $permission => $default) {
    $form['permission'][$permission] = array(
      '#value' => t($permission),
    );
    $form['grant'][str_replace(' ', '_', $permission)] = array(
      '#type' => 'checkbox',
      '#default_value' => in_array($permission, $granted) ? 1 : 0,
    );
  }
  $form['oid'] = array(
    '#type' => 'hidden',
    '#value' => $oid,
  );
  $form['aid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid,
  );
  $form['uid'] = array(
    '#type' => 'hidden',
    '#value' => $user->uid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}