<?php
/**
 * @extension       Marlev Template
 * @author          Lev Milicenco<support@marlev.it>
 * @link            http://www.marlev.it
 * @copyright       Copyright 2017 marlev.it All Rights Reserved
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */JHtml::_('bootstrap.tooltip');

defined('_JEXEC') or die;
include JPATH_COMPONENT_ADMINISTRATOR . "/functions/layout.php";
$input = JFactory::getApplication()->input;
$id = $input->getInt("id");
$render = new ml_layout($this->layout, $this->load->template);
$getlayout = $render->return_layout();
?>

<div id="loadlayout" class="template-layout" >
    <!--    <h1 id="run">ciao</h1>-->

    <?php
    $body = $render->elabora_posdata("ml_body");
    echo '<div class="content-pos-name"><div class="section-name-body"><strong>Body</strong></div>' . $render->in_popup('ml_body', 'ml_body', '', $body, 'Body') . '</div>';
    foreach ($getlayout->sections as $key => $getpos):
        $gkey = $key . '_section'; //_section e' fissaione defiitita in template/admin/layout.php
        ?>
        <div id="<?php echo $gkey; ?>" class="layouts" >
            <?php
            $get_section = $render->elabora_posdata($gkey);
            echo '<div class="content-pos-name"><div class="section-name-resto"><strong>' . JText::_("COM_TMARLEV_SECTION") . ' ' . ucfirst(str_replace("_section", "", $gkey)) . ' </strong></div>' . $render->in_popup($gkey, $gkey, '', $get_section, ucfirst($key) . ' Section') . '</div>';
            foreach ($getpos as $gpos => $pos):

                $pos = trim($pos);
                $posdata = $render->elabora_posdata($pos);
                $parentid = 'pos_' . $pos;
                $positions_details = $render->get_positions_details($posdata, $pos);
                $suspended = $render->assign_suspend($pos);
                ?>
                <div id="<?php echo $parentid ?>" class="<?php echo $suspended->suspended_class; ?> position <?php echo $posdata->width ?>" >
                    <div style="text-align: center;"><strong> <?php echo JText::_("COM_TMARLEV_BLOCK_OF_POSITION") . " " . $pos ?></strong></div>
                    <div class="add-position-block"> <span class="add-position" data-id="<?php echo $parentid ?>" data-class="subposition" data-maxcols="<?php echo $positions_details->maxcols; ?>"  data-positions="<?php echo $positions_details->positions; ?>"><span  class="hasTooltip icon-plus" data-original-title="<?php echo JText::_('COM_TMARLEV_ADD_POSITION_LABEL') ?>"></span></span>
                        <span class="checkbox checkbox-primary checkbox-section suspend-position-block hasTooltip" data-original-title="<?php echo JText::_('COM_TMARLEV_SUSPEND_UNSUSPEND_POSITION') ?>">
                            <input <?php echo $suspended->checked; ?> class='suspend-position' data-id="<?php echo $parentid ?>" id="checkbox-<?php echo $parentid ?>"  type="checkbox" value="1" name="layout[suspended][<?php echo $pos ?>]">
                            <label for="checkbox-<?php echo $parentid ?>"></label>
                        </span>
                        <span class="inlarge-block" ><span class="hasTooltip inlarge-click icon-expand-2" data-inputid="<?php echo $parentid ?>_input" data-actual="<?php echo $posdata->width ?>" data-id="<?php echo $parentid ?>" data-original-title="<?php echo JText::_('COM_TMARLEV_POSITION_BLOCK_WIDTH') ?>"></span></span>
                        <?php
                        $section_key = $pos . '_subsection'; //_subsection e' fissaione defiitita in template/admin/layout.php
                        $get_subsection = $render->elabora_posdata($section_key);
                        echo $render->in_popup($section_key, $section_key, '', $get_subsection, ucfirst($pos) . ' Subsection');
                        ?>

                        <input type="hidden" id="<?php echo $parentid ?>_input" value="<?php echo $posdata->width ?>" name="layout[width][<?php echo $pos ?>]">
                        <input type="hidden" id="<?php echo $parentid ?>-positions" value="<?php echo implode(",", $posdata->defpositions) ?>" name="layout[positions][<?php echo $pos ?>]">

                    </div>
                    <?php
                    if ($posdata->positions != false):
                        $get_defcollayout = array();
                        $get_tabcollayout = array();
                        $get_mobcollayout = array();

                        foreach ($posdata->positions as $n1 => $subpos):

                            if ($this->layout !== false && !isset($this->layout['positions'][$subpos])) {
                                continue;
                            }

                            $subposdata = $render->elabora_posdata($subpos);
                            $get_defcollayout[] = $subposdata->defcollayout[0];
                            $get_tabcollayout[] = $subposdata->tabcollayout[0];
                            $get_mobcollayout[] = $subposdata->mobcollayout[0];
                            ?>
                            <div data-id="pos_<?php echo $subpos ?>" class="subposition pos_<?php echo $subpos ?> col-md-<?php echo $subposdata->defcollayout[0] ?> col-lg-<?php echo $subposdata->defcollayout[0] ?> col-xs-12 col-sm-12" data-mobile="<?php echo $subposdata->mobcollayout[0] ?>" data-tablet="<?php echo $subposdata->tabcollayout[0] ?>" data-pc="<?php echo $subposdata->defcollayout[0] ?>" data-position="<?php echo $subpos ?>">
                                <div style="padding: 2px"> <div class="show-subposition">
                                        <?php
                                        echo $render->inners_positions($subposdata, 'innertop');

                                        $selected = new stdClass;
                                        $selected->pc = $subposdata->defcollayout[0];
                                        $selected->tablet = $subposdata->tabcollayout[0];
                                        $selected->mobile = $subposdata->mobcollayout[0];
                                        ?>

                                        <?php
                                        if ($subpos == "content") {
                                            echo '<div class="content-pos-name"><div class="section-name-resto"><strong>' . ucfirst($subpos) . '</strong></div><div class="small">' . Jtext::_('COM_TMARLEV_CONTENT_BLOCK_DESK') . '</div>' . $render->in_popup($parentid, $subpos, $selected, $subposdata, "Content") . '</div>';
                                        } else {
                                            echo '<div>' . $subpos . '</div>';
                                            echo $render->in_popup($parentid, $subpos, $selected, $subposdata, $subpos);
                                            echo '<div class="colcancel"><span class="hasTooltip icon-cancel" data-original-title="' . JText::_('COM_TMARLEV_DELETE_THIS_COL') . '"></span></div>';
                                        }
                                        echo $render->inners_positions($subposdata, 'innerbottom');
                                        ?> 
                                    </div><div class="clearfix"></div></div>
                                <div class="clearfix end-position"></div>
                            </div>

                        <?php endforeach; ?>
                        <input type="hidden" id="<?php echo $parentid ?>-mobcollayout" value="<?php echo implode(",", $get_mobcollayout) ?>" name="layout[mobcollayout][<?php echo $pos ?>]">
                        <input type="hidden" id="<?php echo $parentid ?>-tabcollayout" value="<?php echo implode(",", $get_tabcollayout) ?>" name="layout[tabcollayout][<?php echo $pos ?>]">
                        <input type="hidden" id="<?php echo $parentid ?>-defcollayout" value="<?php echo implode(",", $get_defcollayout) ?>" name="layout[defcollayout][<?php echo $pos ?>]">
                    <?php else: ?>
                        <input type="hidden" id="<?php echo $parentid ?>-mobcollayout" value="<?php echo implode(",", $posdata->mobcollayout) ?>" name="layout[mobcollayout][<?php echo $pos ?>]">
                        <input type="hidden" id="<?php echo $parentid ?>-tabcollayout" value="<?php echo implode(",", $posdata->tabcollayout) ?>" name="layout[tabcollayout][<?php echo $pos ?>]">
                        <input type="hidden" id="<?php echo $parentid ?>-defcollayout" value="<?php echo implode(",", $posdata->defcollayout) ?>" name="layout[defcollayout][<?php echo $pos ?>]">
                        <?php
                        echo $render->show_subbpositions($posdata, $pos, 'subposition', $posdata->defpositions);

                    endif;
                    
                    ?>

                    <div class="clearfix  end-position"></div>
                </div>
            <?php endforeach; ?>
           
            <div class="clearfix"></div>
        </div>


    <?php endforeach; ?>
    <div class="hidden">

        <span id="cols-warning" data-message="<?php echo JText::_("COM_TMARLEV_MAX12_COLS") ?>"></span>
        <span id="all-positions_added" data-message="<?php echo JText::_("COM_TMARLEV_ALL_POSITIONS_ADDED") ?>"></span>

    </div>
    <div class="clearfix"></div>





    <input type="hidden" name="params[layoutid]" value="<?php echo $this->layoutid; ?>" />
    <div style="display:none" class="avvaiable-positions-content">
        <div  id="avvaiable-positions-block">
            <?php echo $render->get_multiselect_positions(); ?>
        </div>
    </div>
</div>




