Kaynağa Gözat

Basic account creation is now working.

Adam Day 9 yıl önce
ebeveyn
işleme
552b5cb080

+ 31 - 5
application/controllers/accountsController.php

@@ -29,13 +29,39 @@ class accountsController extends Staple_Controller
             {
                 $data = $form->exportFormData();
 
-                print_r($data);
+                if($data['pinNum'] == $data['pinNum2'])
+                {
+                    $user = new accountModel();
 
-                $account = substr($data['firstName'],0,1).$data['lastName'];
-                echo $account;
+                    $user->setFirstName(ucfirst($data['firstName']));
+                    $user->setLastName(ucfirst($data['lastName']));
+                    $user->setSupervisorId($data['supervisor']);
+                    $user->setType($data['type']);
+                    $user->setAuthLevel($data['level']);
+                    $user->setPin($data['pinNum']);
 
-                $form = new newAccountForm();
-                $this->view->form = $form;
+                    if($user->save())
+                    {
+                        $this->view->newUser = true;
+                        $this->view->firstName = $user->getFirstName();
+                        $this->view->lastName = $user->getLastName();
+                        $this->view->tempPin = $user->getTempPin();
+                        $form = new newAccountForm();
+                        $this->view->form = $form;
+                    }
+                    else
+                    {
+                        $form->errorMessage = array("ERROR: Could not create account");
+                        $this->view->form = $form;
+                        $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
+                    }
+                }
+                else
+                {
+                    $form->errorMessage = array("PINs do not match");
+                    $this->view->form = $form;
+                    $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
+                }
             }
             else
             {

+ 8 - 3
application/controllers/reportsController.php

@@ -141,13 +141,18 @@ class reportsController extends Staple_Controller
         }
         else
         {
+            $date = new DateTime();
 
-            $year = date('Y');
-            $month = date('m');
+            if($date->format('d') >= 26)
+            {
+                $date->modify('+1 month');
+            }
 
-            $timesheets = new reportModel($year, $month);
+            $timesheets = new reportModel($date->format('Y'), $date->format('m'));
 
             $this->view->accounts = $timesheets;
+
+            $this->view->dateTitle = $date->format('F')." ".$date->format('Y');
         }
     }
 

+ 48 - 13
application/controllers/timesheetController.php

@@ -92,28 +92,66 @@ class timesheetController extends Staple_Controller
             $this->view->insertTimeForm = $form;
         }
 
-        //Set year and month variables if undefined.
-        if($year == null)
+        $date = new DateTime();
+
+        if ($year == null)
         {
-            $date = new DateTime();
-            $date->setTime(0,0,0);
-            $year = $date->format('Y');
+            if($date->format("m") == 12 && $date->format("d") >= 26)
+            {
+                $year = $date->modify('+1 year')->format('Y');
+            }
+            else
+            {
+                $year = date('Y');
+            }
         }
 
-        if($month == null)
+        if ($month == null)
         {
-            $date = new DateTime();
-            $date->setTime(0,0,0);
-            if($date->format("j") >= 26)
+            if($date->format("d") >= 26)
             {
                 $month = $date->modify('+1 month')->format('m');
             }
             else
             {
-                $month = $date->format('m');
+                $month = date('m');
             }
         }
 
+        $date = new DateTime();
+        $date->setDate($year,$month,26);
+        $date->setTime(0,0,0);
+
+        $this->view->year = $date->format('Y');
+
+        $this->view->date = $date->format("F Y");
+
+        $currentDate = new DateTime();
+
+        if($currentDate->format('d') >= 26)
+        {
+            $currentDate->modify('+1 month');
+        }
+
+        $this->view->currentMonth = $currentDate->format('m');
+        $this->view->currentYear = $currentDate->format('Y');
+
+        $date->modify('+1 year');
+        $this->view->nextYear = $date->format('Y');
+
+        $date->modify('-2 year');
+        $this->view->previousYear = $date->format('Y');
+
+        $date->modify('+1 year');
+
+        $month = $date->format('m');
+        $this->view->month = $month;
+
+        $date->modify('-1 month');
+        $this->view->previousMonth = $date->format('m');
+        $date->modify('+2 month');
+        $this->view->nextMonth = $date->format('m');
+
         //Load timesheet for user.
         $timesheet = new timesheetModel($year,$month);
 
