Преглед изворни кода

Adjusted how the time fields were being scrubbed. This now happens with regex at the form validation for each time field.

Adam Day пре 10 година
родитељ
комит
7821e780d9

+ 12 - 19
application/controllers/timesheetController.php

@@ -46,13 +46,14 @@ class timesheetController extends Staple_Controller
                 $endDate = strtotime($endMonth.'/25/'.$endYear);
                 $endDate = strtotime($endMonth.'/25/'.$endYear);
 
 
                 $userDate = strtotime($data['date']);
                 $userDate = strtotime($data['date']);
+
+                //Date is within pay period
                 if($userDate >= $startDate && $userDate <= $endDate)
                 if($userDate >= $startDate && $userDate <= $endDate)
                 {
                 {
-                    //Date is within pay period
                     //Compare in Times and out Times.
                     //Compare in Times and out Times.
                     if(strtotime($data['inTime']) < strtotime($data['outTime']))
                     if(strtotime($data['inTime']) < strtotime($data['outTime']))
                     {
                     {
-                        //Create a new entry object
+                        //Create a new entry object and set properties
                         $entry = new timeEntryModel();
                         $entry = new timeEntryModel();
                         $entry->setDate($data['date']);
                         $entry->setDate($data['date']);
                         $entry->setInTime($data['inTime']);
                         $entry->setInTime($data['inTime']);
@@ -60,40 +61,45 @@ class timesheetController extends Staple_Controller
                         $entry->setLessTime($data['lessTime']);
                         $entry->setLessTime($data['lessTime']);
                         $entry->setCodeId($data['code']);
                         $entry->setCodeId($data['code']);
 
 
+                        //Save entry data to table.
                         if($entry->save())
                         if($entry->save())
                         {
                         {
+                            //Return a new time form with success message
                             $form = new insertTimeForm();
                             $form = new insertTimeForm();
                             $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
                             $form->successMessage = array("<i class=\"fa fa-check\"></i> Entry saved for ".$data['date']."");
                             $this->view->insertTimeForm = $form;
                             $this->view->insertTimeForm = $form;
                         }
                         }
                         else
                         else
                         {
                         {
-                            $message = $entry->save()->getMessage();
+                            //Return the same form with a warning message
+                            $message = "<i class=\"fa fa-warning\"></i> Cannot insert overlapping time entries. Please add a new entry or edit an already existing one.";
                             $form->errorMessage = array($message);
                             $form->errorMessage = array($message);
                             $this->view->insertTimeForm = $form;
                             $this->view->insertTimeForm = $form;
                         }
                         }
                     }
                     }
                     else
                     else
                     {
                     {
-                        //Send form with error message back.
+                        //Return the same form with error message.
                         $form->errorMessage = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
                         $form->errorMessage = array("<b>'Time In'</b> entry cannot be before <b>'Time Out'</b> entry.");
                         $this->view->insertTimeForm = $form;
                         $this->view->insertTimeForm = $form;
                     }
                     }
                 }
                 }
                 else
                 else
                 {
                 {
-                    //Send form with error message back.
+                    //Return the same form with error message.
                     $form->errorMessage = array("<i class='fa fa-warning'></i> You may only submit time for the current date period.");
                     $form->errorMessage = array("<i class='fa fa-warning'></i> You may only submit time for the current date period.");
                     $this->view->insertTimeForm = $form;
                     $this->view->insertTimeForm = $form;
                 }
                 }
             }
             }
             else
             else
             {
             {
+                //Return form with invalid data.
                 $this->view->insertTimeForm = $form;
                 $this->view->insertTimeForm = $form;
             }
             }
         }
         }
         else
         else
         {
         {
+            //Return form
             $this->view->insertTimeForm = $form;
             $this->view->insertTimeForm = $form;
         }
         }
 
 
@@ -173,20 +179,7 @@ class timesheetController extends Staple_Controller
         if($id != null)
         if($id != null)
         {
         {
             $entry = new timeEntryModel($id);
             $entry = new timeEntryModel($id);
-            if($entry)
-            {
-                $form = new editTimeForm();
-                $form->setAction($this->_link(array('timesheet','edit',$id)));
-                //$form->addData();
-
-                $this->view->form = $form;
-
-            }
-            else
-            {
-                echo "Entry loaded";
-                //header("location: ".$this->_link(array('timesheet'))."");
-            }
+            print_r($entry);
         }
         }
         else
         else
         {
         {

+ 2 - 3
application/forms/insertTimeForm.php

@@ -11,18 +11,17 @@ class insertTimeForm extends Staple_Form
 
 
         $date = new Staple_Form_FoundationTextElement('date','Date');
         $date = new Staple_Form_FoundationTextElement('date','Date');
         $date->setRequired()
         $date->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','10'))
             ->addValidator(new Staple_Form_Validate_Date())
             ->addValidator(new Staple_Form_Validate_Date())
             ->addAttrib('placeholder','mm/dd/yyyy');
             ->addAttrib('placeholder','mm/dd/yyyy');
 
 
         $inTime = new Staple_Form_FoundationTextElement('inTime','Time In');
         $inTime = new Staple_Form_FoundationTextElement('inTime','Time In');
         $inTime->setRequired()
         $inTime->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','8'))
+            ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
             ->addAttrib('placeholder','h:mm am/pm');
             ->addAttrib('placeholder','h:mm am/pm');
 
 
         $outTime = new Staple_Form_FoundationTextElement('outTime','Time Out');
         $outTime = new Staple_Form_FoundationTextElement('outTime','Time Out');
         $outTime->setRequired()
         $outTime->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length('1','8'))
+            ->addValidator(new Staple_Form_Validate_Regex('/^(0|[0-9]|1[012]):[0-5][0-9] ?((a|p)m|(A|P)M)$/','Invalid time format. Expected format: h:mm am/pm.'))
             ->addAttrib('placeholder','h:mm am/pm');;
             ->addAttrib('placeholder','h:mm am/pm');;
 
 
         $lessTime = new Staple_Form_FoundationSelectElement('lessTime','Less Time');
         $lessTime = new Staple_Form_FoundationSelectElement('lessTime','Less Time');

+ 1 - 1
application/forms/layouts/insertFormLayout.phtml

@@ -73,7 +73,7 @@
     $(document).ready(function() {
     $(document).ready(function() {
 
 
         $(function() {
         $(function() {
-            $( "#date" ).datepicker({ minDate: "<?php echo date('m',strtotime('last month'))."/26/".date('Y') ?>", maxDate: "<?php echo date('m',strtotime('m'))."/25/".date('Y') ?>" });
+            $( "#date" ).datepicker({numberOfMonths:2, minDate: "<?php echo date('m',strtotime('last month'))."/26/".date('Y') ?>", maxDate: "<?php echo date('m',strtotime('m'))."/25/".date('Y') ?>" });
         });
         });
 
 
         $('#entryToggle').click(function()
         $('#entryToggle').click(function()

+ 1 - 2
application/models/timeEntryModel.php

@@ -377,8 +377,7 @@
                 }
                 }
                 else
                 else
                 {
                 {
-                    $ex = new Exception('Time block already in use. Submit a new entry or edit an already existing one.');
-                    return $ex;
+                    return false;
                 }
                 }
 			}
 			}
 			else
 			else