You are here

function ad_owner_permissions in Advertisement 5

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

1 string reference to 'ad_owner_permissions'
ad_menu in ./ad.module
Implementation of hook_menu().

File

./ad.module, line 1518
An advertising system for Drupal powered websites.

Code

function ad_owner_permissions($aid, $uid) {
  drupal_set_title('Permissions');
  $oid = db_result(db_query("SELECT oid FROM {ad_owners} WHERE aid = %d and uid = %d", $aid, $uid));
  $granted = explode('|,|', db_result(db_query("SELECT permissions FROM {ad_permissions} WHERE oid = %d", $oid)));
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      t('permissions'),
      t('granted'),
    ),
  );
  $rows = array();
  $node = node_load($aid);
  $permissions = module_invoke_all('adapi', 'permissions', $node);
  foreach ($permissions as $permission) {
    $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' => $aid,
  );
  $form['uid'] = array(
    '#type' => 'hidden',
    '#value' => $uid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}