diff --git a/application/controllers/Cluster.php b/application/controllers/Cluster.php index b5e72216356a273c962be049e765b0e8ef05e01a..f9ccce8888da392758d5b2968a6d676401201311 100644 --- a/application/controllers/Cluster.php +++ b/application/controllers/Cluster.php @@ -12,5 +12,31 @@ class Cluster extends ExhibitionController { $this->output_admin('Cluster/v_cluster_manage'); } + public function get_cluster() + { + $this->load->model('cluster/M_cluster', 'cluster'); + $data = $this->cluster->get_cluster()->result(); + echo json_encode($data); + } + public function add_cluster() + { + $logo = $this->input->post('logo'); + $cluster_name = $this->input->post('cluster_name'); + $this->load->model('cluster/Da_cluster', 'cluster'); + $add = $this->cluster->add_cluster($logo, $cluster_name); + $data['message'] = true; + echo json_encode($data); + } + + public function edit_cluster() + { + $id = $this->input->post('id'); + $logo = $this->input->post('logo'); + $cluster_name = $this->input->post('cluster_name'); + $this->load->model('cluster/Da_cluster', 'cluster'); + $add = $this->cluster->edit_cluster($logo, $cluster_name, $id); + $data['message'] = true; + echo json_encode($data); + } } \ No newline at end of file diff --git a/application/models/cluster/Da_cluster.php b/application/models/cluster/Da_cluster.php new file mode 100644 index 0000000000000000000000000000000000000000..a0184026d3182f5f04ffdab4fcf5d80c3a623010 --- /dev/null +++ b/application/models/cluster/Da_cluster.php @@ -0,0 +1,31 @@ +<?php + +defined('BASEPATH') or exit('No direct script access allowed'); + +require_once dirname(__FILE__) . '/../ExhibitionModel.php'; + +class Da_cluster extends ExhibitionModel +{ + public function __construct() + { + parent::__construct(); + } + + function add_cluster($logo, $cluster_name){ + $sql = "INSERT INTO {$this->db_name}.cluster ( + cluster_name, + image + ) VALUES (?,?);"; + $query = $this->db->query($sql,[$cluster_name,$logo]); + return $query; + } + + function edit_cluster($logo, $cluster_name, $id){ + $sql = "UPDATE {$this->db_name}.cluster + SET cluster_name = ?, + image = ? + WHERE cluster_id = ?;"; + $query = $this->db->query($sql,[$cluster_name,$logo, $id]); + return $query; + } +} \ No newline at end of file diff --git a/application/models/cluster/M_cluster.php b/application/models/cluster/M_cluster.php new file mode 100644 index 0000000000000000000000000000000000000000..d885643a68a77cdb8d45b30e61e48156fef6cc70 --- /dev/null +++ b/application/models/cluster/M_cluster.php @@ -0,0 +1,21 @@ +<?php + +defined('BASEPATH') or exit('No direct script access allowed'); + +require_once 'Da_cluster.php'; + +class M_cluster extends Da_cluster +{ + public function __construct() + { + parent::__construct(); + } + + function get_cluster() + { + $sql = "SELECT * FROM {$this->db_name}.cluster ORDER BY cluster_id DESC"; + $query = $this->db->query($sql); + return $query; + }//end get_cluster + +} \ No newline at end of file diff --git a/application/views/Cluster/v_cluster_manage.php b/application/views/Cluster/v_cluster_manage.php index 3a1a83b1fe578a6d39a43a3374b151ced624ef19..b6d069c92d2893b50f2b552c5c341db4b6a116e6 100644 --- a/application/views/Cluster/v_cluster_manage.php +++ b/application/views/Cluster/v_cluster_manage.php @@ -28,39 +28,10 @@ <h5>Cluster Manage</h5> </div> <div class="card-block"> - <table id="myTable" class="display"> - <thead> - <tr> - <th>No.</th> - <th>Logo</th> - <th>Cluster Number</th> - <th>Manage</th> - <th></th> - <th></th> - - </tr> - </thead> - <tbody> - <tr> - <td>1</td> - <td></td> - <td>0</td> - <td><button type="button" class="btn btn-outline-primary" title="" data-toggle="tooltip" data-original-title="btn btn-outline-primary"><div class="i-block" data-clipboard-text="feather icon-eye" data-filter="icon-eye" data-toggle="tooltip" title="" data-original-title="icon-eye"><i class="feather icon-eye"></i></div></button></td> - <td><button type="button" class="btn btn-outline-warning" title="" data-toggle="tooltip" data-original-title="btn btn-outline-warning"><div class="i-block" data-clipboard-text="feather icon-edit" data-filter="icon-edit" data-toggle="tooltip" title="" data-original-title="icon-edit"><i class="feather icon-edit"></i></div></button></td> - <td><button type="button" class="btn btn-outline-danger" title="" data-toggle="tooltip" data-original-title="btn btn-outline-danger"><div class="i-block" data-clipboard-text="feather icon-trash-2" data-filter="icon-trash-2" data-toggle="tooltip" title="" data-original-title="icon-trash-2"><i class="feather icon-trash-2"></i></div></button></td> + <button type="button" class="btn btn-outline-primary" data-toggle="modal" data-target="#add-cluster-modal" ><div class="i-block" data-toggle="tooltip" ><i class="feather icon-plus-circle"></i></div></button> + <div id='create_table'> - </tr> - <tr> - <td>2</td> - <td></td> - <td>1</td> - <td><button type="button" class="btn btn-outline-primary" title="" data-toggle="tooltip" data-original-title="btn btn-outline-primary"><div class="i-block" data-clipboard-text="feather icon-eye" data-filter="icon-eye" data-toggle="tooltip" title="" data-original-title="icon-eye"><i class="feather icon-eye"></i></div></button></td> - <td><button type="button" class="btn btn-outline-warning" title="" data-toggle="tooltip" data-original-title="btn btn-outline-warning"><div class="i-block" data-clipboard-text="feather icon-edit" data-filter="icon-edit" data-toggle="tooltip" title="" data-original-title="icon-edit"><i class="feather icon-edit"></i></div></button></td> - <td><button type="button" class="btn btn-outline-danger" title="" data-toggle="tooltip" data-original-title="btn btn-outline-danger"><div class="i-block" data-clipboard-text="feather icon-trash-2" data-filter="icon-trash-2" data-toggle="tooltip" title="" data-original-title="icon-trash-2"><i class="feather icon-trash-2"></i></div></button></td> - - </tr> - </tbody> - </table> + </div> </div> </div> </div> @@ -72,11 +43,169 @@ </div> </div> </div> + +<div class="modal fade" id="edit-cluster-modal" tabindex="-1" role="dialog" aria-hidden="true"> + <div class="modal-dialog modal-dialog-centered" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="edit-cluster-modal">Edit Cluster</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body"> + <input class="form-control" type="hidden" id="edit_id"> + <div class="form-group"> + <label for="email">Logo</label> + <input class="form-control" type="file" id="edit_logo"> + </div> + <div class="form-group"> + <label for="cluster_name">Cluster Name</label> + <input class="form-control" type="text" id="edit_name"> + </div> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> + <button type="button" class="btn btn-primary" onclick="editCluster()">Save</button> + </div> + </div> + </div> +</div> + +<div class="modal fade" id="add-cluster-modal" tabindex="-1" role="dialog" aria-hidden="true"> + <div class="modal-dialog modal-dialog-centered" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="add-cluster-modal">Add Cluster</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + </div> + <div class="modal-body"> + <div class="form-group"> + <label for="email">Logo</label> + <input class="form-control" type="file" id="add_logo" > + </div> + <div class="form-group"> + <label for="cluster_name">Cluster Name</label> + <input class="form-control" type="text" id="add_cluster_name"> + </div> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> + <button type="button" class="btn btn-primary" onclick="addCluster()">Save</button> + </div> + </div> + </div> +</div> + <script> $( document ).ready(function() { - $('#myTable').DataTable(); + get_cluster(); }); +function get_cluster(){ + $.ajax({ + type: 'post', + url: "<?php echo site_url() . '/Cluster/get_cluster'; ?>", + dataType: 'json', + success: function(data) { + create_table(data); + } + }) +} + +function create_table(data){ + let html_code = ''; + html_code +='<table id="myTable" class="table-hover">' + html_code +='<thead>' + html_code +='<tr>' + html_code +='<th style="width: 10%;">No.</th>' + html_code +='<th style="width: 20%;">Logo</th>' + html_code +='<th style="width: 55%;">Cluster Number</th>' + html_code +='<th style="width: 15%;">Manage</th>' + html_code +='</tr>' + html_code +='</thead>' + html_code +='<tbody>' + data.forEach((row, index) => { + html_code += '<tr>' + html_code += '<td>'+ (index + 1)+'</td>' + html_code += '<td>Logo</td>' + html_code += '<td>'+row.cluster_name+'</td>' + html_code += '<td>' + html_code +='<button type="button" class="btn btn-outline-warning" data-toggle="modal" data-target="#edit-cluster-modal" onclick="editModal('+ row.cluster_id +',\''+ row.cluster_name+'\')" ><div class="i-block" data-clipboard-text="feather icon-edit" data-filter="icon-edit" data-toggle="tooltip"><i class="feather icon-edit"></i></div></button>' + html_code +='<button type="button" class="btn btn-outline-danger" data-toggle="tooltip" onclick="deleteCluster(' + row.cluster_id + ')" ><div class="i-block" data-clipboard-text="feather icon-trash-2" data-filter="icon-trash-2" data-toggle="tooltip" title="" ><i class="feather icon-trash-2"></i></div></button>' + html_code += '</td>' + html_code += '</tr>'; + }) + html_code +='</tbody>'; + html_code +='</table>'; + $('#create_table').html(html_code); + $('#myTable').DataTable(); +} + +function editModal(id, name){ + $('#edit_id').val(id) + $('#edit_name').val(name); +} + +function addCluster(){ + let logo = $('#add_logo').val(); + let cluster_name = $('#add_cluster_name').val(); + $.ajax({ + type: 'POST', + url: "<?php echo site_url() . '/Cluster/add_cluster'; ?>", + data: { + 'logo': logo, + 'cluster_name': cluster_name, + }, + dataType: 'json', + success: function(data) { + console.log(data) + if (data.message) { + alert('succes'); + $('#add-cluster-modal .close').click(); + get_cluster() + } + else { + alert('fail'); + } + } + }); +} + +function editCluster(){ + let id = $('#edit_id').val(); + let logo = $('#edit_logo').val(); + let cluster_name = $('#edit_name').val(); + $.ajax({ + type: 'POST', + url: "<?php echo site_url() . '/Cluster/edit_cluster'; ?>", + data: { + 'id': id, + 'logo': logo, + 'cluster_name': cluster_name, + }, + dataType: 'json', + success: function(data) { + console.log(data) + if (data.message) { + alert('succes'); + $('#edit-cluster-modal .close').click(); + get_cluster() + } + else { + alert('fail'); + } + /* End Check if log in fail */ + } + }); +} + +function deleteCluster(){ + +} + </script> \ No newline at end of file diff --git a/application/views/Company/v_company_manage.php b/application/views/Company/v_company_manage.php index 24534af44f2136c370ad054736bdad0af808c752..8508aa3134e6514cf6fb941afc48c91e693980d0 100644 --- a/application/views/Company/v_company_manage.php +++ b/application/views/Company/v_company_manage.php @@ -31,12 +31,12 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No.</th> - <th>Logo</th> - <th>Company Name</th> - <th>Manage</th> - <th></th> - <th></th> + <th style="width: 5%;">No.</th> + <th style="width: 30%;">Logo</th> + <th style="width: 50%;">Company Name</th> + <th style="width: 5%;"></th> + <th style="width: 5%;">Manage</th> + <th style="width: 5%;"></th> </tr> </thead> diff --git a/application/views/Information/v_information_manage.php b/application/views/Information/v_information_manage.php index b25b7131c1adb1c21d4094926ba341411a14a386..8056a79cdc6e1e599caf1753ad8b9fd7d0b5c759 100644 --- a/application/views/Information/v_information_manage.php +++ b/application/views/Information/v_information_manage.php @@ -31,11 +31,11 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No.</th> - <th>Information Name</th> - <th>Manage</th> - <th></th> - <th></th> + <th style="width: 10%;">No.</th> + <th style="width: 75%;">Information Name</th> + <th style="width: 5%; "></th> + <th style="width: 5%;">Manage</th> + <th style="width: 5%;"></th> </tr> </thead> @@ -55,7 +55,7 @@ <td><button type="button" class="btn btn-outline-warning" title="" data-toggle="tooltip" data-original-title="btn btn-outline-warning"><div class="i-block" data-clipboard-text="feather icon-edit" data-filter="icon-edit" data-toggle="tooltip" title="" data-original-title="icon-edit"><i class="feather icon-edit"></i></div></button></td> <td><button type="button" class="btn btn-outline-danger" title="" data-toggle="tooltip" data-original-title="btn btn-outline-danger"><div class="i-block" data-clipboard-text="feather icon-trash-2" data-filter="icon-trash-2" data-toggle="tooltip" title="" data-original-title="icon-trash-2"><i class="feather icon-trash-2"></i></div></button></td> - < + </tr> </tbody> diff --git a/application/views/Login/Login.php b/application/views/Login/Login.php index 8ed5272d5233042da92fed2036b14d8f1e0308d7..bf72e6adecf8ad98db29f4f3268c9a6688989a45 100644 --- a/application/views/Login/Login.php +++ b/application/views/Login/Login.php @@ -44,7 +44,6 @@ else { alert('fail') } - /* End Check if log in fail */ } }); diff --git a/application/views/Project/v_project_manage.php b/application/views/Project/v_project_manage.php index b27b78d77968619ab8c29e0fe1489c0a0d14dd23..15611cf2a33c9967dec444414849052564fa014d 100644 --- a/application/views/Project/v_project_manage.php +++ b/application/views/Project/v_project_manage.php @@ -31,13 +31,13 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No.</th> - <th>Student ID</th> - <th>Student Name</th> - <th>Project Name</th> - <th>Manage</th> - <th></th> - <th></th> + <th style="width: 5%;">No.</th> + <th style="width: 15%;">Student ID</th> + <th style="width: 30%;">Student Name</th> + <th style="width: 40%;">Project Name</th> + <th style="width: 5%;"></th> + <th style="width: 5%;">Manage</th> + <th style="width: 5%;"></th> </tr> </thead> diff --git a/application/views/Tag/v_tag_manage.php b/application/views/Tag/v_tag_manage.php index 6e905ecf2dcf965db79c2a1e519bb9d3428a6105..98720a3800c1cd881acfda5d79e9ac692dc136f9 100644 --- a/application/views/Tag/v_tag_manage.php +++ b/application/views/Tag/v_tag_manage.php @@ -31,10 +31,10 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No</th> - <th>Tag Name</th> - <th>Status</th> - <th>Manage</th> + <th style="width: 5%;">No</th> + <th style="width: 55%;">Tag Name</th> + <th style="width: 30%;">Status</th> + <th style="width: 10%; text-align: center">Manage</th> </tr> </thead> <tbody> diff --git a/application/views/Team/v_team_manage.php b/application/views/Team/v_team_manage.php index c668f5078c07db7eb30ed3124405b86acad25b76..44378554096b7c04ea60e676c5bbcfd4a152ef70 100644 --- a/application/views/Team/v_team_manage.php +++ b/application/views/Team/v_team_manage.php @@ -31,12 +31,12 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No.</th> - <th>Logo</th> - <th>Team Number</th> - <th>Manage</th> - <th></th> - <th></th> + <th style="width: 5%;">No.</th> + <th style="width: 30%;">Logo</th> + <th style="width: 50%;">Team Number</th> + <th style="width: 5%;"></th> + <th style="width: 5%;">Manage</th> + <th style="width: 5%;"></th> </tr> </thead> diff --git a/application/views/User/v_user_manage.php b/application/views/User/v_user_manage.php index f07d67960e5ef81341ebdf566af3e30b87fd86ab..14e1ccc5f4a5236d9490098cf3ef6a96603011a5 100644 --- a/application/views/User/v_user_manage.php +++ b/application/views/User/v_user_manage.php @@ -31,12 +31,12 @@ <table id="myTable" class="display"> <thead> <tr> - <th>No.</th> - <th>Student ID</th> - <th>Student Name</th> - <th>Manage</th> - <th></th> - <th></th> + <th style="width: 5%;">No.</th> + <th style="width: 15%;">Student ID</th> + <th style="width: 65%;">Student Name</th> + <th style="width: 5%;"></th> + <th style="width: 5%;">Manage</th> + <th style="width: 5%;"></th> </tr> </thead>