Location: PHPKode > projects > Hosting App > hosting/modules/common.php
<?php
////////////////////////////////////////////////////////////////////////////////
//   Copyright (c), 2002, Sadri Sahraoui <hide@address.com>               //
//   Hosting App - A web based hosting management system                      //
//   http://sf.net/projetcs/hostingapp/                                       //
//   				                                                                  //
//   This program is free software. You can redistribute it and/or modify     //
//   it under the terms of the GNU General Public License                     //
//                                                                            //
//   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 GNU General Public License            //
//   along with this program.                                                 //
////////////////////////////////////////////////////////////////////////////////

/**
 *
 * @version v1.1, 20/09/2002
 */

/*
* Does a complete checking of user posted data and insert or update 
* these data into the db. 
* 
* @param string $what : what we want to do update data or add a new data 
*/


function validate_product_data ($pack_name, $space, $mail, $hits, $bandwidth, $what, $id="")
{
 		global $tpl;
		
		switch($what){

			case "add": 

		if (!$pack_name || !$space || !$mail) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');
		  $tpl -> MxText('body.main_bloc.feedback', 'All fields are required');
			return false;
			
		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $pack_name)) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');
			$tpl -> MxText('body.main_bloc.feedback', "Invalid pack name");

		}elseif (!is_numeric($space)) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');			
			$tpl -> MxText('body.main_bloc.feedback', "Invalid disk space");
			return false;

		}elseif (!is_numeric($mail)) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');		   
			$tpl -> MxText('body.main_bloc.feedback', "Invalid number of mail");
			return false;

		}elseif (!is_numeric($hits)) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');		  
			$tpl -> MxText('body.main_bloc.feedback', "Invalide number of hits/day");
			return false;
			
		}elseif (!is_numeric($bandwidth)) {
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');				
			$tpl -> MxText('body.main_bloc.feedback', "Invalide bandwidth size");
			return false;

		}else{
			$add = add_pack ($pack_name, $space, $mail, $hits, $bandwidth);
			if ($add == 1) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');
				$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");
				return true;    

			}else{
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_product.mxt');
				$tpl -> MxText('body.main_bloc.feedback', $add);
				return false;
			}
		}
		
				break; // end case add 
			case "update": 
				
		if (!$pack_name || !$space || !$mail) {
		
		  $tpl -> MxText('body.main_bloc.feedback', 'All fields are required');
			return false;
			
		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $pack_name)) {
			$tpl -> MxText('body.main_bloc.feedback', "Invalid pack name");

		}elseif (!is_numeric($space)) {
			$tpl -> MxText('body.main_bloc.feedback', "Invalid disk space");
			return false;

		}elseif (!is_numeric($mail)) {
			$tpl -> MxText('body.main_bloc.feedback', "Invalid number of mail");
			return false;

		}elseif (!is_numeric($hits)) {
			$tpl -> MxText('body.main_bloc.feedback', "Invalide number of hits/day");
			return false;
			
		}elseif (!is_numeric($bandwidth)) {
			$tpl -> MxText('body.main_bloc.feedback', "Invalide bandwidth size");
			return false;

		}else{
			$update = update_pack ($id, $pack_name, $space, $mail, $hits, $bandwidth);
			if ($update == 1) {
				$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");
				return true;    

			}else{
				$tpl -> MxText('body.main_bloc.feedback', $add);
				return false;
			}
		}
				
				break;
		} // switch
}


/*
* Does a complete checking of user posted data and insert or update 
* these data into the db. 
* 
* @param string $what : what we want to do update data or add a new data 
*/

function validate_user_data ($first, $last, $email, $login, $password, $company = "", $address = "", $city = "", $zip = "", $phone = "", $what, $id="")
{
 		global $tpl;

		switch($what){

			case "add": 
		if (!$first || !$last || !$email || !$login || !$password) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "All fields are required");
				return false;

		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $first)) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid first name");
				return false;

		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $last)) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid last name");
				return false;
				
		}elseif (!ereg("^[a-z0-9]{3,12}$", $login)) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid Login : Login must contain at least 3 caracter and max 12 caracter");
				return false;

		}elseif (!ereg("^[A-Za-z0-9]{6,12}$", $password)) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid password : Password must contain a least 6 caracter and max 12 caracter");
				return false;
				
		}elseif (!validate_email($email)) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
		    $tpl -> MxText('body.main_bloc.feedback', "Invalide email address");
				return false;

		}else{
			$add = add_new_user($last, $first, $company, $address , $city, $zip, $phone, $email, $login, $password);
			 if ($add == 1) {
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
				$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");
				return true;    

			}else{
				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_user.mxt');
				$tpl -> MxText('body.main_bloc.feedback', $add);
				return false;

			}
		}
				break;

			case "update":  // update case 
				if (!$first || !$last || !$email || !$login || !$password) {
				$tpl -> MxText('body.main_bloc.feedback', "All fields are required");
				return false;

		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $first)) {
				$tpl -> MxText('body.main_bloc.feedback', "Invalid first name");
				return false;

		}elseif (!ereg("^([a-zA-Z]+)([ -][a-zA-Z]+)*$", $last)) {
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid last name");
				return false;

		}elseif (!ereg("^[a-z0-9]{3,12}$", $login)) {
				$tpl -> MxText('body.main_bloc.feedback', "Invalid Login : Login must contain at least 3 caracter and max 12 caracter");
				return false;

		}elseif (!ereg("^[A-Za-z0-9]{6,12}$", $password)) {		
		    $tpl -> MxText('body.main_bloc.feedback', "Invalid password : Password must contain a least 6 caracter and max 12 caracter");
				return false;
				
		}elseif (!validate_email($email)) {
		    $tpl -> MxText('body.main_bloc.feedback', "Invalide email address");
				return false;
				
		}else{
			$mod = modify_user_data ($id, $last, $first, $company, $address, $city, $zip, $phone, $email, $login, $password);
			 if ($mod == 1) {
				$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");
				return true;    
				
			}else{				
				$tpl -> MxText('body.main_bloc.feedback', $mod);
				return false;
				
			}
		}
		break;
		} // switch
  }

