? workflow_history.patch Index: workflow.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.install,v retrieving revision 1.2 diff -r1.2 workflow.install 41a42 > tab_roles varchar(60) NOT NULL default '', 83a85 > old_sid int(10) unsigned NOT NULL default '0', 86a89 > comment longtext, 138c141,151 < } \ No newline at end of file --- > } > > function workflow_update_2() { > $ret = array(); > > $ret[] = update_sql("ALTER TABLE {workflow_node_history} ADD old_sid int(10) unsigned AFTER nid"); > $ret[] = update_sql("ALTER TABLE {workflow_node_history} ADD comment longtext"); > $ret[] = update_sql("ALTER TABLE {workflows} ADD tab_roles varchar(60)"); > > return $ret; > } Index: workflow.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.module,v retrieving revision 1.37 diff -r1.37 workflow.module 88a89,108 > else { > if (arg(0) == 'node' && is_numeric(arg(1))) { > $node = node_load(arg(1)); > $wid = workflow_get_workflow_for_type($node->type); > if ($wid) { // workflow exists for this type > global $user; > $roles = array_merge(array('author'), array_keys($user->roles)); > $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid)); > $allowed_roles = $workflow->tab_roles ? explode(',', $workflow->tab_roles) : array(); > $items[] = array('path' => "node/$node->nid/workflow", > 'title' => t('workflow'), > 'access' => array_intersect($roles, $allowed_roles) || user_access('administer nodes'), > 'type' => MENU_LOCAL_TASK, > 'weight' => 2, > 'callback' => 'workflow_tab_page', > 'callback arguments' => arg(1), > ); > } > } > } 91a112,170 > function workflow_tab_page($nid) { > $node = node_load($nid); > $wid = workflow_get_workflow_for_type($node->type); > $states_per_page = 20; > $states = workflow_get_states($wid) + array(t('(creation)')); > $current = workflow_node_current_state($node); > > $output = "
Current state: " . check_plain($states[$current]) . "
\n"; > > $choices = workflow_field_choices($node); > $min = $states[$current] == t('(creation)') ? 1 : 2; > if (count($choices) >= $min) { // bail out if user has no new target state(s) > ksort($choices); > $wid = workflow_get_workflow_for_type($node->type); > $name = check_plain(workflow_get_name($wid)); > > $form = array(); > workflow_node_form($form, t('Change %s state', array('%s' => $name)), $name, $current, $choices); > $form['node'] = array( > '#type' => 'value', > '#value' => $node, > ); > > $form['submit'] = array( > '#type' => 'submit', > '#value' => t('Submit') > ); > > $output .= drupal_get_form('workflow_tab', $form); > } > > $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 stamp DESC", $states_per_page, 0, NULL, $nid); > $rows = array(); > while ($history = db_fetch_object($result)) { > $rows[] = array( > format_date($history->stamp), > check_plain($states[$history->old_sid]), > check_plain($states[$history->sid]), > theme('username', $history), > check_plain($history->comment) > ); > } > > $output .= theme('table', array(t('Date'), t('Old State'), t('New State'), t('By'), t('Comment')), $rows, array('class' => 'workflow_history'), t('Workflow History')); > $output .= theme('pager', $states_per_page); > return $output; > } > > function workflow_tab_submit($form_id, $form_values) { > $node = $form_values['node']; > $sid = $form_values['workflow']; > > // make sure new state is a valid choice > if (array_key_exists($sid, workflow_field_choices($node))) { > workflow_execute_transition($node, $sid, $form_values['workflow_comment']); // do transition > node_save($node); // ensure na_arbitrator is happy. > } > } > 136c215 < workflow_execute_transition($node, $sid); // do transition --- > workflow_execute_transition($node, $sid, $node->workflow_comment); // do transition 146a226,249 > * Add the actual form widgets for workflow change to the passed in form. > * > * @param array $form > * @param string $name > * @param string $current > * @param array $choices > */ > function workflow_node_form(&$form, $title, $name, $current, $choices) { > $form['workflow'][$name] = array( > '#type' => 'radios', > '#title' => $title, > '#options' => $choices, > '#name' => $name, > '#parents' => array('workflow'), > '#default_value' => $current > ); > $form['workflow']['workflow_comment'] = array( > '#type' => 'textarea', > '#title' => t('Comment'), > '#description' => t('Enter a comment to put in the workflow log; a transition is not required to enter a comment, nor is a comment required to enter a transition.'), > ); > } > > /** 156c259,260 < if (count($choices) < 2) { // bail out if user has no new target state(s) --- > $min = $states[$current] == t('(creation)') ? 1 : 2; > if (count($choices) < $min) { // bail out if user has no new target state(s) 178,185c282 < $form['workflow'][$name] = array( < '#type' => 'radios', < '#title' => $name, < '#options' => $choices, < '#name' => $name, < '#parents' => array('workflow'), < '#default_value' => $current < ); --- > workflow_node_form($form, $name, $name, $current, $choices); 196c293 < function workflow_execute_transition($node, $sid) { --- > function workflow_execute_transition($node, $sid, $comment = NULL) { 198a296,299 > // Write comment into history though. > if ($comment) { > _workflow_write_history($node, $sid, $comment); > } 210c311 < if (!workflow_transition_allowed($tid, array_keys($user->roles))) { --- > if (!workflow_transition_allowed($tid, array_merge(array_keys($user->roles), 'author'))) { 224c325 < _workflow_node_to_state($node, $sid); // change the state --- > _workflow_node_to_state($node, $sid, $comment); // change the state 499c600,601 < $name = workflow_get_name($wid); --- > // $name = workflow_get_name($wid); > $workflow = db_fetch_object(db_query("SELECT * FROM {workflows} WHERE wid = %d", $wid)); 502c604 < '#default_value' => $name, --- > '#default_value' => $workflow->name, 506a609,622 > $form['tab'] = array( > '#type' => 'fieldset', > '#title' => t('Workflow tab permissions'), > '#collapsible' => TRUE, > '#collapsed' => FALSE, > ); > > $form['tab']['tab_roles'] = array( > '#type' => 'checkboxes', > '#options' => workflow_get_roles(), > '#default_value' => explode(',', $workflow->tab_roles), > '#description' => t('Select any roles that should have access to the workflow tab on nodes that have a workflow.'), > ); > 523,527c639 < $result = db_query('SELECT * FROM {role} ORDER BY name'); < $roles = array('author' => 'author'); < while ($data = db_fetch_object($result)) { < $roles[$data->rid] = $data->name; < } --- > $roles = workflow_get_roles(); 594c706 < workflow_update_name($form_values['wid'], $form_values['wf_name']); --- > workflow_update($form_values['wid'], $form_values['wf_name'], array_filter($form_values['tab_roles'])); 715,719c827 < $result = db_query('SELECT * FROM {role} ORDER BY name'); < $roles = array('author' => 'author'); < while ($data = db_fetch_object($result)) { < $roles[$data->rid] = $data->name; < } --- > $roles = workflow_get_roles(); 1127,1128c1235,1236 < function workflow_update_name($wid, $name) { < db_query("UPDATE {workflows} SET name = '%s' WHERE wid = %d", $name, $wid); --- > function workflow_update($wid, $name, $tab_roles) { > db_query("UPDATE {workflows} SET name = '%s', tab_roles = '%s' WHERE wid = %d", $name, implode(',', $tab_roles), $wid); 1341c1449 < function _workflow_node_to_state($node, $sid) { --- > function _workflow_node_to_state($node, $sid, $comment = NULL) { 1349c1457,1477 < db_query("INSERT INTO {workflow_node_history} (nid, sid, uid, stamp) VALUES (%d, %d, %d, %d)", $node->nid, $sid, $user->uid, time()); --- > _workflow_write_history($node, $sid, $comment); > } > > function _workflow_write_history($node, $sid, $comment) { > global $user; > db_query("INSERT INTO {workflow_node_history} (nid, old_sid, sid, uid, comment, stamp) VALUES (%d, %d, %d, %d, '%s', %d)", $node->nid, $node->_workflow, $sid, $user->uid, $comment, time()); > } > > /** > * Function to get a list of roles. Used kind of often. > */ > function workflow_get_roles() { > static $roles = NULL; > if (!$roles) { > $result = db_query('SELECT * FROM {role} ORDER BY name'); > $roles = array('author' => 'author'); > while ($data = db_fetch_object($result)) { > $roles[$data->rid] = $data->name; > } > } > return $roles; 1468c1596 < } \ No newline at end of file --- > }