Index: project_issue/comment.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/comment.inc,v retrieving revision 1.74 diff -u -p -r1.74 comment.inc --- project_issue/comment.inc 5 Jan 2007 00:21:08 -0000 1.74 +++ project_issue/comment.inc 9 Jan 2007 22:00:48 -0000 @@ -1,276 +1,82 @@ arg(3), 'type' => 'project_issue')); - - if ($_POST['op'] == t('Preview') || $_POST['op'] == t('Submit')) { - project_comment_validate($edit); - } else { - foreach (array('nid', 'type', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { - $edit->$var = $node->$var; +function project_issue_comment(&$arg, $op) { + if (is_object($arg)) { + $nid = $arg->nid; + } + if (is_array($arg)) { + $nid = isset($arg['nid']['#value']) ? $arg['nid']['#value'] : $arg['nid']; + } + $node = node_load($nid); + if ($node->type != 'project_issue') { + return; + } + + switch ($op) { + case 'form': + // $arg is a form + if (!$node->comment_count) { + foreach (array('nid', 'type', 'pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { + $edit->$var = $node->$var; + } } - project_comment_validate($edit); - } - $output .= drupal_get_form('project_comment_form', $edit); - - $breadcrumb = drupal_get_breadcrumb(); - $breadcrumb[] = l($node->title, "node/$node->nid"); - drupal_set_breadcrumb($breadcrumb); - drupal_set_title(t('New comment')); - switch ($_POST['op'] ? $_POST['op'] : arg(2)) { - case 'add': - $output .= node_view($node, NULL, TRUE); - return $output; - break; - case t('Preview'): - return $output; - break; - case t('Submit'): - if (!form_get_errors()) { - $edit->nid = $node->nid; - - project_comment_save($edit); - drupal_goto("node/$node->nid"); - } else { - return $output; - } - break; - } - } -} - -function project_comment_form($edit, $param = NULL) { - $op = $_POST['op']; - if (isset($param)) { - $form = array( - '#method' => $param['method'], - '#action' => $param['action'], - '#attributes' => $param['options'], - ); - } else { - $form['#attributes'] = array('enctype' => 'multipart/form-data'); - } - $form['#prefix'] = '
'; - $form['#suffix'] = '
'; - $form['project_issue_form'] = project_issue_form($edit, $param); - unset($form['project_issue_form']['#prefix']); - unset($form['project_issue_form']['#suffix']); - - _project_issue_form_add_required_fields($form['project_issue_form'], FALSE); - if ($edit->cid) { - $form['cid']= array('#type' => 'hidden', '#value' => $edit->cid); - } - $form['preview'] = array('#type' => 'button', '#value' => t('Preview')); - if (!form_get_errors()) { - $form['submit'] = array('#type' => 'button', '#value' => t('Submit')); - } - if ($op == t('Preview')) { - $form['#after_build'] = array('project_comment_form_add_preview'); + else { + $cid = $arg['cid']['#value'] ? $arg['cid']['#value'] : db_result(db_query('SELECT MAX(cid) FROM {comments} WHERE nid = %d', $node->nid)); + $edit = db_fetch_object(db_query('SELECT * FROM {project_issue_comment} WHERE cid = %d', $cid)); + } + $form = drupal_retrieve_form('project_issue_form', $edit, NULL); + $form['project_info']['#weight'] = -2; + $form['issue_info']['#weight'] = -1; + $form['#prefix'] = '
'; + $form['#suffix'] = '
'; + unset($form['page'], $form['issue_details']); + return $form; + case 'validate': + project_issue_comment_validate($arg); + break; + case 'insert': case 'update': + // $arg is form_values + db_query("INSERT INTO {project_issue_comment} (nid, title, cid, prid, rid, component, category, priority, assigned, sid) VALUES (%d, '%s', %d, %d, %d, '%s', '%s', %d, %d, %d)", $arg['nid'], $arg['title'], $arg['cid'], $arg['prid'], $arg['rid'], $arg['component'], $arg['category'], $arg['priority'], $arg['assigned'], $arg['sid']); + project_issue_update($arg); + return; + case 'view': + if ($additional = project_issue_comment_view($arg->nid, $arg)) { + $arg->comment = '
'. $additional .'
' . $arg->comment; + } + break; } - return $form; } -function project_comment_validate(&$edit) { - global $user; - - $edit->uid = $user->uid; - $edit->name = $user->name; +function project_issue_comment_view($nid, $comment = NULL) { + static $additions; - if ($edit->cid) { - $comment = project_comment_load($edit->cid); - $edit->nid = $comment->nid; + if (!isset($comment)) { + $additions[$nid][0] = node_load($nid); + $additions[$nid][0]->prid = $additions[$nid][0]->pid; + return; } - - $edit->comment = true; - - project_issue_comment_validate($edit); - $edit->validated = true; -} - -function project_comment_view($node, $main = 0) { - global $user; + $current = db_fetch_object(db_query('SELECT * FROM {project_issue_comment} WHERE cid = %d', $comment->cid)); + $n = count($additions[$nid]) - 1; + $old = $additions[$nid][$n]; $rows = array(); - $result = db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.nid = %d ORDER BY p.created ASC', $node->nid); - if (db_num_rows($result)) { - $output = '
'; - $i = 0; - while ($comment = db_fetch_object($result)) { - $comment->body = db_decode_blob($comment->body); - $i++; - $output .= _project_comment_view_single($comment, $i); - } - $output .= '
'; - return theme('box', t('Updates'), $output); - } -} - -/** - * Private method to view a single project comment (issue followup). - * - * @param $comment - * An array or object of the comment to view. - * @param $count - * The integer that shows what number of comment this is. - * - * @return - * A string of validated output to theme/display. - * - */ -function _project_comment_view_single($comment, $count) { - $comment = (object)$comment; - $summary = array(); - $output = ''; - - $fields = array( - 'title' => 'Title', - 'pid' => 'Project', - 'rid' => 'Version', - 'component' => 'Component', - 'category' => 'Category', - 'priority' => 'Priority', - 'assigned' => 'Assigned to', - 'sid' => 'Status' + $labels = array( + 'title' => t('Title'), + 'prid' => t('Project'), + 'rid' => t('Version'), + 'component' => t('Component'), + 'category' => t('Category'), + 'priority' => t('Priority'), + 'assigned' => t('Assigned to'), + 'sid' => t('Status'), ); - - // If we got this from the DB, we'll have a $data field to unserialize. - $comment = drupal_unpack($comment); - - // Print out what changed about the issue with this comment. If the - // comment is in the DB, we'll have 'old' and 'new' fields from the - // 'data' field, which record exactly what changed. If not, we'll - // load the origial node and compare against that. - if (!isset($comment->data)) { - $node = node_load(array('nid' => arg(3), 'type' => 'project_issue')); - } - foreach ($fields as $field => $text) { - if (isset($comment->old->$field) && isset($comment->new->$field)) { - $summary[] = array( - t($text) .':', - project_mail_summary($field, $comment->old->$field), - '» '. project_mail_summary($field, $comment->new->$field) + foreach ($labels as $field => $text) { + if ($old->$field != $current->$field) { + $rows[] = array( + $labels[$field] .':', + project_mail_summary($field, $old->$field), + '» '. project_mail_summary($field, $current->$field) ); } - elseif (isset($node->$field) && isset($comment->$field) && $node->$field != $comment->$field ) { - $summary[] = array( - t($text) .':', - project_mail_summary($field, $node->$field), - '» '. project_mail_summary($field, $comment->$field) - ); - } - } - - if ($comment->file_path && file_exists($comment->file_path)) { - $summary[] = array(t('Attachment:'), ''. basename($comment->file_path) .' ('. format_size($comment->file_size) .')'); - } - - if ($summary || $comment->body) { - if ($count) { - $output .= '
'; - $output .= t('!count submitted by !user on !date', array('!count' => l("#$count", "node/$comment->nid", array ('id' => "comment-$comment->cid", 'name' => "comment-$comment->cid"), NULL, "comment-$comment->cid"), '!user' => theme('username', $comment), '!date' => format_date($comment->created))) . theme('mark', node_mark($comment->nid, $comment->changed)); - $output .= '
'; - } - if ($summary) { - $output .= '
'; - $output .= theme('table', array(), $summary); - $output .= '
'; - } - if ($comment->body) { - $output .= '
'; - $output .= check_markup($comment->body); - $output .= '
'; - } - } - return $output; -} - -function project_comment_load($cid) { - $object = db_fetch_object(db_query('SELECT p.*, u.name FROM {project_comments} p INNER JOIN {users} u USING (uid) WHERE p.cid = %d ORDER BY p.created DESC', $cid)); - $object->body = db_decode_blob($object->body); - return $object; -} - -function project_comment_save($edit) { - global $user; - - if (empty($edit->cid)) { - $edit->cid = db_next_id('{project}_cid'); - if ($edit->file) { - $file = file_save_upload($edit->file, variable_get('project_directory_issues', 'issues')); - unset($edit->file); - } - - if (empty($edit->uid)) { - $edit->uid = $user->uid; - } - $node = node_load(array('nid' => $edit->nid, 'type' => 'project_issue')); - - // Check if comment changed any of the state values and update the node if necessary - foreach (array('pid', 'rid', 'category', 'component', 'priority', 'assigned', 'sid', 'title') as $var) { - if ($node->$var != $edit->$var) { - $data['old']->$var = $node->$var; - $data['new']->$var = $edit->$var; - $node->$var = $edit->$var; - } - } - - watchdog('content', t('project_issue: added comment %title', array('%title' => $edit->title)), WATCHDOG_NOTICE, l('view', "node/$node->nid")); - $node->changed = time(); - db_query("INSERT INTO {project_comments} (cid, nid, uid, created, changed, body, data, file_path, file_mime, file_size) VALUES (%d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', %d)", $edit->cid, $edit->nid, $edit->uid, $node->changed, $node->changed, $edit->body, serialize($data), $file->filepath, $file->filemime, $file->filesize); - - // Update node_comment_statistics so the tracker page lists the number of comments - $count = db_result(db_query('SELECT COUNT(cid) FROM {project_comments} WHERE nid = %d', $edit->nid)); - db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, time(), $user->name, $user->uid, $edit->nid); - - node_save($node); - } - - return $edit->cid; -} - -/** - * Form API callback for previewing a project comment. - * - * @param $form - * The form to add the preview information to. - * @param $edit - * The form values for the comment to preview. - * - * @return - * The modified form to render. - * - */ -function project_comment_form_add_preview($form, $edit) { - drupal_set_title(t('Preview comment')); - if (is_array($edit)) { - $comment = (object)$edit; } - else { - $comment = $edit; - } - project_comment_validate($comment); - - // Preview the comment with security check. - if (!form_get_errors()) { - $output = _project_comment_view_single($comment, 0); - } - - $form['comment_preview'] = array( - '#value' => $output, - '#weight' => -100, - '#prefix' => '
', - '#suffix' => '
', - ); - - $output = ''; - if (is_numeric(arg(3))) { - $node = node_load(array('nid' => arg(3), 'type' => 'project_issue')); - $output .= node_view($node, NULL, TRUE); - $form['comment_preview_below'] = array('#value' => $output, '#weight' => 100); - } - return $form; -} + $additions[$nid][] = $current; + return theme('table', array(), $rows); +} \ No newline at end of file Index: project_issue/issue.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/issue.inc,v retrieving revision 1.217 diff -u -p -r1.217 issue.inc --- project_issue/issue.inc 6 Jan 2007 19:17:10 -0000 1.217 +++ project_issue/issue.inc 9 Jan 2007 22:00:48 -0000 @@ -504,6 +503,12 @@ function project_issue_form($node, $para // Fetch a list of all projects to make swapping simpler $uris = NULL; $projects = array(t('')) + project_projects_select_options($uris); + if ($node->prid && !$node->pid) { + $node->pid = $node->prid; + } + if (!$node->pid && $node->prid) { + $node->pid = $node->prid; + } // Try to find the active project, if not already known. if (empty($node->pid)) { @@ -565,7 +569,7 @@ function project_issue_form($node, $para '#prefix' => '
', '#suffix' => '
', ); - $form['project_info']['pid'] = array( + $form['project_info']['prid'] = array( '#type' => 'select', '#title' => t('Project'), '#default_value' => $node->pid, @@ -746,12 +750,12 @@ function project_issue_node_form_validat global $form_values; $edit = $_POST; - if (!$form_values['pid']) { - form_set_error('pid', t('You have to specify a valid project.')); + if (!$form_values['prid']) { + form_set_error('prid', t('You have to specify a valid project.')); } if ($form_values['page'] == 2) { - if ($form_values['pid'] && $project = node_load($form_values['pid'])) { + if ($form_values['prid'] && $project = node_load($form_values['prid'])) { $node->title = $form_values['title']; if (module_exists('project_release') && $releases = project_release_get_releases($project, 0)) { @@ -850,7 +854,7 @@ function project_issue_view($node, $teas $node = node_prepare($node, $teaser); if (!$teaser && $page) { - + project_issue_comment_view($node->nid); $node->content['#prefix'] = '
'; $node->content['#suffix'] = '
'; @@ -882,20 +886,21 @@ function project_issue_view($node, $teas '#value' => '
'. t('Description') .'
', '#weight' => -3, ); +/* $node->content['project_issue_comments'] = array( '#value' => project_comment_view($node), '#weight' => 2, ); - +*/ // Breadcrumb navigation - $breadcrumb[] = array('path' => 'project', 'title' => t('Projects')); + $breadcrumb[] = array('path' => 'project', 'title' => t('Projects')); if (project_use_taxonomy()) { $taxonomy_terms = taxonomy_node_get_terms($node->pid); $term = reset($taxonomy_terms); $breadcrumb[] = array('path' => 'project/'. $term->name, 'title' => $term->name); } $breadcrumb[] = array('path' => 'node/'. $project->nid, 'title' => $project->title); - $breadcrumb[] = array('path' => 'project/issues/'. $project->uri, 'title' => t('Issues')); + $breadcrumb[] = array('path' => 'project/issues/'. $project->uri, 'title' => t('issues')); $breadcrumb[] = array('path' => 'node/'. $node->nid); menu_set_location($breadcrumb); } @@ -912,7 +917,7 @@ function project_issue_insert($node) { $file = file_save_upload($node->file, variable_get('project_directory_issues', 'issues')); } - db_query("INSERT INTO {project_issues} (nid, pid, category, component, priority, rid, assigned, sid, file_path, file_mime, file_size) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', '%s', %d)", $node->nid, $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, $file->filepath, $file->filemime, $file->filesize); + db_query("INSERT INTO {project_issues} (nid, pid, category, component, priority, rid, assigned, sid, file_path, file_mime, file_size) VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, '%s', '%s', %d)", $node->nid, $node->pid, $node->category, $node->component, $node->priority, $node->prid, $node->assigned, $node->sid, $file->filepath, $file->filemime, $file->filesize); project_mail_notify($node); } @@ -921,10 +926,10 @@ function project_issue_update($node) { // Remove old file. file_delete(db_result(db_query('SELECT file_path FROM {project_issues} WHERE nid = %d', $node->nid))); $file = file_save_upload($node->file, variable_get('project_directory_issues', 'issues')); - db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d, file_path = '%s', file_mime = '%s', file_size = %d WHERE nid = %d", $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, $file->filepath, $file->filemime, $file->filesize, $node->nid); + db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d, file_path = '%s', file_mime = '%s', file_size = %d WHERE nid = %d", $node->pid, $node->category, $node->component, $node->priority, $node->prid, $node->assigned, $node->sid, $file->filepath, $file->filemime, $file->filesize, $node->nid); } else { - db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d WHERE nid = %d", $node->pid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, $node->nid); + db_query("UPDATE {project_issues} SET pid = %d, category = '%s', component = '%s', priority = %d, rid = %d, assigned = %d, sid = %d WHERE nid = %d", $node->prid, $node->category, $node->component, $node->priority, $node->rid, $node->assigned, $node->sid, $node->nid); } project_mail_notify($node); } @@ -124,23 +124,6 @@ function project_issue_cron() { } } -function project_issue_link($type, $node = 0, $main = 0) { - $links = array(); - switch ($type) { - case 'node': - if ($node->type == 'project_issue') { - if (user_access('create project issues')) { - $links['project_issue_follow_up'] = array( - 'title' => t('Follow up'), - 'href' => "project/comments/add/$node->nid", - ); - } - } - break; - } - return $links; -} - function project_issue_menu($may_cache) { $items = array(); global $user; @@ -222,15 +205,6 @@ function project_issue_menu($may_cache) 'type' => MENU_CALLBACK, 'weight' => 1, ); - - // Reply to issues - $items[] = array( - 'path' => 'project/comments', - 'title' => t('Comments'), - 'callback' => 'project_comment_page', - 'access' => $access, - 'type' => MENU_CALLBACK, - ); } else { // Authenticated users