Bläddra i källkod

Merge pull request #18 from advation/audit

Audit
Adam 9 år sedan
förälder
incheckning
10aac5b46a

+ 3 - 0
application/controllers/accountsController.php

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

+ 49 - 0
application/controllers/auditController.php

@@ -0,0 +1,49 @@
+<?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()
+    {
+        if(array_key_exists('items',$_GET))
+        {
+            $_SESSION['items'] = $_GET['items'];
+        }
+
+        if(array_key_exists('items',$_SESSION))
+        {
+            $items = $_SESSION['items'];
+        }
+        else
+        {
+            $items = 20;
+        }
+
+        if(array_key_exists('page',$_GET))
+        {
+            $page = $_GET['page'];
+        }
+        else
+        {
+            $page = 1;
+        }
+
+        $audit = new auditModel();
+
+        $auditLog = $audit->getAll($page,$items);
+        $this->view->audit = $auditLog;
+
+        $this->view->pager = $audit->getPager();
+    }
+}
+
+?>

+ 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 >
                         ";
                     }
 

+ 164 - 0
application/models/auditModel.php

@@ -0,0 +1,164 @@
+<?php
+class auditModel extends Staple_Model
+{
+    private $db;
+
+    private $timestamp;
+    private $action;
+    private $userId;
+    private $group;
+    private $item;
+    private $pager;
+
+    /**
+     * @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;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getPager()
+    {
+        return $this->pager;
+    }
+
+    /**
+     * @param mixed $pager
+     */
+    public function setPager($pager)
+    {
+        $this->pager = $pager;
+    }
+
+    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($page,$items)
+    {
+        $pager = new Staple_Pager();
+
+        //Get total rows
+        $sql = "SELECT COUNT(id) as count FROM audit";
+        $result = $this->db->query($sql)->fetch_assoc();
+        $total = $result['count'];
+
+        $pager->setTotal($total);
+        $pager->setItemsPerPage($items);
+        $pager->setPage($page);
+
+        $sql = "
+            SELECT * FROM audit WHERE 1 ORDER BY timestamp ASC LIMIT ".$pager->getStartingItem().", ".$pager->getItemsPerPage()."
+        ";
+
+        $this->pager = $pager;
+
+        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

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

@@ -0,0 +1,55 @@
+<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 class="small-12 columns">
+            <?php
+
+            echo $this->pager;
+
+            ?>
+        </div>
+    </div>
+</div>
+

+ 12 - 12
library/Staple/Pager.class.php

@@ -401,18 +401,18 @@ class Staple_Pager
 		{
 			$action = Staple_Main::getRoute();
 		}
-		$buffer = "<div class=\"staple_pager\">\n<div class=\"staple_pager_pages\">\nPage: ";
+		$buffer = "<div class=\"staple_pager row\">\n<div class=\"staple_pager_pages small-12 medium-11 columns\">\n";
 		$pages = $this->getPages();
 		if(count($pages) > 1)
 		{
 			if($this->getCurrentPage() == 1)
 			{
-				$buffer .= ' &lt;&lt; - &lt; ';
+				$buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a> ';
 			}
 			elseif($this->getCurrentPage() > 1) 
 			{
-				$buffer .= '<a href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>1))).'">&lt;&lt;</a> - ';
-				$buffer .= '<a href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>($this->getCurrentPage()-1)))).'">&lt;</a> ';
+				$buffer .= '<a class="button tiny" href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>1))).'"><i class="fa fa-angle-double-left"></i></a> ';
+				$buffer .= '<a class="button tiny" href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>($this->getCurrentPage()-1)))).'"><i class="fa fa-angle-left"></i></a> ';
 			}
 			if($pages[0] != 1)
 			{
@@ -422,11 +422,11 @@ class Staple_Pager
 			{
 				if($this->getCurrentPage() == $page)
 				{
-					$buffer .= '<span class="currentpage">'.((int)$page).'</span> ';
+					$buffer .= '<span class="currentpage button tiny disabled">'.((int)$page).'</span> ';
 				}
 				else 
 				{
-					$buffer .= '<a href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>(int)$page))).'">'.((int)$page).'</a> ';
+					$buffer .= '<a class="button tiny secondary" href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>(int)$page))).'">'.((int)$page).'</a> ';
 				}
 			}
 			if($pages[count($pages)-1] != $this->getNumberOfPages())
@@ -435,24 +435,24 @@ class Staple_Pager
 			}
 			if($this->getCurrentPage() == $this->getNumberOfPages())
 			{
-				$buffer .= ' &gt; - &gt;&gt; ';
+				$buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
 			}
 			else
 			{
-				$buffer .= '<a href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>($this->getCurrentPage()+1)))).'">&gt;</a> - '; 
-				$buffer .= '<a href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>$this->getNumberOfPages()))).'">&gt;&gt;</a> ';
+				$buffer .= '<a class="button tiny" href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>($this->getCurrentPage()+1)))).'"><i class="fa fa-angle-right"></i></a> ';
+				$buffer .= '<a class="button tiny" href="'.Staple_Link::get($action,array_merge($linkVars,array('page'=>$this->getNumberOfPages()))).'"><i class="fa fa-angle-double-right"></i></a>';
 			}
 		}
 		else 
 		{
-			$buffer .= '<< - < 1 > - >>';
+			$buffer .= '<a class="button tiny secondary disabled"><i class="fa fa-angle-double-left"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-left"></i></a>  <a class="button tiny disabled">1</a> <a class="button tiny secondary disabled"><i class="fa fa-angle-right"></i></a> <a class="button tiny secondary disabled"><i class="fa fa-angle-double-right"></i></a>';
 		}
 		$buffer .= "</div>\n";
 		if($this->getDisplayItemAmountSelector() === true)
 		{
 			
-			$buffer .= "<div class=\"staple_pager_items\">\n";
-			$buffer .= 'Items Per Page: <select onChange="window.location=\''.Staple_Link::get($action,array_merge($linkVars,array('page'=>1)))."&items='+this.value\">\n";
+			$buffer .= "<div class=\"staple_pager_items small-12 medium-1 columns\">\n";
+			$buffer .= '<select onChange="window.location=\''.Staple_Link::get($action,array_merge($linkVars,array('page'=>1)))."&items='+this.value\">\n";
 			foreach($this->getItemAmountSelections() as $value)
 			{
 				$selected = '';

+ 2 - 0
public/timetrackerStyle/scss/_settings.scss

@@ -243,6 +243,8 @@ $primary-color: #315476;
   background-color: #fafafa;
   padding:20px;
 }
+
+
 // We use these to control various global styles
 // $body-bg: $white;
 // $body-font-color: $jet;