<?php
/*----------------------------------------------------------------------------------|  www.vdm.io  |----/
				fdsh 
/-------------------------------------------------------------------------------------------------------/

	@version		1.0.39
	@build			4th April, 2023
	@created		17th December, 2020
	@package		Reservation
	@subpackage		ajax.php
	@author			farhad shahbazi <http://farhad.com>	
	@copyright		Copyright (C) 2015. All Rights Reserved
	@license		GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
  ____  _____  _____  __  __  __      __       ___  _____  __  __  ____  _____  _  _  ____  _  _  ____ 
 (_  _)(  _  )(  _  )(  \/  )(  )    /__\     / __)(  _  )(  \/  )(  _ \(  _  )( \( )( ___)( \( )(_  _)
.-_)(   )(_)(  )(_)(  )    (  )(__  /(__)\   ( (__  )(_)(  )    (  )___/ )(_)(  )  (  )__)  )  (   )(  
\____) (_____)(_____)(_/\/\_)(____)(__)(__)   \___)(_____)(_/\/\_)(__)  (_____)(_)\_)(____)(_)\_) (__) 

/------------------------------------------------------------------------------------------------------*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

use Joomla\Utilities\ArrayHelper;

/**
 * Reservation Ajax Model
 */
class ReservationModelAjax extends JModelList
{
	protected $app_params;
	
	public function __construct() 
	{		
		parent::__construct();		
		// get params
		$this->app_params	= JComponentHelper::getParams('com_reservation');
		
	}

	// Used in bbbclass

/***[JCBGUI.admin_view.php_ajaxmethod.144.$$$$]***/
  public function setWebHook($url, $secret)
  {
    require_once dirname(dirname(__FILE__)) . '/bbb/autoload.php';
    $bbb = new BigBlueButton\BigBlueButton($url, $secret);
    $methods = get_class_methods($bbb);
    // $hooksList = array();
    // $hresponse = $bbb->hooksList();
    // $registered = false;
    // if ($hresponse->getReturnCode() == 'SUCCESS') {
      // foreach ($hresponse->getHooks() as $hook) {
        // if(JURI::root().'administrator/components/com_reservation/helpers/webhook.php')
        // {
          // $registered = true;
          // break;
        // }
      // }
    // }

    // $meetings = array();
    // $response = $bbb->getMeetings();
    // if ($response->getReturnCode() == 'SUCCESS') {
      // foreach ($response->getRawXml()->meetings->meeting as $meeting) {
      	// $meetings[] = $meeting;
      // }
    // }
    // print_r($hresponse->getRawXml(), True)
    $hookURL = JURI::root().'administrator/components/com_reservation/helpers/webhook.php';
    $hp = new BigBlueButton\Parameters\HooksCreateParameters($hookURL);
    $hcresponse = $bbb->hooksCreate($hp);
    return array('status' => ($hcresponse->getReturnCode() == 'SUCCESS'));
  }
  public function isRegistered($url, $secret)
  {
    require_once dirname(dirname(__FILE__)) . '/bbb/autoload.php';
    $bbb = new BigBlueButton\BigBlueButton($url, $secret);
    $hresponse = $bbb->hooksList();
    $registered = false;
    $hookURL = JURI::root().'administrator/components/com_reservation/helpers/webhook.php';
    if ($hresponse->getReturnCode() == 'SUCCESS') {
      foreach ($hresponse->getHooks() as $hook) {
        if($hookURL == $hook->getCallbackUrl())
        {
          $registered = true;
          break;
        }
      }
    }
    return array('status' => $registered);
  }/***[/JCBGUI$$$$]***/


	// Used in sick

/***[JCBGUI.admin_view.php_ajaxmethod.113.$$$$]***/
	public function getCity($capitalid)
    {
        $db = JFactory::getDbo();

        $query = $db->getQuery(true);

        $query
            ->select($db->quoteName(array('a.id', 'a.name'),array('id','name')))
            ->from($db->quoteName('#__reservation_capital', 'a'))
            ->where($db->quoteName('a.capitalid') . ' = ' . $db->quote($capitalid))
            ->order($db->quoteName('a.name') . ' ASC');

        $db->setQuery($query);

        $results = $db->loadAssocList();
        return $results;
    }/***[/JCBGUI$$$$]***/

}
