Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / newreport.php
index a39157b7fc3a1231ad0dc6743ab5e6ac9d392767..d4c9d3865c8ba5acf503175cd22891496395fc50 100755 (executable)
@@ -1,12 +1,12 @@
 <?php
 /*=====================================================================*\
 || ###################################################################
-|| # Bugdar [#]version[#]
-|| # Copyright ©2002-[#]year[#] Blue Static
+|| # 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 [#]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
@@ -23,7 +23,6 @@ $fetchtemplates = array(
        'newreport',
 );
 
-define('SVN', '$Id$');
 
 $focus['newreport'] = 'focus';
 
@@ -33,13 +32,11 @@ 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']);
+$product = explode(',', $input->in['product']);
 if (!can_perform('cansubmitbugs', $product[0]))
 {
-       $message->error_permission();
+       $message->errorPermission();
 }
 
 // ###################################################################
@@ -53,91 +50,83 @@ if (empty($_REQUEST['do']))
 
 if ($_POST['do'] == 'insert')
 {
-       $bug = new BugAPI($bugsys);
-       $comment = new CommentAPI($bugsys);
+       $bug = new BugAPI();
+       $comment = new CommentAPI();
        
-       $notif = new NotificationCenter;
+       $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']);
+       $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',         $bugsys->userinfo['userid']);
-       $comment->set('comment',        $bugsys->in['comment']);
-       $comment->set('parselinks',     $bugsys->in['parselinks']);
+       $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', $bugsys->in['product']))
+       if (!can_perform('canchangestatus', $input->in['product']))
        {
-               $bug->set('priority',   $bugsys->options['defaultpriority']);
-               $bug->set('status',             $bugsys->options['defaultstatus']);
-               $bug->set('resolution', $bugsys->options['defaultresolve']);
+               $bug->set('priority',   bugdar::$options['defaultpriority']);
+               $bug->set('status',             bugdar::$options['defaultstatus']);
+               $bug->set('resolution', bugdar::$options['defaultresolve']);
        }
        else
        {
-               $bug->set('priority',   $bugsys->in['priority']);
-               $bug->set('status',             $bugsys->in['status']);
-               $bug->set('resolution', $bugsys->in['resolution']);
+               $bug->set('priority',   $input->in['priority']);
+               $bug->set('status',             $input->in['status']);
+               $bug->set('resolution', $input->in['resolution']);
        }
-       if (!can_perform('canassign', $bugsys->in['product']))
+       if (!can_perform('canassign', $input->in['product']))
        {
-               $bug->set('assignedto', $bugsys->options['defaultassign']);
+               $bug->set('assignedto', bugdar::$options['defaultassign']);
        }
        else
        {
                // assigned person is not a dev or a valid user
-               $bug->set('assignedto', $bugsys->in['assignedto']);
+               $bug->set('assignedto', $input->in['assignedto']);
        }
                
-       $product = explode(',', $bugsys->in['product']);
+       $product = explode(',', $input->in['product']);
        $bug->set('product',            $product[0]);
        $bug->set('component',          $product[1]);
        $bug->set('version',            $product[2]);
        
-       $cfields = process_custom_fields(null, $message, true);
+       process_custom_fields($bug, $message, true);
        
-       if (!$message->items)
+       if (!$message->hasErrors())
        {
                $bug->insert();
                
                $comment->set('bugid',                  $bug->insertid);
                $comment->insert();
                
-               $notif->send_new_bug_notice($bug->values, $comment->values);
+               $notif->sendNewBugNotice($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 = new BugAPI(); // 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->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('lastpostby',                         bugdar::$userinfo['userid']);
+               $bug->set('lastpostbyname',                     bugdar::$userinfo['displayname']);
                $bug->set('hiddenlastposttime',         $comment->values['dateline']);
-               $bug->set('hiddenlastpostby',           $bugsys->userinfo['userid']);
-               $bug->set('hiddenlastpostbyname',       $bugsys->userinfo['displayname']);
+               $bug->set('hiddenlastpostby',           bugdar::$userinfo['userid']);
+               $bug->set('hiddenlastpostbyname',       bugdar::$userinfo['displayname']);
                $bug->update();
                
-               if ($cfields)
-               {
-                       $db->query(sprintf($cfields, $comment->values['bugid']));
-               }
-               
-               $notif->set_bug_data($bug->objdata);
+               $notif->setBugData($bug->record);
                
                $notif->finalize();
                
-               $message->redirect(_('The bug has been added to the database.'), ($bugsys->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
+               $message->redirect(T('The bug has been added to the database.'), ($input->in['submit_reload'] == '' ? "showreport.php?bugid=" . $bug->values['bugid'] : 'newreport.php'));
        }
        else
        {
                $show['errors'] = true;
                $_REQUEST['do'] = 'add';
-               $message->error_list_process();
        }
 }
 
@@ -145,41 +134,44 @@ if ($_POST['do'] == 'insert')
 
 if ($_REQUEST['do'] == 'add')
 {
-       if (!is_array($bugsys->datastore['product']))
+       if (!is_array(bugdar::$datastore['product']))
        {
-               $message->error(_('No products have been setup, therefore no bugs can be added.'));
+               $message->error(T('No products have been setup, therefore no bugs can be added.'));
        }
-       if (!is_array($bugsys->datastore['version']))
+       if (!is_array(bugdar::$datastore['version']))
        {
-               $message->error(_('No versions have been setup underneath your product(s), therefore no bugs can be added.'));
+               $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', ($bugsys->in['severity'] ? $bugsys->in['severity'] : $bugsys->options['defaultseverity']));
+       $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', ($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']));
+               $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);
-                       $selected = ($bugsys->in['assignedto'] ? ($bugsys->in['assignedto'] == $dev['userid']) : ($dev['userid'] == $bugsys->options['defaultassign']));
-                       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();
                }
        }
        
        // custom fields
-       $fields = construct_custom_fields($bugsys->in, true);           
+       $fields = construct_custom_fields($input->in, true);            
        $i = 0;
        foreach ($fields AS $field)
        {
@@ -194,17 +186,14 @@ if ($_REQUEST['do'] == 'add')
                $i++;
        }
        
-       $productSelect = ConstructProductSelect('cansubmitbugs', $bugsys->in['product'], false);
-       
-       $reporter = construct_user_display($bugsys->userinfo);
-       
-       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