/[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

Annotation of /inc/newsEdit.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations)
Tue Oct 23 16:13:59 2001 UTC (22 years, 6 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 ravilov 1.1 <?php
2 ravilov 1.7 set_magic_quotes_runtime(false);
3 ravilov 1.1 # ---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 ravilov 1.5 $phptmp = "^php";
14 ravilov 1.1 function sql($sql) {
15 ravilov 1.7 #echo "<TT><B>[SQL]</B> $sql<BR>\n";
16 ravilov 1.1 }
17 ravilov 1.7 function my_cmp($a, $b) { return MyCompare($a["txt"], $b["txt"]); }
18 ravilov 1.16 function my_cmp_2($a, $b) { return MyCompare($a["ime"], $b["ime"]); }
19 ravilov 1.7 function newsEdit($art, $trigger = "", $isVijest = false) {
20 ravilov 1.16 global $phptmp, $picdir, $syspicdir, $aupicdir, $sysaupicdir, $dbh;
21 ravilov 1.9 global $section, $section_menu, $section_menu2, $spec;
22 ravilov 1.7 global $ed_id, $ed_cat, $isMed;
23 ravilov 1.1 $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 ravilov 1.7 global $ed_clear_author, $ed_clr_author;
29 ravilov 1.1 $clear_main = $ed_clear_main;
30     $clr_main = $ed_clr_main;
31 ravilov 1.7 $clear_author = $ed_clear_author;
32     $clr_author = $ed_clr_author;
33 ravilov 1.1 global $ed_titlepic_url, $ed_titlepic_url2, $ed_titlepic_name;
34     $titlepic_url = $ed_titlepic_url;
35     $titlepic_url2 = $ed_titlepic_url2;
36 ravilov 1.7 $titlepic_name = urldecode($ed_titlepic_name);
37     # Fix for M$IE
38 ravilov 1.1 if ($titlepic_url == "none") $titlepic_url = "";
39 ravilov 1.7 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 ravilov 1.1 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 ravilov 1.15 global ${"ed_fclear_".$i}, ${"ed_fclr_".$i};
55     ${"fclear_".$i} = ${"ed_fclear_".$i};
56     ${"fclr_".$i} = ${"ed_fclr_".$i};
57 ravilov 1.7 global ${"ed_textpic_url_".$i}, ${"ed_textpic_url2_".$i}, ${"ed_textpic_name_".$i};
58 ravilov 1.1 ${"textpic_url_".$i} = ${"ed_textpic_url_".$i};
59     ${"textpic_url2_".$i} = ${"ed_textpic_url2_".$i};
60 ravilov 1.7 ${"textpic_name_".$i} = urldecode(${"ed_textpic_name_".$i});
61     # Fix for M$IE
62 ravilov 1.1 if (${"textpic_url_".$i} == "none") ${"textpic_url_".$i} = "";
63 ravilov 1.15 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 ravilov 1.1 $i++;
70     }
71 ravilov 1.7 // -----
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 ravilov 1.16 $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 ravilov 1.17 $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 ravilov 1.7 $specs = array();
109 ravilov 1.8 $sql = "SELECT spec_id, opis FROM specijalizacije WHERE (spec_id != 0) AND (NOT link)";
110 ravilov 1.7 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 ravilov 1.16 array_unshift($specs, array("id" => 0, "txt" => "HOME"));
118 ravilov 1.7 // -----
119 ravilov 1.8 $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 ravilov 1.1 global $cancel, $save;
129     if ($cancel || $save) {
130     if ($save) {
131     // Move temp pics & save article.
132 ravilov 1.8 if (ereg("$phptmp", $titlepic_url2) && $ed_id > 0 && file_exists("$syspicdir/$titlepic_url2")) {
133 ravilov 1.1 $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 ravilov 1.8 if (ereg("$phptmp", $author_url2) && $ed_id > 0 && file_exists("$sysaupicdir/$author_url2")) {
144 ravilov 1.7 $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 ravilov 1.1 global $ed_title, $ed_lead, $ed_titlepic_alt,
155 ravilov 1.6 $ed_titlepic_pos, $ed_more, $ed_more_title,
156 ravilov 1.11 $ed_cat, $ed_author_alt, $ed_author_info,
157 ravilov 1.16 $ed_author_ime, $ed_author_cv, $ed_prikazi;
158 ravilov 1.1 $ed_title = MyQuote($ed_title);
159     $ed_lead = MyQuote($ed_lead);
160 ravilov 1.7 $ed_author_nm = urldecode(MyQuote(basename($author_name)));
161     $ed_author_alt = MyQuote($ed_author_alt);
162 ravilov 1.11 $ed_author_ime = MyQuote($ed_author_ime);
163 ravilov 1.7 $ed_author_info = MyQuote($ed_author_info);
164     $ed_titlepic_nm = urldecode(MyQuote(basename($titlepic_name)));
165 ravilov 1.1 $ed_titlepic_alt = MyQuote($ed_titlepic_alt);
166     $ed_more = MyQuote($ed_more);
167 ravilov 1.6 $ed_more_title = MyQuote($ed_more_title);
168 ravilov 1.1 if (!$ed_titlepic_pos) $ed_titlepic_pos = 0;
169 ravilov 1.16 if (!$ed_author_cv) $ed_author_cv = 0;
170 ravilov 1.1 if ($ed_id > 0) {
171 ravilov 1.16 $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 ravilov 1.1 sql($sql);
173     $dbh->dbh_do($sql);
174     } else {
175 ravilov 1.16 $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 ravilov 1.1 sql($sql);
177     $dbh->dbh_do($sql);
178 ravilov 1.10 $sql = "SELECT currval('news_news_id_seq')::text";
179 ravilov 1.1 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 ravilov 1.7 if ($titlepic_url2) MyMove("$syspicdir/$titlepic_url2", urldecode("$syspicdir/$titlepic_name"));
191     if ($author_url2) MyMove("$sysaupicdir/$author_url2", urldecode("$sysaupicdir/$author_name"));
192 ravilov 1.1 $i = 1;
193 ravilov 1.8 $parents = array();
194     $last_level = 0;
195     $last_id = 0;
196 ravilov 1.1 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 ravilov 1.8 ${"ed_text_level_".$i}, ${"ed_hl_".$i},
200     ${"ed_textpic_exp_".$i};
201 ravilov 1.16 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 ravilov 1.15 ${"ed_textpic_pos_".$i}, ${"del_".$i}, ${"ed_text_level_".$i},
206     ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i});
207 ravilov 1.8 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 ravilov 1.1 $tit = MyQuote($tit);
217     $txt = MyQuote($txt);
218 ravilov 1.8 $exp = MyQuote($exp);
219 ravilov 1.7 $hl = MyQuote($hl);
220 ravilov 1.1 $orig = basename($orig);
221     $org = MyQuote($orig);
222 ravilov 1.16 $forig = basename($forig);
223     $forg = MyQuote($forig);
224 ravilov 1.1 $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 ravilov 1.16 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 ravilov 1.1 if ($del) $sql = "DELETE FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
252 ravilov 1.16 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 ravilov 1.1 sql($sql);
254     $dbh->dbh_do($sql);
255     } else if (!$del) {
256 ravilov 1.16 $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 ravilov 1.1 sql($sql);
258     $dbh->dbh_do($sql);
259 ravilov 1.8 $sql = "SELECT currval('paragraphs_paragraph_id_seq')::text";
260 ravilov 1.1 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 ravilov 1.8 $row = $sth->fetchrow_array();
265 ravilov 1.1 $sth->finish();
266 ravilov 1.8 $row = array_shift($row);
267     $last_id = $id = $row;
268 ravilov 1.1 }
269     if ($pic) MyMove("$syspicdir/$pic", "$syspicdir/$orig");
270 ravilov 1.16 if ($full) MyMove("$syspicdir/$full", "$syspicdir/$forig");
271 ravilov 1.1 $i++;
272     }
273 ravilov 1.7 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 ravilov 1.16 $var = "ed_spec_".$specs[$k]["id"];
279     global $$var;
280 ravilov 1.7 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 ravilov 1.17 $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 ravilov 1.7 $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 ravilov 1.8 if ($categories[$k]["id"] != $ed_cat && !$$var) continue;
309 ravilov 1.7 $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 ravilov 1.1 } else {
315     // Delete temp pics.
316 ravilov 1.7 if (ereg("$phptmp", $titlepic_url2)) MyDelete($syspicdir."/".$titlepic_url2);
317     if (ereg("$phptmp", $author_url2)) MyDelete($sysaupicdir."/".$author_url2);
318 ravilov 1.1 $i = 1;
319     while (isset(${"ed_textpic_id_".$i})) {
320     $tmp = ${"textpic_url2_".$i};
321 ravilov 1.5 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
322 ravilov 1.15 $tmp = ${"textpic_full2_".$i};
323     if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
324 ravilov 1.1 $i++;
325     }
326     }
327 ravilov 1.2 if (!isset($art["limit"])) $art["limit"] = 1;
328     if (!isset($art["npar"])) $art["npar"] = 1;
329 ravilov 1.1 return array_shift(newsLoad($ed_id, $ed_cat,
330 ravilov 1.4 $art["limit"], $art["offset"], $art["npar"]));
331 ravilov 1.1 }
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 ravilov 1.8 $name = strtr($name, "¹šðè澞©ŠÐÈÆ®Ž ", "ssdcczzSSDCCZZ_");
342 ravilov 1.1 $nm = basename($tname);
343     $ext = ereg_replace('^.*(\..+)$', '\1', $name);
344     if ($key == "ed_titlepic_url") {
345 ravilov 1.7 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
346 ravilov 1.1 $titlepic_url = $nm.$ext;
347     $titlepic_name = $name;
348     $u = $titlepic_url2;
349 ravilov 1.5 if (ereg("$phptmp", $u)) MyDelete($syspicdir."/".$u);
350 ravilov 1.1 unset($clear_main, $clr_main);
351 ravilov 1.7 } 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 ravilov 1.1 } else if (ereg("^ed_textpic_url_([1-9][0-9]*)$", $key, $regs)) {
359 ravilov 1.7 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
360 ravilov 1.1 $n = $regs[1];
361     ${"textpic_url_".$n} = $nm.$ext;
362     ${"textpic_name_".$n} = $name;
363     $u = ${"textpic_url2_".$n};
364 ravilov 1.5 if (ereg("$phptmp", $u)) MyDelete($syspicdir."/".$u2);
365 ravilov 1.1 unset(${"clear_".$n}, ${"clr_".$n});
366 ravilov 1.15 } 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 ravilov 1.1 } else {
375 ravilov 1.15 // ?!?
376 ravilov 1.1 }
377     }
378     // -----
379     $tp = new Smarty();
380     $tp->assign("levels", $levels);
381 ravilov 1.16 $tp->assign("autori", $autori);
382 ravilov 1.17 $tp->assign("newsi", $newsi);
383 ravilov 1.1 // -----
384     global $ed_id, $ed_title, $ed_lead, $ed_titlepic_pos,
385 ravilov 1.6 $ed_titlepic_alt, $ed_cat, $ed_more,
386 ravilov 1.7 $ed_more_title, $ed_author_url, $ed_author_alt,
387 ravilov 1.12 $ed_author_info, $ed_author_ime, $ed_prikazi;
388 ravilov 1.1 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 ravilov 1.7 global $ed_clear_author;
396     $clear = (count(preg_grep('/^ed_clear_(main|author|[0-9]+)$/',
397 ravilov 1.1 array_keys(array_merge($HTTP_GET_VARS,
398     $HTTP_POST_VARS)))) > 0);
399     $ed_pgfs = array();
400 ravilov 1.2 $ed_warning = 0;
401 ravilov 1.7 $nspecs = array();
402     $ncats = array();
403 ravilov 1.17 $related = array();
404 ravilov 1.7 // Transfer data
405 ravilov 1.1 if ($ed_edit || $ed_preview || $add || $delete || $clear) {
406 ravilov 1.7 for ($i = 0; $i < count($specs); $i++) {
407     $var = "ed_spec_".$specs[$i]["id"];
408     global $$var;
409 ravilov 1.16 $foo = isset($$var) ? $$var : ($spec && $spec == $specs[$i]["id"]);
410     $nspecs[$specs[$i]["id"]] = $foo ? true : false;
411 ravilov 1.7 }
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 ravilov 1.1 global $ed_title, $ed_lead, $ed_titlepic_pos,
418 ravilov 1.17 $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 ravilov 1.1 if (!$HTTP_POST_FILES["ed_titlepic_url"]["name"]) $titlepic_url = "";
422     if (!$titlepic_url) $titlepic_url = $titlepic_url2;
423 ravilov 1.7 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 ravilov 1.1 list($width, $height) = PicSize($titlepic_url);
426 ravilov 1.7 list($width2, $height2) = PicSize($author_url, $sysaupicdir);
427 ravilov 1.2 global $ed_title_force;
428     if ($titlepic_url && !$ed_titlepic_pos && !$ed_title_force) $ed_warning = 2;
429 ravilov 1.1 $i = 1;
430 ravilov 1.17 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 ravilov 1.1 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 ravilov 1.8 ${"ed_textpic_pos_".$i}, ${"ed_hl_".$i},
443     ${"ed_textpic_exp_".$i};
444 ravilov 1.1 $pic_url = ($HTTP_POST_FILES["ed_textpic_url_".$i]["name"]) ?
445     ${"textpic_url_".$i} : "";
446     if (!$pic_url) $pic_url = ${"textpic_url2_".$i};
447 ravilov 1.15 $full_url = ($HTTP_POST_FILES["ed_textpic_full_".$i]["name"]) ?
448     ${"textpic_full_".$i} : "";
449     if (!$full_url) $full_url = ${"textpic_full2_".$i};
450 ravilov 1.1 $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 ravilov 1.15 $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 ravilov 1.1 $level = ${"ed_text_level_".$i};
459 ravilov 1.8 list($w, $h) = PicSize($pic_url);
460 ravilov 1.15 list($w2, $h2) = PicSize($full_url);
461 ravilov 1.1 array_push($ed_pgfs, array($id,
462     ${"ed_text_".$i}, ${"ed_text_title_".$i},
463 ravilov 1.8 $level, $pic_url, ${"textpic_name_".$i},
464 ravilov 1.15 $full_url, ${"textpic_fname_".$i},
465 ravilov 1.1 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
466 ravilov 1.15 $w, $h, $w2, $h2, ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i}, false));
467 ravilov 1.1 $i++;
468     }
469     } else {
470 ravilov 1.7 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 ravilov 1.17 $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 ravilov 1.16 } 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 ravilov 1.1 list($ed_title, $ed_lead, $ed_titlepic_pos, $titlepic_url,
501     $titlepic_url2, $titlepic_name, $ed_titlepic_alt,
502 ravilov 1.7 $ed_cat, $ed_more, $ed_more_title, $width, $height,
503     $author_url, $author_url2, $author_name,
504 ravilov 1.11 $ed_author_alt, $ed_author_info, $width2, $height2,
505 ravilov 1.16 $ed_author_ime, $ed_author_cv, $ed_prikazi) = array($art["title"],
506     $art["lead"], $art["pic_pos"], $art["pic_url"], $art["pic_url"],
507 ravilov 1.12 urldecode($art["pic_url"]), $art["pic_alt"], $art["category"],
508     $art["more"], $art["more_title"], $art["pic_w"], $art["pic_h"],
509 ravilov 1.7 $art["au_pic"], $art["au_pic"], urldecode($art["au_pic"]),
510 ravilov 1.11 $art["au_alt"], $art["au_info"], $art["au_w"], $art["au_h"],
511 ravilov 1.16 $art["au_name"], $art["au_cv"], $art["show"]);
512 ravilov 1.12 if ($art["text"]) reset($art["text"]);
513 ravilov 1.1 while ($art["text"] && list($id, $val) = each($art["text"])) {
514 ravilov 1.7 array_push($ed_pgfs, array($val["id"], $val["text"], $val["title"],
515 ravilov 1.8 $val["level"], urldecode($val["pic"]),
516 ravilov 1.15 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 ravilov 1.1 }
520     $ed_id = $art["id"];
521     if (!$ed_id) $ed_id = -1;
522     }
523 ravilov 1.17 for ($i = count($related); $i < 10; $i++) array_push($related, 0);
524     $tp->assign("related", $related);
525 ravilov 1.7 $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 ravilov 1.1 if ($add) {
535     global $add_num;
536     for ($i = 0; $i < intval($add_num); $i++)
537 ravilov 1.15 array_push($ed_pgfs, array(-1, "", "", -1, "", "", "", "", "", 0, 0, 0, 0, 0, "", "", true));
538 ravilov 1.1 }
539 ravilov 1.3 $ed_empty = ($ed_title || $ed_lead || $ed_titlepic_pos || $ed_more) ? false : true;
540 ravilov 1.1 $ed_text = array();
541     $ed_records = array();
542 ravilov 1.2 $ed_warnings = ($ed_warning ? true : false);
543 ravilov 1.1 $i = 1;
544     while (list($key, $val) = each($ed_pgfs)) {
545 ravilov 1.15 list($id, $txt, $tit, $lev, $pic, $name, $fpic, $fname, $alt, $pos, $w, $h, $fw, $fh, $hl, $exp, $new) = $val;
546 ravilov 1.1 $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 ravilov 1.15 $fullurl = ${"textpic_full_".$id};
552     if (!$fullurl) $fullurl = $fpic;
553 ravilov 1.1 $class = "";
554 ravilov 1.8 reset($levels);
555     while (list($k, $v) = each($levels)) if ($v["id"] == $lev) $class = $v["class"];
556 ravilov 1.1 if ((${"clear_".$i} || ${"clr_".$i}) && $ed_preview && (${"textpic_name_".$i} != ${"textpic_url2_".$i})) {
557     $tmp = ${"textpic_url2_".$i};
558 ravilov 1.5 if (ereg("$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
559 ravilov 1.1 $picurl = ${"textpic_url_".$i} = ${"textpic_url2_".$i} = $name = "";
560     }
561     if (!$name) $name = $picurl;
562 ravilov 1.15 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 ravilov 1.17 // ----
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 ravilov 1.2 global ${"ed_text_force_".$i};
579     $force = ${"ed_text_force_".$i};
580 ravilov 1.1 $empty = (($ed_preview && !$txt && !$pos && !$new) ? true : false);
581 ravilov 1.2 $warning = 0;
582     if ($empty && !$force) $warning = 1;
583     if ($picurl && !$pos && !$force) $warning = 2;
584 ravilov 1.1 $ed_empty = $ed_empty && $empty;
585 ravilov 1.2 $ed_warnings = $ed_warnings || ($warning && !$force);
586 ravilov 1.1 array_push($ed_text, array(
587     "id" => $id,
588     "n" => $i,
589     "txt" => $txt2,
590     "txt2" => $txt,
591 ravilov 1.7 "txt3" => $txt3,
592     "hl" => $hl2,
593     "hl2" => $hl,
594     "hl3" => $hl3,
595 ravilov 1.5 "title" => MyEscape(convert_html($tit)),
596 ravilov 1.1 "level" => $lev,
597 ravilov 1.5 "class" => MyEscape(convert_html($class)),
598     "url" => MyEscape(convert_html($picurl)),
599     "name" => MyEscape(convert_html($name)),
600 ravilov 1.15 "full" => MyEscape(convert_html($fullurl)),
601     "fname" => MyEscape(convert_html($fname)),
602 ravilov 1.5 "alt" => MyEscape(convert_html($alt)),
603 ravilov 1.8 "w" => $w,
604     "h" => $h,
605 ravilov 1.15 "fw" => $fw,
606     "fh" => $fh,
607 ravilov 1.1 "pos" => $pos,
608 ravilov 1.8 "exp" => MyEscape(convert_html($exp)),
609 ravilov 1.2 "warning" => $warning,
610 ravilov 1.15 "clr" => (${"clear_".$i} || ${"clr_".$i} || !$picurl) ? true : false,
611     "fclr" => (${"fclear_".$i} || ${"fclr_".$i} || !$fullurl) ? true : false
612 ravilov 1.1 ));
613     $i++;
614     }
615 ravilov 1.2 if ($ed_warnings) $ed_preview = false;
616 ravilov 1.1 $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 ravilov 1.5 $tp->assign("ed_title", MyEscape(convert_html($ed_title)));
621 ravilov 1.14 $tp->assign("ed_lead", MyEscape(convert_html($ed_lead), true));
622     $tp->assign("ed_lead2", ParseNewline(MyEscape(convert_html($ed_lead), false), false));
623 ravilov 1.1 $tp->assign("ed_titlepic_pos", $ed_titlepic_pos);
624 ravilov 1.5 $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 ravilov 1.1 $tp->assign("ed_titlepic_width", $width);
629     $tp->assign("ed_titlepic_height", $height);
630 ravilov 1.7 $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 ravilov 1.11 $tp->assign("ed_author_ime", MyEscape(convert_html($ed_author_ime)));
636 ravilov 1.7 $tp->assign("ed_author_width", $width2);
637     $tp->assign("ed_author_height", $height2);
638 ravilov 1.1 $tp->assign("ed_more", MyEscape($ed_more));
639 ravilov 1.7 $tp->assign("ed_more_new", strstr($ed_more, "://") ? true : false);
640 ravilov 1.6 $tp->assign("ed_more_title", MyEscape($ed_more_title));
641 ravilov 1.12 $tp->assign("ed_prikazi", $ed_prikazi);
642 ravilov 1.16 $tp->assign("ed_author_cv", $ed_author_cv);
643 ravilov 1.1 $tp->assign("ed_clr_main", ($clear_main || $clr_main || !$titlepic_url) ? true : false);
644 ravilov 1.7 $tp->assign("ed_clr_author", ($clear_author || $clr_author || !$author_url) ? true : false);
645 ravilov 1.1 $tp->assign("ed_text", $ed_text);
646     $tp->assign("ed_empty", $ed_empty);
647 ravilov 1.2 $tp->assign("ed_warning", $ed_warning);
648     $tp->assign("ed_warnings", $ed_warnings);
649 ravilov 1.1 $tp->assign("ed_records", $ed_records);
650     $tp->assign("newspicdir", "$picdir/");
651 ravilov 1.7 $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 ravilov 1.17 $width2, $height2, $ed_author_cv));
658 ravilov 1.7 }
659     $tp->assign("med", $isMed ? true : false);
660 ravilov 1.1 $params = array();
661     if ($section) array_push($params, "section=$section");
662 ravilov 1.6 if ($section_menu) array_push($params, "section_menu=$section_menu");
663 ravilov 1.9 if ($section_menu2) array_push($params, "section_menu2=$section_menu2");
664     if ($spec) array_push($params, "spec=$spec");
665 ravilov 1.1 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 ravilov 1.9 $tp->assign("FORM_ACTION", HTMLSpecialChars("?".implode("&", $params)));
669 ravilov 1.7 if (!$ed_preview) {
670     global $onload;
671 ravilov 1.8 $onload .= "document.forms[1].elements[0].focus();";
672 ravilov 1.7 }
673 ravilov 1.1 return $tp->fetch("edit.tpl");
674     }
675     ?>

  ViewVC Help
Powered by ViewVC 1.1.26