Преглед на файлове

Started adding the accounts views

Adam Day преди 9 години
родител
ревизия
38817ae65f

+ 39 - 1
application/controllers/accountsController.php

@@ -16,7 +16,45 @@ class accountsController extends Staple_Controller
 
     public function index()
     {
-        echo "Accounts";
+        $accounts = new userModel();
+        $this->view->accounts = $accounts->listActive();
+        $this->view->allAccounts = $accounts->listAll();
+
+        $form = new newAccountForm();
+
+        if($form->wasSubmitted())
+        {
+            $form->addData($_POST);
+            if($form->validate())
+            {
+                $data = $form->exportFormData();
+
+                print_r($data);
+
+                $account = substr($data['firstName'],0,1).$data['lastName'];
+                echo $account;
+
+                $form = new newAccountForm();
+                $this->view->form = $form;
+            }
+            else
+            {
+                $this->view->form = $form;
+                $this->layout->addScriptBlock('$(document).ready(function() { $("#new").foundation("reveal", "open"); }); ');
+            }
+        }
+        else
+        {
+            $this->view->form = $form;
+        }
+
+    }
+
+    public function inactive()
+    {
+        $accounts = new userModel();
+        $this->view->accounts = $accounts->listInactive();
+        $this->view->allAccounts = $accounts->listAll();
     }
 }
 

+ 77 - 0
application/forms/newAccountForm.php

@@ -0,0 +1,77 @@
+<?php
+
+class newAccountForm extends Staple_Form
+{
+    public function _start()
+    {
+        //$this->setLayout('accountFormLayout');
+
+        $this->setName('newAccount')
+            ->setAction($this->link(array('accounts','index')));
+
+        $pin = new Staple_Form_FoundationPasswordElement('pin','User PIN');
+        $pin->setRequired()
+            ->addAttrib("readonly","true")
+            ->addValidator(new Staple_Form_Validate_Length(1,4))
+            ->addValidator(new Staple_Form_Validate_Numeric());
+
+        $firstName = new Staple_Form_FoundationTextElement('firstName','First Name');
+        $firstName->setRequired()
+            ->addValidator(new Staple_Form_Validate_Length(1,40))
+            ->addFilter(new Staple_Form_Filter_ToLower());
+
+        $lastName = new Staple_Form_FoundationTextElement('lastName','Last Name');
+        $lastName->setRequired()
+            ->addValidator(new Staple_Form_Validate_Length(1,40))
+            ->addFilter(new Staple_Form_Filter_ToLower());;
+
+        $supervisor = new Staple_Form_FoundationSelectElement('supervisor','Select a Supervisor');
+        $supervisor->setRequired()
+            ->addOption("0","Select an account")
+            ->addOptionsArray($this->accounts())
+            ->addValidator(new Staple_Form_Validate_InArray($this->accounts(1)));
+
+        $type = new Staple_Form_FoundationSelectElement('type','Set Account Type');
+        $type->setRequired()
+            ->addOption("","Select an account")
+            ->addOptionsArray(array("part"=>"Part Time","full"=>"Full Time"))
+            ->addValidator(new Staple_Form_Validate_InArray(array("part","full")));
+
+        $level = new Staple_Form_FoundationSelectElement('level','Set Account Level');
+        $level->setRequired()
+            ->addOption("","Select a level")
+            ->addOptionsArray(array("100"=>"Standard User","500"=>"Supervisor","900"=>"Administrator"))
+            ->addValidator(new Staple_Form_Validate_InArray(array("100","500","900")));
+
+        $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
+        $submit->addClass('button expand radius');
+
+        $this->addField($firstName, $lastName, $supervisor, $type, $level, $submit);
+    }
+
+    public function accounts($ids = null)
+    {
+        $accounts = new userModel();
+        $users = $accounts->listAll();
+        $data = array();
+
+        foreach($users as $user)
+        {
+            if($user['authLevel'] >= 500)
+            {
+                if($ids == 1)
+                {
+                    $data[] = $user['id'];
+                }
+                else
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']."";
+                }
+            }
+        }
+
+        return $data;
+    }
+}
+
+?>

