Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/server/reselleradmin.phps
<?
// If action is set
if ($action == 'update') {
	unset($result);
	unset($tmp);
	unset($error);
	if (is_array($rid)) { // multiple reseller update.
		reset($rid);
		do {
			$tmprid = trim(current($rid));
			$tmp = $data[$tmprid];
			$tmp['id'] = $tmprid;
			
			$tmperr = reseller('update',$tmp,$return);
			
			// Trap errors and 'add' them up.
			if ($tmperr) {
				reset($tmperr);
				foreach($tmperr AS $key=>$val)
					$tmperr[$key] = "$tmprid: $val";
				
				if ($error) $error = array_merge($error,$tmperr);
				else $error = $tmperr;
			}
			else {
				$tmp = fetchdata("name","reseller",$tmprid);
				$result .= $tmp['name']." .";
			}
		} while(next($rid));

	}
	else $error[1] = $T['err']['nothing to update'];

	if ($error)
		echo "<br>&nbsp;&nbsp;• ".implode("<br>\n&nbsp;&nbsp;• ",$error)."<br>\n";
	if ($result) 
		echo $T['reseller '.$action]."<b>".$result."</b><br>\n";
}
elseif ($action AND $confirm == "true") {
	// Initialize
	unset($data);
	unset($error);
	// check if its a GET or POST (i.e is $rid a string or an array?)
	if (!is_array($rid)) { // single action from GET
		// hardcode data
		$data['id'] = $rid;
		
		$tmp = fetchdata("name","reseller",$rid);
		$tmp = $tmp['name'];

		$error = reseller($action,$data,$return);
		
	}
	elseif (is_array($rid)) { // multiple reseller action.
		unset($tmpid);
		while (list($key, $val) = each($rid)) {
			$tmp = fetchdata("name","reseller",$val);
			$tmpid[$key] = $tmp['name'];
		}
		$tmp = implode(", ",$tmpid);
		
		reset($rid);
		do {
			$data['id'] = trim(current($rid));
			$tmperr = reseller($action,$data,$return);
			
			// Trap errors and 'add' them up.
			if ($tmperr) {
				if ($error) $error = array_merge($error,$tmperr);
				else $error = $tmperr;
			}
		} while(next($rid));
		
	}
	else $error[1] = $T['Invalid Input'];

	if ($error)
		echo "<br>&nbsp;&nbsp;&bull; ".implode("<br>\n&nbsp;&nbsp;&bull; ",$error)."<br>\n";
	else 
		echo $T['reseller '.$action]."<b>".$tmp."</b><br>\n";
}
// ask confirmation for suspend - unsuspend - remove
elseif ($action AND $rid AND $confirm != "true") {
	if (is_array($rid)) {
		reset($rid);
		unset($tmpid);
		while (list($key, $val) = each($rid)) {
			$tmp = fetchdata("name","reseller",$val);
			$tmpid[$key] = $tmp['name'];
		}
		$tmp = implode(", ",$tmpid);
	}
	else {
		$tmp = fetchdata("name","reseller",$rid);
		$tmp = $tmp['name'];
	}
?>
<blockquote>
<form action="<?=$current_url;?>" method="post" name="webcp1" onSubmit="submitonce(this);">
&nbsp;&nbsp;&bull; <?=$T['really '.$action];?><b><?=$tmp;?></b><br>
&nbsp;&nbsp;&nbsp;<input type="submit" value="<?=$T['yes'];?>">
<? if (is_array($rid)) {
	reset($rid);
	while (list($key, $val) = each($rid))
		echo "<input type='hidden' name='rid[$key]' value='$val'>\n";
}
else echo '<input type="hidden" name="rid" value="'.$rid.'">';
?>
<input type="hidden" name="action" value="<?=$action;?>">
<input type="hidden" name="confirm" value="true">
</form>
</blockquote>
<? }
// If $search, do it; create appropriate SQL query.
if ($search == 'true') {
	// remove spaces
	foreach($data AS $key=>$val)
		$data[$key] = trim($val);
	
	// if searchin == all OR username, search user table.
	unset($usersearch);
	$i = 0;
	if ($data['searchin'] == 'all' OR $data['searchin'] == 'username') {
		$sql_query = "SELECT DISTINCT(id) AS id FROM users WHERE username LIKE '%".$data['search']."%'";
		$dbp = mysql_query($sql_query);
		if (mysql_num_rows($dbp)) {
			$usersearch = "AND (id = '";
			while ($tmp = mysql_fetch_array($dbp))
				$usersearch .= substr($tmp['id'], 0, 5)."' OR id = '";
			$usersearch .= "0') ";
		}
	}
	// if searchin == all OR domain, search domain table.
	unset($domainsearch);
	$i = 0;
	if ($data['searchin'] == 'all' OR $data['searchin'] == 'domain' OR $data['searchin'] == 'id') {
		$sql_query = "SELECT DISTINCT(owner) AS owner FROM domains WHERE (ip LIKE '%".$data['search']."%' OR host LIKE '%".
				$data['search']."%' OR domain LIKE '%".$data['search']."%' OR aliases LIKE '%".$data['search']."%' OR id LIKE '%".$data['search']."') ";
		$dbp = mysql_query($sql_query);
		if (mysql_num_rows($dbp)) {
			if ($usersearch)
				$domainsearch = " OR ";
			else
				$domainsearch = " AND ";
			$domainsearch .= "(id = '";
			while ($tmp = mysql_fetch_array($dbp))
				$domainsearch .= substr($tmp['owner'], 0, 5)."' OR id = '";
			$domainsearch .= "0') ";
		}
	}
	
	// prepare sql command
	$sql_query = "SELECT * FROM resellers WHERE 1 ";
	
	// add usersearch & domain if they exist..
	$sql_query .= $usersearch.$domainsearch;
	
	if ($data['searchin'] == 'all' AND ($usersearch OR $domainsearch))
		$sql_query .= " OR ";
	else
		$sql_query .= " AND ";
	if ($data['searchin'] != 'all' AND $data['searchin'] != 'username'  AND $data['searchin'] != 'domain')
		$sql_query .= $data['searchin']." LIKE '%".$data['search']."%' ";
	elseif ($data['searchin'] == 'all') {
		$sql_query .= "(ip LIKE '%".$data['search']."%' OR name LIKE '%".
				$data['search']."%' OR email LIKE '%".$data['search'].
				"%' OR id LIKE '%".$data['search']."%') ";
	}
	else
		$sql_query .= "1";
		
	$sql_query .= " ORDER BY name";
}
else 	// Else get reseller list
	$sql_query = "SELECT * FROM resellers ORDER BY name";

