Bug 11578: (follow-up) fix JavaScript error
[koha_ffzg] / koha-tmpl / intranet-tmpl / prog / en / modules / admin / aqbudgets.tt
index 12a70bc..3f50901 100644 (file)
@@ -1,17 +1,78 @@
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Administration &rsaquo; Funds[% IF ( add_form ) %] &rsaquo; [% IF ( budget_id ) %]Modify Fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add Fund [% END %][% END %]</title>
+<title>Koha &rsaquo; Administration &rsaquo; Funds[% IF op == 'add_form' %] &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
-<script type="text/javascript" src="[% themelang %]/js/acq.js"></script>
+<script type="text/javascript">
+//<![CDATA[
+var MSG_BUDGET_PARENT_ALLOCATION = "- " + _("Fund amount exceeds parent allocation") + "\n";
+var MSG_BUDGET_PERIOD_ALLOCATION = "- " + _("Fund amount exceeds period allocation") + "\n";
+var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") + "\n";
+//]]>
+</script>
 
-[% IF ( add_form ) %]
+<script type="text/javascript" src="[% themelang %]/js/acq.js"></script>
+[% IF op == 'add_form' %]
 <script type="text/javascript">
 //<![CDATA[
-//
-     var actTotal ="";
 
-    function ownerRemove(f) {
-        document.getElementById('budget_owner_name').innerHTML = '';
-        document.getElementById('budget_owner_id').value = '';
+    function userPopup() {
+        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=user",
+            'PatronPopup',
+            'width=740,height=450,location=yes,toolbar=no,'
+            + 'scrollbars=yes,resize=yes'
+        );
+    }
+
+    function ownerPopup() {
+        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=owner",
+            'PatronPopup',
+            'width=740,height=450,location=yes,toolbar=no,'
+            + 'scrollbars=yes,resize=yes'
+        );
+    }
+
+    function edit_owner(borrowernumber, surname, firstname) {
+        $('#budget_owner_name').empty();
+        $('#budget_owner_id').val('');
+        if (borrowernumber) {
+            var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
+                + '?borrowernumber=' + borrowernumber + '">'
+                + firstname + ' ' + surname + '</a>';
+            $('#budget_owner_name').html(ownerlink);
+            $('#budget_owner_id').val(borrowernumber);
+        }
+    }
+
+    function ownerRemove() {
+        edit_owner(0);
+    }
+
+    function add_user(borrowernumber, surname, firstname) {
+        var ids = $("#budget_users_id").val().split(':');
+        if(borrowernumber && ids.indexOf(borrowernumber) == -1) {
+            var li = '<li id="user_' + borrowernumber + '">'
+                + '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='
+                + borrowernumber + '">' + firstname + ' ' + surname
+                + '</a> [<a style="cursor:pointer"'
+                + 'onclick="del_user(' + borrowernumber +')">Remove</a>]</li>';
+            $(li).insertBefore("li#add_user_button");
+            ids.push(borrowernumber);
+            $("#budget_users_id").val(ids.join(':'));
+        } else {
+            return -1;
+        }
+        return 0;
+    }
+
+    function del_user(borrowernumber) {
+        var ids = $("#budget_users_id").val().split(':');
+        if (borrowernumber) {
+            var idx = ids.indexOf(borrowernumber+'');
+            if (idx != -1) {
+                ids.splice(idx, 1);
+                $("#budget_users_id").val(ids.join(':'));
+                $("li#user_" + borrowernumber).remove();
+            }
+        }
     }
 
     function Check(f) {
@@ -19,8 +80,6 @@
         var _alertString="";
         var alertString2;
 
-        // var actTotal ="";
-
         if (!(isNotNull(f.budget_code,1))) {
             _alertString += _("- Budget code cannot be blank") + "\n";
         }
     }
 //]]>
 </script>
