-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheda_write.php
More file actions
59 lines (55 loc) · 1.44 KB
/
eda_write.php
File metadata and controls
59 lines (55 loc) · 1.44 KB
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
<?php
include 'connect.php';
$action = $_POST['action'];
$id = $_POST['id'];
if ( $action != 'delete' )
{
$name = $_POST['name'];
$ip = $_POST['ip'];
$mac = $_POST['mac'];
$dest = $_POST['dest'];
$aclvl = $_POST['aclvl'];
if ( $action == 'add' )
{
$uniq = checkUniq($name, $ip, $mac, $id); //в данном случае id = -1
if ( !$uniq )
if ( mysqli_query($sql_link, "INSERT INTO users (`name`, `ip`, `mac`, `destination`, `accesslvl`) VALUES ('$name', '$ip', '$mac', '$dest', '$aclvl')") )
echo 0;
else
echo -1;
else
echo $uniq;
}
else if ( $action == 'edit' )
{
$uniq = checkUniq($name, $ip, $mac, $id);
if ( !$uniq )
if ( mysqli_query($sql_link, "UPDATE users SET `name`='$name', `ip`='$ip', `mac`='$mac', `destination`='$dest', `accesslvl`='$aclvl' WHERE `id`='$id'") )
echo 0;
else
echo -1;
else
echo $uniq;
}
}
else
{
if ( mysqli_query($sql_link, "DELETE FROM users WHERE `id`='$id'") )
echo 0;
else
echo -1;
}
function checkUniq($name, $ip, $mac, $id)
{
global $sql_link;
$flag = 0;
if (mysqli_num_rows(mysqli_query($sql_link, "SELECT * FROM users WHERE name='$name' AND id<>'$id'")) > 0)
$flag|=0b001;
if (mysqli_num_rows(mysqli_query($sql_link, "SELECT * FROM users WHERE ip='$ip' AND id<>'$id'")) > 0)
$flag|=0b010;
if (mysqli_num_rows(mysqli_query($sql_link, "SELECT * FROM users WHERE mac='$mac' AND id<>'$id'")) > 0)
$flag|=0b100;
return $flag;
}
mysqli_close($sql_link);
?>