You are here

function workflow_tab_page in Workflow 5.2

Same name and namespace in other branches
  1. 5 workflow.module \workflow_tab_page()
  2. 6.2 workflow.pages.inc \workflow_tab_page()
  3. 6 workflow.pages.inc \workflow_tab_page()
  4. 7.2 workflow.pages.inc \workflow_tab_page()
  5. 7 workflow.pages.inc \workflow_tab_page()

Menu callback. Displays the workflow information for a node.

Parameters

$nid: Node ID of node for which workflow information will be displayed.

Return value

unknown

1 string reference to 'workflow_tab_page'
workflow_menu in ./workflow.module
Implementation of hook_menu().

File

./workflow.module, line 144

Code

function workflow_tab_page($nid) {
  $node = node_load($nid);
  drupal_set_title(check_plain($node->title));
  $wid = workflow_get_workflow_for_type($node->type);
  $states_per_page = variable_get('workflow_states_per_page', 20);
  $result = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 1 ORDER BY sid");
  while ($data = db_fetch_object($result)) {
    $states[$data->sid] = $data->state;
  }
  $deleted_states = array();
  $result = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 0 ORDER BY sid");
  while ($data = db_fetch_object($result)) {
    $deleted_states[$data->sid] = $data->state;
  }
  $current = workflow_node_current_state($node);

  // theme_workflow_current_state() must run state through check_plain().
  $output = '<p>' . t('Current state: !state', array(
    '!state' => theme('workflow_current_state', $states[$current]),
  )) . "</p>\n";
  $output .= drupal_get_form('workflow_tab_form', $node, $wid, $states, $current);
  $result = pager_query("SELECT h.*, u.name FROM {workflow_node_history} h LEFT JOIN {users} u ON h.uid = u.uid WHERE nid = %d ORDER BY hid DESC", $states_per_page, 0, NULL, $nid);
  $rows = array();
  while ($history = db_fetch_object($result)) {
    if ($history->sid == $current && !isset($deleted_states[$history->sid]) && !isset($current_themed)) {

      // Theme the current state differently so it stands out.
      $state_name = theme('workflow_current_state', $states[$history->sid]);

      // Make a note that we have themed the current state; other times in the history
      // of this node where the node was in this state do not need to be specially themed.
      $current_themed = TRUE;
    }
    elseif (isset($deleted_states[$history->sid])) {

      // The state has been deleted, but we include it in the history.
      $state_name = theme('workflow_deleted_state', $deleted_states[$history->sid]);
      $footer_needed = TRUE;
    }
    else {

      // Regular state.
      $state_name = check_plain(t($states[$history->sid]));
    }
    if (isset($deleted_states[$history->old_sid])) {
      $old_state_name = theme('workflow_deleted_state', $deleted_states[$history->old_sid]);
      $footer_needed = TRUE;
    }
    else {
      $old_state_name = check_plain(t($states[$history->old_sid]));
    }
    $rows[] = theme('workflow_history_table_row', $history, $old_state_name, $state_name);
  }
  $output .= theme('workflow_history_table', $rows, !empty($footer_needed));
  $output .= theme('pager', $states_per_page);
  return $output;
}