<?php
# ---------------------------------------------------------------------
# rth is a requirement, test, and bugtracking system
# Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# User Add Action Page
#
# $RCSfile: user_add_action.php,v $  $Revision: 1.1.1.1 $
# ---------------------------------------------------------------------

include"./api/include_api.php";
include"./api/rndPass.class.php";
auth_authenticate_user();

$redirect_page		= 'user_add_page.php';
$edit_page			= 'user_add_page.php';
$proj_properties	= session_set_properties("project_manage", $_POST);

session_validate_form_set($_POST, $edit_page);

$username		= session_validate_form_get_field("username_required");
$first_name		= session_validate_form_get_field("first_name_required");
$last_name		= session_validate_form_get_field("last_name_required");
$email			= session_validate_form_get_field("email_required");
$phone			= session_validate_form_get_field("phone");
$projects		= session_validate_form_get_field("user_add_to_projects_required");

# check username unique
if( user_get_id($username) ) {
	error_report_show( $edit_page, USERNAME_NOT_UNIQUE );
}

# check email unique
if( user_get_info_by_email($email) ) {
	error_report_show( $edit_page, EMAIL_NOT_UNIQUE );
}

# create new password
$password		= new rndPass(6);
$new_password	= $password->PassGen();


user_add(	$username,
			$new_password,
			$first_name,
			$last_name,
			$email,
			$phone,
			isset($_POST['user_tempest_admin']) ? "Y": "N",
			isset($_POST['user_delete_rights']) ? "Y": "N",
			isset($_POST['user_email_testset']) ? "Y": "N",
			isset($_POST['user_email_discussions']) ? "Y": "N",
			isset($_POST['user_qa_owner']) ? "Y": "N",
			isset($_POST['user_ba_owner']) ? "Y": "N",
			$projects,
			$_POST['user_project_rights'],
			$_POST['user_default_project'] );


#################################################################################
$url		= RTH_URL."login.php";

$subject	 = "New Tempest User Account";
$message	 = "Welcome to Tempest. Here is the information you need to login:\n\n";
$message	.= "Username: $username\n";
$message	.= "Password: $new_password\n\n";
$message	.= "Click the link below to login:\n";
$message	.= "$url";

email_send( $recipients=array($email), $subject, $message, $headers="From: Tempest_Admin\r\n" );
#################################################################################

session_validate_form_reset();

html_print_operation_successful( "add_users_page", $redirect_page );

# ---------------------------------------------------------------------
# $Log: user_add_action.php,v $
# Revision 1.1.1.1  2005/11/30 23:00:59  gth2
# importing initial version - gth
#
# ---------------------------------------------------------------------

?>