{% extends "hostingpackages/base.html" %}
{% load i18n %}

{% block title %}{{ block.super }} - {% spaceless %}
{% if user == customer %}
  {% blocktrans with package=hostingpackage.name %}Details for your Hosting Package {{ package }}{% endblocktrans %}
{% else %}
  {% blocktrans with package=hostingpackage.name full_name=customer.get_full_name %}Details for Hosting Package {{ package }} of {{ full_name }}{% endblocktrans %}
{% endif %}
{% endspaceless %}{% endblock title %}

{% block page_title %}{% blocktrans with package=hostingpackage.name %}Details of Hosting Package {{ package }}{% endblocktrans %}{% endblock page_title %}

{% block content %}
<div class="row">
  <div class="col-lg-4 col-md-6 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% spaceless %}
        {% trans "Hosting Package Information" %}
        {% if user.is_staff %}
        <div class="pull-right">
          <a class="panel-title" href="#" title="{% trans "Edit Hosting Package Information" %}"><i class="glyphicon glyphicon-cog"></i></a>
        </div>
        {% endif %}
      {% endspaceless %}</div>
      <dl class="panel-body dl-horizontal">
        <dt>{% trans "Name" %}</dt>
        <dd>{{ hostingpackage.name }}</dd>
        <dt>{% trans "Description" %}</dt>
        <dd>{{ hostingpackage.description|default:"-" }}</dd>
        <dt>{% trans "Disk space" %}</dt>
        {% with diskspace=hostingpackage.get_disk_space packagespace=hostingpackage.get_package_space %}
        <dd>
          <span title="{% blocktrans %}The reserved disk space for your hosting package is {{ diskspace }} bytes{% endblocktrans %}">{{ diskspace|filesizeformat }}</span>
          <span class="glyphicon glyphicon-info-sign" title="{% blocktrans with humanbytes=packagespace|filesizeformat %}The package contributes {{ humanbytes }} ({{ packagespace }} bytes) the difference comes from disk space options{% endblocktrans %}"></span>
        </dd>
        {% endwith %}
        <dt>{% trans "Mailboxes" %}</dt>
        <dd>{% blocktrans with num=hostingpackage.used_mailbox_count total=hostingpackage.mailbox_count %}{{ num }} of {{ total }} in use{% endblocktrans %} <span class="glyphicon
        glyphicon-info-sign" title="{% blocktrans with mailboxcount=hostingpackage.mailboxcount %}The package provides {{ mailboxcount }} mailboxes the difference comes from mailbox options.{% endblocktrans %}"></span></dd>
        <dt>{% if osuser.is_sftp_user %}{% trans "SFTP username" %}{% else %}{% trans "SSH/SFTP username" %}{% endif %}</dt>
        <dd>{{ osuser.username }}{% if sshkeys %} <a href="{% url 'list_ssh_keys' package=hostingpackage.id %}" class="badge" title="{% blocktrans count counter=sshkeys|length %}There is an SSH public key set for this user.{% plural %}There are {{ counter }} SSH public keys set for this user.{% endblocktrans %}"><i class="fa fa-key"></i> {{ sshkeys|length }}</a>{% endif %}</dd>
        <dt>{% trans "Upload server" %}</dt>
        <dd>{{ uploadserver }}</dd>
      </dl>
    </div>
  </div>
  <div class="col-lg-4 col-md-6 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% trans "Hosting Package Options" %}</div>
      {% if hostingoptions %}
      <ul class="list-group">
        {% for opt in hostingoptions %}
        <li class="list-group-item">{{ opt }}</li>
        {% endfor %}
      </ul>
      {% else %}
      <p class="panel-body text-info">{% trans "No options booked" %}</p>
      {% endif %}
      {% if user.is_staff %}
      <p class="panel-body"><a class="btn btn-primary" href="{% url 'hosting_option_choices' pk=hostingpackage.id %}" title="{% trans "Add another hosting option" %}">{% trans "Add option" %}</a></p>
      {% endif %}
    </div>
  </div>
  <div class="col-lg-4 col-md-6 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% trans "Hosting Package Actions" %}</div>
      <ul class="list-group">
        <li class="list-group-item"><a href="#" title="{% trans "Edit Hosting Package Description" %}">{% trans "Edit description" %}</a></li>
        <li class="list-group-item"><a href="{% url "set_osuser_password" slug=osuser.username %}">{% if osuser.is_sftp_user %}{% trans "Set SFTP password" %}{% else %}{% trans "Set SSH/SFTP password" %}{% endif %}</a></li>
        <li class="list-group-item"><a href="{% url "add_ssh_key" package=hostingpackage.id %}" title="{% blocktrans %}Add an SSH public key that can be used as an alternative for password{% endblocktrans %}">{% trans "Add SSH public key" %}</a></li>
      </ul>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-lg-12 col-md-12 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% trans "Domains" %}</div>
      {% if domains %}
      <table class="table table-condensed">
        <thead>
          <tr>
            <th class="name-column">{% trans "Domain name" %}</th>
            <th>{% trans "Mail addresses" %}</th>
            <th>{% trans "Websites" %}</th>
            <th title="{% trans "Domain actions" %}" class="actions-column"><span class="sr-only">{% trans "Actions" %}</span></th>
          </tr>
        </thead>
        <tbody>
          {% for domain in domains %}
          <tr>
            <td>{{ domain.domain }}</td>
            {% if domain.domain.maildomain.mailaddress_set.exists %}
            <td>
              {% with maildomain=domain.domain.maildomain %}
              {% for mailaddress in maildomain.mailaddresses %}{% spaceless %}
              <a href="{% url 'edit_mailaddress' package=hostingpackage.id domain=maildomain.domain pk=mailaddress.id %}" title="{% trans "Edit mail address targets" %}">{{ mailaddress }}</a>
              <a href="{% url 'delete_mailaddress' package=hostingpackage.id domain=maildomain.domain pk=mailaddress.id %}" title="{% trans "Delete mail address" %}"><i class="glyphicon glyphicon-trash"></i><span class="sr-only"> {% trans "Delete mail address" %}</span></a>
              {% endspaceless %}{% if not forloop.last %}, {% endif %}{% endfor %}
              {% endwith %}
            </td>
            {% else %}
            <td class="text-info">{% trans "None" %}</td>
            {% endif %}
            {% if domain.domain.website_set.exists %}
            <td>
              {% with domain=domain.domain %}
              {% for website in domain.website_set.all %}{% spaceless %}
              {{ website }}
              <a href="{% url 'delete_website' package=hostingpackage.id domain=domain.domain pk=website.id %}" titel="{% trans "Delete website" %}"><i class="glyphicon glyphicon-trash"></i><span class="sr-only"> {% trans "Delete website" %}</span></a>
              {% endspaceless %}{% if not forloop.last %}, {% endif %}{% endfor %}
              {% endwith %}
            </td>
            {% else %}
            <td class="text-info">{% trans "None" %}</td>
            {% endif %}
            <td>
              {% if domain.domain.maildomain %}
                 {% with maildomain=domain.domain.maildomain %}
                   <a href="{% url 'add_mailaddress' package=hostingpackage.id domain=maildomain.domain %}" title="{% trans "Add mail address" %}"><i class="fa fa-envelope"></i><span class="sr-only"> {% trans "Add mail address" %}</span></a>
                 {% endwith %}
              {% endif %}
              {% with hostingdomain=domain.domain %}
              <a href="{% url 'add_website' package=hostingpackage.id domain=hostingdomain.domain %}" title="{% trans "Add website" %}"><i class="glyphicon glyphicon-globe"></i><span class="sr-only"> {% trans "Add website" %}</span></a>
              {% endwith %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <p class="panel-body text-info">{% trans "There are no domains assigned to this hosting package yet." %}</p>
      {% endif %}
      {% if user.is_staff %}
      <p class="panel-body"><a href="{% url 'create_hosting_domain' package=hostingpackage.id %}" class="btn btn-primary">{% trans "Add domain" %}</a></p>
      {% endif %}
    </div>
  </div>
</div>
<div class="row">
  <div class="col-lg-12 col-md-12 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% trans "E-Mail-Accounts" %}</div>
      {% if mailboxes %}
      <table class="table table-condensed">
        <thead>
          <tr>
            <th class="name-column">{% trans "Mailbox" %}</th>
            <th>{% trans "Mail addresses" %}</th>
            <th class="status-column">{% trans "Active" %}</th>
            <th title="{% trans "Mailbox actions" %}" class="actions-column"><span class="sr-only">{% trans "Actions" %}</span></th>
          </tr>
        </thead>
        <tbody>
          {% for mailbox in mailboxes %}
          <tr>
            <td>{{ mailbox.username }}</td>
            <td>{{ mailbox.mailaddresses|join:", " }}</td>
            <td><i class="glyphicon glyphicon-{% if mailbox.active %}ok-circle{% else %}minus-sign{% endif %}"></i><span class="sr-only"> {% if mailbox.active %}{% trans "Active" %}{% else %}{% trans "inactive" %}{% endif %}</span></td>
            <td>
              <a href="{% url 'change_mailbox_password' package=hostingpackage.id slug=mailbox.username %}"><i class="fa fa-user-secret" title="{% trans "Set mailbox password" %}"></i><span class="sr-only"> {% trans "Set mailbox password" %}</span></a>
            </td>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <p class="panel-body text-info">{% trans "There are no mailboxes assigned to this hosting package yet." %}</p>
      {% endif %}
      {% if hostingpackage.may_add_mailbox %}
      <p class="panel-body"><a href="{% url 'create_mailbox' package=hostingpackage.id %}" class="btn btn-primary">{% trans "Add mailbox" %}</a></p>
      {% endif %}
    </div>
  </div>
</div>
<div class="row">
  <div class="col-lg-12 col-md-12 col-xs-12">
    <div class="panel panel-default">
      <div class="panel-heading">{% trans "Databases" %}</div>
      {% if databases %}
      <table class="table table-condensed">
        <thead>
          <tr>
            <th class="name-column">{% trans "Database name" %}</th>
            <th class="name-column">{% trans "Database user" %}</th>
            <th title="{% trans "Database type" %}"><span class="sr-only">{% trans "Type" %}</span></th>
            <th title="{% trans "Database actions" %}" class="actions-column"><span class="sr-only">{% trans "Actions" %}</span></th>
          </tr>
        </thead>
        <tbody>
          {% for database in databases %}
          <tr>
            <td>{{ database.db_name }}</td>
            <td>{{ database.db_user.name }}</td>
            <td>{% include "userdbs/snippets/db_type.html" with db_type=database.db_user.db_type %}</td>
            <td>
              <a href="{% url 'change_dbuser_password' package=hostingpackage.id slug=database.db_user.name %}" title="{% trans "Set database user password" %}"><i class="fa fa-user-secret"></i><span class="sr-only"> {% trans "Set database user password" %}</span></a>
              <a href="{% url 'delete_userdatabase' package=hostingpackage.id slug=database.db_name %}" title="{% trans "Delete database" %}"><i class="glyphicon glyphicon-trash"></i><span class="sr-only">{% trans "Delete database" %}</span></a>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      {% else %}
      <p class="panel-body text-info">{% trans "There are no databases assigned to this hosting package yet." %}</p>
      {% endif %}
      {% if hostingpackage.may_add_database %}
      <p class="panel-body"><a href="{% url 'add_userdatabase' package=hostingpackage.id %}" class="btn btn-primary">{% trans "Add database" %}</a></p>
      {% endif %}
    </div>
  </div>
</div>
{% endblock content %}
