 
<?php 

// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
function load_form_field($sitepart_id, $lid, $sid){

 
                    $queryLine  = "SELECT * FROM multi_contactform_link INNER JOIN main_layout_class on multi_contactform_link.layout_area_id = main_layout_class.id   WHERE contactform_line_id = '" . $lid . "' LIMIT 1";
                    $resultLine = @mysqli_query($GLOBALS['mysql_con'], $queryLine);
                    $input_liner = array();
                    $input_liner['layout_area_id'] = '';
                    if (@mysqli_num_rows($resultLine) == 1) {
                        $input_liner = @mysqli_fetch_array($resultLine);
                    } 
                     
     
    $query  = "SELECT * FROM contactform_line WHERE header_id = '" . $sitepart_id . "' AND id = ".$lid." ORDER BY sorting ASC";
                     
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) > 0) {
        while ($field = @mysqli_fetch_array($result)) {

            if ($field['mandatory'] == 1) {
                $mandatory_text = " *";
                $required = "required";
            } else {
                $mandatory_text = "";
                $required = "";
            }
            $prefillValue = '';
            if (array_key_exists("input_" . $field["code"],$_POST)) {
                $prefillValue = $_POST["input_" . $field["code"]];
            }
            if ($field["infield"] == "1") {
                $placeholder = "placeholder='" . $field['name'] . $mandatory_text . "'";
                $label = "";
            } else {
                $placeholder = "";
                $label = $field['name'] . $mandatory_text;
            }

            if (isset($_GET["action" . $sitepart_id]) && $_GET["action" . $sitepart_id] == "send" && $field["mandatory"] == 1 && trim($_POST["input_" . $field["code"]]) == "") {
                $errorclass = "error";
            } else {
                $errorclass = "";
            }

            if (isset($_GET["action" . $sitepart_id]) && $_GET["action" . $sitepart_id] == "send" && $field["mandatory"] == 1 && in_array($field['id'], $field_errors)) {
                $errorclass = "error";
            } else {
                $errorclass = "";
            }
            if($field["field_img"] != NULL && $field["field_img"] != ''){
                echo "<div class='img_container intranet_user_image'><img class='img-fluid' src='/userdata/collection/resize/".$field["field_img"]."'></div>";
            }
            if (!empty($input_liner)) {
                echo "<div class=\"" . $input_liner['code'] . " ".$input_liner['layout_class_defined']." " . $sitepart['layout_class_defined'] . "\">";
            }
            $queryOpt = 'SELECT * FROM contactform_line_option WHERE line_id = '.$field['id']; 
            $resultOpt = @mysqli_query($GLOBALS['mysql_con'], $queryOpt); 
                           
            switch ($field["typ"]) {
                case 1:?>
                    <div class="form-group">
                        <label for="input_<?=$field["code"];?>"><?=$label?></label>
                        <input data-section="<?=$field['section_id']?>" data-next-section="<?=$field['next_section_id']?>" type="text" class="form-control text <?= $errorclass ?>" <?= $required ?>
                            name="input_<?= $field['code'] ?>"
                            id="input_<?= $field["code"]; ?>" <?= $placeholder; ?>
                            value="<?= htmlspecialchars($_POST["input_" . $field["code"]], ENT_QUOTES, 'UTF-8') ?>">
                    </div>
                    <?
                    break;
                case 2:?>
                    <div class="form-group">
                        <label for="input_<?=$field["code"];?>"><?=$label?></label>
                        <textarea class="form-control textarea <?= $errorclass ?>" <?= $required ?>
                                name="input_<?= $field['code'] ?>"
                                id="input_<?= $field["code"]; ?>" <?= $placeholder; ?>
                                value="<?= htmlspecialchars(str_replace( '\r\n', PHP_EOL, $_POST["input_" . $field["code"]]), ENT_QUOTES, 'UTF-8') ?>"></textarea>
                    </div>
                    <?
                    break;
                case 3:
                    $checked_text = ($prefillValue) ? " checked=\"checked\"" : "";
                    ?>
                    <div class="form-group form-check">
                        <label class="form-check-label">
                            <input data-section="<?=$field['section_id']?>" data-next-section="<?=$field['next_section_id']?>" class="form-check-input input_selection" <?= $checked_text ?> <?= $required ?>
                                name="input_<?= $field['code'] ?>" id="input_<?= $field["code"]; ?>"
                                type="checkbox" value="<?= $field["code"]; ?>">
                            <?=$field['name'] . $mandatory_text;?>
                        </label>
                    </div>
                    <?
                    break;
                case 4:?>
                
                    <div class="form-group">
                        <h2 class="select-headline multi_input_heading" for="input_<?=$field["code"];?>"><?=$label?></h2>
                        <div class="input select_body <?= $errorclass ?>">
                            <select class="select input_select" data-section="<?=$field['section_id']?>" data-next-section="<?=$field['next_section_id']?>" <?= $required ?> name="input_<?= $field['code'] ?>"
                                    id="input_<?= $field['code']; ?>">
                                    <option selected>------</option>
                                <?
                                // $options = explode(";", $field["option_string"]);
                                  while ($option = @mysqli_fetch_array($resultOpt)) {
                                    $className = 'col-md-12';
                                     $linked = 0;
                                     if($option['linked_field']){
                                        $linked = 1;
                                     }
                                    $selected_text = ($prefillValue == $option['option_string']) ? " selected=\"selected\"" : "";
                                    echo "<option data-opt='".$option['id']."' data-linked='".$linked."' data-form='". $sitepart_id."'  data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' data-field='".$field['id']."'  data-id='".$field['id']."'   " . $selected_text . " value=\"" . $option['option_string'] . "\">" . $option['option_string'] . "</option>";
                                //     if($option['linked_field']){
                                //     echo "<div class=\"input_collection_link_input_linked ".$className." iconfield-no-border \">";
                                //     echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' readonly class='input_selection_text inputLinked_".$option['id']."' data-id='".$key."' id=\"input_collection_link_field_" . $field['id'] . "_value_" . $value . "\" placeholder= '".$option['linked_placeholder']."' type=\"text\" name=\"inputlinked_" . $field['id'] . "_".$option['id']."\" value='' >";
                                //     echo '</div>';
                                //  }
                                }
                                
                                ?>
                            </select>
                            <?php 
                             $queryOpt = 'SELECT * FROM contactform_line_option WHERE line_id = '.$field['id']; 
                             $resultOpt = @mysqli_query($GLOBALS['mysql_con'], $queryOpt); 
                             
                                while ($option = @mysqli_fetch_array($resultOpt)) {
                                    if($option['linked_field']){
                                            echo '<div class="noDisplay input_selected_linked select'.$option['id'].'">';
                                            echo "<div class=\"input_collection_link_input_linked ".$className." iconfield-no-border \">";
                                            echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' readonly class='input_selection_text inputLinked_".$option['id']."' data-id='".$key."' id=\"input_collection_link_field_" . $field['id'] . "_value_" . $value . "\" placeholder= '".$option['linked_placeholder']."' type=\"text\" name=\"inputlinked_" . $field['id'] . "_".$option['id']."\" value='' >";
                                            echo '</div>';
                                        echo '</div>'; 
                                        }
                                        
                                }
                                
                            ?>
                        </div>
                    </div>
                    <?
                    break;
                case 5:
                    echo "<h2>" . $field["name"] . "</h2>";
                    break;
                case 6:
                    echo "<br />";
                    break;
                case 7:
                    if ($_GET["registration"] == 1 && (int)$_GET["collection_id"] > 0) {
                        $query      = "SELECT * FROM main_collection WHERE id = '" . $_GET["collection_id"]."'";
                        $newsresult = @mysqli_query($GLOBALS['mysql_con'], $query);
                        if (@mysqli_num_rows($newsresult) == 1) {
                            $news = @mysqli_fetch_array($newsresult);
                            echo "<h3>" . $news["description"] . "</h3>";
                            echo "<input name=\"input_" . $field["code"] . "\" type=\"hidden\" id=\"input_" . $field["code"] . "\" value=\"" . $news["description"] . "\" /></td></tr>\n";
                        }
                    }
                    break;
                case 8:?>
                    <div class="form-group">
                        <label for="input_<?=$field["code"];?>"><?=$label?></label>
                        <input class="form-control file <?= $errorclass ?>" <?= $required ?>
                            name="input_<?= $field['code'] ?>" id="input_<?= $field["code"]; ?>"
                            type="file"/>
                    </div>
                    <?
                    break;
                    case 9: // Checkbox
                        

                        // echo "<div class='form-group'> <label id=\"input_collection_link_" . $field['id'] . "\" class=\"checkbox\" >".$field['name'];
                        // //Get all option_values
                        // $options = explode(";", $field["option_string"]);
                        // //Values als Integer
                        // $value = 1;
                        // foreach ($options as $option) {
                            
                        //     echo "<div class=\"input_collection_link_checkbox\">";
                        //     echo "<input class='input_selection' data-section='".$field['section_id']."' data-next-section='".$field['next_section_id']."'  data-id='".$field['id']."' id=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\" type=\"checkbox\" name=\"input_" . $field['id'] . "[]\" value=val_\"$option\" >";
                        //     echo "<label " . "for=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\">" . $option . "</label>";
                        //     echo "</div>";
                        //     $value++;
                        // }
                        // echo "</label></div>";
                        // checkbox start
                        echo "<div class='form-group'> <h2 id=\"input_collection_link_" . $field['id'] . "\" class=\"checkbox multi_input_heading classLabel\" >".$field['name'].'</h2>';
                        //Get all option_values
                        
                        //Values als Integer
                        $value = 1;
                        while ($option = @mysqli_fetch_array($resultOpt)) {
                            $iconClass = '';
                            if($option['icon'] != NULL && $option['icon'] != ''){
                                $iconClass = ' <span class="material-icons">'.$option['icon'].'</span> ';
                            }
                            $imgClass = '';
                            if($option['field_img'] != NULL && $option['field_img'] != '' && $option['field_img'] != ' '){
                                $imgClass =   "<div class='img_container img-option'><img class='img-fluid' src='/userdata/collection/resize/".$option["field_img"]."'></div>";
                            }
                          
                            if(!$option['linked_field']){
                            echo "<div class=\"input_collection_link_checkbox col-md-4 iconfield \">";
                            echo "<label " . "for=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\">".' '.$imgClass.$iconClass .'<br>'. $option['option_string'] ;
                            echo "<input data-form='". $sitepart_id."'  data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' class='input_selection_checkbox' data-field='".$field['id']."'  data-id='".$field['id']."' id=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\" type=\"checkbox\" name=\"input_" . $field['id'] . "[]\" value='".$option['option_string']."' >";
                            
                            
                            echo  "</label>";
                            echo "</div>";
                            } else{
                                $className = 'col-md-12';
                                if($option['linked_field']){
                                    $className = 'col-md-6';
                                }
                                echo '<div class="row">';
                                echo "<div class=\"input_collection_link_checkbox ".$className." iconfield-no-border \">";
                                echo "<label " . "for=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\">".' '.$imgClass.$iconClass .'<br>'. $option['option_string'] ;
                                echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' class='input_selection_checkbox input_check_linked' data-id='".$field['id']."' data-opt='".$option['id']."' id=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\" type=\"checkbox\" name=\"input_" . $field['id'] . "[]\" value='".$option['option_string']."' >";
                                
                                
                                echo  "</label>";
                                echo "</div>";
                                if($option['linked_field']){
                                    echo "<div class=\"input_collection_link_input_linked ".$className." iconfield-no-border \">";
                                    echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' readonly class='input_selection_text inputLinked_".$option['id']."' data-id='".$key."' id=\"input_collection_link_field_" . $field['id'] . "_value_" . $value . "\" placeholder= '".$option['linked_placeholder']."' type=\"text\" name=\"inputlinked_" . $field['id'] . "_".$option['id']."\" value='' >";
                                    echo '</div>';
                                ?>
                                
                                <?php }
                                echo '</div>';
                            }
                            $value++;
                        }
                        echo "</div>";
                        // checkbox end
                        // break;   
                        case 10: // Radio
                        
                            
                            echo "<div class='form-group'> <h2 id=\"input_collection_link_" . $field['id'] . "\" class=\"checkbox multi_input_heading classLabel\" >".$field['name'].'</h2>';
                            //Get all option_values
                            
                            //Values als Integer
                            $value = 1;
                            while ($option = @mysqli_fetch_array($resultOpt)) {
                                $iconClass = '';
                                if($option['icon'] != NULL && $option['icon'] != ''){
                                    $iconClass = ' <span class="material-icons">'.$option['icon'].'</span> ';
                                }
                                $imgClass = '';
                                if($option['field_img'] != NULL && $option['field_img'] != '' && $option['field_img'] != ' '){
                                    $imgClass =   "<div class='img_container img-option'><img class='img-fluid' src='/userdata/collection/resize/".$option["field_img"]."'></div>";
                                }
                              
                                if(!$option['linked_field']){
                                echo "<div class=\"input_collection_link_checkbox col-md-4 iconfield \">";
                                echo "<label " . "for=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\">".' '.$imgClass.$iconClass .'<br>'. $option['option_string'] ;
                                echo "<input data-form='". $sitepart_id."'  data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' class='input_selection_radio' data-field='".$field['id']."'  data-id='".$field['id']."' id=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\" type=\"radio\" name=\"input_" . $field['id'] . "\" value='".$option['option_string']."' >";
                                
                                
                                echo  "</label>";
                                echo "</div>";
                                } else{
                                    $className = 'col-md-12';
                                    if($option['linked_field']){
                                        $className = 'col-md-6';
                                    }
                                    echo '<div class="row">';
                                    echo "<div class=\"input_collection_link_checkbox ".$className." iconfield-no-border \">";
                                    echo "<label " . "for=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\">".' '.$imgClass.$iconClass .'<br>'. $option['option_string'] ;
                                    echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' class='input_selection_radio input_radio_linked' data-id='".$field['id']."' data-opt='".$option['id']."' id=\"input_collection_link_" . $field['id'] . "_value_" . $value . "\" type=\"radio\" name=\"input_" . $field['id'] . "\" value='".$option['option_string']."' >";
                                    
                                    
                                    echo  "</label>";
                                    echo "</div>";
                                    if($option['linked_field']){
                                        echo "<div class=\"input_collection_link_input_linked ".$className." iconfield-no-border \">";
                                        echo "<input data-form='". $sitepart_id."' data-section='".$field['section_id']."' data-next-section='".$option['next_section_id']."' readonly class='input_selection_text inputLinked_".$option['id']."' data-id='".$key."' id=\"input_collection_link_field_" . $field['id'] . "_value_" . $value . "\" placeholder= '".$option['linked_placeholder']."' type=\"text\" name=\"inputlinked_" . $field['id'] . "_".$option['id']."\" value='' >";
                                        echo '</div>';
                                    ?>
                                    
                                    <?php }
                                    echo '</div>';
                                }
                                $value++;
                            }
                            echo "</div>";
                            // break;   
            }
            $resultOpt = @mysqli_query($GLOBALS['mysql_con'], $queryOpt); 
            $is_end = 1;

            while ($option = @mysqli_fetch_array($resultOpt)) {
                if($option['next_section_id'] != NULL && $option['next_section_id'] != 0 ){
                    $is_end = 0;
                    break;
                }
            }
            ?>
            <div class="hiddenDiv div<?=$field['id']?>">
                <input type="hidden" name="next_section_<?=$sid;?>" id="next_section_<?=$sid;?>" value="<?= $is_end;?>">
            </div>

            <?php if (!empty($input_liner)) {
                echo "</div>";
            }
        }
    }

    // daten sammeln
    $query              = "SELECT * FROM contactform_header WHERE id = '" . $sitepart_id."'";
    $result             = @mysqli_query($GLOBALS['mysql_con'], $query);
    $contactform_header = @mysqli_fetch_array($result);

    if ($contactform_header['recaptcha_active'] == 1) {
        $websiteKey = $reCaptcha['websitekey'];
        $reCaptcha = TRUE;
    } else {
        $reCaptcha = FALSE;
    }

    ?>

    <div style="display:none;">
        <input type="text" name="input_captcha1" id="input_captcha1" value="" />
        <input type="text" name="input_captcha2" id="input_captcha2" value="<?= time() ?>" />
    </div>
    <? if ($reCaptcha == TRUE) { ?>

        <div class="recaptcha-class" style="float: left; padding-top: 0px;width:100%;">
            <div class="g-recaptcha" data-sitekey="<? echo $websiteKey; ?>"></div>
        </div>
        <br/>

    <? } 
}
function show_sitepart_content_contact($sitepart_id, $sitepart_header_id, $link_id = NULL, &$IOCContainer = null)
{
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts = \DynCom\mysyde\common\classes\Siteparts::get();
    $sitepartData = $allSiteparts[$sitepart_id];
    // container um das sitepart, daurch ansprechbar mit javascript
    
    $GLOBALS["navigation"]['sitepart_header_id'] = $sitepart_header_id;
    
    require_once(realpath(MODULE_PATH . $sitepartData['folder']) . DIRECTORY_SEPARATOR . $sitepartData['code'] . ".php");
    $function = '';
    $refFunc = '';
    try {
        
        //If the exception is thrown, this text will not be shown
        $function = $sitepartData['code'].'_show';
        $refFunc = new ReflectionFunction($function);
      }
      
      //catch exception
      catch(Exception $e) {
        echo 'ErrorMsg: ' .$e->getMessage();exit;
      }
   
    
    
   
    $noOfParams = $refFunc->getNumberOfParameters();
    $noOfReqParams = $refFunc->getNumberOfRequiredParameters();
    if ($sitepart_header_id > 0) {
        if ($noOfParams === 1) {
            $function($sitepart_header_id);
        } elseif ($noOfParams > 1) {
            $function($sitepart_header_id, $IOCContainer);
        }
    } elseif ($noOfReqParams === 0) {
        if ($noOfParams > 0 && isset($IOCContainer)) {
            $function($IOCContainer);
        } else {
            $function();
        }
    }
 
}
// Layout Area integration - 10. August 2009 MH
function get_contentContact($cid, $sectionID)
{
    
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts = \DynCom\mysyde\common\classes\Siteparts::get();
    


    if ($cid <= 0) {
        return;
    }

     

    
    $query  = "SELECT * FROM multi_contactform_link WHERE contact_form_id = " . (int)$cid . " AND main_section_link_parent_id = 0 AND main_section_id = ".$sectionID." AND active = 1 ORDER BY sorting ASC";
    
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    
                    
    if (@mysqli_num_rows($result) > 0) {
        while ($sitepart = @mysqli_fetch_array($result)) {
            if($sitepart['contactform_line_id'] > 0 && $sitepart['contactform_line_id'] != NULL){
                load_form_field($cid,$sitepart['contactform_line_id'], $sectionID );
                continue;
            }
            if ($sitepart['main_section_group'] == 1) {
                show_group_content($sitepart);
                continue;
            }
            $queryLine  = "SELECT * FROM multi_contactform_link INNER JOIN main_layout_class on multi_contactform_link.layout_area_id = main_layout_class.id   WHERE multi_contactform_link.id = '" . $sitepart['id'] . "' LIMIT 1";
                    $resultLine = @mysqli_query($GLOBALS['mysql_con'], $queryLine);
                    $input_liner = array();
                    $input_liner['layout_area_id'] = '';
                    if (@mysqli_num_rows($resultLine) == 1) {
                        $input_liner = @mysqli_fetch_array($resultLine);
                    } 
                //    echo '<pre> data'; print_r($sitepart);echo '</pre><br>';
            // layout klassen wrapper anzeigen
            

            if ($sitepart['main_sitepart_id'] > 0) {
                if (!empty($input_liner)) {
                    echo "<div class=\"" . $input_liner['code'] . " ".$input_liner['layout_class_defined']." " . $sitepart['layout_class_defined'] . "\">";
                }
                show_sitepart_content_contact($sitepart['main_sitepart_id'], $sitepart['main_sitepart_header_id'], $sitepart['id'], $IOCContainer);
                if (!empty($input_liner)) {
                       echo "</div>";
                 }
            } elseif ($sitepart['main_collection_setup_id'] > 0) {
                if (!empty($input_liner)) {
                    echo "<div class=\"" . $input_liner['code'] . " ".$input_liner['layout_class_defined']." " . $sitepart['layout_class_defined'] . "\">";
                }
                
                show_collection_setup_content($sitepart);
                if (!empty($input_liner)) {
                    echo "</div>";
                }
           
            }
 
            // layout klassenwrapper beenden
            // 
        }
    }
}
?>

