  [% META title = 'Admin &raquo; User Group Functions' -%]
<!-- BEGIN [% template.name %] -->

  [% PROCESS admin/user_nav.tt page = 'user_groupfunction' %]

    [% # PROCESS dumper.tt dump = user_groups %]

    [% user_functions_dfv_js %]

    [% IF dfv_errors %]
        <p class="error">[% c.cfg('msg').dfv_errors %]</p>
    [% END %]

    [% IF user_groups %]
      <h2 align="center">Set default permissions for user groups</h2>

      <p>View all <a href="[% app_url %]/resources/user_permissions">
        user permissions</a>
      </p>

      <form method="post" action="[% app_url %]/admin/user_group-function"
          name="user_group" id="user_group">
        <p>
          <b>User group</b>:
          <select name="id" [% on_focus %]>
            <option value="">&nbsp;</option>

            [% FOREACH group IN user_groups %]
              <option [% 'selected' IF group.id == c.query.param('id') %]
                  value="[% group.id %]">
              [% group.group_label %]</option>
            [% END %]
          </select>

          <input type="submit" value="Go" name=".select" class="button" />
        </p>
      </form>
    [% END %]

    [% IF user_functions %]
      <form action="[% app_url %]/admin/user_group-function/update/[% c.query.param('id') %]"
          method="post" name="group_function" id="group_function">

        <table>
          <tr>
            <th>Function description</th>
            <th>Active</th>
          </tr>

          [% FOREACH function IN user_functions;
            NEXT UNLESS function.active.match('yes');
            SET checked = function.selected ? 'checked' : '' # so input on 1 line for .t test
          %]
            <tr>
              <td>[% function.detail %]</td>
              <td>
                <input type="checkbox" name="function_id" value="[% function.id %]"
                  [% checked %] />
              </td>
            </tr>
            [% END %]
            <tr>
              <td colspan="2" align="center">
                [% site.html.submit %] [% site.html.reset %]
              </td>
            </tr>
        </table>
      </form>
    [% END %]
<!-- END [% template.name %] -->
