/* ********************************************* * Fisier: noutati.php * * Descriere: pagina principala noutati * * Autor: Mihai Batranu * ************************************************/ include("../class/template.php"); include("../class/db_mysql.php"); include("../inc/db_politica.php"); include("../inc/functions.php"); include("../inc/const.php"); $db=new DB_POLITICA; // *** categoriile *** / $links_categorii=""; $query="select * from categorii order by id"; $db->query($query); while($db->next_record()) { $tmpl=new Template('../html/noutati/cat_inact.html'); $tmpl->add('cat_name', $db->f('nume')); $tmpl->add('cat_id', $db->f('id')); $links_categorii.=$tmpl->execute(); } $tmpl=new Template('../html/noutati/links_categorii.html'); $tmpl->add('links_categorii', $links_categorii); $categorii=$tmpl->execute(); // *** construiesc cautarea dupa data *** // $months=""; //lunile for ($i=1;$i<13;$i++) { $months.="".$months_list[$i-1]; } $year=""; // anul for ($i=1999;$i<2010;$i++) { $year.="".$i; } // *** noutatile *** // if (!isset($key) || (isset($key) && trim($key)=="")) { $query="select count(*) as total from noutati"; if ($m!=0) { $query.=" where month(data)=".$m; if ($y!=0) { $query.=" and year(data)=".$y; } } else { if ($y!=0) { $query.=" where year(data)=".$y; } } $db->query($query); while($db->next_record()) { $total_pages=$db->f('total'); } } else { $ar_ids=array(); $query="select id from noutati where (titlu like '%".$key."%' or rezumat like '%".$key."%')"; if ($m!=0) { $query.=" and month(data)=".$m; if ($y!=0) { $query.=" and year(data)=".$y; } } else { if ($y!=0) { $query.=" and year(data)=".$y; } } $db->query($query); while($db->next_record()) { array_push($ar_ids,$db->f('id')); } $query="select id from noutati left join module_noutati on id_nou=id where (subtitlu like '%".$key."%' or text like '%".$key."%')"; if ($m!=0) { $query.=" and month(data)=".$m; if ($y!=0) { $query.=" and year(data)=".$y; } } else { if ($y!=0) { $query.=" and year(data)=".$y; } } $db->query($query); while($db->next_record()) { array_push($ar_ids,$db->f('id')); } $ar_ids_final=array_unique($ar_ids); $total_pages=count($ar_ids_final); } if (trim($key)!="") { if (trim($key)!="") { $search.="".$key.""; } if ($total_pages!=1) { $e="e"; } $tmpl=new Template('../html/noutati/rezultate.html'); $tmpl->add('search', $search); $tmpl->add('nr_rezultate', $total_pages); $tmpl->add('e', $e); $rezultate=$tmpl->execute(); } if ($total_pages!=0) { if (($total_pages % $max_art_links)!=0) { $num_pages=1+intval($total_pages/$max_art_links); // numarul de pagini } else { $num_pages=intval($total_pages/$max_art_links); } if (!isset($page)) { $page=1; } // pagina curenta else { if ($page>$num_pages) { $page=$num_pages; } } if (!isset($key) || (isset($key) && trim($key)=="")) { $query="select * from noutati"; if ($m!=0) { $query.=" where month(data)=".$m; if ($y!=0) { $query.=" and year(data)=".$y; } } else { if ($y!=0) { $query.=" where year(data)=".$y; } } $query.=" order by `data` desc limit ".(($page-1)*$max_art_links).",".$max_art_links; } else { $ids=""; foreach($ar_ids_final as $i) { $ids.=$i.","; } $ids=substr($ids,0,strlen($ids)-1); $query="select * from noutati where id in (".$ids.") order by `data` desc limit ".(($page-1)*$max_art_links).",".$max_art_links; } // incarc si subtitlurile de la module $db->query("select id_nou,subtitlu from module_noutati order by id_nou,id_modul"); $subtitluri = array(); while($db->next_record()) { $subtitluri[$db->f('id_nou')][] = $db->f('subtitlu'); } //query("select * from module_noutati"); $db->query($query); $noutati=""; while($db->next_record()) { $rezumat=$db->f('rezumat'); if (isset($key) && trim($key)!="") { $rezumat=str_replace($key,"".$key."",$rezumat); } $search_=""; $key_val=""; if (isset($key) && trim($key)!="") { $search_="search_"; $key_val="&key=".urlencode($key); } $tmpl=new Template('../html/noutati/link_noutate.html'); $tmpl->add('titlu', $db->f('titlu')); $tmpl->add('id_nou', $db->f('id')); $tmpl->add('data', show_date($db->f('data'))); $tmpl->add('rezumat', $rezumat); $tmpl->add('search_', $search_); $tmpl->add('key_val', $key_val); if(isset($subtitluri[$db->f('id')])) $sn = $subtitluri[$db->f('id')]; else $sn = array(); $tmpl->add('subtitluri', join('', $sn)); $noutati.=$tmpl->execute(); } // *** navigarea *** // $navbar=""; if ($page!=1) { // inapoi $tmpl=new Template('../html/noutati/link.html'); $tmpl->add('link', "javascript: document.c.page.value--;document.c.submit()"); $tmpl->add('title', "inapoi"); $navbar.=$tmpl->execute()." "; } if ($page % $max_page_links==0) { $set=$page/$max_page_links; } else { $set=intval($page/$max_page_links)+1; } $first_in_set=($set*$max_page_links)-$max_page_links+1; $last_in_set=($set*$max_page_links); for ($i=$first_in_set;$i<($last_in_set+1);$i++) { if ($i==$page) { $navbar.=" ".$page." "; } else { $navbar.=" ".$i." "; } if ($i==$num_pages) { break; } } if ($page!=$num_pages) { // inainte $tmpl=new Template('../html/noutati/link.html'); $tmpl->add('link', "javascript: document.c.page.value++;document.c.submit()"); $tmpl->add('title', "inainte"); $navbar.=$tmpl->execute()." "; } } // *** construiesc header-ul, lista de optiuni si footer-ul pornind de la template *** // $header=implode("", file('../html/noutati/header.html')); $footer=implode("", file('../html/noutati/footer.html')); $links=implode("", file('../html/noutati/links.html')); session_start(); $header=str_replace('{_usersurname_}', $_SESSION['UserSurname'], $header); $header=str_replace('{_username_}', $_SESSION['UserName'], $header); if(isset($_SESSION['UserId'])){ $header=str_replace('{_userid_}', $_SESSION['UserId'], $header); } require_once('../config.php'); $header=str_replace(LOGIN_TAG,isset($_SESSION['UserId'])?LOGOUT_URL:LOGIN_URL, $header); $header=str_replace(REGISTER_TAG,isset($_SESSION['UserId'])?'':REGISTER_URL, $header); $header=str_replace(CURDATE_TAG,date(PHPDATEFORMAT), $header); $footer=str_replace(BANNER_TAG, $tmpl->banners(), $footer); // *** output-ul *** // $tmpl = new Template('../html/noutati/noutati.html'); $tmpl->add('header', $header); $tmpl->add('footer', $footer); $tmpl->add('links', $links); $tmpl->add('categorii', $categorii); $tmpl->add('months', $months); $tmpl->add('year', $year); $tmpl->add('noutati', $noutati); $tmpl->add('navbar', $navbar); $tmpl->add('page', $page); $tmpl->add('key', $key); $tmpl->add('rezultate', $rezultate); echo $tmpl->execute(); ?>
"; if ($page!=1) { // inapoi $tmpl=new Template('../html/noutati/link.html'); $tmpl->add('link', "javascript: document.c.page.value--;document.c.submit()"); $tmpl->add('title', "inapoi"); $navbar.=$tmpl->execute()." "; } if ($page % $max_page_links==0) { $set=$page/$max_page_links; } else { $set=intval($page/$max_page_links)+1; } $first_in_set=($set*$max_page_links)-$max_page_links+1; $last_in_set=($set*$max_page_links); for ($i=$first_in_set;$i<($last_in_set+1);$i++) { if ($i==$page) { $navbar.=" ".$page." "; } else { $navbar.=" ".$i." "; } if ($i==$num_pages) { break; } } if ($page!=$num_pages) { // inainte $tmpl=new Template('../html/noutati/link.html'); $tmpl->add('link', "javascript: document.c.page.value++;document.c.submit()"); $tmpl->add('title', "inainte"); $navbar.=$tmpl->execute()." "; } } // *** construiesc header-ul, lista de optiuni si footer-ul pornind de la template *** // $header=implode("", file('../html/noutati/header.html')); $footer=implode("", file('../html/noutati/footer.html')); $links=implode("", file('../html/noutati/links.html')); session_start(); $header=str_replace('{_usersurname_}', $_SESSION['UserSurname'], $header); $header=str_replace('{_username_}', $_SESSION['UserName'], $header); if(isset($_SESSION['UserId'])){ $header=str_replace('{_userid_}', $_SESSION['UserId'], $header); } require_once('../config.php'); $header=str_replace(LOGIN_TAG,isset($_SESSION['UserId'])?LOGOUT_URL:LOGIN_URL, $header); $header=str_replace(REGISTER_TAG,isset($_SESSION['UserId'])?'':REGISTER_URL, $header); $header=str_replace(CURDATE_TAG,date(PHPDATEFORMAT), $header); $footer=str_replace(BANNER_TAG, $tmpl->banners(), $footer); // *** output-ul *** // $tmpl = new Template('../html/noutati/noutati.html'); $tmpl->add('header', $header); $tmpl->add('footer', $footer); $tmpl->add('links', $links); $tmpl->add('categorii', $categorii); $tmpl->add('months', $months); $tmpl->add('year', $year); $tmpl->add('noutati', $noutati); $tmpl->add('navbar', $navbar); $tmpl->add('page', $page); $tmpl->add('key', $key); $tmpl->add('rezultate', $rezultate); echo $tmpl->execute(); ?>