You are here

function ad_owners_overview in Advertisement 6.3

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

TODO: Make this themeable. TODO: Group permissions by module. TODO: Allow modules to define default value for permission.

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

File

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

Code

function ad_owners_overview($node) {
  drupal_set_title(t('Ad owners'));

  // Be sure the node owner is listed as an ad owner
  if (!db_result(db_query('SELECT oid FROM {ad_owners} WHERE uid = %d AND aid = %d', $node->uid, $node->nid))) {
    ad_owners_add($node, $node->uid);
  }
  $header = array(
    array(
      'data' => t('Username'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Options'),
    ),
  );
  $sql = "SELECT a.uid, u.name FROM {ad_owners} a INNER JOIN {users} u ON a.uid = u.uid WHERE aid = %d";
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 25, 0, NULL, $node->nid);
  $rows = array();
  while ($owner = db_fetch_object($result)) {
    $row = array();
    $row[] = $owner->name;
    $options = array();

    // first option is 'permissions', plug-ins come afterwards
    $options[] = l(t('permissions'), 'node/' . $node->nid . '/adowners/' . $owner->uid . '/permissions');
    $options = array_merge($options, module_invoke_all('adowners', 'overview', $node->nid, $owner->uid));

    // node owner has to remain an ad owner
    if ($node->uid != $owner->uid) {
      $options[] = l(t('remove'), 'node/' . $node->nid . '/adowners/' . $owner->uid . '/remove');
    }
    $options = implode(' | ', $options);
    $row[] = $options;
    $rows[] = $row;
  }
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 25, 0);
  return $output;
}