Location: PHPKode > projects > NetworX - Social networking Service > group_news_profile.php
<?php
/*
NetworX - open-source social networks platform
Copyright (C) 2009 SocialABC, Inc. http://www.socialabc.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 3 of the License, 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 this program in a file called LICENSE; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ 

include('includes/application_top.php');

if (!Session::isCurrentSessionLoggedIn())
{
	cmn_unauthorized_action();
}

$grid = isset($_GET['group_id']) ? $_GET['group_id'] : ( isset($_POST['GroupID']) ? $_POST['GroupID'] : -1 );
$news_id = isset($_GET['news_id']) ? $_GET['news_id'] : ( isset($_POST['NewsID']) ? $_POST['NewsID'] : -1 );
$group = new Group($grid);
$news = new News($news_id);

if ($group->GroupID == -1)
{
	cmn_unauthorized_action();
}

if ($news->NewsEditingPrivacy != NEWS_PRIVACY_PUBLIC)
{
	if ( ($news->NewsEditingPrivacy == NEWS_PRIVACY_ADMINS) && (!$group->userIsAdmin($user->UserID)) )
	{
		if ( ($news->NewsEditingPrivacy == NEWS_PRIVACY_MEMBERS) && (!$group->hasMember($user->UserID)) )
		{
			cmn_unauthorized_action();
		}
	}
}

$news->UserID = $user->UserID;
$news->GroupID = $group->GroupID;
$data = $news->getDataArray();

if (isset($_POST['submitted']))
{
	$error = false;
	foreach ($data as $key => $field)
	{
		if (isset($_POST[$key]))
		{
			$data[$key] = $_POST[$key];
		}
		switch ($key)
		{
			case "NewsDate" :
				if (!chstr_is_date_ymdhsm($_POST[$key]))
				{
					$error = true;
					$template->touchBlock($key . "_err");
				}
				else
				{
					$data[$key] = date('Y-m-d H:i:s', strtotime($data[$key]));
				}
			break;
			case "NewsName" :
				if (empty($_POST[$key]))
                {
                    $error = true;
                    $template->touchBlock($key . "_err");                        
				}
			break;
			case "NewsText":
				{
				}
			break;
		}
	}

	if (!$error)
	{
        if ( ($_POST['Save'] == 'Save') || ($_POST['Save_x'] && $_POST['Save_y']) )
        {
	        if ($news->NewsID > 0)
	        {
        		$news->addVersion();
			}

			$news->populateFromArray($data);
			$template->setVariable("script", "group_news.php?group_id=" . $group->GroupID);
			$template->parse("successfull");
			$news->saveToDB();
		}
		elseif ($_POST['Save_Draft_x'] && $_POST['Save_Draft_y'])
		{
			$news_draft = new NewsDraft(-1);
			$news_draft->populateFromArray($data);
			$template->setVariable("script", "group_news_drafts.php?group_id=" . $group->GroupID);
			$template->parse("successfull");
			$news_draft->saveToDB();
		}
	}
}

$template->setVariable($data);
$template->setGlobalVariable('GroupID', $group->GroupID);
if ($group->userIsAdmin($user->UserID))
{
    $template->touchBlock('settings');
}
include('includes/application_bottom.php');
Return current item: NetworX - Social networking Service