61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
require APPPATH . '/libraries/REST_Controller.php';
|
|
|
|
class Admin extends REST_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->library('session');
|
|
}
|
|
|
|
public function login_get()
|
|
{
|
|
if ($login = $this->get('login')) {
|
|
parse_str(base64_decode($login), $user);
|
|
$this->session->set_userdata($user);
|
|
if($this->session->userdata('username')) {
|
|
header('location:'. ($this->get('redirect') ? $this->get('redirect') : '/'));
|
|
}
|
|
}
|
|
}
|
|
|
|
private function loginCheck() {
|
|
return $this->session->userdata('username');
|
|
}
|
|
|
|
public function station_schedule_get()
|
|
{
|
|
if ($this->loginCheck()) {
|
|
$this->load->model('station_schedule_model');
|
|
if(!$this->get('categoryId') || !$this->get('dayName')) {
|
|
$this->res(402, 'Preconfigure required');
|
|
}else {
|
|
$schedules = $this->station_schedule_model->findSchedulesByCategoryIdAndDayName($this->get('categoryId'), $this->get('dayName'))->result();
|
|
$this->res(200, 'Success', $schedules);
|
|
}
|
|
} else {
|
|
$this->res(401, 'Not authorized');
|
|
}
|
|
}
|
|
|
|
public function station_schedule_post()
|
|
{
|
|
if ($this->loginCheck()) {
|
|
$this->load->model('station_schedule_model');
|
|
if(!$this->post('categoryId') || !$this->post('dayName') || !$this->post('data')) {
|
|
$this->res(402, 'Preconfigure required');
|
|
}else {
|
|
$schedules = $this->station_schedule_model
|
|
->insertSchedules($this->post('categoryId'), $this->post('dayName'), json_decode($this->post('data'), true));
|
|
$this->res(200, 'Success', $schedules);
|
|
}
|
|
} else {
|
|
$this->res(401, 'Not authorized');
|
|
}
|
|
}
|
|
|
|
}
|