<?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('Restricted access');
jimport('joomla.filter.output');
JHTML::_('jquery.framework');
JHtml::_('behavior.formvalidator');
jimport('joomla.environment.browser');
$browser =JBrowser::getInstance();
$browserType = $browser->getBrowser();
$lang_tag=VmConfig::$vmlang;
$document = JFactory::getDocument();
if (!class_exists('MarketplaceHelper')) {
    include JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.
    DIRECTORY_SEPARATOR.'com_marketplace'.DIRECTORY_SEPARATOR.'helpers'.
    DIRECTORY_SEPARATOR.'marketplace.php';
}
if (!class_exists('VmConfig')) {
    include JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php';
}
$document->addStyleSheet(
    JURI::root().
    'components/com_marketplace/css/styles.css'
);
$document->addStyleSheet(
    JURI::root().
    'components/com_marketplace/css/newdesign/addproduct.css'
);
$document->addStyleSheet(
    JURI::root().
    'components/com_marketplace/css/newdesign/marketplace.css'
);
$document->addStyleSheet(
    JURI::root().
    'components/com_marketplace/css/easy-responsive-tabs.css'
);
$document->addStyleSheet('https://fonts.googleapis.com/css?family=Roboto');
$document->addStyleSheet(
    'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.2/css/font-awesome.min.css'
);
$document->addScript(
    JURI::root().
    'components/com_marketplace/js/easy-responsive-tabs.js'
);
$document->addStyleSheet('//fonts.googleapis.com/css?family=Roboto');

$document->addStyleSheet(
    '//cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css'
);
$document->addScript(
    '//cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert-dev.min.js'
);
JText::script('COM_MARKETPLACE_CAPTCHA_DESC');
$user = JFactory::getUser();
$param  = JComponentHelper::getParams('com_marketplace');
$wk_price_discount = $param->get('wk_price_discount');
$wk_price_tax = $param->get('wk_price_tax');
$wk_addproduct_imgsize = $param->get('wk_addproduct_imgsize');
$recaptcha_enable=trim($param->get('recaptcha_enable'));
$captcha=(boolean)$param->get('captcha');
$mp_add_term = $param->get('mp_add_term');
$mp_add_rules = trim($param->get('mp_add_rules'));

$addpromenu=plgSystemMarketplace::getMenuId(
    'index.php?option=com_marketplace&view=addproduct'
);
if ($browserType!="mozilla") {
    $document->addScript(
        JURI::root().
        'components/com_marketplace/js/addproduct2.js'
    );
    $document->addScript(
        JURI::root().
        'components/com_marketplace/assets/webcam/webcam123.js'
    );
} else {
    $document->addScript(JURI::root().'components/com_marketplace/js/addproduct.js');
}
$userid = $user->get('id');
$productname = '';
$product_description = '';
$product_description_short = '';
$sku = '';
$price = '';
$stock = '';
$weight = '';
$virtuemart_product_id = '';
$imagepath = '';
$bgcolor=trim($param->get('head_bg_color'));
$textcolor=trim($param->get('head_txt_color'));
$model=$this->getModel();
for ($i=0, $n=count($this->data); $i < $n; $i++) {
    $item = $this->data[$i];
    $productname = $item->product_name;
    $product_description = $item->product_desc;
    $product_description_short = $item->product_s_desc;
    $sku = $item->product_sku;
    $price = $item->product_price;
    $price = number_format($price, 2, '.', '');
    $stock = $item->product_in_stock;
    $stock = number_format($stock, 2, '.', '');
    $weight = $item->product_weight;
    $weight = number_format($weight, 2, '.', '');
    $virtuemart_product_id = $item->virtuemart_product_id;
}

$defaultcountry_code = VmConfig::$vmlang;
$productmenu = MarketplaceHelper::getMpMenuItem('products');
?>
<script type="text/javascript">
jQuery(window).load(function () {
    jQuery('.wk_main_loader_overlay').css('display', 'none');
});
jQuery(function () {
    jQuery('body').on('click', '.resp-tabs-list .resp-tab-item:nth-child(4)', function () {
        navigator.getMedia = navigator.getUserMedia ||
            navigator.webkitGetUserMedia ||
            navigator.mozGetUserMedia;

        if (navigator.getMedia != undefined) {
            navigator.getMedia({
                video: true
            }, function () {}, function () {
                jQuery('.upload_options_pro .take_pic_').css('display', 'none');
            });
        } else
            jQuery('.upload_options_pro .take_pic_').css('display', 'none');
    });
    if (jQuery('#virtuemart_manufacturer_id option:first').attr('value') == '') {
        jQuery('#virtuemart_manufacturer_id option:first').html('<div style="text-align:center" style="color:#004DCC"><a class="wk_man_selectall" href="javascript:void(0)"><?php echo JText::_("SELECT_ALL");?></a></div>');
    } else {
        jQuery('#virtuemart_manufacturer_id').prepend('<option value=""></option>');
        jQuery('#virtuemart_manufacturer_id option:first').html('<div style="text-align:center" style="color:#004DCC"><a class="wk_man_selectall" href="javascript:void(0)"><?php echo JText::_("SELECT_ALL");?></a></div>');
    }
    jQuery('#virtuemart_manufacturer_id option:first').on('click', function () {
        if (jQuery('#virtuemart_manufacturer_id option a').hasClass('active')) {
            jQuery('#virtuemart_manufacturer_id option').removeAttr('selected');
            jQuery('.wk_man_selectall').text('<?php echo JText::_("SELECT_ALL");?>');
            jQuery('.wk_man_selectall').removeClass('active');
        } else {
            jQuery('#virtuemart_manufacturer_id option:gt(0)').attr('selected', 'true');
            jQuery('#virtuemart_manufacturer_id option:gt(0)').prop('selected', 'true');
            jQuery('#virtuemart_manufacturer_id option div').css('background-color', "#FFFFFF");
            jQuery('.wk_man_selectall').text('<?php echo JText::_("DESELECT_ALL");?>');
            jQuery('.wk_man_selectall').addClass('active');
        }
    });
});
var selectedVal_dis = <?php if(isset($item->product_discount_id)) echo $item->product_discount_id; else echo 0;?>;
jQuery('#price_discount option[value=' + selectedVal_dis + ']').attr("selected", "selected");
var selectedVal_tx = <?php if(isset($item->product_tax_id)) echo $item->product_tax_id; else echo 0;?>;
jQuery('#price_tax option[value=' + selectedVal_tx + ']').attr("selected", "selected");
jQuery(function () {
    jQuery('#product_parent_id option').on('click', function () {});
    jQuery(".wk-back-nav").click(function(){
        location.href="<?php
            echo JRoute::_(
                "index.php?option=com_marketplace&view=products&Itemid=".
                $productmenu->id,
                false
            )
        ?>";
    });
});