+ 30 - 21
application/layouts/main.phtml

@@ -42,47 +42,56 @@
                 <!-- Right Nav Section -->
                 <ul class="left">
                     <li><a href="<?php echo $this->link(array('index')) ?>"><i class="fa fa-dashboard"></i> Your Dashboard</a></li>
-                    <li><a href="<?php echo $this->link(array('timesheet')) ?>"><i class="fa fa-clock-o"></i> Your Timesheet</a></li>
+                    <li><a href="<?php echo $this->link(array('timesheet')) ?>"><i class="fa fa-clock-o"></i> Your Time Sheet</a></li>
                 </ul>
 
                 <!-- Right Nav Section -->
                 <ul class="right">
-                    <?php
-
-                    //Supervisor Accounts
-                    if($user->getAuthLevel() >= 500)
-                    {
-                        echo "
-                            <li><a href=\"".$this->link(array('reports')) ."\"><i class=\"fa fa-file\"></i> Staff Timesheets</a></li>
-                        ";
-                    }
-
-                    ?>
-
                     <?php
                         //Administrative Accounts
                         if($user->getAuthLevel() >= 900)
                         {
                             echo "
+                            <li><a href=\"".$this->link(array('accounts')) ."\"><i class=\"fa fa-users\"></i> Accounts</a></li>
                             <li class=\"has-dropdown\">
-                                <a href=\"#\"><i class='fa fa-gear'></i> Admin Tools</a>
+                                <a href=\"#\"><i class='fa fa-file'></i> Reports</a>
                                 <ul class=\"dropdown\">
-                                    <li><a href=\"".$this->link(array('accounts')) ."\"><i class=\"fa fa-users\"></i> Accounts</a></li>
-                                    <li><a href=\"".$this->link(array('timesheet','admininsert'))."\" ><i class=\"fa fa-plus\" ></i > Admin Time Insert </a ></li >
-                                    <li><a href=\"".$this->link(array('reports','unlock'))."\"><i class=\"fa fa-unlock\"></i> Time Unlock</a></li>
+                                    <li><a href=\"".$this->link(array('reports','payroll'))."\"><i class=\"fa fa-file\"></i> Month Totals</a></li>
+                                    <li><a href=\"".$this->link(array('reports','payperiod'))."\"><i class=\"fa fa-file\"></i> Daily Totals</a></li>
+                                    <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li>
                                 </ul>
                             </li>
+
                             <li class=\"has-dropdown\">
-                                <a href=\"#\"><i class='fa fa-file'></i> Admin Reports</a>
+                                <a href=\"#\"><i class='fa fa-gear'></i> Tools</a>
                                 <ul class=\"dropdown\">
-                                    <li><a href=\"".$this->link(array('reports','payroll'))."\"><i class=\"fa fa-file\"></i> Month Totals</a></li>
-                                    <li><a href=\"".$this->link(array('reports','payperiod'))."\"><i class=\"fa fa-file\"></i> Daily Totals</a></li>
-                                    <li><a href=\"".$this->link(array('audit')) ."\" ><i class=\"fa fa-list-alt\" ></i > Audit Log</a ></li>
+                                    <li><a href=\"".$this->link(array('timesheet','admininsert'))."\" ><i class=\"fa fa-plus\" ></i > Time Insert </a ></li >
+                                    <li><a href=\"".$this->link(array('reports','unlock'))."\"><i class=\"fa fa-unlock\"></i> Time Unlock</a></li>
                                 </ul>
                             </li>
+
                             ";
                         }
                     ?>
+
+                    <?php
+
+                    //Supervisor Accounts
+                    if($user->getAuthLevel() >= 500)
+                    {
+                        echo "
+                            <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>
+                                </ul>
+                            </li>
+                        ";
+                    }
+
+                    ?>
+
                     <li><a href="<?php echo $this->link(array('account','logout')) ?>"><i class="fa fa-close"></i> Logout</a></li>
                 </ul>
             </section>

+ 2 - 2
application/models/reportModel.php

