/[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.16 - (hide annotations)
Tue Oct 16 13:07:03 2001 UTC (17 years, 7 months ago) by ravilov
Branch: MAIN
Changes since 1.15: +54 -17 lines
Added a favicon for IE. Added a new Smarty modifier (js_popup). Fixed the news editor. Other bugfixes.

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

  ViewVC Help
Powered by ViewVC 1.1.26