Location: PHPKode > projects > WebDebEx > webdebex/html/user_add.php
<?php
require_once("functions.php");
DBOpen();
LoginReq();
MyHeader();




if(!isset($_POST[create])) {
		$_POST[user_php_safemode] = 1;
		$_POST[user_php_openbasedir] = 1;
	}



$_POST[user_name] = CheckString($_POST[user_name],32);
$_POST[user_full_name] = CheckString($_POST[user_full_name],32);
//$_POST[user_password] = md5(strip_tags(trim($_POST[user_password])));
//$_POST[user_password2] = md5(strip_tags(trim($_POST[user_password2])));
$_POST[user_password]=trim($_POST[user_password]);
$_POST[user_password2]=trim($_POST[user_password2]);

$_POST[user_mail_enabled] = CheckInt($_POST[user_mail_enabled]);
$_POST[user_mail_quota] = CheckDouble($_POST[user_mail_quota]);
$_POST[user_mail_quota_size] = CheckInt($_POST[user_mail_quota_size]);

$_POST[user_ftp_enabled] = CheckInt($_POST[user_ftp_enabled]);
$_POST[user_ftp_quota] = CheckDouble($_POST[user_ftp_quota]);
$_POST[user_ftp_quota_size] = CheckInt($_POST[user_ftp_quota_size]);
$_POST[user_ftp_files] = CheckInt($_POST[user_ftp_files]);

$_POST[user_www_enabled] = CheckInt($_POST[user_www_enabled]);
$_POST[user_php_safemode] = CheckInt($_POST[user_php_safemode]);
$_POST[user_php_openbasedir] = CheckInt($_POST[user_php_openbasedir]);



if(isset($_POST[create])) {
	if($_POST[user_mail_quota_size]==1) $_POST[user_mail_quota2]=$_POST[user_mail_quota]*1024*1024;
	if($_POST[user_mail_quota_size]==2) $_POST[user_mail_quota2]=$_POST[user_mail_quota]*1024*1024*1024;
	if($_POST[user_ftp_quota_size]==1) $_POST[user_ftp_quota2]=$_POST[user_ftp_quota]*1024*1024;
	if($_POST[user_ftp_quota_size]==2) $_POST[user_ftp_quota2]=$_POST[user_ftp_quota]*1024*1024*1024;

	if(!$_POST[user_mail_enabled]) $_POST[user_mail_quota2]=0;
	if(!$_POST[user_ftp_enabled]) { $_POST[user_ftp_quota2]=0; $_POST[user_ftp_files]=0; }


	$createuser = true;
	if($_POST[user_password]!=$_POST[user_password2]) {
		echo "<BR><B><FONT COLOR=RED>Password confirmation failed.</FONT></B><BR>";
		$createuser = false;
	}

	if(strlen($_POST[user_name])<=0) {
		echo "<BR><B><FONT COLOR=RED>Empty Email Adress.</FONT></B><BR>";
		$createuser = false;
	}

	if(!strpos($_POST[user_name],"@")===false) {
		echo "<B><FONT COLOR=RED>Email Adress doesn't allaow '@' in the name!</FONT></B><BR>";
		$createuser = false;
	}

	$res = DBQuery("SELECT dom_name, dom_max_accounts, dom_max_space, dom_max_files, dom_php_safemode, dom_php_openbasedir FROM domains WHERE dom_id = $_REQUEST[db_session_dom]");
	$domain = mysql_fetch_assoc($res);

	$res = DBQuery("SELECT user_name FROM users WHERE user_name = '".$_POST[user_name]."@".$domain[dom_name]."'");
	$row = mysql_fetch_assoc($res);
	if($row[user_name]!=NULL) {
		echo "<B><FONT COLOR=RED>Email Adress already in use.</FONT></B><BR>";
		$createuser = false;
	}

	if($domain[dom_php_safemode]=='on') $_POST[user_php_safemode] = 1;
	if($domain[dom_php_openbasedir]=='on') $_POST[user_php_openbasedir] = 1;
	

	$res = DBQuery("SELECT count(*) as dom_count, sum(user_mail_quota) + sum(user_ftp_quota) as dom_max_space, sum(user_ftp_files) as dom_max_files FROM users WHERE user_domain = $_REQUEST[db_session_dom]");
	$row = mysql_fetch_assoc($res);
	$spaceleft = $domain[dom_max_space] - $row[dom_max_space];
	$filesleft = $domain[dom_max_files] - $row[dom_max_files];

	if($_POST[user_ftp_files]>$filesleft) {
		echo "<BR><B><FONT COLOR=RED>Too high files count enter: $_POST[user_ftp_files] of $filesleft</FONT></B><BR>";
		$createuser = false;
	}

	if($_POST[user_mail_quota2]+$_POST[user_ftp_quota2]>$spaceleft) {
		echo "<BR><B><FONT COLOR=RED>Out of available space: ".fsizeHR($_POST[user_mail_quota2]+$_POST[user_ftp_quota2])." of ".fsizeHR($spaceleft)."</FONT></B><BR>";
		$createuser = false;
	}


	if($createuser) {
		user_create($_POST[user_name],$_REQUEST[db_session_dom],$_POST[user_password],$_POST[user_full_name],$_POST[user_mail_enabled],$_POST[user_mail_quota2],$_POST[user_ftp_enabled],$_POST[user_ftp_quota2],$_POST[user_ftp_files],$_POST[user_www_enabled],$_POST[user_php_safemode],$_POST[user_php_openbasedir]);
		
		echo "<BR><B><FONT COLOR=GREEN>Account '$_POST[user_name]' created.</FONT></B><BR>";
		//unset($_POST[user_ftp_files]);
	}
	
}