@@ -45,13 +45,13 @@ class reportModel extends Staple_Model
         if($authLevel >= 900)
         {
             $sql = "
-            SELECT id, firstName, lastName FROM accounts WHERE 1 ORDER BY lastName ASC
+            SELECT id, firstName, lastName FROM accounts WHERE status = 1 ORDER BY lastName ASC
             ";
         }
         else
         {
             $sql = "
-            SELECT id, firstName, lastName FROM accounts WHERE supervisorId = '".$this->db->real_escape_string($userId)."' ORDER BY lastName ASC
+            SELECT id, firstName, lastName FROM accounts WHERE status = 1 AND supervisorId = '".$this->db->real_escape_string($userId)."' ORDER BY lastName ASC
             ";
         }
 

+ 33 - 3
application/models/userModel.php

@@ -187,7 +187,7 @@
 
 		function userInfo($id)
 		{
-			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type FROM accounts WHERE id = '".$this->db->real_escape_string($id)."'";
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type, status FROM accounts WHERE id = '".$this->db->real_escape_string($id)."'";
 			$query = $this->db->query($sql);
 			$result = $query->fetch_assoc();
 			return $result;
@@ -195,8 +195,7 @@
 
 		function listAll()
 		{
-			$userId = $this->id;
-			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type FROM accounts ORDER BY type DESC, lastName ASC, firstName ASC";
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type, status FROM accounts ORDER BY type DESC, lastName ASC, firstName ASC";
 			if($this->db->query($sql)->num_rows > 0)
 			{
 				$query = $this->db->query($sql);
@@ -208,7 +207,38 @@
 
 
 			}
+		}
+
+		function listActive()
+		{
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type, status FROM accounts WHERE status = 1 ORDER BY type DESC, lastName ASC, firstName ASC";
+			if($this->db->query($sql)->num_rows > 0)
+			{
+				$query = $this->db->query($sql);
+				while($result = $query->fetch_assoc())
+				{
+					$data[] = $result;
+				}
+				return $data;
 
+
+			}
+		}
+
+		function listInactive()
+		{
+			$sql = "SELECT id, username, firstName, lastName, authLevel, batchId, supervisorId, type, status FROM accounts  WHERE status = 0 ORDER BY type DESC, lastName ASC, firstName ASC";
+			if($this->db->query($sql)->num_rows > 0)
+			{
+				$query = $this->db->query($sql);
+				while($result = $query->fetch_assoc())
+				{
+					$data[] = $result;
+				}
+				return $data;
+
+
+			}
 		}
 	}
 ?>

+ 76 - 0
application/views/accounts/inactive.phtml

@@ -0,0 +1,76 @@
+<div class="section">
+    <div class="row">
+        <div class="small-6 columns">
+            <h1><i class="fa fa-users"></i> Accounts <small>Inactive</small></h1>
+        </div>
+        <div class="small-6 columns text-right">
+            <ul class="button-group round">
+                <li><a class="button secondary" href="<?php echo $this->link(array('accounts')) ?>"><i class="fa fa-user"></i> Show Active</a></li>
+            </ul>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="small-12 columns">
+            <table width="100%">
+                <tr>
+                    <th>Account</th>
+                    <th>Type</th>
+                    <th>Status</th>
+                    <th>Supervisor</th>
+                    <th>Action</th>
+                </tr>
+                <?php
+                if(count($this->accounts) > 0)
+                {
+                    foreach($this->accounts as $account)
+                    {
+                        switch($account['type'])
+                        {
+                            case "part":
+                                $type = "Part Time";
+                                break;
+                            case "full":
+                                $type = "Full Time";
+                                break;
+                            default:
+                                $type = " - ";
+                        }
+
+                        switch($account['status'])
+                        {
+                            case 0:
+                                $status = "Inactive";
+                                break;
+                            case 1:
+                                $status = "Active";
+                                break;
+                            default:
+                                $status = " - ";
+                        }
+
+                        foreach($this->allAccounts as $allAccount)
+                        {
+                            if($allAccount['id'] == $account['supervisorId'])
+                            {
+                                $supervisor = $allAccount['lastName'].", ".$allAccount['firstName'];
+                            }
+                        }
+
+                        echo "
+                            <tr>
+                                <td>".$account['lastName'].", ".$account['firstName']."</td>
+                                <td>$type</td>
+                                <td>$status</td>
+                                <td>$supervisor</td>
+                                <td><a href=\"".$this->link(array('accounts','edit',$account['id']))."\">Edit</a></td>
+                            </tr>
+                        ";
+                    }
+                }
+                ?>
+
+            </table>
+        </div>
+    </div>
+</div>

