chess/application/controllers/Test_api.php

201 lines
3.9 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test_api extends CI_Controller {
function index()
{
$this->load->view('api_view');
}
function action()
{
if($this->input->post('data_action'))
{
$data_action = $this->input->post('data_action');
if($data_action == "Delete")
{
$api_url = "http://localhost/chess/admin/api/delete";
$form_data = array(
'id' => $this->input->post('user_id')
);
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
echo $response;
}
if($data_action == "Edit")
{
$api_url = "http://localhost/chess/admin/api/update";
$form_data = array(
'tid' => $this->input->post('tid'),
'tname' => $this->input->post('tname'),
'entry_fee' => $this->input->post('entry_fee'),
'start_date' => $this->input->post('start_date'),
'end_date' => $this->input->post('end_date'),
'win_amount' => $this->input->post('win_amount'),
'time_slot' => $this->input->post('time_slot')
);
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
echo $response;
}
if($data_action == "fetch_single")
{
$api_url = "http://localhost/chess/admin/api/fetch_single";
$form_data = array(
'tid' => $this->input->post('tid')
);
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
echo $response;
}
if($data_action == "Insert")
{
$api_url = "http://localhost/chess/admin/api/insert";
$form_data = array(
'tname' => $this->input->post('tname'),
'entry_fee' => $this->input->post('entry_fee'),
'start_date' => $this->input->post('start_date'),
'end_date' => $this->input->post('end_date'),
'win_amount' => $this->input->post('win_amount'),
'time_slot' => $this->input->post('time_slot'),
'round' => $this->input->post('round')
);
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, http_build_query($form_data));
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
echo $response;
}
if($data_action == "fetch_all")
{
$api_url = "http://localhost/chess/admin/api";
$client = curl_init($api_url);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client);
curl_close($client);
$result = json_decode($response);
$output = '';
if (is_array($result) && count($result) > 0)
{
foreach($result as $row)
{
$output .= '
<tr>
<td>'.$row->tid.'</td>
<td>'.$row->tname.'</td>
<td>'.$row->entry_fee.'</td>
<td>'.$row->start_date.'</td>
<td>'.$row->end_date.'</td>
<td>'.$row->win_amount.'</td>
<td>'.$row->time_slot.'</td>
<td><butto type="button" name="round" class="btn btn-warning btn-xs round" id="'.$row->tid.'">Round</button></td>
<td><butto type="button" name="edit" class="btn btn-warning btn-xs edit" id="'.$row->tid.'">Edit</button></td>
<td><button type="button" name="delete" class="btn btn-danger btn-xs delete" id="'.$row->tid.'">Delete</button></td>
</tr>
';
}
}
else
{
$output .= '
<tr>
<td colspan="4" align="center">No Data Found</td>
</tr>
';
}
echo $output;
}
}
}
}
?>