Location: PHPKode > projects > Hosting App > hosting/modules/private/adm_users.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, 25/08/2002
 */

function add_new_user($nom, $prenom, $rs = "", $adresse = "", $ville = "", $cp = "", $tel = "", $email, $login, $password)
{

	$sql_verif = "SELECT * FROM $GLOBALS[tbl_client] WHERE Login LIKE '$login'";

	$res_verif = mysql_query($sql_verif) or die ("Impossible d'executer la req ".mysql_error());

	$row = mysql_num_rows($res_verif);

		if ($row > 0) {
			return "The user already exist in database";
		}else{	
			$sql = "INSERT INTO $GLOBALS[tbl_client] (Nom, Prenom, Rs, Adresse, Ville, Cp, Tel, Email, Login, Password, Date) VALUES ('$nom', '$prenom', '$rs', '$adresse', '$ville', '$cp', '$tel', '$email', '$login', '$password', NOW())";
		
			$res = mysql_query($sql) or die("Impossible d'executer la requete - $sql -".mysql_error());

			return 1;
		}	
}

function modify_user_data($id_user, $nom, $prenom, $rs = "", $adresse = "", $ville = "", $cp = "", $tel = "", $email, $login, $password)
{

	$sql = "UPDATE $GLOBALS[tbl_client] SET Nom = '$nom', Prenom = '$prenom', Rs = '$rs', Adresse = '$adresse', Ville = '$ville', Cp = '$cp', Tel = '$tel', Email = '$email', Login = '$login', Password = '$password' WHERE ID_client = '$id_user' ";

	$res = mysql_query($sql) or die("Impossible d'executer la requete".mysql_error());

	return 1;
}



function delete_user($id_user)
{

	$sql = "DELETE FROM $GLOBALS[tbl_client] where ID_client = '$id_user'";

	$res = mysql_query($sql) or die("Impossible d'executer la requete".mysql_error());

	return 1;

}

