<?php
/*=====================================================================*\
-|| ################################################################### ||
-|| # BugStrike [#]version[#]
-|| # --------------------------------------------------------------- # ||
-|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
-|| # This file may not be reproduced in any way without permission. # ||
-|| # --------------------------------------------------------------- # ||
-|| # User License Agreement at http://www.iris-studios.com/license/ # ||
-|| ################################################################### ||
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2004-2009 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 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
+|| # 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');
-if (!can_perform('cansubmitbugs', intval($bugsys->in['productid'])))
+
+$product = explode(',', $input->in['product']);
+if (!can_perform('cansubmitbugs', $product[0]))
{
- $message->error_permission();
+ $message->errorPermission();
}
// ###################################################################
if ($_POST['do'] == 'insert')
{
+ $bug = new BugAPI();
+ $comment = new CommentAPI();
+
+ $notif = new NotificationCenter();
+
+ $bug->set('userid', bugdar::$userinfo['userid']);
+ $bug->set('username', bugdar::$userinfo['displayname']);
+ $bug->set('summary', $input->in['summary']);
+ $bug->set('severity', $input->in['severity']);
+
+ $comment->set('userid', bugdar::$userinfo['userid']);
+ $comment->set('comment', $input->in['comment']);
+ $comment->set('parselinks', $input->in['parselinks']);
+
// -------------------------------------------------------------------
// check permissions on various input values
- if (!can_perform('canchangestatus', intval($bugsys->in['productid'])))
+ if (!can_perform('canchangestatus', $input->in['product']))
{
- $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
- $bugsys->in['status'] = $bugsys->options['defaultstatus'];
- $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
+ $bug->set('priority', bugdar::$options['defaultpriority']);
+ $bug->set('status', bugdar::$options['defaultstatus']);
+ $bug->set('resolution', bugdar::$options['defaultresolve']);
}
else
{
- if (!$bugsys->datastore['priority'][ $bugsys->in['priority'] ])
- {
- $bugsys->in['priority'] = $bugsys->options['defaultpriority'];
- }
- if (!$bugsys->datastore['status'][ $bugsys->in['status'] ])
- {
- $bugsys->in['status'] = $bugsys->options['defaultstatus'];
- }
- if (!$bugsys->datastore['resolution'][ $bugsys->in['resolution'] ])
- {
- $bugsys->in['resolution'] = $bugsys->options['defaultresolve'];
- }
+ $bug->set('priority', $input->in['priority']);
+ $bug->set('status', $input->in['status']);
+ $bug->set('resolution', $input->in['resolution']);
}
- if (!can_perform('canassign', intval($bugsys->in['productid'])))
+ if (!can_perform('canassign', $input->in['product']))
{
- $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
+ $bug->set('assignedto', bugdar::$options['defaultassign']);
}
else
{
// assigned person is not a dev or a valid user
- if (!$bugsys->datastore['assignto'][ $bugsys->in['assignedto'] ]['userid'])
- {
- $bugsys->in['assignedto'] = $bugsys->options['defaultassign'];
- }
+ $bug->set('assignedto', $input->in['assignedto']);
}
+
+ $product = explode(',', $input->in['product']);
+ $bug->set('product', $product[0]);
+ $bug->set('component', $product[1]);
+ $bug->set('version', $product[2]);
- // -------------------------------------------------------------------
- // product/component/version stuff
- $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
+ process_custom_fields($bug, $message, true);
- // -------------------------------------------------------------------
- // sanity checks
- if (!$pcv)
- {
- $message->error($lang->string('Invalid product/component/version selected.'));
- }
- if (!$bugsys->in['summary'])
- {
- $message->error($lang->string('Please enter a title for the bug'));
- }
- if (!$bugsys->in['comment'])
+ if (!$message->hasErrors())
{
- $message->error($lang->string('Please fill in the bug\'s description field'));
+ $bug->insert();
+
+ $comment->set('bugid', $bug->insertid);
+ $comment->insert();
+
+ $notif->sendNewBugNotice($bug->values, $comment->values);
+
+ $bug = new BugAPI(); // need to destroy because update will think the insert fields need to be changed, too
+ $bug->set('bugid', $comment->values['bugid']);
+ $bug->fetch();
+ $bug->set('dateline', $comment->values['dateline']);
+ $bug->set('initialreport', $comment->insertid);
+ $bug->set('lastposttime', $comment->values['dateline']);
+ $bug->set('lastpostby', bugdar::$userinfo['userid']);
+ $bug->set('lastpostbyname', bugdar::$userinfo['displayname']);
+ $bug->set('hiddenlastposttime', $comment->values['dateline']);
+ $bug->set('hiddenlastpostby', bugdar::$userinfo['userid']);
+ $bug->set('hiddenlastpostbyname', bugdar::$userinfo['displayname']);
+ $bug->update();
+
+ $notif->setBugData($bug->record);
+
+ $notif->finalize();
+
+ $message->redirect(T('The bug has been added to the database.'), ($input->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
}
-
- // -------------------------------------------------------------------
- // data clean and insert
- $bugsys->in['comment_parsed'] = $bugsys->in['comment'];
-
- if (!$bugsys->options['allowhtml'])
+ else
{
- $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']);
+ $show['errors'] = true;
+ $_REQUEST['do'] = 'add';
}
-
- // create the bug report
- $db->query("
- INSERT INTO " . TABLE_PREFIX . "bug
- (userid, productid, componentid, versionid, summary, severity, priority, status, assignedto, resolution)
- VALUES
- (" . $bugsys->userinfo['userid'] . ", " . $pcv['product'] . ", " . $pcv['component'] . ", " . $pcv['version'] . ",
- '" . $bugsys->in['summary'] . "', " . intval($bugsys->in['severity']) . ", " . intval($bugsys->in['priority']) . ",
- " . intval($bugsys->in['status']) . ", " . intval($bugsys->in['assignedto']) . ", " . intval($bugsys->in['resolution']) . "
- )"
- );
-
- $bugid = $db->insert_id();
-
- $time = TIMENOW;
-
- // insert the comment to the database
- $db->query("
- INSERT INTO " . TABLE_PREFIX . "comment
- (bugid, userid, dateline, comment, comment_parsed)
- VALUES
- ($bugid, " . $bugsys->userinfo['userid'] . ",
- $time, '" . $bugsys->in['comment'] . "',
- '" . nl2br($bugsys->in['comment_parsed']) . "'
- )"
- );
-
- $initialreport = $db->insert_id();
-
- $db->query("
- UPDATE " . TABLE_PREFIX . "bug
- SET dateline = $time,
- initialreport = $initialreport,
- lastposttime = $time,
- lastpostby = " . $bugsys->userinfo['userid'] . ",
- hiddenlastposttime = $time,
- hiddenlastpostby = " . $bugsys->userinfo['userid'] . "
- WHERE bugid = $bugid"
- );
-
- $db->query("INSERT INTO " . TABLE_PREFIX . "vote (bugid, votefor, voteagainst) VALUES ($bugid, 0, 0)");
-
- $message->redirect($lang->string('The bug has been added to the database.'), "showreport.php?bugid=$bugid");
}
// ###################################################################
if ($_REQUEST['do'] == 'add')
{
- $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid');
+ if (!is_array(bugdar::$datastore['product']))
+ {
+ $message->error(T('No products have been setup, therefore no bugs can be added.'));
+ }
+ if (!is_array(bugdar::$datastore['version']))
+ {
+ $message->error(T('No versions have been setup underneath your product(s), therefore no bugs can be added.'));
+ }
+
+ $select['severity'] = construct_datastore_select('severity', 'severity', 'severityid', ($input->in['severity'] ? $input->in['severity'] : bugdar::$options['defaultseverity']));
- $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false);
+ $show['changestatus'] = can_perform('canchangestatus');
if (can_perform('canchangestatus'))
{
- $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid');
- $select['status'] = construct_datastore_select('status', 'status', 'statusid');
- $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid');
+ $select['priority'] = construct_datastore_select('priority', 'priority', 'priorityid', ($input->in['priority'] ? $input->in['priority'] : bugdar::$options['defaultpriority']));
+ $select['status'] = construct_datastore_select('status', 'status', 'statusid', ($input->in['status'] ? $input->in['status'] : bugdar::$options['defaultstatus']));
+ $select['resolution'] = construct_datastore_select('resolution', 'resolution', 'resolutionid', ($input->in['resolution'] ? $input->in['resolution'] : bugdar::$options['defaultresolve']));
}
- $show['assign'] = ((can_perform('canassign')) ? true : false);
+ $show['assign'] = can_perform('canassign');
if (can_perform('canassign'))
{
- foreach ($bugsys->datastore['assignto'] AS $dev)
+ foreach (bugdar::$datastore['assignto'] as $dev)
{
- $value = $dev['userid'];
- $label = construct_user_display($dev, false);
- eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
+ $tpl = new BSTemplate('selectoption');
+ $tpl->vars = array(
+ 'value' => $dev['userid'],
+ 'label' => construct_user_display($dev, false),
+ 'selected' => ($input->in['assignedto'] ? ($input->in['assignedto'] == $dev['userid']) : ($dev['userid'] == bugdar::$options['defaultassign']))
+ );
+ $select['dev'] = $tpl->evaluate()->getTemplate();
}
}
- $pcv_select = construct_pcv_select();
+ // custom fields
+ $fields = construct_custom_fields($input->in, true);
+ $i = 0;
+ foreach ($fields AS $field)
+ {
+ if ($i % 2 == 0)
+ {
+ $customfields['left'] .= $field;
+ }
+ else
+ {
+ $customfields['right'] .= $field;
+ }
+ $i++;
+ }
- eval('$template->flush("' . $template->fetch('newreport') . '");');
+ $tpl = new BSTemplate('newreport');
+ $tpl->vars = array(
+ 'reporter' => construct_user_display(bugdar::$userinfo),
+ 'productSelect' => construct_product_select('cansubmitbugs', $input->in['product'], false),
+ 'select' => $select,
+ 'customfields' => $customfields
+ );
+ $tpl->evaluate()->flush();
}
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
?>
\ No newline at end of file