query_first(" SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail FROM " . TABLE_PREFIX . "bug AS bug LEFT JOIN " . TABLE_PREFIX . "user AS user ON (bug.userid = user.userid) LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill ON (bug.bugid = bugvaluefill.bugid) WHERE bug.bugid = " . intval($bugsys->in['bugid']) ); if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['productid'])) { $message->error_permission(); } if (!$bug) { $message->error($lang->getlex('error_invalid_id')); } if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid'])) { $message->error_permission(); } // setup logging require_once('./includes/class_history.php'); $log = new History(); $log->bugid = $bug['bugid']; // ################################################################### if ($_POST['do'] == 'update') { // ------------------------------------------------------------------- // process comment stuff if (!((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid']))) { $hascomment = (!empty($bugsys->in['comment'])) ? true : false; if ($hascomment OR $autoaction['comment']) { if ($hascomment AND $autoaction['comment']) { $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment']; } else if (!$hascomment AND $autoaction['comment']) { $bugsys->in['comment'] = $autoaction['comment']; } $bugsys->in['comment_parsed'] = $bugsys->in['comment']; if (!$bugsys->options['allowhtml']) { $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']); } $time = TIMENOW; $db->query(" INSERT INTO " . TABLE_PREFIX . "comment (bugid, userid, dateline, comment, comment_parsed) VALUES (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ", $time, '" . $bugsys->in['comment'] . "', '" . nl2br($bugsys->in['comment_parsed']) . "' )" ); $commentid = $db->insert_id(); $db->query(" UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . ", hiddenlastposttime = $time, hiddenlastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = " . intval($bugsys->in['bugid']) ); if ($hascomment) { $log->arguments = array($commentid); $log->log(); } } $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]"); } // ------------------------------------------------------------------- // do update stuff $pcv = parse_pcv_select($bugsys->in['pcv_select'], true); if (!$bugsys->in['summary']) { $message->error($lang->string('You need to enter a summary for this bug.')); } if (!$pcv) { $message->error($lang->string('Invalid product/component/version selected.')); } $hist[0] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]"); $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); // ------------------------------------------------------------------- // start updates // auto action $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction'])); if ($autoaction) { $autoaction['fields'] = unserialize($autoaction['fieldchanges']); foreach ($autoaction['fields']['builtin'] AS $field => $value) { $bugsys->in["$field"] = $value; } foreach ($autoaction['fields']['custom'] AS $field => $value) { $bugsys->in["field$field"] = $value; } } process_custom_fields($bug['bugid']); $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY); $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies)); $db->query(" UPDATE " . TABLE_PREFIX . "bug SET summary = '" . $bugsys->in['summary'] . "', severity = " . intval($bugsys->in['severity']) . "," . (can_perform('canchangestatus', $bug['productid']) ? " priority = " . intval($bugsys->in['priority']) . ", status = " . intval($bugsys->in['status']) . ", resolution = " . intval($bugsys->in['resolution']) . "," : '') . " " . (can_perform('canassign', $bug['productid']) ? "assignedto = " . intval($bugsys->in['assignedto']) . "," : '') . " duplicateof = " . intval($bugsys->in['duplicateof']) . ", dependency = '$dependencies', productid = " . $pcv['product'] . ", componentid = " . $pcv['component'] . ", versionid = " . $pcv['version'] . ", hidden = " . intval($bugsys->in['hidden']) . " WHERE bugid = $bug[bugid]" ); // ------------------------------------------------------------------- // do diff history $hist[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[bugid]"); $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"); $diff[0] = array_diff_assoc($hist[0], $hist[1]); $diff[1] = array_diff_assoc($hist[1], $hist[0]); $lookupindex = array( 'status' => 'status', 'severity' => 'severity', 'priority' => 'priority', 'versionid' => 'version', 'assignedto' => 'assignto', 'resolution' => 'resolution', 'productid' => 'product', 'componentid' => 'product' ); foreach ($diff AS $num => $diffs) { foreach ($diffs AS $key => $value) { if (!isset($lookupindex["$key"])) { continue; } $ref = $lookupindex["$key"]; $temp =& $bugsys->datastore["$ref"]["$value"]; $thevalue = $temp["$ref"]; $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')'; if ($key == 'assignedto') { $thevalue = (($temp['userid']) ? construct_user_display($temp) : ''); $idbit = ''; } else if ($key == 'productid' OR $key == 'componentid') { $ref = 'product'; $thevalue = $temp['title']; } $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : ''); } } foreach ($diff[1] AS $key => $value) { $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"])); } $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]); $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]); if ($noinitialcustom === false) { $canallowempty = true; $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'"); while ($box = $db->fetch_array($checkbox)) { $boxlist[] = 'field' . $box['fieldid']; } } foreach ($diff2[1] AS $key => $value) { if (in_array($key, $boxlist) AND $canallowempty) { $log->allowempty = true; } else { $log->allowempty = false; } if ($key == 'bugid') { continue; } $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"])); } $log->allowempty = false; // ------------------------------------------------------------------- // more comment $hascomment = (!empty($bugsys->in['comment'])) ? true : false; if ($hascomment OR $autoaction['comment']) { if ($hascomment AND $autoaction['comment']) { $bugsys->in['comment'] .= "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment']; } else if (!$hascomment AND $autoaction['comment']) { $bugsys->in['comment'] = $autoaction['comment']; } $bugsys->in['comment_parsed'] = $bugsys->in['comment']; if (!$bugsys->options['allowhtml']) { $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']); } $time = TIMENOW; $db->query(" INSERT INTO " . TABLE_PREFIX . "comment (bugid, userid, dateline, comment, comment_parsed) VALUES (" . intval($bugsys->in['bugid']) . ", " . $bugsys->userinfo['userid'] . ", $time, '" . $bugsys->in['comment'] . "', '" . nl2br($bugsys->in['comment_parsed']) . "' )" ); $commentid = $db->insert_id(); $db->query(" UPDATE " . TABLE_PREFIX . "bug SET lastposttime = $time, lastpostby = " . $bugsys->userinfo['userid'] . ", hiddenlastposttime = $time, hiddenlastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = " . intval($bugsys->in['bugid']) ); } $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]"); } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>