You are here

function ad_owners_overview in Advertisement 5

Same name and namespace in other branches
  1. 6.3 owners/ad_owners.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_menu in ./ad.module
Implementation of hook_menu().

File

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

Code

function ad_owners_overview($node) {

  // 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->nid, $node->uid);
  }
  $header = array(
    array(
      'data' => t('Username'),
      'field' => 'uid',
    ),
    array(
      'data' => t('Options'),
    ),
  );
  drupal_set_title('owners');
  $sql = "SELECT uid FROM {ad_owners} WHERE aid = {$node->nid}";
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 25);
  $rows = array();
  while ($ad = db_fetch_object($result)) {
    $row = array();
    $user = user_load(array(
      'uid' => $ad->uid,
    ));
    $row[] = $user->name;
    $options = array();

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

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