  <h1 tal:replace="structure here/manage_page_header">Header</h1>
  <h2 tal:define="manage_tabs_message options/manage_tabs_message | nothing"
    tal:replace="structure here/manage_tabs">Tabs</h2>

  <h4>Users management</h4>
  <form action="" method="POST" tal:attributes="action request/URL1">
    <ol tal:define="users here/getPureUsers">
      <table cellspacing="10" width="90%">
        <tr>
          <!-- Users selection -->
          <td valign="top">
            <table bgcolor="#EEEEEE" width="100%">
              <tr class="list-header" tal:condition="users">
                <th>&nbsp;</th>
                <th>User</th>
                <th class="list-header">Member <br>of groups</th>
                <th class="list-header">Implicitly <br>member of*</th>
                <th class="list-header">Has roles</th>
                <th class="list-header">Implicitly <br>has roles**</th>
              </tr>
              
              <tr 
                  tal:repeat="user users" 
                class="" 
                tal:attributes="class python:test(path('repeat/user/odd'), 'row-hilite', 'row-normal')"
                >
                <div tal:define="
                  label_groups python:user.getGroups();
                  label_groups_no_recurse python:user.getGroups(no_recurse = 1);
                  label_groups_recurse python:filter(lambda x: x not in label_groups_no_recurse, label_groups);
                  groups_no_recurse python:map(lambda x: here.getUser(x), label_groups_no_recurse);
                  groups_recurse python:map(lambda x: here.getUser(x), label_groups_recurse);
                  roles python:filter(lambda x: x not in ('Authenticated', 'Shared'), user.getRoles());
                  roles_no_recurse python:filter(lambda x: x not in ('Authenticated', 'Shared'), user.getUserRoles());
                  roles_recurse python:filter(lambda x: x not in roles_no_recurse, roles);"
                  tal:omit-tag="">
                  <td><div class="list-item"><input type="checkbox" name="users:list" value="" tal:attributes="value user"></td>
                  <td>
                    <div class="list-item">
                      <img src="img_user" />
                        <strong tal:content="structure user/asHTML">
                        </strong>
                  </td>
                  <td class="list-item">
                    <span tal:repeat="group groups_no_recurse" >
                      <span tal:replace="structure group/asHTML"></span><span tal:condition="not:repeat/group/end">, </span>
                    </span>
                  </td>
                  <td class="list-item">
                    <span tal:repeat="group groups_recurse" >
                      <span tal:replace="structure python:group.asHTML(implicit=1)"></span><span tal:condition="not:repeat/group/end">, </span>
                    </span>
                  </td>
                  <td class="list-item">
                    <div class="list-item">
                      <span tal:repeat="role roles_no_recurse" >
                        <font color=""
                              tal:attributes="color here/role_color">
                          <span tal:replace="role"></span><span tal:condition="not:repeat/role/end">, </span>
                        </font>
                      </span>
                    </div>
                  </td>
                  <td class="list-item">
                    <div class="list-item">
                      <span tal:repeat="role roles_recurse" >
                        <font color=""
                              tal:attributes="color here/role_color">
                          <i><span tal:replace="role"></span></i><span tal:condition="not:repeat/role/end">, </span>
                        </font>
                      </span>
                    </div>
                  </td>
                </div>
              </tr>

              <tr tal:condition="not: users">
                <td colspan="4">
                  <div class="list-item">
                    No user available. This happens either if you have no users defined or if
                    the underlying UserFolder cannot retreive the entire users list (for example, LDAPUserFolder
                    is limited in results size)
                  </div>
                </td>
              </tr>

              <!-- New user -->
              <tr>
                <td><div class="list-item">&nbsp;</div></td>
                <td>
                  <div class="list-item">Create users:</div>
                </td>
              </tr>
              <tr>
                <td><div class="list-item">&nbsp;</div></td>
                <td>
                  <div class="list-item">
                    <textarea name="new_users:lines" cols="20" rows="3"></textarea>
                  </div>
                </td>
                <td colspan="4">
                  <div class="list-item" valign="top">
                    Newly created users will be affected groups and roles according to the table below.
                  </div>
                </td>
              </tr>
              <tr>
                <td><div class="list-item">&nbsp;</div></td>
                <td>
                  <div class="list-item">Default password:</div>
                </td>
              </tr>
              <tr>
                <td><div class="list-item">&nbsp;</div></td>
                <td>
                  <div class="list-item">
                      <input name="default_password:string" size="20" />
                  </div>
                </td>
                <td colspan="4">
                  <div class="list-item">
                    Fill in this field to specify a default password for new users, 
                    or leave it empty to let GRUF generate random ones.
                  </div>
                </td>
              </tr>
              <tr>
                <td colspan="2" align="center">
                  <input type="submit" name="changeOrCreateUsers:method" value="Create" />
                    &nbsp;
                    <input type="submit" name="deleteUsers:method" value="Delete" />
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td align="center">
            <div class="list-item">
              Select one or more users in the upper table, select one or more groups / roles in the table below
              and click "Change" to affect groups / roles to these users.
            </div>
          </td>
        </tr>
        <tr>
          <td valign="top" align="center" colspan="6">
            <table  bgcolor="#EEEEEE">
              <tr>
                <td valign="top">
                  <!-- Groups selection -->
                  <table width="100%">
                    <tr class="list-header">
                      <th colspan="2">Affect groups</th>
                    </tr>
                    
                    <tr tal:repeat="group here/getGroups">
                      <td>
                        <input type="checkbox" name="groups:list" value="" tal:attributes="value group">
                      </td>
                      <td>
                        <div class="list-item" tal:content="structure group/asHTML"></div>
                      </td>
                    </tr>
                    
                    <!-- "(None)" item -->
                    <tr>
                      <td><div class="list-item"><input type="checkbox" name="nested_groups:list" value="__None__"></div></td>
                      <td><div class="list-item"><i>(None)</i></div></td>
                    </tr>
                  </table>
                </td>
                <td valign="top">
                    <!-- Roles selection -->
                    <table width="100%">
                      <tr class="list-header">
                        <th colspan="2">Affect roles</th>
                      </tr>
                      
                      <tr tal:repeat="role here/valid_roles">
                        <td tal:condition="python:role not in ('Authenticated', 'Anonymous', 'Shared')">
                          <input type="checkbox" name="roles:list" value="" tal:attributes="value role">
                        </td>
                        <td tal:condition="python:role not in ('Authenticated', 'Anonymous', 'Shared')">
                          <div class="list-item"><font color="" tal:attributes="color here/role_color" tal:content="role">Role</font></div>
                        </td>
                      </tr>
                      
                      <!-- "(None)" item -->
                      <tr>
                        <td><div class="list-item"><input type="checkbox" name="roles:list" value="__None__"></div></td>
                        <td><div class="list-item"><i>(None)</i></div></td>
                      </tr>
                    </table>
                </td>
              </tr>
              <tr>
                <td colspan="2" align="middle"><input type="submit" name="changeOrCreateUsers:method" value="Change" /></td>
            </table>
          </td>
        </tr>
      </table>

      <p class="form-help">
        If you do not select any role, roles won't be reseted for the selected users.<br />
          If you do not select any group, groups won't be reseted for the selected users.<br />
            To explicitly reset groups or roles, just click the "(None)" entry (and no other entry).
      </p>

      <p class="form-help">
        * According to the groups inheritance, this group is also recursively member of these groups. <br />This is what we call nested groups.
      </p>
      <p class="form-help">
        ** Accorded to the groups inheritance, this group also has these roles - even if they are not defined explicitly on it.
      </p>

    </ol>
  </form>


  <h4>Instructions</h4>
  <ol>
    <p class="form-help">
      To change roles for one or several users, select them in the left form, 
      select the roles you want to give them and the groups they belong to in the forms on the right and click "Change".<br />
        You can also create one or several users by filling the text area (one user per line). 
        The "Change" button will create them with the roles and group affectation you've selected. 
        A random password will be generated for them, and it will be shown in a page so that you can click/paste them somewhere.<br />
        If you want to kill some users, you can delete them by selecting them and clicking the "Delete" button.
    </p>
  </ol>

  <h4>Important notice / disclaimer</h4>
  
  <ol>
    <p class="form-help">
      This form uses the regular Zope Security API from the underlying user folders. However, you may experience problems with some
      of them, especially if they are not tuned to allow user adding. For example, an LDAPUserFolder can be configured to disable
      users management. In case this form doesn't work, you'll have to do things by hand within the 'Users' and 'Groups' GRUF folders.
    </p>

    <p class="form-help">
      This is not a GRUF limitation ! :-)
    </p>
  </ol>

  <h1 tal:replace="structure here/manage_page_footer">Footer</h1>
