<?php 
/**
* @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
*/

defined('_JEXEC') or die;
$doc = JFactory::getDocument();
// $doc->addStyleSheet(JURI::root() . "components/com_os_cck/assets/css/jquerOs-ui.min.css");
// $doc->addScript(JURI::root() . 'components/com_os_cck/assets/js/jquery.raty.js');

// $doc->addScript(JURI::root() . "components/com_os_cck/assets/js/jquerOs-ui.min.js");

// $key = 'key='.$os_cck_configuration->get("google_map_key",'');
// $doc->addScript('//maps.googleapis.com/maps/api/js?'.$key);
// $doc->addStyleSheet(JURI::root() . "components/com_os_cck/assets/css/jquery.cck_timepicker.css");
// $doc->addScript(JURI::root() . "components/com_os_cck/assets/js/jquery.cck_timepicker.js");
// $doc->addStyleSheet(JUri::root() . "/components/com_os_cck/assets/css/fine-uploader-new.css");
// $doc->addScript(JURI::root() . "/components/com_os_cck/assets/js/fine-uploader.js");
// JHtml::_('jquery.framework');
$hidden = '';

$gtree = get_group_children_tree_cck();
$access = ($entityInstance->access != '') ? explode(',', $entityInstance->access) : '1';

$robots_option[]  = JHTML::_('select.option','0','Use Global');
$robots_option[]  = JHTML::_('select.option','1','Index, Follow');
$robots_option[]  = JHTML::_('select.option','2','No index, follow');
$robots_option[]  = JHTML::_('select.option','3','Index, No follow');
$robots_option[]  = JHTML::_('select.option','4','No index, no follow');

if (version_compare(JVERSION, "3.7.0", "ge")) {
    $install_lang = JLanguageHelper::getKnownLanguages();
}else{
    $install_lang = JLanguage::getKnownLanguages();
}
    
$lang_list = array();
$instanse_lang_list = array();
$lang_list[] = JHTML::_('select.option','*','All');
foreach($install_lang as $key => $item){
    $lang_list[] = JHTML::_('select.option',$key,$item['name']);
    $lang_instancies = $entityInstance->getInstanciesListLang($key);
    
    if(!empty($lang_instancies)){
        $instanse_lang_list[$key] = array();
        $instanse_lang_list[$key][] = JHTML::_('select.option','',cck_lang_text('COM_OS_CCK_ADMIN_PLEASE_SEL'));
        foreach($lang_instancies as $inst){
            if($inst->title == ''){
                $temp_inst = new os_cckEntityInstance($db->_db);
                $temp_inst->load($inst->eiid);
                $inst->title = getInstanceTitle($temp_inst);
            }
            $instanse_lang_list[$key][] = JHTML::_('select.option',$inst->eiid,$inst->title);
        }
    }
}

if($entityInstance->associate_instances){
    $assoc_list = unserialize($entityInstance->associate_instances);
}else{
    $assoc_list = array();
}


if(!$entityInstance->language){
    $lang_select = $layout->language;
}else{
    $lang_select = $entityInstance->language;
}
$lang_list = JHTML::_('select.genericlist',$lang_list, 'language', 'size="1" class="inputbox"', 'value', 'text', $lang_select);


?>
<script>
    var checkExpr = [];
</script>
<?php

$form_name = 'adminForm';
$form_id = 'adminForm' ;
$table = new os_cckViewTable($form_name, $form_id, '', 'index.php?option=com_os_cck&task=show_instance', 'show_instance');

$what_check = 'fields' ;
$table->create_button('Save & Close', 'save_instance', '', 'fa-save','',$what_check);
$table->create_button('Apply', 'apply_instance', '', 'fa-save','',$what_check);
$table->create_button('Cancel', 'cancel_instance', '', 'fa-close', '', "false");

?>
<!-- tabs -->
<?php
    $layout_html = '';
    ob_start();
    $layout->getEditInstanceLayoutViews($layout, $layout_params, $entityInstance, $option, $robots_option, 'adminForm','', $lang_list, $instanse_lang_list, $assoc_list);
    $layout_html = ob_get_contents();
    //ob_end_flush();
    ob_end_clean();

  $table->set_custom_html($layout_html);
  echo $table->viewTable();
?>



<script language="javascript" type="text/javascript">
  window.addEventListener('load', function() {
      jQuerOs(document).ready(function() {
        jQuerOs("[make='disabled']").attr('disabled','disabled');
        jQuerOs(['id^=cck_col']).removeClass('resizable');
        jQuerOs('.ui-resizable-handle').remove();
      });


      showHideAssocInstance();
      jQuerOs('#language').on('change', showHideAssocInstance);
    })
    
    function swich_task(task){
      if(task == 'save_instance' || task == 'send_request'){
        document.getElementById('inst_task').value = 'save_instance';
      }
      if(task == 'edit_instance'){
        document.getElementById('inst_task').value = 'edit_instance';
      }
      if(task == 'new_instance'){
        document.getElementById('inst_task').value = 'new_instance';
      }
      
      if(task == 'cancel_instance'){
        document.getElementById('inst_task').value = 'cancel_instance';
      }
    }
    
    function lay_type_select() {
      document.forms["adminForm"].submit();;
      return;
    }
    
    function showHideAssocInstance(){
      var val = jQuerOs('#language').val();
      if(val == '*'){
          jQuerOs('.assoc_instancce').hide();
      }else{
          jQuerOs('.assoc_instancce').each(function (index, value){
              if(jQuerOs(value).hasClass(val)){
                  jQuerOs(value).hide();
              }else{
                  jQuerOs(value).show();
              }
              
          })

      }

      jQuerOs('input[name=featured_clicks], input[name=featured_shows]').on('input',function(){
        var value = jQuerOs(this).val()
        if(value > 2147483647){
          jQuerOs(this).val(2147483647)
        }
        
      })
    }
    

</script>
<!--************************   end change review ***********************-->
