Location: PHPKode > projects > WB News > admin/news.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2007                          #||
||#     Created: 16th August 2005                        #||
||#     Filename: news.php                               #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: news.php,v 1.4.2.4.2.1 2008/07/14 11:04:07 pmcilwaine Exp $
 */

require_once( "global.php" );
$auth->login_if( !$auth->has_perm( "canadmin" ) );

$_SESSION["return_page"] = make_url( array("ajax"=>FALSE) );

$page = new PageTemplateEngine( BuildPath("admin/main-page.ihtml") );
$tmpl->SetFilename( USE_AJAX ? BuildPath("admin/ajax/news.ixml") : BuildPath("admin/news.ihtml") );

$params = array(
	"entry" => "\t<li>%s</li>\n\t",
	"separator" => FALSE,
	"class_open" => "open",
	"links" => toolbarmenu()
	);
$toolbar = include( INCDIR . "/page-menu.php" );

$rows =& $tmpl->AddParam( "rows", array() );

if ( !USE_AJAX )
{
	$page->AddParam( "toolbar", $toolbar );
	$page->AddParam( "userinfo", $userinfo );
}

/** filter stuff **/
$params = array(
	"caption" => "Search News",
	"index" => "news",
	"fields" => array(
		"title" => array(
			"heading" => "Title",
			"type" => "text"
			),
		"date" => array(
			"heading" => "Period",
			"type" => "daterange"
			)
		)
	);
$filter = include( INCDIR . "/filter.php" );
$tmpl->AddParam( "filter", $filter );

$fields = array();
$fields[] = "n.\"id\"";
$fields[] = "n.\"title\"";
$fields[] = "u.\"postname\"";
$fields[] = "n.\"userid\"";
$fields[] = "n.\"ts\"";
$fields[] = "c.\"name\" as category";
$fields[] = "n.\"publish\"";

$tables = array();
$tables[] = TBL_NEWS . " n";

$joins = array();
$joins["leftjoin"][] = TBL_USERS . " u ON n.\"userid\" = u.\"userid\"";
$joins["leftjoin"][] = TBL_CATEGORY . " c ON c.\"id\" = n.\"catid\"";
$joins["leftjoin"][] = TBL_CATPERMS . " cp ON c.\"id\" = cp.\"catid\"";

$cond = array();
if ( isset($sess_filter["news"]) )
{
	$filter = $sess_filter["news"];
	if ( isset($filter["title"]) )
	{
		$title = addslashes(str_replace("*", "%", $filter["title"]));
		$like = strpos( $title, "%" ) === FALSE ? "=" : "LIKE";
		$cond[] = "title $like '$title'";
	}
	
	if ( isset($filter["date"][0]) )
	{
		list( $d, $m, $y ) = split( "/", $filter["date"][0] );
		$time = mktime( 0, 0, 0, $m, $d, $y );
		$cond[] = "timeposted >= '$time'";
	}
	
	if ( isset($filter["date"][1]) )
	{
		list( $d, $m, $y ) = split( "/", $filter["date"][1] );
		$time = mktime( 0, 0, 0, $m, $d, $y );
		$cond[] = "timeposted <= '$time'";
	}
}
$cond[] = "(cp.\"groupid\"='" . $userinfo["groupid"] . "' OR n.\"catid\" = -1)";
$cond = join( " AND ", $cond );

$offset = 0;
if ( isset($_GET["ajax"]) && $_GET["ajax"] == 1 )
{
	if ( isset($_GET["offset"]) )
	{
		$offset = intval( $_GET["offset"] );
	}
}
else
{
	$offset = isset($_REQUEST["offset"]) ? intval( $_REQUEST["offset"] ) : 0 ;
}

$ids = $DB->ListByJoin( $tables, $fields, $cond, $joins, "n.\"ts\" DESC", 10, $offset );
// plain_print_r( $DB->last_sql );
$count_ids = $DB->CountBy( $tables, $cond, $joins, "n" );

if ( is_array($ids) && count($ids) != 0 )
{
	foreach ( $ids as $id )
	{
		list( $y, $m, $d, $h, $i, $s ) = split("[-: ]", $id["ts"] );
		$rows[$id["id"]] = array(
			"title" => htmlspecialchars( $id["title"] ),
			"postname" => htmlspecialchars( $id["postname"] ),
			"timeposted" => tz_date( $config["dateFormat"], mktime( $h, $i, $s, $m, $d, $y ) ),
			"userid" => htmlspecialchars( $id["userid"] ),
			"category" => htmlspecialchars( $id["category"] ),
			"publish" => $id["publish"],
			"edit-link" => make_url_html( array("id"=>$id["id"]), MAIN_SERVER . "/admin/edit-news" )
			);
	}
}

$pagemenu =& $tmpl->AddParam( "pagemenu", array() );
$page->BindParam( "pagemenu", $tmpl );

$params = array(
	"entry" => "\t<li>%s</li>\n\t",
	"separator" => "\t<li>|</li>\n\t",
	"links" => buildmenu( $theme_info["pagemenu_build"] )
	);
$params = array_merge( $params, $theme_info["pagemenu"] );
$pagemenu = include( INCDIR . "/page-menu.php" );

$tmpl->Pagination( $count_ids, $offset, 10 );

if ( USE_AJAX )
{
	header( "Content-Type: text/xml" );
	echo $tmpl->GetHTML();
	return;
}

$page->ParseContent( $tmpl->GetHTML() );
$page->ShowPage();

?>
Return current item: WB News