-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateDocs.php
executable file
·155 lines (136 loc) · 4.96 KB
/
updateDocs.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
ob_start();
include 'checkUser.php';
if (!canEdit()){
header('Location: ./consult.php');
exit();
}
include 'connectionFactory.php';
$mysqli= ConnectionFactory::GetConnection();
if(isset($_GET['id'])){
$id=$_GET['id'];
$origin=$_GET['o'];
} else {
$id=$_POST['id'];
$origin=$_POST['o'];
}
$query = 'SELECT
RecordTypeId,
Reg_Individual.IdCard,
Reg_Individual.IdCard2,
Reg_Legal.IdCard_1,
Reg_Legal.IdCard_2,
Reg_Legal.IdCard_3,
Reg_Legal.IdCard_4,
Reg_Legal.IdCard_5,
Reg_Legal.IdCard_6,
Reg_Legal.IdCard_7,
Reg_Legal.IdCard_8,
Reg_Legal.IdCard_9,
Reg_Legal.IdCard_10,
Reg_Legal.IdCard_11,
Reg_Legal.IdCard_12,
Reg_Legal.FinState_1,
Reg_Legal.FinState_2,
Reg_Legal.FinState_3,
Reg_Legal.Registration_1,
Reg_Legal.Registration_2,
Reg_Legal.Registration_3
FROM Reg_Person
LEFT OUTER JOIN Reg_Individual on Reg_Individual.Id=Reg_Person.Id
LEFT OUTER JOIN Reg_Legal on Reg_Legal.Id=Reg_Person.Id
WHERE Reg_Person.Id = ?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("i",$id);
$stmt->bind_result($type, $IdCard,$IdCard2,
$IdCard_1,$IdCard_2,$IdCard_3,$IdCard_4,$IdCard_5,$IdCard_6,
$IdCard_7,$IdCard_8,$IdCard_9,$IdCard_10,$IdCard_11,$IdCard_12, $FinState_1,$FinState_2,$FinState_3,$Registration_1,$Registration_2,$Registration_3);
$stmt->execute();
$stmt->fetch();
$stmt->close();
$cards=[$IdCard_1,$IdCard_2,$IdCard_3,$IdCard_4,$IdCard_5,$IdCard_6,
$IdCard_7,$IdCard_8,$IdCard_9,$IdCard_10,$IdCard_11,$IdCard_12];
$fs=[$FinState_1,$FinState_2,$FinState_3];
$rs=[$Registration_1,$Registration_2,$Registration_3];
$folder = './Data/img_'.$id.'/';
if (isset($_GET['id']) && isset($_GET['tp']) && isset($_GET['ind'])){
$file_to_delete='';
$field='';
if ($type==1){
if ($_GET['tp']=='c'){
$field='IdCard_'.$_GET['ind'];
$file_to_delete=$cards[$_GET['ind']-1];
} else if ($_GET['tp']=='ef'){
$field='FinState_'.$_GET['ind'];
$file_to_delete=$fs[$_GET['ind']-1];
} else if ($_GET['tp']=='r'){
$field='Registration_'.$_GET['ind'];
$file_to_delete=$rs[$_GET['ind']-1];
}
if ($file_to_delete!=''){
$query = 'UPDATE Reg_Legal set '.$field.'="" WHERE Id=?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->close();
unlink($folder.$file_to_delete);
}
} else {
if ($IdCard2!=''){
$query = 'UPDATE Reg_Individual set IdCard2="" WHERE Id=?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->close();
unlink($folder.$IdCard2);
}
}
}
if (isset($_POST['id']) && isset($_POST['tp']) && isset($_POST['ind'])){
$ext = pathinfo($_FILES['img']['name'], PATHINFO_EXTENSION);
$new_file_name = uniqid('img_'.$_POST['tp'].'_').'.'.$ext;
$new_file = $folder.$new_file_name;
move_uploaded_file($_FILES['img']['tmp_name'], $new_file);
if ($type==1){
if ($_POST['tp']=='c'){
$field='IdCard_'.$_POST['ind'];
$file_to_delete=$cards[$_POST['ind']-1];
} else if ($_POST['tp']=='ef'){
$field='FinState_'.$_POST['ind'];
$file_to_delete=$fs[$_POST['ind']-1];
} else if ($_POST['tp']=='r'){
$field='Registration_'.$_POST['ind'];
$file_to_delete=$rs[$_POST['ind']-1];
}
if ($file_to_delete!=''){
unlink($folder.$file_to_delete);
}
$query = 'UPDATE Reg_Legal set '.$field.'=? WHERE Id=?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("si",$new_file_name,$id);
$stmt->execute();
$stmt->close();
} else {
if ($_POST['ind']==1) {
if ($IdCard!=''){
unlink($folder.$IdCard);
}
$query = 'UPDATE Reg_Individual set IdCard=? WHERE Id=?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("si",$new_file_name,$id);
$stmt->execute();
$stmt->close();
} else {
if ($IdCard2!=''){
unlink($folder.$IdCard2);
}
$query = 'UPDATE Reg_Individual set IdCard2=? WHERE Id=?';
$stmt = $mysqli->prepare($query);
$stmt->bind_param("si",$new_file_name,$id);
$stmt->execute();
$stmt->close();
}
}
}
header('Location: ./docs.php?id='.$id.'&o='.$origin);
?>