<?php

/**
 * @version    CVS: 1.0.0
 * @package    Com_Mmap
 * @author     David <davidgeorgespam@gmail.com>
 * @copyright  2017 David
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access
defined('_JEXEC') or die;

/**
 * Mmap controller class.
 *
 * @since  1.6
 */
class MmapControllerFunc extends JControllerLegacy
{
    public function fullSetup() {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');
        
            $model->createTableStructre(); 
            $result = $model->setUserEntries();
            $model->setPtEntries();
            $result = $model->setMedicationEntries(); 
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    public function survey() {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');
        
            $model->setSurveyEntries(55);
            $result = $model->setSurveyEntries(57);
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    public function users() {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');
        
            $result = $model->setUserEntries();
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    
    
    
    
    public function meds() {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');
        
        
       // $result = $model->getVisits();
        
            $result = $model->setMedicationId(); 
            
            print_r($result); 
		
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
        
    }
    
    
    
    public function comments() {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Compare', 'MmapModel');
        
        
       // $result = $model->getVisits();
        
            $result = $model->selectComments(); 
            
            print_r($result); 
		
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
        
    }
    
    
    
    
    
    
    /** 
    public function populate () {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');
        
        
       // $result = $model->getVisits();
        
            $result = $model->setPtEntries(); 
            
            print_r($result); 
		
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    
    
    public function setvisit () {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');

            $result = $model->setVisitNumber();
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    public function setmed () {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');

            $result = $model->setMedicationEntries();
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    
    
    public function clean () {
        try {
        
        // Initialise variables.
		$app = JFactory::getApplication();

		// Checking if the user can remove object
		$user = JFactory::getUser();

		if (!$user->authorise('core.admin', 'com_mmap')) {
			throw new Exception('Not Authorised', 403); 
		}
		    $model = $this->getModel('Func', 'MmapModel');

            $result = $model->cleanPtEntry(); 
            
		    echo new JResponseJson($result);
        } catch(Exception $e) {
            echo new JResponseJson($e);
        }
        $app->close(); 
    }
    
    */
}