Index: trac/ticket/report.py
===================================================================
--- trac/ticket/report.py	(revision 7181)
+++ trac/ticket/report.py	(working copy)
@@ -34,7 +34,7 @@
 from trac.util.text import to_unicode, unicode_urlencode
 from trac.util.translation import _
 from trac.web.api import IRequestHandler, RequestDone
-from trac.web.chrome import add_ctxtnav, add_link, add_stylesheet, \
+from trac.web.chrome import add_ctxtnav, add_link, add_script, add_stylesheet, \
                             INavigationContributor, Chrome
 from trac.wiki import IWikiSyntaxProvider, WikiParser
 
@@ -219,10 +219,6 @@
 
     def _render_view(self, req, db, id):
         """Retrieve the report results and pre-process them for rendering."""
-        try:
-            args = self.get_var_args(req)
-        except ValueError,e:
-            raise TracError(_('Report failed: %(error)s', error=e))
 
         if id == -1:
             # If no particular report was requested, display
@@ -241,7 +237,11 @@
                 raise ResourceNotFound(
                     _('Report %(num)s does not exist.', num=id),
                     _('Invalid Report Number'))
-
+        
+        try:
+            args = self.get_var_args(req, sql)
+        except ValueError,e:
+            raise TracError(_('Report failed: %(error)s', error=e))
         # If this is a saved custom query. redirect to the query module
         #
         # A saved query is either an URL query (?... or query:?...),
@@ -498,6 +498,8 @@
                             del req.session[var]
                 except (ValueError, KeyError):
                     pass
+            if len(data['args']) > 0 :
+                add_script(req, 'common/js/folding.js')
             return 'report_view.html', data, None
 
     def add_alternate_links(self, req, args):
@@ -578,8 +580,16 @@
 
         return cols, info
 
-    def get_var_args(self, req):
+    def get_var_args(self, req, sql):
         report_args = {}
+        
+        def repl_literal(expr):
+            var_re = re.compile("[$]([A-Z]+)")
+            parts = var_re.split(expr[1:-1])
+            if len(parts) == 1:
+                return []
+            return [str(param) for param in parts[1::2]]
+        
         for arg in req.args.keys():
             if not arg.isupper():
                 continue
@@ -588,7 +598,11 @@
         # Set some default dynamic variables
         if 'USER' not in report_args:
             report_args['USER'] = req.authname
-
+        
+        for arg in repl_literal(sql) :
+            if not report_args.has_key(arg) :
+                report_args[arg] = ''
+        
         return report_args
 
     def sql_sub_vars(self, sql, args, db=None):
@@ -599,8 +613,7 @@
             try:
                 arg = args[aname]
             except KeyError:
-                raise TracError(_("Dynamic variable '%(name)s' not defined.",
-                                  name='$%s' % aname))
+                arg = ''
             values.append(arg)
 
         var_re = re.compile("[$]([A-Z]+)")
Index: trac/ticket/templates/report_view.html
===================================================================
--- trac/ticket/templates/report_view.html	(revision 7181)
+++ trac/ticket/templates/report_view.html	(working copy)
@@ -11,7 +11,11 @@
 
   <body>
     <div id="content" class="report">
-
+      <script type="text/javascript">
+          jQuery(document).ready(function($) {
+            $("fieldset legend").enableFolding(false);
+          });
+      </script>
       <h1>$title
         <span py:if="numrows and report.id != -1" class="numrows">($numrows matches)</span>
       </h1>
@@ -19,7 +23,28 @@
       <div py:if="description" id="description" xml:space="preserve">
         ${wiki_to_html(context, description)}
       </div>
-
+      <form py:if="len(args) > 1" method="GET" action="">
+        <fieldset id="filters" >
+          <legend style="cursor: pointer;">
+            <a href="#no1">Filters</a>
+          </legend>
+          <table>
+            <py:for each="variable in args">
+               <py:if test="variable not in ['id', 'USER']">
+                 <tr>
+                   <td>${variable}: </td>
+                   <td><input type="text" name="${variable}" value="${req.args[variable] or None}" /></td>
+                 </tr>
+               </py:if>
+            </py:for>
+          </table>
+        </fieldset>
+        <br />
+        <div class="buttons" align="right">
+            <input type="submit" value="Update" name="filter"/>
+        </div>
+        <br />
+      </form>
       <div py:if="report.id != -1" class="buttons">
         <form py:if="'REPORT_MODIFY' in perm(report.resource)" action="" method="get">
           <div>

