  <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>
  <tal:block tal:define="
    global user python:here.getUser(request.username); 
    kind python:test(user.isGroup(), 'Group', 'User'); 
    icon python:test(user.isGroup(), 'img_group', 'img_user');
    color python:test(user.isGroup(), here.acl_users.group_color, here.acl_users.user_color);
    ">
    
    <br />
      
      <div class="std-text">&nbsp;
        <img src="" alt="kind" tal:attributes="src icon; alt kind" align="middle">
          <strong tal:condition="user/isGroup" tal:content="structure string:${user/asHTML} (Group)">toto group management</strong>
    <strong tal:condition="not: user/isGroup" tal:content="structure string:${user/asHTML} (User)">toto user management</strong>
  </div>


    <h4>Settings</h4>
    
    <form action="" method="POST" tal:attributes="action here/absolute_url">
      <tal:block 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)
        ">
        <ol>
          <table cellspacing="10">
            <tr>
              <!-- User info -->
              <input type="hidden" name="user" value="" tal:attributes="value user/getUserName">
                <td valign="top">
                  <table bgcolor="#EEEEEE">
                    <tr>
                      <th class="list-header"><span tal:replace="kind" /> name</th>
                      <td class="list-item">
                        <strong tal:content="structure user/asHTML">
                        </strong>
                      </td>
                    </tr>
                    <tr>
                      <th class="list-header">Member of groups</th>
                      <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>
                    </tr>
                    <tr>
                      <th class="list-header">Implicitly member of groups</th>
                      <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>
                    </tr>
                    <tr>
                      <th class="list-header">Has roles</th>
                      <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>
                    </tr>
                    <tr>
                      <th class="list-header">Implicitly has roles (from groups)</th>
                      <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>
                    </tr>
                    <tr>
                      <td colspan="4" align="center"><br>
                          <input type="submit" name="changeUser:method" value="Change" />
                            <tal:block tal:replace="nothing">
                              XXX have to make this work again
                              &nbsp;
                              <input type="submit" name="deleteUser:method" value="Delete" />
                                <br>&nbsp;
                            </tal:block>
                      </td>
                    </tr>
                  </table>
                </td>

                <td valign="middle">
                  =>
                </td>

                <td valign="top">
                  <table  bgcolor="#EEEEEE">
                    <tr>
                      <td>
                        <!-- Groups selection -->
                        <table width="100%">
                          <tr class="list-header">
                            <th colspan="2">Set groups</th>
                          </tr>
                          
                          <tr tal:repeat="group here/getGroups">
                            <td>
                              <input type="checkbox" name="groups:list" value="" checked=""
                                     tal:condition="python: group.getUserName() != user.getUserName()"
                                tal:attributes="
                                value group/getUserName; 
                                checked python:test(group.getUserName() in user.getGroups(no_recurse=1), '1', '')">
                            </td>
                            <td>
                              <div class="list-item" tal:content="structure group/asHTML"></div>
                            </td>
                          </tr>
                        </table>

                        <br>

                          <!-- Roles selection -->
                          <table width="100%">
                            <tr class="list-header">
                              <th colspan="2">Set 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="" checked="" 
                                       tal:attributes="value role; checked python:test(role in user.getUserRoles(), '1', '')">
                              </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>
                          </table>
                      </td>
                    </tr>
                  </table>
        </ol>
      </tal:block>

    </form>


    <tal:block tal:condition="nothing|user/isGroup">
      XXX TODO ! XXX
      <h4>Group contents</h4>
      <ol>      
      <table bgcolor="#EEEEEE" tal:define="content python:list(user.getGroups(no_recurse=1))">
        <tr class="list-header">
          <th>Group/User</th>
          <th class="list-header">Member <br>of groups</th>
          <th class="list-header">Implicitly <br>member <br>of groups</th>
          <th class="list-header">Has roles</th>
          <th class="list-header">Implicitly <br>has roles <br>(from groups)</th>
        </tr>
        
        <tr 
            tal:repeat="user python:content" 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 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:user.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>
      </table>
      </ol>
    </tal:block>


    <h4>Instructions</h4>
    <ol>
      <p class="form-help">
        To change roles for a <span tal:replace="kind" />, 
          select the roles you want to give it and the groups it belongs to in the forms on the right and click "Change".<br />
      </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>

  </tal:block>

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

  
