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

Contents of /inc/newsEdit.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Fri Aug 3 09:12:42 2001 UTC (22 years, 8 months ago) by ravilov
Branch: pliva
CVS Tags: r0
Changes since 1.1: +0 -0 lines
initial import

1 <?php
2 # ---KLUDGE-BEGIN---
3 function ss(&$i, $k) {
4 if (is_array($i)) array_walk($i, "ss");
5 if (!is_string($i)) return;
6 $i = stripslashes($i);
7 if ($k) { global $$k; $$k = stripslashes($$k); }
8 }
9 $ss = array("HTTP_GET_VARS", "HTTP_POST_VARS", "HTTP_POST_FILES");
10 while (list($key, $val) = each($ss)) array_walk($$val, "ss");
11 # ---KLUDGE-END---
12 $phptmp = "php";
13 function sql($sql) {
14 # echo "<TT><B>[SQL]</B> $sql<BR>\n";
15 }
16 function newsEdit($art, $trigger = "") {
17 global $phptmp, $picdir, $syspicdir, $section, $dbh, $tpl;
18 global $ed_id, $ed_cat;
19 $i = 1;
20 global $ed_delete_main, $ed_del_main;
21 $delete_main = $ed_delete_main;
22 $del_main = $ed_del_main;
23 global $ed_clear_main, $ed_clr_main;
24 $clear_main = $ed_clear_main;
25 $clr_main = $ed_clr_main;
26 global $ed_titlepic_url, $ed_titlepic_url2, $ed_titlepic_name;
27 $titlepic_url = $ed_titlepic_url;
28 $titlepic_url2 = $ed_titlepic_url2;
29 $titlepic_name = $ed_titlepic_name;
30 if ($titlepic_url == "none") $titlepic_url = "";
31 while (true) {
32 global ${"ed_text_id_".$i};
33 if (!isset(${"ed_text_id_".$i})) break;
34 global ${"ed_delete_".$i}, ${"ed_del_".$i};
35 ${"delete_".$i} = ${"ed_delete_".$i};
36 ${"del_".$i} = ${"ed_del_".$i};
37 global ${"ed_clear_".$i}, ${"ed_clr_".$i};
38 ${"clear_".$i} = ${"ed_clear_".$i};
39 ${"clr_".$i} = ${"ed_clr_".$i};
40 global ${"ed_textpic_url_".$i},
41 ${"ed_textpic_url2_".$i}, ${"ed_textpic_name_".$i};
42 ${"textpic_url_".$i} = ${"ed_textpic_url_".$i};
43 ${"textpic_url2_".$i} = ${"ed_textpic_url2_".$i};
44 ${"textpic_name_".$i} = ${"ed_textpic_name_".$i};
45 if (${"textpic_url_".$i} == "none") ${"textpic_url_".$i} = "";
46 $i++;
47 }
48 global $cancel, $save;
49 if ($cancel || $save) {
50 if ($save) {
51 // Move temp pics & save article.
52 if (ereg("^$phptmp", $titlepic_url2) && $ed_id > 0) {
53 $sql = "SELECT title_pic FROM news WHERE (news_id = $ed_id)";
54 sql($sql);
55 $sth = $dbh->prepare($sql);
56 if (!$sth) error("Cannot prepare query: \"$sql\"");
57 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
58 $row = $sth->fetchrow_array();
59 $sth->finish();
60 $row = array_shift($row);
61 if ($row) MyDelete($syspicdir."/".$row);
62 }
63 global $ed_title, $ed_lead, $ed_titlepic_alt,
64 $ed_titlepic_pos, $ed_more, $ed_cat;
65 $ed_title = MyQuote($ed_title);
66 $ed_lead = MyQuote($ed_lead);
67 $ed_titlepic_nm = MyQuote(basename($titlepic_name));
68 $ed_titlepic_alt = MyQuote($ed_titlepic_alt);
69 $ed_more = MyQuote($ed_more);
70 if (!$ed_titlepic_pos) $ed_titlepic_pos = 0;
71 if ($ed_id > 0) {
72 $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, url = $ed_more, date = CURRENT_TIMESTAMP WHERE (news_id = $ed_id)";
73 sql($sql);
74 $dbh->dbh_do($sql);
75 } else {
76 $sql = "INSERT INTO news (category, title, lead, title_pic, title_alt, title_pos, url, date) VALUES ('$ed_cat', $ed_title, $ed_lead, $ed_titlepic_nm, $ed_titlepic_alt, $ed_titlepic_pos, $ed_more, CURRENT_TIMESTAMP)";
77 sql($sql);
78 $dbh->dbh_do($sql);
79 $sql = "SELECT news_id FROM news WHERE (title = $ed_title)";
80 sql($sql);
81 $sth = $dbh->prepare($sql);
82 if (!$sth) error("Cannot prepare query: \"$sql\"");
83 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
84 $rows = array();
85 while ($row = $sth->fetchrow_array()) array_push($rows, $row);
86 $sth->finish();
87 $row = array_pop($rows);
88 if (is_array($row)) $row = array_shift($row);
89 if ($row) $ed_id = $row;
90 }
91 if ($titlepic_url2) MyMove("$syspicdir/$titlepic_url2", "$syspicdir/$titlepic_name");
92 $i = 1;
93 while ($ed_id > 0 && isset(${"ed_text_id_".$i})) {
94 global ${"ed_text_title_".$i}, ${"ed_text_".$i},
95 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
96 ${"ed_text_level_".$i};
97 list($id, $tit, $txt, $pic, $orig, $alt, $pos, $del, $lev) = array(
98 ${"ed_text_id_".$i}, ${"ed_text_title_".$i},
99 ${"ed_text_".$i}, ${"textpic_url2_".$i}, ${"textpic_name_".$i},
100 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
101 ${"del_".$i}, ${"ed_text_level_".$i});
102 $tit = MyQuote($tit);
103 $txt = MyQuote($txt);
104 $orig = basename($orig);
105 $org = MyQuote($orig);
106 $alt = MyQuote($alt);
107 if (!$pos) $pos = 0;
108 if ($id && $id > 0) {
109 if ($del || !$orig) {
110 $sql = "SELECT pic FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
111 sql($sql);
112 $sth = $dbh->prepare($sql);
113 if (!$sth) error("Cannot prepare query: \"$sql\"");
114 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
115 while ($row = $sth->fetchrow_array()) {
116 list($pic) = $row;
117 MyDelete($syspicdir."/".$pic);
118 }
119 $sth->finish();
120 }
121 if ($del) $sql = "DELETE FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
122 else $sql = "UPDATE paragraphs SET title = $tit, level = $lev, text = $txt, pic = $org, alt = $alt, pos = $pos WHERE (news_id = $ed_id) AND (paragraph_id = $id)";
123 sql($sql);
124 $dbh->dbh_do($sql);
125 } else if (!$del) {
126 $sql = "INSERT INTO paragraphs (news_id, title, level, text, pic, alt, pos) VALUES ($ed_id, $tit, $lev, $txt, $org, $alt, $pos)";
127 sql($sql);
128 $dbh->dbh_do($sql);
129 $sql = "SELECT paragraph_id FROM paragraphs WHERE (text = $txt)";
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 $rows = array();
135 while ($row = $sth->fetchrow_array()) array_push($rows, $row);
136 $sth->finish();
137 $row = array_pop($rows);
138 if (is_array($row)) $row = array_shift($row);
139 $id = $row;
140 }
141 if ($pic) MyMove("$syspicdir/$pic", "$syspicdir/$orig");
142 $i++;
143 }
144 } else {
145 // Delete temp pics.
146 if (ereg("^$phptmp", $titlepic_url2))
147 MyDelete($syspicdir."/".$titlepic_url2);
148 $i = 1;
149 while (isset(${"ed_textpic_id_".$i})) {
150 $tmp = ${"textpic_url2_".$i};
151 if (ereg("^$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
152 $i++;
153 }
154 }
155 if (!$art["limit"]) $art["limit"] = 1;
156 if (!$art["npar"]) $art["npar"] = 1;
157 return array_shift(newsLoad($ed_id, $ed_cat,
158 $art["limit"], $art["npar"]));
159 }
160 // Handle temp pic upload.
161 global $HTTP_POST_FILES;
162 while (list($key, $val) = each($HTTP_POST_FILES)) {
163 list($name, $type, $tname, $size) = array(
164 $val["name"], $val["type"],
165 $val["tmp_name"], $val["size"]);
166 if ($size <= 0) continue;
167 if (!$name) continue;
168 if ($tname == "none") continue;
169 $nm = basename($tname);
170 $ext = ereg_replace('^.*(\..+)$', '\1', $name);
171 move_uploaded_file($tname, $syspicdir."/".$nm.$ext);
172 if ($key == "ed_titlepic_url") {
173 $titlepic_url = $nm.$ext;
174 $titlepic_name = $name;
175 $u = $titlepic_url2;
176 if (ereg("^$phptmp", $u)) MyDelete($syspicdir."/".$u);
177 unset($clear_main, $clr_main);
178 } else if (ereg("^ed_textpic_url_([1-9][0-9]*)$", $key, $regs)) {
179 $n = $regs[1];
180 ${"textpic_url_".$n} = $nm.$ext;
181 ${"textpic_name_".$n} = $name;
182 $u = ${"textpic_url2_".$n};
183 if (ereg("^$phptmp", $u)) MyDelete($syspicdir."/".$u2);
184 unset(${"clear_".$n}, ${"clr_".$n});
185 } else {
186 // [?!?]
187 }
188 }
189 // -----
190 $tp = new Smarty();
191 // -----
192 $categories = array();
193 $sql = "SELECT cat_id, text FROM news_categories ORDER BY text";
194 sql($sql);
195 $sth = $dbh->prepare($sql);
196 if (!$sth) error("Cannot prepare query: \"$sql\"");
197 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
198 while ($row = $sth->fetchrow_array()) array_push($categories, array("id" => $row[0], "txt" => $row[1]));
199 $sth->finish();
200 $tp->assign("categories", $categories);
201 // -----
202 $levels = array();
203 $sql = "SELECT level_id, class, name FROM par_levels ORDER BY name";
204 sql($sql);
205 $sth = $dbh->prepare($sql);
206 if (!$sth) error("Cannot prepare query: \"$sql\"");
207 if (!$sth->execute()) error("Cannot execute query: \"$sql\"");
208 while ($row = $sth->fetchrow_array()) array_push($levels, array("id" => $row[0], "class" => $row[1], "name" => $row[2]));
209 $sth->finish();
210 $tp->assign("levels", $levels);
211 // -----
212 global $ed_id, $ed_title, $ed_lead, $ed_titlepic_pos,
213 $ed_titlepic_alt, $ed_cat, $ed_more;
214 global $ed_edit, $ed_preview, $preview, $add;
215 if (!$ed_preview) $ed_preview = ($preview ? true : false);
216 if ($ed_edit) $ed_preview = false;
217 global $HTTP_POST_VARS, $HTTP_GET_VARS;
218 $delete = count(preg_grep('/^ed_delete_[0-9]+$/',
219 array_keys(array_merge($HTTP_GET_VARS,
220 $HTTP_POST_VARS)))) > 0;
221 $clear = (count(preg_grep('/^ed_clear_(main|[0-9]+)$/',
222 array_keys(array_merge($HTTP_GET_VARS,
223 $HTTP_POST_VARS)))) > 0);
224 $ed_pgfs = array();
225 if ($ed_edit || $ed_preview || $add || $delete || $clear) {
226 global $ed_title, $ed_lead, $ed_titlepic_pos,
227 $ed_titlepic_alt, $ed_cat, $ed_more;
228 if (!$HTTP_POST_FILES["ed_titlepic_url"]["name"]) $titlepic_url = "";
229 if (!$titlepic_url) $titlepic_url = $titlepic_url2;
230 if (!$titlepic_url && !($clear_main || $clr_main))
231 $titlepic_url = $art["pic_url"];
232 list($width, $height) = PicSize($titlepic_url);
233 $i = 1;
234 while (isset(${"ed_text_id_".$i})) {
235 $id = ${"ed_text_id_".$i};
236 global ${"ed_text_".$i}, ${"ed_text_title_".$i},
237 ${"ed_text_level_".$i}, ${"ed_textpic_alt_".$i},
238 ${"ed_textpic_pos_".$i};
239 $pic_url = ($HTTP_POST_FILES["ed_textpic_url_".$i]["name"]) ?
240 ${"textpic_url_".$i} : "";
241 if (!$pic_url) $pic_url = ${"textpic_url2_".$i};
242 $tmp = "";
243 for ($j = 0; $j < count($art["text"]); $j++)
244 if ($art["text"][$j]["id"] == $id) $tmp = $art["text"][$j]["pic"];
245 if (!$pic_url && $tmp && !(${"clear_".$i} || ${"clr_".$i})) $pic_url = $tmp;
246 $level = ${"ed_text_level_".$i};
247 $class = "";
248 while (list($key, $val) = each($levels))
249 if ($val["id"] == $level) $class = $val["class"];
250 array_push($ed_pgfs, array($id,
251 ${"ed_text_".$i}, ${"ed_text_title_".$i},
252 $level, $class, $pic_url, ${"textpic_name_".$i},
253 ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i},
254 false));
255 $i++;
256 }
257 } else {
258 list($ed_title, $ed_lead, $ed_titlepic_pos, $titlepic_url,
259 $titlepic_url2, $titlepic_name, $ed_titlepic_alt,
260 $ed_cat, $ed_more, $width, $height) = array($art["title"],
261 $art["lead"], $art["pic_pos"], $art["pic_url"],
262 $art["pic_url"], $art["pic_url"], $art["pic_alt"],
263 $art["category"], $art["more"], $art["pic_w"], $art["pic_h"]);
264 while ($art["text"] && list($id, $val) = each($art["text"])) {
265 list($id, $txt, $title, $lev, $cls, $pic, $alt, $pos, $w, $h) = array(
266 $val["id"], $val["text"], $val["title"], $val["level"],
267 $val["class"], $val["pic"], $val["alt"], $val["pos"],
268 $val["w"], $val["h"]);
269 array_push($ed_pgfs, array($id, $txt, $title, $lev, $cls, $pic, $pic, $alt,
270 $pos, $w, $h, false));
271 }
272 $ed_id = $art["id"];
273 if (!$ed_id) $ed_id = -1;
274 }
275 if ($add) {
276 global $add_num;
277 for ($i = 0; $i < intval($add_num); $i++)
278 array_push($ed_pgfs, array(-1, "", "", -1, "", "", "", "", 0, 0, 0, true));
279 }
280 $ed_text = array();
281 $ed_empties = false;
282 $ed_records = array();
283 $i = 1;
284 while (list($key, $val) = each($ed_pgfs)) {
285 list($id, $txt, $tit, $lev, $cls, $pic, $name, $alt, $pos, $w, $h, $new) = $val;
286 $del = ((${"delete_".$i} || ${"del_".$i}) ? true : false);
287 array_push($ed_records, array("val" => $del, "id" => $id));
288 if ($del) { $i++; continue; }
289 $picurl = ${"textpic_url_".$id};
290 if (!$picurl) $picurl = $pic;
291 $class = "";
292 while (list($key, $val) = each($levels))
293 if ($val["id"] == $lev) $class = $val["class"];
294 if ((${"clear_".$i} || ${"clr_".$i}) && $ed_preview && (${"textpic_name_".$i} != ${"textpic_url2_".$i})) {
295 $tmp = ${"textpic_url2_".$i};
296 if (ereg("^$phptmp", $tmp)) MyDelete($syspicdir."/".$tmp);
297 $picurl = ${"textpic_url_".$i} = ${"textpic_url2_".$i} = $name = "";
298 }
299 if (!$name) $name = $picurl;
300 $txt = MyEscape($txt);
301 $txt2 = ParseNewline($txt);
302 $empty = (($ed_preview && !$txt && !$pos && !$new) ? true : false);
303 $ed_empty = $ed_empty && $empty;
304 global ${"ed_text_force_".$i};
305 $ed_empties = $ed_empties || ($empty && !${"ed_text_force_".$i});
306 array_push($ed_text, array(
307 "id" => $id,
308 "n" => $i,
309 "txt" => $txt2,
310 "txt2" => $txt,
311 "title" => MyEscape($tit),
312 "level" => $lev,
313 "class" => MyEscape($class),
314 "url" => MyEscape($picurl),
315 "name" => MyEscape($name),
316 "alt" => MyEscape($alt),
317 "width" => $w,
318 "height" => $h,
319 "pos" => $pos,
320 "empty" => $empty,
321 "clr" => (${"clear_".$i} || ${"clr_".$i} || !$picurl) ? true : false
322 ));
323 $i++;
324 }
325 if ($ed_empties) $ed_preview = false;
326 $tp->assign("ed_id", $ed_id);
327 $tp->assign("ed_cat", $ed_cat);
328 $tp->assign("ed_preview", $ed_preview);
329 $tp->assign("ed_trigger", $trigger);
330 $tp->assign("ed_title", MyEscape($ed_title));
331 $tp->assign("ed_lead", MyEscape($ed_lead));
332 $tp->assign("ed_titlepic_pos", $ed_titlepic_pos);
333 $tp->assign("ed_titlepic_url", MyEscape($titlepic_url));
334 $tp->assign("ed_titlepic_url2", MyEscape($titlepic_url2));
335 $tp->assign("ed_titlepic_name", MyEscape($titlepic_name));
336 $tp->assign("ed_titlepic_alt", MyEscape($ed_titlepic_alt));
337 $tp->assign("ed_titlepic_width", $width);
338 $tp->assign("ed_titlepic_height", $height);
339 $tp->assign("ed_more", MyEscape($ed_more));
340 $tp->assign("ed_clr_main", ($clear_main || $clr_main || !$titlepic_url) ? true : false);
341 $tp->assign("ed_text", $ed_text);
342 $tp->assign("ed_empty", $ed_empty);
343 $tp->assign("ed_empties", $ed_empties);
344 $tp->assign("ed_read", count($ed_text) > 1);
345 $tp->assign("ed_records", $ed_records);
346 $tp->assign("newspicdir", "$picdir/");
347 $params = array();
348 if ($section) array_push($params, "section=$section");
349 if ($ed_id) array_push($params, "ed_id=$ed_id");
350 if ($ed_preview) array_push($params, "ed_preview=$ed_preview");
351 if ($trigger) array_push($params, "$trigger=1");
352 global $PHP_SELF;
353 $tp->assign("FORM_ACTION", $PHP_SELF.HTMLSpecialChars("?".implode("&", $params)));
354 return $tp->fetch("edit.tpl");
355 }
356 ?>

  ViewVC Help
Powered by ViewVC 1.1.26