 
<?php
$translation        = \DynCom\mysyde\common\classes\Registry::get("translation");
$formname           = "form_field_list";
$inputname          = "input_id";
$input_page_id      = (isset($_REQUEST["input_page_id"]) ? $_REQUEST["input_page_id"] : "");
$input_component_id = (isset($_REQUEST["input_component_id"]) ? $_REQUEST["input_component_id"] : "");
$main_layout_id = $GLOBALS["language"]["main_layout_id"];
$siteparts      = \DynCom\mysyde\common\classes\Siteparts::get();
 
?>

<form id="<?= $formname ?>" name="<?= $formname ?>" method="post">
    <input name="input_id" type="hidden" value="<?= $input_id ?>">
    <input type="hidden" id="input_line_id" class="selected_linklist_row" name="input_line_id" value="" />
    <input type="hidden" name="input_page_id" value="<?php echo $input_page_id; ?>" />
    <input type="hidden" name="input_component_id" value="<?php echo $input_component_id; ?>" />
    <input type="hidden" name="is_multiform" value="1">
    <input type="hidden" name="step_id" id="step_id">
    <input type="hidden" name="section_id" id="section_id">
     
    <div class="tab">
    <ul class="toolbar_menu">
        <?= button("new", $translation->get("new_level"), $formname, "loadCard('new_line_contactform_level', true)", "", FALSE); ?>
        <?= button("new", $translation->get("new_section"), $formname, "loadCard('new_line_contactform_section', true)", "", FALSE); ?>
        <?php
    //    echo  button("new", $translation->get("new"), $formname, "loadCard('new_line_contactform', true)", "", FALSE);
         ?>
        <?php
        // echo button("edit", $translation->get("edit"), $formname, "loadCard('edit_line_contactform')", "", FALSE); 
        
       
        ?>
        <?php 
        //  button("delete", $translation->get("delete"), $formname, "loadCard('delete_line_contactform', false, '{$translation->get('delete_contactform_field_confirm')}')", "", FALSE); 
        ?>

        <?php 
        //  button("up", $translation->get("go_up"), $formname, "loadCard('moveup_line_contactform')", "", FALSE); 
        ?>
        <?php 
        //  button("down", $translation->get("go_down"), $formname, "loadCard('movedown_line_contactform')", "", FALSE); ?>

    </ul>


            <?
                $query = "SELECT * FROM contactform_steps where contactform_id = ".$input_id.' ORDER BY sorting ASC';
                
                $result = @mysqli_query($GLOBALS['mysql_con'], $query);
                $i = 0;
                while($row    = mysqli_fetch_array($result)){
                    ?>
                    
                    <button class="tablinks" onclick="openTab(event, 'tab<?=$row['id']?>')" <?php if($i == 0){ ?> id="defaultOpen" <?php } ?> ><?= ($i+1).': '.$row['name'];?></button>
                    
                    <? $i ++; } ?>
        </div>
        
   <!-- tab div -->

 
 

   <?
    $query = "SELECT * FROM contactform_steps where contactform_id = ".$input_id.' ORDER BY sorting ASC';
   
    $resultStep = @mysqli_query($GLOBALS['mysql_con'], $query);
    
    $e = 1;
     while($rowStep    = mysqli_fetch_array($resultStep)){
        
    ?>
        <div id="tab<?=$rowStep['id']?>" class="tabcontent">
            
                <div class="tab two">
                <ul class="toolbar_menu">
                    <?= button("edit", "Ebene bearbeiten", $formname, "edit_level(this, '{$formname}',  '{$rowStep['id']}')", "", FALSE); ?>
                  
                </ul>    
                <?

                        
                        $query = "SELECT * FROM contactform_section where step_id = ".$rowStep['id'].'';
                        
                        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
                        $i = 0;
                        $a = 1;
                        while($row    = mysqli_fetch_array($result)){
                            ?>
                            <button class="tablinksSection" onclick="openSection(event, 'tab_section_<?=$row['id']?>')" <?php if($i == 0){ ?> id="defaultOpen2" <?php } ?> ><?= $e.'.'.$a.': '.$row['name'];?></button>
                            
                            <? $i ++; $a++; } ?>
                </div>
                
        <!-- tab div -->

        </div>
    <?php $e++; }
    
                        $query = "SELECT * FROM contactform_section where contactform_id = ".$input_id.'';
                        
                        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
                        $i = 0;
                        while($row    = mysqli_fetch_array($result)){
    ?>






</form>
<div id="tab_section_<?=$row['id']?>" class="tabcontentSection">
                             
                            <div class="data-link text-right">
                            <ul class="toolbar_menu">
                                <?= button("new", $translation->get("add_content2"), $formname, "toggleScrollerHeadline('" . $translation->get("add_content2") . "', 'new', ".$row['id'].");", "", false); ?>
                                <?=  button("edit", "Abschnitt bearbeiten", $formname, "edit_section(this, '{$formname}',  '{$row['id']}')", "", false);?>
                                <?= button("new", $translation->get("new"), $formname, "new_field(this, '{$formname}',  '{$row['id']}','{$row['step_id']}')", "", false) ?>
                                <?= button("up",$translation->get("go_up"),$formname,"moveup_line_multi(this, '{$formname}',  '{$row['id']}')", "", false); ?>
                                <?= button("down",$translation->get("go_down"),$formname,"movedown_line_multi(this, '{$formname}',  '{$row['id']}')", "", false); ?>
                            </ul>
                            <!-- Form -->
                            <form style="position:inherit;" id="form_inhalte<?= $row['id']?>" name="form_inhalte<?= $row['id']?>" method="post" class="inhalte_toggle_container<?=$row['id']?>">
                                    <input type="hidden" name="update_visitor_data" value="1" />
                                    <input type="hidden" name="sitepart_id" value="0" />
                                    <input name="input_section_id" type="hidden" value="<?= $row['id'] ?>">

                                    <input name="input_contactform_id" type="hidden" value="<?= $input_id; ?>">

                                    <div class="inhalte_toggle_container inhalte_toggle_container<?=$row['id']?>" id="inhalte_form_headline<?=$row['id']?>">
                                        <div id="srollerInhalteHeadline<?=$row['id']?>"><h2></h2></div>
                                        <div id="scroller_inhalte_form<?=$row['id'];?>">
                                            <table class="cardform" border="0" cellspacing="0" cellpadding="0">
                                                <tr>
                                                    <td>
                                                        <? 
                                                        // layout_area_select($translation->get("layout_area")); 
                                                        ?>

                                                    </td>
                                                    <td>
                                                        <? 
                                                        // input($translation->get("active"), "input_active", "checkbox", 1); 
                                                        ?>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                    <div id="pagecontentScroller<?=$row['id']?>" class="pagecontentScroller inhalte_toggle_container inhalte_toggle_container<?=$row['id']?>">
                                        <div class="scroller_inhalte">

                                            <ul class="inhalte_menu">
                                                <?php
                                                foreach ($siteparts as $sitepartId => $sitepartData) {
                                                    // keine shop siteparts anzeigen
                                                    if ($sitepartData['code'] == 'slideshow' || $sitepartData['code'] ==  'textcontent') {
                                                      

                                                    button($sitepartData['class'], $sitepartData['description'], 'form_inhalte'.$row['id'], "contentmenuClick(this, '{$sitepartData['code']}', false, $sitepartId, '{$row['id']}')");
                                                    }
                                                }

                                                button("inhalt_collection graybox", $translation->get("collection"), 'form_inhalte'.$row['id'], "contentmenuClick(this, 'collection_list', true, '{$row['id']}')"); 
                                                button("inhalt_collection graybox", $translation->get("collection_preview"), 'form_inhalte'.$row['id'], "contentmenuClick(this, 'collection_preview', true, '{$row['id']}')");
                                                // button("inhalt_collection graybox", $translation->get("group"), 'form_inhalte'.$row['id'], "contentmenuClick(this, 'group', true, '{$row['id']}')");

                                                foreach ($siteparts as $sitepartId => $sitepartData) {
                                                    // nur shop siteparts anzeigen
                                                    if (!isset($sitepartData['is_shop']) || $sitepartData['is_shop'] === FALSE || $sitepartData['code'] == 'contactform') {
                                                        continue;
                                                    }
 
                                                    button($sitepartData['class'] . ' graybox', $sitepartData['description'], 'form_inhalte'.$row['id'], "contentmenuClick(this, '{$sitepartData['code']}', false, $sitepartId, '{$row['id']}')");
                                                }
                                                ?>


                                            </ul>

                                        </div>
                                    </div>
                                    <?
                                        show_contact_link_rows($row['id']);
                                    ?>
                            </form>
                            <!-- Form End -->
                            </div>
                          
  
</div>
<?php $i ++; } ?>


