<?php

// masked collection
function create_collection_input_field_masked($fieldSetup, $collection_setup_id, $fieldCount)
{
    
   
    //Übersetzung anzeigen
    $translation   = \DynCom\mysyde\common\classes\Registry::get("translation");
    
    //Pflichtfeld einblenden wenn vorhanden
    if (isset($fieldSetup['mandatory']) && $fieldSetup['mandatory'] != 0) {
        $mandatory = "<span class=\"mandatory\"> *</span>";
    }

    echo "<div class=\"collection_field\">";
    echo "<div class=\"label\"><label for=\"" . $fieldSetup['code'] . "\">" . $fieldSetup['fieldname'] . $mandatory . "</label></div>";
    echo "	<div class=\"input\">";
    //Hinweis einblenden wenn vorhanden
    if (isset($fieldSetup['note']) && $fieldSetup['note'] != '') {
        echo  "<div class=\"input_note\">" . $translation->get("note") . ": " . $fieldSetup['note'] . "</div>";
    }

    if ($fieldSetup['fieldtype'] == 'siteparts') {
       
        $siteparts = \DynCom\mysyde\common\classes\Siteparts::get();
         
        $sitepartConfig = $siteparts[$fieldSetup['type_id']];
        
        $headerData = get_sitepart_header_data(0, $fieldSetup['id']);
       
        // print_r(MODULE_PATH . $sitepartConfig['folder'] . "/collection_" . $sitepartConfig['code'] . "_line_listform.inc.php");
        require(MODULE_PATH . $sitepartConfig['folder'] . "/collection_" . $sitepartConfig['code'] . "_line_listform.inc.php");
        
         
    } else {
        
        // vorhandenen value auslesen
        $data = '';
        $linkText = '';
        $query = "SELECT data, linkText FROM main_collection_link WHERE main_collection_setup_content_id = " . $fieldSetup['id'] . " AND main_collection_id = " . 0;
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 1) {
            $row = @mysqli_fetch_array($result);
            $data = $row['data'];
            $linkText = $row['linkText'];
        }

        echo "<form id=\"form_collection_input_" . $fieldSetup['id'].'_count'.$fieldCount . "\" method=\"post\" name=\"form_collection_input_" . $fieldSetup['id'] .'_count'.$fieldCount. "\">";
        echo "<input type=\"hidden\" name=\"input_collection_hidden_info_" . $fieldSetup['id'].'_count'.$fieldCount . "\" value=\"" . $fieldSetup['type_id'] . "\" />";

        if ($fieldSetup['type_id'] != 2) {
            $input_maxlength = 255;
        }

        if (isset($fieldSetup['input_maxlength']) && $fieldSetup['input_maxlength'] != 0) {
            $input_maxlength = $fieldSetup['input_maxlength'];
        }
       
        switch ($fieldSetup['type_id']) {
            
            case 2: // textarea
                echo "<textarea id=\"input_collection_link_" . $fieldSetup['id']. '_count'.$fieldCount. "\" class=\"normal\" maxlength=\"" . $input_maxlength . "\" name=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\">" . $data . "</textarea>";
                break;

            case 3: // datumsfeld
                echo "<input id=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount. "\" class=\"code datepicker\" type=\"text\" value=\"" . $data . "\" maxlength=\"255\" name=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "\">";
                echo "<script type=\"text/javascript\">$('#input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "').datepicker();</script>";
                break;

            case 4: // link
                echo "<input id=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\" class=\"code\" type=\"text\" value=\"" . $data . "\" maxlength=\"255\" name=\"input_collection_link_" . $fieldSetup['id'] . "\">";
                echo "<div><div class='input_note'>Link Text </div><input id=\"input_collection_link_text_" . $fieldSetup['id'] .'_count'.$fieldCount. "\" class=\"code\" type=\"text\" value=\"" . $linkText . "\" maxlength=\"255\" name=\"input_collection_link_text_" . $fieldSetup['id'] . "\"></div>";
                break;

            case 5: // einzelnes bild
                if ($data != "") {
                    echo "<table cellpadding=\"0\" cellspacing=\"0\">";
                    echo "<tr><td>";
                    echo "<img src=\"" . PATH_ICON_COLLECTION . $data . "?time=" . time() . "\" /></td><td><input type=\"checkbox\" name=\"delete_collection_image_" . $fieldSetup['id'] . '_count'.$fieldCount."\" />&nbsp;Bild entfernen</td>";
                    echo "</tr>";
                    echo "</table>";
                }
                echo "<input id=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "\" class=\"code\" type=\"file\" name=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\">";
                break;

            case 6: // Dropdown
                echo "<select style=\"float:left;\" id=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "\" class=\"code\" type=\"text\" name=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\" >";
                //Get all option_values
                $options = explode(";", $fieldSetup["option_string"]);
                //Values als Integer
                $value = 0;
                $data = unserialize($data);
                foreach ($options as $option) {
                    $selected_text = ($data == $value) ? " selected=\"selected\"" : "";
                    echo "<option" . $selected_text . " value=\"" . $value . "\">" . $option . "</option>";
                    $value++;
                }
                echo "</select>";

                if ($fieldSetup['id'] == 38 || $fieldSetup['id'] == 45 || $fieldSetup['id'] == 57) {
                    echo "<div class=\"dropdownPreview\" data-image=\"" . $fieldSetup['id'] .'_count'.$fieldCount. "\" style=\"float:left\" >dsadas</div>";
                }
                break;

            case 7: // Checkbox

                echo "<label id=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "\" class=\"checkbox\" >";
                //Get all option_values
                $options = explode(";", $fieldSetup["option_string"]);
                //Values als Integer
                $value = 1;
                foreach ($options as $option) {
                    $selected_text = ($data == 1) ? " checked=\"checked\"" : "";
                    // $selected_text = ($data == $value) ? " checked=\"checked\"" : "";
                    echo "<div class=\"input_collection_link_checkbox\">";
                    echo "<input id=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "_value_" . $value . "\" type=\"checkbox\" name=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "[]\" value=val_\"$value\" ".$selected_text.">";
                    echo "<label " . "for=\"input_collection_link_" . $fieldSetup['id'] .'_count'.$fieldCount. "_value_" . $value . "\">" . $option . "</label>";
                    echo "</div>";
                    $value++;
                }
                echo "</label>";
                break;

            case 1: // normales inputfeld
            default:
                if($fieldSetup['id'] == 119 || $fieldSetup['id'] == 120){
                    create_collection_azubi_select($data, $fieldSetup['id']);
                }else if($fieldSetup['id'] == 283){
                    create_collection_person_select($data, $fieldSetup['id']);
                }else if($fieldSetup['id'] == 115){
                    create_select_from_collection($data, $fieldSetup['id'], 32);
                }else if($fieldSetup['id'] == 286){
                create_select_from_collection($data, $fieldSetup['id'], 31);
                }else {
                    echo "<input id=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\" class=\"code\" type=\"text\" value=\"" . htmlspecialchars($data) . "\" maxlength=\"" . $input_maxlength . "\" name=\"input_collection_link_" . $fieldSetup['id'] . '_count'.$fieldCount."\">";
                   
                }
                break;
        }
        echo "</form>";
    }

    echo "	</div>";
    echo "</div>";
}
?>