From d19332fbfbab851de1efd37f95ee04b10cb87d1f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 30 Apr 2006 17:18:36 +0000 Subject: [PATCH] r798: Implementing APIs in newreport.php --- newreport.php | 103 ++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 71 deletions(-) diff --git a/newreport.php b/newreport.php index 8491514..1158d10 100755 --- a/newreport.php +++ b/newreport.php @@ -49,108 +49,69 @@ if (empty($_REQUEST['do'])) if ($_POST['do'] == 'insert') { $bug = new BugAPI($bugsys); + $comment = new CommentAPI($bugsys); + + $bug->set('userid', $bugsys->userinfo['userid']); + $bug->set('summary', $bugsys->in['summary']); + $bug->set('severity', $bugsys->in['severity']); + + $comment->set('userid', $bugsys->userinfo['userid']); + $comment->set('comment', $bugsys->in['comment']); // ------------------------------------------------------------------- // check permissions on various input values if (!can_perform('canchangestatus', intval($bugsys->in['productid']))) { - $bugsys->in['priority'] = $bugsys->options['defaultpriority']; - $bugsys->in['status'] = $bugsys->options['defaultstatus']; - $bugsys->in['resolution'] = $bugsys->options['defaultresolve']; + $bug->set('priority', $bugsys->options['defaultpriority']); + $bug->set('status', $bugsys->options['defaultstatus']); + $bug->set('resolution', $bugsys->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', $bugsys->in['priority']); + $bug->set('status', $bugsys->in['status']); + $bug->set('resolution', $bugsys->in['resolution']); } if (!can_perform('canassign', intval($bugsys->in['productid']))) { - $bugsys->in['assignedto'] = $bugsys->options['defaultassign']; + $bug->set('assignedto', $bugsys->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', $bugsys->in['assignedto']); } // ------------------------------------------------------------------- // product/component/version stuff $pcv = parse_pcv_select($bugsys->in['pcv_select'], true); - - // ------------------------------------------------------------------- - // sanity checks if (!$pcv) { $message->items[] = $lang->string('Invalid product/component/version selected.'); } - if (!$bugsys->in['summary']) - { - $message->items[] = $lang->string('Please enter a title for the bug'); - } - if (!$bugsys->in['comment']) - { - $message->items[] = $lang->string('Please fill in the bug\'s description field'); - } + $bug->set('productid', $pcv['product']); + $bug->set('componentid', $pcv['component']); + $bug->set('versionid', $pcv['version']); if (!$message->items) { - // ------------------------------------------------------------------- - // data clean and insert - $bugsys->in['comment_parsed'] = $bugsys->in['comment']; + $bug->insert(); - if (!$bugsys->options['allowhtml']) - { - $bugsys->in['comment_parsed'] = $bugsys->sanitize($bugsys->in['comment_parsed']); - } - - // 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(); - - $comment = new CommentAPI($bugsys); - $comment->set('bugid', $bugid); - $comment->set('userid', $bugsys->userinfo['userid']); - $comment->set('comment', $_POST['comment']); + $comment->set('bugid', $bug->insertid); $comment->insert(); - $time = $comment->values['dateline']; - - $db->query(" - UPDATE " . TABLE_PREFIX . "bug - SET dateline = $time, - initialreport = " . $comment->insertid . ", - 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)"); + $bug = new BugAPI($bugsys); // need to destroy because update will think the insert fields need to be changed, too + $bug->set('bugid', $comment->values['bugid']); + $bug->set_condition(); + $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('hiddenlastposttime', $comment->values['dateline']); + $bug->set('hiddenlastpostby', $bugsys->userinfo['userid']); + $bug->update(); - $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=$bugid" : 'newreport.php')); + $message->redirect($lang->string('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php')); } else { -- 2.22.5