function search_users (& $tpl, $q, $what, $start, $limit)
{

$query = str_replace('+', ' ', $q);
$query = str_replace(',', ' ', $query);
$query = str_replace(':', ' ', $query);
$query = str_replace('%', ' ', $query);


	switch($what) { 
	
		case "ID" :

			$sql = "SELECT ID_client, Nom, Prenom, Login FROM $GLOBALS[tbl_client] WHERE ID_client = '".$query."' ";
//			echo $sql;
			break;
	
		case "name" : 

			$sql = "SELECT ID_client, Nom, Prenom, Login FROM $GLOBALS[tbl_client] WHERE Nom LIKE '%".$query."%' OR Prenom LIKE '%".$query."%'";

			break;

		case "user" : 

			$sql = "SELECT ID_client, Nom, Prenom, Login FROM $GLOBALS[tbl_client] WHERE Login LIKE '".$query."%'";

			break;

		case "company" :
			
			$sql = "SELECT ID_client, Nom, Prenom, Login FROM $GLOBALS[tbl_client] WHERE Rs LIKE '".$query."%'";
			
			break;
	
	} // switch	

	
	$res = mysql_query($sql) or die("query failed ".mysql_error());
	
	$total = mysql_num_rows($res);
	
	if ($total == 0) {
	    $tpl -> MxText('body.main_bloc.feedback', "No result found");
			return false;
	}
	
	if (!$start) $start = 0;

		if ($total < $limit) {
		    $end = $total;
		}else{
			$end = $start + $limit;
		}

	$query = $sql." LIMIT ".$start.", ".$limit;
	
	$result = mysql_query($query) or die("query failed ".mysql_error());

	
	$tpl -> MxText('body.main_bloc.start', $start + 1);

	$tpl -> MxText('body.main_bloc.limit', $end);

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

	while($row = mysql_fetch_array($res)){

		$tpl -> MxText('body.main_bloc.view_loop.first_last', $row[2]." ".$row[1]);

		$tpl -> MxText('body.main_bloc.view_loop.login', $row[3]);

		$tpl -> MxText('body.main_bloc.view_loop.num_domains', count_user_domain($row[0]));

		$tpl -> MxUrl('body.main_bloc.view_loop.view', 'view.php', 'what=user&id='.$row[0]);

		$tpl -> MxUrl('body.main_bloc.view_loop.mod', 'modify.php', 'what=user&id='.$row[0]);

		$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=user&user='.$row[3].'&id='.$row[0]);

		$tpl -> MxBloc('body.main_bloc.view_loop', "loop");

	} // while

	$tpl -> MxText('body.main_bloc.sep', '||');

	    if ($total > $end) {
			$tpl -> MxText('body.main_bloc.next', "next");
			$tpl -> MxUrl('body.main_bloc.next', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=user&offset=".$end);
			}
			if ($start >= $limit) 
			{
			$s = $start - $limit;
			$tpl -> MxText('body.main_bloc.previous', "previous");
			$tpl -> MxUrl('body.main_bloc.previous', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=user&offset=".$s);			
			}

} // end search function 



function list_users ($start, $limit)
{
	global $tpl;
	if (!$start) $start = 0;

	$total = count_users();

		if ($total < $limit) {
		    $end = $total;
		}else{
			$end = $start + $limit;
		}
	$sql = "SELECT ID_client, Nom, Prenom, Login FROM $GLOBALS[tbl_client] LIMIT $start, $limit";

	$res = mysql_query($sql) or die ("Impossible d'executer la requete ".mysql_error());

	$tpl -> MxText('body.main_bloc.start', $start + 1);

	$tpl -> MxText('body.main_bloc.limit', $end);

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

	while($row = mysql_fetch_array($res)){

		$tpl -> MxText('body.main_bloc.view_loop.first_last', $row[2]." ".$row[1]);

		$tpl -> MxText('body.main_bloc.view_loop.login', $row[3]);

		$tpl -> MxText('body.main_bloc.view_loop.num_domains', count_user_domain($row[0]));

		$tpl -> MxUrl('body.main_bloc.view_loop.view', 'view.php', 'what=user&id='.$row[0]);

		$tpl -> MxUrl('body.main_bloc.view_loop.mod', 'modify.php', 'what=user&id='.$row[0]);

		$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=user&user='.$row[3].'&id='.$row[0]);

		$tpl -> MxBloc('body.main_bloc.view_loop', "loop");

	} // while

	$tpl -> MxText('body.main_bloc.sep', '||');

	    if ($total > $end) {
			$tpl -> MxText('body.main_bloc.next', "next");
			$tpl -> MxUrl('body.main_bloc.next', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=user&offset=".$end);
			}
			if ($start >= $limit) 
			{
			$s = $start - $limit;
			$tpl -> MxText('body.main_bloc.previous', "previous");
			$tpl -> MxUrl('body.main_bloc.previous', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=user&offset=".$s);			
			}
}



function count_users ()
{

		$sql = "SELECT COUNT(*) FROM $GLOBALS[tbl_client]";	

		$res = mysql_query($sql);

		$total = mysql_fetch_row($res)	;

		return  $total[0];
}

function view_user (&$tpl, $id, $q)
{

	$sql = "SELECT * FROM $GLOBALS[tbl_client] WHERE ID_client = '$id'";

	$res = mysql_query($sql) or die ("Impossible d'executer la req ".mysql_error());

	$row = mysql_fetch_array($res);

	switch($q){

		case "view": 

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

			$tpl -> MxText('body.main_bloc.last', $row[1]);

			$tpl -> MxText('body.main_bloc.first', $row[2]);

			$tpl -> MxText('body.main_bloc.company', $row[3]);

			$tpl -> MxText('body.main_bloc.address', $row[4]);

			$tpl -> MxText('body.main_bloc.city', $row[5]);

			$tpl -> MxText('body.main_bloc.zip', $row[6]);

			$tpl -> MxText('body.main_bloc.phone', $row[7]);

			$tpl -> MxText('body.main_bloc.email', $row[8]);

			$tpl -> MxText('body.main_bloc.login', $row[9]);

			$tpl -> MxText('body.main_bloc.password', $row[10]);

			$tpl -> MxText('body.main_bloc.edit', "Edit User");

			$tpl -> MxUrl('body.main_bloc.edit', "modify.php", "what=user&id=".$id);

			$dom = count_user_domain ($id);

			$tpl -> MxText('body.main_bloc.domcount', $dom);

			if ($dom > 0 ) {

				$domains = get_user_domain ($id);

					while($row = mysql_fetch_array($domains)){

						$tpl -> MxText('body.main_bloc.dom_list.dom', $row[1]);

						$pack = pack_name ($row[1]);

						$tpl -> MxText('body.main_bloc.dom_list.pack', $pack);

						$tpl -> MxBloc('body.main_bloc.dom_list', "loop");

					} // while	

			} // end if

			break;

		case "edit": 

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

			$tpl -> MxFormField('body.main_bloc.last', "text", "last", $row[1]);

			$tpl -> MxFormField('body.main_bloc.first', "text", "first", $row[2]);

			$tpl -> MxFormField('body.main_bloc.company', "text", "company", $row[3]);

			$tpl -> MxFormField('body.main_bloc.address', "text", "address", $row[4]);

			$tpl -> MxFormField('body.main_bloc.city', "text", "city", $row[5]);

			$tpl -> MxFormField('body.main_bloc.zip_code', "text", "zip_code", $row[6]);

			$tpl -> MxFormField('body.main_bloc.phone', "text", "phone", $row[7]);

			$tpl -> MxFormField('body.main_bloc.email', "text", "email", $row[8]);

			$tpl -> MxFormField('body.main_bloc.login', "text", "login", $row[9]);

			$tpl -> MxFormField('body.main_bloc.password', "text", "password", $row[10]);

			$tpl -> MxHidden('body.main_bloc.id', "id=".$id);

			break;

	} // switch
	return 1;
}



function remove_user(&$tpl, $id)
{

	$number_of_domains = count_user_domain($id);

	if ($number_of_domains != 0) $user_domains = get_user_domain($id);

		while($rows = mysql_fetch_array($user_domains)){

			$number_of_mail = count_domainmail($row[0]);
		
		 	if ($number_of_mail != 0) delete_mail($rows[0]);
		
			delete_domain($rows[0]);

		} // while	

		delete_user($id);

		$tpl -> MxText ('body.main_bloc.message', "User and related data are successfully deleted");
}



?>
Return current item: Hosting App