Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / editreport.php
index af2ff9b92f7503cf831e19da598acf5ca84c0cf1..09d941e46e1c4a76a984cab299131140433c990f 100644 (file)
@@ -1,12 +1,12 @@
 <?php
 /*=====================================================================*\
 || ###################################################################
-|| # Bugdar [#]version[#]
-|| # Copyright 2002-[#]year[#] Blue Static
+|| # 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
@@ -19,7 +19,6 @@
 || ###################################################################
 \*=====================================================================*/
 
-define('SVN', '$Id$');
 
 $focus['showreport'] = 'focus';
 
@@ -29,17 +28,12 @@ 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'));
-
-$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 = " . $bugsys->input_clean('bugid', TYPE_UINT)
+       WHERE bug.bugid = " . $input->inputClean('bugid', TYPE_UINT)
 );
 
 if (!$bug)
@@ -49,35 +43,18 @@ if (!$bug)
 
 if (!check_bug_permissions($bug))
 {
-       $message->error_permission();
+       $message->errorPermission();
 }
 
 // setup logging
 require_once('./includes/class_logging.php');
-$log = new Logging;
-$log->set_bugid($bug['bugid']);
-
-$bugfields = array(
-       'duplicateof',
-       'dependency',
-       'hidden',
-       'summary',
-       'status',
-       'severity',
-       'priority',
-       'version',
-       'assignedto'    => 'assignto',
-       'resolution',
-       'product',
-       'component'
-);
+$log = new Logging();
+$log->setBugId($bug['bugid']);
 
-$notif = new NotificationCenter;
+$notif = new NotificationCenter();
 
-$bugapi = new BugAPI($bugsys);
-$bugapi->set('bugid',          $bugsys->in['bugid']);
-$bugapi->set_condition();
-$bugapi->dorelations = array();
+$bugapi = new BugAPI();
+$bugapi->set('bugid', $input->in['bugid']);
 $bugapi->fetch();
 
 // ###################################################################
@@ -86,12 +63,12 @@ if ($_POST['do'] == 'kill')
 {
        if (!can_perform('candeletedata', $bug['product']))
        {
-               $message->error_permission();
+               $message->errorPermission();
        }
        
-       $bugapi->delete();
+       $bugapi->remove();
        
-       $message->redirect(_('The entire bug has been deleted.'), 'index.php');
+       $message->redirect(T('The entire bug has been deleted.'), 'index.php');
 }
 
 // ###################################################################
@@ -100,153 +77,150 @@ if ($_REQUEST['do'] == 'delete')
 {
        if (!can_perform('candeletedata', $bug['product']))
        {
-               $message->error_permission();
+               $message->errorPermission();
        }
        
-       $message->confirm(_('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', _('Delete Bug Permanently'), 'showreport.php?bugid=' . $bug['bugid'], array('bugid' => $bug['bugid']));
+       $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']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])) AND !can_perform('canpostcomments', $bug['product']))
+       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->error_permission();
+               $message->errorPermission();
        }
        
-       $log->add_data(true, $bugapi->objdata, $bugfields);
+       $log->addData(true, $bugapi->record, $log->getCommonFields(), true);
        
        // -------------------------------------------------------------------
        // handle automations
-       $automation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $bugsys->input_clean('automation', TYPE_UINT));
-       if ($automation)
+       if ($input->in['automation'])
        {
-               $automation['fields'] = unserialize($automation['fieldchanges']);
-               
-               if (is_array($automation['fields']['builtin']))
+               $automation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $input->inputClean('automation', TYPE_UINT));
+               if ($automation)
                {
-                       foreach ($automation['fields']['builtin'] AS $field => $value)
+                       $automation['fields'] = unserialize($automation['fieldchanges']);
+
+                       if (is_array($automation['fields']['builtin']))
                        {
-                               $bugsys->in["$field"] = $value;
+                               foreach ($automation['fields']['builtin'] AS $field => $value)
+                               {
+                                       $input->in["$field"] = $value;
+                               }
                        }
-               }
-               
-               if (is_array($automation['fields']['custom']))
-               {
-                       foreach ($automation['fields']['custom'] AS $field => $value)
+
+                       if (is_array($automation['fields']['custom']))
                        {
-                               $bugsys->in["field$field"] = $value;
+                               foreach ($automation['fields']['custom'] AS $field => $value)
+                               {
+                                       $input->in["custom$field"] = $value;
+                               }
                        }
                }
        }
 
        // -------------------------------------------------------------------
        // process comment stuff
