-
Notifications
You must be signed in to change notification settings - Fork 0
/
editUserData.php
executable file
·78 lines (62 loc) · 2.15 KB
/
editUserData.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php require('core/init.php'); ?>
<?php
if (!isset($_SESSION['user_name'])) {
redirect('index.php', 'Niste prijavljeni na sistem', 'error');
} else {
// Create Company Object
$editCompany = new EditCompany;
// Create Company Object
$company = new Company;
//Create Validator object
$validate = new Validator;
// Get Template
$template = new Template('templates/editUserData.php');
//Get Vars
$companyId = $_SESSION['company_id'];
// Get values and forvard to template
$template->centralUsers = $company->getCentralUsers($companyId);
$template->retailUsers = $company->getRetailUsers($companyId);
$template->erpUsers = $company->getErpUsers($companyId);
$template->ipAddress = $company->getIpAdr($companyId);
$template->transponder = $company->getTrans($companyId);
// Collect all posible submit Id's
$usersData = $editCompany->getAllUserData($companyId);
foreach ($usersData as $userData) {
if (isset($_POST['editData' . $userData->id])) {
// Sanitize POST data
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
//Get Vars
$data = [
'userId' => $userData->id,
'userCompany_id' => $userData->company_id,
'userName' => trim($_POST['userName']),
'userPassword' => trim($_POST['userPassword']),
'userTestPassword' => trim($_POST['userTestPassword'])
];
//Required array
$field_array = array('userName', 'userPassword');
if ($validate->isRequired($field_array)) {
if ($editCompany->editUserData($data)) {
redirect('editUserData.php', 'Uspešno ste izmenili podatak', 'success');
} else {
redirect('editUserData.php', 'Izmena podatka nije uspela', 'error');
}
} else {
redirect('editUserData.php', 'Molim vas popunite sva obavezna polja', 'error');
}
} elseif (isset($_POST['deleteData' . $userData->id])){
//Get Vars
$data = [
'userId' => $userData->id,
'userCompany_id' => $userData->company_id
];
if ($editCompany->deleteUserData($data)) {
redirect('editUserData.php', 'Uspešno ste obrisali podatak', 'success');
} else {
redirect('editUserData.php', 'Brisanje podatka nije uspelo', 'error');
}
}
}
// Display template
echo $template;
}