-[% ELSE %]
-<link href="[% themelang %]/lib/jquery/plugins/treetable/stylesheets/jquery.treeTable.css" rel="stylesheet" type="text/css" />
-
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/treetable/jquery.treeTable.min.js"></script>
-<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.qtip.js"></script>
+[% ELSIF op == 'list' %]
+    <link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
+    [% INCLUDE 'datatables.inc' %]
+    <link href="[% interface %]/lib/jquery/plugins/treetable/stylesheets/jquery.treetable.css" rel="stylesheet" type="text/css" />
+    <script type="text/javascript" src="[% interface %]/lib/jquery/plugins/treetable/jquery.treetable.js"></script>
 
 <script type="text/javascript">
 //<![CDATA[
     //
     $(document).ready(function() {
-        var tooltipcontent = $(".tooltipcontent");
-        tooltipcontent.hide();
-
-        $(".tooltiped td").each(function (){
-            contentelem = $(this).parent().children().filter(".tooltipcontent");
-            if(contentelem.html() != ""){
-            $(this).qtip({
-                content: contentelem.html(),
-                show: "mouseover",
-                hide: "mouseout",
-                style: {
-                    name: "light",
-                    tip: "bottomLeft",
-                    border: {
-                        radius: 5,
-                        color: "#356CA1"
-                    }
-                },
-                position: {
-                    corner: {
-                        target: "topRight",
-                        tooltip: "bottomRight"
+        var oTable = $("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
+            "fnDrawCallback": function ( oSettings ) {
+                if ( oSettings.aiDisplay.length == 0 )
+                {
+                    return;
+                }
+
+                var nTrs = $('#budgeth tbody tr');
+                var iColspan = nTrs[0].getElementsByTagName('td').length;
+                var sLastGroup = "";
+                for ( var i=0 ; i<nTrs.length ; i++ )
+                {
+                    var iDisplayIndex = oSettings._iDisplayStart + i;
+                    var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[1];
+                    if ( sGroup != sLastGroup )
+                    {
+                        var nGroup = document.createElement( 'tr' );
+                        var nCell = document.createElement( 'td' );
+                        nCell.colSpan = iColspan;
+                        nCell.className = "group";
+                        nCell.innerHTML = sGroup;
+                        nGroup.appendChild( nCell );
+                        nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
+                        sLastGroup = sGroup;
                     }
                 }
-            });
-            }
+            },
+            "aoColumnDefs": [
+                { "bVisible": false, "aTargets": [ 0, 1 ] },
+                { "bSortable": false, "aTargets": ["_all"] }
+            ],
+            'bSort': true,
+            'aaSortingFixed': [[ 1, 'asc' ]],
+            'bPaginate': false,
+            "bAutoWidth": false
+        }));
+
+        $(oTable).treetable({
+            expandable: true
         });
-        [% IF ( notree ) %]
-        $("#budgeth").tablesorter({
-            widgets : ['zebra'],
-            sortList: [[0,0]],
-            headers: { 7: { sorter: false }}
+        $(oTable).treetable('expandAll');
+        $("#expand_all").click(function(e){
+            e.preventDefault();
+            $(oTable).treetable('expandAll');
         });
-        [% ELSE %]
-        $("#budgeth").treeTable();
+        $("#collapse_all").click(function(e){
+            e.preventDefault();
+            $(oTable).treetable('collapseAll');
+        });
+
+        [% UNLESS budget_period_id %]
+          $("#hide_inactive").click(function(e){
+            e.preventDefault();
+            oTable.fnFilter( 1, 0 ); // Show only active=1
+          });
+          $("#show_inactive").click(function(e){
+            e.preventDefault();
+            oTable.fnFilter( '', 0 );
+          });
+          $("#hide_inactive").click();
         [% END %]
 
         $("#filterbutton").click(function() {
             $("#fundfilters").slideToggle(0);
-            $("#content").css({ marginLeft:  $("#content").css("marginLeft") == "4em"?"15em":"4em"});
         });
     });
 //]]>
 [% END %]
 
 </head>
-<body>
+<body id="admin_aqbudgets" class="admin">
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'budgets-admin-search.inc' %]
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
-    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> &rsaquo; [% IF ( else ) %]Funds for '[% budget_period_description %]'[% END %][% IF ( add_form ) %]
-    <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]">Funds</a> &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund[% END %][% END %]  [% IF ( delete_confirm ) %]
-    <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> &rsaquo; Delete fund?[% END %]</div>
+    <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/aqbudgetperiods.pl">Budgets</a> &rsaquo; [% IF op == 'list' %][% IF budget_period_id %]Funds for '[% budget_period_description %]'[% ELSE %]All funds[% END %][% END %]
+    [% IF op == 'add_form' %]
+      <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]">Funds</a> &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund[% END %]
+    [% END %]
+    [% IF op == 'delete_confirm' %]
+      <a href="/cgi-bin/koha/admin/aqbudgets.pl">Funds</a> &rsaquo; Delete fund?
+    [% END %]
+</div>
 
 <div id="doc3" class="yui-t2">
 <div id="bd">
 <div id="yui-main">
 <div class="yui-b" id="content">
 
-[% UNLESS ( delete_confirm ) %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
-[% IF ( else ) %]
 
-<h1>Funds for '[% budget_period_description %]'</h1>
+[% UNLESS op == 'delete_confirm' %][% INCLUDE 'budgets-admin-toolbar.inc' %][% END %]
+
+[% IF (error_not_authorised_to_modify) %]
+    <div class="error">
+        <p>You are not authorized to modify this fund</p>
+    </div>
+[% END %]
+
+[% IF op == 'list' %]
+
+<h1>
+  [% IF budget_period_id %]
+    Funds for '[% budget_period_description %]'
+  [% ELSE %]
+    All funds
+  [% END %]
+</h1>
 
 [% INCLUDE 'budgets-active-currency.inc' %]
 
+[% IF budgets %]
+
 <table id="budgeth">
+    [% UNLESS budget_period_id %]
+      <caption>
+        <span class="actions"><a href="#" id="expand_all">Expand all</a>
+        | <a href="#" id="collapse_all">Collapse all</a>
+        | <a href="#" id="hide_inactive">Hide inactive budgets</a>
+        | <a href="#" id="show_inactive">Show inactive budgets</a></span>
+      </caption>
+    [% END %]
     <thead>
         <tr>
+            <th>Active</th>
+            <th>Budget period description</th>
             <th>Fund code</th>
             <th>Fund name</th>
-            <th>Total<br />allocated</th>
-            <th>Base-level<br />allocated</th>
-            <th>Base-level<br />spent</th>
-            <th>Total sublevels<br />spent</th>
-            <th>Base-level<br />remaining</th>
-            <th class="tooltipcontent">&nbsp;</th>
+            <th>Base-level allocated</th>
+            <th>Base-level ordered</th>
+            <th>Total ordered</th>
+            <th>Base-level spent</th>
+            <th>Total spent</th>
+            <th>Base-level available</th>
+            <th>Total available</th>
             <th>Actions</th>
         </tr>
     </thead>
-<tfoot>
+    <tfoot>
     <tr>
+    <th></th>
+    <th></th>
     <th colspan="2" style="text-align: left;" nowrap="nowrap">Period allocated [% IF ( budget_period_total ) %][% budget_period_total %][% END %]  </th>
     <th nowrap="nowrap" class="data"> [% period_alloc_total %]</th>
-    <th nowrap="nowrap"  class="data"> [% base_alloc_total %]</th>
-    <th class="data">[% base_spent_total %]</th>
-    <th class="data">[% base_spent_total %]</th>
-    <th class="data">[% base_remaining_total %]</th>
-    <th class="tooltipcontent"></th>
+    <th></th>
+    <th class="data">[% ordered_total %]</th>
+    <th></th>
+    <th class="data">[% spent_total %]</th>
+    <th></th>
+    <th class="data">[% available_total %]</th>
     <th></th>
     </tr>
     </tfoot>
     <tbody>
-    [% IF ( budget ) %]
-        [% FOREACH budge IN budget %]
-    [% IF ( budge.toggle ) %]
-    <tr id="node-[% budge.budget_id %]" class="highlight[% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %] tooltiped">
+    [% FOREACH budget IN budgets %]
+    [% IF budget.budget_parent_id %]
+      <tr data-tt-id="[% budget.budget_id %]" data-tt-parent-id="[% budget.budget_parent_id %]">
     [% ELSE %]
-    <tr id="node-[% budge.budget_id %]" class="tooltiped [% IF ( budge.budget_parent_id ) %] child-of-node-[% budge.budget_parent_id %][% END %]">
+      <tr data-tt-id="[% budget.budget_id %]">
     [% END %]
-
-    <td>[% budge.budget_code_indent %]</td>
-    <td>[% budge.budget_name %]</td>
-    <td class="data">[% budge.budget_amount_total %]</td>
-    <td class="data">[% budge.budget_amount %] </td>
-    <td class="data">[% budge.budget_spent %] </td>
-    <td class="data">[% budge.total_levels_spent %]</td>
-    [% IF ( budge.remaining_pos ) %]
-        <td class="data" style="color: green;">
-    [% ELSIF ( budge.remaining_neg ) %] 
-        <td class="data" style="color: red;">
-    [% ELSE %]
-        <td class="data">
+    <td>[% budget.budget_period_active %]</td>
+    <td>Budget [% budget.budget_period_description %] [id=[% budget.budget_period_id %]][% UNLESS budget.budget_period_active %] (inactive)[% END %]</td>
+    <td>[% budget.budget_code_indent %]</td>
+    <td>[% budget.budget_name %]</td>
+    <td class="data">
+      [% IF budget.budget_parent_id %]
+        <span class="child_fund_amount">[% budget.budget_amount %]</span>
+      [% ELSE %]
+        [% budget.budget_amount %]
+      [% END %]
+    </td>
+    <td class="data">
+      [% IF budget.budget_parent_id %]
+        <span class="child_fund_amount">[% budget.budget_ordered %]</span>
+      [% ELSE %]
+        [% budget.budget_ordered %]
+      [% END %]
+    </td>
+    <td class="data">
+      [% IF budget.budget_parent_id %]
+        <span class="child_fund_amount">[% budget.total_ordered %]</span>
+      [% ELSE %]
+        [% budget.total_ordered %]
+      [% END %]
+    </td>
+    <td class="data">
+      [% IF budget.budget_parent_id %]
+        <span class="child_fund_amount">[% budget.budget_spent %]</span>
+      [% ELSE %]
+        [% budget.budget_spent %]
+      [% END %]
+    </td>
+    <td class="data">
+      [% IF budget.budget_parent_id %]
+        <span class="child_fund_amount">[% budget.total_spent %]</span>
+      [% ELSE %]
+        [% budget.total_spent %]
+      [% END %]
+    </td>
+
+
+    [% BLOCK colorcellvalue %]
+        [% IF parent %]
+            [% IF (value > 0) %]
+                <span class="child_fund_amount" style="color: green;">
+            [% ELSIF (value < 0) %]
+                <span class="child_fund_amount" style="color: red;">
+            [% ELSE %]
+                <span class="child_fund_amount">
+            [% END %]
+         [% ELSE %]
+            [% IF (value > 0) %]
+                <span style="color: green;">
+            [% ELSIF (value < 0) %]
+                <span style="color: red;">
+            [% ELSE %]
+                <span>
+            [% END %]
+        [% END %]
+            [% text %]
+        </span>
     [% END %]
-            [% budge.budget_remaining %] </td>
-
-    <td class="tooltipcontent">[% IF ( budge.budget_owner_id ) %]<strong>Owner: </strong><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budge.budget_owner_id %]">[% budge.budget_owner_name %]</a>[% END %]
-        [% IF ( budge.budget_branchcode ) %]<br /><strong>Library: </strong>[% budge.budget_branchcode %][% END %]
-        [% IF ( budge.budget_notes ) %]<br /><strong>Notes: </strong>[% budge.budget_notes %][% END %]
-        [% IF ( budge.budget_hierarchy ) %]
-            <ul class="budget_hierarchy">[% FOREACH budget_hierarch IN budge.budget_hierarchy %]
-                [% IF ( budget_hierarch.element_id ) %]
-                    <li><a href="?op=add_form&amp;budget_id=[% budget_hierarch.element_id %]&amp;budget_period_id=[% budget_hierarch.budget_period_id %]">[% budget_hierarch.element_name %]</a></li>
-                [% ELSE %]
-                    <li><strong>[% budget_hierarch.element_name %] : </strong></li>
-                [% END %]
-                [% END %]
-            </ul>
-        [% END %]</td>
-    [% IF ( budge.budget_lock ) %]
-        <td> <span style="color: gray;" > Edit Delete </span> </td>
+    <td class="data">
+        [% INCLUDE colorcellvalue value=budget.budget_remaining text=budget.budget_remaining_display parent=budget.budget_parent_id %]
+    </td>
+    <td class="data">
+        [% INCLUDE colorcellvalue value=budget.total_remaining text=budget.total_remaining_display parent=budget.budget_parent_id %]
+    </td>
+    [% IF ( budget.budget_lock ) %]
+        <td> <span style="color: gray;"> Edit Delete </span> </td>
     [% ELSE %]
         <td>
-            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]" >Edit</a>
-            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&amp;budget_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]">Delete</a>
-            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_parent_id=[% budge.budget_id %]&amp;budget_period_id=[% budge.budget_period_id %]">Add Child Fund</a>
+            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_id=[% budget.budget_id %]&amp;budget_period_id=[% budget.budget_period_id %]" >Edit</a>
+            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=delete_confirm&amp;budget_id=[% budget.budget_id %]&amp;budget_period_id=[% budget.budget_period_id %]">Delete</a>
+            <a href="/cgi-bin/koha/admin/aqbudgets.pl?op=add_form&amp;budget_parent_id=[% budget.budget_id %]&amp;budget_period_id=[% budget.budget_period_id %]">Add child fund</a>
         </td>
     [% END %]
     </tr>
