Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / editreport.php
index 2c1726ab115d87bd5e0d0a009d8c784a9eb9d3de..09d941e46e1c4a76a984cab299131140433c990f 100644 (file)
@@ -1,12 +1,12 @@
 <?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'];
-
-// setup new logging
 require_once('./includes/class_logging.php');
-$log2 = new Logging;
-$log2->set_bugid($bug['bugid']);
+$log = new Logging();
+$log->setBugId($bug['bugid']);
 
-$bugfields = array(
-       'duplicateof',
-       'dependency',
-       'hidden',
-       'summary',
-       'status',
-       'severity',
-       'priority',
-       'versionid'             => 'version',
-       'assignedto'    => 'assignto',
-       'resolution',
-       'productid'             => 'product',
-       'componentid'   => 'component'
-);
+$notif = new NotificationCenter();
+
+$bugapi = new BugAPI();
+$bugapi->set('bugid', $input->in['bugid']);
+$bugapi->fetch();
+
+// ###################################################################
+
+if ($_POST['do'] == 'kill')
+{
+       if (!can_perform('candeletedata', $bug['product']))
+       {
+               $message->errorPermission();
+       }
+       
+       $bugapi->remove();
+       
+       $message->redirect(T('The entire bug has been deleted.'), 'index.php');
+}
+
+// ###################################################################
+
+if ($_REQUEST['do'] == 'delete')
+{
+       if (!can_perform('candeletedata', $bug['product']))
+       {
+               $message->errorPermission();
+       }
+       
+       $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')
 {
-       $bugapi = new BugAPI($bugsys);
-       $bugapi->set('bugid',           $bugsys->in['bugid']);
-       $bugapi->set_condition();
-       $bugapi->dorelations = array();
-       $bugapi->fetch();
+       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->errorPermission();
+       }
        
-       $log2->add_data(true, $bugapi->objdata, $bugfields);
+       $log->addData(true, $bugapi->record, $log->getCommonFields(), true);
        
        // -------------------------------------------------------------------
-       // handle autoaction
-       $autoaction = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "autoaction WHERE actionid = " . $bugsys->input_clean('autoaction', TYPE_UINT));
-       if ($autoaction)
+       // handle automations
+       if ($input->in['automation'])
        {
-               $autoaction['fields'] = unserialize($autoaction['fieldchanges']);
-               
-               foreach ($autoaction['fields']['builtin'] AS $field => $value)
+               $automation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "automation WHERE actionid = " . $input->inputClean('automation', TYPE_UINT));
+               if ($automation)
                {
-                       $bugsys->in["$field"] = $value;
-               }
-               
-               foreach ($autoaction['fields']['custom'] AS $field => $value)
-               {
-                       $bugsys->in["field$field"] = $value;
+                       $automation['fields'] = unserialize($automation['fieldchanges']);
+
+                       if (is_array($automation['fields']['builtin']))
+                       {
+                               foreach ($automation['fields']['builtin'] AS $field => $value)
+                               {
+                                       $input->in["$field"] = $value;
+                               }
+                       }
+
+                       if (is_array($automation['fields']['custom']))
+                       {
+                               foreach ($automation['fields']['custom'] AS $field => $value)
+                               {
+                                       $input->in["custom$field"] = $value;
+                               }
+                       }
                }
        }
-       
+
        // -------------------------------------------------------------------
        // process comment stuff
