Location: PHPKode > scripts > Purple Beanie Web Booking For Joomla > com_pbbooking/admin/controllers/treatment.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 PbbookingsControllertreatment 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_treatments";
		$db =& JFactory::getDBO();
		$db->setQuery( $sql );
		$treatments = $db->loadAssocList();
		JRequest::setVar('treatments',$treatments);
		JRequest::setVar( 'view', 'treatment' );
		JRequest::setVar( 'layout', 'default'  );
		
			$db =& JFactory::getDBO();

			$query = "SELECT path from #__pbbooking_cals where in_cal=1";
			$db->setQuery($query);
			$cals = $db->loadResultArray();

			$calprobs = 0;
			foreach($cals as $test) {
				if (file_exists($test)) {
				} else {
					$calprobs = 1;
				}
			}

			if ($calprobs == 0) {
				parent::display();
			} else {
				$this->setMessage( JText::sprintf( 'It appears your calendars are not configured correctly
					please ensure this configuration is fixed first.', $n ) );
				$this->setRedirect( 'index.php?option=com_pbbooking&controller=calendar&task=display' );
			}
    }

	function edit()
	{
	    JRequest::setVar( 'view', 'treatment' );
	    JRequest::setVar( 'layout', 'form'  );
	    JRequest::setVar('hidemainmenu', 1);
		
		$cid = JRequest::getVar('cid');
		if ($cid) {
			$sql = "select * from #__pbbooking_treatments where id = ".$cid[0];
			$db =& JFactory::getDBO();
			$db->setQuery( $sql );
			$treatments = $db->loadAssocList();
			JRequest::setVar('treatment',$treatments[0]);
		} else {
			$treatment = Array("name"=>"Treatment Name","duration"=>60,"price"=>75,"id"=>0);
			JRequest::setVar('treatment',$treatment);
		}

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

}
Return current item: Purple Beanie Web Booking For Joomla