Jelajahi Sumber

Created a simple audit submission for all validation entries.

Adam Day 9 tahun lalu
induk
melakukan
7db24a223f

+ 3 - 0
application/controllers/accountsController.php

@@ -17,6 +17,9 @@ class accountsController extends Staple_Controller
     public function index()
     {
         echo "Accounts";
+
+
+
     }
 }
 

+ 24 - 0
application/controllers/auditController.php

@@ -0,0 +1,24 @@
+<?php
+
+class auditController extends Staple_Controller
+{
+    public function _start()
+    {
+        $auth = Staple_Auth::get();
+        $this->authLevel = $auth->getAuthLevel();
+        if($this->authLevel < 900)
+        {
+            header("location:".$this->_link(array('index','index'))."");
+        }
+    }
+
+    public function index()
+    {
+        $audit = new auditModel();
+        $auditLog = $audit->getAll();
+
+        $this->view->audit = $auditLog;
+    }
+}
+
+?>

+ 4 - 3
application/layouts/main.phtml

@@ -15,10 +15,10 @@
     <body>
     <div class="header">
         <div class="row">
-            <div class="small-8 column">
+            <div class="small-7 column">
                 <h1><i class="fa fa-clock-o"></i> TimeTracker</h1>
             </div>
-            <div class="small-3 column text-right">
+            <div class="small-4 column text-right">
                 <h4>
                     <?php
                     $auth = Staple_Auth::get();
@@ -49,7 +49,7 @@
                     if($user->getAuthLevel() >= 500)
                     {
                         echo "
-                            <li><a href=\"".$this->link(array('reports')) ."\"><i class=\"fa fa-file\"></i> Reports</a></li>
+                            <li><a href=\"".$this->link(array('reports')) ."\"><i class=\"fa fa-file\"></i> Timesheet Reports</a></li>
                         ";
                     }
 
@@ -58,6 +58,7 @@
                     {
                         echo "
                             <li><a href=\"".$this->link(array('accounts')) ."\"><i class=\"fa fa-users\"></i> Accounts</a></li>
+                            <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li >
                         ";
                     }
 

+ 134 - 0
application/models/auditModel.php

@@ -0,0 +1,134 @@
+<?php
+class auditModel extends Staple_Model
+{
+    private $db;
+
+    private $timestamp;
+    private $action;
+    private $userId;
+    private $group;
+    private $item;
+
+    /**
+     * @return mixed
+     */
+    public function getTimestamp()
+    {
+        return $this->timestamp;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getAction()
+    {
+        return $this->action;
+    }
+
+    /**
+     * @param mixed $action
+     */
+    public function setAction($action)
+    {
+        $this->action = $action;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getUserId()
+    {
+        return $this->userId;
+    }
+
+    /**
+     * @param mixed $userId
+     */
+    public function setUserId($userId)
+    {
+        $this->userId = $userId;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getGroup()
+    {
+        return $this->group;
+    }
+
+    /**
+     * @param mixed $group
+     */
+    public function setGroup($group)
+    {
+        $this->group = $group;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getItem()
+    {
+        return $this->item;
+    }
+
+    /**
+     * @param mixed $item
+     */
+    public function setItem($item)
+    {
+        $this->item = $item;
+    }
+
+    function __construct()
+    {
+        $this->db = Staple_DB::get();
+    }
+
+    function save()
+    {
+        if(isset($this->userId) && isset($this->action) && isset($this->item))
+        {
+            $sql = "
+                INSERT INTO audit (action, userId, item) VALUES ('".$this->db->real_escape_string($this->getAction())."','".$this->db->real_escape_string($this->getUserId())."','".$this->db->real_escape_string($this->getItem())."');
+            ";
+
+            if($this->db->query($sql))
+            {
+                return true;
+            }
+        }
+    }
+
+    function getAll()
+    {
+        $sql = "
+            SELECT * FROM audit WHERE 1 ORDER BY timestamp ASC;
+        ";
+
+        if($this->db->query($sql)->num_rows > 0)
+        {
+            $query = $this->db->query($sql);
+
+            $data = array();
+            $i = 0;
+            while($result = $query->fetch_assoc())
+            {
+                $data[$i]['timestamp'] = $result['timestamp'];
+                $account = new userModel();
+                $data[$i]['account'] = $account->userInfo($result['userId']);
+                $data[$i]['action'] = $result['action'];
+                $data[$i]['item'] = $result['item'];
+                $i++;
+            }
+
+            return $data;
+        }
+        else
+        {
+            return array();
+        }
+    }
+}
+?>

+ 8 - 2
application/models/timesheetModel.php

@@ -429,6 +429,7 @@
 
 			$user = new userModel();
 			$userId = $user->getId();
+			$oldKey = $user->getBatchId();
 
 			$key = sha1(time().$user->getUsername().rand(999,9999999999));
 
@@ -438,16 +439,21 @@
 			{
 				//Key already in use
 				return false;
-				echo "this";
 			}
 			else
 			{
-				echo "that";
 				//Set new key in user account
 				$sql = "UPDATE accounts SET batchId='".$this->db->real_escape_string($key)."' WHERE id=$userId";
 
 				if($this->db->query($sql))
 				{
+					//Log Audit
+					$audit = new auditModel();
+					$audit->setAction('validate');
+					$audit->setUserId($userId);
+					$audit->setItem($oldKey);
+					$audit->save();
+
 					return true;
 				}
 				else

+ 47 - 0
application/views/audit/index.phtml

@@ -0,0 +1,47 @@
+<div class="section">
+    <div class="row">
+        <div class="small-12 columns text-center">
+            <h1><i class="fa fa-list-alt"></i> Audit Log</h1>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="small-12 columns">
+            <?php
+
+            if(count($this->audit) > 0)
+            {
+                echo "
+                <table width=\"100%\">
+                <thead>
+                <tr>
+                    <th>Time Stamp</th>
+                    <th>Account</th>
+                    <th>Action</th>
+                    <th>Item</th>
+                </tr>
+                </thead>
+                <tbody>
+                ";
+
+                foreach($this->audit as $log)
+                {
+                    echo "
+                        <tr>
+                               <td>".$log['timestamp']."</td>
+                               <td><span data-tooltip aria-haspopup=\"true\" class=\"has-tip\" title=\"".$log['account']['firstName']." ".$log['account']['lastName']."\">".$log['account']['username']."</span></td>
+                               <td>".$log['action']."</td>
+                               <td>".$log['item']."</td>
+                        </tr>
+                    ";
+                }
+
+                echo "
+                </tbody>
+                </table>";
+            }
+
+            ?>
+        </div>
+    </div>
+</div>