<!-- FormPrefix --><?= $f_AdminCommon ?>
<?php

    $netshop_forms = nc_netshop::get_instance($catalogue)->forms->get_objects();

?>
<div class="nc-bg-lighten nc-padding-10" style="border-bottom: 1px solid #DDD">
    <form class="nc-form nc--horizontal" method="get">
        <!-- при использовании в качестве обычного шаблона инфоблока: -->
        <input type='hidden' name='admin_mode' value='<?= $admin_mode ?>'/>
        <input type='hidden' name='inside_admin' value='<?= (int)$inside_admin ?>'/>
        <input type='hidden' name='catalogue' value='<?= $catalogue ?>'>
        <input type='hidden' name='sub' value='<?= $sub ?>'>
        <input type='hidden' name='cc' value='<?= $cc ?>'>
        <!-- для работы внутри панели управления модулем: -->
        <input type="hidden" name="controller" value="order">
        <input type="hidden" name="action" value="index">

        <label style="padding: 0 5px"><?= NETCAT_MODULE_NETSHOP_ORDER_STATUS ?></label>
        <select name="order_status" onchange="this.form.submit();">
            <option value="-1"><?= NETCAT_MODULE_NETSHOP_ORDER_ANY ?></option>
            <option value="0"<?=(isset($order_status) && $order_status == 0) ? " selected" : "" ?>>
                <?= NETCAT_MODULE_NETSHOP_ORDER_NEW ?>
            </option>
            <?= listQuery("SELECT ShopOrderStatus_ID, ShopOrderStatus_Name FROM Classificator_ShopOrderStatus",
                          "<option value='\$data[ShopOrderStatus_ID]'\" .
                           (\$data['ShopOrderStatus_ID']==\$_GET['order_status'] ? ' selected' : '') .
                           \">\$data[ShopOrderStatus_Name]</option>\\n")
            ?>
        </select>
        <table class="nc--wide"><tr>
                <td class="nc--wide">
                    <input type="text" name="text_filter" class="nc--wide"
                           style="padding:4px 6px 3px; margin:0; height: 30px"
                           placeholder="<?=htmlspecialchars(NETCAT_MODULE_NETSHOP_ORDER_SEARCH) ?>"
                           value="<?=htmlspecialchars($text_filter) ?>">
                    <i class="nc-icon nc--remove"
                       style="position: absolute; margin:5px 0 0 -25px; cursor: pointer; display: none">
                </td>
                <td>
                    <button type="submit" style="height: 30px">OK</button>
                </td>
        </tr></table>
        <script>
            (function() {
                var input = $nc('input[name=text_filter]'),
                    clearButton = input.next(".nc--remove");

                input.on('change keyup', function() {
                    clearButton.css('display', (this.value ? '' : 'none'));
                }).change();

                clearButton.on('click', function() {
                    input.val('');
                    if (input.attr('value')) { input.closest('form').submit(); }
                    else { input.change(); }
                });
            })();
        </script>
    </form>
</div>
<!-- /FormPrefix -->

<!-- RecordTemplate --><?php

    $order = new nc_netshop_order($res[$f_RowNum]);
    $order->set_catalogue_id($catalogue);

?>
<div style='padding:10px 0'>

    <? $toolbar = $nc_core->ui->toolbar()->left() ?>
    <? $toolbar->add_text('#' . $f_RowID) ?>
    <? $toolbar[] = $nc_core->ui->html->li()->div($f_ContactName)->icon('user nc--dark') ?>
    <? $toolbar->add_btn("mailto:{$f_Email}", $f_Email)->icon('mod-subscriber nc--dark') ?>
    <? $toolbar->add_btn($SUB_FOLDER . $HTTP_ROOT_PATH . "modules/netshop/export/cml2_orders.php?order_id=" . $f_RowID . "&catalogue_id=" . $catalogue, 'Экспорт в CommerceML2') ?>
    <div class='nc--clearfix nc-padding-10 nc-bg-lighten'>
        <div class='nc--right'><?= $f_AdminButtons ?></div>
        <?= $toolbar ?>
        <form class='nc-form'
              action='<?= $SUB_FOLDER . $HTTP_ROOT_PATH ?>modules/netshop/forms.php'
              target='_blank' method='GET'>
            <input type='hidden' name='phase' value='print'/>
            <input type='hidden' name='order' value='<?= $f_RowID ?>'/>
            <input type='hidden' name='catalogue' value='<?= $catalogue ?>'/>
            <select name='type' onchange='if(this.value)jQuery(this.parentNode).submit()'>
                <option value=''>Бланки:</option>
                <? foreach ($netshop_forms as $k => $form): ?>
                <option value='<?=$form->keyword ?>'><?=$form->name ?></option>
                <? endforeach ?>
            </select>
        </form>
        <div class='nc--clearfix'></div>
        <? if ($f_Phone): ?><span class='nc-label'>Телефон:</span>
            <span><?= $f_Phone; ?></span><? endif ?>
        <? if ($f_Phone && $f_Address): ?>&nbsp;&nbsp;&nbsp;<? endif ?>
        <? if ($f_Address): ?><span
            class='nc-label'>Адрес:</span> <?=$f_City ?>, <?= $f_Address; ?><? endif ?>
    </div>
    <table width='100%' class='nc-table nc--bordered nc--small nc--striped'>
        <col width='1%'/>
        <col/>
        <col width='10%'/>
        <col width='1%'/>
        <col width='10%'/>
        <? foreach ($order->get_items() as $item): ?>
            <? $item_id = ($item["Article"] ? "$item[Article]" : "[$item[Message_ID]]"); ?>
            <tr>
                <td><?= $item_id ?></td>
                <td><a href='<?=htmlspecialchars($item['URL']) ?>' target='_blank'>
                        <?= htmlspecialchars($item['Vendor']) . " " .
                            htmlspecialchars($item['Name']) . " " .
                            htmlspecialchars($item['VariantName']) ?></a>
                </td>
                <td class='nc-text-right'><?= $item['ItemPriceF'] ?></td>
                <td class='nc-text-right'><span class='nc-label nc--blue'><?= $item['Qty'] ?> <?= $item['Units'] ?></span>
                </td>
                <td class='nc-text-right'><?= $item['TotalPriceF'] ?></td>
            </tr>
        <? endforeach ?>
    </table>
</div><!-- /RecordTemplate -->

<!-- FormSuffix --><div style="margin: 15px 0">
    <?=browse_messages($cc_env, 15, array(
        'prefix' => "",
        'suffix' => "",
        'active' => "<b>%PAGE</b>",
        'unactive' => "<a href=%URL>%PAGE</a>",
        'divider' => " | ",
    )) ?></div><!-- /FormSuffix -->