<?php
/*=====================================================================*\
|| ###################################################################
|| # Bugdar [#]version[#]
|| # Copyright ©2002-[#]year[#] 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.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/
$fetchtemplates = array(
'newreport',
);
define('SVN', '$Id$');
$focus['newreport'] = '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');
require_once('./includes/class_api_error.php');
APIError(array(new API_Error_Handler($message), 'user_cumulative'));
$product = explode(',', $bugsys->in['product']);
if (!can_perform('cansubmitbugs', $product[0]))
{
$message->errorPermission();
}
// ###################################################################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'add';
}
// ###################################################################
if ($_POST['do'] == 'insert')
{
$bug = new BugAPI($bugsys);
$comment = new CommentAPI($bugsys);
$notif = new NotificationCenter();
$bug->set('userid', $bugsys->userinfo['userid']);
$bug->set('username', $bugsys->userinfo['displayname']);
$bug->set('summary', $bugsys->in['summary']);
$bug->set('severity', $bugsys->in['severity']);
$comment->set('userid', $bugsys->userinfo['userid']);
$comment->set('comment', $bugsys->in['comment']);
$comment->set('parselinks', $bugsys->in['parselinks']);
// -------------------------------------------------------------------
// check permissions on various input values
if (!can_perform('canchangestatus', $bugsys->in['product']))
{
$bug->set('priority', $bugsys->options['defaultpriority']);
$bug->set('status', $bugsys->options['defaultstatus']);
$bug->set('resolution', $bugsys->options['defaultresolve']);
}
else
{
$bug->set('priority', $bugsys->in['priority']);
$bug->set('status', $bugsys->in['status']);
$bug->set('resolution', $bugsys->in['resolution']);
}
if (!can_perform('canassign', $bugsys->in['product']))
{
$bug->set('assignedto', $bugsys->options['defaultassign']);
}
else
{
// assigned person is not a dev or a valid user
$bug->set('assignedto', $bugsys->in['assignedto']);
}
$product = explode(',', $bugsys->in['product']);
$bug->set('product', $product[0]);
$bug->set('component', $product[1]);
$bug->set('version', $product[2]);
process_custom_fields($bug, $message, true);
if (!$message->hasErrors())
{
$bug->insert();
$comment->set('bugid', $bug->insertid);
$comment->insert();
$notif->send_new_bug_notice($bug->values, $comment->values);
$bug = new BugAPI($bugsys); // need to destroy because update will think the insert fields need to be changed, too
$bug->dorelations = array();
$bug->set('bugid', $comment->values['bugid']);
$bug->set_condition();
$bug->fetch();
$bug->set('dateline', $comment->values['dateline']);
$bug->set('initialreport', $comment->insertid);
$bug->set('lastposttime', $comment->values['dateline']);
$bug->set('lastpostby', $bugsys->userinfo['userid']);
$bug->set('lastpostbyname', $bugsys->userinfo['displayname']);
$bug->set('hiddenlastposttime', $comment->values['dateline']);
$bug->set('hiddenlastpostby', $bugsys->userinfo['userid']);
$bug->set('hiddenlastpostbyname', $bugsys->userinfo['displayname']);
$bug->update();
$notif->set_bug_data($bug->objdata);
$notif->finalize();
$message->redirect(_('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
}
else
{
$show['errors'] = true;
$_REQUEST['do'] = 'add';
}
}
// ###################################################################
if ($_REQUEST['do'] == 'add')
{
if (!is_array($bugsys->datastore['product']))
{
$message->error(_('No products have been setup, therefore no bugs can be added.'));
}
if (!is_array($bugsys->datastore['version']))
{
$message->error(_('No versions have been setup underneath your product(s), therefore no bugs can be added.'));
}
$select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
$show['changestatus'] = can_perform('canchangestatus');
if (can_perform('canchangestatus'))
{
$select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($bugsys->in['priority'] ? $bugsys->in['priority'] : $bugsys->options['defaultpriority']));
$select['status'] = construct_datastore_select('status', 'status', 'statusid', ($bugsys->in['status'] ? $bugsys->in['status'] : $bugsys->options['defaultstatus']));
$select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($bugsys->in['resolution'] ? $bugsys->in['resolution'] : $bugsys->options['defaultresolve']));
}
$show['assign'] = can_perform('canassign');
if (can_perform('canassign'))
{
foreach ($bugsys->datastore['assignto'] AS $dev)
{
$value = $dev['userid'];
$label = construct_user_display($dev, false);
$selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
}
}
// custom fields
$fields = construct_custom_fields($bugsys->in, true);
$i = 0;
foreach ($fields AS $field)
{
if ($i % 2 == 0)
{
$customfields['left'] .= $field;
}
else
{
$customfields['right'] .= $field;
}
$i++;
}
$productSelect = ConstructProductSelect('cansubmitbugs', $bugsys->in['product'], false);
$reporter = construct_user_display($bugsys->userinfo);
eval('$template->flush("' . $template->fetch('newreport') . '");');
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>