<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
    lang="en"
    metal:use-macro="context/prefs_main_template/macros/master"
    i18n:domain="plone">

<body>

<metal:main fill-slot="prefs_configlet_content"
    tal:define="Batch python:modules['Products.CMFPlone'].Batch;
                b_start request/b_start | python:0;
                b_size request/b_size | python:20;
                portal_roles context/getGlobalPortalRoles;
                searchstring request/searchstring | nothing;
                portal_url context/portal_url;
                checkPermission nocall: context/portal_membership/checkPermission;">

      <div class="documentEditable"
           tal:condition="python:checkPermission('Manage users', context)">

          <div id="edit-bar">
              <ul class="contentViews" id="content-views">
                <li class="selected">
                  <a href=""
                     tal:attributes="href string:$portal_url/${template/getId}"
                     i18n:translate="label_users">Users</a>
                </li>
                <li>
                  <a href=""
                     tal:attributes="href string:$portal_url/prefs_groups_overview"
                     i18n:translate="label_groups">Groups</a>
                </li>
                <li>
                  <a href=""
                     tal:attributes="href string:$portal_url/@@usergroup-controlpanel"
                     i18n:translate="label_usergroup_settings">Settings</a>
                </li>
              </ul>
              <div class="contentActions">&nbsp;</div>
          </div>

          <div metal:use-macro="context/global_statusmessage/macros/portal_message">
            Portal status message
          </div>

          <div id="content">
            <h1 class="documentFirstHeading"
                i18n:translate="heading_users_overview">Users Overview</h1>

            <div id="content-core">
                <a href=""
                   class="link-parent"
                   tal:attributes="href string:$portal_url/plone_control_panel"
                   i18n:translate="label_up_to_plone_setup">
                  Up to Site Setup
                </a>

                <p i18n:translate="description_user_management">
                  Click the user's name to see and change the details of a
                  specific user. You can also add and remove users.
                </p>
                <p i18n:translate="user_role_note">
                  Note that roles listed here apply directly to a user.
                  They do not reflect additional roles users may have due
                  to group memberships.
                </p>
                <p i18n:translate="description_pas_users_listing"
                   tal:condition="nothing | python:not searchstring and not context.acl_users.canListAllUsers()">
                  Note: Some or all of your PAS user source
                  plugins do not allow listing of users, so you may not see
                  the users defined by those plugins unless doing a specific
                  search.
                </p>

                <form action=""
                      name="users_add"
                      method="post"
                      tal:attributes="action string:$portal_url/${template/getId}">

                  <input class="standalone add"
                             type="submit"
                             name="form.button.AddUser"
                             value="Add New User"
                             i18n:attributes="value label_add_new_user;"
                             />
                  <input type="hidden" name="form.submitted" value="1" />
                </form>

                <form action=""
                      class="enableAutoFocus"
                      name="users_search"
                      method="post"
                      tal:attributes="action template/getId"
                      tal:define="findAll python:'form.button.FindAll' in request.keys();
                                  search_view context/@@pas_search;
                                  portal_users python:(searchstring or findAll) and search_view.searchUsers(**(findAll and dict(sort_by='userid') or dict(sort_by='userid', fullname=searchstring))) or [];
                                  batch python:Batch(portal_users, b_size, int(b_start), orphan=1);
                                  many_users context/portal_properties/site_properties/many_users">
                  <input type="hidden" name="form.submitted" value="1" />

                  <table class="listing" summary="User Listing">
                        <tr>
                          <th colspan="6" tal:attributes="colspan python:len(portal_roles)+4">
                            <span tal:omit-tag="" i18n:translate="label_user_search">User Search</span>:
                                <input class="quickSearch"
                                       type="text"
                                       name="searchstring"
                                       value=""
                                       tal:attributes="value searchstring;"
                                       />

                            <input type="submit"
                                           class="searchButton"
                                           name="form.button.Search"
                                           value="Search"
                                           i18n:attributes="value label_search;"
                                           />

                            <input type="submit"
                                           class="searchButton"
                                           name="form.button.FindAll"
                                           value="Show all"
                                           i18n:attributes="value label_showall;"
                                           tal:condition="not:many_users"
                                           />
                          </th>
                        </tr>
                        <tal:block tal:condition="portal_users" >
                          <tr>
                            <th rowspan="2" i18n:translate="listingheader_user_name">User name</th>
                            <th rowspan="2" i18n:translate="listingheader_email_address">E-mail Address</th>
                            <th colspan="3" tal:attributes="colspan python:len(portal_roles)"
                                i18n:translate="listingheader_roles">Roles</th>
                            <th rowspan="2" i18n:translate="listingheader_reset_password">Reset Password</th>
                            <th rowspan="2" i18n:translate="listingheader_remove_user">Remove user</th>
                          </tr>
                          <tr>
                            <th tal:repeat="portal_role portal_roles" tal:content="portal_role" i18n:translate="">Role</th>
                          </tr>
                        </tal:block>

                        <tal:block repeat="this_user batch">
                            <tr tal:define="oddrow repeat/this_user/odd;
                                            userid this_user/userid;
                                            mq python:modules['ZTUtils'].make_query;
                                            userquery python:mq(userid=userid);
                                            user python:context.portal_membership.getMemberById(userid)"
                                tal:condition="python:user is not None"
                                tal:attributes="class python:test(oddrow,'odd','even')">

                              <td>
                                    <a href="prefs_user_details"
                                       tal:attributes="href string:$portal_url/prefs_user_details?${userquery}">
                                  <tal:block replace="structure context/portal_url/user.png"/>&nbsp;<span tal:replace="userid">username</span>
                                  (<span tal:replace="python:user.getProperty('fullname')">Full Name</span>)
                                    </a>
                                    <input type="hidden" name="users.id:records" tal:attributes="value userid" />
                              </td>

                              <td tal:define="email python:user.getProperty('email')">
                                <a href="#"
                                           class="link-plain"
                                           tal:attributes="href string:mailto:${email}"
                                           title="Send a mail to this user"
                                           i18n:attributes="title title_send_mail_to_user;"
                                           ><tal:block replace="structure context/mail_icon.png"/></a>
                                <input style="margin:2px;"
                                               type="text"
                                   size="15"
                                   name="users.email:records"
                                   value=""
                                   tal:attributes="value email;
                                                   disabled python:user.canWriteProperty('email') and default or 'disabled'" />
                              </td>

                              <td class="listingCheckbox"
                                  tal:define="user_roles user/getRoles"
                                  tal:repeat="portal_role portal_roles">
                                <input type="checkbox"
                                   class="noborder"
                                   name="users.roles:list:records"
                                   value="Manager"
                                               tal:attributes="value portal_role;
                                                   checked python:test(portal_role in user_roles, 'checked', nothing);
                                                   disabled python:user.canAssignRole(portal_role) and default or 'disabled'" />
                              </td>

                              <td class="listingCheckbox">
                                <input type="checkbox"
                                   class="noborder"
                                   name="users.resetpassword:records"
                                               value=""
                                               tal:attributes="value userid;
                                                               disabled python:user.canPasswordSet() and default or 'disabled'" />
                              </td>

                              <td class="listingCheckbox">
                                <input type="checkbox"
                                               class="noborder notify"
                                               name="delete:list"
                                               value=""
                                               tal:attributes="value userid;
                                                               disabled python:user.canDelete() and default or 'disabled'" />
                              </td>
                            </tr>
                        </tal:block>
                        <tr tal:condition="not:batch">
                            <td tal:condition="searchstring"
                                i18n:translate="text_nomatches"
                                style="text-align:center;">No matches</td>
                            <tal:block tal:condition="not:searchstring">
                              <td tal:condition="many_users"
                                  class="discreet"
                                  i18n:translate="text_no_user_searchstring"
                                  style="text-align:center; font-size: 100%;">
                                  Enter a username to search for
                              </td>
                              <td tal:condition="not:many_users"
                                  class="discreet"
                                  i18n:translate="text_no_user_searchstring_largesite"
                                  style="text-align:center; font-size: 100%;">
                                  Enter a username to search for, or click 'Show All'
                              </td>
                            </tal:block>
                        </tr>
                  </table>

                  <div metal:use-macro="context/batch_macros/macros/navigation" />

                  <input class="context"
                     type="submit"
                     name="form.button.Modify"
                     value="Apply Changes"
                     i18n:attributes="value label_apply_changes;"
                     tal:condition="batch"
                     />

                  <input tal:replace="structure context/@@authenticator/authenticator" />

                </form>
            </div>
          </div>
      </div>

      <div class="documentEditable"
           tal:condition="python:not checkPermission('Manage users', context)">
        <tal:block replace="context/raiseUnauthorized" />
      </div>
</metal:main>

</body>
</html>