<script>
    var clickmode = 'new';
    $('.inhalte_toggle_container').hide();                                            
function toggle_inhalte_scroller() {

    if (contentscroller.css('display') == 'none') {
        contentscroller.show();
    } else {
        contentscroller.hide();
    }
}
    function toggleScrollerHeadline( _headline, _clickAction, section_id = '' ) {
        var contentscroller = $('.inhalte_toggle_container'+section_id);
        $('#srollerInhalteHeadline'+section_id+' h2').html(_headline);
        contentscroller.show();

        clickmode = _clickAction;
    }
    function contentmenuClick( _el, _module, _listOnly, _sitepartId, section_id = '' ) {
        var listOnly = _listOnly || false;
        var sitepartId = _sitepartId || 0;
        console.log(_el);
        setCurrentToolbarClicked(_el);

        if (listOnly === true) {
           
            loadCard('list_' + _module + '_page', true);
            return;
        }
        console.log(clickmode);
        $('input[name="sitepart_id"]', $('#form_inhalte'+section_id)).val(_sitepartId);

        if (clickmode == 'list') {
            loadCard('list_' + _module + '_page', true);
        } else {
            _module = 'contact_'+_module;
            loadCard('new_' + _module, true);
        }
    }
    function edit_level(_el, fornmame, level_id){
        console.log('level');
        $('#step_id').val(level_id);
        loadCard('edit_line_level', true)
    }
    function edit_section(_el, fornmame, section_id){
        $('#section_id').val(section_id);
        loadCard('edit_line_section', true)
    }
    function moveup_line_multi(_el, fornmame, section_id){
        $('#section_id').val(section_id);
        input_line_id = 0;
        input_line_id = $('#form_inhalte'+section_id+" ol.linklist li>div").attr('data-inputid');
        $('#input_line_id').val(input_line_id);
        loadCard('moveup_line_multicontactform', true);
    }
    function movedown_line_multi(_el, fornmame, section_id){
        $('#section_id').val(section_id);
        input_line_id = 0;
        input_line_id = $('#form_inhalte'+section_id+" ol.linklist li>div").attr('data-inputid');
        $('#input_line_id').val(input_line_id);
        loadCard('movedown_line_multicontactform', true);
    }
    function new_field(_el, fornmame, section_id, step_id){
        $('#section_id').val(section_id);
        $('#step_id').val(step_id);
        loadCard('new_line_contactform', true)
    }