$dbp = mysql_query($sql_query);
$numrows = mysql_num_rows($dbp);

// set limits:
$data['showrows'] = intval($data['showrows']);
if ($previous) {
	if (($currentrow - $data['showrows']) > 0)
		$currentrow = $currentrow - $data['showrows'];
	else
		$currentrow = 0;
}
if ($next)
	$currentrow = $currentrow + $data['oldrows'];

if (!$currentrow)
	$currentrow = 0;
if (!$data['showrows'])
	$data['showrows'] = $data['oldrows'] = 25;
	
// if there is more than 25 rows, redo the query with limits.
if ($numrows > 25)
	$dbp = mysql_query($sql_query." LIMIT $currentrow,".$data['showrows']);

if (!$numrows AND $search != 'true') 
	echo $T['no resellers'];
else {
	//if more than 1 reseller, display search 
	if ($numrows > 1 OR $search == 'true') {
		unset($chk_in);
		unset($chk_show);
		unset($chk_order);
		$chk_in[$data['searchin']] = ' selected';
		$chk_show[$data['show']] = ' selected';
		$chk_order[$data['order']] = ' selected';
		?>

<div align="center">
<form action="<?=$current_url;?>" method="post" name="webcp2" onSubmit="submitonce(this);">
<input type="hidden" name="search" value="true">
<table border="0" cellpadding="0" cellspacing="0" summary="">
	<tr>
		<td class="tblbg">
<table border="0" cellpadding="0" cellspacing="1" summary="">
	<tr>
		<td class="row1">
<table border="0" cellspacing="1" summary="">
	<tr>
		<td class="small"><?=$T['Search'];?></td>
		<td><input type="text" name="data[search]" size="15" maxlength="256" value="<?=$data['search'];?>" class="small"></td>
		<td class="small"><?=$T['in'];?></td>
		<td><select name="data[searchin]" class="small">
	      	<option value="all"<?=$chk_in['all'];?>> <?=$T['All'];?></option>
	      	<option value="name"<?=$chk_in['host'];?>> <?=$T['Name'];?></option>
		<option value="ip"<?=$chk_in['ip'];?>> <?=$T['IP Address'];?></option>
		<option value="email"<?=$chk_in['email'];?>> <?=$T['Email'];?></option>
		<option value="username"<?=$chk_in['username'];?>> <?=$T['Username'];?></option>
		<option value="domain"<?=$chk_in['domain'];?>> <?=$T['Domain Name'];?></option>
	      	<option value="id"<?=$chk_in['id'];?>> <?=$T['ID Number'];?></option>
	      </select>
      	</td>
		<td class="small"><?=$T['display'];?></td>
		<td><select name="data[show]" class="small">
	      	<option value="brief"<?=$chk_show['brief'];?>> <?=$T['Brief'];?></option>
	      	<option value="detailed"<?=$chk_show['detailed'];?>> <?=$T['Detailed'];?></option>
	      	<option value="editable"<?=$chk_show['editable'];?>> <?=$T['Editable'];?></option>
	      </select>
      </td>
      <td><input type="submit" value="<?=$T['Search'];?>" class="small"></td>
	</tr>
</table></td>
	</tr>
</table></td>
	</tr>
</table>
<?
if (!$numrows AND $search == 'true')
	echo $T['no results'];
?>
</div>
</form><br>
	<? } ?>

<div align="center">
<table border="0" cellpadding="0" cellspacing="0"><tr><td>
<? if ($numrows > 25) { ?>
<form action="<?=$current_url;?>" method="post" name="webcp3" onSubmit="submitonce(this);">
<div align="right">
<?=$T['Show'];?>
&nbsp;
<? if ($search == 'true') { ?>
<input type="hidden" name="data[search]" value="<?=addslashes($data['search']);?>">
<input type="hidden" name="data[searchin]" value="<?=addslashes($data['searchin']);?>">
<input type="hidden" name="data[order]" value="<?=addslashes($data['order']);?>">
<input type="hidden" name="data[show]" value="<?=addslashes($data['show']);?>">
<input type="hidden" name="search" value="true">
<? }
if ($currentrow) 
	echo '<input type="submit" name="previous" value="'.$T['Previous'].'" class="small">';
$chk_showr[$data['showrows']] = ' selected';
?>
<select name="data[showrows]" class="small">
      	<option value=25<?=$chk_showr[25];?>> 25</option>
      	<option value=50<?=$chk_showr[50];?>> 50</option>
      	<option value=100<?=$chk_showr[100];?>> 100</option>
      	<option value=500<?=$chk_showr[500];?>> 500</option>
</select>
<?
if (($currentrow + $data['showrows']) < $numrows)
	echo '<input type="submit" name="next" value="'.$T['Next'].'" class="small">';
echo '<input type="hidden" name="currentrow" value="'.$currentrow.'">';
echo '<input type="hidden" name="data[oldrows]" value="'.$data['showrows'].'">';
?>
&nbsp;&nbsp;
<? echo $T['Total Records'].($currentrow+1)."-".($currentrow+$data['showrows'])." / ".$numrows; ?>
</div>
</form>
<? } ?>
<form action="<?=$current_url;?>" method="post" name="webcp4" onSubmit="submitonce(this);">
<table border="0" cellspacing="1">
<?
$i = 0;
// Get reseller list
while ($rlist = mysql_fetch_array($dbp)) {
	// select cell bg color
	($i++ % 2) ? ($cell = "row1") : ($cell = "row2");
	
	// if the current reseller is suspended, put no bg color
	if ($rlist['hold'] == "true")
		$cell = "suspend";
	// Get number of allocated domains for current reseller
	$num = fetchdata("domains","total",$rlist['id']);
	?>
	<tr>
		<td class="<?=$cell;?>" width="10"><input type="checkbox" name="rid[]" value="<?=$rlist['id'];?>"></td>
		<td class="<?=$cell;?>" width="500">
		<b><a href="./?cp=reseller&number=<?=$rlist['id'];?>" target='_top'><?=$rlist['name'];?></a></b>
		&nbsp;
		<?
		// ** BRIEF
		if ($data['show'] == 'brief') { ?>
			( <? echo $num['domains']."/".$rlist['domains']." ".$T['Domains Used'];?> )
			<? }
			// ** DETAILED
			elseif ($data['show'] == 'detailed') { ?>
			<br><div class="small"><?
			
			echo $T['Email'].": <i><a href='mailto:".$rlist['email']."'>".$rlist['email']."</a></i><br>\n";
			$tmp = fetchdata("hd","alloc",$rlist['id']);
			echo $T['HD Quota'].": <i>".$tmp['hd']." / ".$rlist['hd']." ".$T['mb']." (".(round($tmp['hd'] / $rlist['hd'] * 100,2))."%)</i><br>\n";
			$tmp = fetchdata("transfer","total",$rlist['id']);
			echo $T['Data Transfer'].": <i>".round($tmp['transfer'],2)." / ".$rlist['transfer']." ".$T['gb']." (".(round($tmp['transfer'] / $rlist['transfer'] * 100,2))."%)</i><br>\n";
			$tmp = fetchdata("users","total",$rlist['id']);
			echo $T['Num Users'].": <i>".$tmp['users']." / ".$rlist['users']." (".(round($tmp['users'] / $rlist['users'] * 100,2))."%)</i><br>\n";
			$tmp = fetchdata("domains","total",$rlist['id']);
			echo $T['Num Domains'].": <i>".$tmp['domains']." / ".$rlist['domains']." (".(round($tmp['domains'] / $rlist['domains'] * 100,2))."%)</i><br>\n";
			
			// show domains & sub/pointers
			if ($data['searchin'] == 'domain' OR $data['searchin'] == 'all') {
				$dbp1 = mysql_query("SELECT id,host,domain FROM domains WHERE (ip LIKE '%".$data['search']."%' OR host LIKE '%".$data['search']."%' OR domain LIKE '%".$data['search']."%' OR aliases LIKE '%".$data['search']."%' OR id LIKE '%".$data['search']."') AND owner=".$rlist['id']." ORDER BY domain");
				if (mysql_num_rows($dbp1)) {
					echo $T['Domains'].": <br>\n";
					while ($tmp = mysql_fetch_array($dbp1)) {
						echo "- <a href='./?cp=domain&url=useradmin&number=".$tmp['id']."' target='_top'>".$tmp['host'].".".$tmp['domain']."</a><br>\n";
						
						// sub-domains
						echo "<i>";
						$dbp3 = mysql_query("SELECT id,host,domain FROM domains WHERE type = 'subdomain' AND owner = ".$tmp['id']);
						if (mysql_num_rows($dbp3)) {
							echo "&nbsp;&nbsp;&nbsp;&nbsp;".$T['Subdomains'].":<br>";
							while ($tmp3 = mysql_fetch_array($dbp3))
								echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./?cp=domain&url=subpointer&number=".$tmp['id']."&domid=".$tmp3['id']."' target='_top'>".$tmp3['host'].".".$tmp3['domain']."</a><br>\n";
						}
						
						// domain pointers
						$dbp3 = mysql_query("SELECT id,host,domain,path FROM domains WHERE type = 'pointer' AND owner = ".$tmp['id']);
						if (mysql_num_rows($dbp3)) {
							echo "&nbsp;&nbsp;".$T['Domain Pointers'].":<br>";
							while ($tmp3 = mysql_fetch_array($dbp3)) {
								$root = trim(str_replace($cfg['webdir']."/".$tmp['id'],"",$tmp3['path']));
								echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='./?cp=domain&url=subpointer&number=".$tmp['id']."&domid=".$tmp3['id']."' target='_top'>".$tmp3['host'].".".$tmp3['domain']."</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;$root<br>\n";
							}
						}
						echo "</i>\n";
					}
				}
			}
			if ($data['searchin'] == 'username' OR $data['searchin'] == 'all') {
				$dbp2 = mysql_query("SELECT username,id FROM users WHERE username LIKE '%".$data['search']."%' AND (id >= ".$rlist['id']."10000 AND id <= ".$rlist['id']."99999) ORDER BY username");
				if (mysql_num_rows($dbp2)) {
					echo $T['Users'].": <i>";
					while ($tmp2 = mysql_fetch_array($dbp2))
						echo "<a href='./?cp=personal&url=userset&number=".$tmp2['id']."&user=".$tmp2['username']."' target='_top'>".$tmp2['username']."</a> . ";
					echo "</i>";
				}
			}
		// ** EDITABLE
		} elseif ($data['show'] == 'editable') {?>
			<br><div class="small"><br>
			<table border="0" cellpadding="0" cellspacing="1">
			<tr>
			<td class="small">
			<table border="0" cellpadding="0" summary="">
			<tr><td class="small"><div class='small'><input type="text" name="data[<?=$rlist['id'];?>][name]" size="25" maxlength="255" value="<?=$rlist['name'];?>"></td>
			<td class="small"><nobr>.
				<?
				if (strstr($cfg['sslang'],","))
					$sslang = explode(",",$cfg['sslang']);
				else
					$sslang[0] = $cfg['sslang'];
				
				// get reseller serverside
				$tmpdata = fetchdata('serverside','reseller',$rlist['id']);
				$j = 0;
				while ($sslang[$j]) {
					$tmp = trim($sslang[$j]);
					
					unset($check);
					$check[$tmpdata['serverside'][$tmp]] = ' checked';
					
					echo "<tr><td><div class='small'>&nbsp;".$T['ss'][$tmp]."&nbsp;</div></td><td class='small'><nobr>\n";
					
					echo '&nbsp;<input type="radio" name="data['.$rlist['id'].'][serverside]['.$tmp.']" value="on"'.$check['on'].'>'.$T['on'];
					echo '&nbsp;<input type="radio" name="data['.$rlist['id'].'][serverside]['.$tmp.']" value="off"'.$check['off'].'>'.$T['off'];
					echo "\n</nobr></td></tr>\n";
					++$j;
				}
			?></table></nobr></td>
			<td class="small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td class="small" valign="bottom"><table border="0" cellpadding="0" cellspacing="1">
			<tr>
			<td class="small"><nobr>&nbsp;<?=$T['Num Domains'];?>&nbsp;</nobr></td>
			<td class="small">&nbsp;<input type="text" name="data[<?=$rlist['id'];?>][domains]" size="5" maxlength="255" value="<?=$rlist['domains'];?>">&nbsp;</td>
			</tr>
			<tr>
			<td class="small"><nobr>&nbsp;<?=$T['HD Quota'];?>&nbsp;</nobr></td>
			<td class="small"><nobr>&nbsp;<input type="text" name="data[<?=$rlist['id'];?>][hd]" size="5" maxlength="255" value="<?=$rlist['hd'];?>"> <?=$T['mb'];?>&nbsp;</nobr></td>
			</tr>
			<tr>
			<td class="small"><nobr>&nbsp;<?=$T['Transfer Quota'];?>&nbsp;</nobr></td>
			<td class="small">&nbsp;<input type="text" name="data[<?=$drlist['id'];?>][transfer]" size="5" maxlength="255" value="<?=$rlist['transfer'];?>"> <?=$T['gb'];?>&nbsp;</td>
			</tr>
			<tr>
			<td class="small"><nobr>&nbsp;<?=$T['Num Users'];?>&nbsp;</nobr></td>
			<td class="small">&nbsp;<input type="text" name="data[<?=$rlist['id'];?>][users]" size="5" maxlength="255" value="<?=$rlist['users'];?>">&nbsp;</td>
			</tr>
			</table></td>
			</tr></table>
		<? } ?>
		&nbsp;</td>
		<td class="<?=$cell;?>" width="50"><nobr>&nbsp;
		<? // select suspend or unsuspend icon/link
		if ($rlist['hold'] == "true" OR $rlist['action'] == "suspend") { ?>
		<a href="<?=$current_url;?>&action=unsuspend&confirm=true&rid=<?=$rlist['id'];?>"><img src="icon/unsuspend.gif" border="0" width="16" height="16" alt="Unsuspend"></a><? } else { ?>
		<a href="<?=$current_url;?>&action=suspend&rid=<?=$rlist['id'];?>"><img src="icon/suspend.gif" border="0" width="16" height="16" alt="Suspend"></a><? } ?>
		<a href="<?=$current_url;?>&action=remove&rid=<?=$rlist['id'];?>"><img src="icon/remove.gif" border="0" width="15" height="15" alt="Remove"></a></nobr></td>
	</tr>
	<? } ?>
</table><br><?
if ($numrows > 1) {
	if ($search == "true") { ?>
	<input type="hidden" name="search" value="true">
	<input type="hidden" name="data[search]" value="<?=$data['search'];?>">
	<input type="hidden" name="data[searchin]" value="<?=$data['searchin'];?>">
	<input type="hidden" name="data[show]" value="<?=$data['show'];?>">
	<? } ?>
<div align="right">
<select name="action">
	<option value=""> <?=$T['Select Action'];?></option>
	<? if ($data['show'] == 'editable') { ?><option value="update"> <?=$T['Modify Resellers'];?></option><? } ?>
	<option value="suspend"> <?=$T['Suspend Resellers'];?></option>
	<option value="unsuspend"> <?=$T['Reactivate Resellers'];?></option>
	<option value="remove"> <?=$T['Remove Resellers'];?></option>
</select>
&nbsp;
<input type="submit" value="<?=$T['Apply'];?>"></div><? } ?>
</td></tr></table>
</form>
</div>
<? } ?>
Return current item: web-cp - Web Hosting Control Panel