{# empty Twig template #}

<ul id="tree" class="filetree">

  {% if app.getAclForUser(app.getAuthenticatedUser()).is_admin() %}
  <li>
    <a target="right" href="{{ path('admin_dashboard') }}" class="ajax">
      <img src="/assets/admin/images/Dashboard.png" />
      <span>{{ 'Tableau de bord' | trans }}</span>
    </a>
  </li>
  {% else %}
  <li>
    <span>{{ app['conf'].get('servername') }}</span>
  </li>
  {% endif %}

  {% if app.getAclForUser(app.getAuthenticatedUser()).is_admin() %}
  <li>
    <a target="right" href="{{ path('setup_display_globals') }}" class="ajax">
      <img src="/assets/admin/images/Setup.png" />
      <span>{% trans %}Setup{% endtrans %}</span>
    </a>
  </li>
  <li>
    <a target="right" href="{{ path('admin_searchengine_form') }}">
      <span>{{ 'SearchEngine settings' | trans }}</span>
    </a>
  </li>
  {% endif %}

  <li class="{% if feature == 'connected' %}selected{% endif %}">
    <a target="right" href="{{ path('admin_connected_users') }}" class="ajax zone_online_users">
      <img src="/assets/admin/images/Connected.png" />
      <span>{{ 'admin::utilisateurs: utilisateurs connectes' | trans }}</span>
    </a>
  </li>

  {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::CANADMIN')) %}
  <li class="{% if feature == 'users' %}selected{% endif %}">
    <a target="right" href="{{ path('admin_users_search') }}" class="ajax zone_editusers">
      <img src="/assets/admin/images/Users.png" />
      <span>{{ 'admin::utilisateurs: utilisateurs' | trans }}</span>
    </a>
  </li>
  <li class="{% if feature == 'registrations' %}selected{% endif %}">
    <a target="right" href="{{ path('users_display_registrations') }}" class="ajax">
      <img src="/assets/admin/images/Demandes.png" />
      <span>{{ 'admin::utilisateurs: demandes en cours' | trans }}</span>
    </a>
  </li>
  {% endif %}

  {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::BAS_CHUPUB')) %}
  <li class="">
    <a target="right" href="{{ path('admin_feeds_list') }}" class="ajax">
      <img src="/assets/common/images/icons/rss16.png" />
      <span>{{ 'Publications' | trans }}</span>
    </a>
  </li>
  {% endif %}

  {% if app.getAclForUser(app.getAuthenticatedUser()).has_right(constant('\\ACL::TASKMANAGER')) %}
  <li class="{% if feature == 'taskmanager' %}selected{% endif %}">
    <a target="right" href="{{ path('admin_tasks_list') }}" class="ajax">
      <img src="/assets/admin/images/TaskManager.png" />
      <span>{{ 'admin::utilisateurs: gestionnaire de taches' | trans }}</span>
    </a>
  </li>
  {% endif %}

  <li>
    <a target="right" href="{{ path('admin_plugins_list') }}" class="ajax">
      <img src="/assets/admin/images/plugins-admin.png" />
      <span>{{ 'admin::plugins: plugins' | trans }}</span>
    </a>
  </li>

  <li class="open">
    <div class="{% if feature == 'bases' %}selected{% endif %}" style="padding:0 0 2px 0;">
      <a id="TREE_DATABASES" target="right" href="{{ path('admin_databases') }}" class="ajax">
        <img src="/assets/admin/images/DatabasesAvailable.png" />
        <span>{{ 'admin::utilisateurs: bases de donnees' | trans }}</span>
      </a>
    </div>
    <ul>

    {% for databox in databoxes %}

      {% set sbas_id = databox.get_sbas_id() %}

      {% if feature in ['base', 'collection', 'user'] and featured == sbas_id %}
        {% set this_is_open = true %}
      {% else %}
        {% set this_is_open = false %}
      {% endif %}

      {% if this_is_open and feature == 'base' %}
        {% set this_is_selected = true %}
      {% else %}
        {% set this_is_selected = false %}
      {% endif %}

      <li class="{% if this_is_open %}open{% endif %}">
        <div style="padding:0 0 2px 0;" class="{% if this_is_selected %}selected{% endif %}">
            <a target="right" href="{{ path('admin_database', { 'databox_id' : sbas_id }) }}" class="ajax">
                <img src="/assets/admin/images/Database.png"/>
                <span>{{ databox.get_label(app['locale']) }}</span>
            </a>
        </div>
        <ul>

        {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_sbas( sbas_id , constant('\\ACL::BAS_MODIFY_STRUCT')) %}
          <li>
            <a target="right" class="ajax" href="{{ path('database_display_stucture', { 'databox_id' : sbas_id }) }}">
              <img src="/assets/common/images/icons/miniadjust01.gif"/>
              <span>{{ 'admin::structure: reglage de la structure' | trans }}</span>
            </a>
          </li>
          <li>
            <a target="right" href="{{ path('admin_fields', {'sbas_id': sbas_id}) }}" class="ajax">
              <img src="/assets/common/images/icons/miniadjust01.gif"/>
              <span>{{ 'CHAMPS' | trans }}</span>
            </a>
          </li>
          <li>
            <a target="right" href="{{ path('admin_subdefs_subdef', { 'sbas_id' : sbas_id } ) }}">
              <img src="/assets/common/images/icons/miniadjust01.gif"/>
              <span>{{ 'SUBDEFS' | trans }}</span>
            </a>
          </li>
          <li>
            <a target="right" href="{{ path('database_display_statusbit', { 'databox_id' : sbas_id } ) }}" class="ajax">
              <img src="/assets/common/images/icons/miniadjust02.gif"/>
              <span>{{ 'admin::status: reglage des status' | trans }}</span>
            </a>
          </li>
          <li>
            <a target="right" href="{{ path('admin_database_display_cgus', { 'databox_id' : sbas_id } ) }}" class="ajax">
              <img src="/assets/common/images/icons/miniadjust02.gif"/>
              <span>{{ 'Terms of use' | trans }}</span>
            </a>
          </li>
          <li>
              <a target="right" href="{{ path('admin_database_display_collections_order', { 'databox_id' : sbas_id } ) }}" class="ajax">
              <img src="/assets/common/images/icons/miniadjust03.gif"/>
              <span>{{ 'admin::collection: ordre des collections' | trans }}</span>
            </a>
          </li>
        {% endif %}

        {% set seeUsrGene = false %}

        {% for coll in databox.get_collections() %}
          {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base( coll.get_base_id() , constant('\\ACL::CANADMIN')) %}
            {% set seeUsrGene = true %}
          {% endif %}
        {% endfor %}

        {% if seeUsrGene %}
          <li>
            <a target="right" href="{{ path('admin_users_search', { 'sbas_id' : [ sbas_id ] }) }}" class="ajax">
              <img src="/assets/admin/images/Users.png"/>
              <span>{{ 'admin::utilisateurs: utilisateurs' | trans }}</span>
            </a>
          </li>
        {% endif %}

        {% for collection in databox.get_collections()|sort_collections %}
          {% if (collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base([constant('\\ACL::CANADMIN')])|keys
              or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base([constant('\\ACL::COLL_MANAGE')])|keys
              or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base([constant('\\ACL::COLL_MODIFY_STRUCT')])|keys) %}

          {% if feature == 'collection' and featured == collection.get_base_id() %}
              {% set coll_selected = true %}
          {% else %}
              {% set coll_selected = false %}
          {% endif %}

          <li>
            <div style="padding:0 0 2px 0;" {% if coll_selected %}class="selected"{% endif %}>
                <a target="right" href="{{ path('admin_display_collection', { 'bas_id' : collection.get_base_id() }) }}" class="ajax">
                    <span>{{ collection.get_name() }}</span>
                </a>
            </div>
            <ul>

            {% if (app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(collection.get_base_id(), constant('\\ACL::COLL_MODIFY_STRUCT'))) %}
              <li>
                <a target="right" href="{{ path('admin_collection_display_suggested_values', { 'bas_id' : collection.get_base_id() }) }}" class="ajax">
                  <img src="/assets/common/images/icons/foldph20open_0.gif"/>
                  <span>{{ 'admin::base: preferences de collection' | trans }}</span>
                </a>
              </li>
            {% endif %}

            {% if app.getAclForUser(app.getAuthenticatedUser()).has_right_on_base(collection.get_base_id(), constant('\\ACL::CANADMIN')) %}
              <li>
                <a target="right" href="{{ path('admin_users_search', { 'base_id' : [ collection.get_base_id() ] }) }}" class="ajax">
                  <img src="/assets/admin/images/Users.png"/>
                  <span>{{ 'admin::utilisateurs: utilisateurs' | trans }}</span>
                </a>
              </li>
            {% endif %}

            </ul>
          </li>

          {% endif %}
        {% endfor %}

        </ul>
      </li>
    {% endfor %}

    </ul>
  </li>

  {% for databox in off_databoxes %}
  <li>
    <img src="/assets/common/images/icons/db-remove.png"/>
    {{ databox.get_dbname() }} ({{ databox.get_host() }} {{ databox.get_port() }})
  </li>
  {% endfor %}
</ul>
