<?php
defined('_JEXEC') or die('Restricted access');

/**
* @package OS CCK
* @copyright 2020 OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru),Roman Akoev (akoevroman@gmail.com)
* @link http://ordasoft.com/cck-content-construction-kit-for-joomla.html
* @description OrdaSoft Content Construction Kit
*/



$fName = $field->db_field_name;

$icon_alias_prefix = (isset($field_from_params[$fName.'_add_icon_alias_prefix'])) ? $field_from_params[$fName.'_add_icon_alias_prefix'] : '';
if($icon_alias_prefix != ''){
    $layout_html = str_replace($field->db_field_name.'_label_icon_prefix_hidden', 'fa '.$icon_alias_prefix, $layout_html);
}
$icon_alias_suffix = (isset($field_from_params[$fName.'_add_icon_alias_suffix'])) ? $field_from_params[$fName.'_add_icon_alias_suffix'] : '';
if($icon_alias_suffix != ''){
    $layout_html = str_replace($field->db_field_name.'_label_icon_suffix_hidden', 'fa '.$icon_alias_suffix, $layout_html);
}

$fParams['type'] = isset($layout_params['fields']['search_'.$fName])?$layout_params['fields']['search_'.$fName]:'';

if($fParams['type'] == 3){
    
    if($field->fk_eid != $layout->fk_eid){
        $parent_field = new os_cckEntityField($db->_db);
        $parent_field->load($field->fid);
//        var_dump($parent_field);
        $search_db_field_name = $parent_field->db_field_name;
    }else{
        $search_db_field_name = $fName;
    }
    $options = getTextfieldOptons($field->fk_eid, $search_db_field_name);
    $arr = array();
    $arr[] = JHTML::_('select.option', 'all', cck_lang_text('COM_OS_CCK_PLEASE_SELECT_OPTION'), "value", "text");
    foreach ($options as $opt){
        if(!$opt) continue;
        $arr[] = JHTML::_('select.option', $opt, $opt, "value", "text");
    }
    $required = '';
    if(isset($layout_params['fields'][$fName.'_required']) && $layout_params['fields'][$fName.'_required']=='on')
        $required = ' required ';
    $select_type = '';
    $tag_name = "os_cck_search_".$fName;
    $key = 'value';
    $text = 'text';
    
    
    $select_type_value = isset($layout_params['fields']['select_type_'.$fName]) ? $layout_params['fields']['select_type_'.$fName] : 1;
    
    if($select_type_value > 1){
      $arr[0]->disable = TRUE;
      $select_type  = 'multiple="multiple" size="'.$select_type_value.'"';
    }

}

?><span <?php if(isset($layout_params['fields']['description_'.$fName]) && $layout_params['fields']['description_'.$fName]=='on' && !empty($layout_params['fields'][$fName.'_tooltip']))
        {?>
rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo $layout_params['fields'][$fName.'_tooltip'];?>"
    <?php } ?> ><?php

if($fParams['type'] == 1){?>
    <input <?php echo $field_styling?> class="<?php echo $custom_class?>" <?php echo $offset_animation; ?> type="checkbox" name="os_cck_search_<?php echo $fName?>" checked="checked" value="on">
    <?php
} elseif($fParams['type'] == 2){?>
    <input <?php echo $field_styling?> class="<?php echo $custom_class?>" <?php echo $offset_animation; ?> type="hidden" name="os_cck_search_<?php echo $fName?>" value="on">
    <?php
}elseif($fParams['type'] == 3){?>
    
    <?php
    echo JHTML::_('select.genericlist', $arr, $tag_name. '[]', $field_styling.' class="'.$custom_class.$required.'"'.$select_type . ' ' . $offset_animation, $key, $text, 'all');
}

?></span>