<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
//
// Copyright (C) 2003 - 2007 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
//
// 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, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

if (!isset($menu_section)) {
	$menu_section = "structure";
}

//[participation_permission 31

// if I receive a module_id I check that the module_participant can send an announcement
// else I check from the core

// only people with ext_announce permission can email
if (isset($_REQUEST['module_id'])) {
	if (!isset($add_annoucement_resource) || (!$output_participation['participation_permission'] & $add_annoucement_resource)) {
		header("Location: index.php?amn=core_ann_list&" . strip_tags(SID));
		exit;
	}
}
elseif (!$_SESSION['user_core_permission'] & $core_config['resource']['user']['int_announce']) {
	header("Location: index.php?amn=core_ann_list&" . strip_tags(SID));
	exit;
}


// SETUP ANNOUNCE
require_once ("class/Announce.class.php");
$announce = new Announce($db, $_SESSION['user_id']);


if (isset($_POST['sub_insert'])) {
	if (empty($_POST['announce_body'])) {
		$GLOBALS['am_error_log'][] = array('body_empty');
	}

	if (empty($_POST['announce_title'])) {
		$GLOBALS['am_error_log'][] = array('title_empty');
	}
	
	if (empty($GLOBALS['am_error_log'])) {
	
		require_once('components/core/class/Kses/kses.php');
		
		$_POST['announce_body'] = kses_parse($_POST['announce_body'], 'min');
		$_POST['announce_title'] = stripslashes(htmlspecialchars($_POST['announce_title']));
		
		$announce->insertAnnouncement($_POST);
	
		header("location: index.php?amn=core_ann_view&" . strip_tags(SID));
		exit;
	}
	else {
		$output_announce = $_POST;
		$body->set('announce', $output_announce);
	}
}
elseif (isset($_POST['sub_preview'])) {
	$output_announce = $_POST;
	$output_announce['display_announce_body'] = $_POST['announce_body'];
	$body->set('announce', $output_announce);
}
elseif (!empty($_REQUEST['announce_id'])) {
	$output_announce = $announce->selAnnouncement($_REQUEST['announce_id']);
	
	$body->set('announce', $output_announce);
}


?>