{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
{$xajax}
<h1>{trans("Price lists")}</h1>

<style>

    #prefix-group-list {
        margin-top: 1em;
    }

    #prefix-group-list caption {
        text-align: left;
        font-weight: bold;
        padding-top: 0.3em;
        padding-bottom: 0.3em;
    }

    #prefix-group-list  thead {
        border-bottom: 1px dotted gray;
    }

    #prefix-group-list tr td:first-child {
        min-width: 30px;
    }

    #prefix-group-list tr td {
        min-width: 75px;
        padding-right: 10px;
    }

    #prefix-group-list thead {
        font-weight: bold;
    }

    #prefix-group-add input {
        width: 70px;
    }

</style>

<form name="voippricelist" id="voippricelist" method="post" action="?m=voippricelist{if isset($pricelist.id)}&id={$pricelist.id}{/if}" enctype="multipart/form-data">
    <table class="lmsbox">
        <thead>
            <tr>
                <td class="bold" width="40%" colspan="2">
                    <img src="img/add.gif" alt=""> {trans("Create")} / {trans("Edit")}
                </td>
            </tr>
        </thead>
        <tbody id="voippricelist-add">
            <tr>
                <td style="vertical-align: top;">
                    <table>
                        <tr>
                            <td><img src="img/size.gif" alt=""></td>
                            <td><b>{trans("Price list:")}</b></td>
                            <td>
                                <select id="tariff_select" style="width: 205px;">
                                    <option value="0">--</option>
                                    {if !empty($price_list)}
                                        {foreach from=$price_list item=list}
                                        <option value="{$list.id}" {if !empty($pricelist.id) && $pricelist.id == $list.id}SELECTED{/if}>
                                            {$list.name}
                                        </option>
                                        {/foreach}
                                    {/if}
                                </select>
                                &nbsp;&nbsp;<a href="javascript:loadTariff();">{trans("load<!voip>")}</a>
                                &nbsp;&nbsp;<a id="delete-tariff" href="javascript:deleteTariff();">{trans("delete")}</a>
                            </td>
                        </tr>
                        <tr class="space_row">
                            <td><img src="img/customer.gif" alt=""></td>
                            <td><b>{trans("Name:")}</b></td>
                            <td>
                                {if isset($pricelist.id)}
                                <input type="hidden"
                                       name="pricelist[id]"
                                       value="{$pricelist.id}">
                                {/if}
                                <input type="text"
                                       id="pricelist_name"
                                       name="pricelist[name]"
                                       value="{if isset($pricelist.name)}{$pricelist.name}{/if}"
                                       style="width: 200px;"
                                       maxlength="100"
                                       {tip text="Enter tariff name" trigger="name"}>
                            </td>
                        </tr>
                        <tr>
                            <td><img src="img/desc.gif" alt=""></td>
                            <td><b>{trans("Description:")}</b></td>
                            <td>
                                <textarea name="pricelist[description]" style="width: 200px;">{if isset($pricelist.description)}{$pricelist.description}{/if}</textarea>
                            </td>
                        </tr>
                    </table>
                </td>
                <td style="vertical-align: top;">
                    <fieldset style="display: block; min-width: 30%;">
                        <legend><b>{trans("<!voip>Prefix group prices")}</b></legend>

                        {if !empty($pricelist.group) && count($pricelist.group) > 50}
                        <div style="text-align: right;">
                            <a href="javascript:document.voippricelist.submit();">
                                {trans("Submit")} <img src="img/save.gif" alt="">
                            </a>
                            <a href="?m={if $customerinfo.id}customerinfo&id={$customerinfo.id}{else}voipaccountlist{/if}">
                                {trans("Cancel")} <img src="img/cancel.gif" alt="">
                            </a>
                        </div>
                        {/if}

                        <table id="prefix-group-add">
                            <tr>
                                <td colspan="100%"><b>{trans("Add group")}</b></td>
                            </tr>
                            <tr>
                                <td colspan="100%">
                                    <input name="file" type="file" style="width: 220px;" {tip text="" trigger="file"}>
                                </td>
                            </tr>
                        </table>

                        <table id="prefix-group-list" class="lmsbox-inner lms-ui-background-cycle">
                            <caption>
                                {trans("<!voip>Prefix groups")}
                            </caption>
                            <thead>
                                <tr class="dark">
                                    <td>
                                        {trans("ID")}
                                    </td>
                                    <td style="width: 230px;">
                                        {trans("Name")}
                                    </td>
                                    <td {tip text="<!voip>Price per single tariff unit"}>
                                        {trans("Price")}
                                    </td>
                                    <td {tip text="<!voip>Size of single tariff unit"}>
                                        {trans("Unit size<!voip>")}
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                                {if isset($pricelist)}
                                    {foreach $pricelist.group as $group}
                                        {include file="voipaccount/voippricelisttablerow.html"}
                                    {/foreach}
                                {/if}
                            </tbody>
                        </table>

                        <div id="no-prefix-groups" class="lucid" style="text-align: center; padding: 10px; font-weight: bold;{if !$pricelist.group} display: none;{/if}">
                            {trans("No prefix groups assigned to tariff.")}
                        </div>
                    </fieldset>
                </td>
            </tr>

            <tr>
                <td class="text-right" colspan="2">
                    <a href="javascript:document.voippricelist.submit();">
                        {trans("Submit")} <img src="img/save.gif" alt="">
                    </a>
                    <a href="?m={if $customerinfo.id}customerinfo&id={$customerinfo.id}{else}voipaccountlist{/if}">
                        {trans("Cancel")} <img src="img/cancel.gif" alt="">
                    </a>
                </td>
            </tr>
        </tbody>
    </table>
</form>

<SCRIPT>
    var table = $('#prefix-group-list');
    var pricelist_list = document.getElementById("tariff_select");

    // load tariffs
    function loadTariff() {
        var id = pricelist_list.selectedIndex;

        if (id == 0)
            return 0;

        window.location.href = "?m=voippricelist&id=" + pricelist_list[id].value;
    }

    // delete tariff
    function deleteTariff() {
        var id = pricelist_list.selectedIndex;

        if (id == 0)
            return 0;

        confirmDialog($t("Are you sure that you want remove tariff '$a'?", pricelist_list[id].text), $('#delete-tariff')).done(function() {
            window.location.href = "?m=voippricelist&id=" + pricelist_list[id].value + "&action=delete";
        });
        return 0;

    }

    // groups table is empty check
    function groupsTableInfoUpdate() {
        $('#no-prefix-groups').toggle(table.find('tbody tr').length);
    }

    groupsTableInfoUpdate();
</SCRIPT>
{/block}
