-
Notifications
You must be signed in to change notification settings - Fork 0
/
next_check.php
executable file
·63 lines (50 loc) · 1.79 KB
/
next_check.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
Check if entries are valid when level 0 user clicks 0.
*/
# Initialize variables
$error = '';
$info = '';
if(isset($_POST['next'])) { # If next was clicked
$number_of_items = count($_POST['item']) - 1; # Ommitting last one because of hidden element in HTML
$success_count = 0;
$temp_array = array();
for($i = 0 ; $i < $number_of_items ; $i ++) {
$current_success = 1;
if(floatval($_POST['qty'][$i]) <= 0.0) { # Quantity provided was 0
$error .= " Quantity must be greater than 0.";
$current_success = 0;
break;
}
if(in_array($_POST['item'][$i], $temp_array)) {
$error .= " Please check for repeated items.";
$current_success = 0;
break;
}
$success_count += $current_success;
array_push($temp_array, $_POST['item'][$i]);
}
$pass_1 = 1;
if(strcmp($_POST['forwarded_user'], 'Please Select') == 0) { # Not selected any user
$pass_1 = 0;
$error .= " Please select a valid user to forward.";
}
$pass_2 = 1;
if(strcmp($_POST['supplier'], 'Please Select') == 0) { # Not selected anu supplier
$pass_2 = 0;
$error .= ' Please select a valid supplier.';
}
if($success_count == $number_of_items && $pass_1 == 1 && $pass_2 == 1) { # All entries are valid
# Set session variables upon slicing last element of array
$_SESSION['valid_next_item_entry'] = 1;
$_SESSION['item'] = array_slice($_POST['item'], 0, -1);
$_SESSION['unit'] = array_slice($_POST['unit'], 0, -1);
$_SESSION['qty'] = array_slice($_POST['qty'], 0, -1);
$_SESSION['desc'] = array_slice($_POST['desc'], 0, -1);
$_SESSION['forwarded_user'] = $_POST['forwarded_user'];
$_SESSION['supplier'] = $_POST['supplier'];
# Redirect to next page
header("Location: submit_item.php");
}
}
?>