-        [% END %]
-    [% ELSE %]
-        <tr><td colspan="12">No fund found</td></tr>
     [% END %]
     </tbody>
 </table>
 
-[% IF ( pagination_bar ) %]<div class="pages">[% pagination_bar %]</div>[% END %]
-[% END %] <!-- else -->
+[% ELSE %]
+    No fund found
+[% END %]
+
+[% END %] <!-- list -->
 
 <!-- ********************************************************************************************** -->
 <!-- create add/mod entry form -->
-[% IF ( add_form ) %]
+[% IF op == 'add_form' && !error_not_authorised_to_modify %]
 <form action="/cgi-bin/koha/admin/aqbudgets.pl" name="Aform" method="post">
     <fieldset class="rows">
     <legend>[% IF ( budget_id ) %]Modify[% ELSE %]Add[% END %] Fund
     <ol>
     [% IF ( budget_parent_id ) %]
     <li>
-        <span class="label">Fund Parent: </span>
+        <span class="label">Fund parent: </span>
         [% budget_parent_name %]
         [% budget_parent_id %] - [% budget_parent_name %]
         <input type="hidden" name="budget_parent_id" value="[% budget_parent_id %]" />
     </li>
     [% END %]
     <li>
-    <label class="required"  for="budget_code">Fund Code: </label>
+    <label class="required"  for="budget_code">Fund code: </label>
     <input type="text" name="budget_code" id="budget_code" value="[% budget_code %]" size="30" />
     </li>
 
     <li>
