<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>

  <ol>
    <p class="form-help">
      You are currently running <strong>GRUF v.<span tal:replace="here/getGRUFVersion">version</span></strong><br />
      Information, latest version, documentation... see 
      <a target="_blank" href="http://ingeniweb.sourceforge.net/Products/GroupUserFolder">The GRUF Webpage</a>.
    </p>
  </ol>

  <!-- Show problems if it happens -->
  <div tal:condition="request/GRUF_PROBLEM|nothing">
    <font color="red"><strong><span tal:content="request/GRUF_PROBLEM">gruf message</span></strong></font>
  </div>


  <h4>Users folders management</h4>
  <ol>
    <p class="form-help">Use this form to check/manage the underlying user folders.</p>
    <p class="form-help">BE CAREFUL THAT MISUSE OF THIS FORM CAN LEAD YOU TO UNRECOVERABLE LOSS OF USER DATA.</p>
    <p class="form-help">For this reason, all destructive actions (ie. replacing or deleting) with existing UserFolders must be confirmed
    by clicking the rightmost checkbox.</p>

    <form action="" tal:attributes="action string:${here/absolute_url}" method="POST">
      <!-- Users selection -->
      <table bgcolor="#EEEEEE" tal:on-error="nothing">
        <tr>
          <td rowspan="2" valign="middle"></td>
          <th class="list-header" rowspan="2" valign="middle">Type</th>
          <th class="list-header" colspan="5">Actions</th>
        </tr>
        <tr class="list-header">
          <th>Move</th>
          <th>Enable</th>
          <th>Replace</th>
          <th>Delete</th>
          <th>Confirm</th>
        </tr>

        <!-- Groups source row -->
        <tr>
          <th class="list-header">Groups source</th>
          <td bgcolor="#EEEEEE">
              <img src="" tal:attributes="src here/Groups/acl_users/icon">&nbsp;
              <a href="Groups/acl_users/manage_workspace" tal:content="here/Groups/acl_users/meta_type">Type</a>
          </td>
          <td></td>
          <td bgcolor="#EEEEEE">&nbsp;</td>
          <td bgcolor="#EEEEEE">
            <table border="0">
              <tr>
                <td align="left">
                  <input type="hidden" name="source_rec.id:records" value="Groups" />
                  <select name="source_rec.new_factory:records">
                    <option value="">-- Select your source type --</option>
                    <tal:block tal:repeat="source here/listAvailableUserSources">
                      <option value="" 
                              tal:condition="python:source[0] != path('here/Groups/acl_users/meta_type')"
                        tal:attributes="value python:source[1]">
                        <span tal:replace="python:source[0]">name</span>
                      </option>
                    </tal:block>
                  </select>
                </td>
                <td align="right">
                  <input type="submit" name="replaceUserSource:action" value="Ok" />
                </td>
              </tr>
            </table>
          </td>
          <td class="list-item">(forbidden)</td>
          <td bgcolor="#EEEEEE" class="list-item">
            <input type="checkbox" name="id" value="Groups" />I'm sure
          </td>
        </tr>


        <!-- Users sources row -->
        <tr tal:repeat="source here/listUserSourceFolders">
          <th class="list-header">Users source #<span tal:replace="repeat/source/number">1</span></th>
          <td bgcolor="#EEEEEE" tal:condition="source/isValid">
            <img src="" 
	    tal:attributes="src source/acl_users/icon;
	    title source/acl_users/meta_type;">&nbsp;
              <a href="" 
	      tal:attributes="
	      href string:${source/acl_users/absolute_url}/manage_workspace;
	      title source/acl_users/meta_type;" 
	       tal:content="source/acl_users/title|source/acl_users/meta_type">Type</a>
                <tal:block condition="not:source/isEnabled">
                  <font color="red"><i>(disabled)</i></font>
                </tal:block>
          </td>
          <td bgcolor="#EEEEEE" tal:condition="not:source/isValid">
            <font color="red"><strong><i>(invalid or broken)</i></strong></font>
          </td>
          <td bgcolor="#EEEEEE" align="center">
            <a tal:condition="not:repeat/source/start" 
              tal:attributes="href string:${here/absolute_url}/moveUserSourceUp?id=${source/getUserSourceId}"
              href=""><img src="img_up_arrow" border="0" alt="Move up"></a>
            <span tal:condition="repeat/source/start"><img src="img_up_arrow_grey" border="0" alt="Move up"></span>
            &nbsp;
            <a tal:condition="not:repeat/source/end" 
              tal:attributes="href string:${here/absolute_url}/moveUserSourceDown?id=${source/getUserSourceId}"
              href=""><img src="img_down_arrow" border="0" alt="Move down"></a>
            <span tal:condition="repeat/source/end"><img src="img_down_arrow_grey" border="0" alt="Move down"></span>
          </td>
              <td bgcolor="#EEEEEE">
                <font size="-2">
                  <a
                    tal:condition="source/isEnabled"
                    tal:attributes="href string:${here/absolute_url}/toggleSource?src_id=${source/getUserSourceId}"
                    >Disable
                  </a>
                  <a
                    tal:attributes="href string:${here/absolute_url}/toggleSource?src_id=${source/getUserSourceId}"
                    tal:condition="not: source/isEnabled"
                    >Enable
                  </a>
                </font>
              </td>
          <td bgcolor="#EEEEEE">
            <table border="0">
              <tr>
                <td align="left">
                  <input type="hidden" name="source_rec.id:records" value="" tal:attributes="value source/getUserSourceId" />
                  <select name="source_rec.new_factory:records">
                    <option value="">-- Select your source type --</option>
                    <tal:block tal:repeat="new_source here/listAvailableUserSources">
                      <option value="" 
                              tal:condition="python:new_source[0] != path('source/acl_users/meta_type')"
                        tal:attributes="value python:new_source[1]">
                        <span tal:replace="python:new_source[0]">name</span>
                      </option>
                    </tal:block>
                  </select>
                </td>
                <td align="right">
                  <input type="submit" name="replaceUserSource:action" value="Ok" />
                </td>
              </tr>
            </table>
          </td>
          <td bgcolor="#EEEEEE" tal:condition="python:repeat['source'].length > 1" class="list-item">
            <input 
                   type="submit" 
                   name="deleteUserSource:action" 
                   value="Delete" />
          </td>
          <td tal:condition="python:not repeat['source'].length > 1" class="list-item">
            (forbidden)
          </td>
          <td bgcolor="#EEEEEE" class="list-item">
            <input type="checkbox" name="id" value="" tal:attributes="value source/getUserSourceId" />I'm sure
          </td>
        </tr>


        <!-- Blank row -->
        <tr>
          <td class="list-item" colspan="6">&nbsp;</td>
        </tr>

        <!-- New sources row -->
        <tr>
          <th class="list-header">Add...</th>
          <td colspan="6" class="list-item">
            <select name="factory_uri">
              <option value="">-- Select your source type --</option>
              <option value="" tal:repeat="source here/listAvailableUserSources" tal:attributes="value python:source[1]">
                <span tal:replace="python:source[0]">name</span>
              </option>
            </select>
            <input type="submit" name="addUserSource:method" value="Add" />
          </td>
        </tr>
      </table>
    </form>
    
  </ol>

    <tal:block condition="here/hasLDAPUserFolderSource">
      <h4>Special operations</h4>
      <ol>
          <p class="form-help">
            To manage groups with a LDAPUserFolder, one must map LDAP groups to Zope Roles.<br />
            You can do this mapping manually or click this button to have it done automatically.<br />
            Please not that any previously existing ldap-group - to - zope-role mapping may be lost.
          </p>
          <p class="form-help">
            To help you in this task, you can have a look at the following table, which summs up<br />
            the mappings done (or not done!) in LDAPUserFolder.
          </p>

      <table>
        <thead>
          <th>GRUF group</th>
          <th>LDAP group</th>
        </thead>
        <tbody>
          <tr tal:repeat="group_info here/listLDAPUserFolderMapping">
            <td tal:content="python:group_info[0]"></td>
            <td tal:content="python:group_info[1]"></td>
          </tr>
        </tbody>
      </table>
          <form action="updateLDAPUserFolderMapping">
            <input type="submit" value="Update LDAP mapping" />
          </form>
      </ol>
    </tal:block>


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