-       if ($bugsys->in['comment'] OR $automation['comment'])
+       if ($input->in['comment'] OR $automation['comment'])
        {
-               if (!empty($bugsys->in['comment']) AND $automation['comment'])
+               if (!empty($input->in['comment']) AND $automation['comment'])
                {
-                       $commenttext = $bugsys->in['comment'] . "\n\n" . _('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
+                       $commenttext = $input->in['comment'] . "\n\n" . T('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
                }
-               else if (empty($bugsys->in['comment']) AND $automation['comment'])
+               else if (empty($input->in['comment']) AND $automation['comment'])
                {
                        $commenttext = $automation['comment'];
                }
                else
                {
-                       $commenttext = $bugsys->in['comment'];
+                       $commenttext = $input->in['comment'];
                }
                
-               $comment = new CommentAPI($bugsys);
-               $comment->set('bugid',          $bugsys->in['bugid']);
-               $comment->set('userid',         $bugsys->userinfo['userid']);
+               $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->set_bug_data($bugapi->objdata);
-               $notif->send_new_comment_notice($comment->values);
+               $notif->setBugData($bugapi->record);
+               $notif->sendNewCommentNotice($comment->values);
                
                $bugapi->set('lastposttime',                    $comment->values['dateline']);
-               $bugapi->set('lastpostby',                              $bugsys->userinfo['userid']);
-               $bugapi->set('lastpostbyname',                  $bugsys->userinfo['displayname']);
+               $bugapi->set('lastpostby',                              bugdar::$userinfo['userid']);
+               $bugapi->set('lastpostbyname',                  bugdar::$userinfo['displayname']);
                $bugapi->set('hiddenlastposttime',              $comment->values['dateline']);
-               $bugapi->set('hiddenlastpostby',                $bugsys->userinfo['userid']);
-               $bugapi->set('hiddenlastpostbyname',    $bugsys->userinfo['displayname']);
+               $bugapi->set('hiddenlastpostby',                bugdar::$userinfo['userid']);
+               $bugapi->set('hiddenlastpostbyname',    bugdar::$userinfo['displayname']);
                
-               if (!((can_perform('caneditown', $bug['product']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['product']) AND $bugsys->userinfo['userid'] != $bug['userid'])))
+               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(_('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
+                       $message->redirect(T('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
                }
        }
        
        // -------------------------------------------------------------------
-       // do update stuff
-       $pcv = parse_pcv_select($bugsys->in['pcv_select'], true);
-       
-       $dependencies = preg_split('#([^0-9].*?)#', $bugsys->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
+       // do update stuff      
+       $dependencies = preg_split('#([^0-9].*?)#', $input->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
        $dependencies = ((sizeof($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('hidden',          $bugsys->in['hidden']);
-       
-       $product = explode(',',         $bugsys->in['product']);
-       $bugapi->set('product',         $product[0]);
-       $bugapi->set('component',       $product[1]);
-       $bugapi->set('version',         $product[2]);
+       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',        $bugsys->in['priority']);
-               $bugapi->set('status',          $bugsys->in['status']);
-               $bugapi->set('resolution',      $bugsys->in['resolution']);
+               $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',      $bugsys->in['assignedto']);
+               $bugapi->set('assignedto',      $input->in['assignedto']);
        }
        
-       $notif->set_bug_data($bugapi->objdata, $bugapi->values);
+       process_custom_fields($bugapi, $message, false);
        
        // -------------------------------------------------------------------
        // handle logging and perform updates
        
-       if ($fields = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]"))
+       $notif->setBugData($bugapi->record, array_merge($bugapi->record, $bugapi->values));
+       $log->addData(false, $bugapi->values, $log->getCommonFields(), true);
+       
+       if (!$message->hasErrors())
        {
-               $log->add_data(true, $fields, array('bugid'), true, 'custom');
+               $bugapi->update();
+       }
+       else
+       {
+               $message->error();
        }
-       
-       $log->add_data(false, $bugapi->values, $bugfields);
-       
-       process_custom_fields($bug['bugid'], $message, false);
-       
-       $bugapi->update();
        
        // -------------------------------------------------------------------
        // do diff history
+
+       $log->updateHistory();
        
-       $fieldsnew = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
-       $log->add_data(false, $fieldsnew, array('bugid'), true, 'custom');
-       
-       $log->update_history();
-       
-       $notif->send_bug_changes_notice($fields, $fieldsnew);
+       $notif->sendBugChangeNotice();
        
        $notif->finalize();
        
-       $message->redirect(_('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
+       $message->redirect(T('Your changes to the bug have been saved.'), "showreport.php?bugid=$bug[bugid]");
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file