function validate_email ($address) 
{
	return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address));
}

/*
* Does a complete checking of user posted data and insert or update 
* these data into the db. 
* 
* @param string $what : what we want to do update data or add a new data 
* 
* TODO : introduce a whois function to check if the domain s available or not
*/	
function validate_domain ($domain, $user, $pack, $create_mail = "", $what, $id = "")
{
		global $tpl;

		switch($what){
			case "add": 
				
		if (!$domain){
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "You Must Insert a Domain name.");
			return false;
		}

		$explode = explode(".", $domain);
		$domain = $explode[0];
		$extension = $explode[1];
		if (!$extension) {
		   $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "A Domain Must Be In This Format \"name.extensions\".");
			return false;
		}
		if( strpos($domain, "-", 0) < 1 AND strpos($domain, "-", 0) > -1 )
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "Your Domain Cannot Start With A Dash.");
			return false;
		}

		if( strlen($domain) > 2 )
		{
			if( strrpos($domain, "-") == strlen($domain)-1 )
			{
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "Your Domain Cannot End With A Dash.");
			return false;
			}	
		}

		if( eregi("[^a-z0-9\-]", $domain) == true )
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "Use only letters, numbers, or hyphen (\"-\").");
			return false;
		}

		if( $extension == "com" || $extension == "net" || $extension == "org" AND strlen($domain) > 63)
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');
			get_domain_admin(); // print domain admin 
			get_packs(); //print packs to sell 
			$tpl -> MxText('body.main_bloc.feedback', "Please Enter Less Then 63 Characters, Not Including [.".$extension."].");
			return false;
		}
			$dom = $domain.".".$extension;
			$add = add_domain($user, $dom, $pack); // adding this domain 
				//echo $dom;
				if (is_numeric($add)) {
					if ($create_mail == 1) { // determine if the user want to create email now 
					
						$properties = pack_properties($pack);

						$data = mysql_fetch_array($properties);

						$num_mail = $data[2];
						
						$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/bloc_mail.mxt');
						
							// building dynamicly the form field based on the number of mail for this product						
							for ($i=0; $i < $num_mail; $i++){ 
								$tpl -> MxFormField('body.main_bloc.mail.email', 'text', 'email[]', '@'.$dom);
								$tpl -> MxFormField('body.main_bloc.mail.password', 'text', 'password[]', '');
								$tpl -> MxBloc('body.main_bloc.mail', 'loop');
							}
						$tpl -> MxHidden('body.main_bloc.id', "id=".$add);
						$tpl -> MxHidden('body.main_bloc.what', "what=email");
						$tpl -> MxHidden('body.main_bloc.form', "form_mail=1");
					}else{
					  $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');

						get_domain_admin(); // print domain admin 
		
						get_packs(); //print packs to sell 

						$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");

						return $num_mail;     
					}
				}else{

				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/add_domain.mxt');

				get_domain_admin(); // print domain admin 

				get_packs(); //print packs to sell 

				$tpl -> MxText('body.main_bloc.feedback', $add);

				return false;    
				}
				
				break; // end add case 
			
			case "update": 
				
		if (!$domain){
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');
			get_domain_admin($user); // print domain admin 
			get_packs($pack); //print packs to sell 
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
			$tpl -> MxText('body.main_bloc.feedback', "You Must Insert a Domain name.");
			return false;
		}

		$explode = explode(".", $domain);
		$domain = $explode[0];
		$extension = $explode[1];

		if( strpos($domain, "-", 0) < 1 AND strpos($domain, "-", 0) > -1 )
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');
			get_domain_admin($user); // print domain admin 
			get_packs($pack); //print packs to sell 
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
			$tpl -> MxText('body.main_bloc.feedback', "Your Domain Cannot Start With A Dash.");
			return false;
		}

		if( strlen($domain) > 2 )
		{
			if( strrpos($domain, "-") == strlen($domain)-1 )
			{
			$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');
			get_domain_admin($user); // print domain admin 
			get_packs($pack); //print packs to sell 
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
			$tpl -> MxText('body.main_bloc.feedback', "Your Domain Cannot End With A Dash.");
			return false;
			}	
		}

		if( eregi("[^a-z0-9\-]", $domain) == true )
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');
			get_domain_admin($user); // print domain admin 
			get_packs($pack); //print packs to sell 
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
			$tpl -> MxText('body.main_bloc.feedback', "Use only letters, numbers, or hyphen (\"-\").");
			return false;
		}

		if( $extension == "com" || $extension == "net" || $extension == "org" AND strlen($domain) > 63)
		{
	    $tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');
			get_domain_admin($user); // print domain admin 
			get_packs($pack); //print packs to sell 
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
			$tpl -> MxText('body.main_bloc.feedback', "Please Enter Less Then 63 Characters, Not Including [.".$extension."].");
			return false;
		}
			$dom = $domain.".".$extension;
			$update = update_domain($id, $user, $dom, $pack);

				if ($update == 1) {

				$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/edit_domain.mxt');

				get_domain_admin($user); // print domain admin 

				get_packs($pack); //print packs to sell 
				
				$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $domain);
				$tpl -> MxText('body.main_bloc.feedback', "le compte est bon");
					
				}				
				break; //end update case 
			
		} // switch
		
}

?>
Return current item: Hosting App