@@ -138,9 +176,6 @@ class timesheetController extends Staple_Controller
         {
             $this->view->needsValidation = false;
         }
-
-        $changeYearForm = new changeYearForm();
-        $this->view->changeYearForm = $changeYearForm;
     }
 
     public function printpreview($id = null, $year = null, $month = null)

+ 65 - 0
application/forms/layouts/newAccountFormLayout.phtml

@@ -0,0 +1,65 @@
+<div class="row">
+    <?php
+    if(count($this->errorMessage) > 0)
+    {
+
+        echo "<div data-alert class=\"alert-box warning\">";
+        foreach($this->errorMessage as $message)
+        {
+            echo $message;
+        }
+        echo "<a href=\"#\" class=\"close\">&times;</a></div>";
+
+    }
+
+    if(count($this->successMessage) > 0)
+    {
+
+        echo "<div data-alert class=\"alert-box success\">";
+        foreach($this->successMessage as $message)
+        {
+            echo $message;
+        }
+        echo "<a href=\"#\" class=\"close\">&times;</a></div>";
+
+    }
+    ?>
+</div>
+<?php echo $this->formstart(); ?>
+<div class="row">
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['firstName'] ?>
+    </div>
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['lastName'] ?>
+    </div>
+</div>
+<div class="row">
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['supervisor'] ?>
+    </div>
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['type'] ?>
+    </div>
+</div>
+<div class="row">
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['level'] ?>
+    </div>
+</div>
+<div class="row">
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['pinNum'] ?>
+    </div>
+    <div class="small-12 medium-6 columns">
+        <?php echo $this->fields['pinNum2'] ?>
+    </div>
+</div>
+<div class="row">
+    <div class="small-12 columns text-center">
+        <br>
+        <?php echo $this->fields['submit'] ?>
+    </div>
+</div>
+    <?php echo $this->formend(); ?>
+</div>

+ 16 - 6
application/forms/newAccountForm.php

@@ -4,7 +4,7 @@ class newAccountForm extends Staple_Form
 {
     public function _start()
     {
-        //$this->setLayout('accountFormLayout');
+        $this->setLayout('newAccountFormLayout');
 
         $this->setName('newAccount')
             ->setAction($this->link(array('accounts','index')));
@@ -17,13 +17,11 @@ class newAccountForm extends Staple_Form
 
         $firstName = new Staple_Form_FoundationTextElement('firstName','First Name');
         $firstName->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length(1,40))
-            ->addFilter(new Staple_Form_Filter_ToLower());
+            ->addValidator(new Staple_Form_Validate_Length(1,40));
 
         $lastName = new Staple_Form_FoundationTextElement('lastName','Last Name');
         $lastName->setRequired()
-            ->addValidator(new Staple_Form_Validate_Length(1,40))
-            ->addFilter(new Staple_Form_Filter_ToLower());;
+            ->addValidator(new Staple_Form_Validate_Length(1,40));
 
         $supervisor = new Staple_Form_FoundationSelectElement('supervisor','Select a Supervisor');
         $supervisor->setRequired()
@@ -43,10 +41,22 @@ class newAccountForm extends Staple_Form
             ->addOptionsArray(array("100"=>"Standard User","500"=>"Supervisor","900"=>"Administrator"))
             ->addValidator(new Staple_Form_Validate_InArray(array("100","500","900")));
 
+        $pin = new Staple_Form_FoundationTextElement('pinNum','4 Digit PIN');
+        $pin->setRequired()
+            ->addValidator(new Staple_Form_Validate_Length(4,4))
+            ->addValidator(new Staple_Form_Validate_Numeric())
+            ->addAttrib("maxlength","4");
+
+        $pin2 = new Staple_Form_FoundationTextElement('pinNum2','Confirm 4 Digit PIN');
+        $pin2->setRequired()
+            ->addValidator(new Staple_Form_Validate_Length(4,4))
+            ->addValidator(new Staple_Form_Validate_Numeric())
+            ->addAttrib("maxlength","4");
+
         $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
         $submit->addClass('button expand radius');
 
-        $this->addField($firstName, $lastName, $supervisor, $type, $level, $submit);
+        $this->addField($firstName, $lastName, $supervisor, $type, $level, $pin, $pin2, $submit);
     }
 
     public function accounts($ids = null)

