/[health_html]/inc/newsEdit.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /inc/newsEdit.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations)
Tue Oct 16 13:07:03 2001 UTC (17 years, 7 months ago) by ravilov
Branch: MAIN
Changes since 1.15: +54 -17 lines
Added a favicon for IE. Added a new Smarty modifier (js_popup). Fixed the news editor. Other bugfixes.

1 <?php
2 set_magic_quotes_runtime(false);
3 # ---KLUDGE-BEGIN---
4 function ss(&$i, $k) {
5 if (is_array($i)) array_walk($i, "ss");
6 if (!is_string($i)) return;
7 $i = stripslashes($i);
8 if ($k) { global $$k; $$k = stripslashes($$k); }
9 }
10 $ss = array("HTTP_GET_VARS", "HTTP_POST_VARS", "HTTP_POST_FILES");
11 while (list($key, $val) = each($ss)) array_walk($$val, "ss");
12 # ---KLUDGE-END---
13 $phptmp = "^php";
14 function sql($sql) {
15 #echo "<TT><B>[SQL]</B> $sql<BR>\n";
16 }
17 function my_cmp($a, $b) { return MyCompare($a["txt"], $b["txt"]); }
18 function my_cmp_2($a, $b) { return MyCompare($a["ime"], $b["ime"]); }
19 function newsEdit($art, $trigger = "", $isVijest = false) {
20 global $phptmp, $picdir, $syspicdir, $aupicdir, $sysaupicdir, $dbh;
21 global $section, $section_menu, $section_menu2, $spec;
22 global $ed_id, $ed_cat, $isMed;
23 $i = 1;
24 global $ed_delete_main, $ed_del_main;
25 $delete_main = $ed_delete_main;
26 $del_main = $ed_del_main;
27 global $ed_clear_main, $ed_clr_main;
28 global $ed_clear_author, $ed_clr_author;
29 $clear_main = $ed_clear_main;
30 $clr_main = $ed_clr_main;
31 $clear_author = $ed_clear_author;
32 $clr_author = $ed_clr_author;
33 global $ed_titlepic_url, $ed_titlepic_url2, $ed_titlepic_name;
34 $titlepic_url = $ed_titlepic_url;
35 $titlepic_url2 = $ed_titlepic_url2;
36 $titlepic_name = urldecode($ed_titlepic_name);
37 # Fix for M$IE
38 if ($titlepic_url == "none") $titlepic_url = "";
39 global $ed_author_url, $ed_author_url2, $ed_author_name;
40 $author_url = $ed_author_url;
41 $author_url2 = $ed_author_url2;
42 $author_name = urldecode($ed_author_name);
43 # Fix for M$IE
44 if ($author_url == "none") $author_url = "";
45 while (true) {
46 global ${"ed_text_id_".$i};
47 if (!isset(${"ed_text_id_".$i})) break;
48 global ${"ed_delete_".$i}, ${"ed_del_".$i};
49 ${"delete_".$i} = ${"ed_delete_".$i};
50 ${"del_".$i} = ${"ed_del_".$i};
51 global ${"ed_clear_".$i}, ${"ed_clr_".$i};
52 ${"clear_".$i} = ${"ed_clear_".$i};
53 ${"clr_".$i} = ${"ed_clr_".$i};
54 global ${"ed_fclear_".$i}, ${"ed_fclr_".$i};
55 ${"fclear_".$i} = ${"ed_fclear_".$i};
56 ${"fclr_".$i} = ${"ed_fclr_".$i};
57 global ${"ed_textpic_url_".$i}, ${"ed_textpic_url2_".$i}, ${"ed_textpic_name_".$i};
58 ${"textpic_url_".$i} = ${"ed_textpic_url_".$i};
59 ${"textpic_url2_".$i} = ${"ed_textpic_url2_".$i};
60 ${"textpic_name_".$i} = urldecode(${"ed_textpic_name_".$i});
61 # Fix for M$IE
62 if (${"textpic_url_".$i} == "none") ${"textpic_url_".$i} = "";
63 global ${"ed_textpic_full_".$i}, ${"ed_textpic_full2_".$i}, ${"ed_textpic_fname_".$i};
64 ${"textpic_full_".$i} = ${"ed_textpic_full_".$i};
65 ${"textpic_full2_".$i} = ${"ed_textpic_full2_".$i};
66 ${"textpic_fname_".$i} = urldecode(${"ed_textpic_fname_".$i});
67 # Fix for M$IE
68 if (${"textpic_full_".$i} == "none") ${"textpic_full_".$i} = "";
69 $i++;
70 }
71 // -----
72 $categories = array();
73 $sql = "SELECT cat_id, text FROM news_categories ORDER BY text";
74 sql($sql);
75 $sth = $dbh->prepare($sql);
76 if (!$sth) error("Cannot prepare query: \"$sql\"");
77 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
78 while ($row = $sth->fetchrow_array()) array_push($categories,
79 array("id" => $row[0], "txt" => $row[1]));
80 $sth->finish();
81 usort($categories, "my_cmp");
82 // -----
83 $autori = array();
84 $sql = "SELECT autor_id, ime FROM autori";
85 sql($sql);
86 $sth = $dbh->prepare($sql);
87 if (!$sth) error("Cannot prepare query: \"$sql\"");
88 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
89 while ($row = $sth->fetchrow_array()) array_push($autori, array("id" => $row[0], "ime" => MyEscape($row[1], false)));
90 $sth->finish();
91 usort($autori, "my_cmp_2");
92 // -----
93 $specs = array();
94 $sql = "SELECT spec_id, opis FROM specijalizacije WHERE (spec_id != 0) AND (NOT link)";
95 sql($sql);
96 $sth = $dbh->prepare($sql);
97 if (!$sth) error("Cannot prepare query: \"$sql\"");
98 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
99 while ($row = $sth->fetchrow_array()) array_push($specs, array("id" => $row[0], "txt" => $row[1]));
100 $sth->finish();
101 usort($specs, "my_cmp");
102 array_unshift($specs, array("id" => 0, "txt" => "HOME"));
103 // -----
104 $levels = array();
105 $sql = "SELECT level_id, class, name FROM par_levels ORDER BY name";
106 sql($sql);
107 $sth = $dbh->prepare($sql);
108 if (!$sth) error("Cannot prepare query: \"$sql\"");
109 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
110 while ($row = $sth->fetchrow_array()) array_push($levels, array("id" => $row[0], "class" => $row[1], "name" => $row[2]));
111 $sth->finish();
112 // -----
113 global $cancel, $save;
114 if ($cancel || $save) {
115 if ($save) {
116 // Move temp pics & save article.
117 if (ereg("$phptmp", $titlepic_url2) && $ed_id > 0 && file_exists("$syspicdir/$titlepic_url2")) {
118 $sql = "SELECT title_pic FROM news WHERE (news_id = $ed_id)";
119 sql($sql);
120 $sth = $dbh->prepare($sql);
121 if (!$sth) error("Cannot prepare query: \"$sql\"");
122 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
123 $row = $sth->fetchrow_array();
124 $sth->finish();
125 $row = array_shift($row);
126 if ($row) MyDelete($syspicdir."/".$row);
127 }
128 if (ereg("$phptmp", $author_url2) && $ed_id > 0 && file_exists("$sysaupicdir/$author_url2")) {
129 $sql = "SELECT author_pic FROM news WHERE (news_id = $ed_id)";
130 sql($sql);
131 $sth = $dbh->prepare($sql);
132 if (!$sth) error("Cannot prepare query: \"$sql\"");
133 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
134 $row = $sth->fetchrow_array();
135 $sth->finish();
136 $row = array_shift($row);
137 if ($row) MyDelete($sysaupicdir."/".$row);
138 }
139 global $ed_title, $ed_lead, $ed_titlepic_alt,
140 $ed_titlepic_pos, $ed_more, $ed_more_title,
141 $ed_cat, $ed_author_alt, $ed_author_info,
142 $ed_author_ime, $ed_author_cv, $ed_prikazi;
143 $ed_title = MyQuote($ed_title);
144 $ed_lead = MyQuote($ed_lead);
145 $ed_author_nm = urldecode(MyQuote(basename($author_name)));
146 $ed_author_alt = MyQuote($ed_author_alt);
147 $ed_author_ime = MyQuote($ed_author_ime);
148 $ed_author_info = MyQuote($ed_author_info);
149 $ed_titlepic_nm = urldecode(MyQuote(basename($titlepic_name)));
150 $ed_titlepic_alt = MyQuote($ed_titlepic_alt);
151 $ed_more = MyQuote($ed_more);
152 $ed_more_title = MyQuote($ed_more_title);
153 if (!$ed_titlepic_pos) $ed_titlepic_pos = 0;
154 if (!$ed_author_cv) $ed_author_cv = 0;
155 if ($ed_id > 0) {
156 $sql = "UPDATE news SET category = '$ed_cat', title = $ed_title, lead = $ed_lead, title_pic = $ed_titlepic_nm, title_alt = $ed_titlepic_alt, title_pos = $ed_titlepic_pos, author_pic = $ed_author_nm, author_alt = $ed_author_alt, author_info = $ed_author_info, author_name = $ed_author_ime, autor_cv = $ed_author_cv, url = $ed_more, url_title = $ed_more_title, plivamed = ".($isMed?"true":"false").", prikazi = ".($ed_prikazi?"true":"false").", ord = 0, d_change = NOW() WHERE (news_id = $ed_id)";
157 sql($sql);
158 $dbh->dbh_do($sql);
159 } else {
160 $sql = "INSERT INTO news (category, title, lead, title_pic, title_alt, title_pos, author_pic, author_alt, author_info, author_name, autor_cv, url, url_title, plivamed, prikazi, d_orig, d_change) VALUES ('$ed_cat', $ed_title, $ed_lead, $ed_titlepic_nm, $ed_titlepic_alt, $ed_titlepic_pos, $ed_author_nm, $ed_author_alt, $ed_author_info, $ed_author_ime, $ed_author_cv, $ed_more, $ed_more_title, ".($isMed?"true":"false").", ".($ed_prikazi?"true":"false").", NOW(), NOW())";
161 sql($sql);
162 $dbh->dbh_do($sql);
163 $sql = "SELECT currval('news_news_id_seq')::text";
164 sql($sql);
165 $sth = $dbh->prepare($sql);
166 if (!$sth) error("Cannot prepare query: \"$sql\"");
167 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
168 $rows = array();
169 while ($row = $sth->fetchrow_array()) array_push($rows, $row);
170 $sth->finish();
171 $row = array_pop($rows);
172 if (is_array($row)) $row = array_shift($row);
173 if ($row) $ed_id = $row;
174 }
175 if ($titlepic_url2) MyMove("$syspicdir/$titlepic_url2", urldecode("$syspicdir/$titlepic_name"));
176 if ($author_url2) MyMove("$sysaupicdir/$author_url2", urldecode("$sysaupicdir/$author_name"));
177 $i = 1;
178 $parents = array();
179 $last_level = 0;
180 $last_id = 0;
181 while ($ed_id > 0 && isset(${"ed_text_id_".$i})) {
182 global ${"ed_text_title_".$i}, ${"ed_text_".$i},
183 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
184 ${"ed_text_level_".$i}, ${"ed_hl_".$i},
185 ${"ed_textpic_exp_".$i};
186 list($id, $tit, $txt, $pic, $orig,$full, $forig, $alt, $pos, $del, $lev, $hl, $exp) = array(
187 ${"ed_text_id_".$i}, ${"ed_text_title_".$i}, ${"ed_text_".$i},
188 ${"textpic_url2_".$i}, ${"textpic_name_".$i}, ${"textpic_full2_".$i},
189 ${"textpic_fname_".$i}, ${"ed_textpic_alt_".$i},
190 ${"ed_textpic_pos_".$i}, ${"del_".$i}, ${"ed_text_level_".$i},
191 ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i});
192 if ($lev != $last_level) {
193 if ($last_level) {
194 if ($last_level < $lev) array_push($parents, $id);
195 if ($last_level > $lev && count($parents) > 0) array_pop($parents);
196 }
197 $last_level = $lev;
198 $parent = $parents[0];
199 if ($parent < 0) $parent = $last_id;
200 }
201 $tit = MyQuote($tit);
202 $txt = MyQuote($txt);
203 $exp = MyQuote($exp);
204 $hl = MyQuote($hl);
205 $orig = basename($orig);
206 $org = MyQuote($orig);
207 $forig = basename($forig);
208 $forg = MyQuote($forig);
209 $alt = MyQuote($alt);
210 if (!$pos) $pos = 0;
211 if ($id && $id > 0) {
212 if ($del || !$orig) {
213 $sql = "SELECT pic FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
214 sql($sql);
215 $sth = $dbh->prepare($sql);
216 if (!$sth) error("Cannot prepare query: \"$sql\"");
217 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
218 while ($row = $sth->fetchrow_array()) {
219 list($pic) = $row;
220 MyDelete($syspicdir."/".$pic);
221 }
222 $sth->finish();
223 }
224 if ($del || !$forig) {
225 $sql = "SELECT full_pic FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
226 sql($sql);
227 $sth = $dbh->prepare($sql);
228 if (!$sth) error("Cannot prepare query: \"$sql\"");
229 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
230 while ($row = $sth->fetchrow_array()) {
231 list($pic) = $row;
232 MyDelete($syspicdir."/".$pic);
233 }
234 $sth->finish();
235 }
236 if ($del) $sql = "DELETE FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
237 else $sql = "UPDATE paragraphs SET title = $tit, level = $lev, text = $txt, hl = $hl, pic = $org, full_pic = $forg, alt = $alt, pos = $pos, pic_title = $exp WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
238 sql($sql);
239 $dbh->dbh_do($sql);
240 } else if (!$del) {
241 $sql = "INSERT INTO paragraphs (news_id, title, level, text, pic, full_pic, alt, pos, hl, pic_title) VALUES ($ed_id, $tit, $lev, $txt, $org, $forg, $alt, $pos, $hl, $exp)";
242 sql($sql);
243 $dbh->dbh_do($sql);
244 $sql = "SELECT currval('paragraphs_paragraph_id_seq')::text";
245 sql($sql);
246 $sth = $dbh->prepare($sql);
247 if (!$sth) error("Cannot prepare query: \"$sql\"");
248 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
249 $row = $sth->fetchrow_array();
250 $sth->finish();
251 $row = array_shift($row);
252 $last_id = $id = $row;
253 }
254 if ($pic) MyMove("$syspicdir/$pic", "$syspicdir/$orig");
255 if ($full) MyMove("$syspicdir/$full", "$syspicdir/$forig");
256 $i++;
257 }
258 if ($ed_id) {
259 $sql = "DELETE FROM spec_news WHERE (news_id = $ed_id)";
260 sql($sql);
261 $dbh->dbh_do($sql);
262 for ($k = 0; $k < count($specs); $k++) {
263 $var = "ed_spec_".$specs[$k]["id"];
264 global $$var;
265 if (!$$var) continue;
266 $sql = "INSERT INTO spec_news (news_id, spec_id) VALUES ($ed_id, ".$specs[$k]["id"].")";
267 sql($sql);
268 $dbh->dbh_do($sql);
269 }
270 $sql = "DELETE FROM cat_news WHERE (news_id = $ed_id)";
271 sql($sql);
272 $dbh->dbh_do($sql);
273 for ($k = 0; $k < count($categories); $k++) {
274 $var = "ed_cat_".$categories[$k]["id"];
275 global $$var;
276 if ($categories[$k]["id"] != $ed_cat && !$$var) continue;
277 $sql = "INSERT INTO cat_news (news_id, cat_id) VALUES ($ed_id, '".$categories[$k]["id"]."')";
278 sql($sql);
279 $dbh->dbh_do($sql);
280 }
281 }
282 } else {
283 // Delete temp pics.
284 if (ereg("$phptmp", $titlepic_url2)) MyDelete($syspicdir."/".$titlepic_url2);
285 if (ereg("$phptmp", $author_url2)) MyDelete($sysaupicdir."/".$author_url2);
286 $i = 1;
287 while (isset(${"ed_textpic_id_".$i})) {
288 $tmp = ${"textpic_url2_".$i};
289 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
290 $tmp = ${"textpic_full2_".$i};
291 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
292 $i++;
293 }
294 }
295 if (!isset($art["limit"])) $art["limit"] = 1;
296 if (!isset($art["npar"])) $art["npar"] = 1;
297 return array_shift(newsLoad($ed_id, $ed_cat,
298 $art["limit"], $art["offset"], $art["npar"]));
299 }
300 // Handle temp pic upload.
301 global $HTTP_POST_FILES;
302 while (list($key, $val) = each($HTTP_POST_FILES)) {
303 list($name, $type, $tname, $size) = array(
304 $val["name"], $val["type"],
305 $val["tmp_name"], $val["size"]);
306 if ($size <= 0) continue;
307 if (!$name) continue;
308 if ($tname == "none") continue;
309 $name = strtr($name, "¹šðè澞©ŠÐÈÆ®Ž ", "ssdcczzSSDCCZZ_");
310 $nm = basename($tname);
311 $ext = ereg_replace('^.*(\..+)$', '\1', $name);
312 if ($key == "ed_titlepic_url") {
313 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
314 $titlepic_url = $nm.$ext;
315 $titlepic_name = $name;
316 $u = $titlepic_url2;
317 if (ereg("$phptmp", $u)) MyDelete($syspicdir."/".$u);
318 unset($clear_main, $clr_main);
319 } else if ($key == "ed_author_url") {
320 move_uploaded_file($tname, $sysaupicdir."/".$nm.$ext);
321 $author_url = $nm.$ext;
322 $author_name = $name;
323 $u = $author_url2;
324 if (ereg("$phptmp", $u)) MyDelete($sysaupicdir."/".$u);
325 unset($clear_author, $clr_author);
326 } else if (ereg("^ed_textpic_url_([1-9][0-9]*)$", $key, $regs)) {
327 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
328 $n = $regs[1];
329 ${"textpic_url_".$n} = $nm.$ext;
330 ${"textpic_name_".$n} = $name;
331 $u = ${"textpic_url2_".$n};
332 if (ereg("$phptmp", $u)) MyDelete($syspicdir."/".$u2);
333 unset(${"clear_".$n}, ${"clr_".$n});
334 } else if (ereg("^ed_textpic_full_([1-9][0-9]*)$", $key, $regs)) {
335 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
336 $n = $regs[1];
337 ${"textpic_full_".$n} = $nm.$ext;
338 ${"textpic_fname_".$n} = $name;
339 $u = ${"textpic_full2_".$n};
340 if (ereg("$phptmp", $u)) MyDelete($syspicdir."/".$u2);
341 unset(${"fclear_".$n}, ${"fclr_".$n});
342 } else {
343 // ?!?
344 }
345 }
346 // -----
347 $tp = new Smarty();
348 $tp->assign("levels", $levels);
349 $tp->assign("autori", $autori);
350 // -----
351 global $ed_id, $ed_title, $ed_lead, $ed_titlepic_pos,
352 $ed_titlepic_alt, $ed_cat, $ed_more,
353 $ed_more_title, $ed_author_url, $ed_author_alt,
354 $ed_author_info, $ed_author_ime, $ed_prikazi;
355 global $ed_edit, $ed_preview, $preview, $add;
356 if (!$ed_preview) $ed_preview = ($preview ? true : false);
357 if ($ed_edit) $ed_preview = false;
358 global $HTTP_POST_VARS, $HTTP_GET_VARS;
359 $delete = count(preg_grep('/^ed_delete_[0-9]+$/',
360 array_keys(array_merge($HTTP_GET_VARS,
361 $HTTP_POST_VARS)))) > 0;
362 global $ed_clear_author;
363 $clear = (count(preg_grep('/^ed_clear_(main|author|[0-9]+)$/',
364 array_keys(array_merge($HTTP_GET_VARS,
365 $HTTP_POST_VARS)))) > 0);
366 $ed_pgfs = array();
367 $ed_warning = 0;
368 $nspecs = array();
369 $ncats = array();
370 // Transfer data
371 if ($ed_edit || $ed_preview || $add || $delete || $clear) {
372 for ($i = 0; $i < count($specs); $i++) {
373 $var = "ed_spec_".$specs[$i]["id"];
374 global $$var;
375 $foo = isset($$var) ? $$var : ($spec && $spec == $specs[$i]["id"]);
376 $nspecs[$specs[$i]["id"]] = $foo ? true : false;
377 }
378 for ($i = 0; $i < count($categories); $i++) {
379 $var = "ed_cat_".$categories[$i]["id"];
380 global $$var;
381 $ncats[$categories[$i]["id"]] = $$var ? true : false;
382 }
383 global $ed_title, $ed_lead, $ed_titlepic_pos,
384 $ed_titlepic_alt, $ed_cat, $ed_more,
385 $ed_more_title, $ed_author_url,
386 $ed_author_alt, $ed_author_info,
387 $ed_author_ime, $ed_author_cv,
388 $ed_prikazi;
389 if (!$HTTP_POST_FILES["ed_titlepic_url"]["name"]) $titlepic_url = "";
390 if (!$titlepic_url) $titlepic_url = $titlepic_url2;
391 if (!$titlepic_url && !($clear_main || $clr_main)) $titlepic_url = $art["pic_url"];
392 if (!$author_url && !($clear_author || $clr_author)) $author_url = $art["au_pic"];
393 list($width, $height) = PicSize($titlepic_url);
394 list($width2, $height2) = PicSize($author_url, $sysaupicdir);
395 global $ed_title_force;
396 if ($titlepic_url && !$ed_titlepic_pos && !$ed_title_force) $ed_warning = 2;
397 $i = 1;
398 while (isset(${"ed_text_id_".$i})) {
399 $id = ${"ed_text_id_".$i};
400 global ${"ed_text_".$i}, ${"ed_text_title_".$i},
401 ${"ed_text_level_".$i}, ${"ed_textpic_alt_".$i},
402 ${"ed_textpic_pos_".$i}, ${"ed_hl_".$i},
403 ${"ed_textpic_exp_".$i};
404 $pic_url = ($HTTP_POST_FILES["ed_textpic_url_".$i]["name"]) ?
405 ${"textpic_url_".$i} : "";
406 if (!$pic_url) $pic_url = ${"textpic_url2_".$i};
407 $full_url = ($HTTP_POST_FILES["ed_textpic_full_".$i]["name"]) ?
408 ${"textpic_full_".$i} : "";
409 if (!$full_url) $full_url = ${"textpic_full2_".$i};
410 $tmp = "";
411 for ($j = 0; $j < count($art["text"]); $j++)
412 if ($art["text"][$j]["id"] == $id) $tmp = $art["text"][$j]["pic"];
413 if (!$pic_url && $tmp && !(${"clear_".$i} || ${"clr_".$i})) $pic_url = $tmp;
414 $tmp = "";
415 for ($j = 0; $j < count($art["text"]); $j++)
416 if ($art["text"][$j]["id"] == $id) $tmp = $art["text"][$j]["full"];
417 if (!$full_url && $tmp && !(${"fclear_".$i} || ${"fclr_".$i})) $full_url = $tmp;
418 $level = ${"ed_text_level_".$i};
419 list($w, $h) = PicSize($pic_url);
420 list($w2, $h2) = PicSize($full_url);
421 array_push($ed_pgfs, array($id,
422 ${"ed_text_".$i}, ${"ed_text_title_".$i},
423 $level, $pic_url, ${"textpic_name_".$i},
424 $full_url, ${"textpic_fname_".$i},
425 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
426 $w, $h, $w2, $h2, ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i}, false));
427 $i++;
428 }
429 } else {
430 if ($ed_id) {
431 $sql = "SELECT spec_id FROM spec_news WHERE (news_id = $ed_id)";
432 sql($sql);
433 $sth = $dbh->prepare($sql);
434 if (!$sth) error("Cannot prepare query: \"$sql\"");
435 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
436 while ($row = $sth->fetchrow_array()) $nspecs[$row[0]] = true;
437 $sth->finish();
438 $sql = "SELECT cat_id FROM cat_news WHERE (news_id = $ed_id)";
439 sql($sql);
440 $sth = $dbh->prepare($sql);
441 if (!$sth) error("Cannot prepare query: \"$sql\"");
442 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
443 while ($row = $sth->fetchrow_array()) $ncats[$row[0]] = true;
444 $sth->finish();
445 } else {
446 $art["show"] = true;
447 for ($j = 0; $j < count($specs); $j++)
448 $nspecs[$specs[$j]["id"]] = ($specs[$j]["id"] == $spec) ? true : false;
449 }
450 list($ed_title, $ed_lead, $ed_titlepic_pos, $titlepic_url,
451 $titlepic_url2, $titlepic_name, $ed_titlepic_alt,
452 $ed_cat, $ed_more, $ed_more_title, $width, $height,
453 $author_url, $author_url2, $author_name,
454 $ed_author_alt, $ed_author_info, $width2, $height2,
455 $ed_author_ime, $ed_author_cv, $ed_prikazi) = array($art["title"],
456 $art["lead"], $art["pic_pos"], $art["pic_url"], $art["pic_url"],
457 urldecode($art["pic_url"]), $art["pic_alt"], $art["category"],
458 $art["more"], $art["more_title"], $art["pic_w"], $art["pic_h"],
459 $art["au_pic"], $art["au_pic"], urldecode($art["au_pic"]),
460 $art["au_alt"], $art["au_info"], $art["au_w"], $art["au_h"],
461 $art["au_name"], $art["au_cv"], $art["show"]);
462 if ($art["text"]) reset($art["text"]);
463 while ($art["text"] && list($id, $val) = each($art["text"])) {
464 array_push($ed_pgfs, array($val["id"], $val["text"], $val["title"],
465 $val["level"], urldecode($val["pic"]),
466 urldecode($val["pic"]), urldecode($val["full"]), urldecode($val["full"]),
467 $val["alt"], $val["pos"], $val["w"], $val["h"], $val["fw"], $val["fh"],
468 $val["hl"], $val["exp"], false));
469 }
470 $ed_id = $art["id"];
471 if (!$ed_id) $ed_id = -1;
472 }
473 $ncats[$ed_cat] = true;
474 for ($i = 0; $i < count($specs); $i++) $specs[$i]["check"] = $nspecs[$specs[$i]["id"]];
475 for ($i = 0; $i < count($categories); $i++) $categories[$i]["check"] = $ncats[$categories[$i]["id"]];
476 $tp->assign("specs", $specs);
477 $tp->assign("categories", $categories);
478 if ($ed_more && !strstr($ed_more, "://")) {
479 $pos = strpos($ed_more, "?");
480 if ($pos === false || $pos != 0) $ed_more = "http://".$ed_more;
481 }
482 if ($add) {
483 global $add_num;
484 for ($i = 0; $i < intval($add_num); $i++)
485 array_push($ed_pgfs, array(-1, "", "", -1, "", "", "", "", "", 0, 0, 0, 0, 0, "", "", true));
486 }
487 $ed_empty = ($ed_title || $ed_lead || $ed_titlepic_pos || $ed_more) ? false : true;
488 $ed_text = array();
489 $ed_records = array();
490 $ed_warnings = ($ed_warning ? true : false);
491 $i = 1;
492 while (list($key, $val) = each($ed_pgfs)) {
493 list($id, $txt, $tit, $lev, $pic, $name, $fpic, $fname, $alt, $pos, $w, $h, $fw, $fh, $hl, $exp, $new) = $val;
494 $del = ((${"delete_".$i} || ${"del_".$i}) ? true : false);
495 array_push($ed_records, array("val" => $del, "id" => $id));
496 if ($del) { $i++; continue; }
497 $picurl = ${"textpic_url_".$id};
498 if (!$picurl) $picurl = $pic;
499 $fullurl = ${"textpic_full_".$id};
500 if (!$fullurl) $fullurl = $fpic;
501 $class = "";
502 reset($levels);
503 while (list($k, $v) = each($levels)) if ($v["id"] == $lev) $class = $v["class"];
504 if ((${"clear_".$i} || ${"clr_".$i}) && $ed_preview && (${"textpic_name_".$i} != ${"textpic_url2_".$i})) {
505 $tmp = ${"textpic_url2_".$i};
506 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
507 $picurl = ${"textpic_url_".$i} = ${"textpic_url2_".$i} = $name = "";
508 }
509 if (!$name) $name = $picurl;
510 if ((${"fclear_".$i} || ${"fclr_".$i}) && $ed_preview && (${"textpic_full_".$i} != ${"textpic_full2_".$i})) {
511 $tmp = ${"textpic_full2_".$i};
512 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
513 $fullurl = ${"textpic_full_".$i} = ${"textpic_full2_".$i} = $fname = "";
514 }
515 if (!$fname) $fname = $fullurl;
516 $txt = MyEscape(convert_html($txt), false);
517 $txt2 = ParseNewline($txt, true);
518 $txt3 = str_replace("&", "&amp;", MyEscape(convert_html($txt), true));
519 $txt3 = str_replace("\"", "&quot;", $txt3);
520 $txt3 = str_replace("<", "&lt;", $txt3);
521 $txt3 = str_replace(">", "&gt;", $txt3);
522 $hl = MyEscape(convert_html($hl), false);
523 $hl2 = ParseNewline($hl, true);
524 if ($hl2) $hl2 = GetHighlight($hl2);
525 $hl3 = str_replace("&", "&amp;", MyEscape(convert_html($hl), true));
526 $hl3 = str_replace("\"", "&quot;", $hl3);
527 $hl3 = str_replace("<", "&lt;", $hl3);
528 $hl3 = str_replace(">", "&gt;", $hl3);
529 global ${"ed_text_force_".$i};
530 $force = ${"ed_text_force_".$i};
531 $empty = (($ed_preview && !$txt && !$pos && !$new) ? true : false);
532 $warning = 0;
533 if ($empty && !$force) $warning = 1;
534 if ($picurl && !$pos && !$force) $warning = 2;
535 $ed_empty = $ed_empty && $empty;
536 $ed_warnings = $ed_warnings || ($warning && !$force);
537 array_push($ed_text, array(
538 "id" => $id,
539 "n" => $i,
540 "txt" => $txt2,
541 "txt2" => $txt,
542 "txt3" => $txt3,
543 "hl" => $hl2,
544 "hl2" => $hl,
545 "hl3" => $hl3,
546 "title" => MyEscape(convert_html($tit)),
547 "level" => $lev,
548 "class" => MyEscape(convert_html($class)),
549 "url" => MyEscape(convert_html($picurl)),
550 "name" => MyEscape(convert_html($name)),
551 "full" => MyEscape(convert_html($fullurl)),
552 "fname" => MyEscape(convert_html($fname)),
553 "alt" => MyEscape(convert_html($alt)),
554 "w" => $w,
555 "h" => $h,
556 "fw" => $fw,
557 "fh" => $fh,
558 "pos" => $pos,
559 "exp" => MyEscape(convert_html($exp)),
560 "warning" => $warning,
561 "clr" => (${"clear_".$i} || ${"clr_".$i} || !$picurl) ? true : false,
562 "fclr" => (${"fclear_".$i} || ${"fclr_".$i} || !$fullurl) ? true : false
563 ));
564 $i++;
565 }
566 if ($ed_warnings) $ed_preview = false;
567 $tp->assign("ed_id", $ed_id);
568 $tp->assign("ed_cat", $ed_cat);
569 $tp->assign("ed_preview", $ed_preview);
570 $tp->assign("ed_trigger", $trigger);
571 $tp->assign("ed_title", MyEscape(convert_html($ed_title)));
572 $tp->assign("ed_lead", MyEscape(convert_html($ed_lead), true));
573 $tp->assign("ed_lead2", ParseNewline(MyEscape(convert_html($ed_lead), false), false));
574 $tp->assign("ed_titlepic_pos", $ed_titlepic_pos);
575 $tp->assign("ed_titlepic_url", MyEscape(convert_html($titlepic_url)));
576 $tp->assign("ed_titlepic_url2", MyEscape(convert_html($titlepic_url2)));
577 $tp->assign("ed_titlepic_name", MyEscape(convert_html($titlepic_name)));
578 $tp->assign("ed_titlepic_alt", MyEscape(convert_html($ed_titlepic_alt)));
579 $tp->assign("ed_titlepic_width", $width);
580 $tp->assign("ed_titlepic_height", $height);
581 $tp->assign("ed_author_url", MyEscape(convert_html($author_url)));
582 $tp->assign("ed_author_url2", MyEscape(convert_html($author_url2)));
583 $tp->assign("ed_author_name", MyEscape(convert_html($author_name)));
584 $tp->assign("ed_author_alt", MyEscape(convert_html($ed_author_alt)));
585 $tp->assign("ed_author_info", MyEscape(convert_html($ed_author_info)));
586 $tp->assign("ed_author_ime", MyEscape(convert_html($ed_author_ime)));
587 $tp->assign("ed_author_width", $width2);
588 $tp->assign("ed_author_height", $height2);
589 $tp->assign("ed_more", MyEscape($ed_more));
590 $tp->assign("ed_more_new", strstr($ed_more, "://") ? true : false);
591 $tp->assign("ed_more_title", MyEscape($ed_more_title));
592 $tp->assign("ed_prikazi", $ed_prikazi);
593 $tp->assign("ed_author_cv", $ed_author_cv);
594 $tp->assign("ed_clr_main", ($clear_main || $clr_main || !$titlepic_url) ? true : false);
595 $tp->assign("ed_clr_author", ($clear_author || $clr_author || !$author_url) ? true : false);
596 $tp->assign("ed_text", $ed_text);
597 $tp->assign("ed_empty", $ed_empty);
598 $tp->assign("ed_warning", $ed_warning);
599 $tp->assign("ed_warnings", $ed_warnings);
600 $tp->assign("ed_records", $ed_records);
601 $tp->assign("newspicdir", "$picdir/");
602 $tp->assign("aupicdir", "$aupicdir/");
603 $tp->assign("vijest", $isVijest ? true : false);
604 if ($ed_preview) {
605 $tp->assign("AUTHOR", GetAuthor(MyEscape(convert_html($author_url)),
606 MyEscape(convert_html($ed_author_alt)),
607 MyEscape(convert_html($ed_author_info)),
608 $width2, $height2));
609 }
610 $tp->assign("med", $isMed ? true : false);
611 $params = array();
612 if ($section) array_push($params, "section=$section");
613 if ($section_menu) array_push($params, "section_menu=$section_menu");
614 if ($section_menu2) array_push($params, "section_menu2=$section_menu2");
615 if ($spec) array_push($params, "spec=$spec");
616 if ($ed_id) array_push($params, "ed_id=$ed_id");
617 if ($ed_preview) array_push($params, "ed_preview=$ed_preview");
618 if ($trigger) array_push($params, "$trigger=1");
619 $tp->assign("FORM_ACTION", HTMLSpecialChars("?".implode("&", $params)));
620 if (!$ed_preview) {
621 global $onload;
622 $onload .= "document.forms[1].elements[0].focus();";
623 }
624 return $tp->fetch("edit.tpl");
625 }
626 ?>

  ViewVC Help
Powered by ViewVC 1.1.26