--- inc/newsEdit.php 2001/10/12 13:13:38 1.15 +++ inc/newsEdit.php 2001/10/16 13:07:03 1.16 @@ -15,8 +15,9 @@ #echo "[SQL] $sql
\n"; } function my_cmp($a, $b) { return MyCompare($a["txt"], $b["txt"]); } + function my_cmp_2($a, $b) { return MyCompare($a["ime"], $b["ime"]); } function newsEdit($art, $trigger = "", $isVijest = false) { - global $phptmp, $picdir, $syspicdir, $aupicdir, $sysaupicdir, $dbh, $tpl; + global $phptmp, $picdir, $syspicdir, $aupicdir, $sysaupicdir, $dbh; global $section, $section_menu, $section_menu2, $spec; global $ed_id, $ed_cat, $isMed; $i = 1; @@ -79,6 +80,16 @@ $sth->finish(); usort($categories, "my_cmp"); // ----- + $autori = array(); + $sql = "SELECT autor_id, ime FROM autori"; +sql($sql); + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth->fetchrow_array()) array_push($autori, array("id" => $row[0], "ime" => MyEscape($row[1], false))); + $sth->finish(); + usort($autori, "my_cmp_2"); + // ----- $specs = array(); $sql = "SELECT spec_id, opis FROM specijalizacije WHERE (spec_id != 0) AND (NOT link)"; sql($sql); @@ -88,6 +99,7 @@ while ($row = $sth->fetchrow_array()) array_push($specs, array("id" => $row[0], "txt" => $row[1])); $sth->finish(); usort($specs, "my_cmp"); + array_unshift($specs, array("id" => 0, "txt" => "HOME")); // ----- $levels = array(); $sql = "SELECT level_id, class, name FROM par_levels ORDER BY name"; @@ -127,7 +139,7 @@ global $ed_title, $ed_lead, $ed_titlepic_alt, $ed_titlepic_pos, $ed_more, $ed_more_title, $ed_cat, $ed_author_alt, $ed_author_info, - $ed_author_ime, $ed_prikazi; + $ed_author_ime, $ed_author_cv, $ed_prikazi; $ed_title = MyQuote($ed_title); $ed_lead = MyQuote($ed_lead); $ed_author_nm = urldecode(MyQuote(basename($author_name))); @@ -139,12 +151,13 @@ $ed_more = MyQuote($ed_more); $ed_more_title = MyQuote($ed_more_title); if (!$ed_titlepic_pos) $ed_titlepic_pos = 0; + if (!$ed_author_cv) $ed_author_cv = 0; if ($ed_id > 0) { - $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, 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)"; + $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)"; sql($sql); $dbh->dbh_do($sql); } else { - $sql = "INSERT INTO news (category, title, lead, title_pic, title_alt, title_pos, author_pic, author_alt, author_info, author_name, 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_more, $ed_more_title, ".($isMed?"true":"false").", ".($ed_prikazi?"true":"false").", NOW(), NOW())"; + $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())"; sql($sql); $dbh->dbh_do($sql); $sql = "SELECT currval('news_news_id_seq')::text"; @@ -170,10 +183,10 @@ ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i}, ${"ed_text_level_".$i}, ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i}; - list($id, $tit, $txt, $pic, $full, $orig, $alt, $pos, $del, $lev, $hl, $exp) = array( - ${"ed_text_id_".$i}, ${"ed_text_title_".$i}, - ${"ed_text_".$i}, ${"textpic_url2_".$i}, ${"textpic_full2_".$i}, - ${"textpic_name_".$i}, ${"ed_textpic_alt_".$i}, + list($id, $tit, $txt, $pic, $orig,$full, $forig, $alt, $pos, $del, $lev, $hl, $exp) = array( + ${"ed_text_id_".$i}, ${"ed_text_title_".$i}, ${"ed_text_".$i}, + ${"textpic_url2_".$i}, ${"textpic_name_".$i}, ${"textpic_full2_".$i}, + ${"textpic_fname_".$i}, ${"ed_textpic_alt_".$i}, ${"ed_textpic_pos_".$i}, ${"del_".$i}, ${"ed_text_level_".$i}, ${"ed_hl_".$i}, ${"ed_textpic_exp_".$i}); if ($lev != $last_level) { @@ -191,6 +204,8 @@ $hl = MyQuote($hl); $orig = basename($orig); $org = MyQuote($orig); + $forig = basename($forig); + $forg = MyQuote($forig); $alt = MyQuote($alt); if (!$pos) $pos = 0; if ($id && $id > 0) { @@ -206,12 +221,24 @@ } $sth->finish(); } + if ($del || !$forig) { + $sql = "SELECT full_pic FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)"; +sql($sql); + $sth = $dbh->prepare($sql); + if (!$sth) error("Cannot prepare query: \"$sql\""); + if (!$sth->execute()) error("Cannot execute query: \"$sql\""); + while ($row = $sth->fetchrow_array()) { + list($pic) = $row; + MyDelete($syspicdir."/".$pic); + } + $sth->finish(); + } if ($del) $sql = "DELETE FROM paragraphs WHERE (news_id = $ed_id) AND (paragraph_id = $id)"; - else $sql = "UPDATE paragraphs SET title = $tit, level = $lev, text = $txt, hl = $hl, pic = $org, alt = $alt, pos = $pos, pic_title = $exp WHERE (news_id = $ed_id) AND (paragraph_id = $id)"; + 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)"; sql($sql); $dbh->dbh_do($sql); } else if (!$del) { - $sql = "INSERT INTO paragraphs (news_id, title, level, text, pic, alt, pos, hl, pic_title) VALUES ($ed_id, $tit, $lev, $txt, $org, $alt, $pos, $hl, $exp)"; + $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)"; sql($sql); $dbh->dbh_do($sql); $sql = "SELECT currval('paragraphs_paragraph_id_seq')::text"; @@ -225,6 +252,7 @@ $last_id = $id = $row; } if ($pic) MyMove("$syspicdir/$pic", "$syspicdir/$orig"); + if ($full) MyMove("$syspicdir/$full", "$syspicdir/$forig"); $i++; } if ($ed_id) { @@ -232,7 +260,8 @@ sql($sql); $dbh->dbh_do($sql); for ($k = 0; $k < count($specs); $k++) { - $var = "ed_spec_".$specs[$k]["id"]; global $$var; + $var = "ed_spec_".$specs[$k]["id"]; + global $$var; if (!$$var) continue; $sql = "INSERT INTO spec_news (news_id, spec_id) VALUES ($ed_id, ".$specs[$k]["id"].")"; sql($sql); @@ -317,6 +346,7 @@ // ----- $tp = new Smarty(); $tp->assign("levels", $levels); + $tp->assign("autori", $autori); // ----- global $ed_id, $ed_title, $ed_lead, $ed_titlepic_pos, $ed_titlepic_alt, $ed_cat, $ed_more, @@ -342,7 +372,8 @@ for ($i = 0; $i < count($specs); $i++) { $var = "ed_spec_".$specs[$i]["id"]; global $$var; - $nspecs[$specs[$i]["id"]] = $$var ? true : false; + $foo = isset($$var) ? $$var : ($spec && $spec == $specs[$i]["id"]); + $nspecs[$specs[$i]["id"]] = $foo ? true : false; } for ($i = 0; $i < count($categories); $i++) { $var = "ed_cat_".$categories[$i]["id"]; @@ -353,7 +384,8 @@ $ed_titlepic_alt, $ed_cat, $ed_more, $ed_more_title, $ed_author_url, $ed_author_alt, $ed_author_info, - $ed_author_ime, $ed_prikazi; + $ed_author_ime, $ed_author_cv, + $ed_prikazi; if (!$HTTP_POST_FILES["ed_titlepic_url"]["name"]) $titlepic_url = ""; if (!$titlepic_url) $titlepic_url = $titlepic_url2; if (!$titlepic_url && !($clear_main || $clr_main)) $titlepic_url = $art["pic_url"]; @@ -410,19 +442,23 @@ if (!$sth->execute()) error("Cannot execute query: \"$sql\""); while ($row = $sth->fetchrow_array()) $ncats[$row[0]] = true; $sth->finish(); - } else $art["show"] = true; + } else { + $art["show"] = true; + for ($j = 0; $j < count($specs); $j++) + $nspecs[$specs[$j]["id"]] = ($specs[$j]["id"] == $spec) ? true : false; + } list($ed_title, $ed_lead, $ed_titlepic_pos, $titlepic_url, $titlepic_url2, $titlepic_name, $ed_titlepic_alt, $ed_cat, $ed_more, $ed_more_title, $width, $height, $author_url, $author_url2, $author_name, $ed_author_alt, $ed_author_info, $width2, $height2, - $ed_author_ime, $ed_prikazi) = array($art["title"], $art["lead"], - $art["pic_pos"], $art["pic_url"], $art["pic_url"], + $ed_author_ime, $ed_author_cv, $ed_prikazi) = array($art["title"], + $art["lead"], $art["pic_pos"], $art["pic_url"], $art["pic_url"], urldecode($art["pic_url"]), $art["pic_alt"], $art["category"], $art["more"], $art["more_title"], $art["pic_w"], $art["pic_h"], $art["au_pic"], $art["au_pic"], urldecode($art["au_pic"]), $art["au_alt"], $art["au_info"], $art["au_w"], $art["au_h"], - $art["au_name"], $art["show"]); + $art["au_name"], $art["au_cv"], $art["show"]); if ($art["text"]) reset($art["text"]); while ($art["text"] && list($id, $val) = each($art["text"])) { array_push($ed_pgfs, array($val["id"], $val["text"], $val["title"], @@ -554,6 +590,7 @@ $tp->assign("ed_more_new", strstr($ed_more, "://") ? true : false); $tp->assign("ed_more_title", MyEscape($ed_more_title)); $tp->assign("ed_prikazi", $ed_prikazi); + $tp->assign("ed_author_cv", $ed_author_cv); $tp->assign("ed_clr_main", ($clear_main || $clr_main || !$titlepic_url) ? true : false); $tp->assign("ed_clr_author", ($clear_author || $clr_author || !$author_url) ? true : false); $tp->assign("ed_text", $ed_text);