<?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.0, 23/09/2002
*/
/**
* add_email()
* adding email to database
*
* @param int $id_domain
* @param string $email
* @param string $password
* @return 1 // case success return 1
**/
function add_email($id_domain, $email, $password) // Adding a domain name to the database
{
$sql_verif = "SELECT * FROM $GLOBALS[tbl_mail] WHERE ID_domain = '$id_domain' AND Login = '$email'";
$res_verif = mysql_query($sql_verif) or die ("Impossible d'executer la req ".mysql_error());
$row = mysql_num_rows($res_verif);
if ($row > 0) {
die ("Email $email already exist in database.");
}else{
$sql = "INSERT INTO $GLOBALS[tbl_mail] (ID_domain, Login, Pwd, Date) VALUES ('$id_domain', '$email', '$password', NOW())";
$res = mysql_query($sql) or die("Impossible d'executer la requete".mysql_error());
return 1;
}
}
/**
* update_email()
*
* Upating email parameter
*
* @param int $id
* @param string $email
* @param string $password
* @return bool true
**/
function update_email ($id, $email, $password)
{
$sql = "UPDATE $GLOBALS[tbl_mail] SET Login = '$email', Pwd = '$password' WHERE ID_mail = '$id'";
$res = mysql_query($sql) or die ("Query Failed - $sql - ".mysql_error());
return true;
}
/**
* delete_email()
*
* deleting an email
*
* @param int $id
* @return bool true
**/
function delete_email($id)
{
$sql = "DELETE FROM $GLOBALS[tbl_mail] where ID_domain = '$id'";
$res = mysql_query($sql) or die("Impossible d'executer la requete".mysql_error());
return true;
}
// count number of email created
function count_emails()
{
$sql = "SELECT COUNT(*) FROM $GLOBALS[tbl_mail] ";
$res = mysql_query($sql) or die("Impossible d'executer la requete ".mysql_error());
$total = mysql_fetch_row($res) ;
return $total[0];
}
// count the number of mail for a specific domain
function count_domainmail($id)
{
$sql = "SELECT COUNT(*) FROM $GLOBALS[tbl_mail] WHERE ID_domain = '$id'";
$res = mysql_query($sql) or die("Impossible d'executer la requete ".mysql_error());
$total = mysql_fetch_row($res) ;
return $total[0];
}
// display email created
function list_emails ($start, $limit)
{
global $tpl;
if (!$start) $start = 0;
$total = count_emails();
if ($total < $limit) {
$end = $total;
}else{
$end = $start + $limit;
// echo $start;
// echo $end;
}
$sql = "SELECT $GLOBALS[tbl_mail].ID_mail, $GLOBALS[tbl_mail].Login, $GLOBALS[tbl_domains].Domain FROM $GLOBALS[tbl_mail], $GLOBALS[tbl_domains] WHERE $GLOBALS[tbl_domains].ID_domain = $GLOBALS[tbl_mail].ID_domain ORDER BY $GLOBALS[tbl_mail].ID_domain ASC LIMIT $start, $limit ";
$res = mysql_query($sql) or die ("Impossible d'executer la requete ".mysql_error());
/*
* building the status bar
*/
$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.email', $row[1]);
$tpl -> MxText('body.main_bloc.view_loop.domain', $row[2]);
$tpl -> MxUrl('body.main_bloc.view_loop.view', 'view.php', 'what=email&id='.$row[0]);
$tpl -> MxUrl('body.main_bloc.view_loop.mod', 'modify.php', 'what=email&id='.$row[0]);
$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=email&email='.$row[1].'&id='.$row[0]);
$tpl -> MxBloc('body.main_bloc.view_loop', "loop"); // looping while limit is reached
} // while
$tpl -> MxText('body.main_bloc.sep', '||');
if ($total > $end)
{
$tpl -> MxText('body.main_bloc.next', "next"); // builing next link if necessary
$tpl -> MxUrl('body.main_bloc.next', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=email&offset=".$end);
}
if ($start >= $limit)
{
$s = $start - $limit;
$tpl -> MxText('body.main_bloc.previous', "previous"); // building previous link if necessary
$tpl -> MxUrl('body.main_bloc.previous', $HTTP_ENV_VARS['SCRIPT_FILENAME'],"what=user&offset=".$s);
}
}
// view or edit specific email
function view_email (&$tpl, $id, $q)
{
$sql = "SELECT $GLOBALS[tbl_mail].*, $GLOBALS[tbl_domains].Domain FROM $GLOBALS[tbl_domains], $GLOBALS[tbl_mail] WHERE $GLOBALS[tbl_mail].ID_mail = '$id' AND $GLOBALS[tbl_domains].ID_domain = $GLOBALS[tbl_mail].ID_domain";
$res = mysql_query($sql) or die ("Impossible d'executer la req ".mysql_error());
$row = mysql_fetch_assoc($res);
switch($q){
case "view": // view case : build view page
$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/view_mail.mxt');
$tpl -> MxText('body.main_bloc.mail.email', $row['Login']);
$tpl -> MxText('body.main_bloc.mail.domain', $row['Domain']);
$tpl -> MxText('body.main_bloc.mail.password', $row['Pwd']);
$tpl -> MxText('body.main_bloc.edit', "Edit This Email");
$tpl -> MxUrl('body.main_bloc.edit', "modify.php", "what=email&id=".$id);
break;
case "edit": // edit case : build edit page
$tpl -> MxBloc('body.main_bloc', 'modify', './tpl/admin/bloc_mail.mxt');
$tpl -> MxFormField('body.main_bloc.mail.email', "text", "email", $row['Login']);
$tpl -> MxFormField('body.main_bloc.mail.password', "text", "password", $row['Pwd']);
$tpl -> MxHidden('body.main_bloc.id', "id=".$id);
$tpl -> MxHidden('body.main_bloc.form', "form=1");
$tpl -> MxHidden('body.main_bloc.what', "what=email");
break;
} // switch
return 1;
}
function search_mail (& $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 "email" :
$sql = "SELECT $GLOBALS[tbl_mail].ID_mail, $GLOBALS[tbl_mail].Login, $GLOBALS[tbl_domains].Domain FROM $GLOBALS[tbl_mail], $GLOBALS[tbl_domains] WHERE $GLOBALS[tbl_mail].Login LIKE '%".$query."%' AND $GLOBALS[tbl_domains].ID_domain = $GLOBALS[tbl_mail].ID_domain";
break;
case "domain" :
$sql = "SELECT $GLOBALS[tbl_mail].ID_mail, $GLOBALS[tbl_mail].Login, $GLOBALS[tbl_domains].Domain FROM $GLOBALS[tbl_mail], $GLOBALS[tbl_domains] WHERE $GLOBALS[tbl_mail].ID_domain = $GLOBALS[tbl_domains].ID_domain AND $GLOBALS[tbl_domains].Domain 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.email', $row[1]);
$tpl -> MxText('body.main_bloc.view_loop.domain', $row[2]);
$tpl -> MxUrl('body.main_bloc.view_loop.view', 'view.php', 'what=email&id='.$row[0]);
$tpl -> MxUrl('body.main_bloc.view_loop.mod', 'modify.php', 'what=email&id='.$row[0]);
$tpl -> MxUrl('body.main_bloc.view_loop.del', 'delete.php', 'what=email&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
?>