Location: PHPKode > projects > Hosting App > hosting/modules/private/adm_pack.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.2, 20/09/2002
 */


function add_pack ($pack, $space, $num_mail, $hits, $bandwidth) // adding a new product
{
	$sql_verif = "SELECT * FROM $GLOBALS[tbl_products] WHERE Pack_name LIKE '$pack'";

	$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 "This product already exist in database";
		}else{
			$sql = "INSERT INTO $GLOBALS[tbl_products] (`Pack_name`, `Space`, `Number_mail`, `Max_hits`, `Max_bandwidth`) VALUES ('$pack', '$space', '$num_mail', '$hits', '$bandwidth')";

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

	   return 1;
}
}

function update_pack ($id_pack, $pack, $space, $num_mail, $hits, $bandwidth) // updating a product 
{
	$sql = "UPDATE $GLOBALS[tbl_products] SET Pack_name = '$pack', Space = '$space', Number_mail = '$num_mail', Max_hits = '$hits', Max_bandwidth = '$bandwidth' WHERE ID_pack = '$id_pack'";

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

  return 1;
}


function delete_pack ($id_pack)
{

	$sql = "DELETE * FROM $GLOBALS[tbl_products] WHERE ID_pack = '$id_pack'";

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

  return 1;

}

function get_packs($selected = "") // get all packs to sell to display them in a select box 
{
	global $tpl;

	$sql = "SELECT ID_pack, Pack_name FROM $GLOBALS[tbl_products]";

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

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

function pack_properties ($id_pack)
{
	$sql = "SELECT Pack_name, Space, Number_mail, Max_hits, Max_bandwidth FROM $GLOBALS[tbl_products] WHERE ID_pack = '$id_pack'";

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

  return $res;
}


function pack_name ($id)
{
	$sql = "SELECT Pack_name FROM $GLOBALS[tbl_products] WHERE ID_pack = '$id'";

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

	$row = mysql_fetch_array($res);

	return $row[0];
}


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

	if (!$start) $start = 0;

	$total = count_users();

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

	$sql = "SELECT ID_pack, Pack_name FROM $GLOBALS[tbl_products] 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.pack', $row[1]);

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

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

		//$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=product&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 search_products (& $tpl, $q, $what, $start, $limit)
{
// replacing + , : % by a blank space 
$query = str_replace('+', ' ', $q);
$query = str_replace(',', ' ', $query);
$query = str_replace(':', ' ', $query);
$query = str_replace('%', ' ', $query);


	switch($what) { 
	
		case "ID" :

			$sql = "SELECT ID_pack, Pack_name FROM $GLOBALS[tbl_products] WHERE ID_pack = '".$query."' ";
//			echo $sql;
			break;
	
		case "name" : 

			$sql = "SELECT ID_pack, Pack_name FROM $GLOBALS[tbl_products] WHERE Pack_name 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.pack', $row[1]);

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

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

		$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=product&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 view_product (&$tpl, $id, $q)
{

	$sql = "SELECT * FROM $GLOBALS[tbl_products] WHERE ID_pack = '$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_product.mxt');

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

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

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

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

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

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

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

			break;

		case "edit": 

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

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

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

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

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

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

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

			break;

	} // switch
	return 1;
}





?>
Return current item: Hosting App