168 lines
6.4 KiB
PHP
168 lines
6.4 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Myfloat_version extends Admin_Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$this->load->model('myfloat_version_model');
|
|
$platform_id = "";
|
|
$validated = true;
|
|
$data = [
|
|
"platform_id" => "",
|
|
"name" => "",
|
|
"released" => "",
|
|
"notes" => "",
|
|
"rev_count" => "",
|
|
"short_hash" => "",
|
|
"url" => "",
|
|
"form_button" => "Create",
|
|
];
|
|
$data['message'] = "";
|
|
|
|
$query = "SELECT id,platform
|
|
FROM members_device_platforms
|
|
WHERE platform != ''";
|
|
|
|
$platforms = $this->read_replica->query($query);
|
|
$platforms = $platforms->result_array();
|
|
|
|
try {
|
|
if ($_POST) {
|
|
$data['id'] = $this->input->post('id') ? trim($this->input->post('id')) : "";
|
|
$platform_id = trim($this->input->post('platform_id'));
|
|
$data['platform_id'] = $platform_id;
|
|
$data['name'] = trim($this->input->post('name'));
|
|
$data['released'] = trim($this->input->post('released'));
|
|
$data['notes'] = trim($this->input->post('notes'));
|
|
$data['rev_count'] = trim($this->input->post('rev_count'));
|
|
$data['short_hash'] = trim($this->input->post('short_hash'));
|
|
$data['url'] = trim($this->input->post('url'));
|
|
|
|
// Validate
|
|
if (empty($data['platform_id'])) {
|
|
$data['message'] .= "<br/>Invalid platform id";
|
|
$validated = false;
|
|
}
|
|
if (empty($data['name']) || strlen($data['name']) > 50) {
|
|
$data['message'] .= "<br/>Invalid name";
|
|
$validated = false;
|
|
}
|
|
if (empty($data['released'])) {
|
|
$data['message'] .= "<br/>Invalid released";
|
|
$validated = false;
|
|
}
|
|
if ($validated == true) {
|
|
// Upsert
|
|
$q = "INSERT INTO myfloat_version
|
|
(
|
|
platform_id,
|
|
name,
|
|
released,
|
|
notes,
|
|
rev_count,
|
|
short_hash,
|
|
url
|
|
)
|
|
VALUES
|
|
(
|
|
'" . pg_escape_string($data['platform_id']) . "',
|
|
'" . pg_escape_string($data['name']) . "',
|
|
'" . pg_escape_string($data['released']) . "',
|
|
'" . pg_escape_string($data['notes']) . "',
|
|
" . ($data['rev_count'] ?: 0) . ",
|
|
'" . pg_escape_string($data['short_hash']) . "',
|
|
'" . pg_escape_string($data['url']) . "'
|
|
) ON CONFLICT (platform_id,name) DO UPDATE SET
|
|
platform_id = '" . pg_escape_string($data['platform_id']) . "',
|
|
name = '" . pg_escape_string($data['name']) . "',
|
|
released = '" . pg_escape_string($data['released']) . "',
|
|
notes = '" . pg_escape_string($data['notes']) . "',
|
|
short_hash = '" . pg_escape_string($data['short_hash']) . "',
|
|
rev_count = " . ($data['rev_count'] ?: 0) . ",
|
|
url = '" . pg_escape_string($data['url']) . "'
|
|
RETURNING *,
|
|
CASE WHEN xmax::text::int > 0
|
|
THEN 'updated' else 'inserted' END AS act";
|
|
|
|
if ($data['message'] == "") {
|
|
$r = $this->db->query($q);
|
|
$f = $r->row_array();
|
|
$act = $f["act"];
|
|
if ($f != null && isset($act)) {
|
|
$data['message'] = 'My float version ' . $act . '!';
|
|
$data["form_button"] = $act == 'inserted' ? 'Insert' : 'Update';
|
|
} else {
|
|
$data['message'] = 'Failed to ' . $act . ' my float version!';
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$params = [];
|
|
$params = $this->input->get();
|
|
|
|
$query = $this->myfloat_version_model->getVersionQuery($params);
|
|
$tableData = $this->returnAdminTable(
|
|
[
|
|
'count_query' => $query,
|
|
'query' => $query,
|
|
],
|
|
'/myfloat_version/index',
|
|
[
|
|
'per_page' => 20,
|
|
'reuse_query_string' => TRUE,
|
|
]
|
|
);
|
|
|
|
$data['links'] = $tableData['links'];
|
|
$data['crashlog_table'] = $tableData['output_table'];
|
|
|
|
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
|
|
|
|
$data['filterData'] = $params;
|
|
$data = array_merge($data, [
|
|
"versions" => $tableData['limited_data'],
|
|
"page" => $page,
|
|
"platforms" => $platforms,
|
|
]);
|
|
} catch (Exception $e) {
|
|
$data["message"] = $e->getMessage();
|
|
}
|
|
|
|
$this->renderAdminPage('view_myfloat_version', $data);
|
|
}
|
|
|
|
public function deleteVersion()
|
|
{
|
|
$data = [];
|
|
$id = (int) $this->input->get('id');
|
|
header('Content-Type: application/json');
|
|
|
|
if ($id > 0) {
|
|
$q = "DELETE FROM myfloat_version WHERE id=${id}";
|
|
$r = $this->db->query($q);
|
|
if ($r) {
|
|
echo json_encode([
|
|
'state' => 'successful',
|
|
'message' => 'My Float Version is deleted',
|
|
'id' => $id,
|
|
]);
|
|
} else {
|
|
echo json_encode([
|
|
'state' => 'failure',
|
|
'message' => 'Delete failed',
|
|
]);
|
|
}
|
|
} else {
|
|
echo json_encode([
|
|
'state' => 'failure',
|
|
'message' => 'Invalid ID',
|
|
]);
|
|
}
|
|
}
|
|
|
|
}
|