<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<div class="content_title">
	<h3><?php _e($content_title); ?></h3>
</div>
<div class="space"></div>
<div class="content_toolbar">
	<a href="<?php echo Html::uriquery('mod_product', 'admin_list'); ?>" title=""><?php _e('Back'); ?></a>
</div>
<div class="space"></div>
<div class="status_bar">
<?php if (Notice::get('mod_product/msg')) { ?>
	<span id="adminprdfrm_stat" class="status"><?php echo Notice::get('mod_product/msg'); ?></span>
<?php } ?>
</div>
<div class="space"></div>
<?php
$prd_form = new Form('index.php', 'productform', 'check_product_info');
$prd_form->setEncType('multipart/form-data');
$prd_form->p_open('mod_product', $next_action);
?>
<table id="productform_table" class="form_table" cellspacing="1">
    <tfoot>
        <tr>
            <td colspan="2">
            <?php
            echo Html::input('reset', 'reset', __('Reset'));
            echo Html::input('button', 'cancel', __('Cancel'), 'onclick="window.history.go(-1);"');
            echo Html::input('submit', 'submit', __('Save'));
            echo Html::input('hidden', 'prd[id]', $curr_product->id);
            ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td class="label"><?php _e('Language'); ?></td>
            <td class="entry">
            <?php
            echo Toolkit::switchText($curr_product->s_locale?$curr_product->s_locale:$mod_locale, 
                Toolkit::toSelectArray($langs, 'locale', 'name'));
            echo Html::input('hidden', 'prd[s_locale]', 
           		$curr_product->s_locale?$curr_product->s_locale:$mod_locale);
            ?>
            </td>
        </tr>
		<tr>
            <td class="label"><?php _e('Category'); ?></td>
            <td class="entry">
            <?php
            echo Html::select('prd[product_category_id]', 
            	$select_categories, 
            	$curr_product->product_category_id);
            ?>
            &nbsp;<a href="<?php echo Html::uriquery('mod_category_p', 'admin_list'); ?>" title=""><?php _e('Manage Categories'); ?></a>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Name'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'prd[name]', $curr_product->name, 
                '', $prd_form, 'RequiredTextbox', 
                __('Please input name!'));
            ?>
            </td>
        </tr>
		<tr>
            <td class="label"><?php _e('Introduction'); ?></td>
            <td class="entry">
			<?php
            echo Html::textarea('prd[introduction]', $curr_product->introduction, 'rows="6" cols="56"', 
            	$prd_form, 'RequiredTextbox', __('Please input introduction!'))
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Description'); ?></td>
            <td class="entry">
            <?php
            echo Html::textarea('prd[description]', $curr_product->description)."\n";
            $o_fck = new RichTextbox('prd[description]');
            $o_fck->toolbar_set = 'Default';
            $o_fck->width = 420;
            $o_fck->height = 360;
            echo $o_fck->create(FCK_REPLACE_TEXTAREA);
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Full Image'); ?></td>
            <td class="entry">
            <?php
			if($p_id) {
			?>
			<img src="<?php echo $curr_product->feature_img?>"><br />
			<?php
				echo Html::input('file', 'prd_file', '', 
                '', $prd_form);
			}else{
				echo Html::input('file', 'prd_file', '', 
                '', $prd_form, 'RequiredTextbox', 
                __('Please select a product big image to upload!'));
			}
            ?>
			<BR />
			<?php _e('Supported file format'); ?>:<?php echo PIC_ALLOW_EXT;?>
			<BR />
			<?php _e('Upload size limit'); ?>:<?php echo ini_get('upload_max_filesize');?>
            </td>
        </tr>
		<tr>
            <td class="label"><?php _e('Thumbnail'); ?></td>
            <td class="entry">
            <?php
			if($p_id) {
			?>
			<img src="<?php echo $curr_product->feature_smallimg?>"><br />
			<?php
				echo Html::input('file', 'prd_small_file', '', 
                '', $prd_form);
			}else{
				echo Html::input('file', 'prd_small_file', '', 
                '', $prd_form, 'RequiredTextbox', 
                __('Please select a product small image to upload!'));
			}
            ?>
			<BR />
			<?php _e('Supported file format'); ?>:<?php echo PIC_ALLOW_EXT;?>
			<BR />
			<?php _e('Upload size limit'); ?>:<?php echo ini_get('upload_max_filesize');?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Price'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'prd[price]', $curr_product->price?$curr_product->price:'0.00', 
                'size="10"', $prd_form, 'RequiredTextbox', 
                __('Please input price!'));
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Discount Price'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'prd[discount_price]', $curr_product->discount_price?$curr_product->discount_price:'0.00', 
                'size="10"', $prd_form, 'RequiredTextbox', 
                __('Please input discount price!'));
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Delivery Fee'); ?></td>
            <td class="entry">
            <?php
            echo Html::input('text', 'prd[delivery_fee]', $curr_product->delivery_fee?$curr_product->delivery_fee:'0.00', 
                'size="10"', $prd_form, 'RequiredTextbox', 
                __('Please input delivery fee!'));
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"></td>
            <td class="entry">
            <?php
            echo Html::input('checkbox', 'prd[online_orderable]', '1', 
                Toolkit::switchText($curr_product->online_orderable, 
                    array('0' => '', '1' => 'checked="checked"')));
            ?>
            &nbsp;<?php _e('Online Orderable'); ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('Publish Time'); ?></td>
            <td class="entry">
            <?php
            $pub_start_time = $curr_product->pub_start_time?$curr_product->pub_start_time:-1;
            $value_0 = '';
            $value_1 = '';
            $value_t = '';
            if ($pub_start_time < 0) {
                $value_0 = 'checked="checked"';
            } else {
                $value_1 = 'checked="checked"';
                $value_t = date('Y-m-d H:i:s', $pub_start_time);
            }
            echo Html::input('radio', 'pub_start_time', '0', $value_0);
            _e('Immediately');
            echo Html::input('radio', 'pub_start_time', '1', $value_1);
            echo DatetimeInput::create('prd[pub_start_time]', $prd_form, $value_t);
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"><?php _e('End Publish Time'); ?></td>
            <td class="entry">
            <?php
            $pub_end_time = $curr_product->pub_end_time?$curr_product->pub_end_time:-1;
            $value_0 = '';
            $value_1 = '';
            $value_t = '';
            if ($pub_end_time < 0) {
                $value_0 = 'checked="checked"';
            } else {
                $value_1 = 'checked="checked"';
                $value_t = date('Y-m-d H:i:s', $pub_end_time);
            }
            echo Html::input('radio', 'pub_end_time', '1', $value_1);
            echo DatetimeInput::create('prd[pub_end_time]', $prd_form, $value_t);
            echo Html::input('radio', 'pub_end_time', '0', $value_0);
            _e('Never Expire');
            ?>
            </td>
        </tr>
        <tr>
            <td class="label"></td>
            <td class="entry">
            <?php
            echo Html::input('checkbox', 'prd[recommended]', '1', 
                Toolkit::switchText($curr_product->recommended, 
                    array('0' => '', '1' => 'checked="checked"')));
            ?>
            &nbsp;<?php _e('Recommend'); ?>
            </td>
        </tr>
        <tr>
            <td class="label"></td>
            <td class="entry">
            <?php
            echo Html::input('checkbox', 'prd[published]', '1', 
                Toolkit::switchText($curr_product->published, 
                    array('0' => '', '1' => 'checked="checked"')));
            ?>
            &nbsp;<?php _e('Publish'); ?>
            </td>
        </tr>
        <tr>
            <td class="label"></td>
            <td class="entry">
            <?php
            echo Html::input('checkbox', 'ismemonly', '1', 
                Toolkit::switchText(strval(ACL::isMemOnly($curr_product->for_roles)), 
                    array('0' => '', '1' => 'checked="checked"')));
            ?>
            &nbsp;<?php _e('Member only access'); ?>
            </td>
        </tr>
    </tbody>
</table>
<?php
$prd_form->close();
$prd_form->writeValidateJs();
?>