</script>
<?php
/*********Calculated Modules******************/
$obj=new JDocumentHTML();$mod="";
if (!$obj->countModules('wk_marketplace-left')&& !$obj->countModules('wk_marketplace-right')) {
        $both=0;
} elseif ((!$obj->countModules('wk_marketplace-left') && $obj->countModules('wk_marketplace-right'))||($obj->countModules('wk_marketplace-left') && !$obj->countModules('wk_marketplace-right'))) {
    $both=1;
    if (!$obj->countModules('wk_marketplace-left') && $obj->countModules('wk_marketplace-right')) {
        $mod="r";
    } else {
        $mod="l";
    }
} else {
        $both=2;
}

if ($both==0) {
    $maxwidth="900";
} elseif ($both==1) {
    $maxwidth="700";
} else {
    $maxwidth="550";
}
/*********Calculated Modules End******************/
?>
<style type="text/css">
    .wkRules {
        margin-left: 5px;
        cursor: pointer;
    }
    #t_and_c {
        margin: 0;
        width: auto !important;
    }
    .wk_man_selectall{
        text-decoration: none;
    }
    .add_product_main,.marketplace_position1,.marketplace_position2 {
        margin: 5px;
        display:inline-block;
        vertical-align: top;
    }
    .order_history{
        width:99.5%!important;
        background-color:<?php echo $bgcolor;?>;
        color: <?php echo $textcolor;?>;
    }
    #wk_image_label {
        margin-left: -5px;
    }
    .wk-cus select{
        display: block;
        margin-top: 1%;
        min-height: 40px;
        padding: 1% 2% !important;
        width: 98% !important;
    }
    #product_description_short {
        width: 95% !important;
    }
    #custom_fields {
        max-width:80%;
        margin: 0 auto;
        overflow:auto;
    }
    #custom_fields td {
        width:80px;
    }
    #custom_fields td input,#custom_fields td select {
        width:170px;
    }
    .wk_main_loader {
        position: relative;
    }
    .wk_main_loader_overlay {
        position: absolute;
        background-color: #FFF ! important;
        z-index: 999;
        width:101%;
        height:100%;
        border: 1px solid #CCCCCC;
        border-radius: 10px;
    }
    .term_div {
        padding: 5px 10px;
        overflow-wrap: break-word;
        overflow-y: scroll;
        max-height:300px;
    }
    .wk-back-nav {
        padding: 10px 5px;
        border: 1px solid #ccc;
        width: 100px;
        box-sizing: border-box;
        text-align: center;
        margin: 5px 0;
        font-weight: bold;
        position:relative;
        cursor:pointer;
    }
    .wk-back-nav:hover {
        background: #404040;
        color: white;
        box-shadow: 6px 8px 10px #404040;
    }
</style>
<div style="width:100%;" class="wk_main_loader">
    <div class="wk_main_loader_overlay" >
        <img style="display:block;margin:0 auto;" src="<?php echo JURI::root()."components/com_marketplace/"?>images/ajaxspinner1.gif"/>
    </div>
