<?php
/**
 * Marketplace - Component Marketplace 
 * ******************************************************************
 *
 * PHP version 7.0
 *
 * @category   Component
 * @package    Joomla
 * @author     WebKul software private limited <support@webkul.com>
 * @copyright  2010 WebKul software private limited
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @version    GIT:5.2
 * @filesource http://store.webkul.com
 * @link       Technical Support:  webkul.uvdesk.com
 * ******************************************************************
 */
// no direct access
defined('_JEXEC') or die();
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
$input = JFactory::getApplication()->input;
jimport('joomla.html.editor');
JHtml::_('bootstrap.tooltip');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
JHtml::_('formbehavior.chosen', 'select');
JHtml::_('behavior.framework', true);
JHtml::_('behavior.formvalidator');
$document = JFactory::getDocument();
$config = JFactory::getConfig();
$style = '
.modal-header {
    color: #fff;
    padding: 15px;
    text-align: center;
    border-bottom: 1px solid #eee;
    background-color: #428bca;
    -webkit-border-top-left-radius: 5px;
    -webkit-border-top-right-radius: 5px;
    -moz-border-radius-topleft: 5px;
    -moz-border-radius-topright: 5px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    margin: 0 4px 10px 0;
}

.toggle-editor {
    display: none;
}

iframe {
    height: 135px !important;
}

#jform_subject {
    width: 97%;
}

#jform_subject-lbl,
#jform_reciepient-lbl,
#jform_description-lbl {
    font-weight: 900;
    display: inline-block;
}

#jform_reciepient {
    width: 97%;
}

.control-label {
    font-weight: bold;
    width: 150px!important;
}

#jform_upcommision-lbl {
    display: inline-block;
}

.btn.wbtn.btn-success.pull-right {
    margin-right: 50px;
}
';
$document->addStyleDeclaration($style);
$jinput=JFactory::getApplication()->input;
$model=$this->getModel('commisions');
$currency=$model->getCurrencySymbol();
$jinput=JFactory::getApplication()->input;
$valuse=$jinput->getVar('ids');
@$commision_ids=unserialize(urldecode($valuse));
$commision_id=$jinput->get('commision_id');
$seller_id=$jinput->get('seller_id');

if (isset($commision_id)) {
    $this->form->setValue('commision_id', '', $commision_id);
} elseif (count($commision_ids)) {
    $this->form->setValue('commision_ids', '', implode(',', $commision_ids));
}
if (isset($commision_id)) {
    $total=1;
} else {
    $total=count($commision_ids);
}
?>
<form action="<?php
    echo 'index.php?option=com_marketplace&tmpl=component&view=commisions&layout=update_commision'
    ?>" method="post" name="adminForm" id="item-form" class="form-validate form-horizontal">
    <div class="queshead">
        <h3 class="modal-header">
        <?php
        echo JText::_('COM_MARKETPLACE_UPDATE_COMMISION_TITLE');
        ?>
        </h3>
    </div>
    <?php
    echo $this->form->getInput('commision_ids');
    ?>
        <table>
            <tr>
                <div class="control-group">
                    <td>
                        <div class="control-label">
                            <?php echo $this->form->getLabel('commisiontype'); ?>
                        </div>
                    </td>
                    <td>
                        <div class="qcontrols">
                            <?php echo $this->form->getInput('commisiontype'); ?>
                        </div>
                    </td>
                </div>
            </tr>
            <tr>
                <td>&nbsp</td>
            </tr>
            <tr>
                <div class="control-group">
                    <td>
                        <div class="control-label">
                            <?php echo $this->form->getLabel('upcommision'); 
    
    ?>
                        </div>
                    </td>
                    <td>
                        <div class="qcontrols">

                            <?php echo $this->form->getInput('upcommision'); ?>

                        </div>
                    </td>
                    <td><span class="wk_symbol"></span></td>
                </div>
            </tr>
            <tr>
                <td>&nbsp</td>
            </tr>
            <tr>
                <td>&nbsp</td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <button class="btn wbtn btn-success">Update</button>
                    <div class="btn wbtn btn-danger" onclick="cancelpop()">Cancel</div>
                </td>
            </tr>
        </table>
        <input type="hidden" name="commision_id" value="<?php echo $commision_id;?>">
        <input type="hidden" name="task" value="commisions.updateCommision" />
        <?php echo JHtml::_('form.token'); ?>
</form>

<script type="text/javascript">
jQuery(function () {
    jQuery('#jform_commisiontype-lbl').append('*');
    jQuery('#jform_upcommision-lbl').append('*');
    jQuery('#jform_commisiontype').on('change', function () {
        if (jQuery(this).val() == 'r') {
            jQuery('.wk_symbol').html('<h3>%</h3>');
        } else if (jQuery(this).val() == 'f') {
            jQuery('.wk_symbol').html('<h3><?php  echo $currency["currency_symbol"] ?></h3>');
        }
    });
    jQuery("#item-form").on('submit', function () {
        if (jQuery("#jform_commisiontype").val() == '') {
            jQuery('#jform_commisiontype-lbl').css('color', 'red');
            return false;
        } else if (jQuery("#jform_upcommision").val() == '') {
            jQuery('#jform_upcommision-lbl').css('color', 'red');
            jQuery('#jform_commisiontype-lbl').css('color', '#4F4F4F');
            return false;
        } else {
            jQuery('#jform_upcommision-lbl').css('color', '#4F4F4F');
        }
    });
});

function cancelpop() {

    window.parent.location.href = "<?php echo JURI::root().'administrator/index.php?option=com_marketplace&view=commisions'?>"
}

</script>