-    <label class="required" for="budget_name">Fund Name: </label>
+    <label class="required" for="budget_name">Fund name: </label>
     <input type="text" name="budget_name" id="budget_name" value="[% budget_name %]" size="60" />
     </li>
 
     </li>
 
     <li>
-    <label for="budget_encumb">Encumbrance: </label>
-    <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb %]" size="8" />
+      <label for="budget_encumb">Warning at (%): </label>
+      <input type="text" name="budget_encumb" id="budget_encumb" value="[% budget_encumb %]" size="10" />
+      <span style="color:grey">0 to disable</span>
     </li>
 
     <li>
-    <label for="budget_expend">Expenditure: </label>
-    <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend %]" size="8" /><input type="hidden" name="budget_owner_id" id="budget_owner_id" value="[% budget_owner_id %]" />
+      <label for="budget_expend">Warning at (amount): </label>
+      <input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend %]" size="10" /><input type="hidden" name="budget_owner_id" id="budget_owner_id" value="[% budget_owner_id %]" />
+      <span style="color:grey">0 to disable</span>
     </li>
 
     <li>
-    <span class="label">Owner: </span>
-    <span  id="budget_owner_name">
-    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budget_owner_id %]">[% budget_owner_name %]</a>
-    </span>
-
-    <!-- FIXME: hardcoded button positions :/ -->
-    <input style="" type="button" id="edit_owner" value="Edit owner" onclick="ownerPopup(); return false;" />
-    <input style=""  type="button" id="remove_owner" value="Remove owner" onclick="ownerRemove(this.form); return false;" />
+        <span class="label">Owner: </span>
+        <span  id="budget_owner_name">
+        <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% budget_owner_id %]">
+            [% budget_owner_name %]
+        </a>
+        </span>
+        <input type="hidden" name="budget_owner_id" id="budget_owner_id"
+            value="[% budget_owner_id %]" />
+
+        <!-- FIXME: hardcoded button positions :/ -->
+        <input type="button" id="edit_owner" value="Edit owner"
+            onclick="ownerPopup(); return false;" />
+        <input type="button" id="remove_owner" value="Remove owner"
+            onclick="ownerRemove(); return false;" />
     </li>
 
     <li>
