<?php
/*=====================================================================*\
|| ###################################################################
-|| # Bugdar [#]version[#]
-|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
+|| # Bugdar
+|| # Copyright 2002-2007 Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| # the Free Software Foundation; version 2 of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| ###################################################################
\*=====================================================================*/
-define('SVN', '$Id$');
$focus['showreport'] = 'focus';
require_once('./global.php');
require_once('./includes/functions_product.php');
+require_once('./includes/class_notification.php');
require_once('./includes/api_bug.php');
require_once('./includes/api_comment.php');
-$bug = $db->query_first("
- SELECT bugvaluefill.*, bug.*, user.email, user.displayname, user.showemail
+$bug = $db->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)
- LEFT JOIN " . TABLE_PREFIX . "bugvaluefill AS bugvaluefill
- ON (bug.bugid = bugvaluefill.bugid)
- WHERE bug.bugid = " . intval($bugsys->in['bugid'])
+ WHERE bug.bugid = " . $input->inputClean('bugid', TYPE_UINT)
);
-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'));
+ $message->error(L_INVALID_ID);
}
-if ($bug['hidden'] AND !can_perform('canviewhidden', $bug['productid']))
+if (!check_bug_permissions($bug))
{
- $message->error_permission();
+ $message->errorPermission();
}
// setup logging
-require_once('./includes/class_history.php');
-$log = new History();
-$log->bugid = $bug['bugid'];
+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'] == 'update')
+if ($_POST['do'] == 'kill')
{
- // -------------------------------------------------------------------
- // process comment stuff
- if ($bugsys->in['comment'] AND !((can_perform('caneditown', $bug['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
+ if (!can_perform('candeletedata', $bug['product']))
{
- $comment = new CommentAPI($bugsys);
- $comment->set('bugid', $bugsys->in['bugid']);
- $comment->set('userid', $bugsys->userinfo['userid']);
- $comment->set('comment', $_POST['comment']);
- $comment->insert();
-
- $time = $comment->values['dateline'];
- $commentid = $comment->insertid;
-
- $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]");
+ $message->errorPermission();
}
- // -------------------------------------------------------------------
- // do update stuff
- $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
-
- $bugapi = new BugAPI($bugsys);
- $bugapi->set('bugid', $bugsys->in['bugid']);
- $bugapi->set_condition();
- $bugapi->dorelations = array();
- $bugapi->fetch();
-
- $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
-
- // -------------------------------------------------------------------
- // start updates
+ $bugapi->remove();
- // auto action
- $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . intval($bugsys->in['autoaction']));
- if ($autoaction)
+ $message->redirect(T('The entire bug has been deleted.'), 'index.php');
+}
+
+// ###################################################################
+
+if ($_REQUEST['do'] == 'delete')
+{
+ if (!can_perform('candeletedata', $bug['product']))
{
- $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;
- }
+ $message->errorPermission();
}
- process_custom_fields($bug['bugid']);
-
- $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
- $dependencies = ((count($dependencies) < 1) ? '' : implode(', ', $dependencies));
-
- $bugapi->set('summary', $bugsys->in['summary']);
- $bugapi->set('severity', $bugsys->in['severity']);
- $bugapi->set('duplicateof', $bugsys->in['duplicateof']);
- $bugapi->set('dependency', $dependencies);
- $bugapi->set('productid', $pcv['product']);
- $bugapi->set('componentid', $pcv['component']);
- $bugapi->set('versionid', $pcv['version']);
- $bugapi->set('hidden', $bugsys->in['hidden']);
-
- if (can_perform('canchangestatus', $bug['productid']))
- {
- $bugapi->set('priority', $bugsys->in['priority']);
- $bugapi->set('status', $bugsys->in['status']);
- $bugapi->set('resolution', $bugsys->in['resolution']);
- }
- if (can_perform('canassign', $bug['productid']))
+ $message->confirm(T('Are you sure you want to delete this bug? Doing so will <strong>destroy</strong> 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']))
{
- $bugapi->set('assignedto', $bugsys->in['assignedto']);
+ $message->errorPermission();
}
- $bugapi->update();
+ $log->addData(true, $bugapi->record, $log->getCommonFields(), true);
// -------------------------------------------------------------------
- // do diff history
-
- $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
-
- $diff[0] = array_diff_assoc($bugapi->objdata, $bugapi->values);
- $diff[1] = array_diff_assoc($bugapi->values, $bugapi->objdata);
-
- $lookupindex = array(
- 'status' => 'status',
- 'severity' => 'severity',
- 'priority' => 'priority',
- 'versionid' => 'version',
- 'assignedto' => 'assignto',
- 'resolution' => 'resolution',
- 'productid' => 'product',
- 'componentid' => 'product'
- );
-
- foreach ($diff AS $num => $diffs)
+ // handle automations
+ if ($input->in['automation'])
{
- foreach ($diffs AS $key => $value)
+ $automation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $input->inputClean('automation', TYPE_UINT));
+ if ($automation)
{
- if (!isset($lookupindex["$key"]))
- {
- continue;
- }
-
- $ref = $lookupindex["$key"];
- $temp =& $bugsys->datastore["$ref"]["$value"];
- $thevalue = $temp["$ref"];
- $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
-
- if ($key == 'assignedto')
+ $automation['fields'] = unserialize($automation['fieldchanges']);
+
+ if (is_array($automation['fields']['builtin']))
{
- $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
- $idbit = '';
+ foreach ($automation['fields']['builtin'] AS $field => $value)
+ {
+ $input->in["$field"] = $value;
+ }
}
- else if ($key == 'productid' OR $key == 'componentid')
+
+ if (is_array($automation['fields']['custom']))
{
- $ref = 'product';
- $thevalue = $temp['title'];
+ foreach ($automation['fields']['custom'] AS $field => $value)
+ {
+ $input->in["custom$field"] = $value;
+ }
}
-
- $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)
+
+ // -------------------------------------------------------------------
+ // process comment stuff
+ if ($input->in['comment'] OR $automation['comment'])
{
- $canallowempty = true;
- $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
- while ($box = $db->fetch_array($checkbox))
+ if (!empty($input->in['comment']) AND $automation['comment'])
{
- $boxlist[] = 'field' . $box['fieldid'];
+ $commenttext = $input->in['comment'] . "\n\n" . T('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
}
- }
-
- foreach ($diff2[1] AS $key => $value)
- {
- if (in_array($key, $boxlist) AND $canallowempty)
+ else if (empty($input->in['comment']) AND $automation['comment'])
{
- $log->allowempty = true;
+ $commenttext = $automation['comment'];
}
else
{
- $log->allowempty = false;
+ $commenttext = $input->in['comment'];
}
- if ($key == 'bugid')
+ $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'])))
{
- continue;
+ $bugapi->update();
+ $notif->finalize();
+ $message->redirect(T('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
}
-
- $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
}
- $log->allowempty = false;
+ // -------------------------------------------------------------------
+ // 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);
// -------------------------------------------------------------------
- // more comment
- $hascomment = (!empty($bugsys->in['comment'])) ? true : 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 ($hascomment OR $autoaction['comment'])
+ if (!$message->hasErrors())
{
- 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'];
- }
-
- $comment = new CommentAPI($bugsys);
- $comment->set('bugid', $bugsys->in['bugid']);
- $comment->set('userid', $bugsys->userinfo['userid']);
- $comment->set('comment', $bugsys->in['comment']);
- $comment->insert();
-
- $time = $comment->values['dateline'];
- $commentid = $comment->insertid;
-
- $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'])
- );
+ $bugapi->update();
+ }
+ else
+ {
+ $message->error();
}
+
+ // -------------------------------------------------------------------
+ // do diff history
+ $log->updateHistory();
- $message->redirect($lang->string('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
+ $notif->sendBugChangeNotice();
+
+ $notif->finalize();
+
+ $message->redirect(T('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
}
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
?>
\ No newline at end of file