Fork me on GitHub

50212 bytes of PHP

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
<?php

class Main extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();
        $this->load->model('muser', '', true);
	}

	public function index()
	{
        $this->setPageTitle('Home');
        //$data = $this->addSystemParameters(array(), $this, $this->config, false);
        // AppUtils::deb($data, '$data::');
        //$this->showTwigTemplate('main.tpl', $data, false, false, false);
        $data= array();
        //$this->showTwigTemplate('empty', $data, false, false, false);
        //echo '<pre>Main index : '.print_r(1,true).'</pre>';
        $this->load->model('mhostel', '', true);
        $this->load->model('mhostel_review', '', true);
        $this->load->model('mhostel_room', '', true);
        $this->load->model('mregion', '', true);
        $this->load->model('mstate', '', true);
        $this->load->model('mcms_item', '', true);
        $this->load->model('mtour', '', true);
        $this->load->model('mtour_review', '', true);
        $this->load->model('mcategory', '', true);
        $config_array = $this->config->config;
        $A = $this->mhostel->getHostelsList(false, '', '', 'F', '', '', '', '', 'A', 'hostel.created_at', 'desc', '', '', true);
        $MaxElements= 4;
        if ( $MaxElements> count($A) ) $MaxElements= count($A);
        $hostels_indexes= array_rand($A, $MaxElements);
        $HostelsList= array();
        $orig_width = 145;
        $orig_height = 100;
        foreach($hostels_indexes as $hostel_index) {
            $filename_path = $A[$hostel_index]['default_image_path'];
            $FilenameInfo = AppUtils::GetImageShowSize($filename_path, $orig_width, $orig_height);
            $A[$hostel_index]['width']= $FilenameInfo['Width'];
            $A[$hostel_index]['height']= $FilenameInfo['Height'];
            $Hostel_Rooms= $this->mhostel_room->getHostel_RoomsList( false, '', '', $A[$hostel_index]['id'], '', '', '', '', '', '', false );
            $MinPrice= 0;
            foreach($Hostel_Rooms as $Hostel_Room) {
                if ( $Hostel_Room['price']> 0 and ( $Hostel_Room['price']< $MinPrice or $MinPrice == 0) ) {
                    $MinPrice= $Hostel_Room['price'];
                }
            }
            $A[$hostel_index]['price']= $MinPrice;
            $A[$hostel_index]['reviews_avg_rating']= (int)round($this->mhostel_review->getHostel_ReviewsAvgRating('',$A[$hostel_index]['id'], 'A' ), 0);

            $HostelsList[]= $A[$hostel_index];
        }
        $A = $this->mtour->getToursList( false, '', array( 'filter_feature'=>'F', 'filter_status'=>'A', 'show_default_image'=> 1 ), 'tour.created_at', 'desc' );
        if ( $MaxElements> count($A) ) $MaxElements= count($A);
        $tours_indexes= array_rand($A, $MaxElements);
        $ToursList= array();
        foreach($tours_indexes as $tour_index) {
            $filename_path = $A[$tour_index]['default_image_path'];
            $FilenameInfo = AppUtils::GetImageShowSize($filename_path, $orig_width, $orig_height);
            $A[$tour_index]['width']= $FilenameInfo['Width'];
            $A[$tour_index]['height']= $FilenameInfo['Height'];
            $A[$tour_index]['reviews_avg_rating']= (int)round($this->mtour_review->getTour_ReviewsAvgRating('',$A[$tour_index]['id'], 'A' ), 0);
            $ToursList[]= $A[$tour_index];
        }

        $RegionValueArray = $this->mregion->getRegionsSelectionList();
        $StateValueArray = $this->mstate->getStatesSelectionList();
        $create_a_listing_text = $this->mcms_item->getBodyContentByAlias('create_a_listing');
        $BlogArticlesList = $this->mcms_item->getCms_ItemsList(false, '', 'B', 'Y', '', '', '', 'cms_item.created_at', 'desc', '', false, true, 4);

        $orig_width = 245;
        $orig_height = 100;
        foreach ( $BlogArticlesList as $key=>$BlogArticle ) {
            $filename_path = $BlogArticle['default_image_path'];
            $FilenameInfo = AppUtils::GetImageShowSize($filename_path, $orig_width, $orig_height);
            $BlogArticlesList[$key]['width']= $FilenameInfo['Width'];
            $BlogArticlesList[$key]['height']= $FilenameInfo['Height'];
        }
        $CategorysList = $this->mcategory->getCategorysList(false);
//        echo '<pre>$CategorysList::'.print_r($CategorysList,true).'</pre>';
//        echo '<pre>$HostelsList::'.print_r($HostelsList,true).'</pre>';
//        echo '<pre>$ToursList::'.print_r($ToursList,true).'</pre>';
        //AppUtils::deb($HostelsList, '$HostelsList::');
        //AppUtils::deb($ToursList, '$ToursList::');
        AppUtils::deb($BlogArticlesList, '$BlogArticlesList::');

        $data = array('HostelsList' => $HostelsList, 'ToursList'=>$ToursList,  'RegionValueArray' => $RegionValueArray,
            'StateValueArray' => $StateValueArray, 'BlogArticlesList' => $BlogArticlesList,
            'CategorysList' => $CategorysList, 'create_a_listing_text' => $create_a_listing_text);
        $this->showTwigTemplate('main', $data, false, false, false);
	}

	public function invalid_url()
	{
		$config_array = $this->config->config;
		AppUtils::DebToFile( '-01 invalid_url::' ,false);
		$UriArray = $this->uri->uri_to_assoc(1);
		 $data = array('UriArray' => $UriArray);
		// AppUtils::DebToFile( '-02 $data::'.print_r($data,true) ,false);

		// public function showTwigTemplate( $template_name, $data, $config_object, $is_backend, $show_header_template= false, $show_footer_template= false ) {

		//$this->showTwigTemplate('invalid_url.tpl', $data, $this->config, false, false, false);
	}

	public function test()
	{
		$this->load->model('mcms_item', '', true);
		$UriArray = $this->uri->uri_to_assoc(1);
        $this->setPageTitle('Test page');
        $data = array( );
        $this->showTwigTemplate('test', $data, false, false, false);
    }
	public function cms_page()
	{
		$this->load->model('mcms_item', '', true);
		$UriArray = $this->uri->uri_to_assoc(1);
		$A= array_keys($UriArray);
		$PageKey= '';
		if ( !empty($A[0]) ) {
			$PageKey= $A[0];
		}
		$cms_item = $this->mcms_item->getRowByFieldName('alias', $PageKey, true);
		$cms_item_text = $this->mcms_item->getBodyContentByAlias($PageKey, array(), true);
		$cms_item_header = $this->mcms_item->getBodyContentByAlias($PageKey, array(), false);
        $this->setPageTitle('Content Editor');
        $data = array('cms_item' => $cms_item, 'cms_item_header' => $cms_item_header, 'cms_item_text' => $cms_item_text, 'cms_page' => $PageKey);
		$this->showTwigTemplate('cms_item_text.tpl', $data, $this->config, false, false, false);
	}

	public function get_cms_item_by_alias()
	{
		$this->load->model('mcms_item', '', true);
		$UriArray = $this->uri->uri_to_assoc(3);
		$cms_item = $this->mcms_item->getRowByFieldName('alias', $UriArray['alias'], true);
        $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 0, 'cms_item'=> $cms_item, 'content'=> $cms_item['content'] )));
	}


	public function insert_subscribe_to_newsletter()
	{
		//require_once 'application/libraries/mailchimp-api-class/MCAPI.class.php';
		//require_once 'application/libraries/mailchimp-api-class/config.inc.php'; //contains apikey

		$UriArray = $this->uri->uri_to_assoc(3);
		$post_array = $this->input->post();
		$user_email = urldecode(AppUtils::getParameter($this, $UriArray, $post_array, 'user_email'));
		$user_name = urldecode(AppUtils::getParameter($this, $UriArray, $post_array, 'user_name'));
        $this->output->set_content_type( 'application/json')->set_output(json_encode(array(  'ErrorMessage' => 'Test for "'.$user_name.'" for "'.($user_email).'" email!', 'ErrorCode' => 0 ) )  );
        return;
		//$api = new MCAPI($apikey);

		$merge_vars = array('FNAME'=>$user_name, 'LNAME'=>$user_name,
			/*'GROUPINGS'=>array(
				array('name'=>'Your Interests:', 'groups'=>'Bananas,Apples'),
				array('id'=>22, 'groups'=>'Trains'),
			) */
		);

		if ($api->errorCode){
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "Error adding subsriber to mailchimp.com, Code=".$api->errorCode . ", Msg=".$api->errorMessage, 'ErrorCode' => 1 )));
		} else {
			$this->output->set_content_type('application/json')->set_output(json_encode(array(  'ErrorMessage' => 'Subscribed - look for the confirmation email!', 'ErrorCode' => 0 )));
		}
	}

	public function send_contact_us()
	{
		$UriArray = $this->uri->uri_to_assoc(3);

		$config_array = $this->config->config;
		$post_array = $this->input->post();
		$name = urldecode(AppUtils::getParameter($this, $UriArray, $post_array, 'name'));
		$email = urldecode(AppUtils::getParameter($this, $UriArray, $post_array, 'email'));
		$message = urldecode(AppUtils::getParameter($this, $UriArray, $post_array, 'message'));

		$capture = AppUtils::getParameter($this, $UriArray, $post_array, 'capture');
		$blog_capture_word = trim($this->session->userdata('blog_capture_word'));
		$blog_capture_expired_time = $this->session->userdata('blog_capture_expired_time');
		if ($blog_capture_word != $capture or $blog_capture_expired_time < time()) {
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'Invalid Capture', 'ErrorCode' => 1, 'ErrorFieldName' => 'contact_us_capture')));
			return;
		}

		$Content = $name . '(' . $email . ')' . ' wrote : ' . $message;
		$EmailOutput = AppUtils::SendEmail($config_array['contact_us_email'], 'Contact Us Email', $Content, false, '');
		if (!empty($EmailOutput)) {
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => '', 'ErrorCode' => 0, 'EmailOutput' => $EmailOutput)));
			return;
		}
		$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'Invalid Parameters', 'ErrorCode' => 1, 'id' => 0)));
	}

	public function show_capture_image()
	{
		$this->load->helper('captcha');
		$UriArray = $this->uri->uri_to_assoc(3);
		$capture_prefix = AppUtils::getParameter($this, $UriArray, array(), 'capture_prefix', '');
		$random_string = AppUtils::PrepareRandomWord(); // 'Random';
		$vals = array(
			'word' => $random_string,
			'img_path' => './images/captcha/',
			'img_url' => $this->config->config['base_root_url'] . '/images/captcha/', //'http://example.com/captcha/',
			'font_path' => $this->config->config['ttf_file_path'],
			'img_width' => '120',
			'img_height' => 30,
			'expiration' => 7200
		);
		$capture_image = create_captcha($vals);
		$this->session->set_userdata(array( $capture_prefix . 'word' => $random_string, $capture_prefix . 'expired_time' => time() + $vals['expiration']));
		echo $capture_image['image'];
	}

	public function blog_view()
	{
		$this->load->model('mcms_item', '', true);
		$UriArray = $this->uri->uri_to_assoc(2);
		$cms_item = $this->mcms_item->getRowById($UriArray['id'], true);

		$post_array = array();
		$page = AppUtils::getParameter($this, $UriArray, $post_array, 'page', 1);
		$filter_page_type = 'B';
		$filter_published = 'Y';
		$filter_author_id = '';
		$filter_date_1 = '';
		$filter_date_2 = '';
		$sorting = AppUtils::getParameter($this, $UriArray, $post_array, 'sorting', 'cms_item.created_at');
		$sort = AppUtils::getParameter($this, $UriArray, $post_array, 'sort', 'desc');
		$RowsInTable = $this->mcms_item->getCms_ItemsList(true, '', $filter_page_type, $filter_published, $filter_author_id, AppUtils::ConvirtDateToMySqlFormat($filter_date_1),
			AppUtils::ConvirtDateToMySqlFormat($filter_date_2), $sorting, $sort);

		$this->load->library('pagination');
		$config_array = $this->config->config;
		$config_array['base_url'] = $this->config->base_url() . 'main/blog_view/' . $cms_item['alias'] . '/id/' . $cms_item['id'] . '/page';
		$config_array['total_rows'] = $RowsInTable;
		$this->pagination->initialize($config_array);

		$Cms_ItemsList = array();
		if ( $RowsInTable> 0 ) {
  		$Cms_ItemsList = $this->mcms_item->getCms_ItemsList(false, $page, $filter_page_type, $filter_published, $filter_author_id, AppUtils::ConvirtDateToMySqlFormat($filter_date_1),
			AppUtils::ConvirtDateToMySqlFormat($filter_date_2), $sorting, $sort, '', true, true);
		}

		$this->pagination->suffix = $this->PreparePageParameters($UriArray, $post_array, false, true);
		$pagination_links = $this->pagination->create_links();

		$orig_width = 245;
		$orig_height = 100;
	  $filename_path = $cms_item['default_image_path'];
		$FilenameInfo = AppUtils::GetImageShowSize($filename_path, $orig_width, $orig_height);
		$cms_item['width']= $FilenameInfo['OriginalWidth'];
		$cms_item['height']= $FilenameInfo['OriginalHeight'];

		$data = array('page' => $page, 'PageParametersWithSort' => '', 'cms_item' => $cms_item, 'RowsInTable' => $RowsInTable, 'Cms_ItemsList' => $Cms_ItemsList, 'pagination_links' => $pagination_links);
		$this->showTwigTemplate('blog_view.tpl', $data, $this->config, false, false, false);
	}


	private function PreparePageParameters($UriArray, $_post_array, $WithPage, $WithSort)
	{
		return '';
		$ResStr = '';
		if (!empty($_post_array)) { // form was submitted
			if ($WithPage) {
				$page = $this->input->post('page');
				$ResStr .= !empty($page) ? 'page/' . $page . '/' : 'page/1/';
			}
			$filter_page_type = $this->input->post('filter_page_type');
			$ResStr .= !empty($filter_page_type) ? 'filter_page_type/' . $filter_page_type . '/' : '';
			$filter_user_group = $this->input->post('filter_user_group');
			$ResStr .= !empty($filter_user_group) ? 'filter_user_group/' . $filter_user_group . '/' : '';
			if ($WithSort) {
				$sorting = $this->input->post('sorting');
				$ResStr .= !empty($sorting) ? 'sorting/' . $sorting . '/' : '';
				$sort = $this->input->post('sort');
				$ResStr .= !empty($sort) ? 'sort/' . $sort . '/' : '';
			}
		} else {
			if ($WithPage) {
				$ResStr .= !empty($UriArray['page']) ? 'page/' . $UriArray['page'] . '/' : 'page/1/';
			}
			$ResStr .= !empty($UriArray['filter_page_type']) ? 'filter_page_type/' . $UriArray['filter_page_type'] . '/' : '';
			$ResStr .= !empty($UriArray['filter_user_group']) ? 'filter_user_group/' . $UriArray['filter_user_group'] . '/' : '';
			if ($WithSort) {
				$ResStr .= !empty($UriArray['sorting']) ? 'sorting/' . $UriArray['sorting'] . '/' : '';
				$ResStr .= !empty($UriArray['sort']) ? 'sort/' . $UriArray['sort'] . '/' : '';
			}
		}
		if (substr($ResStr, strlen($ResStr) - 1, 1) == '/') {
			$ResStr = substr($ResStr, 0, strlen($ResStr) - 1);
		}
		return '/' . $ResStr;
	}

	public function register() {
		$this->load->model('mcms_item', '', true);
		$this->load->model('muser', '', true);
		$UriArray = $this->uri->uri_to_assoc(3);
		$register_content_text = $this->mcms_item->getBodyContentByAlias('register_content');
        if (!empty($_POST)) { // form was submitted
            echo '<pre>MAIN register $_POST::'.print_r($_POST,true).'</pre>';
            die("-1 ! register form was submitted");
        }

        $data = array( 'register_content_text' => $register_content_text);
		$this->showTwigTemplate('operator_register.tpl', $data, $this->config, false, false, false);

	}

	public function operator_register() {
		$this->load->model('muser', '', true);
		$UriArray = $this->uri->uri_to_assoc(3);
		$config_array = $this->config->config;
		$post_array = $this->input->post();

		$login = AppUtils::getParameter($this, $UriArray, array(), 'login', '');
		$email = AppUtils::getParameter($this, $UriArray, array(), 'email', '');
		$password = AppUtils::getParameter($this, $UriArray, array(), 'password', '');
		$first_name = AppUtils::getParameter($this, $UriArray, array(), 'first_name', '');
		$last_name = AppUtils::getParameter($this, $UriArray, array(), 'last_name', '');
		$phone = AppUtils::getParameter($this, $UriArray, array(), 'phone', '');
		$company = AppUtils::getParameter($this, $UriArray, array(), 'company', '');
		$capture = AppUtils::getParameter($this, $UriArray, $post_array, 'capture');

		$operator_register_word = trim($this->session->userdata('operator_register_word'));
		$operator_register_expired_time = $this->session->userdata('operator_register_expired_time');
		if ($operator_register_word != $capture or $operator_register_expired_time < time()) {
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'Invalid Capture !', 'ErrorCode' => 1, 'ErrorFieldName' => 'operator_register_capture')));
			return;
		}

		$lUser= $this->muser->getRowByFieldName( 'login', $login );
		if ( !empty($lUser) ) {
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'There is already registered user with this login ', 'ErrorCode' => 1,
				'login' => $login, 'ErrorFieldName' => 'operator_register_login' ) ) );
			return;
		}

		$lUser= $this->muser->getRowByFieldName( 'email', $email );
		if ( !empty($lUser) ) {
			$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'There is already registered user with this email ', 'ErrorCode' => 1,
				'login' => $login, 'ErrorFieldName' => 'operator_register_email' ) ) );
			return;
		}

		$OkResult = $this->muser->UpdateUser( '', Array( 'user_group'=>/*TODO*/'O', 'status'=>'A', 'login'=>$login, 'email'=>$email, 'password'=>md5($password),
			'first_name' => $first_name, 'last_name' => $last_name,	'company' => $company, 'phone' => $phone));
		if ( !$OkResult ) {
		  $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => 'Database error inserting new Operator ', 'ErrorCode' => 1,
			  'login' => $login ) ) );
		} else {
		  $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => '', 'ErrorCode' => 0,
			  'login' => $login ) ) );
		}

	}

	public function login() {   // http://local-tb.com/main/login
		$this->load->model('muser', '', true);
        $uriArray = $this->uri->uri_to_assoc(3);
        //echo '<pre>$uriArray::'.print_r($uriArray,true).'</pre>';
        if (!empty($_POST)) { // form was submitted
            //echo '<pre>MAIN login $_POST::'.print_r($_POST,true).'</pre>';
            $result= $this->ion_auth->login($_POST['username'],$_POST['password'] , !empty($_POST['remember']) );
            //echo '<pre>$result::'.print_r($result,true).'</pre>';
            if ( $result ) {
                $user = $this->ion_auth->user()->row();
                //echo '<pre>--11$user::'.print_r($user,true).'</pre>';
                $user_groups= $this->ion_auth->get_users_groups( $user->id )->result('array');
                //echo '<pre>$user_groups::'.print_r($user_groups,true).'</pre>';
                if ( !empty($user) and !empty($user_groups) ) {
                    $user_groups_name= '';
                    foreach( $user_groups as $next_user_group ) {
                        $user_groups_name.= $next_user_group['name'].', ';
                    }
                    //echo '<pre>!!!::'.print_r(AppUtils::getRightSubstring($user_groups_name, 2),true).'</pre>';
                    if ( AppUtils::getRightSubstring($user_groups_name, 2) == ', ' ){
                        //echo '<pre>INSIDE</pre>';
                        $user_groups_name= substr($user_groups_name,0,strlen($user_groups_name)-2 );
                    }
                    $user_data= array('is_logged' => 1, 'user_group' => 'Admin', 'logged_name' => $user->username, 'logged_user_id' => $user->id,
                        'last_login' => $user->last_login, 'admin_watch_operator_id' => -1, 'admin_watch_operator_login' => '', 'current_backend_template_name' => $user->backend_template_id, 'current_frontend_template_id' => $user->frontend_template_id, 'user_groups'=> $user_groups, 'user_groups_name'=> $user_groups_name);
                    // backend_template_id] => 4
                    echo '<pre>$user_data::'.print_r($user_data,true).'</pre>';
                    //die("-1 OK!");
                    $this->session->set_userdata($user_data);
                    redirect('admin/dashboard/index');
                }

            } else {
                redirect('main/login/type/warning/msg/' . urlencode ( 'Invalid login or password !').'/action/show-login' );

            }
            die("-1 ! form was submitted");
        }
        //echo '<pre>$this->config::'.print_r($this->config,true).'</pre>';
        //$data = $this->addSystemParameters(array(), $this, $this->config, false);
        // AppUtils::deb($data, '$data::');
        //$this->showTwigTemplate('main.tpl', $data, false, false, false);
        $this->showTwigTemplate('login', array(), false, false, false);

//		$UriArray = $this->uri->uri_to_assoc(3);
//
//		$config_array = $this->config->config;
//		$login = AppUtils::getParameter($this, $UriArray, array(), 'login', '');
//		$password = AppUtils::getParameter($this, $UriArray, array(), 'password', '');
//
//		$this->output->set_content_type('application/json')->set_output(  json_encode($ResArray)  );
	}

	public function logout() {   // http://local-tb.com/main/
		$this->load->model('muser', '', true);
        echo '<pre>MAIN logout $_POST::'.print_r($_POST,true).'</pre>';
//            die("-1 ! form was submitted");
        $this->ion_auth->logout();
        $this->session->unset_userdata(  array('is_logged' => false, 'user_group' => '', 'logged_name' => 'guest', 'logged_user_id' => -1, 'last_login' => '',                'admin_watch_operator_id' => -1, 'admin_watch_operator_login' => '', 'current_backend_template_name' => '' ,  'current_frontend_template_name' => '')  );
        redirect('main/msg/type/info/msg/' . urlencode ( 'You logged from system !').'/action/show-login' );
	}

	public function get_subregions_list_by_region_id() {
		$this->load->model('msubregion', '', true);
		$UriArray = $this->uri->uri_to_assoc(3);
		$region_id = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'region-id') );
		$current_subregion_id = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'current-subregion-id') );
		// current_subregion_id
		$format = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'format', 'html') );
		$SubregionsList= $this->msubregion->getSubregionsList( false, '', $region_id );
		$html= '<option value="">Select an Area</option>';
		foreach( $SubregionsList as $Subregion ) {
			if ( $format== 'html' )
				$html.= '<option value="'.$Subregion['id'].'"  '.($current_subregion_id==$Subregion['id']?" selected ":"").' >'.$Subregion['name'].'</option>';
		}
		$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => '', 'ErrorCode' => 0, 'html'=> $html ) ) );
	}

	public function get_regions_list_by_state_id() {
		$this->load->model('mregion', '', true);
		$UriArray = $this->uri->uri_to_assoc(3);
		$state_id = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'state-id') );
		$current_region_id = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'current-region-id') );
        //if (empty($current_region_id)) $current_region_id= 24;
		$format = urldecode( AppUtils::getParameter($this, $UriArray, array(), 'format', 'html') );
		$RegionsList= $this->mregion->getRegionsList( false, '', $state_id );
		$html= '<option value="">Select a Region</option>';
		foreach( $RegionsList as $Region ) {
			if ( $format== 'html' )
				$html.= '<option value="'.$Region['id'].'"  '.($current_region_id==$Region['id']?" selected ":"").'  >'.$Region['name'].'</option>';
		}
		$this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => '', 'ErrorCode' => 0, 'html'=> $html ) ) );
	}

  // http://local-tb.com/index.php/main/msg/info/You+logged+from+system

    public function msg() {
        $uriArray = $this->uri->uri_to_assoc(3);
        $data = $uriArray;
        //echo '<pre>!!$data::'.print_r($data,true).'</pre>';
        $this->showTwigTemplate('msg', $data, false, false, false);
    }


    public function calendar()
    {
        $this->setPageTitle('Calendar');
        $this->load->model('mstate', '', true);
        $this->load->model('mfacility', '', true);
        $facilitysList = $this->mfacility->getFacilitysList(false, '', '', '', '', '');
        //echo '<pre>get_last_day_of_month::'.print_r(AppUtils::get_last_day_of_month(),true).'</pre>';
        $current_year= (int)strftime("%Y");
        $current_month= (int)strftime("%m") - 1;
        $data= array();
        $StatesList = $this->mstate->getStatesList(false, '', '', '', 'state.name', '', 'state.id, state.name');
         $data = array('StatesList' => $StatesList, 'facilitysList'=> $facilitysList, 'current_year'=> $current_year, 'current_month'=> $current_month);
        $this->showTwigTemplate('calendar/choose_calendar', $data, false, false, false);

    }

    public function get_selected_item_info()
    { // var HRef = "{{ base_url }}main/get_selected_item_info/hostel_id/"+hostel_id+"/filter_facilitys/"+filter_facilitys
        $this->load->model('mhostel', '', true);
        $UriArray = $this->uri->uri_to_assoc(3);
        $hostel_id = AppUtils::getParameter($this, $UriArray, array(), 'hostel_id' );
        $hostel= $this->mhostel->getRowById($hostel_id);
        if (empty($hostel)) {
            $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "Hostel not found", 'ErrorCode' => 1)));
            return;
        }
        $images_list = $this->mhostel->get_images_list( $hostel_id, false, $hostel['feature']);
        $images_count= count($images_list);
        $html= AppUtils::concatArray( array('<b>'.$hostel['name'].'</b>', $hostel['postal_code'], $hostel['town'], $hostel['street_addr'], $hostel['phone'], $hostel['email'], ( $images_count> 0 ? ' has ' . count($images_list).' image(s)' : '' ) ), ', ', true );
        $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 0, 'html'=> $html, 'images_count'=> $images_count, 'hostel'=> $hostel )));

    }

    public function load_calendar_hostel_inqueries()
    { //  var HRef = "{{ base_url }}main/load_calendar_hostel_inqueries/hostel_id/"+hostel_id+"/filter_facilitys/"+filter_facilitys
        $this->load->model('mhostel_inquery', '', true);
        $this->load->model('mhostel', '', true);
        $this->load->model('mhostel_facility', '', true);
        $UriArray = $this->uri->uri_to_assoc(3);
//        $cms_item = $this->mcms_item->getRowByFieldName('alias', $UriArray['alias'], true);

        $filter_user_id= '';
        $filter_status= 'N';
        $filter_request_callback= '';
        //$filter_hostel_id= '1'; //
        $filter_hostel_id = AppUtils::getParameter($this, $UriArray, array(), 'hostel_id' );
        if ($filter_hostel_id=='-') $filter_hostel_id= '';
        //AppUtils::deb($filter_hostel_id, '$filter_hostel_id::');

        $filter_calendar_month = AppUtils::getParameter($this, $UriArray, array(), 'calendar_month' );
        if ($filter_calendar_month=='-') $filter_calendar_month= '';     // 'start_date']) and !empty($ExtendedFilters['end_date']
        AppUtils::deb($filter_calendar_month, '$filter_calendar_month::');

        $filter_calendar_year = AppUtils::getParameter($this, $UriArray, array(), 'calendar_year' );
        if ($filter_calendar_year=='-') $filter_calendar_year= '';     // 'start_date']) and !empty($ExtendedFilters['end_date']
        AppUtils::deb($filter_calendar_year, '$filter_calendar_year::');

        echo '<pre>get_last_day_of_month::'.print_r(AppUtils::get_last_day_of_month(),true).'</pre>';
        $start_date= $filter_calendar_year.'-'.$filter_calendar_month.'-01 00:00:00'; ///2013-10-07 07:51:02
        $end_date= $filter_calendar_year.'-'.$filter_calendar_month.'-'.AppUtils::get_last_day_of_month().' 00:00:00'; ///2013-10-07 07:51:02
        $sorting= '';
        $sort= '';
        $fields_for_select= '';
        $show_related_count= '';

        // if ( !empty($ExtendedFilters['start_date']) and !empty($ExtendedFilters['end_date']) ) {

        $filter_filter_facilitys = AppUtils::getParameter($this, $UriArray, array(), 'filter_facilitys' );
        if ($filter_filter_facilitys=='-') $filter_filter_facilitys= '';
        $filter_filter_facilitys_array = AppUtils::preg_split( '/,/', $filter_filter_facilitys );
        //AppUtils::deb($filter_filter_facilitys_array, '$filter_filter_facilitys_array::');

        //     public function getHostel_InquerysList($OutputFormatCount = false, $page = '', $filter_user_id = '', $filter_hostel_id = '', $filter_request_callback = '', $filter_status = '', $sorting = '', $sort = '', $fields_for_select = '', $show_related_count= false, $ExtendedFilters = array()) {

        $ret_array= array();
        $Operator_Hostel_InquerysList = $this->mhostel_inquery->getHostel_InquerysList(false, '', $filter_user_id, $filter_hostel_id, $filter_request_callback, $filter_status, $sorting, $sort, $fields_for_select, $show_related_count, array( 'start_date'=> $start_date, 'end_date'=> $end_date) );
        // $Operator_Hostel_InquerysList = $this->mhostel_inquery->getHostel_InquerysList(false, '', '', '', '', '', ''); // run ALL for uploading
        echo '<pre>$Operator_Hostel_InquerysList::'.print_r($Operator_Hostel_InquerysList,true).'</pre>';
        die("-1 XXZ");
        foreach( $Operator_Hostel_InquerysList as $next_Operator_Hostel_Inquery ) {
            //$start_date= strftime( '%Y-%m-%d', strtotime(  (' - '.rand(1,90)) . ' days ') );

//            $next_Operator_Hostel_Inquery['start_date']= '2016-05-18 08:00:00';
//            $next_Operator_Hostel_Inquery['end_date']= '2016-05-19 08:00:00';
//            $start_date= $next_Operator_Hostel_Inquery['start_date'];
//            AppUtils::deb($next_Operator_Hostel_Inquery, '++$next_Operator_Hostel_Inquery::');
//            AppUtils::deb($start_date, '++$start_date::');
            $hostel= $this->mhostel->getRowById($next_Operator_Hostel_Inquery['hostel_id']);
            $HostelFacilitiesList = $this->mhostel_facility->getHostel_FacilitysList(false, $next_Operator_Hostel_Inquery['hostel_id']);

            //echo '<pre>$HostelFacilitiesList::'.print_r($HostelFacilitiesList,true).'</pre>';
            $hostel_facility_label= '';
            foreach( $HostelFacilitiesList as $next_hostel_facility ) {
                $hostel_facility_label.= $next_hostel_facility['facility_name'].', ';
            }
            if ( substr($hostel_facility_label,strlen($hostel_facility_label)-2,2) == ', ' ) {
                $hostel_facility_label = substr($hostel_facility_label, 0, strlen($hostel_facility_label) - 2);
            }
            if (empty($hostel)) continue;


            $start_date= round( strtotime($next_Operator_Hostel_Inquery['start_date']) * 1000);
            $end_date= round( strtotime($next_Operator_Hostel_Inquery['end_date']) * 1000);
            $hostel_inquery_class= 'event-info';
            if ( $next_Operator_Hostel_Inquery['request_callback'] == 'Y' ) {
                $hostel_inquery_class= 'event-special';   // event-important, event-success, event-warning, event-info, event-inverse and event-special.
            }
            $ret_array[]= array( "id" => $next_Operator_Hostel_Inquery['id'], "title"=> $next_Operator_Hostel_Inquery['id'] .' : ' . $hostel['name'].' : '. $next_Operator_Hostel_Inquery['hostel_id'] . '  '."\r\n".'Facilities:'.$hostel_facility_label.' '."\r\n".' '.AppUtils::ConcatStr($next_Operator_Hostel_Inquery['extro_info']) . "\r\n During:" . strftime( '%B %d, %Y %H:%M%p',strtotime($next_Operator_Hostel_Inquery['start_date']) ) .' - '.strftime( '%B %d, %Y %H:%M%p' ,strtotime($next_Operator_Hostel_Inquery['end_date']) ),
                "url"=> $this->config->base_url() .'hostels/hostel_show_inquery/id/'. $next_Operator_Hostel_Inquery['id'], "class"=> $hostel_inquery_class, "start"=> $start_date,  "end"=> $end_date );

//            $request_callback= 'N';
//            if ( rand(0,3) == 2 ) $request_callback= 'Y';
//
//            $hours= rand(0,23);
//            $minutes= rand(0,1)*30;
//            $start_date= strftime( '%Y-%m-%d %H:', strtotime(  (' - '.rand(1,30)) . ' days ' . ' + '.$hours.' hours  ') ).$minutes.':00';
//            //echo '<pre>start_date::'.print_r($start_date,true).'</pre>';
//
//
//            $hours= rand(0,23);
//            $minutes= rand(0,1)*30;
//            $end_date= strftime( '%Y-%m-%d %H:', strtotime(' + '.(rand(1,30)).' days '. ' + '.$hours.' hours  ')).$minutes.':00';
//            //echo '<pre>end_date::'.print_r($end_date,true).'</pre>';
//            $this->mhostel_inquery->UpdateHostel_Inquery( $next_Operator_Hostel_Inquery['id'], array('start_date'=> $start_date, 'end_date'=>$end_date, 'extro_info'=> $hostel['name'].' extro info text...'.AppUtils::loremIpsumText(), 'request_callback'=> $request_callback) );
            //die("-1 XXZ");

        }

//        $start_time= strtotime( '2016-05-03' );
//        $start_time_milliseconds = round($start_time * 1000);
//        $end_time= strtotime('2016-05-12');
//        $end_time_milliseconds = round($end_time * 1000);
//
//        $ret_array= array( array( "id" => 293, "title"=> "Event 1", "url"=> "http://example.com", "class"=> "event-important",
//            "start"=> $start_time_milliseconds, /* Milliseconds */  "end"=> $end_time_milliseconds /* Milliseconds */
//        ));

        $this->output->set_content_type('application/json')->set_output(json_encode(array('success' => 1, 'result' => $ret_array )));
    }

    //
    public function add_hostel_inquery() {
        $this->load->model('mhostel_inquery', '', true);
        $this->load->model('mhostel', '', true);
        $this->load->model('mhostel_facility', '', true);

    }
    public function get_calendar_data_day()
    {
        $this->load->model('mhostel', '', true);
        $this->load->model('muser', '', true);
        $this->load->model('mhostel_inquery', '', true);
        $UriArray = $this->uri->uri_to_assoc(3);
        $config_array = $this->config->config;           // data_day/"+encodeURIComponent(data_day)+"/event_id

        $post_array = $this->input->post();
        $data_day = AppUtils::getParameter($this, $UriArray, $post_array, 'data_day');
        $event_id = AppUtils::getParameter($this, $UriArray, $post_array, 'event_id');
        $hostel_id= AppUtils::getParameter($this, $UriArray, $post_array, 'hostel_id');

        $Hostel_InquerysList = $this->mhostel_inquery->getHostel_InquerysList(false, '', '', $hostel_id, 'Y', 'N', 'start_date', 'asc', '', false, array('start_date'=>$data_day, 'end_date'=>$data_day) );

        //echo '<pre>'.count($Hostel_InquerysList).'::$Hostel_InquerysList::'.print_r($Hostel_InquerysList,true).'</pre>';
        $calendar_data_array= array();          // ConcatStr($Str, $MaxLength = '', $AddStr = '...', $ShowHelp = false, $StripTags = true)
        foreach( $Hostel_InquerysList as $next_Hostel_Inquery ) {
            $calendar_data_array[]= array( 'type'=>'Hostel', 'id'=>$next_Hostel_Inquery['id'], 'hostel_id'=>$next_Hostel_Inquery['hostel_id'], 'email'=>$next_Hostel_Inquery['email'], 'full_name'=>$next_Hostel_Inquery['full_name'], 'phone'=>$next_Hostel_Inquery['phone'], 'extro_info'=>AppUtils::ConcatStr($next_Hostel_Inquery['extro_info'], '', '...', true), 'start_date'=>$next_Hostel_Inquery['start_date'], 'end_date'=>$next_Hostel_Inquery['end_date'], 'created_at'=>$next_Hostel_Inquery['created_at'] );
        }
        $data = array( 'calendar_data_array'=>$calendar_data_array, 'data_day'=>$data_day );
        $this->showTwigTemplate('calendar/get_calendar_data_day', $data, false, false, false);
        //$this->output->set_content_type('application/json')->set_output(json_encode(array(  'ErrorMessage' => '', 'ErrorCode' => 0, 'calendar_data_array'=>$calendar_data_array, 'data_day'=>$data_day )));

    } //public function get_calendar_data_day()


    public function set_request_callback_status()
    {
        $this->load->model('mhostel', '', true);
        $this->load->model('muser', '', true);
        $this->load->model('mhostel_inquery', '', true);
        $UriArray = $this->uri->uri_to_assoc(3);    // type/"+encodeURIComponent(type)+"/id/" + encodeURIComponent(id)
        $config_array = $this->config->config;

        $post_array = $this->input->post();
        $type = AppUtils::getParameter($this, $UriArray, $post_array, 'type');
        $id = AppUtils::getParameter($this, $UriArray, $post_array, 'id');
        if ( strtolower($type) == 'hostel' ) {
            $hostel= $this->mhostel_inquery->getRowById($id);
            if (empty($hostel)) {
                $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "Hostel not found", 'ErrorCode' => 1)));
                return;
            }
            $this->mhostel_inquery->UpdateHostel_Inquery( $id, array('request_callback'=> 'N') );

            $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 0, 'id'=> $id )));
            return;
        }
        $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "Invalid Parameters", 'ErrorCode' => 1 )));
    } //public function set_request_callback_status()




    public function get_hostels_treeview_data( )
    {

        $this->load->model('mregion', '', true);
        $this->load->model('mstate', '', true);
        $this->load->model('msubregion', '', true);
        $this->load->model('mhostel', '', true);

        $UriArray = $this->uri->uri_to_assoc(3);
        //echo '<pre>$UriArray::'.print_r($UriArray,true).'</pre>';
        $format = AppUtils::getParameter($this, $UriArray, array(), 'format');
        AppUtils::deb($UriArray, '$UriArray::');
        $filter_facilitys = AppUtils::getParameter($this, $UriArray, array(), 'filter_facilitys');
        AppUtils::deb($filter_facilitys, 'filter_facilitys::');
        $only_with_items = AppUtils::getParameter($this, $UriArray, array(), 'only_with_items');
        //echo '<pre>$only_with_items::'.print_r($only_with_items,true).'</pre>';
        AppUtils::deb($only_with_items, 'only_with_items::');

        AppUtils::deb($format, '$format::');
        // preg_split($splitter, $string_items, $skip_empty= true)
        $filter_state_id = AppUtils::getParameter($this, $UriArray, array(), 'state-id' );
        if ($filter_state_id=='-') $filter_state_id= '';
        $filter_state_id_array = AppUtils::preg_split( '/,/', $filter_state_id );
        AppUtils::deb($filter_state_id_array, '$filter_state_id_array::');

        $filter_hostel_id = AppUtils::getParameter($this, $UriArray, array(), 'hostel-id' );
        if ($filter_hostel_id=='-') $filter_hostel_id= '';
        AppUtils::deb($filter_hostel_id, '$filter_hostel_id::');

        $filter_region_id = AppUtils::getParameter($this, $UriArray, array(), 'region-id' );
        if ($filter_region_id=='-') $filter_region_id= '';
        AppUtils::deb($filter_region_id, '$filter_region_id::');

        $filter_subregion_id = AppUtils::getParameter($this, $UriArray, array(), 'subregion-id' );
        if ($filter_subregion_id=='-') $filter_subregion_id= '';
        AppUtils::deb($filter_subregion_id, '$filter_subregion_id::');

        $sorting = AppUtils::getParameter($this, $UriArray, array(), 'sorting' );
        $sort = AppUtils::getParameter($this, $UriArray, array(), 'sort' );


/*             var HRef = "{{ base_url }}main/get_hostels_treeview_data/hostel-id/"+encodeURIComponent(hostel_id)+"state-id/" + encodeURIComponent(state_id) + "/region-id/"+region_id+"/subregion-id/"+subregion_id+"/filter_facilitys/" + encodeURIComponent(filter_facilitys) + "/format/html";
 */
//        $filter_state_id_array= array(1,2);

        $ret_array= array();
        $show_label= 1;
        //$only_with_items= true;
        foreach( $filter_state_id_array as $next_state_id ) {
            $nextState= $this->mstate->getRowById( $next_state_id );
            if ( empty($nextState) ) continue;

            $RegionsList = $this->mregion->getRegionsList(false, '', $next_state_id);
            $hostels_in_region_count= 0;
            //echo '<pre>$RegionsList::'.print_r($RegionsList,true).'</pre>';
            //die("-1 XXZ");
            $regions_array = array();
            foreach ($RegionsList as $nextRegion) {

                if ( !empty($filter_region_id) and (int)$nextRegion['id'] != (int)$filter_region_id) continue;
                //  getSubregionsList( $OutputFormatCount = false, $page = '',  $filter_region_id = '',$filter_state_id = '', $filter_name = '', $sorting = '', $sort = '', $show_related_count= false) {
                $SubregionsList = $this->msubregion->getSubregionsList(false, '', $nextRegion['id'], $next_state_id );
                $subregions_array = array();
                foreach ($SubregionsList as $nextSubregion) {      //$filter_hostel_id
                    if ( !empty($filter_subregion_id) and (int)$nextSubregion['id'] != (int)$filter_subregion_id) continue;
                    $HostelsList = $this->mhostel->getHostelsList(false, '', '', '', '', $next_state_id, $nextRegion['id'], $nextSubregion['id'], 'A', $sorting, $sort, '',  0, '', '', array('id'=> $filter_hostel_id));
                    $hostels_array = array();
                    foreach ($HostelsList as $next_Hostel) {
                        $images_list = $this->mhostel->get_images_list( $next_Hostel['id'], false, $next_Hostel['feature']);
                        $hostels_array[] = array('hostel_id' => $next_Hostel['id'], 'hostel_name' => ( $show_label ? ' Hostel : ':' ' ).$next_Hostel['id'] . ', ' . $next_Hostel['name'] . ', ' . $next_Hostel['town'] . ', ' . $next_Hostel['street_addr'], 'images_count'=>  count($images_list));
                    }


                    if (!$only_with_items or count($hostels_array) > 0) {
                        $subregions_array[] = array('subregion_id' => $nextSubregion['id'], 'subregion_name' => ($show_label ? ' Subregion : ' : ' ') . $nextSubregion['name'], 'hostels_array' => $hostels_array);
                        $hostels_in_region_count+= count($hostels_array);
                    }
                    //}


                } // foreach ($SubregionsList as $nextSubregion) {
                if ( $hostels_in_region_count > 0 ) {
                    $regions_array[] = array('region_id' => $nextRegion['id'], 'region_name' => ($show_label ? ' Region : ' : ' ') . $nextRegion['name'], 'subregions_array' => $subregions_array);
                }
            } // foreach ($RegionsList as $nextRegion) {

            $ret_array[] = array('state_id' => $nextState['id'], 'state_name' => ( $show_label ? ' State : ':' ' ) . $nextState['name'], 'regions_array' => $regions_array);

        } // foreach( $filter_state_id_array as $next_state_id ) {

        //echo '<pre>'.count($ret_array).'::$ret_array::'.print_r($ret_array,true).'</pre>';
        //die("-1 XXZ");
        if ($format=='html') {
            $ret_html= '     <div class="easy-tree">
        <ul>';  // common treeview
            foreach ($ret_array as $next_state) {
                if ( empty($next_state['state_id']) ) continue;
                $ret_html.= '            <li assign_class="glyphicon glyphicon-inbox" id="li_state_'.$next_state['state_id'].'">'.$next_state['state_name'].'</li>'; // next state item
                if ( is_array($next_state['regions_array']) and count($next_state['regions_array']) > 0 ) {
                    $ret_html.= '                <ul>'; // block of regions start
                    foreach( $next_state['regions_array'] as $next_region ) {
                        $ret_html.= '                    <li assign_class="glyphicon glyphicon-road" id="li_region_'.$next_region['region_id'].'">'.$next_region['region_name'].'</li>'; // next region item
                        if ( is_array($next_region['subregions_array']) and count($next_region['subregions_array']) > 0 ) {
                            $ret_html.= '                <ul>'; // block of subregions start
                            foreach( $next_region['subregions_array'] as $next_subregion ) {
                                $ret_html.= '                            <li assign_class="glyphicon glyphicon-chevron-down" id="li_subregion_'.$next_subregion['subregion_id'].'">'.$next_subregion['subregion_name'].'</li>'; // next subregion item

                                if ( is_array($next_subregion['hostels_array']) and count($next_subregion['hostels_array']) > 0 ) {
                                    $ret_html .= '                <ul>'; // block of hostels start
                                    foreach( $next_subregion['hostels_array'] as $next_hostel ) {
                                        $ret_html .= '                    <li assign_class="glyphicon glyphicon-home state_'.$next_state['state_id'].' region_'.$next_region['region_id'].' subregion_'.$next_subregion['subregion_id'].' hostel_' . $next_hostel['hostel_id'] ."  images_count_".$next_hostel['images_count'] . '"  id="li_hostel_' . $next_hostel['hostel_id'] . '">' . $next_hostel['hostel_name'] . '. ' . $next_hostel['images_count'] .' images'. '</li>'; // next hostel item
                                    }
                                    $ret_html .= '                </ul>'; // block of hostels end
                                }
                            }
                            $ret_html.= '                </ul>'; // block of subregions end
                        }
                    }
                    $ret_html.= '                </ul>';  // block of regions end
                }
            }

            $ret_html.= '
        </ul>
    </div>';    // common treeview
            //echo '<pre>$ret_html::'.print_r($ret_html,true).'</pre>';
            $this->output->set_content_type('application/json')->set_output( json_encode( array( 'ErrorMessage' => "", 'ErrorCode' => 0, 'ret_array'=> $ret_array, 'ret_html'=> $ret_html ) )  );
            return;
        } // if ($format=='html') {
        $this->output->set_content_type('application/json')->set_output( json_encode( array( 'ErrorMessage' => "", 'ErrorCode' => 0, 'ret_array'=> $ret_array, 'format'=> $format ) )  );
    } // public function get_hostels_treeview_data()

    public function get_images_carousel()
    {
        $this->load->model('mhostel', '', true);
        $UriArray = $this->uri->uri_to_assoc(3); //type/hostel/id/" + encodeURIComponent(current_hostel_id)
        $type = AppUtils::getParameter($this, $UriArray, array(), 'type');
        //AppUtils::deb($UriArray, '$UriArray::');
        $id = AppUtils::getParameter($this, $UriArray, array(), 'id');
        //AppUtils::deb($id, 'id::');
        if ( $type == 'hostel' ) {
            $title= 'Hostel Images';
            // private function get_images_list($hostel_id, $skip_first_image = true, $feature)
            $hostel= $this->mhostel->getRowById($id);
            if (empty($hostel)) {
                $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 1, 'items_count' => 0, 'html' => 'Hostel not found !', 'title' => $title)));
                return;
            }

            ob_start();
            $ret_data = $this->mhostel->get_images_list($id, false, $hostel['feature'], true);
            if ( empty($ret_data['items']) or empty($ret_data['max_width']) or empty($ret_data['max_height']) ) {
                $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 1, 'items_count' => 0, 'html' => 'Invalid data !', 'title' => $title)));
                return;

            }
            $images_list= $ret_data['items'];
            $max_width= $ret_data['max_width'];
            $max_height= $ret_data['max_height'];
            //AppUtils::deb($images_list, '$images_list::');
            $data = array( 'images_list'=>$images_list, 'type'=>$type, 'title'=>$title, 'max_width'=>$max_width, 'max_height'=> $max_height );
            //echo '<pre>'.count($data).'::$data::'.print_r($data,true).'</pre>';
            $html= $this->showTwigTemplate('calendar/carousel_images_list', $data, false, false, false);

            //$html = ob_get_contents();
            //echo '<pre>$html::'.print_r(htmlspecialchars($html),true).'</pre>';
            ob_end_clean();
            $this->output->set_content_type('application/json')->set_output(json_encode(array('ErrorMessage' => "", 'ErrorCode' => 0, 'items_count'=> 2, 'html'=> $html, 'title'=> $title )) );
            return;
        }
    }

    public function code_highlight()
    {
        $this->load->model('mcms_item', '', true);
        $UriArray = $this->uri->uri_to_assoc(1);
        //echo '<pre>$UriArray::'.print_r($UriArray,true).'</pre>';
        //     [page] => application/views/plain/calendar/choose_calendar.twig
        $data = array( );
        if ( empty($_REQUEST['page']) ) {
            //echo '<pre>_Z1</pre>';
            $data = array( 'page' => $_REQUEST['page'], 'code_to_highlight'=> 'No filename specifies');
        } else {
            // echo '<pre>_Z2</pre>';
            $file_path= FCPATH.$_REQUEST['page'];
            //echo '<pre>$file_path::'.print_r($file_path,true).'</pre>';
            if ( !file_exists($file_path) ) {
                //echo '<pre>_Z3</pre>';
                $data = array( 'page' => $_REQUEST['page'], 'code_to_highlight' => 'file ' . $file_path .' not found');
            } else {
                //echo '<pre>_Z300</pre>';
                //echo '<pre>WW$file_path::'.print_r($file_path,true).'</pre>';
                $file_content= AppUtils::readFileAsText($file_path);
                //echo '<pre>::'.print_r($file_content,true).'</pre>';
                $data = array( 'file_path' => $file_path, 'code_to_highlight' => '[code language=php]'.$file_content.'
'); } } //echo '
_Z4
'; //echo '
$_REQUEST::'.print_r($_REQUEST,true).'
'; //AppUtils::deb($data, '$data::'); $this->setPageTitle('Code Highlight page'); $this->showTwigTemplate('code_highlight_page', $data, false, false, false); } }[/code]