<metal:block use-macro="python:here.getFormsTool().getForm('site_admin_users').macros['page']">
    <metal:block fill-slot="second-title" i18n:translate="">All users</metal:block>
    <metal:block use-macro="python:here.getFormsTool().getForm('site_admin_users').macros['description-text']">
    </metal:block>

    <metal:block fill-slot="content"><metal:block define-macro="content" tal:define="
            disabled_type python:request.form.get('disabled', 'no_disabled');
            users python: user_tool.search_users('', all_users=True);">

            <input type="hidden" id="template" value="site_admin_all_users" />
            <input type="hidden" id="all_users" value="True" />

            <script type="text/javascript" src="/++resource++Products.Naaya/lib/datatables/jquery.dataTables.min.js"></script>
            <link rel="stylesheet" type="text/css" href="/++resource++Products.Naaya/lib/datatables/jquery.dataTables.css" />
            <script type="text/javascript">
                $(document).ready(function(){
                    $('.users_listing').each(function(){
                      $(this).dataTable({
                        'aaSorting': [[0, "desc"]],
                        'sPaginationType': 'full_numbers',
                        'aLengthMenu': [[10, 25, 50, -1],
                                        [10, 25, 50, "All"]],
                        'iDisplayLength': 10

                      });
                    });

                    $('.ldap_groups').each(function(){
                      $(this).dataTable({
                        'aaSorting': [[0, "desc"]],
                        'sPaginationType': 'full_numbers',
                        'aLengthMenu': [[10, 25, 50, -1],
                                        [10, 25, 50, "All"]]
                      });
                    });
                });
            </script>
            <metal:block define-macro="datatable">
                <div class="user-results">
                    <table cellspacing="0" cellpadding="4" width="95%"
                        tal:define="users_roles user_tool/getUsersRoles;
                        users_roles_by_source python: dict((source.title, source.getUsersRoles(here)) for source in user_sources)"
                        class="datatable users_listing">
                        <thead>
                            <tr tal:condition="python:len(users) != 0">
                                <tal:block define="sortdata python: ({'key': 'username', 'label': 'Username'},
                                    {'key': 'name', 'label': 'Name/Email', 'width': '30%'},
                                    {'key': '', 'label': 'Roles in Locations'},
                                    {'key': 'source', 'label': 'Source'});">
                                    <th align="left" tal:repeat="item sortdata"
                                      tal:attributes="width item/width|nothing" i18n:translate=""
                                      tal:content="item/label" />
                                </tal:block>
                            </tr>
                        </thead>

                        <tbody>
                            <tal:block repeat="user users">
                                <tal:block define="all_user_roles user/roles;
                                    user_roles python:[user_role for user_role in all_user_roles if user_role[0][0] in user_tool.list_valid_roles()];
                                    row_class python:test(path('repeat/user/odd'), 'row-odd', 'row-even');
                                    user_nrows python: max(1, len(user_roles));
                                    user_id user/user_id;
                                    user_source_title user/source_title;">
                                    <tr tal:attributes="class row_class" tal:condition="python:user_roles or user_source_title == 'Local'">
                                        <!-- Username -->
                                        <td>
                                            <strong>
                                                <tal:block condition="python:user_source_title.lower() == 'local'">
                                                    <a tal:define="user_quoted python:here.utUrlEncode(user_id)"
                                                        tal:attributes="href string:${site_url}/admin_edituser_html?name=${user_quoted}&from=all"
                                                        tal:content="user_id">username</a>
                                                </tal:block>
                                                <tal:block condition="python: user_source_title.lower() == 'eionet'">
                                                    <a rel="external" tal:define="user_quoted python:here.utUrlEncode(user_id)"
                                                        tal:attributes="href string:https://www.eionet.europa.eu/directory/user?uid=${user_quoted}"
                                                        tal:content="user_id">username</a>
                                                </tal:block>
                                                <tal:block condition="python: user_source_title.lower() not in ['local', 'eionet']" tal:content="user_id"></tal:block>
                                            </strong>
                                            <tal:block define="user_photo_url python: user_tool.get_user_photo_url(user_id)">
                                                <a tal:condition="user_photo_url"
                                                    tal:attributes="href user_photo_url"
                                                    class="preview">[view photo]</a>
                                            </tal:block>
                                            <span tal:condition="user/is_new_user">
                                                <img src="misc_/Naaya/star.png" alt="New account"
                                                  tal:define="global any_new_account python:True" />
                                          </span>
                                          <span tal:condition="python: user_id in user_tool.user_names() and user_source_title != 'Local'">
                                              <img src="misc_/Naaya/conflict_users.png" alt="Conflicting usernames"  i18n:attributes="alt"
                                                  tal:define="global any_username_conflict python:True" />
                                          </span>
                                      </td>
                                        <!-- end of Username -->

                                        <!-- Name/Email -->
                                        <td>
                                            <div class="datatable-username">
                                                <tal:block replace="user/full_name"></tal:block>
                                                <span tal:content="user/status|nothing" />
                                            </div>

                                            <div class="datatable-email" tal:define="email python:user_tool.getUserEmail(user)">
                                                <a tal:attributes="href string:mailto:${email}; title string:Click to open email client" i18n:attributes="title" tal:content="email"></a>
                                            </div>
                                        </td>
                                        <!-- end of Name/Email -->

                                        <!-- Roles in Locations -->
                                        <td class="user-role" tal:condition="user_roles">
                                            <div tal:repeat="role user_roles">
                                                <span class="roles-title" tal:content="python: ', '.join(role[0])"></span> in
                                                <a class="roles-location" tal:define="obj python: role[1]" tal:attributes="href obj/absolute_url" tal:content="obj/title_or_id"></a>
                                            </div>
                                        </td>
                                        <td tal:condition="not: user_roles" class="user-role">-</td>
                                        <!-- end of Roles in Locations -->

                                        <!-- Source -->
                                        <td tal:content="string:${user_source_title} users"></td>
                                        <!-- end of Source -->
                                    </tr>
                                </tal:block>
                            </tal:block>

                            <tr tal:condition="python:len(users) == 0" class="tr-messages">
                                <td colspan="6">
                                    <p class="table-message" tal:define="source_id python: user_sources[0].id" i18n:translate="">
                                        No local users defined and no roles assigned to LDAP users yet.
                                        You can <a i18n:name="add-user-link" tal:attributes="href string:${site_url}/admin_adduser_html" title="Add local user" i18n:attributes="title" i18n:translate="">add a local user</a>
                                        and/or <a i18n:name="assing-role-link" tal:attributes="href string:${site_url}/admin_sources_html?id=${source_id}&s=assign_to_users">assign a role</a> to a LDAP			 user.
                                    </p>
                                </td>
                            </tr>
                        </tbody>
                    </table>

                    <div class="cleaner">&nbsp;</div>
                    <div class="tip"
                        tal:define="any_new_account any_new_account|nothing;
                        any_username_conflict any_username_conflict|nothing"
                        tal:condition="python:any_new_account or any_username_conflict">
                        <p>
                            <span i18n:translate="" tal:condition="any_new_account">
                                <img src="misc_/Naaya/star.png" alt="New-account" title="New-account" i18n:attributes="alt; title" i18n:name="new-account" /> local users added in the past 5 days
                            </span>
                            <br class="cleaner" />
                            <span i18n:translate="" tal:condition="any_username_conflict">
                                <img src="misc_/Naaya/conflict_users.png" alt="Conflicting usernames" title="Conflicting usernames" i18n:attributes="alt; title" i18n:name="conflicting-usernames" /> local and
                                LDAP accounts for the same username
                            </span>
                        </p>
                    </div>
                </div>
            </metal:block>

            <div class="separator"></div>

            <tal:block repeat="user_source user_sources">
                <div class="groups-roles-list" tal:condition="python:user_source.getUserFolder().meta_type == 'LDAPUserFolder'">
                    <tal:block tal:define="groups_roles_map user_source/get_groups_roles_map;">
                        <h3 i18n:translate="">
                            <tal:block i18n:name="source_title" replace="user_source/title_or_id"></tal:block> groups
                        </h3>

                        <div class="cleaner"></div>
                        <div class="description-text">
                            <p tal:condition="groups_roles_map" i18n:translate="">
                                Roles currently granted for <tal:block i18n:name="source_title" replace="user_source/title_or_id"></tal:block> groups are listed in the table
                                below.
                            </p>
                        </div>

                        <table cellspacing="0" cellpadding="3"
                            class="ldap_groups datatable">
                            <thead tal:condition="python: len(groups_roles_map) != 0">
                                <tr>
                                    <th i18n:translate=""><tal:block i18n:name="source_title" replace="user_source/title_or_id"></tal:block> groups</th>
                                    <th i18n:translate="">Roles/Location</th>
                                </tr>
                            </thead>

                            <tbody>
                                <tr tal:repeat="group_id groups_roles_map" tal:attributes="class python:test(path('repeat/group_id/odd'), 'row-odd', 'row-even')">
                                    <td>
                                        <a tal:attributes="href string:${here/absolute_url}/admin_sources_html?id=${user_source/id}&s=group_members&group_id=${group_id};
                                            title string:Click to see members of ${group_id};"
                                            tal:content="group_id" />
                                    </td>

                                    <td>
                                        <ul tal:define="group_roles python:groups_roles_map[group_id]">
                                            <li tal:repeat="role_and_location group_roles">
                                                <tal:block define="role python:role_and_location[0];
                                                    location python:role_and_location[1];">
                                                    <span tal:content="role" /> on
                                                    <a tal:condition="not:location/is_site"
                                                        tal:content="location/ob/title_or_id"
                                                        tal:attributes="href location/ob/absolute_url" />
                                                    <strong tal:condition="location/is_site">entire portal</strong>
                                                </tal:block>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>

                                <tr tal:condition="not:groups_roles_map" class="tr-messages">
                                    <td colspan="6">
                                        <p class="table-message" i18n:translate="">
                                            No <tal:block i18n:name="source_title" replace="user_source/title_or_id"></tal:block> groups have roles in this portal.
                                        </p>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </tal:block>

                </div>
                <div class="separator"></div>
            </tal:block>
    </metal:block></metal:block>
</metal:block>
