Location: PHPKode > projects > GForge Advanced Server > gforge-as-6.0-src/wwwlib/register/ProjectAddAction.php
<?php
/**
 * Copyright (c) 2005-2011 GForge, LLC
 *
 * @version   $Id$
 * @author Tim Perdue hide@address.com
 * @date 2006-02-27
 *
 * This file is part of GForge.
 *
 * See LICENSE for details. This file is part of GForge AS and may not be
 * redistributed without written permission of GForge, LLC
 */

//
// This code creates a new Project and saves it to the 
// database
//
require_once('Validator.php');
require_once('exceptions/InvalidDataException.php');
require_once('core/Project.php');
require_once('html/TroveRenderer.php');
require_once('exceptions/NotLoggedInException.php');

$session = Session::getSession();
if (!$session->isLoggedIn()) {
	throw new NotLoggedInException();
}

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
	throw new PermissionDeniedException();
}

$Project = new Project();

// this was checked before, but let´s double check
if (Session::getSession()->isSiteAdmin() || (GFConf::get('system.projectRegRestricted')==false) ) {

	try {
		if (GFConf::get('system.projectRegClickLicense')) {
			if (isset($_REQUEST['iagree']) && Validator::sanitizeBool($_REQUEST['iagree'])) {
			} else {
				throw new InvalidDataException(array(Language::getSessText('License.DidntCheck')));
			}
		}
		$Project->setProjectName( Validator::sanitizeString(trim($_POST['project_name'])) );
		$Project->setUnixName( Validator::sanitizeString(trim($_POST['unix_name'])) );
		$Project->setHomepageUrl( Validator::sanitizeString($_POST['homepage_url']) );
		//$is_public = isset($_POST['is_public']) ? Validator::sanitizeBool($_POST['is_public']) : false;
		$is_public = true;
		$Project->setIsPublic( $is_public );
		$Project->setDescription( Validator::sanitizeString(trim($_POST['description'])) );
		$Project->setRegisterPurpose( Validator::sanitizeString($_POST['register_purpose']) );
		
		// This will be moved to Trove
		//$Project->setRegisterLicenseOther( Validator::sanitizeString($_POST['register_license_other']) );
		$Project->setRegisterLicenseOther('');
		
		if (!isset($_POST['template_project_id'])) {
			$template_project_id = 0;
		} else {
			$template_project_id = Validator::sanitizeInt($_POST['template_project_id']);
		}
		
		$Project->setTemplateProjectId($template_project_id);
		$Project->setStatus(Project::STATUS_PENDING);
		$Project->save();
		
		// now save the trove information
		$trove_renderer = new TroveRenderer();
		$trove_renderer->setSection(Project::SECTION);
		$trove_renderer->setRefId($Project->getPrimaryKey());
		$trove_renderer->savePOSTData();
		
		GFUrl::getUrl()->redirect(GFUrl::getUrl()->currentBaseURL('PostRegister'));
	} catch (InvalidDataException $ex) {
		$errors = $ex->getErrors();
		$feedback = '* '.implode('<br />* ', $errors);
		include_once('ProjectAdd.php');
	}
} else {
	GFUrl::redirect(GFUrl::getUrl()->currentBaseURL('ProjectAdd'),array('feedback'=>Language::getSessText('Common.PermissionDenied')));
}

?>
Return current item: GForge Advanced Server