-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.php
125 lines (111 loc) · 2.94 KB
/
index.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
require_once('MysqliDb.php');
error_reporting(E_ALL);
$action = 'adddb';
$data = array();
function printUsers () {
global $db;
$users = $db->get ("users");
if ($db->count == 0) {
echo "<td align=center colspan=4>No users found</td>";
return;
}
foreach ($users as $u) {
echo "<tr>
<td>{$u['id']}</td>
<td>{$u['login']}</td>
<td>{$u['firstName']} {$u['lastName']}</td>
<td>
<a href='index.php?action=rm&id={$u['id']}'>rm</a> ::
<a href='index.php?action=mod&id={$u['id']}'>ed</a>
</td>
</tr>";
}
}
function action_adddb () {
global $db;
$data = Array(
'login' => $_POST['login'],
'customerId' => 1,
'firstName' => $_POST['firstName'],
'lastName' => $_POST['lastName'],
'password' => $db->func('SHA1(?)',Array ($_POST['password'] . 'salt123')),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y')
);
$id = $db->insert ('users', $data);
header ("Location: index.php");
exit;
}
function action_moddb () {
global $db;
$data = Array(
'login' => $_POST['login'],
'customerId' => 1,
'firstName' => $_POST['firstName'],
'lastName' => $_POST['lastName'],
);
$id = (int)$_POST['id'];
$db->where ("customerId",1);
$db->where ("id", $id);
$db->update ('users', $data);
header ("Location: index.php");
exit;
}
function action_rm () {
global $db;
$id = (int)$_GET['id'];
$db->where ("customerId",1);
$db->where ("id", $id);
$db->delete ('users');
header ("Location: index.php");
exit;
}
function action_mod () {
global $db;
global $data;
global $action;
$action = 'moddb';
$id = (int)$_GET['id'];
$db->where ("id", $id);
$data = $db->getOne ("users");
}
$db = new Mysqlidb ('localhost', 'root', '', 'testdb');
if ($_GET) {
$f = "action_".$_GET['action'];
if (function_exists ($f)) {
$f();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Users</title>
</head>
<body>
<center>
<h3>Users:</h3>
<table width='50%'>
<tr bgcolor='#cccccc'>
<th>ID</th>
<th>Login</th>
<th>Name</th>
<th>Action</th>
</tr>
<?php printUsers();?>
</table>
<hr width=50%>
<form action='index.php?action=<?php echo $action?>' method=post>
<input type=hidden name='id' value='<?php echo $data['id']?>'>
<input type=text name='login' required placeholder='Login' value='<?php echo $data['login']?>'>
<input type=text name='firstName' required placeholder='First Name' value='<?php echo $data['firstName']?>'>
<input type=text name='lastName' required placeholder='Last Name' value='<?php echo $data['lastName']?>'>
<input type=password name='password' placeholder='Password'>
<input type=submit value='New User'></td>
</form>
</table>
</center>
</body>
</html>