<div class="Wk_outer">
    <div class="marketplace_position-top" style="clear:both;"><?php echo JHTML::_('content.prepare', '{loadposition wk_marketplace-top}'); ?></div>
    <div class="marketplace_position1"><?php echo JHTML::_('content.prepare', '{loadposition wk_marketplace-left}'); ?></div>
    <div class="wk-nav-buttons">
        <div class="wk-back-nav"><span class="icon-undo" style="font-size: 18px;position: absolute;left: 8px;top: 12px;"> </span> <?php echo JText::_('BACK') ?></div>
    </div>
    <div class="add_product_main">
        <div class="order_history"><span class="detail_design"></span><span class="detail_text">
    <?php
    $_input = JFactory::getApplication()->input;
    $vmedit=$_input->getInt('virtuemart_product_id', '0');
    if ($vmedit) {
        echo JText::_('COM_MARKETPLACE_ADDPRODUCT_VIEW_EDIT_TITLE');
    } else {
        echo JText::_('COM_MARKETPLACE_ADDPRODUCT_VIEW_DEFAULT_TITLE');
    }
    ?>
    </span></div>
    <div><span class=""></span></div>
    <div id="horizontalTab">

        <form action="<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&Itemid='.$addpromenu, false); ?>" method="post" name="adminForm" id="" enctype="multipart/form-data" class="form-validate form-horizontal" >
            <ul class="resp-tabs-list">
                <li><?php echo JText::_('PRODUCT_INFO');?></li>
                <li><?php echo JText::_('PRODUCT_DESC');?></li>
                <li><?php echo JText::_('BASE_PRICE_PRO');?></li>
                <li><?php echo JText::_('IMAGE');?></li>
                <?php
                foreach ($this->addonData as $value) {
                    echo "<li>".$value["title"]."</li>";
                }
                ?>
            </ul>
            <div class="resp-tabs-container">
                <div class="panel-body contentbar">
                    <?php	$div='';
                    if ($virtuemart_product_id) {
                        $div = '';
                        echo '<div class="wk_selector"><strong>Multilingual shop :- </strong><select id="multilang" name="country_code">';
                        $wk_lang = 1;
                        foreach ($this->active_lang as $data_lang) {
                            $data_lang_code = explode('-', $data_lang);
                            $country_name = $model->getCountryName($data_lang_code['1']);
                            $data_lang=$data_lang_code[0]."_".$data_lang_code[1];
                            if ($defaultcountry_code == strtolower($data_lang)) {
                                echo '<option value="'.$data_lang_code['1'].' '.$data_lang.'" selected="selected">'.$country_name.'</option>';
                            } else {
                                echo '<option value="'.$data_lang_code['1'].' '.$data_lang.'" >'.$country_name.'</option>';
                            }
                            $wk_lang++;
                        }
                        echo '</select></div>';
                    } ?>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-product-hunt" aria-hidden="true"></i>
                            <label ><?php echo JText::_('PRODUCT_NAME'); ?><span style="color:red;">*</span></label>
                        </div>
                        <div class="wk_input_box" id="wk_pro_container">
                            <input type="text" name="productname" id="productname" value="<?php echo htmlspecialchars($productname, ENT_QUOTES); ?>" autocomplete="off" class="is-not-empty form-control width-100-mp text-padd" placeholder="<?php echo JText::_('ENTER_PRODUCT_NAME'); ?>"/>
                            <div id="wk_suggesstion-box" class=""></div>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-tags" aria-hidden="true"></i>
                            <label ><?php echo JText::_('PRODUCT_CAT'); ?><span style="color:red;">*</span></label>
                        </div>
                        <div class="wk_input_box">
                            <?php
                            $cidarray=array();
                            if ($virtuemart_product_id!='') {
                                $model=$this->getModel();
                                $result_cat=$model->getCategoryOfEditProduct(
                                    $this->virtuemart_product_id
                                );

                                foreach ($result_cat as $key => $value) {
                                    $cidarray[]=$value
                                        ->virtuemart_category_id;
                                }
                            }
                            /**************Select category updated by kailash*************/
                            if (count($cidarray)) {
                                $this->category_tree =@MarketplaceViewAddproduct::categoryListTree($cidarray);
                            } else {
                                $this->category_tree = MarketplaceViewAddproduct::categoryListTree();
                            }
                            ?>
                            <div class="wk_category_tree">
                                <select id="product_parent_id" class="inputbox wk_desktop_cat category width-100-mp text-padd hidden-phone" multiple="multiple" size="1" name="product_parent_id[]" style="width:99%;">
                                    <option value=""><?php echo vmText::_('COM_VIRTUEMART_UNCATEGORIZED') ?></option>
                                    <?php echo $this->category_tree; ?>
                                </select>
                                <select id="product_parent_id" style="width:98%;" class="inputbox wk_phone_cat visible-phone" multiple="multiple" size="1" name="product_parent_id[]">
                                    <option value=""><?php echo vmText::_('COM_VIRTUEMART_UNCATEGORIZED') ?></option>
                                    <?php echo $this->category_tree; ?>
                                </select>

                            </div>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_suggest_category"  data-toggle="modal" data-target="#wkModal"><?php echo JText::_('SUGGESTED_CATEGORY');?>
                            <span class="icon-plus wk_suggest_category_plus "></span>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-building-o" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('MANUFACTURERS'); ?></label>
                        </div>
                        <div class="wk_input_box">
                            <div class="sel wk_manufacturer "><?php echo $this->lists['manufacturers']; ?></div>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-cubes" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('STOCK'); ?></label>
                        </div>
                        <div class="wk_input_box">
                            <input type="text" name="product_in_stock" id="product_in_stock" value="<?php echo $stock; ?>" class="is-not-empty form-control width-100-mp text-padd" placeholder="<?php echo JText::_('ENTER_PRODUCT_STOCK'); ?>"/>
                            <div style="display:none;" id="product-numstock" class="validation-advice"><?php echo JText::_('STOCK_WARN'); ?></div>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-balance-scale" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('WEIGHT'); ?><?php echo JText::_("IN_KG");?></label>
                        </div>
                        <div class="wk_input_box">
                            <input type="text" name="product_weight" id="product_weight" value="<?php echo $weight; ?>"  class="form-control width-100-mp text-padd" placeholder="<?php echo JText::_('ENTER_PRODUCT_WEIGHT'); ?>">
                            <div style="display:none;" id="product-numweight" class="validation-advice"><?php echo JText::_('WEIGHT_WARN'); ?></div>
                        </div>
                    </div>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-barcode" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('SKU'); ?></label>
                        </div>
                        <div class="wk_input_box">
                            <input type="text" name="product_sku" id="product_sku" value="<?php echo htmlspecialchars($sku, ENT_QUOTES); ?>" class="form-control width-100-mp text-padd" autocomlete="off" placeholder="<?php echo JText::_('ENTER_PRODUCT_SKU'); ?>"/>
                            <div id="skuavail">
                                <img src="<?php echo Juri::root(); ?>components/com_marketplace/images/tick.png">
                            </div>
                            <div id="skunotavail">
                                <img src="<?php echo Juri::root(); ?>components/com_marketplace/images/publish_r.png">

                            </div>
                        </div>
                    </div>
                    <?php
                    if ($mp_add_term) {?>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_box" style="overflow:hidden">
                                <input type="checkbox" id="t_and_c" name="t_and_c"><span type="button" class="wkRules" data-toggle="modal" data-target="#myModal"><?php echo JText::_("TERMS_AND_CONDITIONS_VIEW") ?></span>
                            </div>
                            <div class="modal fade" id="myModal" role="dialog" style="display:none;">
                                <div class="modal-dialog">
                                    <!-- Modal content-->
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <h4 class="modal-title"><?php echo JText::_("TERMS_AND_CONDITIONS") ?></h4>
                                        </div>
                                        <div class="modal-body">
                                            <div class="term_div"><?php echo $mp_add_rules ?></div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php
                    }
                    if ($recaptcha_enable && $captcha) {?>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_label">
                            <i class="fa fa-lock" aria-hidden="true"></i><?php
                                echo $this->form->getLabel('captcha');
                                ?>
                            </div>
                            <div class="wk_input_box" style="overflow:hidden">
                            <?php
                                echo $this->form->getInput('captcha');
                                ?>
                            </div>
                        </div>
                        <?php
                    }
                    ?>
                    <div class="final-submit">
                        <input class="sub btn btn-primary product_save" type="submit" value="<?php echo JText::_('SAVE'); ?>" style="margin-bottom:10px;"/>
                    </div>
                </div>
                <div class="panel-body contentbar">
                    <div class="">
                        <div class="wk_input_label">
                            <i class="fa fa-file-text" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('PRODUCT_DESC'); ?></label>
                        </div>
                        <div>
                            <span class="product_description edit tinymce-entry" style="width:100%;">
                                <?php
                                jimport('joomla.html.editor');
                                $editor = JFactory::getEditor();
                                $params =  array( 
                                    'smilies'=> '0' ,
                                    'style'  => '1' ,
                                    'layer'  => '0' ,
                                    'table'  => '0' ,
                                    'clear_entities'=>'0'
                                );

                                echo $editor->display(
                                    'product_description',
                                    $product_description,
                                    '100',
                                    '100',
                                    '20',
                                    '20',
                                    false,
                                    null,
                                    null,
                                    null,
                                    $params
                                );
                                ?>
                            </span>
                        </div>
                    </div>
                    <div class="" style="margin:30px 0 0 0;">
                        <div class="wk_input_label">
                            <i class="fa fa-sort-alpha-desc" aria-hidden="true"></i>
                            <label for="icon_prefix"><?php echo JText::_('PRODUCT_SDESC'); ?></label>
                        </div>
                        <div class="">
                            <span class="product_description_short edit tinymce-entry">
                                <?php
                                    jimport('joomla.html.editor');

                                    $editor = JFactory::getEditor("none");
                                    echo $editor->display(
                                        'product_description_short',
                                        $product_description_short,
                                        '270',
                                        '100',
                                        '20',
                                        '20',
                                        false,
                                        null,
                                        null,
                                        null
                                    );
                                ?>
                            </span>
                        </div>
                    </div>
                    <div class="final-submit">
                        <input class="sub btn btn-primary product_save" type="submit" value="<?php echo JText::_('SAVE'); ?>"  style="margin-bottom:10px;"/>
                    </div>
                </div>
                <div class="panel-body contentbar">
                    <?php
                    $currency_obj=CurrencyDisplay::getInstance();
                    $curr_symbl =$currency_obj->getSymbol($currency_obj->getId());
                    $vmconf=VmConfig::loadConfig();
                    $curr_pro=$curr_symbl;
                    $proCurr=0;
                    if (isset($virtuemart_product_id) && JString::strlen($virtuemart_product_id)) {
                        $proMod=VmModel::getModel("Product");
                        $poData=$proMod->getProduct($virtuemart_product_id, true, true, false);
                        if (isset($poData)
                            && isset($poData->allPrices)
                            && isset($poData->allPrices[0]["product_currency"])
                        ) {
                            $proCurr=$poData->allPrices[0]["product_currency"];
                            $currency_obj2=CurrencyDisplay::getInstance($proCurr);
                            $curr_pro =$currency_obj2->getSymbol($proCurr);
                        }
                    }
                    ?>
                    <div class="wk_input_wrapper">
                        <div class="wk_input_label">
                            <i class="fa fa-rub" aria-hidden="true"></i>
                            <label ><?php echo JText::_('BASE_PRICE_A'); ?>
                                <span style="color:red;">*</span></label>
                            </div>
                            <div class="wk_input_box" >
                                <input type="text" name="price" id="price" value="<?php echo $price; ?>" placeholder="<?php echo JText::_('PRODUCT_BASE_PRICE'); ?>" class="<?php echo $curr_symbl." ";?> width-100-mp is-not-empty form-control text-padd" placeholder="<?php echo JText::_('ENTER_PRODUCT_PRICE'); ?>"/>
                                <div style="display:none;" id="product-price" class="validation-advice"><?php echo JText::_('REQUIRED_FIELD'); ?></div>
                                <div style="display:none;" id="product-numprice" class="validation-advice"><?php echo JText::_('PRICE_WARN'); ?></div>

                            </div>
                        </div>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_label">
                                <i class="fa fa-money" aria-hidden="true"></i>
                                <label for="icon_prefix"><?php echo JText::_('PRO_CURR'); ?></label>
                            </div>
                            <div class="wk_input_box" >
                                <div class="sel">
                                    <select name="pro_curr">
                                        <?php
                                        
                                        if ($proCurr==0) {
                                            $currency = CurrencyDisplay::getInstance();
                                            $currency_id = (int)$currency->getId();
                                        } else {
                                            $currency_id=$proCurr;
                                        }
                                        $currency_model = VmModel::getModel('currency');
                                        $currencies = $currency_model->getCurrencies();
                                        foreach ($currencies as $currency) {
                                            if ($currency->virtuemart_currency_id == $currency_id) { ?>
                                                <option selected value="<?php echo $currency->virtuemart_currency_id?>" ><?php echo $currency->currency_name ?></option>
                                            <?php
                                            } else { ?>
                                                <option value="<?php echo $currency->virtuemart_currency_id?>" ><?php echo $currency->currency_name ?></option>
                                            <?php
                                            }
                                        } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        
