From f6124c8da92a8924de1232b295970bc6e3bc31f7 Mon Sep 17 00:00:00 2001
From: doanpv <doanpv@dcv.vn>
Date: Mon, 13 Apr 2020 00:14:55 +0700
Subject: [PATCH] fixbug quản lý log: bỏ action và fix lọc + tìm kiếm

---
 application/controllers/backend/CmsSetting.php                    |  6 ++++--
 application/controllers/backend/CmsTrack.php                      | 12 ++++++------
 application/models/Actionlog_model.php                            | 24 ++++++++++++------------
 application/views/backend/ajax/cms_setting/log_action_view.php    |  9 ---------
 application/views/backend/cms_setting/log_cms/log_action_view.php |  4 ++--
 5 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/application/controllers/backend/CmsSetting.php b/application/controllers/backend/CmsSetting.php
index c21eb29..b2fab01 100644
--- a/application/controllers/backend/CmsSetting.php
+++ b/application/controllers/backend/CmsSetting.php
@@ -1280,6 +1280,7 @@ class CmsSetting extends CI_Controller
         //
         $data = array();
         $filterByAccount = $this->input->post('filterByAccount');
+        $filterByActionType = $this->input->post('filterByActionType');
         $pageId = $this->input->post('pageId');
         //
         $pageId = ($pageId == 0) ? 1 : $pageId;
@@ -1287,9 +1288,10 @@ class CmsSetting extends CI_Controller
         $limit = 20;
         $offset = ($pageId - 1)*$limit;
         $data['offset'] = ($pageId - 1)*$limit;
-        $totalRecord = $this->actionlog_model->countAll($filterByAccount);
+        $totalRecord = $this->actionlog_model->countAll(null, null, null, $filterByAccount, $filterByActionType);
         $data['pagination'] = MyHelper::genPaginationLink($totalRecord, $limit, $pageId);
-        $data['listData'] = $this->actionlog_model->getPagination($limit, $offset, $filterByAccount);
+        //getPagination($record, $start, $dtFrom=NULL, $dtTo=NULL, $filterByIP=NULL, $filterByAccount=NULL, $filterByActionType=NULL)
+        $data['listData'] = $this->actionlog_model->getPagination($limit, $offset, null, null, null, $filterByAccount, $filterByActionType);
         //
         $this->load->view('backend/ajax/cms_setting/log_action_view', $data);
     }
diff --git a/application/controllers/backend/CmsTrack.php b/application/controllers/backend/CmsTrack.php
index 5381831..68ae853 100644
--- a/application/controllers/backend/CmsTrack.php
+++ b/application/controllers/backend/CmsTrack.php
@@ -136,7 +136,7 @@ class CmsTrack extends CI_Controller
             $this->track_model->update_track_user($track_id, $id_singer, $id_user, $active_singer);
 
             // Ghi log
-            $this->actionlog_model->add('UPDATED', 'Cập nhật bài hát.', 'Actionlog_model', 'action_log', $track_id);
+            $this->actionlog_model->add('UPDATED', 'Cập nhật bài hát.', 'Actionlog_model', 'tracks', $track_id);
 
             $this->session->set_flashdata('success', 'Cập nhật bài hát thành công');
             redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
@@ -243,7 +243,7 @@ class CmsTrack extends CI_Controller
                 $this->track_model->add_artist($artist, $insert_id);
             }
                 // Ghi log
-                // $this->mactionlog->add('UPDATED', 'Cập nhật Cuộc đua thành công!', 'Mactionlog', 'action_log', $contest_id);
+                // $this->mactionlog->add('UPDATED', 'Cập nhật Cuộc đua thành công!', 'Mactionlog', 'tracks', $contest_id);
                 //
                 $this->session->set_flashdata('success', 'Tạo Bài hát thành công');
             }else{
@@ -251,7 +251,7 @@ class CmsTrack extends CI_Controller
             }
 
             // Ghi log
