Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/domain/emailadmin.phps
<?
// Init vars
$i = 0;
$j = 0;
$k = 0;
unset($done);
unset($userlist);
unset($error);

// If data is set (i.e the submit button has been hit)
$reload_data = false;
if ((isset($data) || isset($action)) && ($userdata['type'] != 'demo') && $action=='update') {
	// remove spaces and slashes.
	$data = strip_array($data);

	//Check if something changed
	$update_alias = array();
	if(isset($salias)) {
		$salias = strip_array($salias);
		foreach($salias as $tmp) {
			if($tmp['nuser']!=$tmp['user'] || $tmp['nemail']!=$tmp['email']) {
				$update_alias[$tmp['user']]['del'][$tmp['email']] = true;
				$update_alias[$tmp['nuser']]['add'][$tmp['nemail']] = true;
			}
		}
	}
	if(!empty($data['newalias']['email']) && !empty($data['newalias']['user'])) {
		$update_alias[$data['newalias']['user']]['add'][$data['newalias']['email']] = true;
	}
		
	$update_fwd = array();
	if(isset($sfwd)) {
		$sfwd = strip_array($sfwd);
		foreach($sfwd as $tmp) {
			if($tmp['nuser']!=$tmp['user'] || $tmp['nemail']!=$tmp['email']) {
				//username is different
				$update_fwd[$tmp['user']]['del'][$tmp['email']] = true;
				$update_fwd[$tmp['nuser']]['add'][$tmp['nemail']] = true;
			}
		}
	}
	if(!empty($data['newfwd']['email']) && !empty($data['newfwd']['user'])) {
		$update_fwd[$data['newfwd']['user']]['add'][$data['newfwd']['email']] = true;
	}

//	echo '<pre>';var_dump($update_fwd);echo '</pre>';
	
	if($data['ncauser']!=$data['causer']) {
		//remove old
		$res = user('update', array(
			'uid'     => $data['causer'],
			'id'      => $domaindata['id'],
			'catchall'=> 'false'
		));

		if(!empty($data['ncauser']))
			$res = user('update', array(
				'uid'     => $data['ncauser'],
				'id'      => $domaindata['id'],
				'catchall'=> 'true'
			));
	}
}


//$useroption = '';
$userlist = array();
$forwardlist = array();
$aliaslist = array();
unset($catchalluser);

$dbp = mysql_query('SELECT username, aliases, forward, catchall FROM users WHERE id = "'.$domaindata['id'].'"');

while ($tmp = mysql_fetch_array($dbp)) {
	$userlist[] = $tmp['username'];
//	$useroption .= '<option value="'.$tmp['username'].'">'.$tmp['username'].'</option>'."\n";

	$aliaslist[$tmp['username']] = $tmp['username'];
	
	$aliases = '';
	$update = false;
	foreach(explode(' ', trim($tmp['aliases'])) as $alias) {
		if(!empty($alias)) {
			if(isset($action) && (($action=='remove_alias' && $aliasuser==$tmp['username'])
				|| ($action=='update' && isset($update_alias[$tmp['username']])))
				&& ($userdata['type'] != 'demo')) {
				
				if($aliasid!=$alias && !isset($update_alias[$tmp['username']]['del'][$alias])) {
					$aliases .= $alias.' ';
					$aliaslist[$alias] = $tmp['username'];
				} else
					$update = true;
			} else
				$aliaslist[$alias] = $tmp['username'];
		}
	}
	if(isset($update_alias[$tmp['username']]['add'])) {
		foreach($update_alias[$tmp['username']]['add'] as $alias => $discard) {
			$aliaslist[$alias] = $tmp['username'];
			$aliases .= $alias.' ';
			$update = true;
		}
	}

	if($update) {
		$res = user('update', array(
			'uid'    => $tmp['username'],
			'id'     => $domaindata['id'],
			'aliases'=> rtrim($aliases)
		));
	}
	$aliases = ''; //clean up memory
	
	$forwarders = '';
	$update = false;
	foreach(explode(' ', trim($tmp['forward'])) as $fwd) {
		if(!empty($fwd)) {
			if(isset($action) && (($action=='remove_fwd' && $fwduser==$tmp['username'])
				|| ($action=='update' && isset($update_fwd[$tmp['username']])))
				&& ($userdata['type'] != 'demo')) {
				
				if($fwdid!=$fwd && !isset($update_fwd[$tmp['username']]['del'][$fwd])) {
					$forwarders .= $fwd.' ';
					$forwardlist[] = array($fwd, $tmp['username']);
				} else
					$update = true;
			} else
				$forwardlist[] = array($fwd, $tmp['username']);
		}
	}
	if(isset($update_fwd[$tmp['username']]['add'])) {
		foreach($update_fwd[$tmp['username']]['add'] as $fwd => $discard) {
			$forwarders .= $fwd.' ';
			$forwardlist[] = array($fwd, $tmp['username']);
			$update = true;
		}
	}
	if($update) {
		$res = user('update', array(
			'uid'    => $tmp['username'],
			'id'     => $domaindata['id'],
			'forward'=> rtrim($forwarders)
		));
	}
	$forwarders = ''; //clean up memory
	
	if($tmp['catchall']=='true' /*|| $data['causer']==$tmp['username']*/) {
		$catchalluser = $tmp['username'];
	}
}