<?php if ($wk_price_discount == '1' ) { ?>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_label">
                                <i class="fa fa-code" aria-hidden="true"></i>
                                <label for="icon_prefix"><?php echo JText::_('PRICE_DISCOUNT'); ?></label>
                            </div>
                            <div class="wk_input_box" >
                                <div class="sel"><?php echo $this->lists['custom_discount']; ?></div>
                            </div>
                        </div>

<?php } if ($wk_price_tax == '1') { ?>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_label">
                                <i class="fa fa-exclamation-circle" aria-hidden="true"></i>
                                <label for="icon_prefix"><?php echo JText::_('PRICE_TAX'); ?></label>
                            </div>
                            <div class="wk_input_box sel" >
                                <?php echo $this->lists['custom_tax']; ?>
                            </div>
                        </div>

<?php }
$sales_price='';
if (isset($this->virtuemart_product_id) && $this->virtuemart_product_id != '') {
    $mp_model = VmModel::getModel('product');
    $vmids=$this->virtuemart_product_id;
    $pbls_rest=$mp_model->getProduct($vmids);
    $GLOBALS['virtuemart_categories_table_name']=VmConfig::$vmlang;
    @$pbls =$pbls_rest->published;
    @$sales_price=$pbls_rest->allPrices[0]['salesPrice'];

}
                        ?>
                        <div class="wk_input_wrapper">
                            <div class="wk_input_label">
                                <i class="fa fa-ticket" aria-hidden="true"></i>
                                <label for="icon_prefix"><?php echo JText::_('SALES_PRICE_A'); ?></label>
                            </div>
                            <div class="wk_input_box sel" >
                                <input type="text" name="final_price" id="salesprice" value="<?php
                                if (strlen($sales_price)!=0) {
                                    echo $curr_symbl." ".$sales_price;
                                }
                                ?>" placeholder="<?php echo JText::_('SALSE_PRICE_NON_EDIT'); ?>" readonly class="width-100-mp text-padd"/>
                            </div>
                        </div>
                        <div class="final-submit">
                            <input class="sub btn btn-primary product_save" type="submit" value="<?php echo JText::_('SAVE'); ?>" style="margin-bottom:10px;"/>
                        </div>
                    </div>
                    <div class="panel-body contentbar">
                        <div class="label1"><?php echo JText::_('UPLOAD_IMAGE'); ?></div>
                        <div class="upload_div">
                            <p class="Upload_img btn btn-success">Upload Images</p>
                            <p class="upload_options_pro" style="display:none;color:#428bca;margin-top:0px;padding:5px;font-size:14px;">
                                <span style="margin-top:5%;" class="take_pic_">
                                    <i class="fa fa-camera"></i>
                                    <?php echo JText::_('TAKE_PHOTO'); ?>
                                </span>
                                <label id="wk_image_label" for="image" class="fileUpload ">
                                    <span style="padding:5px;">
                                        <i class="fa fa-folder"></i>
                                        <?php echo JText::_('CHOOSE_FROM_GALLERY'); ?>
                                        <input type="file" name="image[]" id="image" multiple="multiple" accept="image/*" value="" class="upload nonipad" />
                                    </span>
                                </label>
                            </p>
                        </div>
                        <div class="pic_pr">
                            <?php
                            $param  = JComponentHelper::getParams('com_marketplace');
                            $bytes = $param->get('wk_addproduct_imgsize');

                            if ($bytes >= 1048576) {
                                $bytes = number_format($bytes / 1048576) . ' GB';
                            } elseif ($bytes >= 1024) {
                                $bytes = number_format($bytes / 1024) . ' MB';
                            } else {
                                $bytes = number_format($bytes) . ' KB';
                            }
                            $bytes_img = number_format(
                                $wk_addproduct_imgsize / 1048576
                            );
                            ?>
                            <span style="color:#e04852;"><?php echo JText::_('IMAGE_NOT_GREATER').' '.$bytes; ?></span>
                            <br>
                            <div id="result_holder"></div>
                            <div id="camera">
                                <span id="close_cam">X</span>
                            <?php
                            if ($browserType!="mozilla") { ?>
                                <div id="video"></div>
                                <input type=button value="Capture" id="cam_snap">
                                <div id="canvas" width="600" height="400"></div>
                            <?php } else { ?>
                                <video id="video" autoplay></video>
                                <input type="button" id="cam_snap" value="Capture" name="cam_snap">
                                <canvas id="canvas" width="600" height="400"></canvas>
                            <?php }
                            ?>
                            <button id="new">New</button>
                            <button id="upload_pic">uplaod</button>
                        </div>
                    </div>
                    <?php
                    if ($browserType!="mozilla") { ?>
                        <script src="components/com_marketplace/assets/webcam/webcam123.js"></script>
                        <script language="JavaScript">
                            Webcam.set({
                                // live preview size
                                width: 600,
                                height: 400,
                                // device capture size
                                dest_width: 600,
                                dest_height: 400,

                                // final cropped size
                                crop_width: 600,
                                crop_height: 400,

                                // format and quality
                                image_format: 'jpeg',
                                jpeg_quality: 90
                            });
                            Webcam.attach( '#video' );
                        </script>
                    <?php }
                    ?>
                    <div class="collection">
                        <div id="preview"></div>
                        <div class="imagecollection_container">
                        <?php
                        if (isset($virtuemart_product_id)) { 
                        ?>
                            <div id="imagecollection">
                            <?php
                            
                            if ($this->images) {
                                foreach ($this->images as $res) { ?>
                                <div class="imagebody"><img id="<?php echo $res->virtuemart_media_id; ?>" class="deleteimg" src="<?php echo $res->file_url; ?>" height="70" width="70" style="opacity:1;display:block;"/>
                                    <span class="image_over" style="display:none;"></span>
                                </div>
                                <?php
                                }
                            } ?>
                            </div>
                        </div>

                    <?php
                        }
                    ?>
                    </div>
                    <div class="final-submit">
                        <input class="sub btn btn-primary product_save" type="submit" value="<?php echo JText::_('SAVE'); ?>" style="margin-bottom:10px;"/>
                    </div>
                </div>
                <?php
                $str="";
                foreach ($this->addonData as $value) {
                    $str.='<div class="panel-body contentbar">';
                    $str.=$value["content"];
                    $str.='<div class="final-submit">
                        <input class="sub btn btn-primary product_save" type="submit" value="'.JText::_('SAVE').'" style="margin-bottom:10px;"/>
                    </div>';
                    $str.='</div>';
                }
                echo $str;
            ?>
            </div>

            <input type="hidden" name="task" value="addproduct.productSave" />
            <input type="hidden" name="created_by" value="<?php echo $userid; ?>" />
            <input type="hidden" name="virtuemart_product_id" value="<?php echo $virtuemart_product_id; ?>" />
            <?php echo JHTML::_('form.token'); ?>
            <?php echo $div;?>
        </form>
    </div>
    <div class="container-fluid">

        <!-- Modal -->
        <div class="modal fade" id="wkModal" role="dialog">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title"><?php echo JText::_('YOUR_SUGGEST_CATEGORY');?></h4>
                    </div>

                    <div class="modal-body">

                        <div class="form-group">
                            <label for="recipient-name" class="control-label"><?php echo JText::_('CATEGORY_NAME');?><span style="color:red;">*</span></label>
                            <input type="text" name="catname"  placeholder="<?php echo JText::_('CATEGORY_NAME');?>" id="catname" class="form-control input-lg" style="width:94%;height:25px;font-size:15px">
                        </div>
                        <div class="form-group">
                            <label for="message-text" class="control-label"><?php echo JText::_('ADDITIONAL_INFO_CAT');?></label>
                            <textarea class="form-control" id="catdesc" name="catdesc" style="width:94%;font-size:15px" id="message-text"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="message-text" class="control-label"><?php echo JText::_('ADDITIONAL_INFO');?></label>
                            <textarea class="form-control" id="catinfo" name="catinfo" style="width:94%;font-size:15px" id="message-text"></textarea>
                        </div>

                    </div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success" id="modal_submit" value="<?php echo JText::_('SEND_REQUEST_ADMIN');?>"/>
                        <input type="reset" class="btn btn-warning" id="modal_reset" value="<?php echo JText::_('RESET');?>"/>
                        <button  data-dismiss="modal" class="btn btn-default hidden-phone" >Close</button>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