+ 2 - 2
application/layouts/main.phtml

@@ -83,8 +83,8 @@
                             <li class=\"has-dropdown\">
                                 <a href=\"#\"><i class='fa fa-file'></i> Time Sheets</a>
                                 <ul class=\"dropdown\">
-                                    <li><a href=\"".$this->link(array('reports')) ."\"><i class=\"fa fa-user\"></i> Active</a></li>
-                                    <li><a href=\"".$this->link(array('reports','inactive'))."\" ><i class=\"fa fa-user\" ></i > Inactive</a ></li>
+                                    <li><a href=\"".$this->link(array('reports')) ."\"><i class=\"fa fa-user\"></i> Active Accounts</a></li>
+                                    <li><a href=\"".$this->link(array('reports','inactive'))."\" ><i class=\"fa fa-user\" ></i > Inactive Accounts</a ></li>
                                 </ul>
                             </li>
                         ";

+ 218 - 0
application/models/accountModel.php

@@ -0,0 +1,218 @@
+<?php
+
+class accountModel extends Staple_Model
+{
+    private $db;
+
+    private $id;
+    private $username;
+    private $password;
+    private $pin;
+    private $tempPin;
+    private $firstName;
+    private $lastName;
+    private $authLevel;
+    private $batchId;
+    private $supervisorId;
+    private $type;
+    private $status;
+
+    /**
+     * @param mixed $id
+     */
+    public function setId($id)
+    {
+        $this->id = $id;
+    }
+
+    /**
+     * @param mixed $username
+     */
+    public function setUsername($username)
+    {
+        $this->username = $username;
+    }
+
+    /**
+     * @param mixed $password
+     */
+    public function setPassword($password)
+    {
+        $this->password = $password;
+    }
+
+    /**
+     * @param mixed $pin
+     */
+    public function setPin($pin)
+    {
+        $this->pin = $pin;
+    }
+
+    /**
+     * @param mixed $firstName
+     */
+    public function setFirstName($firstName)
+    {
+        $this->firstName = $firstName;
+    }
+
+    /**
+     * @param mixed $lastName
+     */
+    public function setLastName($lastName)
+    {
+        $this->lastName = $lastName;
+    }
+
+    /**
+     * @param mixed $authLevel
+     */
+    public function setAuthLevel($authLevel)
+    {
+        $this->authLevel = $authLevel;
+    }
+
+    /**
+     * @param mixed $batchId
+     */
+    public function setBatchId($batchId)
+    {
+        $this->batchId = $batchId;
+    }
+
+    /**
+     * @param mixed $supervisorId
+     */
+    public function setSupervisorId($supervisorId)
+    {
+        $this->supervisorId = $supervisorId;
+    }
+
+    /**
+     * @param mixed $type
+     */
+    public function setType($type)
+    {
+        $this->type = $type;
+    }
+
+    /**
+     * @param mixed $status
+     */
+    public function setStatus($status)
+    {
+        $this->status = $status;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getTempPin()
+    {
+        return $this->tempPin;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getFirstName()
+    {
+        return $this->firstName;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getLastName()
+    {
+        return $this->lastName;
+    }
+
+    function __construct()
+    {
+        $this->db = Staple_DB::get();
+
+    }
+
+    function save()
+    {
+        if(isset($this->id))
+        {
+            //Edit user
+
+        }
+        else
+        {
+            //Build username
+            $username = strtolower(substr($this->firstName,0,1).$this->lastName);
+
+            //Check if username already exists
+            $sql = "SELECT username FROM accounts WHERE username = '".$this->db->real_escape_string($username)."'";
+            $query = $this->db->query($sql);
+            if($query->num_rows == 0)
+            {
+                //Check if PIN already exists
+                $sql = "SELECT pin FROM accounts WHERE pin = '".$this->db->real_escape_string(sha1($this->pin))."'";
+                $query = $this->db->query($sql);
+
+                if($query->num_rows > 0)
+                {
+                    $pin = $this->generatePin();
+                }
+                else
+                {
+                    $pin = $this->pin;
+                }
+
+                $sql = "
+
+                    INSERT INTO accounts (username,password,pin,firstName,lastName,authLevel,batchId,supervisorId,type,status)
+                    VALUES (
+                    '".$this->db->real_escape_string($username)."',
+                    '".$this->db->real_escape_string(sha1('taketime'))."',
+                    '".$this->db->real_escape_string(sha1($pin))."',
+                    '".$this->db->real_escape_string($this->firstName)."',
+                    '".$this->db->real_escape_string($this->lastName)."',
+                    '".$this->db->real_escape_string($this->authLevel)."',
+                    '".$this->db->real_escape_string('0')."',
+                    '".$this->db->real_escape_string($this->supervisorId)."',
+                    '".$this->db->real_escape_string($this->type)."',
+                    '".$this->db->real_escape_string('1')."'
+                    );
+                ";
+
+                if($this->db->query($sql))
+                {
+                    $this->tempPin = $pin;
+                    return true;
+                }
+            }
+        }
+
+    }
+
+    function generatePin()
+    {
+        $pin = array();
+
+        for($i=0;$i<4;$i++)
+        {
+            $pin[$i] = rand(0,9);
+        }
+
+        $pin = implode("",$pin);
+
+        $sql = "SELECT pin FROM accounts WHERE pin = '".$this->db->real_escape_string(sha1($pin))."'";
+        $query = $this->db->query($sql);
+        if($query->num_rows == 0)
+        {
+            return $pin;
+        }
+        else
+        {
+            $this->generatePin();
+        }
+    }
+}
+?>

+ 0 - 2
application/models/userModel.php

@@ -220,8 +220,6 @@
 					$data[] = $result;
 				}
 				return $data;
-
-
 			}
 		}
 

