1 |
<?php |
2 |
include("inc/global.php"); |
3 |
if (!Auth()) exit; |
4 |
$page = CalcPage($PHP_SELF); |
5 |
$p = $page; |
6 |
if (isparam("wb_p")) $p--; |
7 |
if (isparam("wb_OK")) $p++; |
8 |
if (isparam("wb_h")) $p = 0; |
9 |
if (isparam("wb_o")) $p = 15; |
10 |
include("inc/conn.php"); |
11 |
DBOpen(); |
12 |
$del = 0; |
13 |
reset($HTTP_GET_VARS); |
14 |
while ($var = key($HTTP_GET_VARS)) { |
15 |
next($HTTP_GET_VARS); |
16 |
if (!eregi('^del_([0-9]+)$', $var, $match)) continue; |
17 |
$del = $match[1]; |
18 |
} |
19 |
reset($HTTP_POST_VARS); |
20 |
while ($var = key($HTTP_POST_VARS)) { |
21 |
next($HTTP_POST_VARS); |
22 |
if (!eregi('^del_([0-9]+)$', $var, $match)) continue; |
23 |
$del = $match[1]; |
24 |
} |
25 |
if ($del) { |
26 |
unset($edit); |
27 |
DBQuery("DELETE FROM u_plivi WHERE (id=$del) AND (sif_radnika='$sifra')"); |
28 |
} |
29 |
$warning = 0; |
30 |
if ($update || $p != $page) { |
31 |
if ($radno_mjesto || $zadaci || $dat_od || $dat_do) { |
32 |
if (!$warning) { |
33 |
if ($dat_od) { |
34 |
list($d, $m, $y) = split("\s*\.+\s*", $dat_od); |
35 |
if (!checkdate($m, $d, $y)) $warning = 1; |
36 |
$datum_od = ComposeDate($dm, $m, $y); |
37 |
} else $warning = 2; |
38 |
} |
39 |
if (!$warning) { |
40 |
if ($dat_do) { |
41 |
list($d, $m, $y) = split("\s*\.+\s*", $dat_do); |
42 |
if (!checkdate($m, $d, $y)) $warning = 3; |
43 |
$datum_do = ComposeDate($dm, $m, $y); |
44 |
} else $warning = 4; |
45 |
} |
46 |
if (!$warning) { |
47 |
$radno_mjesto = ereg_replace("\r?\n", "\n", ISO_Win($radno_mjesto)); |
48 |
$zadaci = ereg_replace("\r?\n", "\n", ISO_Win($zadaci)); |
49 |
if ($edit) |
50 |
DBQuery("UPDATE u_plivi SET radno_mjesto='$radno_mjesto',zadaci='$zadaci',datum_od='$datum_od',datum_do='$datum_do' WHERE (sif_radnika='$sifra') AND (id=$edit)"); |
51 |
else { |
52 |
$id = DBQuery("SELECT MAX(id) FROM u_plivi"); |
53 |
$id = $id[0][0] + 1; |
54 |
DBQuery("INSERT INTO u_plivi (sif_radnika,radno_mjesto,zadaci,datum_od,datum_do,id) VALUES ('$sifra','$radno_mjesto','$zadaci','$datum_od','$datum_do',$id)"); |
55 |
} |
56 |
} |
57 |
} else if ($edit) |
58 |
DBQuery("DELETE FROM u_plivi WHERE (sif_radnika='$sifra') AND (id=$edit)"); |
59 |
if ($p != $page && !$warning) { |
60 |
DBClose(); |
61 |
Header("Location: $pages[$p]".Params($p)); |
62 |
exit; |
63 |
} |
64 |
} |
65 |
if (($new || $update) && !$warning) { |
66 |
unset($edit, $radno_mjesto, $zadaci); |
67 |
unset($dat_od, $dat_od_d, $dat_od_m, $dat_od_g); |
68 |
unset($dat_do, $dat_do_d, $dat_do_m, $dat_do_g); |
69 |
} |
70 |
$rows = DBQuery("SELECT id,radno_mjesto,zadaci,datum_od,datum_do FROM u_plivi WHERE (sif_radnika='$sifra')"); |
71 |
DBClose(); |
72 |
$vars = array(); |
73 |
$fnd = false; |
74 |
for ($i = 0; $i < count($rows); $i++) { |
75 |
list($id, $rm, $zad, $od, $do) = $rows[$i]; |
76 |
$od = ParseDate($od); |
77 |
$do = ParseDate($do); |
78 |
$rm = HTML_Escape(Win_ISO($rm)); |
79 |
$zad = HTML_Escape(Win_ISO($zad)); |
80 |
$rm2 = ereg_replace("\r?\n", "<BR>", $rm); |
81 |
$zad2 = ereg_replace("\r?\n", "<BR>", $zad); |
82 |
nepoznato($rm2); |
83 |
nepoznato($zad2); |
84 |
array_push($vars, array( |
85 |
"id" => $id, |
86 |
"link" => $PHP_SELF.Params($page, array("edit" => $id)), |
87 |
"radno_mjesto" => $rm2, |
88 |
"zadaci" => $zad2, |
89 |
"od_d" => $od["mday"], "od_m" => $od["mon"], "od_g" => $od["year"], |
90 |
"do_d" => $do["mday"], "do_m" => $do["mon"], "do_g" => $do["year"] |
91 |
)); |
92 |
if ($edit && $edit == $id) { |
93 |
$radno_mjesto = $rm; |
94 |
$zadaci = $zad; |
95 |
list($dat_od_d, $dat_od_m, $dat_od_g) = |
96 |
array($od["mday"], $od["mon"], $od["year"]); |
97 |
list($dat_do_d, $dat_do_m, $dat_do_g) = |
98 |
array($do["mday"], $do["mon"], $do["year"]); |
99 |
$fnd = true; |
100 |
} |
101 |
} |
102 |
if (!$fnd) unset($edit); |
103 |
include("inc/Smarty.class.php"); |
104 |
$tpl = new Smarty; |
105 |
$tpl->template_dir = "./tpl"; |
106 |
$tpl->compile_dir = "./tpc"; |
107 |
$tpl->assign("action", $PHP_SELF.Params($page, |
108 |
$edit ? array("edit" => $edit) : array())); |
109 |
$tpl->assign("language", $language); |
110 |
$tpl->assign("sifra", $sifra); |
111 |
$tpl->assign("vars", $vars); |
112 |
$tpl->assign("edit", $edit); |
113 |
$tpl->assign("radno_mjesto", $radno_mjesto); |
114 |
$tpl->assign("zadaci", $zadaci); |
115 |
if ($dat_od_d && $dat_od_m && $dat_od_g) { |
116 |
$tpl->assign("dat_od_d", $dat_od_d); |
117 |
$tpl->assign("dat_od_m", $dat_od_m); |
118 |
$tpl->assign("dat_od_g", $dat_od_g); |
119 |
} else $tpl->assign("dat_od", $dat_od); |
120 |
if ($dat_do_d && $dat_do_m && $dat_do_g) { |
121 |
$tpl->assign("dat_do_d", $dat_do_d); |
122 |
$tpl->assign("dat_do_m", $dat_do_m); |
123 |
$tpl->assign("dat_do_g", $dat_do_g); |
124 |
} else $tpl->assign("dat_do", $dat_do); |
125 |
$tpl->assign("warning", $warning); |
126 |
$pg = basename($PHP_SELF); |
127 |
$pg = eregi_replace("\.php$", "", $pg); |
128 |
$tpl->display("$pg-$language.tpl"); |
129 |
?> |