-            $this->actionlog_model->add('ADDED', 'Thêm mới bài hát.', 'Actionlog_model', 'action_log', null);
+            $this->actionlog_model->add('ADDED', 'Thêm mới bài hát.', 'Actionlog_model', 'tracks', null);
 
             redirect(base_url('backend/cmsTrack/listTrack'));
         }
@@ -293,7 +293,7 @@ class CmsTrack extends CI_Controller
             $this->session->set_flashdata('success', 'Thêm ca sĩ vào bài hát thành công');
 
             // Ghi log
-            $this->actionlog_model->add('ADDED', 'Thêm mới Ca sĩ cho bài hát.', 'Actionlog_model', 'action_log', $track_id);
+            $this->actionlog_model->add('ADDED', 'Thêm mới Ca sĩ cho bài hát.', 'Actionlog_model', 'tracks', $track_id);
 
             redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
         }
@@ -313,7 +313,7 @@ class CmsTrack extends CI_Controller
         $this->track_model->removeSinger($track_id, $singer_id);
 
         // Ghi log
-        $this->actionlog_model->add('DELETED', 'Xóa Ca sĩ khỏi bài hát.', 'Actionlog_model', 'action_log', $track_id);
+        $this->actionlog_model->add('DELETED', 'Xóa Ca sĩ khỏi bài hát.', 'Actionlog_model', 'tracks', $track_id);
 
         redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
     }
@@ -354,7 +354,7 @@ class CmsTrack extends CI_Controller
             $this->session->set_flashdata('success', 'Thêm Nhạc sĩ vào bài hát thành công');
 
             // Ghi log
-            $this->actionlog_model->add('ADDED', 'Thêm Nhạc sĩ cho bài hát.', 'Actionlog_model', 'action_log', $track_id);
+            $this->actionlog_model->add('ADDED', 'Thêm Nhạc sĩ cho bài hát.', 'Actionlog_model', 'tracks', $track_id);
 
             redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
         }
diff --git a/application/models/Actionlog_model.php b/application/models/Actionlog_model.php
index 50985c1..9585eba 100644
--- a/application/models/Actionlog_model.php
+++ b/application/models/Actionlog_model.php
@@ -50,15 +50,15 @@ class Actionlog_model extends CI_Model {
         return $query->result_array();
     }
 