?>
<form action="<?=$current_url;?>" method="post" name="webcp1" onSubmit="submitonce(this);">
<input type="hidden" name="action" value="update">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" summary=""  width="550">
	<tr>
		<td>
		<b class="big"><?=$T['E-Mail Aliases'];?></b>
		<table border="0" cellpadding="0" cellspacing="0" summary="" class="tblbg" width="100%">
			<tr>
				<td>
				<table border="0" cellspacing="1" summary="" width=100%>
					<tr>
						<td class="tbltop"><b><?=$T['Alias'];?></b></td>
						<td class="tbltop">&nbsp;</td>
						<td class="tbltop"><b><?=$T['Username'];?></b></td>
						<td class="tbltop">&nbsp;</td>
					</tr>
					<input type="hidden" name="data[causer]" value="<?=isset($catchalluser)?$catchalluser:'';?>">
					<tr>
						<td class="row1"><?=$T['Catch-All'];?></td>
						<td class="row1"><div align="center">=&gt;</div></td>
						<td class="row1"><select name="data[ncauser]">
							<option value=""<?=!isset($catchalluser)?' selected':'';?>>
								[<?=strip_tags($T['none']);?>]
							</option>
<?php
						foreach($userlist as $user) {
							if(isset($catchalluser) && $user == $catchalluser) {
?>
							<option value="<?=$user;?>" selected><?=$user;?></option>
<?php						} else { ?>
							<option value="<?=$user;?>"><?=$user;?></option>
<?php
							}
						}
?>
						</select></td>
						<td class="row1">&nbsp;</td>
					</tr>
<?php
				$row = 2;
				$i=0;
				foreach($aliaslist as $alias => $user) {
?>
					<input type="hidden" name="salias[<?=$i;?>][email]" value="<?=$alias;?>">
					<input type="hidden" name="salias[<?=$i;?>][user]" value="<?=$user;?>">
					<tr>
						<td class="row<?=$row;?>">
<?php					if($alias!=$user) { ?>
							<input type="text" name="salias[<?=$i;?>][nemail]" value="<?=$alias;?>">
<?php					} else
							echo $alias;
?>
							@<?=$domaindata['domain'];?>
						</td>
						<td class="row<?=$row;?>"><div align="center">=&gt;</div></td>
						<td class="row<?=$row;?>">
<?php					if($alias!=$user) { ?>
							<select name="salias[<?=$i;?>][nuser]">
<?php
						foreach($userlist as $luser) {
							if($luser == $user) {
?>
								<option value="<?=$luser;?>" selected><?=$luser;?></option>
<?php						} else { ?>
								<option value="<?=$luser;?>"><?=$luser;?></option>
<?php
							}
						}
?>
							</select>
<?php
						} else
							echo $user;
?>
						</td>
						<td class="row<?=$row;?>">
<?php					if($alias!=$user) { ?>
							<div align=center><a href="<?=$current_url;?>&action=remove_alias&aliasid=<?=$alias;?>&aliasuser=<?=$user;?>">
								<img src="icon/remove.gif" border="0" width="15" height="15" alt="Remove">
							</a></div>
<?php
						}
?>
						</td>
					</tr>
<?php
					$row = ($row==1)?2:1;
					++$i;
				}