-       if ($bugsys->in['comment'])
+       if ($input->in['comment'] OR $automation['comment'])
        {
-               if (!empty($bugsys->in['comment']) AND $autoaction['comment'])
+               if (!empty($input->in['comment']) AND $automation['comment'])
                {
-                       $commenttext = $bugsys->in['comment'] . "\n\n" . $lang->string('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $autoaction['comment'];
+                       $commenttext = $input->in['comment'] . "\n\n" . T('--------------- AUTOMATIC RESPONSE ---------------') . "\n" . $automation['comment'];
                }
-               else if (empty($bugsys->in['comment']) AND $autoaction['comment'])
+               else if (empty($input->in['comment']) AND $automation['comment'])
                {
-                       $commenttext = $autoaction['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();
                
-               $bugapi->set('lastposttime',            $comment->values['dateline']);
-               $bugapi->set('lastpostby',                      $bugsys->userinfo['userid']);
-               $bugapi->set('hiddenlastposttime',      $comment->values['dateline']);
-               $bugapi->set('hiddenlastpostby',        $bugsys->userinfo['userid']);
+               // 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['productid']) AND $bugsys->userinfo['userid'] == $bug['userid']) OR (can_perform('caneditother', $bug['productid']) 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();
-                       $message->redirect($lang->string('Your reply has been added to the comment list.'), "showreport.php?bugid=$bug[bugid]");
+                       $notif->finalize();
+                       $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);
-       
-       $hist2[0] = (array)$temp = $noinitialcustom = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
-       
-       // -------------------------------------------------------------------
-       // start updates
+       // do update stuff      
+       $dependencies = preg_split('#([^0-9].*?)#', $input->in['dependency'], -1, PREG_SPLIT_NO_EMPTY);
+       $dependencies = ((sizeof($dependencies) < 1) ? '' : implode(', ', $dependencies));
        
-       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('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['productid']))
+       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['productid']))
+       if (can_perform('canassign', $bug['product']))
        {
-               $bugapi->set('assignedto',              $bugsys->in['assignedto']);
+               $bugapi->set('assignedto',      $input->in['assignedto']);
        }
        
-       $log2->add_data(false, $bugapi->values, $bugfields);
-       print_r($log2); exit;
-       
-       $bugapi->update();
+       process_custom_fields($bugapi, $message, false);
        
        // -------------------------------------------------------------------
-       // do diff history
-       
-       $hist2[1] = (array)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "bugvaluefill WHERE bugid = $bug[bugid]");
+       // handle logging and perform updates
        
-       $diff[0] = array_diff_assoc($bugapi->objdata, $bugapi->values);
-       $diff[1] = array_diff_assoc($bugapi->values, $bugapi->objdata);
+       $notif->setBugData($bugapi->record, array_merge($bugapi->record, $bugapi->values));
+       $log->addData(false, $bugapi->values, $log->getCommonFields(), true);
        
-       $lookupindex = array(
-               'status' => 'status',
-               'severity' => 'severity',
-               'priority' => 'priority',
-               'versionid' => 'version',
-               'assignedto' => 'assignto',
-               'resolution' => 'resolution',
-               'productid' => 'product',
-               'componentid' => 'product'
-       );
-               
-       foreach ($diff AS $num => $diffs)
+       if (!$message->hasErrors())
        {
-               foreach ($diffs AS $key => $value)
-               {
-                       if (!isset($lookupindex["$key"]))
-                       {
-                               continue;
-                       }
-                       
-                       $ref = $lookupindex["$key"];
-                       $temp =& $bugsys->datastore["$ref"]["$value"];
-                       $thevalue = $temp["$ref"];
-                       $idbit = ' (id: ' . $temp["$ref" . 'id'] . ')';
-                       
-                       if ($key == 'assignedto')
-                       {
-                               $thevalue = (($temp['userid']) ? construct_user_display($temp) : '');
-                               $idbit = '';
-                       }
-                       else if ($key == 'productid' OR $key == 'componentid')
-                       {
-                               $ref = 'product';
-                               $thevalue = $temp['title'];
-                       }
-                       
-                       $diff["$num"]["$key"] = (($thevalue) ? $thevalue . $idbit : '');
-               }
+               $bugapi->update();
        }
-       
-       foreach ($diff[1] AS $key => $value)
+       else
        {
-               $log->log($log->diff($key, $diff[0]["$key"], $diff[1]["$key"]));
+               $message->error();
        }
        
-       $diff2[0] = array_diff_assoc($hist2[0], $hist2[1]);
-       $diff2[1] = array_diff_assoc($hist2[1], $hist2[0]);
-       
-       if ($noinitialcustom === false)
-       {
-               $canallowempty = true;
-               $checkbox = $db->query("SELECT * FROM " . TABLE_PREFIX . "bugfield WHERE type = 'input_checkbox'");
-               while ($box = $db->fetch_array($checkbox))
-               {
-                       $boxlist[] = 'field' . $box['fieldid'];
-               }
-       }
+       // -------------------------------------------------------------------
+       // do diff history
+
+       $log->updateHistory();
        
-       foreach ($diff2[1] AS $key => $value)
-       {
-               if (in_array($key, $boxlist) AND $canallowempty)
-               {
-                       $log->allowempty = true;
-               }
-               else
-               {
-                       $log->allowempty = false;
-               }
-               
-               if ($key == 'bugid')
-               {
-                       continue;
-               }
-               
-               $log->log($log->diff('custom_' . $key, $diff2[0]["$key"], $diff2[1]["$key"]));
-       }
+       $notif->sendBugChangeNotice();
        
-       $log->allowempty = false;
+       $notif->finalize();
        
-       $message->redirect($lang->string('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