$res = DBQuery("SELECT dom_name, dom_max_accounts, dom_max_space, dom_max_files, dom_php_safemode, dom_php_openbasedir FROM domains WHERE dom_id = $_REQUEST[db_session_dom]");
$domain = mysql_fetch_assoc($res);

$res = DBQuery("SELECT count(*) as dom_count, sum(user_mail_quota) + sum(user_ftp_quota) as dom_max_space, sum(user_ftp_files) as dom_max_files FROM users WHERE user_domain = $_REQUEST[db_session_dom]");
$row = mysql_fetch_assoc($res);
$spaceleft = $domain[dom_max_space] - $row[dom_max_space];
$filesleft = $domain[dom_max_files] - $row[dom_max_files];



$addacc = true;
if($row[dom_count]>=$domain[dom_max_accounts]) {
		echo "<BR><B><FONT COLOR=RED>Maximum number of accounts reached: $domain[dom_max_accounts]</FONT></B><BR>";
		$addacc = false;
	}

if($spaceleft<=0) {
		echo "<BR><B><FONT COLOR=RED>Maximum space of domain reached: ".fsizeHR($domain[dom_max_space])."</FONT></B><BR>";
		$addacc = false;
	}

if($filesleft<=0) {
		echo "<BR><B><FONT COLOR=RED>Maximum Filecount of domain reached: ".fcountHR($domain[dom_max_files])."</FONT></B><BR>";
		$addacc = false;
	}

