/[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.17 - (show annotations)
Tue Oct 23 16:13:59 2001 UTC (17 years, 10 months ago) by ravilov
Branch: MAIN
Changes since 1.16: +68 -19 lines
Added an author's CV. Added a secondary main article. Added the Related fields to news editor, and also fixed some bugs in it. Other bugfixes and improvements.

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

  ViewVC Help
Powered by ViewVC 1.1.26