forked from devlab-oy/pupesoft
/
kopioitoimittaja.php
170 lines (136 loc) · 4.22 KB
/
kopioitoimittaja.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
<?php
require "inc/parametrit.inc";
echo "<font class='head'>".t("Kopioi toimittaja").":</font><hr>";
if ($tee == "write") {
// Luodaan puskuri, jotta saadaan taulukot kuntoon
$query = "SELECT *
FROM toimi
WHERE tunnus = '$id'";
$result = pupe_query($query);
$trow = mysql_fetch_array($result);
// Tarkistetaan
$errori = '';
for ($i=1; $i < mysql_num_fields($result)-1; $i++) {
require "inc/toimitarkista.inc";
if ($virhe[$i] != "") {
$errori = 1;
}
}
if ($errori != '') {
echo "<font class='error'>".t("Jossain oli jokin virhe! Ei voitu paivittaa")."!</font>";
}
// Luodaan tietue
if ($errori == '') {
// Taulun ensimmäinen kenttä on aina yhtiö
$query = "INSERT into toimi values ('$kukarow[yhtio]'";
for ($i=1; $i < mysql_num_fields($result); $i++) {
$query .= ",'" . $t[$i] . "'";
}
$query .= ")";
$result = pupe_query($query);
$uusiidee = mysql_insert_id($GLOBALS["masterlink"]);
// Tämä funktio tekee myös oikeustarkistukset!
synkronoi($kukarow["yhtio"], "toimi", $uusiidee, "", "");
$tee = '';
}
else {
$tee = 'edit';
}
}
if ($tee == "edit") {
echo "<form method = 'post'>";
echo "<input type = 'hidden' name = 'tee' value ='write'>";
echo "<input type = 'hidden' name = 'id' value ='$id'>";
// Kokeillaan geneeristä
$query = "SELECT *
FROM toimi
WHERE tunnus='$id' and yhtio='$kukarow[yhtio]'";
$result = pupe_query($query);
$trow = mysql_fetch_array($result);
echo "<table>";
for ($i=0; $i < mysql_num_fields($result) - 1; $i++) {
$nimi = "t[$i]";
require "inc/toimirivi.inc";
if (mysql_field_len($result, $i)>10) $size='35';
elseif (mysql_field_len($result, $i)<5) $size='5';
else $size='10';
if ($tyyppi > 0) {
echo "<tr>";
}
if ($tyyppi > 0) {
echo "<th align='left'>".t(mysql_field_name($result, $i))."</th>";
}
if ($jatko == 0) {
echo $ulos;
}
else {
$mita = 'text';
if ($tyyppi != 1) {
$mita='hidden';
echo "<td class='back'>";
}
else {
echo "<td>";
}
echo "<input type = '$mita' name = '$nimi'";
if ($errori == '') {
echo " value = '$trow[$i]' size='$size' maxlength='" . mysql_field_len($result, $i) ."'>";
}
else {
echo " value = '$t[$i]' size='$size' maxlength='" . mysql_field_len($result, $i) ."'>";
}
if ($tyyppi == 2) {
echo "$trow[$i]";
}
echo "</td>";
}
if ($tyyppi > 0) {
echo "<td class='back'><font class='error'>$virhe[$i]</font></td></tr>\n";
}
}
echo "</table>";
echo "<input type = 'submit' value = '".t("Perusta")."'>";
echo "</form>";
}
if ($tee == '') {
$kentat = 'tunnus, ytunnus, nimi, postitp, maa, oletus_valkoodi';
$jarjestys = poista_osakeyhtio_lyhenne_mysql("nimi").", nimitark, ytunnus, tunnus";
$array = explode(",", $kentat);
$count = count($array);
for ($i=0; $i<=$count; $i++) {
if (strlen($haku[$i]) > 0) {
$lisa .= " and " . $array[$i] . " like '%" . $haku[$i] . "%'";
$ulisa .= "&haku[" . $i . "]=" . $haku[$i];
}
}
if (strlen($ojarj) > 0) {
$jarjestys = $ojarj;
}
$query = "SELECT $kentat FROM toimi WHERE yhtio = '$kukarow[yhtio]' $lisa ";
$query .= "$ryhma ORDER BY $jarjestys LIMIT 100";
$result = pupe_query($query)
or die ("Kysely ei onnistu $query");
echo " <table><tr>
<form method = 'post'>";
for ($i = 1; $i < mysql_num_fields($result); $i++) {
echo "<th valign='top' align='left'><a href = '$PHP_SELF?ojarj=".$array[$i].$ulisa ."'>
" . t(mysql_field_name($result, $i)) . "</a>";
echo "<br><input type='text' name = 'haku[" . $i . "]' value = '$haku[$i]'>";
echo "</th>";
}
echo "<td valign='bottom' class='back'><input type='submit' class='hae_btn' value='".t("Etsi")."'></td></form></tr>";
while ($trow=mysql_fetch_array($result)) {
echo "<tr>";
for ($i=1; $i<mysql_num_fields($result); $i++) {
if ($i == 1) {
echo "<td><a href='$PHP_SELF?id=$trow[tunnus]&tee=edit'>$trow[$i]</a></td>";
}
else {
echo "<td>$trow[$i]</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
require "inc/footer.inc";