<?php

/*************************************************************************/
/* DOCEBO CMS - Content Management System                                */
/* ============================================                          */
/*                                                                       */
/* Copyright (c) 2004 by Giovanni Derks                                  */
/* http://www.docebocms.com                                              */
/*                                                                       */
/* This program is free software. You can redistribute it and/or modify  */
/* it under the terms of the GNU General Public License as published by  */
/* the Free Software Foundation; either version 2 of the License.        */
/*************************************************************************/

// ---------------------------------------------------------------------------
if (!defined("IN_DOCEBO")) die ("You can't access this file directly...");
// ---------------------------------------------------------------------------


$css=getModuleCss($GLOBALS["pb"]);
$GLOBALS["page"]->add("<div class=\"".$css."\">\n", "content");
$GLOBALS["page"]->add(getModuleBlockTitle($GLOBALS["pb"]), "content");


//$backurl="javascript:history.go(-1);";
$backurl="index.php?special=changearea&amp;newArea=".$GLOBALS["area_id"];

$GLOBALS["page"]->add("<div style=\"text-align: right\">\n", "content");
$GLOBALS["page"]->add("<a class=\"back_link\" href=\"$backurl\">".def("_BACK")."</a></div>\n", "content");

$op=importVar("op");
if (empty($op))
	$op="shownews";
switch ($op) {
	case "shownews": {
		show_news($GLOBALS["pb"]);
	} break;

	case "news": {
		if ((isset($_GET["sel"])) && ($_GET["sel"]))
			show_news_list($GLOBALS["pb"], "", "sel");
		else
			show_news_list($GLOBALS["pb"]);
	} break;

	/* case "listcat": {
		show_news_list($GLOBALS["pb"]);
	} break; */

	case "listtopic": {
		if ((isset($_GET["sel"])) && ($_GET["sel"]))
			show_news_list($GLOBALS["pb"], "", "sel");
		else
			show_news_list($GLOBALS["pb"]);
	} break;

	case "download": {
		downloadNewsAttachment();
	} break;

}


$GLOBALS["page"]->add("<div style=\"text-align: right\">\n", "content");
$GLOBALS["page"]->add("<a class=\"back_link\" href=\"$backurl\">".def("_BACK")."</a></div>\n", "content");
$GLOBALS["page"]->add("</div>\n", "content");




function show_news($pb) {

	$out=& $GLOBALS['page'];
	$out->setWorkingZone('content');

	// ---------------------                                   ---------------------
	if (!check_news_perm($GLOBALS["pb"], (int)$_GET["id"])) die("You can't access!");
	// ---------------------                                   ---------------------

	$opt=loadBlockOption($pb);

	$qtxt="SELECT publish_date , title, long_desc FROM ".$GLOBALS["prefix_cms"]."_news WHERE idNews='".(int)$_GET["id"]."';";
	$q=mysql_query($qtxt);
	if (($q) && (mysql_num_rows($q) > 0)) {
		$row=mysql_fetch_array($q);
		$data=$GLOBALS["regset"]->databaseToRegional($row["publish_date"]); //conv_datetime($row["publish_date"], 0, _TIMEOFFSET);

		$out->add('<div class="news_read">');
		$out->add('<div class="news_title">'
			.''.$row["title"]);

		if ($opt["show_newsdate"])
			$out->add('<span class="news_date">'.$data.'</span>');

		$out->add('</div>');

		require_once($GLOBALS["where_cms"]."/admin/modules/news/functions.php");

		$news_topic=get_maintopic_info((int)$_GET["id"]);

		if (isset($news_topic["label"])) {
			show_topic_img($news_topic["label"], $news_topic["image"], $news_topic["img_align"]);
		}

		$out->add('<div class="news_box">');
		$out->add('<div class="news_text">'.fixAnchors($row["long_desc"]));

		$out->add('<div class="news_line"></div>');

		$attach_txt=getNewsAttach((int)$_GET["id"]);
		if (!empty($attach_txt)) {
			$out->add($attach_txt);
			$out->add('<div class="news_line"></div>');
		}

		$use_comments=((isset($opt["use_comments"]) && ($opt["use_comments"] == 1)) ? true : false);

		if ($use_comments) {
			load_news_comments((int)$_GET["id"], $pb);
		}

		$out->add('</div>'); // news_text
		$out->add('<div class="no_float"></div>');

		$out->add('</div>'); // news_box
		$out->add('</div>'); // news_read

	}

}



?>