+        <span class="label">Users:</span>
+        <ul style="float:left;" id="budget_users">
+            [% FOREACH user IN budget_users %]
+                <li id="user_[% user.borrowernumber %]">
+                    <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% user.borrowernumber %]">
+                        [% user.firstname %] [% user.surname %]
+                    </a>
+                    [<a style="cursor:pointer"
+                    onclick="del_user([% user.borrowernumber %])">Remove</a>]
+                </li>
+            [% END %]
+            <li id="add_user_button">
+                <input type="button" onclick="userPopup()" value="Add users" />
+            </li>
+        </ul>
+        <input type="hidden" name="budget_users_ids" id="budget_users_id" value="[% budget_users_ids %]" />
+    <li>
     <label for="budget_branchcode">Library: </label>
     <select name="budget_branchcode" id="budget_branchcode">
     <option value=""></option>
     <li>
     <label for="budget_permission">Restrict access to: </label>
     <select name="budget_permission" id="budget_permission">
-    [% IF ( budget_perm_0 ) %]<option value="0" selected="selected">None</option>[% ELSE %]<option value="0">None</option>[% END %]
-    [% IF ( budget_perm_1 ) %]<option value="1" selected="selected">Owner</option>[% ELSE %]<option value="1">Owner</option>[% END %]
-    [% IF ( budget_perm_2 ) %]<option value="2" selected="selected">Library</option>[% ELSE %]<option value="2">Library</option>[% END %]
-    </option>
+        [% IF ( budget_perm_0 ) %]
+            <option value="0" selected="selected">
+        [% ELSE %]
+            <option value="0">
+        [% END %]
+            None
+        </option>
+
+        [% IF ( budget_perm_1 ) %]
+            <option value="1" selected="selected">
+        [% ELSE %]
+            <option value="1">
+        [% END %]
+            Owner
+        </option>
+
+        [% IF ( budget_perm_3) %]
+            <option value="3" selected="selected">
+        [% ELSE %]
+            <option value="3">
+        [% END %]
+            Owner and users
+        </option>
+
+        [% IF ( budget_perm_2 ) %]
+            <option value="2" selected="selected">
+        [% ELSE %]
+            <option value="2">
+        [% END %]
+            Owner, users and library
+        </option>
     </select>
     </li>
 
 
 [% END %] <!-- add_form -->
 
