Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / attachment.php
index e6e506cbb9453f9c2c7bb38d9ecb498b5512cb74..89a6240a7d4fc36b570ec802bcc402a3902d7eac 100755 (executable)
@@ -2,7 +2,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # Bugdar
-|| # Copyright ©2002-2007 Blue Static
+|| # 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
@@ -24,18 +24,14 @@ $fetchtemplates = array(
        'editattach'
 );
 
-define('SVN', '$Id$');
 
 $focus['showreport'] = 'focus';
 
 require_once('./global.php');
-require_once('./includes/class_api_error.php');
 require_once('./includes/class_notification.php');
 require_once('./includes/api_attachment.php');
 require_once('./includes/api_comment.php');
 
-APIError(array(new API_Error_Handler($message), 'user_cumulative'));
-
 if (isset($input->in['attachmentid']))
 {
        $attachment = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . $input->inputClean('attachmentid', TYPE_UINT));
@@ -58,8 +54,8 @@ if (!check_bug_permissions($bug))
 
 require_once('./includes/class_logging.php');
 
-$notif = new NotificationCenter;
-$notif->set_bug_data($bug);
+$notif = new NotificationCenter();
+$notif->setBugData($bug);
 
 // ###################################################################
 
@@ -78,7 +74,7 @@ if ($_POST['do'] == 'insert')
        BSApp::debug("max_allowed_packet = $var[Value]");
        
        // create alias
-       $FILE =$_FILES['attachment'];
+       $FILE = &$_FILES['attachment'];
        
        // PHP errors
        switch ($FILE['error'])
@@ -118,21 +114,21 @@ if ($_POST['do'] == 'insert')
                
                $obsoletes = $input->inputClean('obsoletes', TYPE_UINT);
                
-               $notif->send_new_attachment_notice($attachapi->values, $obsoletes, $attachapi->insertid);
+               $notif->sendNewAttachmentNotice($attachapi->values, $obsoletes, $attachapi->insertid);
                
                // mark obsoletes
                if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
                {
                        $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
                        
-                       foreach ($obsoletes AS $attachmentid)
+                       foreach ($obsoletes as $attachmentid)
                        {
                                $log = new Logging;
-                               $log->set_bugid($bug['bugid']);
-                               $log->set_attachmentid($attachmentid);
-                               $log->add_data(true, array('obsolete' => 0), array('obsolete'), false, 'attachment');
-                               $log->add_data(false, array('obsolete' => 1), array('obsolete'), false, 'attachment'); 
-                               $log->update_history();
+                               $log->setBugId($bug['bugid']);
+                               $log->setAttachmentId($attachmentid);
+                               $log->addData(true, array('obsolete' => 0), array('obsolete'), false, 'attachment');
+                               $log->addData(false, array('obsolete' => 1), array('obsolete'), false, 'attachment'); 
+                               $log->updateHistory();
                        }
                }
                
@@ -146,7 +142,7 @@ if ($_POST['do'] == 'insert')
                        $comment->set('dateline',       $attachapi->values['dateline']);
                        $comment->insert();
                        
-                       $notif->send_new_comment_notice($comment->values);
+                       $notif->sendNewCommentNotice($comment->values);
                }
                
                // update the last post data
@@ -185,7 +181,15 @@ if ($_REQUEST['do'] == 'add')
                $obsoletes .= "<div><input name=\"obsoletes[]\" type=\"checkbox\" value=\"$obsolete[attachmentid]\"" . (is_array($input->in['obsoletes']) AND in_array($obsolete['attachmentid'], $input->in['obsoletes']) ? ' checked="checked"' : '') . " /> $obsolete[filename]" . ($obsolete['description'] ? " [$obsolete[description]]" : '') . "</div>\n";
        }
        
-       eval('$template->flush("' . $template->fetch('newattach') . '");');
+       $tpl = new BSTemplate('newattach');
+       $tpl->vars = array(
+               'bug'                   => $bug,
+               'message'               => $message,
+               'MAXFILESIZE'   => $MAXFILESIZE,
+               'obsoletes'             => $obsoletes,
+               'input'                 => $input
+       );
+       $tpl->evaluate()->flush();
 }
 
 // ###################################################################
@@ -199,8 +203,6 @@ if ($_POST['do'] == 'update')
        
        $attachapi = new AttachmentAPI();
        $attachapi->set('attachmentid', $input->in['attachmentid']);
-       $attachapi->dorelations = array();
-       $attachapi->set_condition();
        
        if ($input->in['__delete__'] != '')
        {
@@ -209,27 +211,27 @@ if ($_POST['do'] == 'update')
                        $message->errorPermission();
                }
                
-               $attachapi->delete();
+               $attachapi->remove();
                
                $message->redirect(T('The attachment was successfully deleted.'), "showreport.php?bugid=$bug[bugid]");
        }
        else
        {
-               $log = new Logging;
-               $log->set_bugid($bug['bugid']);
-               $log->set_attachmentid($input->in['attachmentid']);
+               $log = new Logging();
+               $log->setBugId($bug['bugid']);
+               $log->setAttachmentId($input->in['attachmentid']);
                
                $attachapi->fetch();
                
-               $log->add_data(true, $attachapi->record, array('attachment'), true, 'attachment');
+               $log->addData(true, $attachapi->record, array('attachment'), true, 'attachment');
                
                $attachapi->set('description',  $input->in['description']);
                $attachapi->set('obsolete',             $input->in['obsolete']);
                $attachapi->update();
                
-               $log->add_data(false, $attachapi->values, array('attachment'), true, 'attachment');
+               $log->addData(false, $attachapi->values, array('attachment'), true, 'attachment');
                
-               $log->update_history();
+               $log->updateHistory();
                
                $message->redirect(T('The attachment was successfully modified.'), "showreport.php?bugid=$bug[bugid]");
        }
@@ -246,13 +248,12 @@ if ($_REQUEST['do'] == 'edit')
        
        $show['delete'] = (can_perform('caneditattach', $bug['product']) AND can_perform('candeletedata', $bug['productid']));
        
-       eval('$template->flush("' . $template->fetch('editattach') . '");');
+       $tpl = new BSTemplate('editattach');
+       $tpl->vars = array(
+               'attachment'    => $attachment,
+               'bug'                   => $bug
+       );
+       $tpl->evaluate()->flush();
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file