<?php
/**
 * @package     Joomla OrdaSoft ССK
 * @copyright   OrdaSoft Copyright (C)
 */


defined('_JEXEC') or die;

/**
 * HTML Article View class for the Content component
 *
 * @since  1.5
 */
class Os_CCKViewAll_instance extends JViewLegacy
{
	protected $item;
	protected $params;
	protected $print;
	protected $state;
	protected $user;

	/**
	 * Execute and display a template script.
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
    global $db;

    $db = new os_cckDb();
    $app        = JFactory::getApplication();
    $input      = $app->input;
    $Itemid = $input->get('Itemid', 0, 'INT');

    $event_date = ($input->get('event_date', '') && $input->get('event_date', '') != '')?$input->get('event_date', ''):false;
    $event_date_field = ($input->get('event_date_field', '') && $input->get('event_date_field', '') != '')?$input->get('event_date_field', ''):false;

    $menu = new JTableMenu($db->_db);
    $menu->load($Itemid);
    $params = new JRegistry;

    if($menu->params){
      $params->loadString($menu->params);
    }
    $lid = $params->get('all_instance_layout');

    if(!$lid){
      $lid = $params->get('layout');
    }
    if($lid){
      $layout = new os_cckLayout($db->_db);
      $layout->load($lid);
      if($layout->type != 'all_instance'){
        $lid = false;
      }
    }
    if($event_date && $event_date_field){
      $lid = intval($input->get('lid', 0, 'INT'));
    }
    if(!$lid){
        $lid = intval(protectInjectionWithoutQuote('lid'));
    }
    Instance::show_all_instance($input->get('option'), $lid);

	}

}