?>
					<tr>
						<td class="row<?=$row;?>">
							<input type="text" name="data[newalias][email]" value="">
							@<?=$domaindata['domain'];?>
						</td>
						<td class="row<?=$row;?>"><div align="center">=&gt;</div></td>
						<td class="row<?=$row;?>"><select name="data[newalias][user]">
<?php					foreach($userlist as $luser) { ?>
							<option value="<?=$luser;?>"><?=$luser;?></option>
<?php					} ?>
						</select></td>
						<td class="row<?=$row;?>">&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td><div align="right"><br><input type="submit" value="<?=$T['submit'];?>"></div><br>&nbsp;</td>
	</tr>
<!-- #################### -->
	<tr>
		<td>
		<b class="big"><?=$T['Forwarders'];?></b>
		<table border="0" cellpadding="0" cellspacing="0" summary="" class="tblbg">
			<tr>
				<td>
				<table border="0" cellspacing="1" summary="" width="550">
					<tr>
						<td class="tbltop"><b><?=$T['Username'];?></b></td>
						<td class="tbltop">&nbsp;</td>
						<td class="tbltop"><b><?=$T['E-Mail Address'];?></b></td>
						<td class="tbltop">&nbsp;</td>
					</tr>
<?php
				$row = 1;
				$i = 0;
				foreach($forwardlist as $tmp) {
				list($fwd, $user) = $tmp;
?>
					<input type="hidden" name="sfwd[<?=$i;?>][email]" value="<?=$fwd;?>">
					<input type="hidden" name="sfwd[<?=$i;?>][user]" value="<?=$user;?>">
					<tr>
						<td class="row<?=$row;?>"><select name="sfwd[<?=$i;?>][nuser]">
<?php
						foreach($userlist as $luser) {
							if($luser == $user) {
?>
							<option value="<?=$luser;?>" selected><?=$luser;?></option>
<?php						} else { ?>
							<option value="<?=$luser;?>"><?=$luser;?></option>
<?php
							}
						}
?>
						</select></td>
						<td class="row<?=$row;?>"><div align="center">=&gt;</div></td>
						<td class="row<?=$row;?>">
							<input type="text" name="sfwd[<?=$i;?>][nemail]" value="<?=$fwd;?>" size="45">
						</td>
						<td class="row<?=$row;?>">
							<div align=center><a href="<?=$current_url;?>&action=remove_fwd&fwdid=<?=$fwd;?>&fwduser=<?=$user;?>">
								<img src="icon/remove.gif" border="0" width="15" height="15" alt="Remove">
							</a></div>
						</td>
					</tr>
<?php
					$row = ($row==1)?2:1;
					++$i;
				}
?>
					<tr>
						<td class="row<?=$row;?>"><select name="data[newfwd][user]">
<?php					foreach($userlist as $luser) { ?>
							<option value="<?=$luser;?>"><?=$luser;?></option>
<?php					} ?>
						</select></td>
						<td class="row<?=$row;?>"><div align="center">=&gt;</div></td>
						<td class="row<?=$row;?>">
							<input type="text" name="data[newfwd][email]" value="" size="45">
						</td>
						<td class="row<?=$row;?>">&nbsp;</td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td><div align="right"><br><input type="submit" value="<?=$T['submit'];?>"></div></td>
	</tr>
</table>
</div></form>
Return current item: web-cp - Web Hosting Control Panel