--- new.php 2001/02/20 12:53:02 1.1 +++ new.php 2001/02/23 16:36:56 1.7 @@ -25,38 +25,100 @@ $back_url="index.php"; } -$smarty->assign( array ( lpic=>$lpic, lext=>$lext, mpic=>$mpic, Section_title=>$title ) ); +$smarty->assign( array ( lpic=>$lpic, lext=>$lext, mpic=>$mpic, ) ); -$sql_where=""; +$sql_where="where visible is true"; -if (isset($id)) { - $sql_where.=" where id=$id "; +function find_html_file($dir,$file) { + $file="./$dir/$file"; + if (is_file("$file") && file_exists("$file")) { return "$file"; } + if (is_file("$file.htm") && file_exists("$file.htm")) { return "$file.htm"; } + if (is_file("$file.html") && file_exists("$file.html")) { return "$file.html"; } + return 0; } -if (! isset($more) || !file_exists("./news/$more")) { +if (file_exists(find_html_file("news",$more))) { -$sth = $dbh->prepare("select id,title,date,body,more,pdf from news $sql_where order by id desc"); -$sth->execute(); -while ($row=$sth->fetchrow_hash()) { - $data[]=$row; -} + $main=join('',file(find_html_file("news",$more))); + $back_url=$GLOBALS[HTTP_REFERER]; -$smarty->assign("data",$data); +} else { + if (isset($id)) { + $sql_where.=" and id=$id "; + } -$main=$smarty->fetch("new.tpl"); + if (isset($type)) { + if ($type == "n") { + $sql_where .= " and type='n'"; + $title.=" : News"; + } elseif ($type == "e") { + $sql_where .= " and type='e'"; + $title.=" : Events"; + } + } - if (isset($id) && $data[0][more]) { - $main=join('',file("./news/".$data[0][more])); + if (! isset($show) && !isset($start)) { + $sql_limit="limit 10"; + } elseif (isset($start)) { + $sql_limit="limit 10,$start"; + } + + $num_selected=0; + $sql="select + id,upper(title) as title,town_date,body,more,pdf, + (date-now()::date) as comming,type,title as title_lc + from news $sql_where order by priority desc,date desc $sql_limit"; +# print "$sql"; + $sth = $dbh->prepare("$sql"); + $sth->execute(); + while ($row=$sth->fetchrow_hash()) { + $data[]=$row; + $num_selected++; + } + + if ($num_selected == 10) { + $smarty->assign(array( + "multi_page_show" => 1, + "multi_page_next" => "$PHP_SELF?start=".($start+10), + )); + } + if ($start && $start >= 10) { + $smarty->assign(array( + "multi_page_show" => 1, + "multi_page_prev" => "$PHP_SELF?start=".($start-10), + )); + } + + if (isset($id) && $num_selected == 1) { + if ($data[0][type] == "n") { + $title.=" : News : ".$data[0][title_lc]; + } elseif ($data[0][type] == "e") { + $title.=" : Event : ".$data[0][title_lc]; + } elseif ($data[0][type] == "c") { + $title.=" : Community : ".$data[0][title_lc]; + } elseif ($data[0][type] == "r") { + $title.=" : Result : ".$data[0][title_lc]; + } + } + + $smarty->assign("data",$data); + + $main=$smarty->fetch("new.tpl"); + + if (isset($id) && find_html_file("news",$data[0][more])) { + $main=join('',file(find_html_file("news",$data[0][more]))); + } + + if ($main == "") { + $main = "This news item is no longer available"; } -} else { // display details - $main=join('',file("./news/$more")); - $back_url=$GLOBALS[HTTP_REFERER]; } include("common.inc"); -$smarty->assign( array(back_url=>$back_url, MAIN=>$main)); +$smarty->assign( array(back_url=>$back_url, MAIN=>$main, + Section_title=>$title ) ); $smarty->display("index.tpl"); ?>