if($addacc) {
	
	
		if(!isset($_POST[create])) {
				$_POST[user_mail_quota] = $spaceleft/2;
		
				$_POST[user_mail_quota]/=(1024*1024);
				$_POST[user_mail_quota_size] = 1;
				if(fmod($_POST[user_mail_quota],1024)==0) {
						$_POST[user_mail_quota]/=1024;
						$_POST[user_mail_quota_size] = 2;
					}
				
				$_POST[user_ftp_quota] = $_POST[user_mail_quota];
				$_POST[user_ftp_quota_size] = $_POST[user_mail_quota_size];
				
				$_POST[user_ftp_files] = $filesleft;
			}
	
	
	
	
		echo "<BR>";
		echo "<FORM METHOD=POST STYLE='display:inline;'>";
		echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3>";
			echo "<TR>";
				echo "<TD>Email</TD>";
				echo "<TD><INPUT TYPE=text NAME=user_name VALUE='$_POST[user_name]'></TD>";
				echo "<TD COLSPAN=2>@$domain[dom_name]</TD>";
				echo "<TD><INPUT TYPE=HIDDEN NAME=create VALUE=true><INPUT TYPE=image NAME=createX SRC='icons/add.gif' STYLE='border:0px;background-color:transparent;' ALT='Create new User'></TD>";
			echo "</TR>";

			echo "<TR><TD>&nbsp;</TD></TR>";

			echo "<TR>";
				echo "<TD>Full Name</TD>";
				echo "<TD><INPUT TYPE=text NAME=user_full_name VALUE='$_POST[user_full_name]'></TD>";
				echo "<TD>Password</TD>";
				echo "<TD><INPUT TYPE=password NAME=user_password></TD>";
			echo "</TR>";
			echo "<TR>";
				echo "<TD COLSPAN=2>&nbsp;</TD>";
				echo "<TD>Confirm P.</TD>";
				echo "<TD><INPUT TYPE=password NAME=user_password2></TD>";
			echo "</TR>";

			echo "<TR><TD>&nbsp;</TD></TR>";
		
			echo "<TR>";
				echo "<TD>Mail Enabled</TD>";
				if($_POST[user_mail_enabled]) echo "<TD><INPUT TYPE=checkbox NAME=user_mail_enabled VALUE=1 CHECKED></TD>";
				else echo "<TD><INPUT TYPE=checkbox NAME=user_mail_enabled VALUE=1></TD>";
				echo "<TD>Mail Quota</TD>";
				echo "<TD><INPUT TYPE=text NAME=user_mail_quota STYLE='width:80px;' VALUE='$_POST[user_mail_quota]'> <SELECT NAME=user_mail_quota_size>";
					if($_POST[user_mail_quota_size]!=2) echo "<OPTION VALUE=1 SELCETED>MB</OPTION><OPTION VALUE=2>GB</OPTION></SELECT>";
					else echo "<OPTION VALUE=1>MB</OPTION><OPTION VALUE=2 SELECTED>GB</OPTION></SELECT>";
				echo "</TD>";
			echo "</TR>";

		
			echo "<TR><TD>&nbsp;</TD></TR>";
		
			echo "<TR>";
				echo "<TD>FTP Access</TD>";
				if($_POST[user_ftp_enabled]) echo "<TD><INPUT TYPE=checkbox NAME=user_ftp_enabled VALUE=1 CHECKED></TD>";
				else echo "<TD><INPUT TYPE=checkbox NAME=user_ftp_enabled VALUE=1></TD>";
				echo "<TD>FTP Quota</TD>";
				echo "<TD><INPUT TYPE=text NAME=user_ftp_quota VALUE='$_POST[user_ftp_quota]' STYLE='width:80px;'> <SELECT NAME=user_ftp_quota_size>";
					if($_POST[user_ftp_quota_size]!=2) echo "<OPTION VALUE=1 SELECTED>MB</OPTION><OPTION VALUE=2>GB</OPTION>";
					else echo "<OPTION VALUE=1>MB</OPTION><OPTION VALUE=2 SELECTED>GB</OPTION>";
				echo "</SELECT></TD>";
			echo "</TR>";
			echo "<TR>";
				echo "<TD COLSPAN=2>&nbsp;</TD>";
				echo "<TD>FTP Files</TD>";
				echo "<TD><INPUT TYPE=text NAME=user_ftp_files VALUE='$_POST[user_ftp_files]'></TD>";
			echo "</TR>";
		
			echo "<TR><TD>&nbsp;</TD></TR>";
		
			echo "<TR>";
				echo "<TD>WWW Enabled</TD>";
				if($_POST[user_www_enabled]) echo "<TD><INPUT TYPE=checkbox NAME=user_www_enabled VALUE=1 CHECKED></TD>";
				else echo "<TD><INPUT TYPE=checkbox NAME=user_www_enabled VALUE=1></TD>";
				echo "<TD>PHP Safemode</TD>";
				if($domain[dom_php_safemode]=='off') {
						if($_POST[user_php_safemode]) echo "<TD><INPUT TYPE=checkbox NAME=user_php_safemode VALUE=1 CHECKED></TD>";
						else echo "<TD><INPUT TYPE=checkbox NAME=user_php_safemode VALUE=1></TD>";
					} else echo "<TD>On</TD>";
			echo "</TR>";
			echo "<TR>";
				echo "<TD COLSPAN=2>&nbsp;</TD>";
				echo "<TD>PHP OpenBaseDir</TD>";
				if($domain[dom_php_openbasedir]=='off') {

						if($_POST[user_php_openbasedir]) echo "<TD><INPUT TYPE=checkbox NAME=user_php_openbasedir VALUE=1 CHECKED></TD>";
						else echo "<TD><INPUT TYPE=checkbox NAME=user_php_openbasedir VALUE=1></TD>";

					} else echo "<TD>On</TD>";
			echo "</TR>";
		echo "</TABLE>";
		echo "</FORM>";
	}





DBClose();
MyFooter();
MyEnd();
?>
Return current item: WebDebEx