-[% IF ( delete_confirm ) %]
-<div class="dialog alert"> <h3>Delete Fund [% budget_name %]?</h3>
+[% IF op == 'delete_confirm' %]
+<div class="dialog alert"> <h3>Delete fund [% budget_name %]?</h3>
 <table>
     <tr>
-    <th scope="row">Fund Amount:</th>
+    <th scope="row">Fund amount:</th>
     <td>[% budget_amount %]</td>
     </tr>
 </table>
 
-<form action="[% action %]" method="post">
+<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="post">
     <input type="hidden" name="op" value="delete_confirmed" />
     <input type="hidden" name="budget_id" value="[% budget_id %]" />
     <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
-    <input type="submit" value="Delete this budget" class="approve" />
+    <input type="submit" value="Delete" class="approve" />
 </form>
 
-<form action="[% action %]" method="get">
-    <input type="submit" class="deny" value="No, Do Not Delete" />
+<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
+    <input type="submit" class="deny" value="Cancel" />
 </form>
 </div>
 [% END %]
 </div>
 </div>
 <div class="yui-b">
-[% IF ( else ) %]<form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
+[% IF op == 'list' %]
+  <form action="/cgi-bin/koha/admin/aqbudgets.pl" method="get">
     <a href="#" id="filterbutton">Filters</a>
     <fieldset class="brief" id="fundfilters">
     <h4>Fund filters</h4>
                 <input type="checkbox" id="show_mine"  name="show_mine" value="1" />
         [% END %]
         </li>
+
+        [% IF periods %]
+          <li>
+            <label for="periods">Budget:</label>
+            <select id="periods" name="budget_period_id">
+              <option value="">All budgets</option>
+              [% FOR period IN periods %]
+                [% IF budget_period_id && period.budget_period_id == budget_period_id %]
+                  <option value="[% period.budget_period_id %]" selected="selected">[% period.budget_period_description %]</option>
+                [% ELSE %]
+                  <option value="[% period.budget_period_id %]">[% period.budget_period_description %]</option>
+                [% END %]
+              [% END %]
+            </select>
+          </li>
+        [% END %]
         </ol>
 
-        <input type="hidden" name="show" value="1" />
-        <input type="hidden"  name="budget_period_id" value="[% budget_period_id %]" />
+        <input type="hidden" name="op" value="list" />
         <input type="submit" class="submit" name="filter" value="Go" />
     </fieldset>
 </form>[% END %]