+ 77 - 0
application/views/accounts/index.phtml

@@ -0,0 +1,77 @@
+<div class="section">
+    <div class="row">
+        <div class="small-6 columns">
+            <h1><i class="fa fa-users"></i> Accounts <small>Active</small></h1>
+        </div>
+        <div class="small-6 columns text-right">
+            <ul class="button-group round">
+                <li><a class="button secondary" href="<?php echo $this->link(array('accounts','inactive')) ?>"><i class="fa fa-user-times"></i> Show Inactive</a></li>
+                <li><a class="button success" data-reveal-id="new" href="#"><i class="fa fa-plus"></i> New Account</a></li>
+            </ul>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="small-12 columns">
+            <table width="100%">
+                <tr>
+                    <th>Account</th>
+                    <th>Type</th>
+                    <th>Status</th>
+                    <th>Supervisor</th>
+                    <th>Action</th>
+                </tr>
+            <?php
+            if(count($this->accounts) > 0) {
+                foreach ($this->accounts as $account) {
+                    switch ($account['type']) {
+                        case "part":
+                            $type = "Part Time";
+                            break;
+                        case "full":
+                            $type = "Full Time";
+                            break;
+                        default:
+                            $type = " - ";
+                    }
+
+                    switch ($account['status']) {
+                        case 0:
+                            $status = "Inactive";
+                            break;
+                        case 1:
+                            $status = "Active";
+                            break;
+                        default:
+                            $status = " - ";
+                    }
+
+                    foreach ($this->allAccounts as $allAccount) {
+                        if ($allAccount['id'] == $account['supervisorId']) {
+                            $supervisor = $allAccount['lastName'] . ", " . $allAccount['firstName'];
+                        }
+                    }
+
+                    echo "
+                        <tr>
+                            <td>" . $account['lastName'] . ", " . $account['firstName'] . "</td>
+                            <td>$type</td>
+                            <td>$status</td>
+                            <td>$supervisor</td>
+                            <td><a href=\"" . $this->link(array('accounts', 'edit', $account['id'])) . "\">Edit</a></td>
+                        </tr>
+                    ";
+                }
+            }
+            ?>
+
+            </table>
+        </div>
+    </div>
+</div>
+
+<div id="new" class="reveal-modal small" data-reveal aria-labelledby="New ACcount" aria-hidden="true" role="dialog">
+    <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 - 4
application/views/reports/index.phtml

@@ -1,9 +1,9 @@
 <div class="section">
     <div class="row">
-        <div class="small-6 columns">
-            <h1><i class="fa fa-file"></i> Reports</h1>
+        <div class="small-7 columns">
+            <h1><i class="fa fa-file"></i>Time Sheets <small>Active</small></h1>
         </div>
-        <div class="small-6 columns text-right">
+        <div class="small-5 columns text-right">
             <h1 class="subheader"><?php echo $this->monthName ?> <?php echo $this->year?></h1>
         </div>
     </div>
@@ -129,7 +129,7 @@
 
                     if($this->accountLevel >= 900)
                     {
-                        echo "<td><a class='button tiny radius warning' href=\"".$this->link(array('timesheet','remove',$key))."\"><i class=\"fa fa-trash\"></i> Delete</a></td>";
+                        echo "<td><a href=\"".$this->link(array('timesheet','remove',$key))."\"><i class=\"fa fa-trash\"></i> Remove</a></td>";
                     }
 
                     echo "</tr>";