Location: PHPKode > scripts > Purple Beanie Web Booking For Joomla > com_pbbooking/admin/controllers/calendar.php
<?php
/**
 * @package    PurpleBeanie.PBBooking
 * @subpackage Components
 * @link http://www.purplebeanie.com
 * @license    GNU/GPL
 */
 
// No direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport('joomla.application.component.controller');
 
/**
 * PBBooking Component Controller
 *
 * @package    PurpleBeanie.PBBooking
 * @subpackage Components
 */

class PbbookingsControllercalendar extends JController
{
	
	function __construct()
	{
	    parent::__construct();

	    // Register Extra tasks
	    $this->registerTask( 'add'  ,     'edit' );
	}
	
    /**
     * Method to display the view
     *
     * @access    public
     */
    function display()
    {	
		$sql = "select * from #__pbbooking_cals";
		$db =& JFactory::getDBO();
		$db->setQuery( $sql );
		$cals = $db->loadAssocList();
		JRequest::setVar('cals',$cals);
		JRequest::setVar( 'view', 'calendar' );
		JRequest::setVar( 'layout', 'default'  );
        parent::display();
    }

	function edit()
	{
	    JRequest::setVar( 'view', 'calendar' );
	    JRequest::setVar( 'layout', 'form'  );
	    JRequest::setVar('hidemainmenu', 1);
		
		$cid = JRequest::getVar('cid');
		if ($cid) {
			$sql = "select * from #__pbbooking_cals where id = ".$cid[0];
			$db =& JFactory::getDBO();
			$db->setQuery( $sql );
			$cals = $db->loadAssocList();
			JRequest::setVar('calendar',$cals[0]);
		} else {
			$calendar = Array("path"=>"/path/to/calendar","in_cal"=>1,"out_cal"=>0,"id"=>0);
			JRequest::setVar('calendar',$calendar);
		}

	    parent::display();
	}
	
	function save() 
	{
		$path = JRequest::getVar('path');
		$in_cal = JRequest::getVar('in_cal');
		$out_cal = JRequest::getVar('out_cal');
		$id = JRequest::getVar('id');
		
		if ($id !=0) {
			$sql = sprintf("update #__pbbooking_cals set path = '%s',in_cal=%s,out_cal=%s where id = %s",
				$path,$in_cal,$out_cal,$id);
		} else {
			$sql = sprintf("insert into #__pbbooking_cals (path,in_cal,out_cal) values ('%s',%s,%s)",
				$path,$in_cal,$out_cal);
		}
		$db =& JFactory::getDBO();
		$db->setQuery( $sql );
		$db->Execute($sql);
		$this->setRedirect( 'index.php?option=com_pbbooking&controller=calendar', null );
		
	}
	
	function remove()
	{
		$ids = JRequest::getVar('cid');
		foreach ($ids as $id) 
		{
			$sql = sprintf("delete from #__pbbooking_cals where id = %s",$id);
			//echo $sql;
			$db =& JFactory::getDBO();
			$db->setQuery($sql);
			$db->Execute($sql);
		}
		$this->setRedirect( 'index.php?option=com_pbbooking&controller=calendar', null );
	}
	

}
Return current item: Purple Beanie Web Booking For Joomla