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 (!$bug) { $message->error('alert: bad bug'); } if (!(((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo'))) { $message->error_permission(); } if ($bug['hidden'] AND !can_perform('canviewhidden')) { $message->error_permission(); } // setup logging require_once('./includes/class_history.php'); $log = new History(); $log->bugid = $bug['bugid']; // ################################################################### if ($_POST['do'] == 'update') { $pcv = parse_pcv_select($bugsys->in['pcv_select'], true); if (!$bugsys->in['summary']) { $message->error('you need to enter a summary'); } if (!$pcv) { $message->error('invalid product/component/version'); } $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)); // #*# need to put in permission checks here because we do not show the fields the user has no permission to change in the edit section so they'll be blank on update $db->query(" UPDATE " . TABLE_PREFIX . "bug SET summary = '" . $bugsys->in['summary'] . "', priority = " . intval($bugsys->in['priority']) . ", status = " . intval($bugsys->in['status']) . ", severity = " . intval($bugsys->in['severity']) . ", resolution = " . intval($bugsys->in['resolution']) . ", 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' ); $log->language = 'log_update_bug'; 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; // ------------------------------------------------------------------- // process comment stuff $hascomment = (!empty($bugsys->in['comment'])) ? true : false; if ($hascomment OR $autoaction['comment']) { if ($hascomment AND $autoaction['comment']) { $bugsys->in['comment'] .= "\n\n--------------- 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->language = 'log_new_comment'; $log->arguments = array($commentid); $log->log(); } } $message->redirect('done with update bug', "showreport.php?bugid=$bug[bugid]"); } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>