forked from devlab-oy/pupesoft
/
tiedostotallennus.php
207 lines (172 loc) · 5.95 KB
/
tiedostotallennus.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
if (@include "inc/parametrit.inc") {
}
elseif (@include "parametrit.inc") {
}
else {
exit;
}
require_once "tiedostofunkkarit.inc";
echo "<font class='head'>" . t('Tiedostojen tallennus') . "</font>";
echo "<hr>";
$tee = isset($tee) ? $tee : "";
$selite = isset($selite) ? $selite : "";
$aihealue = isset($aihealue) ? $aihealue : "";
$tiedostotyyppi = isset($tiedostotyyppi) ? $tiedostotyyppi : "";
$listaa_tiedostot = isset($listaa_tiedostot) ? $listaa_tiedostot : "";
$poistettava_tiedosto = isset($poistettava_tiedosto) ? $poistettava_tiedosto : "";
$tallenna_nappi = isset($tallenna_nappi) ? $tallenna_nappi : "";
$tiedosto = isset($_FILES["tiedosto"]) ? $_FILES["tiedosto"] : "";
if ($tee == "poista") {
poista_liitetiedosto($poistettava_tiedosto, $aihealue, $tiedostotyyppi);
$tee = "";
}
if ($tee == "tallenna_tiedosto" and
!empty($tiedosto["tmp_name"]) and
!empty($selite) and
!empty($aihealue) and
!empty($tiedostotyyppi)
) {
if (tallenna_liite("tiedosto", "muut_tiedostot", 0, $selite, "{$aihealue} | {$tiedostotyyppi}")) {
echo "<font class='ok'>" . t("Tiedosto tallennettu onnistuneesti") . "</font>";
}
$tee = "";
}
if (!empty($tiedostotyyppi) and empty($tiedosto["tmp_name"]) and $tallenna_nappi) {
echo "<font class='error'>" . t("Sinun täytyy valita tiedosto") . "</font>";
$tee = "";
}
elseif (!empty($tiedostotyyppi) and empty($selite) and $tallenna_nappi) {
echo "<font class='error'>" . t("Sinun täytyy valita tiedostolle selite") . "</font>";
$tee = "";
}
if ($tee == "tallenna_tiedosto" and !empty($aihealue)) {
$tee = "";
}
if ($tee == "") {
$aihealueet = hae_aihealueet();
$params = array(
"tiedoston_tyyppi" => $tiedostotyyppi,
"aihealue" => $aihealue
);
$tiedostot = hae_tiedostot($params);
if (!empty($aihealueet)) {
piirra_formi($aihealue, $tiedostotyyppi, $aihealueet);
if ($tiedostot) {
piirra_tiedostolista($tiedostot, $aihealue, $tiedostotyyppi);
}
}
else {
echo "<font class='error'>" . t("Et ole vielä lisännyt aihealueita avainsanoihin") . "</font>";
}
}
function piirra_formi($valittu_aihealue, $valittu_tiedostotyyppi, $aihealueet) {
$tiedostotyypit = tiedostotyypit($valittu_aihealue);
echo "<form method='post' enctype='multipart/form-data'>";
echo "<input type='hidden' name='tee' value='tallenna_tiedosto'>";
echo "<table>";
echo "<tbody>";
echo "<tr>";
echo "<td><label for='aihealue'>" . t("Aihealue") . "</label></td>";
echo "<td>";
echo '<select id="aihealue" name="aihealue" onchange="submit();">';
foreach ($aihealueet as $aihealue) {
$valittu = $valittu_aihealue == $aihealue['selite'] ? "selected" : "";
echo "<option {$valittu} value='{$aihealue['selite']}'>{$aihealue['selite']}</option>";
}
echo '</select>';
echo "</td>";
echo "</tr>";
if (!empty($valittu_aihealue) and !empty($tiedostotyypit)) {
echo "<tr>";
echo "<td><label for='tiedostotyyppi'>" . t("Tiedoston tyyppi") . "</label></td>";
echo "<td>";
echo "<select id='tiedostotyyppi' name='tiedostotyyppi' onclick='submit();'>";
foreach ($tiedostotyypit as $tiedostotyyppi) {
$valittu = $valittu_tiedostotyyppi == $tiedostotyyppi["selitetark"] ? "selected" : "";
echo "<option value='{$tiedostotyyppi["selitetark"]}'
{$valittu}>{$tiedostotyyppi["selitetark"]}</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "<tr>
<td><label for='tiedosto'>" . t("Tiedosto") . "</label></td>
<td><input type='file' name='tiedosto' id='tiedosto'></td>
</tr>";
echo "<tr>
<td><label for='selite'>" . t("Selite") . "</label></td>
<td><input type='text' name='selite' id='selite'></td>
</tr>";
}
elseif (!empty($valittu_aihealue)) {
echo
"<tr>
<td colspan='2'>
<font class='error'>" .
t("Tälle aihealueelle ei ole vielä lisätty tiedostotyyppejä") .
"</font>
</td>
</tr>";
}
echo "<tr>";
echo "<td class='back'>";
$buttonin_teksti = (empty($valittu_aihealue) or empty($tiedostotyypit)) ? "Jatka" : "Tallenna";
echo "<input name='tallenna_nappi' type='submit' value='" . t($buttonin_teksti) . "'>";
if (!empty($valittu_aihealue) and !empty($tiedostotyypit)) {
echo "<input name='listaa_tiedostot'
type='submit'
value='Listaa aihealueen valitun tyyppiset tiedostot'>";
}
echo "</td>";
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "</form>";
}
function piirra_tiedostolista($tiedostot, $aihealue, $tiedostotyyppi) {
echo "<table>";
echo "<tbody>";
foreach ($tiedostot as $tiedosto) {
echo "<tr>";
echo "<td>";
echo "<a href='view.php?id={$tiedosto['tunnus']}'
target='Attachment'>{$tiedosto['selite']}</a>";
echo "</td>";
echo "<td>";
echo "<form method='post'>";
echo "<input type='hidden' name='tee' value='poista'>";
echo "<input type='hidden' name='aihealue' value='{$aihealue}'>";
echo "<input type='hidden' name='tiedostotyyppi' value='{$tiedostotyyppi}'>";
echo "<input type='hidden' name='poistettava_tiedosto' value='{$tiedosto["tunnus"]}'>";
echo
"<input type='submit'
value='Poista'
onclick='return confirm(\"" .
t("Oletko varma, että haluat poistaa tämän tiedoston") .
"\");'>
</td>";
echo "</form>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "<br>";
}
function poista_liitetiedosto($tunnus, $aihealue, $tiedostotyyppi) {
global $kukarow;
if ($tunnus and $aihealue and $tiedostotyyppi) {
$query =
"DELETE
FROM liitetiedostot
WHERE tunnus = {$tunnus}
AND yhtio = '{$kukarow["yhtio"]}'
AND liitos = 'muut_tiedostot'
AND liitostunnus = 0
AND kayttotarkoitus = '{$aihealue} | {$tiedostotyyppi}'";
return pupe_query($query);
}
else {
return false;
}
}