Location: PHPKode > projects > Hosting App > hosting/modules/private/adm_domains.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
 */
 
function build_select_box ($result, $name) // build dynamicly a select box  

{ 
    $rows = mysql_num_rows($result);
    echo '<SELECT NAME="'.$name.'">';
    for ($i=0; $i<$rows; $i++) {
        echo '
            <OPTION VALUE="'.mysql_result($result,$i,0).'"';
        if (mysql_result($result,$i,0) == $checked_val) {
            echo ' SELECTED';
        }
        echo '>'.mysql_result($result,$i,1).'</OPTION>';
    }
    echo '
        </SELECT>';
}


function get_domain_admin ($selected = "") // like get_packs function 
{
	global $tpl;

	$sql = "SELECT ID_client, Login FROM $GLOBALS[tbl_client]";

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

	$dom = array();
		while ($data = mysql_fetch_array($res)) {
			$dom["$data[0]"] = $data[1];		
		}
		return $tpl -> MxSelect('body.main_bloc.domain_admin', 'domain_admin', $selected, $dom);
}

function get_domains ($selected = "") // like get_packs function 
{
	global $tpl;

	$sql = "SELECT ID_domain, Domain FROM $GLOBALS[tbl_domains]";

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

	$dom = array();
		while ($data = mysql_fetch_array($res)) {
			$dom["$data[0]"] = $data[1];		
		}
		return $tpl -> MxSelect('body.main_bloc.mail.domain', 'domain', $selected, $dom);
}


function add_domain($id_user, $domain, $id_pack) // Adding a domain name to the database
{

	$sql_verif = "SELECT * FROM $GLOBALS[tbl_domains] WHERE Domain LIKE '$domain'";

	$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 "Domain exist in database";
		}else{
		$sql = "INSERT INTO $GLOBALS[tbl_domains] (ID_client, Domain, ID_pack, Date) VALUES ('$id_user', '$domain', '$id_pack', NOW())";

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

		return mysql_insert_id();
		}
}

function update_domain ($id_domain, $id_user, $domain, $id_pack) // Updating domain 
{

$sql = "UPDATE $GLOBALS[tbl_domains] SET ID_client = '$id_user', Domain = '$domain', ID_pack = '$id_pack' WHERE ID_domain = '$id_domain'";

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

return 1;

}

function delete_domain($id)
{

	$sql = "DELETE FROM $GLOBALS[tbl_domains] where ID_domain = '$id'";

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

	return 1;
}



function count_user_domain ($id)
{

	$sql = "SELECT COUNT(*) FROM $GLOBALS[tbl_domains] WHERE ID_client = '$id'";

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

	$total = mysql_fetch_row($res)	;

	return  $total[0];

}

function count_domains()
{
	$sql = "SELECT COUNT(*) FROM $GLOBALS[tbl_domains] ";

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

	$total = mysql_fetch_row($res)	;

	return  $total[0];

}

function get_user_domain ($id)
{

	$sql = "SELECT ID_Domain, Domain, ID_Pack FROM $GLOBALS[tbl_domains] WHERE ID_client = '$id'";

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

	return $res;	
}


function list_domains ($start, $limit)
{
	global $tpl;

	if (!$start) $start = 0;

	$total = count_domains();

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

//			echo $start;

//			echo $end;
		}

	$sql = "SELECT $GLOBALS[tbl_domains].ID_domain, $GLOBALS[tbl_domains].Domain, $GLOBALS[tbl_client].Login, $GLOBALS[tbl_products].Pack_name FROM $GLOBALS[tbl_client], $GLOBALS[tbl_domains], $GLOBALS[tbl_products] WHERE $GLOBALS[tbl_products].ID_pack = $GLOBALS[tbl_domains].ID_pack AND $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client ORDER BY $GLOBALS[tbl_domains].ID_client ASC 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.domain', $row[1]);

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

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

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

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

		$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=domain&domain='.$row[1].'&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=domain&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 view_domain (&$tpl, $id, $q)
{

	$sql = "SELECT $GLOBALS[tbl_domains].*, $GLOBALS[tbl_client].Login FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_client] WHERE $GLOBALS[tbl_domains].ID_domain = '$id' AND $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client";

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

	$row = mysql_fetch_assoc($res);

	switch($q){

		case "view": 
			$pack = pack_name ($row['ID_pack']);

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

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

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

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

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

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

			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_domain.mxt');

			get_domain_admin($row['ID_client']);
			get_packs($row['ID_pack']);
			
			$tpl -> MxFormField('body.main_bloc.domain', "text", "domain", $row['Domain']);
			
			$tpl -> MxHidden('body.main_bloc.id', "id=".$id);

			break;

	} // switch
	return 1;
}


function search_domains (& $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 $GLOBALS[tbl_domains].*, $GLOBALS[tbl_client].Login, $GLOBALS[tbl_products].Pack_name FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_client], $GLOBALS[tbl_products] WHERE $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client AND $GLOBALS[tbl_domains].ID_pack = $GLOBALS[tbl_products].ID_pack AND $GLOBALS[tbl_domains].ID_domain = '".$query."' ";

			break;
	
		case "domain" : 

			$sql = "SELECT $GLOBALS[tbl_domains].*, $GLOBALS[tbl_client].Login, $GLOBALS[tbl_products].Pack_name FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_client], $GLOBALS[tbl_products] WHERE $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client AND $GLOBALS[tbl_domains].ID_pack = $GLOBALS[tbl_products].ID_pack AND $GLOBALS[tbl_domains].Domain LIKe '%".$query."%' ";

			break;

		case "pack" : 

			$sql = "SELECT $GLOBALS[tbl_domains].*, $GLOBALS[tbl_client].Login, $GLOBALS[tbl_products].Pack_name FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_client], $GLOBALS[tbl_products] WHERE $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client AND $GLOBALS[tbl_domains].ID_pack = $GLOBALS[tbl_products].ID_pack AND $GLOBALS[tbl_domains].ID_pack = $GLOBALS[tbl_products].ID_pack AND $GLOBALS[tbl_products].Pack_name LIKE '%".$query."%' ";

			break;

		case "user" :
			
			$sql = "SELECT $GLOBALS[tbl_domains].*, $GLOBALS[tbl_client].Login, $GLOBALS[tbl_products].Pack_name FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_client], $GLOBALS[tbl_products] WHERE $GLOBALS[tbl_client].ID_client = $GLOBALS[tbl_domains].ID_client AND $GLOBALS[tbl_domains].ID_pack = $GLOBALS[tbl_products].ID_pack AND $GLOBALS[tbl_client].Login 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.domain', $row[1]);

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

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

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

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

		$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=domain&domain='.$row[1].'&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 




?>
Return current item: Hosting App