jQuery(function(){
        if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
          jQuery('.take_pic_').css('display','none');
        }
});
 var resp=0;
  var pic_snaps='';
  var pic_size='';

    jQuery('#catname').on('blur',function(){
        var catname=jQuery("#catname").val();
        if(catname.trim()==''){
            jQuery('#catname').css('border','1px solid RED');
        }
        else{
            jQuery('#catname').css('border','1px solid #CCC');
        }

    });
    jQuery("#modal_submit").on('click',function(){
        
var catval=jQuery('#catname').val();
catval=catval.trim();
var catdesc=jQuery('#catdesc').val();
var catinfo=jQuery('#catinfo').val();
    if(catval.trim()!=''){
        jQuery(this).attr("disabled",true);
        jQuery.ajax({
            url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.categoryRequest', false);?>",
            type: "post",
            data:{catval:catval,catdesc:catdesc,catinfo:catinfo,seller_email:'<?php echo $user->email;?>'},
            success: function(result){
                jQuery("#modal_submit").attr("disabled",false);
                if(result==1){
                    jQuery('#wkModal .modal-body').css('display','none');
                    jQuery('#wkModal .modal-footer').css('display','none');
                    jQuery('#wkModal').append("<p style='color:green ;padding:10px'><?php echo JText::_('YOUR_RQUEST_SUCCESSFULLY_SUBMITTED');?></p>");
                }
                else if(result==0){
                    jQuery('#wkModal .modal-body').css('display','none');
                    jQuery('#wkModal .modal-footer').css('display','none');
                    jQuery('#wkModal').append("<p style='color:red ;padding:10px'><?php echo JText::_('YOUR_RQUEST_SUCCESSFULLY_FAILED');?></p>");
                }
                else if(result<0){
                    jQuery('#wkModal .modal-body').css('display','none');
                    jQuery('#wkModal .modal-footer').css('display','none');
                    jQuery('#wkModal').append("<p style='color:red ;padding:10px'><?php echo JText::_('YOUR_RQUEST_VM_FAILED');?></p>");
                }
                else{
                    jQuery('#wkModal .modal-body').css('display','none');
                    jQuery('#wkModal .modal-footer').css('display','none');
                    jQuery('#wkModal').append("<p style='padding:10px'>"+result+"</p>");
                }
            }
        });
    } else{
jQuery('#catname').css("border-color",'red');
}
});
jQuery('#result_holder').on('click','#rm',function(e){
var dataUrl=jQuery(this).parent('#result').children('img').attr('src');
var fname=dataUrl.split("product/");
jQuery(this).parent('#result').remove();
jQuery.ajax({
type: "post",
url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.deleteimagepreview', false);?>",
data: {
imgBase64: fname[1]},
success: function(data)
{
}
});
e.preventDefault();
});
// Upload image to sever
//
jQuery("#upload_pic").on("click", function(e){
        <?php
        if ($browserType!="mozilla") {
        ?>
            var dataUrl = jQuery("#canvas").find("img").attr("src");
        <?php
        } else { ?>
            var dataUrl = canvas.toDataURL();
        <?php
        }
        ?>
    jQuery.ajax({
        async:'false',
        type: "post",
        url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.uploadImage', false);?>",
        data: {
        imgBase64: dataUrl},
        success: function(data){
            data=data.split(',');
              var name=data[0];
              pic_snaps=pic_snaps+','+name;
              pic_size=pic_size+','+data[1];

            jQuery("#result_holder").append('<div id="result"><img src="<?php echo juri::root().$vmconf->get("media_product_path");?>'+name+'"><span class="image_over" id="rm"></span></div>');
            jQuery('#video').show('slow');
            jQuery('#canvas').hide('slow');
            jQuery('#cam_snap').show('slow');
            jQuery('#new').hide();
            jQuery('#upload_pic').hide();
            jQuery('#camera').hide();
        }
    });
    e.preventDefault();
});
  jQuery(".add_product_main .product_save").click(function(e){
    var input = jQuery("<input>").attr("type", "hidden").attr("name", "mydata").val(pic_snaps);
    jQuery('#adminForm input[name="mydata"],#adminForm input[name="mydata_size"]').remove();
    jQuery('#adminForm').append(jQuery(input));
    var input1 = jQuery("<input>")
        .attr("type", "hidden")
                .attr("name", "mydata_size").val(pic_size);
    jQuery('#adminForm').append(jQuery(input1));
    if (typeof grecaptcha != undefined) {
        var response = grecaptcha.getResponse();
        if(response.length == 0) {
            var message = {};
            message.error = [];
            message.error.push(Joomla.JText._('COM_MARKETPLACE_CAPTCHA_DESC'));
            Joomla.renderMessages(message);
            jQuery(".resp-tab-item:nth-child(0)").click();
            e.preventDefault();
        }
    }
});
jQuery('#result_holder').on('click','#rm',function(e){
var dataUrl=jQuery(this).parent('#result').children('img').attr('src');
var fname=dataUrl.split("product/");
jQuery(this).parent('#result').remove();
jQuery.ajax({
type: "post",
url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.delete', false);?>",
data: {
imgBase64: fname[1]},
success: function(data)
{
}
});
e.preventDefault();
});
var both=<?php echo $both;?>;
var mod="<?php echo $mod;?>";
jQuery(function(){
jQuery(window).on('load resize',function(){
if(both==2){
if(jQuery('.Wk_outer').width()>=900){
jQuery('.marketplace_position1').css("width","19%");
jQuery('.marketplace_position2').css("width","19%");
jQuery('.add_product_main').css("width","57%");
}
else if(jQuery('.Wk_outer').width()<766 && jQuery('.Wk_outer').width()>650){
jQuery('.marketplace_position1').css("width","23%");
jQuery('.marketplace_position2').css("width","99%");
jQuery('.add_product_main').css("width","73%");
}
else if( jQuery('.Wk_outer').width()<=650){
jQuery('.marketplace_position1').css("width","99.5%");
jQuery('.marketplace_position2').css("width","99.5%");
jQuery('.add_product_main').css("width","99.5%");
}
}
else if(both==1){
if(jQuery('.Wk_outer').width()>=724){
if (mod=="l")
jQuery('.marketplace_position1').css("width","23.5%");
else
jQuery('.marketplace_position2').css("width","23.5%");
jQuery('.add_product_main').css("width","70.5%");
}
else if( jQuery('.Wk_outer').width()<724){
if (mod=="l")
jQuery('.marketplace_position1').css("width","99.5%");
else
jQuery('.marketplace_position2').css("width","99.5%");
jQuery('.add_product_main').css("width","99.5%");
}
}
else{
jQuery('.add_product_main').css("width","99.5%");
}
});
});
</script>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function(){
    jQuery("span[aria-controls=tab_item-0]").addClass("resp-tab-active");
jQuery("body").on('click','.image_over',function(event){
    swal({
        title: " <?php echo JText::_('ARE_YOU_SURE'); ?>",
        text: "<?php echo JText::_('CONFIRM_DELETE'); ?>",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: '<?php echo JText::_("Y_ES")?>',
        cancelButtonText: "<?php echo JText::_('N_O')?>",
        closeOnConfirm: false,
        closeOnCancel: true
    },
    function(isConfirm){
        if (isConfirm){
            var this_this = jQuery(event.target);
            var this_image = this_this.prev("img");
            var dataUrl=jQuery(event.target).prev('img').attr('src');
            var fname=dataUrl.split("product/");
           
            jQuery.ajax({
                url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.deleteimage', false);?>",
                type: "POST",
                data: {id:this_image.attr("id"),imgBase64:fname[1]},
                dataType: "html",
                success:function(){
                    this_this.prev("img").remove();
                    this_this.parent(".imagebody").remove();
                    this_this.parent(".imgdiv").remove();
                    jQuery(".image_over").css({'display':'none'});
                    swal({
                        title:'',
                        type: "success",
                        text: "<?php echo JText::_('SUCCESSFULY_DELETED')?>",
                        timer: 3000,
                        showConfirmButton: false
                    });
                }
            });
        }
    });
});
/*********************start multilang**************************************/
jQuery("#multilang").on('change', function(){
jQuery( "<div id='mpopup_overlay'></div>").appendTo("body");
var country_code_pre = jQuery(this).val();
var country_code = country_code_pre.split(' ');
jQuery.ajax({
url: "index.php?option=com_marketplace&view=addproduct&task=addproduct.multilang",
type: "POST",
data: {code:country_code[1],virtuemart_product_id: '<?php echo $virtuemart_product_id; ?>'},
dataType: "json",
beforeSend:function(){
jQuery("#mpopup_overlay").fadeIn("fast");
jQuery('body').append('<div id="wk_loader"></div>');
},
success:function(data){
setTimeout(
function()
{
jQuery("#mpopup_overlay").fadeOut("slow");
jQuery('#wk_loader').remove();
jQuery('input#productname').val(data[0].product_name);
jQuery('#product_description_ifr').contents().find('body').html('<p>'+data[0].product_desc+'</p>');
// jQuery('#product_description_short').contents().find('body').val('<p>'+data[0].product_s_desc+'</p>');
if(country_code_pre)
{
var url = '<?php echo juri::root();?>components/com_marketplace/images/countryflags/'+country_code[0]+'.gif';
jQuery('.multilangflag img').show();
jQuery('.multilangflag img').attr('src', url);
} else {
jQuery('.multilangflag img').hide();
}
}, 2000);
}
});
});
jQuery("#productname").keyup(function(){
 var a=jQuery(this).val();
 if(!a){
     jQuery("#wk_suggesstion-box").hide();
 }else{
     jQuery.ajax({
         type: "POST",
         url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.selectProduct', false);?>",
         data:'keyword='+jQuery(this).val(),
         beforeSend: function(){
         jQuery("#productname").css("background","#FFF url(<?php echo JURI::root().'components/com_marketplace/images/LoaderIcon.gif'?>) no-repeat 80%");
         },
         success: function(data){
            jQuery("#productname").css("background","#FFF");
            if(!data){
                jQuery("#wk_suggesstion-box").hide();
            }else{
                jQuery("#wk_suggesstion-box").show();
                 jQuery("#wk_suggesstion-box").css('max-height',"100px");
                 jQuery("#wk_suggesstion-box").html(data);

            }
         }
    });
 }

});
jQuery('html').click(function(e) {
if(!jQuery(e.target).hasClass('#wk_pro_container') )
{
jQuery("#wk_suggesstion-box").hide();
}
});
});
var wki=0;
function selectproducts(val,vmid) {
jQuery("#productname").val(val);
jQuery("#wk_suggesstion-box").hide();
jQuery.ajax({
type: "POST",
url: "<?php echo JRoute::_('index.php?option=com_marketplace&view=addproduct&task=addproduct.getProductDetail', false);?>",
data:'vmid='+vmid,
beforeSend: function(){
jQuery("body").css("background","#FFF url(<?php echo JURI::root().'components/com_marketplace/images/LoaderIcon.gif'?>) no-repeat center");
},
success: function(data){
var data=JSON.parse(data);

jQuery('#product_parent_id option').removeAttr('selected');
for(var cat in data.categories){
jQuery('#product_parent_id option[value='+data.categories[cat]+']').attr('selected','selected');
}
jQuery('#virtuemart_manufacturer_id option').removeAttr('selected');
for(var cat in data.manufacturer){
jQuery('#virtuemart_manufacturer_id option[value='+data.manufacturer[cat]+']').attr('selected','selected');
}
jQuery('#product_in_stock').val(data.product_in_stock);
jQuery('#product_weight').val(data.product_weight);
jQuery('#product_sku').val(data.product_sku);
jQuery('#price').val(data.baseprice);
if(!isNaN(data.price_discount))
    jQuery('#product_discount_id option[value='+data.price_discount+']').attr('selected','selected');
if(!isNaN(data.price_tax))
jQuery('#product_tax_id option[value='+data.price_tax+']').attr('selected','selected');
jQuery("#salesprice").val(data.salesprice);
jQuery('#product_description_ifr').contents().find('body').html('<p>'+data.product_description+'</p>');
jQuery('#product_description_short').val(data.product_description_short);
var images='';
jQuery.each(data.image,function(i,val){
    images+='<div class="imgdiv" style="width: 70px; border: 2px solid rgb(204, 204, 204); display: inline-block; overflow: hidden;margin: 0px 5px;position:relative;"><img class="" src="<?php echo JURI::root()?>'+data.image[i]+'" height="70" width="70" style="opacity:1;display:block;"/><span class="image_over" style="display:none;"></span><input name="imagepre[]" value="'+data.image[i]+'" type="hidden"></div>';
});
jQuery('.add_product_main .collection').append("<div id='preview'>"+images+"</div>");
jQuery("body").css("background","#FFF");
if(data.customfields!=undefined){
jQuery.ajax({
type: "POST",
url: '<?php echo JRoute::_("index.php?option=com_marketplace&view=addproduct&task=addproduct.getDataFill", false);?>&virtuemart_product_id='+vmid+'&type=fields&row='+wki++,
success: function(data){
jQuery("#custom_field").append(data);
}
});
}
}
});
}
</script>

<div class="marketplace_position2"><?php echo JHTML::_('content.prepare', '{loadposition wk_marketplace-right}'); ?></div>
<div class="marketplace_position-bottom" style="clear:both;"><?php echo JHTML::_('content.prepare', '{loadposition wk_marketplace-bottom}'); ?></div>
</div>
</div>
