Browse Source

Created a sql statement that will prevent a user from submitting a new time entry that falls within an already existing time entry.

Adam Day 9 years ago
parent
commit
d65b92717f
1 changed files with 7 additions and 1 deletions
  1. 7 1
      application/models/timeEntryModel.php

+ 7 - 1
application/models/timeEntryModel.php

@@ -426,13 +426,19 @@
 
         function _overlap($inTime,$outTime,$id = null)
         {
+            //Checks to see if the times entered fit within any other time entry for that user.
             $this->db = Staple_DB::get();
 
             $auth = Staple_Auth::get();
             $user = new userModel($auth->getAuthId());
             $userId = $user->getId();
 
-            $sql = "SELECT id FROM timeEntries WHERE '".$this->db->real_escape_string($inTime)."' >= inTime AND '".$this->db->real_escape_string($outTime)."' <= outTime AND id <> '".$this->db->real_escape_string($id)."' AND userId = '".$this->db->real_escape_string($userId)."'";
+            $sql = "
+                SELECT id FROM timeEntries
+                WHERE ('".$this->db->real_escape_string($outTime)."' > inTime AND '".$this->db->real_escape_string($outTime)."' < outTime)
+                OR ('".$this->db->real_escape_string($inTime)."' > inTime AND '".$this->db->real_escape_string($inTime)."' < outTime)
+                AND userId = '".$this->db->real_escape_string($userId)."'
+            ";
 
             if($this->db->query($sql)->num_rows > 0)
             {