1 |
ravilov |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
//----------------------------------------- |
4 |
|
|
// Custom made by Dobrica Pavlinusic <dpavlin@rot13.org> |
5 |
|
|
|
6 |
|
|
// helper function to make full path of relative dir |
7 |
|
|
function dir2path($dir) { |
8 |
|
|
if (substr($dir,0,1) != "/") { |
9 |
|
|
return dirname($GLOBALS[SCRIPT_FILENAME])."/$dir"; |
10 |
|
|
} else { |
11 |
|
|
return $dir; |
12 |
|
|
} |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
function smarty_func_img() { |
16 |
|
|
extract(func_get_arg(0)); |
17 |
|
|
|
18 |
ravilov |
1.3 |
$f = array(); |
19 |
ravilov |
1.1 |
|
20 |
|
|
global $img_time; |
21 |
|
|
if (!isset($img_time)) { |
22 |
|
|
$img_time=time(); |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
if (isset($dir)) { |
26 |
|
|
$tdir=dir2path($dir); |
27 |
|
|
$h=opendir($dir); |
28 |
|
|
$pics=0; |
29 |
|
|
while ($tmp = readdir($h)) { |
30 |
|
|
if (is_file("$tdir/$tmp") && substr($tmp,0,1)!=".") { |
31 |
|
|
// print "$tdir/$tmp<br>\n"; |
32 |
|
|
$f[]=$tmp; |
33 |
|
|
$pics++; |
34 |
|
|
} |
35 |
|
|
} |
36 |
|
|
closedir($h); |
37 |
|
|
// $f=shuffle($f); |
38 |
|
|
$ord=($img_time+$nr) % $pics; |
39 |
|
|
$src="$dir/$f[$ord]"; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
$add=""; |
43 |
|
|
if (isset($border)) { |
44 |
|
|
$add.=" border=\"$border\""; |
45 |
|
|
} |
46 |
|
|
if (isset($alt)) { |
47 |
|
|
$add.=" alt=\"$alt\""; |
48 |
|
|
} |
49 |
|
|
if (isset($align)) { |
50 |
|
|
$add.=" align=\"$align\""; |
51 |
|
|
} |
52 |
|
|
if (isset($hspace)) { |
53 |
|
|
$add.=" hspace=\"$hspace\""; |
54 |
|
|
} |
55 |
|
|
if (isset($vspace)) { |
56 |
|
|
$add.=" vspace=\"$vspace\""; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
$out=""; |
60 |
|
|
$product_link = array ( |
61 |
|
|
"andol.gif"=>"http://www.pliva.hr/human_health.php?search=andol&show_description=on#results", |
62 |
|
|
"andol_c.jpg"=>"http://www.pliva.hr/human_health.php?search=andol%25c&show_description=on#results", |
63 |
|
|
"bisolex.jpg"=>"http://www.pliva.hr/human_health.php?search=bisolex&show_description=on#results", |
64 |
|
|
"plibex.gif"=>"http://www.pliva.hr/human_health.php?search=plibex&show_description=on#results", |
65 |
|
|
"plivit_b.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25b&show_description=on#results", |
66 |
|
|
"plivit_b6.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25b6&show_description=on#results", |
67 |
|
|
"plivit_c.gif"=>"http://www.pliva.hr/human_health.php?search=plivit%25c&show_description=on#results", |
68 |
|
|
); |
69 |
|
|
|
70 |
|
|
$pic=basename($src); |
71 |
|
|
if ($product_link[$pic]) { |
72 |
|
|
$out.="<a href=\"$product_link[$pic]\">"; |
73 |
|
|
$add.=" border=\"0\""; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
$size = GetImageSize(dir2path($src)); |
77 |
|
|
$out.="<img src=\"$src\" $size[3]$add>"; |
78 |
|
|
if ($product_link[$pic]) { |
79 |
|
|
$out.="</a>"; |
80 |
|
|
} |
81 |
|
|
print $out; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
// checkboxes |
85 |
|
|
|
86 |
|
|
function smarty_func_html_checkboxes() |
87 |
|
|
{ |
88 |
|
|
$print_result = true; |
89 |
|
|
|
90 |
|
|
extract(func_get_arg(0)); |
91 |
|
|
|
92 |
|
|
settype($output, 'array'); |
93 |
|
|
settype($values, 'array'); |
94 |
|
|
|
95 |
|
|
$html_result = ""; |
96 |
|
|
|
97 |
|
|
for ($i = 0; $i < count($output); $i++) { |
98 |
|
|
/* By default, check value against $selected */ |
99 |
|
|
$sel_check = $values[$i]; |
100 |
|
|
if (isset($before)) $html_result.=$before; |
101 |
|
|
$html_result .= "<input type=checkbox name=\"".$values[$i]."\""; |
102 |
|
|
if (isset($GLOBALS[$values[$i]])) { |
103 |
|
|
$html_result .= " checked"; |
104 |
|
|
} |
105 |
|
|
$html_result .= ">".$output[$i]."\n"; |
106 |
|
|
if (isset($after)) $html_result.=$after; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
if ($print_result) |
110 |
|
|
print $html_result; |
111 |
|
|
else |
112 |
|
|
return $html_result; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
// $filename|filesize:"dir":"unit" |
116 |
|
|
// |
117 |
|
|
// dir -- path to file (or "") |
118 |
|
|
// unit -- Mb|Kb|auto |
119 |
|
|
|
120 |
|
|
function smarty_mod_filesize($file,$dir,$unit="") |
121 |
|
|
{ |
122 |
|
|
$path=dir2path("$dir/$file"); |
123 |
|
|
$ext=explode(".",$file); |
124 |
|
|
$ext=strtoupper(array_pop($ext)); |
125 |
|
|
|
126 |
|
|
if ($size=filesize($path)) { |
127 |
ravilov |
1.2 |
switch (strtoupper($unit)) { |
128 |
|
|
case 'MB': |
129 |
|
|
return sprintf("%s, %2.1f MB",$ext,$size/(1024*1024)); |
130 |
|
|
case 'KB': |
131 |
|
|
return sprintf("%s, %2.1f kB",$ext,$size/1024); |
132 |
ravilov |
1.1 |
case 'auto': |
133 |
|
|
$size=$size/1024; # Kb |
134 |
|
|
if ($size > 1024) { |
135 |
ravilov |
1.2 |
return sprintf("%s, %2.1f MB",$ext,$size/1024); |
136 |
ravilov |
1.1 |
} else { |
137 |
ravilov |
1.2 |
return sprintf("%s, %2.1f kB",$ext,$size); |
138 |
ravilov |
1.1 |
} |
139 |
|
|
|
140 |
|
|
} |
141 |
|
|
return $size; |
142 |
|
|
} |
143 |
ravilov |
1.3 |
} |
144 |
|
|
|
145 |
|
|
// pic_url|js_popup:"dir_reference" |
146 |
|
|
|
147 |
|
|
function smarty_mod_js_popup($pic, $dir) { |
148 |
|
|
if ($dir) { global ${$dir}; $pic = ${$dir}."/".$pic; } |
149 |
|
|
if ($pic) { |
150 |
|
|
@$size = GetImageSize($pic); |
151 |
|
|
list($w, $h) = array($size[0], $size[1]); |
152 |
|
|
} |
153 |
|
|
$opts = array("scrollbar=no", "menu=no", "personal=no"); |
154 |
|
|
// KLUDGY!!! I have to somehow include the window chrome (ie. |
155 |
|
|
// decorations: titlebar, borders...) when calculating |
156 |
ravilov |
1.4 |
// width/height... |
157 |
|
|
if ($w) $w += 18; |
158 |
|
|
if ($h) $h += 25; |
159 |
|
|
if ($w) array_push($opts, "width=$w"); |
160 |
|
|
if ($h) array_push($opts, "height=$h"); |
161 |
|
|
if (!$w) $w = 0; |
162 |
|
|
if (!$h) $h = 0; |
163 |
|
|
return "var tmp = window.open(this.href, this.target, '".implode(',', $opts)."'); if (tmp && tmp.moveTo) tmp.moveTo((screen.availWidth - $w) / 2, (screen.availHeight - $h) / 2); return false;"; |
164 |
ravilov |
1.1 |
} |
165 |
|
|
|
166 |
|
|
// input functions (input, rinput) |
167 |
|
|
|
168 |
|
|
function smarty_func_input() { |
169 |
|
|
extract(func_get_arg(0)); |
170 |
|
|
print "<input name=\"$name\" size=\"$size\" value=\"".$GLOBALS[$name]."\">"; |
171 |
|
|
print "<input type=\"hidden\" name=\"inputs_required[]\" value=\"$name\">"; |
172 |
|
|
if ($type) print "<input type=\"hidden\" name=\"inputs_required_type[$name]\" value=\"$type\">"; |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
function smarty_func_rinput() { |
176 |
|
|
extract(func_get_arg(0)); |
177 |
|
|
global $inputs_required_type; |
178 |
|
|
$ok=1; |
179 |
|
|
if (! isset($GLOBALS[$name]) || $GLOBALS[$name] == "") { |
180 |
|
|
$ok=0; |
181 |
|
|
} else { |
182 |
|
|
switch($inputs_required_type[$name]) { |
183 |
|
|
case 'email': |
184 |
|
|
if (!strstr($GLOBALS[$name],'@')) $ok=0; |
185 |
|
|
} |
186 |
|
|
} |
187 |
|
|
if ($ok) { |
188 |
|
|
print "$desc"; |
189 |
|
|
} else { |
190 |
|
|
print "<b>$desc</b>"; |
191 |
|
|
} |
192 |
|
|
} |
193 |
|
|
?> |