Location: PHPKode > projects > ProjectPress > projectpress/pm-admin/add_member.php
<?php 
/**
 * ProjectPress add new member form
 *
 * @package ProjectPress
 * @since 2.0
 */

// Starts the session.
session_start();

define('access',true);

include(dirname(dirname(__FILE__)) . '/config.inc.php');
include(PM_DIR . 'pm-includes/global.inc.php');
require(PM_DIR . 'pm-includes/functions.php');
include(PM_DIR . 'pm-includes/header.php');

// User is logged in and is an admin.
is_admin();

// Enable for error checking and troubleshooting.
//display_errors();

if(isset($_POST['submit'])) {
	$username = pmdb::connect()->escape($_POST['username']);
	$md5_id = pmdb::connect()->escape(md5($_POST['username']));
	$first_name = pmdb::connect()->escape($_POST['first_name']);
	$last_name = pmdb::connect()->escape($_POST['last_name']);
	$email = pmdb::connect()->escape($_POST['email']);
	$level = pmdb::connect()->escape($_POST['level']);
	$password = pmdb::connect()->escape(md5($_POST['password']));
	$active = pmdb::connect()->escape($_POST['active']);

	//run the query which adds the data gathered from the form into the database
	$result = pmdb::connect()->query("INSERT INTO ". DB ."members (user_id,md5_id,username, first_name, last_name, email, password, active) 
	VALUES (LAST_INSERT_ID(),'$md5_id','$username','$first_name','$last_name','$email','$password','1')");
	
	pmdb::connect()->query("INSERT INTO " . DB . "user_roles (userID,roleID,addDate) VALUES (LAST_INSERT_ID(),'2',NOW())");
	
	if($result) {
		$amessage = '<div class="success">Your new member has been added and was sent an email with new account details.</div>';
	} else {
		$amessage = '<div class="error">Sorry, the new user could not be added. Please try again.</div>';
	}
	
	$sitetitle = get_pm_option('sitetitle');
	$siteurl = get_pm_option('siteurl');
	$email = $_POST['email'];
	$subject = "New " . $sitetitle . " Account";
	$headers  = "From: \"Member Account\" <auto-reply@$host>\r\n";
	$headers .= "X-Mailer: PHP/" . phpversion();
	$message = 
	"Hello \n
	A new account has been created for you at $sitetitle. Below are your login details.\n

	User ID: $username
	Email: $email \n 
	Password: $_POST[password] \n

	$siteurl/login.php

	Thank You

	$sitetitle Administrator
	$host_upper
	______________________________________________________
	THIS IS AN AUTOMATED RESPONSE. 
	***DO NOT RESPOND TO THIS EMAIL****
";

	pm_mail($email,$subject,$message,$headers);
}

	/**
	 * Creates a new template for the add member page.
	 */
	$addmember = new Template(PM_DIR . "pm-includes/tpl/add_member.tpl");
	$addmember->set("pmurl", get_pm_option('siteurl'));
	$addmember->set("phpself", $PHP_SELF);
	$addmember->set("message", $amessage);
	
	/**
	 * Outputs the page with add member form.
	 */
	echo $addmember->output();

include(PM_DIR . 'pm-includes/footer.php');
Return current item: ProjectPress