{extends "manage/manage.tpl.html"}

{block "manage_content"}


<script type="text/javascript">
    function validateForm()
    {
        if (Validation.isFieldWhitespace('title')) {
            Validation.selectField('title');
            alert('{t escape=js}Please enter the name of this product.{/t}');
            return false;
        }
        if (Validation.isFieldWhitespace('rank')) {
            Validation.selectField('rank');
            alert('{t escape=js}Please enter the rank of this product.{/t}');
            return false;
        }
        return true;
    }

    function checkDelete()
    {
        if (!Validation.hasOneChecked('items[]')) {
            alert('{t escape=js}Please select at least one of the products.{/t}');
            return false;
        }
        if (!confirm('{t escape=js}WARNING: This action will remove the selected products permanently.{/t}\n{t escape=js}Please click OK to confirm.{/t}')) {
            return false;
        } else {
            return true;
        }
    }
    $().ready(function() {
        $('.select_all').click(function() { Eventum.toggleCheckAll('items[]'); });

        $('#delete_product').submit(checkDelete);
        $('#product_form').submit(validateForm);
    });
</script>

<form id="product_form" method="post">
    {if $smarty.get.cat|default:'' == 'edit'}
    <input type="hidden" name="cat" value="update">
    <input type="hidden" name="id" value="{$smarty.get.id|intval|default:''}">
    {else}
    <input type="hidden" name="cat" value="new">
    {/if}
    <table class="bordered">
        <tr class="title">
            <th colspan="2">
                {t}Manage Products{/t}
            </th>
        </tr>
        <tr>
            <th width="120">
                {t}Title{/t} *
            </th>
            <td>
                <input type="text" name="title" size="40" value="{$info.pro_title|default:''|escape:'html'}">
                {include file="error_icon.tpl.html" field="title"}
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Version How To{/t}
            </th>
            <td>
                <input type="text" name="version_howto" size="100" value="{$info.pro_version_howto|default:''|escape}">
                {include file="error_icon.tpl.html" field="version_howto"}
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Email Address{/t}
            </th>
            <td>
                <input type="text" name="email" size="100" value="{$info.pro_email|default:''|escape}">
                {include file="error_icon.tpl.html" field="email"}
                <br />{t}This address will be notified when issues are created with this product.{/t}
            </td>
        </tr>
        <tr>
            <th width="120">
                <nobr>{t}Rank{/t} *</nobr>
            </th>
            <td>
                <input type="text" name="rank" size="3" value="{$info.pro_rank|default:''}" />
                {include file="error_icon.tpl.html" field="rank"}
            </td>
        </tr>
        <tr>
            <th width="120">
                {t}Removed{/t}
            </th>
            <td width="80%">
                <input type="checkbox" name="removed" value="1" {if $info.pro_removed|default:'' == 1}checked{/if} />
            </td>
        </tr>
        <tr class="buttons">
            <th colspan="2">
                {if $smarty.get.cat|default:'' == 'edit'}
                <input type="submit" value="{t}Update Product{/t}">
                {else}
                <input type="submit" value="{t}Create Product{/t}">
                {/if}
                <input type="reset" value="{t}Reset{/t}">
            </th>
        </tr>
    </table>
</form>

<form id="delete_product" method="post">
    <table class="bordered grid">
        <tr class="title">
            <th colspan="5">
                {t}Existing Products{/t}
            </th>
        </tr>
        <tr>
            <th nowrap><input type="button" value="{t}All{/t}" class="select_all"></th>
            <th>&nbsp;{t}Title{/t}</th>
            <th>&nbsp;{t}Version How To{/t}</th>
            <th>&nbsp;{t}Email{/t}</th>
            <th>&nbsp;{t}Rank{/t}</th>
            <th>&nbsp;{t}Removed{/t}</th>
        </tr>
        {section name="i" loop=$list}
        <tr class="{cycle values='odd,even'}">
            <td width="4" nowrap align="center">
                <input type="checkbox" name="items[]" value="{$list[i].pro_id}" {if $smarty.section.i.total == 0}disabled{/if}>
            </td>
            <td width="20%">
                &nbsp;<a class="link" href="{$core.rel_url}manage/products.php?cat=edit&id={$list[i].pro_id}" title="{t}update this entry{/t}">{$list[i].pro_title|escape}</a>
            </td>
            <td width="20%">
                &nbsp;{$list[i].pro_version_howto|escape}
            </td>
            <td width="40%">
                &nbsp;{$list[i].pro_email|escape}
            </td>
            <td width="10%">
                &nbsp;{$list[i].pro_rank}
            </td>
            <td width="10%">
                &nbsp;{if $list[i].pro_removed == 1}Yes{/if}
            </td>
        </tr>
        {sectionelse}
        <tr class="no_results">
            <td colspan="5">
                {t}No products could be found.{/t}
            </td>
        </tr>
        {/section}
        <tr class="buttons">
            <td width="4">
                <input type="button" value="{t}All{/t}" class="select_all">
                <input type="hidden" name="cat" value="delete">
            </td>
            <td colspan="5">
                <input type="submit" value="{t}Delete{/t}">
            </td>
        </tr>
    </table>
</form>
{/block}