<form  class="form-label-left regForm regForm<?=$sitepart_id; ?>" id="contactformular_<?= $sitepart_id ?>" method="post" action="<?= ml($tempSitepart, "action", "send") ?>" enctype="multipart/form-data">
                    <?
                    $querySteps = "SELECT cfst.id as stepID, cfst.name as stepName, cfst.class as stepClass , cfs.id as sectionID, cfs.name, cfs.class FROM contactform_steps as cfst INNER JOIN contactform_section as cfs on cfst.id = cfs.step_id WHERE cfst.contactform_id = ".$sitepart_id." ORDER BY cfst.sorting ASC, cfs.id ASC";
                    $resultStep = @mysqli_query($GLOBALS['mysql_con'], $querySteps);
                    $current = 0;
                   while($rowStep = @mysqli_fetch_array($resultStep)){ ?>
                        <div class="tab dataNumber<?= $current; ?> abschnitt_<?= $rowStep['sectionID']?>  <?=$rowStep['class']?>">
                            <?php
                             get_contentContact($sitepart_id, $rowStep['sectionID']); 
                            ?>
                        </div>
                        
                    <?  $current ++;} ?>
                    
                    
                    <div class="contact-button" id="submit_button">
                        <!-- <input type="submit" name="button" class="button" id="button" value="<?= $translation->get('send') ?>" />
                     -->
                            <div style="overflow:auto;">
                                <div style="float:right;">
                                <button type="button" class="prevBtn" data-form="<?= $sitepart_id;?>" data-id="-1" id="prevBtn" >Bisherige</button>
                                <button type="button" class="nextBtn" data-ende="0" data-form="<?= $sitepart_id;?>" id="nextBtn" >Nächste</button>
                                </div>
                            </div>
                            
                           
                            
                    </div>
                    
</form>
                     

                   
 

<script>
    $(document).ready(function (){
        console.log('ready');
       jQuery('body').addClass('multiFormPage');
    });
</script>              