-    public function countAll($dtFrom=NULL, $dtTo=NULL, $filterByIP=NULL, $filterByAccount=NULL, $filterByActionType=NULL){
+    public function countAll($dtFrom=null, $dtTo=null, $filterByIP=null, $filterByAccount=null, $filterByActionType=null){
         $this->db->select('COUNT(*) AS totalResults');
         $this->db->from($this->_table);
 
-        if($dtFrom != NULL){$this->db->where('DATE(created_at) >=', $dtFrom);}
-        if($dtTo != NULL){$this->db->where('DATE(created_at) <=', $dtTo);}
-        if($filterByIP != NULL){$this->db->like('ip_address', $filterByIP);}
-        if($filterByAccount != NULL){$this->db->like('actor_name', $filterByAccount);}
-        if($filterByActionType != NULL){$this->db->where('UPPER(action)', $filterByActionType);}
+        if($dtFrom != null){$this->db->where('DATE(created_at) >=', $dtFrom);}
+        if($dtTo != null){$this->db->where('DATE(created_at) <=', $dtTo);}
+        if($filterByIP != null){$this->db->like('ip_address', $filterByIP);}
+        if($filterByAccount != null){$this->db->like('actor_name', $filterByAccount);}
+        if($filterByActionType != null){$this->db->where('UPPER(action)', $filterByActionType);}
 
         $query = $this->db->get();
         $result = $query->result_array();
@@ -69,15 +69,15 @@ class Actionlog_model extends CI_Model {
         }
     }
 
-    public function getPagination($record, $start, $dtFrom=NULL, $dtTo=NULL, $filterByIP=NULL, $filterByAccount=NULL, $filterByActionType=NULL){
+    public function getPagination($record, $start, $dtFrom=null, $dtTo=null, $filterByIP=null, $filterByAccount=null, $filterByActionType=null){
         $this->db->select($this->_table.'.*');
         $this->db->from($this->_table);
 
-        if($dtFrom != NULL){$this->db->where('DATE(created_at) >=', $dtFrom);}
-        if($dtTo != NULL){$this->db->where('DATE(created_at) <=', $dtTo);}
-        if($filterByIP != NULL){$this->db->like('ip_address', $filterByIP);}
-        if($filterByAccount != NULL){$this->db->like('actor_name', $filterByAccount);}
-        if($filterByActionType != NULL){$this->db->where('UPPER(action)', $filterByActionType);}
+        if($dtFrom != null){$this->db->where('DATE(created_at) >=', $dtFrom);}
+        if($dtTo != null){$this->db->where('DATE(created_at) <=', $dtTo);}
+        if($filterByIP != null){$this->db->like('ip_address', $filterByIP);}
+        if($filterByAccount != null){$this->db->like('actor_name', $filterByAccount);}
+        if($filterByActionType != null){$this->db->where('UPPER(action)', $filterByActionType);}
 
         $this->db->order_by($this->_table.'.id', 'desc');
         $this->db->limit($record, $start);
diff --git a/application/views/backend/ajax/cms_setting/log_action_view.php b/application/views/backend/ajax/cms_setting/log_action_view.php
index 0beb0ca..b2a10bc 100644
--- a/application/views/backend/ajax/cms_setting/log_action_view.php
+++ b/application/views/backend/ajax/cms_setting/log_action_view.php
@@ -11,7 +11,6 @@
             <th style="text-align: center">ID bản ghi</th>
             <th style="text-align: center">IP</th>
             <th style="text-align: center">Ngày tạo</th>
-            <th style="text-align: center">Xử lý</th>
         </tr>
         </thead>
         <tbody>
@@ -32,14 +31,6 @@
                 <td style="text-align: center">
                     <?php echo MyHelper::reFormatDate($data['created_at']); ?>
                 </td>
-                <td style="text-align: center">
-                    <?php if((time() - strtotime($data['created_at'])) > 15*24*3600): ?>
-                        <a href="<?php echo base_url().'dcvsetting/deleteLogAction/'.$data['id']; ?>"
-                           onclick="return confirm('Bạn có chắc chắn muốn xóa không?')" title="Xóa">
-                            <i class="ace-icon red fa fa-trash-o bigger-130"></i>
-                        </a>
-                    <?php else: echo 'Xóa sau '.(15-(gmdate('d', time()-strtotime($data['created_at'])))).' ngày'; endif;?>
-                </td>
             </tr>
         <?php
         endforeach;
diff --git a/application/views/backend/cms_setting/log_cms/log_action_view.php b/application/views/backend/cms_setting/log_cms/log_action_view.php
index bfc1211..c704ff8 100644
--- a/application/views/backend/cms_setting/log_cms/log_action_view.php
+++ b/application/views/backend/cms_setting/log_cms/log_action_view.php
@@ -100,7 +100,7 @@
             clearTimeout(oldTimeout);
             oldTimeout = setTimeout(function(){
                 loadDataByAjaxFromInput(url);
-            }, 1000);
+            }, 250);
         });
         // Tìm kiếm theo cú pháp
         var oldTimeout2 = '';
@@ -108,7 +108,7 @@
             clearTimeout(oldTimeout2);
             oldTimeout2 = setTimeout(function(){
                 loadDataByAjaxFromInput(url);
-            }, 1000);
+            }, 250);
         });
         // Tìm kiếm theo kênh
         loadDataByAjaxFromSelectBox("select-action-type", url);
--
libgit2 0.27.0