Equipment_loan::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class Equipment_loan extends My_Force_Login {
4
5
    public function __construct() {
6
        parent::__construct();
7
        $this->load->library('grocery_CRUD');
8
        $this->load->model('computing-support/Equipment_loan_model', 'equipment_loan_model');
9
    }
10
11
    public function index() {
12
        
13
        if (in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
14
15
            $this->load->helper('form');
16
            $this->load->library('form_validation');
17
18
            // validation rules
19
            $this->form_validation->set_rules('full_name', 'First Name', 'trim|required|min_length[3]');
20
            $this->form_validation->set_rules('ern', 'ERN', 'trim|required|min_length[7]');
21
            $this->form_validation->set_rules('make', 'Make', 'trim|required|min_length[3]');
22
            $this->form_validation->set_rules('model', 'Model', 'trim|required|min_length[3]');
23
            $this->form_validation->set_rules('sn', 'Serial Number', 'trim|required|min_length[3]');
24
25
            if ($this->form_validation->run() === false) {
26
27
                $this->load->view('templates/header');
28
                $this->load->view('computing-support/equipment-loan/view');
29
                $this->load->view('templates/footer');
30
            } else {
31
32
                $logged = $this->input->post('logged');
33
                $first_name = $this->input->post('full_name');
0 ignored issues
show
Unused Code introduced by
$first_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
                $ern = $this->input->post('ern');
35
                $make = $this->input->post('make');
36
                $model = $this->input->post('model');
37
                $sn = $this->input->post('sn');
38
39 View Code Duplication
                if ($this->equipment_loan_model->loan($logged, $full_name, $ern, $make, $model, $sn)) {
0 ignored issues
show
Bug introduced by
The variable $full_name does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
                    
41
                    $function = 'new_loan';
42
                    $this->user_model->function_log($function);
43
44
                    // user created
45
                    $this->load->view('templates/header');
46
                    $this->load->view('computing-support/equipment-loan/complete');
47
                    $this->load->view('templates/footer');
48
                } else {
49
                    
50
                    $function = 'new_loan_error';
51
                    $this->user_model->function_log($function);
52
53
                    $data = new stdClass();
54
                    $data->error = 'There was a problem accepting the terms. Please try again.';
55
56
                    // failed to create user
57
                    $this->load->view('templates/header');
58
                    $this->load->view('computing-support/equipment-loan/view', $data);
59
                    $this->load->view('templates/footer');
60
                }
61
            }
62
        } else {
63
            redirect('permissions');
64
        }
65
    }
66
    
67
    public function history() {
68
        
69
        if (in_array('CN=Dashboard_Admin,OU=Dashboard_Group,OU=Intranet_Group,OU=Groups,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups']) || 
70
            in_array('CN=DG06,OU=Distribution Groups,OU=Email Groups,OU=Accounts,DC=cant-col,DC=ac,DC=uk', $_SESSION['ldap']['groups'])) {
71
        
72
            $crud = new grocery_CRUD();
73
            $crud->set_table('equipment_loan');
74
            $crud->set_subject('Equipment Loan', 'Equipment Loan');
75
            $crud->unset_columns('id'); 
76
            $crud->display_as('ern','ER no.')
77
                 ->display_as('sn','Serial Number');
78
            $crud->unset_edit_fields('logged', 'date'); 
79
            $crud->unset_add();
80
            $crud->unset_read();
81
            $output = $crud->render();
82
83
            $this->load->view('templates/header.php');
84
            $this->load->view('computing-support/equipment-loan/history', $output);
85
            $this->load->view('templates/footer.php');
86
            $this->load->view('templates/table_assets.php', $output);
87
            
88
        } else {
89
            redirect('permissions');
90
        }
91
        
92
    }
93
}
94