+ 22 - 2
application/views/accounts/index.phtml

@@ -11,6 +11,26 @@
         </div>
     </div>
 
+    <?php
+    if($this->newUser == true)
+    {
+        echo "
+        <div class=\"row\">
+            <div class=\"small-12 columns text-center\">
+            <div data-alert class=\"alert-box success radius\">
+            <h3><i class='fa fa-check'></i> Created account for <b>
+        ";
+        echo $this->firstName." ".$this->lastName."</b>. PIN: <b>".$this->tempPin;
+        echo "
+            </b></h3>
+            <a href=\"#\" class=\"close\">&times;</a>
+            </div>
+            </div>
+        </div>
+        ";
+    }
+    ?>
+
     <div class="row">
         <div class="small-12 columns">
             <table width="100%">
@@ -70,8 +90,8 @@
     </div>
 </div>
 
-<div id="new" class="reveal-modal small" data-reveal aria-labelledby="New ACcount" aria-hidden="true" role="dialog">
+<div id="new" class="reveal-modal small" data-reveal aria-labelledby="NewAccount" aria-hidden="true" role="dialog">
+    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
     <h2 id="modalTitle"><i class="fa fa-plus"></i> New Account</h2>
     <?php echo $this->form ?>
-    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
 </div>

+ 4 - 1
application/views/reports/unlock.phtml

@@ -1,8 +1,11 @@
 <div class="section">
     <div class="row">
-        <div class="small-12 columns">
+        <div class="small-6 columns">
             <h2><i class="fa fa-unlock"></i> Time Unlock</h2>
         </div>
+        <div class="small-6 columns text-right">
+            <h2 class="subheader"><?php echo $this->dateTitle ?></h2>
+        </div>
     </div>
     <div class="row">
         <div class="small-12 columns">

+ 55 - 30
application/views/timesheet/index.phtml

@@ -1,42 +1,73 @@
 <?php echo $this->insertTimeForm ?>
 <div class="section">
     <div class="row">
-        <div class="small-12 medium-4 text-left columns">
-            <h3><i class="fa fa-calendar"></i> <?php echo $this->timesheet->currentMonthText ?> <a href="#" data-reveal-id="yearForm"><?php echo $this->timesheet->currentYear ?></a></h3>
+        <div class="small-6 text-left columns">
+            <h2><i class="fa fa-calendar"></i> <?php echo $this->timesheet->currentMonthText ?> <?php echo $this->timesheet->currentYear ?></h2>
         </div>
