You are here

function subscriptions_content_node_form in Subscriptions 5.2

Same name and namespace in other branches
  1. 6 subscriptions_content.module \subscriptions_content_node_form()

Build the Thread subscriptions form at user/UID/subscriptions/node.

1 string reference to 'subscriptions_content_node_form'
subscriptions_content_page_node in ./subscriptions_content.module
Subscriptions page callback: List thread subscriptions.

File

./subscriptions_content.module, line 929
Subscriptions to content events

Code

function subscriptions_content_node_form($account, $form) {
  $uid = $account->uid;
  $subscriptions = array();
  $sql = db_rewrite_sql("\n    SELECT s.value, s.send_interval, s.author_uid, s.send_comments, s.send_updates, n.title, n.status\n    FROM {node} n\n    INNER JOIN {subscriptions} s ON " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "n.nid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " = s.value\n    WHERE s.module = 'node' AND s.field = 'nid' AND s.recipient_uid = %d\n    ORDER BY s.author_uid");
  $result = db_query($sql, $uid);
  while ($s = db_fetch_array($result)) {
    $subscriptions[$s['value']][$s['author_uid']] = $s;
  }
  $form[0] = array(
    '#type' => 'item',
    '#title' => '',
    '#tree' => TRUE,
    '#theme' => 'subscriptions_form_table',
  );
  $defaults = array();
  foreach ($subscriptions as $nid => $bundle) {
    foreach ($bundle as $author_uid => $subscription) {
      $title = truncate_utf8($subscription['title'], 40);
      if ($title != $subscription['title']) {
        $title .= '...';
      }
      $title = l($title, 'node/' . $subscription['value']);
      if (!$subscription['status']) {
        if (user_access('administer nodes')) {
          $title = SUBSCRIPTIONS_UNAVAILABLE . ' ' . $title;
        }
        else {
          continue;
        }
      }
      subscriptions_form_helper($form[0], $defaults, $author_uid, $subscription['value'], $title, $subscription);
    }
  }
  unset($form[0]['author']);
  if (count(element_children($form[0]))) {
    $form[0]['defaults'] = array(
      '#type' => 'value',
      '#value' => $defaults,
    );
    subscriptions_form_column_filter($form[0], $uid);
    $form['#tree'] = TRUE;
    $form['uid'] = array(
      '#type' => 'value',
      '#value' => $uid,
    );
    $form['access_key'] = array(
      '#type' => 'value',
      '#value' => 'node',
    );
    $form['module'] = array(
      '#type' => 'value',
      '#value' => 'node',
    );
    $form['field'] = array(
      '#type' => 'value',
      '#value' => 'nid',
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
      '#weight' => 10,
    );
    $form['#submit']['subscriptions_page_form_submit'] = array();
  }
  else {
    $form = array(
      array(
        '#type' => 'item',
        '#value' => t('There are no subscribed pages.'),
      ),
    );
  }
  return $form;
}