<?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;

$description_show = (isset($fields_from_params['description_'.$fName])) ? 'checked="true"' : '';
$field_tooltip = (isset($fields_from_params[$fName.'_tooltip'])) ? $fields_from_params[$fName.'_tooltip'] : '';
$field_prefix = (isset($fields_from_params[$fName.'_prefix'])) ? $fields_from_params[$fName.'_prefix'] : '';
$field_suffix = (isset($fields_from_params[$fName.'_suffix'])) ? $fields_from_params[$fName.'_suffix'] : '';

$image_width = (isset($fields_from_params[$fName]['width'])) ? $fields_from_params[$fName]['width'] : '50';
$image_height = (isset($fields_from_params[$fName]['height'])) ? $fields_from_params[$fName]['height'] : '50';
$field_php_show = (isset($fields_from_params[$fName.'_php_show'])) ? $fields_from_params[$fName.'_php_show'] : '';

$gtree = get_group_children_tree_cck();
$access_selected = (isset($fields_from_params['access_'.$fName])) ? $fields_from_params['access_'.$fName] : '1';

$icon_prefix_prefix = (isset($fields_from_params[$fName.'_add_icon_prefix_prefix'])) ? $fields_from_params[$fName.'_add_icon_prefix_prefix'] : '';
$icon_prefix_suffix = (isset($fields_from_params[$fName.'_add_icon_prefix_suffix'])) ? $fields_from_params[$fName.'_add_icon_prefix_suffix'] : '';
$icon_suffix_prefix = (isset($fields_from_params[$fName.'_add_icon_suffix_prefix'])) ? $fields_from_params[$fName.'_add_icon_suffix_prefix'] : '';
$icon_suffix_suffix = (isset($fields_from_params[$fName.'_add_icon_suffix_suffix'])) ? $fields_from_params[$fName.'_add_icon_suffix_suffix'] : '';

$categoryLayoutSelected = (isset($fields_from_params[$fName.'_category_layout'])) ? $fields_from_params[$fName.'_category_layout'] : '-1';
$layouts_for_link_options = get_options_for_layout_select_list('category', $entity->eid, $layout->lid, $layout->language);

$def_img = (isset($fields_from_params[$fName.'_def_img'])) ? $fields_from_params[$fName.'_def_img'] : '';
$def_img = os_cck_HTML::imageList('fi_' . $fName . '_def_img', $def_img);

