123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- function workflow_tab_page($node = NULL) {
- drupal_set_title($node->title);
- $workflow = workflow_get_workflow_type_map_by_type($node->type);
- $states = array();
- $state_system_names = array();
- foreach (workflow_get_workflow_states() as $data) {
- $states[$data->sid] = check_plain(t($data->state));
- $state_system_names[$data->sid] = check_plain($data->state);
- }
- $deleted_states = array();
- $deleted_state_system_names = array();
- $options = array('status' => 0);
- foreach (workflow_get_workflow_states($options) as $data) {
- $deleted_states[$data->sid] = check_plain(t($data->state));
- $deleted_state_system_names[$data->sid] = check_plain($data->state);
- }
- $current = workflow_node_current_state($node);
-
- $current_state = theme('workflow_history_current_state', array('state_name' => $states[$current], 'state_system_name' => $state_system_names[$current], 'sid' => $current));
- $output = theme('workflow_current_state', array('state' => $states[$current], 'state_system_name' => $state_system_names[$current], 'sid' => $current));
-
-
- $choices = workflow_field_choices($node);
- if (count($choices) != 0 || count($choices) != 1 || $current != key($choices)) {
- $form = drupal_get_form('workflow_tab_form', $node, $workflow->wid, $states, $current);
- $output .= drupal_render($form);
- }
- $rows = array();
- foreach (workflow_get_workflow_node_history_by_nid($node->nid) as $history) {
- if ($history->sid == $current && !isset($deleted_states[$history->sid]) && !isset($current_themed)) {
-
- $state_name = theme('workflow_history_current_state', array('state_name' => $states[$history->sid], 'state_system_name' => $state_system_names[$history->sid], 'sid' => $history->sid));
-
-
- $current_themed = TRUE;
- }
- elseif (isset($deleted_states[$history->sid])) {
-
- $state_name = theme('workflow_deleted_state', array('state_name' => $deleted_states[$history->sid], 'state_system_name' => $deleted_state_system_names[$history->sid], 'sid' => $history->sid));
- $footer_needed = TRUE;
- }
- else {
-
- $state_name = check_plain(t($states[$history->sid]));
- }
- if (isset($deleted_states[$history->old_sid])) {
- $old_state_name = theme('workflow_deleted_state', array('state_name' => $deleted_states[$history->old_sid], 'state_system_name' => $deleted_state_system_names[$history->old_sid], 'sid' => $history->old_sid));
- $footer_needed = TRUE;
- }
- elseif (isset($states[$history->old_sid])) {
- $old_state_name = check_plain(t($states[$history->old_sid]));
- }
- else {
- $old_state_name = '*';
- }
- $variables = array(
- 'history' => $history,
- 'old_sid' => $history->old_sid,
- 'old_state_name' => $old_state_name,
- 'sid' => $history->sid,
- 'uid' => $history->uid,
- 'state_name' => $state_name,
- );
-
- drupal_alter('workflow_history', $variables);
- $rows[] = theme('workflow_history_table_row', $variables);
- }
-
- $rows[0]['class'][] = 'first';
- $last = count($rows) - 1;
- $rows[$last]['class'][] = 'last';
-
- if ($rows) {
- $output .= theme('workflow_history_table', array('rows' => $rows, 'footer' => !empty($footer_needed)));
- $output .= theme('pager', array('tags' => variable_get('workflow_states_per_page', 20)));
- }
- return $output;
- }
- function theme_workflow_history_table_row($variables) {
- $row = array();
- $old_state_name = $variables['old_state_name'];
- $state_name = $variables['state_name'];
- $history = $variables['history'];
- $account = user_load($variables['uid']);
- $row = array(
- 'data' => array(
- array('data' => format_date($history->stamp), 'class' => array('timestamp')),
- array('data' => $old_state_name, 'class' => array('previous-state-name')),
- array('data' => $state_name, 'class' => array('state-name')),
- array('data' => theme('username', array('account' => $account)), 'class' => array('user-name')),
- array('data' => filter_xss($history->comment), 'class' => array('log-comment')),
- ),
- 'class' => array('workflow_history_row'),
- );
- if (!empty($variables['extra'])) {
- $row['data'][] = $variables['extra'];
- }
- return $row;
- }
- function theme_workflow_history_table($variables) {
- $rows = $variables['rows'];
- $footer = $variables['footer'];
- $headers = array(t('Date'), t('Old State'), t('New State'), t('By'), t('Comment'));
- $output = theme('table', array('header' => $headers, 'rows' => $rows, 'caption' => t('Workflow History')));
- if ($footer) {
- $output .= t('*State is no longer available.');
- }
- return $output;
- }
- function theme_workflow_history_current_state($variables) {
- return check_plain(t($variables['state_name']));
- }
- function theme_workflow_deleted_state($variables) {
- return check_plain(t($variables['state_name'])) . '*';
- }
- function workflow_tab_form($form, $form_state, $node, $wid, $states, $current) {
-
- form_load_include($form_state, 'inc', 'workflow', 'workflow.pages');
-
- if (workflow_node_tab_access($node) === FALSE) {
- return;
- }
- $form['#tab'] = TRUE;
- $choices = workflow_field_choices($node);
- $min = ($states[$current] == t('(creation)') ? 1 : 2);
-
- if (count($choices) >= $min) {
- $workflow = workflow_get_workflow_type_map_by_type($node->type);
- $workflow = workflow_get_workflows_by_wid($workflow->wid);
- $form['#wf'] = $workflow;
- $form['#choices'] = $choices;
- $name = t($workflow->name);
- $timestamp = '';
- $comment = '';
-
- if (!empty($node->workflow_scheduled_timestamp) && !empty($node->workflow_scheduled_sid)) {
- global $user;
- if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) {
- $timezone = $user->timezone;
- }
- else {
- $timezone = variable_get('date_default_timezone', 0);
- }
-
- $current = $node->workflow_scheduled_sid;
- $timestamp = $node->workflow_scheduled_timestamp;
- $comment = $node->workflow_scheduled_comment;
- }
-
-
- workflow_node_form($form, $form_state, t('Change !name state', array('!name' => $name)), $name, $current, $choices, $timestamp, $comment);
- $form['node'] = array(
- '#type' => 'value',
- '#value' => $node,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update workflow'),
- );
- }
- return $form;
- }
- function workflow_tab_form_submit($form, &$form_state) {
-
- $node = $form_state['values']['node'];
- if (isset($form_state['values']['workflow'])) {
- $node->workflow = $form_state['values']['workflow'];
- $node->workflow_comment = isset($form_state['values']['workflow_comment']) ?
- $form_state['values']['workflow_comment'] : '';
- if (!empty($form_state['values']['workflow_scheduled'])) {
- $node->workflow_scheduled = $form_state['values']['workflow_scheduled'];
- }
- if (!empty($form_state['values']['workflow_scheduled_date'])) {
- $node->workflow_scheduled_date = $form_state['values']['workflow_scheduled_date'];
- }
- if (!empty($form_state['values']['workflow_scheduled_hour'])) {
- $node->workflow_scheduled_hour = $form_state['values']['workflow_scheduled_hour'];
- }
- if (!empty($form_state['values']['workflow_scheduled_timezone'])) {
- $node->workflow_scheduled_timezone = $form_state['values']['workflow_scheduled_timezone'];
- }
- }
-
-
-
-
- workflow_transition($node, $node->workflow);
- }
|