</script>
<script type="text/javascript">
    // var reorderCall = null;

    // //$('.dd').nestable({ /* config options */ });
    // $('ol.sortable').nestedSortable({
    //                                     forcePlaceholderSize: true,
    //                                     handle              : '.dd-icon',
    //                                     helper              : 'clone',
    //                                     items               : 'li',
    //                                     opacity             : .6,
    //                                     placeholder         : 'placeholder',
    //                                     revert              : 250,
    //                                     tabSize             : 25,
    //                                     tolerance           : 'pointer',
    //                                     toleranceElement    : '> div',
    //                                     maxLevels           : 2,
    //                                     isTree              : true,
    //                                     expandOnHover       : 1000,
    //                                     cookieIndex         : 'nestedSortable_pagecontent_expanded',
    //                                     startCollapsed      : true,
    //                                     stop                : function ( event, ui ) {
    //                                         reorder_navigation();
    //                                         store_expanded();
    //                                     },
    //                                     disabled            : false,
    //                                     isAllowed           : function ( placeholder, placeholderParent, originalItem ) {

    //                                         // gruppe in eine gruppe hinzufuegen nicht moeglich
    //                                         if (placeholderParent !== null &&
    //                                             jQuery(originalItem).hasClass("mjs-nestedSortable-no-nesting") === false &&
    //                                             jQuery(placeholderParent).hasClass("mjs-nestedSortable-no-nesting") === false) {
    //                                             return false;
    //                                         }
    //                                         return true;
    //                                     }
    //                                 });

    // $('.disclose').click(function () {
    //     $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded');
    //     store_expanded();
    // });

    // function store_expanded() {
    //     var list = [];
    //     $('ol.sortable').find('li.mjs-nestedSortable-expanded').each(function () {
    //         list.push($(this).attr("id"));
    //     });
    //     $.cookie('nestedSortable_pagecontent_expanded', list.join(','));
    // }

    // function reorder_navigation() {
    //     if (reorderCall !== null) {
    //         reorderCall.abort();
    //     }

    //     serialized = $('ol.sortable').nestedSortable('serialize');
    //     arraied = $('ol.sortable').nestedSortable('toHierarchy', {startDepthCount: 0});
    //     var parameter = {
    //         list: arraied
    //     };
    //     reorderCall = jQuery.post("?action=reorder_content_page", parameter, function ( output, status, xhr ) {
    //         if (xhr.getResponseHeader('REQUIRES_AUTH') == 1) {
    //             window.location.replace("/dc/");
    //         }
    //     });
    // }

</script>