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

  ViewVC Help
Powered by ViewVC 1.1.26