{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% set active_menu = 'support' %}
{% block meta_title %}Forum{% endblock %}

{% block content %}
<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-index">{% trans 'Topics' %}</a></li>
        <li><a href="#tab-forums">{% trans 'Forums' %}</a></li>
        <li><a href="#tab-new">{% trans 'New topic' %}</a></li>
        <li><a href="#tab-new-forum">{% trans 'New forum' %}</a></li>
    </ul>

    <div class="tabs_container">

        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">

        {{ mf.table_search }}
        <table class="tableStatic wide">
            <thead>
                <tr>
                    <td style="width: 60%">{% trans 'Title' %}</td>
                    <td>{% trans 'Replies' %}</td>
                    <td>{% trans 'Views' %}</td>
                    <td>{% trans 'Status' %}</td>
                    <td>{% trans 'Sticky' %}</td>
                    <td style="width: 13%">Actions</td>
                </tr>
            </thead>

            <tbody>
            {% set topics = admin.forum_topic_get_list({"per_page":30, "page":request.page}|merge(request)) %}
            {% for i, topic in topics.list %}

            {% if topic.forum.id != group %}
            <tr class="group">
                <th colspan="6"><a href="{{ '/forum'|alink }}/{{topic.forum.id}}">{{topic.forum.title}}</a></th>
            </tr>
            {% set group = topic.forum.id %}
            {% endif %}

            <tr>
                <td>{{ topic.title }}</td>
                <td>{{ topic.stats.posts_count }}</td>
                <td>{{ topic.stats.views_count }}</td>
                <td>{{ mf.status_name(topic.status) }}</td>
                <td>{{ mf.q(topic.sticky) }}</td>
                <td class="actions">
                    <a class="bb-button btn14" href="{{ '/forum/topic'|alink }}/{{topic.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                    <a class="bb-button btn14 bb-rm-tr api-link" href="admin/forum/topic_delete?id={{topic.id}}" data-api-confirm="Are you sure?" data-api-redirect="forum"><img src="images/icons/dark/trash.png" alt=""></a>
                </td>
            </tr>
            </tbody>

            {% else %}
            <tbody>
                <tr>
                    <td colspan="6">
                        {% trans 'The list is empty' %}
                    </td>
                </tr>
            </tbody>
            {% endfor %}

            {% if topics.pages > 1 %}
            <tfoot>
                <tr>
                    <td colspan="6">
                        {% include "partial_pagination.phtml" with {'list': topics, 'url':'forum'} %}
                    </td>
                </tr>
            </tfoot>
            {% endif %}
        </table>
        </div>

        <div class="tab_content nopadding" id="tab-new">

            <form method="post" action="admin/forum/topic_create" class="mainForm save api-form" data-api-redirect="forum">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Forum' %}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('forum_id', admin.forum_get_pairs, request.forum_id, 1) }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Status' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="status" value="active" checked="checked"/><label>{% trans 'Active' %}</label>
                            <input type="radio" name="status" value="locked" /><label>{% trans 'Locked' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Sticky' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="sticky" value="1" /><label>{% trans 'Yes' %}</label>
                            <input type="radio" name="sticky" value="0" checked="checked"/><label>{% trans 'No' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{% trans 'Message' %}</label>
                        <div class="formRight">
                            <textarea name="message" cols="5" rows="10">{{ request.message }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div class="tab_content nopadding" id="tab-new-forum">

            <form method="post" action="admin/forum/create" class="mainForm save api-form" data-api-redirect="forum">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Status' %}:</label>
                        <div class="formRight">
                            <input type="radio" name="status" value="active" checked="checked"/><label>{% trans 'Active' %}</label>
                            <input type="radio" name="status" value="locked" /><label>{% trans 'Locked' %}</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Description' %}</label>
                        <div class="formRight">
                            <textarea name="description" cols="5" rows="4">{{ request.description }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
            <div class="fix"></div>
        </div>
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-forums">
            <form method="post" action="admin/forum/update_priority" class="mainForm api-form" data-api-reload="1">
                <fieldset>
                    <table class="tableStatic wide">
                        <thead>
                            <tr>
                                <td style="width: 5%">{% trans 'Sorting' %}</td>
                                <td>{% trans 'Title' %}</td>
                                <td>{% trans 'Actions' %}</td>
                            </tr>
                        </thead>
                        <tbody>
                            {% for forum in admin.forum_get_list.list %}
                            <tr {% if loop.first %}class="noborder"{% endif %}>
                                <td><input type="text" name="priority[{{forum.id}}]" value="{{ forum.priority }}" style="width:30px;"></td>
                                <td>{{forum.title}}</td>
                                <td class="actions" style="width:13%">
                                    <a class="bb-button btn14" href="{{ '/forum/'|alink }}/{{forum.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                                    <a class="bb-button btn14 bb-rm-tr api-link" href="admin/forum/delete?id={{forum.id}}" data-api-redirect="forum"><img src="images/icons/dark/trash.png" alt=""></a>
                                </td>
                            </tr>
                            {% else %}
                            <tr>
                                <td colspan="3">{% trans 'The list is empty' %}</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="3"></td>
                            </tr>
                        </tfoot>
                    </table>
                    <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

    </div>
</div>

{% endblock %}
