<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Seminar extends MY_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		echo "<h1>Access Denied</h1>";
		exit;
	}

	public function register()
	{
		$request = $this->input->get();
		$required_fields = ['seminar', 'date', 'location', 'participant', 'email'];
		$fail = false;
		foreach ($required_fields as $field) {
			if (! array_key_exists($field, $request)) {
				$fail = true;
				break;
			}
		}
		if ($fail) {
			echo json_encode(['success' => false, 'data' => []], JSON_UNESCAPED_UNICODE);
			exit;
		}
		$this->load->model('Webinar_model', 'webinar');
		$seminar_token = $this->webinar->register($request);
		echo json_encode(['success' => true, 'data' => ['seminar_token' => $seminar_token]], JSON_UNESCAPED_UNICODE);
	}

	public function get()
	{
		$request = $this->input->get();
		echo json_encode(['success' => true, 'data' => ['seminar_token' => 'nhC9HSIvXBnZ4YIW']], JSON_UNESCAPED_UNICODE);
	}
}