$cck_image_object_fit  = (isset($lParams['cck_image_object_fit_'.$fName])) ? $lParams['cck_image_object_fit_'.$fName] : "cover";
$cck_object_fit_type[] =  JHTML::_('select.option','cover','cover');
$cck_object_fit_type[] =  JHTML::_('select.option','contain','contain');
?>
<div id="options-field-<?php echo $fName?>">
    <div>
      <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_SHOW_DESCRIPTION")?></label>
      <input type="checkbox" data-field-name="<?php echo $fName?>" name="fi_description_<?php echo $fName?>" <?php echo $description_show?>>
    </div>
    <div>
      <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_TOOLTIP")?></label>
      <input type="text" size="4" name="fi_<?php echo $fName?>_tooltip"  value="<?php echo $field_tooltip?>" >
    </div>
    <div class="prefix_wrap">
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_PREFIX")?></label>
        <div class="fa <?php echo $icon_prefix_prefix; ?> add_font_awesom" id="<?php echo $fName;?>_add_icon_prefix_prefix" rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo cck_lang_text("COM_OS_CCK_TOOLTIP_ADD_ICON");?>"><?php echo ($icon_prefix_prefix == '') ? '&#10000;' : ''; ?></div>
        <input type="hidden" name="fi_<?php echo $fName; ?>_add_icon_prefix_prefix" value="<?php echo $icon_prefix_prefix; ?>">
        <input type="text" size="4" name="fi_<?php echo $fName?>_prefix"  value="<?php echo $field_prefix?>" >
        <div class="fa <?php echo $icon_prefix_suffix; ?> add_font_awesom" id="<?php echo $fName;?>_add_icon_prefix_suffix" rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo cck_lang_text("COM_OS_CCK_TOOLTIP_ADD_ICON");?>"><?php echo ($icon_prefix_suffix == '') ? '&#10000;' : ''; ?></div>
        <input type="hidden" name="fi_<?php echo $fName; ?>_add_icon_prefix_suffix" value="<?php echo $icon_prefix_suffix; ?>">
    </div>
    <div class="suffix_wrap">
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_SUFFIX")?></label>
        <div class="fa <?php echo $icon_suffix_prefix; ?> add_font_awesom" id="<?php echo $fName;?>_add_icon_suffix_prefix" rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo cck_lang_text("COM_OS_CCK_TOOLTIP_ADD_ICON");?>"><?php echo ($icon_suffix_prefix == '') ? '&#10000;' : ''; ?></div>
        <input type="hidden" name="fi_<?php echo $fName; ?>_add_icon_suffix_prefix" value="<?php echo $icon_suffix_prefix; ?>">
        <input type="text" size="4" name="fi_<?php echo $fName?>_suffix"  value="<?php echo $field_suffix?>" >
        <div class="fa <?php echo $icon_suffix_suffix; ?> add_font_awesom" id="<?php echo $fName;?>_add_icon_suffix_suffix" rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo cck_lang_text("COM_OS_CCK_TOOLTIP_ADD_ICON");?>"><?php echo ($icon_suffix_suffix == '') ? '&#10000;' : ''; ?></div>
        <input type="hidden" name="fi_<?php echo $fName; ?>_add_icon_suffix_suffix" value="<?php echo $icon_suffix_suffix; ?>">
    </div>
    
    <span class="clearfix" ></span>
    <div>
        <label><?php echo cck_lang_text("COM_OS_CCK_CATEGORY_UNIQUE_FIELD_CAT_IMAGE_WIDTH")?></label>
        <input type="text" size="4" name="fi_<?php echo $fName?>[width]"  value="<?php echo $image_width?>" > px
    </div>
    <div>
        <label><?php echo cck_lang_text("COM_OS_CCK_CATEGORY_UNIQUE_FIELD_CAT_IMAGE_HEIGHT")?></label>
        <input type="text" size="4" name="fi_<?php echo $fName?>[height]"  value="<?php echo $image_height?>" > px
    </div>
    <div>
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_IMAGE_TYPE")?></label>
        <?php echo JHTML::_('select.genericlist',$cck_object_fit_type, 'fi_cck_image_object_fit_'.$fName,
                    'size="1" class="inputbox" ', 'value', 'text', $cck_image_object_fit);?>
    </div>
    <div>
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_FIELD_DEFAULT_IMG")?><i title="<?php echo cck_lang_text("COM_OS_CCK_LOAD_DEFAULT_IMAGE")?>" class="glyphicon glyphicon-info-sign date_tooltip"></i></label>
        <?php
          
              echo $def_img;
          
        ?>
    <script language="javascript" type="text/javascript">
    window.addEventListener('load', function() {    
        window.getOsSelectedValue = function ( frmName, srcListName ) {
//		console.warn('window.getSelectedValue() is deprecated without a replacement!');

		var srcList = document[ frmName ][ srcListName ],
		    i = srcList.selectedIndex;

		if ( i !== null && i > -1 ) {
			return srcList.options[ i ].value;
		} else {
			return null;
		}
	};
        
        function hide_img(){

          var selVal = document.getElementById('fi_<?php echo $fName; ?>_def_img');

          if (selVal.options[selVal.selectedIndex].value != ''){
              jsimg='<?php echo JURI::ROOT(); ?>images/os-cck/' + getOsSelectedValue( 'adminForm', 'fi_<?php echo $fName; ?>_def_img' );
              jQuerOs('#imagelib_<?php echo $fName; ?>').css("display", "block");
              jQuerOs('#imagelib_<?php echo $fName; ?>').css("max-height", "100px");
              jQuerOs('#imagelib_<?php echo $fName; ?>').css("max-width", "100px");
              jQuerOs('#imagelib_<?php echo $fName; ?>').css("margin-left", "3px");
              jQuerOs('#imagelib_<?php echo $fName; ?>').css("object-fit", "cover");
          }
          else{
              //jQuerOs('#imagelib').hide();
              jsimg='<?php echo JURI::ROOT(); ?>components/com_os_cck/images/blank.png';

              jQuerOs('#imagelib_<?php echo $fName; ?>').css("display", "none");
          }
        }

        hide_img();

        jQuerOs('#fi_<?php echo $fName; ?>_def_img').change(function(event) {
          hide_img();
        });


        jQuerOs('#fi_<?php echo $fName; ?>_def_img').parent().append('<img src=' + jsimg + ' name="imagelib_fi_<?php echo $fName; ?>_def_img" id="imagelib_<?php echo $fName; ?>"  '+
                                                         'border="2" alt="<?php echo cck_lang_text('COM_OS_CCK_CATEGORIES_IMAGEPREVIEW');?>" />');
    //    
        function height_img(){
            var selVal = document.getElementById('fi_<?php echo $fName; ?>_def_img');
            //console.log('222222222222', selVal);
            if (selVal != null && selVal.options[selVal.selectedIndex].value != ''){
                jQuerOs('#imagelib_<?php echo $fName; ?>').css("display", "block");
                jQuerOs('#imagelib_<?php echo $fName; ?>').css("max-height", "100px");
                jQuerOs('#imagelib_<?php echo $fName; ?>').css("max-width", "100px");
                jQuerOs('#imagelib_<?php echo $fName; ?>').css("margin-left", "3px");
                jQuerOs('#imagelib_<?php echo $fName; ?>').css("object-fit", "cover");
            }
        }
        height_img();
    
    })                               
    </script> 
    </div>
    <div>
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_LAYOUT_FOR_REDIRECT")?></label>
        <?php echo JHTML::_('select.genericlist',$layouts_for_link_options, 'fi_' . $fName . '_category_layout',
                                        'size="1" class="inputbox" ', 'value', 'text',$categoryLayoutSelected);?>
    </div>
    
    <div class="php_show">
        <label><?php echo cck_lang_text("COM_OS_CCK_LABEL_PHP_SHOW")?> <i title="<?php echo cck_lang_text("COM_OS_CCK_LABEL_PHP_SHOW_DESC")?>" class="glyphicon glyphicon-info-sign date_tooltip"></i></label>
        <!-- <input id="add-field-mask-php-show" class="new-mask" type="button" aria-invalid="false" value="+field"> -->
        <span class="editor-button">Editor</span>
        <textarea class="php-show-editor" rows="5" cols="30" name="fi_<?php echo $fName?>_php_show"><?php echo $field_php_show?></textarea>
    </div>  
    <?php if(isset($cck_entity_configuration[$layout->fk_eid]['check_access_fields']) && $cck_entity_configuration[$layout->fk_eid]['check_access_fields'] == '1'){ 
        $attr = array (
            'list.attr' => ' multiple="true" ',
            'id' => 'fi_access_'.$fName,
            'list.select' => $access_selected,
            'group.items' => null,
            'option.key.toHtml' => false,
            'option.text.toHtml' => false
        );
        ?>
    <div>
        <label class="access-label"><?php echo cck_lang_text("COM_OS_CCK_LABEL_FIELD_ACCESS")?></label>
        <?php //echo JHTML::_('select.genericlist', $gtree, 'fi_access_'.$fName.'[]', 'multiple="true"','value', 'text',$access_selected);
        echo JHTML::_('select.groupedlist',$gtree,'fi_access_'.$fName.'[]', $attr);?>
    </div>
    <?php } ?>
</div>
