queryFirst(" SELECT 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) WHERE bug.bugid = " . $input->inputClean('bugid', TYPE_UINT) ); if (!$bug) { $message->error(L_INVALID_ID); } if (!check_bug_permissions($bug)) { $message->errorPermission(); } // setup logging require_once('./includes/class_logging.php'); $log = new Logging(); $log->setBugId($bug['bugid']); $notif = new NotificationCenter(); $bugapi = new BugAPI(); $bugapi->set('bugid', $input->in['bugid']); $bugapi->fetch(); // ################################################################### if ($_POST['do'] == 'kill') { if (!can_perform('candeletedata', $bug['product'])) { $message->errorPermission(); } $bugapi->remove(); $message->redirect(T('The entire bug has been deleted.'), 'index.php'); } // ################################################################### if ($_REQUEST['do'] == 'delete') { if (!can_perform('candeletedata', $bug['product'])) { $message->errorPermission(); } $message->confirm(T('Are you sure you want to delete this bug? Doing so will destroy all associated data, including comments, attachments, and votes. We strongly recommend only deleting span records and nothing else as users may wish to go back and look at any bug to check its status.'), 'editreport.php', 'kill', T('Delete Bug Permanently'), 'showreport.php?bugid=' . $bug['bugid'], array('bugid' => $bug['bugid'])); } // ################################################################### if ($_POST['do'] == 'update') { if (!((can_perform('caneditown', $bug['product']) && bugdar::$userinfo['userid'] == $bug['userid']) || (can_perform('caneditother', $bug['product']) && bugdar::$userinfo['userid'] != $bug['userid'])) && !can_perform('canpostcomments', $bug['product'])) { $message->errorPermission(); } $log->addData(true, $bugapi->record, $log->getCommonFields(), true); // ------------------------------------------------------------------- // handle automations if ($input->in['automation']) { $automation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $input->inputClean('automation', TYPE_UINT)); if ($automation) { $automation['fields'] = unserialize($automation['fieldchanges']); if (is_array($automation['fields']['builtin'])) { foreach ($automation['fields']['builtin'] AS $field => $value) { $input->in["$field"] = $value; } } if (is_array($automation['fields']['custom'])) { foreach ($automation['fields']['custom'] AS $field => $value) { $input->in["custom$field"] = $value; } } } } // ------------------------------------------------------------------- // process comment stuff if ($input->in['comment'] OR $automation['comment']) { if (!empty($input->in['comment']) AND $automation['comment']) { $commenttext = $input->in['comment'] . "\n\n" . T('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment']; } else if (empty($input->in['comment']) AND $automation['comment']) { $commenttext = $automation['comment']; } else { $commenttext = $input->in['comment']; } $comment = new CommentAPI(); $comment->set('bugid', $input->in['bugid']); $comment->set('userid', bugdar::$userinfo['userid']); $comment->set('comment', $commenttext); $comment->set('parselinks', $input->in['parselinks']); $comment->insert(); // we redefine the bug data later, but it needs to be here in order to generate the user list $notif->setBugData($bugapi->record); $notif->sendNewCommentNotice($comment->values); $bugapi->set('lastposttime', $comment->values['dateline']); $bugapi->set('lastpostby', bugdar::$userinfo['userid']); $bugapi->set('lastpostbyname', bugdar::$userinfo['displayname']); $bugapi->set('hiddenlastposttime', $comment->values['dateline']); $bugapi->set('hiddenlastpostby', bugdar::$userinfo['userid']); $bugapi->set('hiddenlastpostbyname', bugdar::$userinfo['displayname']); if (!((can_perform('caneditown', $bug['product']) AND bugdar::$userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND bugdar::$userinfo['userid'] != $bug['userid']))) { $bugapi->update(); $notif->finalize(); $message->redirect(T('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]"); } } // ------------------------------------------------------------------- // do update stuff $dependencies = preg_split('#([^0-9].*?)#', $input->in['dependency'], -1, PREG_SPLIT_NO_EMPTY); $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies)); if ((can_perform('caneditown', $bug['product']) && bugdar::$userinfo['userid'] == $bug['userid']) || (can_perform('caneditother', $bug['product']) && bugdar::$userinfo['userid'] != $bug['userid'])) { $bugapi->set('summary', $input->in['summary']); $bugapi->set('severity', $input->in['severity']); $bugapi->set('duplicateof', $input->in['duplicateof']); $bugapi->set('dependency', $dependencies); $bugapi->set('hidden', $input->in['hidden']); $product = explode(',', $input->in['product']); $bugapi->set('product', $product[0]); $bugapi->set('component', $product[1]); $bugapi->set('version', $product[2]); } if (can_perform('canchangestatus', $bug['product'])) { $bugapi->set('priority', $input->in['priority']); $bugapi->set('status', $input->in['status']); $bugapi->set('resolution', $input->in['resolution']); } if (can_perform('canassign', $bug['product'])) { $bugapi->set('assignedto', $input->in['assignedto']); } process_custom_fields($bugapi, $message, false); // ------------------------------------------------------------------- // handle logging and perform updates $notif->setBugData($bugapi->record, array_merge($bugapi->record, $bugapi->values)); $log->addData(false, $bugapi->values, $log->getCommonFields(), true); if (!$message->hasErrors()) { $bugapi->update(); } else { $message->error(); } // ------------------------------------------------------------------- // do diff history $log->updateHistory(); $notif->sendBugChangeNotice(); $notif->finalize(); $message->redirect(T('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]"); } ?>