-        <div class="small-12 medium-8 text-right columns hide-for-print">
-            <ul class="button-group round even-5 stack-for-small">
-                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->previousMonth)) ?>"><i class="fa fa-caret-left"></i> Prev.</a></li>
-                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->nextMonth)) ?>">Next <i class="fa fa-caret-right"></i></a></li>
-                <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
-                <li><a class="button small" target="_blank" href="<?php echo $this->link(array('timesheet','printpreview',$this->timesheet->userId,$this->timesheet->currentYear,$this->timesheet->currentMonth)) ?>"><i class="fa fa-print"></i> Print</a></li>
+        <div class="small-6 text-right columns">
+            <?php
+            if($this->needsValidation)
+            {
+                echo "<a class=\"button round success\" href=\"".$this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))."\"><i class=\"fa fa-check\"></i> Validate</a>";
+            }
+            ?>
+        </div>
+        <div class="small-12 text-center columns hide-for-print">
+            <ul class="button-group radius even-7">
                 <?php
-                    if($this->needsValidation)
+
+                $year = $this->year;
+
+                if($this->month == 12)
+                {
+                    $year = $this->nextYear;
+                }
+
+                if($this->momth == 1)
+                {
+                    $year = $this->previousYear;
+                }
+                ?>
+
+                <li><a class="button small secondary" href="
+                    <?php
+                    switch ($this->month)
                     {
-                        echo "<li><a class=\"button small success\" href=\"".$this->link(array('timesheet','validate',$this->timesheet->currentYear,$this->timesheet->currentMonth))."\"><i class=\"fa fa-check\"></i> Validate</a></li>";
+                        case 01:
+                            echo $this->link(array('timesheet',$this->previousYear, $this->previousMonth));
+                            break;
+                        default:
+                            echo $this->link(array('timesheet',$this->year, $this->previousMonth));
                     }
-                ?>
+                    ?>
+                    "><i class="fa fa-caret-left"></i> Previous</a></li>
+                <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->currentYear,$this->currentMonth))?>"><i class="fa fa-flag"></i> Current</a></li>
+                <li><a class="button small secondary" href="
+                    <?php
+                    switch ($this->month)
+                    {
+                        case 12:
+                            echo $this->link(array('timesheet',$this->nextYear, $this->nextMonth));
+                            break;
+                        default:
+                            echo $this->link(array('timesheet',$this->year, $this->nextMonth));
+                    }
+                    ?>
+                    ">Next <i class="fa fa-caret-right"></i></a></li>
+                <li><a class="button small secondary" id="hideAll" href="#"><i class="fa fa-eye-slash"></i> Hide All</a></li>
+                <li><a class="button small secondary" id="showAll" href="#"><i class="fa fa-eye"></i> Show All</a></li>
+                <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
+                <li><a class="button small" target="_blank" href="<?php echo $this->link(array('timesheet','printpreview',$this->timesheet->userId,$this->timesheet->currentYear,$this->timesheet->currentMonth)) ?>"><i class="fa fa-print"></i> Print</a></li>
             </ul>
         </div>
     </div><!-- end row -->
 <?php
-    echo "
-        <div class=\"row\">
-            <div class=\"small-12 columns hide-for-print\">
-                <ul class=\"inline-list right\">
-                    <li><a id=\"hideAll\" href=\"#\"><i class=\"fa fa-eye-slash\"></i> Hide All</a></li>
-                    <li><a id=\"showAll\" href=\"#\"><i class=\"fa fa-eye\"></i> Show All</a></li>
-                </ul>
-            </div>
-        </div>
-    ";
-
     if(count($this->timesheet->entries) > 0)
     {
         echo "
-            <div class=\"row\" style=\"margin-bottom:10px;\">
+            <div class=\"row\" style=\"padding-top:20px; padding-bottom:10px; background-color:#ccc;\">
                 <div class=\"small-4 medium-2 columns\">
-                   &nbsp;
+                    <b>Status</b>
                 </div>
                 <div class=\"small-4 medium-2 columns\">
                     <b>Time In</b> <small>(Adjusted)</small>
@@ -144,12 +175,6 @@
 ?>
 </div><!-- end section -->
 
-<div id="yearForm" class="reveal-modal small" data-reveal aria-labelledby="Change Year" aria-hidden="true" role="dialog">
-    <h2 id="modalTitle">Select a Year</h2>
-    <?php echo $this->changeYearForm ?>
-    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
-</div>
-
 <div id="totals" class="totalsPanel">
     <div class="row">
         <div class="small-10 columns">