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

	}
	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['domain '.$action]."<b>".$result."</b><br>\n";
}
elseif ($action AND $confirm) {
	// Initialize
	unset($data);
	unset($error);
	
	// check if its a GET or POST (i.e is $domid a string or an array?)
	if (!is_array($domid)) { // single action from GET
		// hardcode data
		$data['owner'] = $resellerdata['id'];
		$data['id'] = $domid;
		
		$tmp = fetchdata("host,domain","domain",$domid);
		$tmp = $tmp['host'].'.'.$tmp['domain'];
		
		$error = domain($action,$data,$return);
		
	}
	elseif (is_array($domid)) { // multiple domain action.
		unset($tmpid);
		while (list($key, $val) = each($domid)) {
			$tmp = fetchdata("host,domain","domain",$val);
			$tmpid[$key] = $tmp['host'].'.'.$tmp['domain'];
		}
		$tmp = implode(", ",$tmpid);
		reset($domid);
		
		// hardcode data
		$data['owner'] = $resellerdata['id'];

		do {
			$data['id'] = trim(current($domid));
			$tmperr = domain($action,$data,$return);
			
			// Trap errors and 'add' them up.
			if ($tmperr) {
				if ($error) $error = array_merge($error,$tmperr);
				else $error = $tmperr;
			}
		} while(next($domid));
		
	}
	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['domain '.$action]."<b>".$tmp."</b><br>\n";
}
// ask confirmation for suspend - unsuspend - remove
elseif ($action AND $domid AND !$confirm) {
	if (is_array($domid)) {
		reset($domid);
		unset($tmpid);
		while (list($key, $val) = each($domid)) {
			$tmp = fetchdata("host,domain","domain",$val);
			$tmpid[$key] = $tmp['host'].'.'.$tmp['domain'];
		}
		$tmp = implode(", ",$tmpid);
	}
	else {
		$tmp = fetchdata("host,domain","domain",$domid);
		$tmp = $tmp['host'].'.'.$tmp['domain'];
	}
?>
<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($domid)) {
	reset($domid);
	while (list($key, $val) = each($domid))
		echo "<input type='hidden' name='domid[$key]' value='$val'>\n";
}
else echo '<input type="hidden" name="domid" value="'.$domid.'">';
?>
<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']."%' OR name LIKE '%".$data['search']."%'";
		$dbp = mysql_query($sql_query);
		if (mysql_num_rows($dbp)) {
			$usersearch = "OR id = '";
			while ($tmp = mysql_fetch_array($dbp))
				$usersearch .= $tmp['id']."' OR id = '";
			$usersearch .= "0'";
		}
	}
	// if searchin == all, host or domain, search through subdomains & pointers as well.
	if ($data['searchin'] == 'all') {
		$sql_query = "SELECT DISTINCT(owner) AS owner FROM domains WHERE type != 'domain' ". 
				"AND (ip LIKE '%".$data['search']."%' OR host LIKE '%".
				$data['search']."%' OR domain LIKE '%".$data['search'].
				"%' OR email LIKE '%".$data['search']."%' OR aliases LIKE '%".
				$data['search']."%' OR id LIKE '%".$data['search']."%')";
		$dbp = mysql_query($sql_query);
		if (mysql_num_rows($dbp)) {
			$subsearch = "OR id = '";
			while ($tmp = mysql_fetch_array($dbp))
				$subsearch .= $tmp['owner']."' OR id = '";
			$subsearch .= "0'";
		}
	}

	// prepare sql command
	$sql_query = "SELECT * FROM domains WHERE owner=".$resellerdata['id']." AND type='domain' AND action != 'remove' ";
	
	if ($data['searchin'] == 'all') {
		$sql_query .= "AND (ip LIKE '%".$data['search']."%' OR host LIKE '%".
				$data['search']."%' OR domain LIKE '%".$data['search'].
				"%' OR email LIKE '%".$data['search']."%' OR aliases LIKE '%".
				$data['search']."%' OR id LIKE '%".$data['search']."%' $usersearch $subsearch) ";
	}
	elseif ($data['searchin'] == 'username')
		$sql_query .= "AND (id = 0 $usersearch)";
	else
		$sql_query .= "AND ".$data['searchin']." LIKE '%".$data['search']."%' ";
	
	if ($data['order'] == 'domain' OR $data['order'] == 'ip' OR $data['order'] == 'suspended')
		$sql_query .= "ORDER BY ".$data['order'].",priority,domain";
	elseif ($data['order'] == 'hdusage')
		$sql_query .= "ORDER BY hd_used/hd DESC,priority,domain";
	elseif ($data['order'] == 'tfxusage')
		$sql_query .= "ORDER BY transfer_used/transfer DESC,priority,domain";
	else
		$sql_query .= " ORDER BY priority,domain";
}
else 	// Else get domain list
	$sql_query = "SELECT * FROM domains WHERE owner=".$resellerdata['id']." AND type='domain' AND action != 'remove' ORDER BY priority,domain";

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

// set limits:
$data['showrows'] = intval($data['showrows']);

//by downsize
//15.03.2004 02:13 GMT -8
//apparently the javascript is not allowing for submit names to be sent to the
//server, therefore, using the registered global $previous will never be called
if ($previous && !$next) {
	if (($currentrow - $data['showrows']) > 0)
		$currentrow = $currentrow - $data['showrows'];
	else
		$currentrow = 0;
}

//by downsize
//15.03.2004 02:13 GMT -8
//apparently the javascript is not allowing for submit names to be sent to the
//server, therefore, using the registered global $next will never be called
if ($next && strcasecmp($next, "change") != 0 && !$previous){
	$currentrow = $currentrow + $data['oldrows'];
}elseif(strcasecmp($next, "change") == 0){
	//if the user changes the number, increment to that number from current row
	//as long as it is not over the total number of rows
	if(($currentrow + $data['showrows']) < $numrows){
		$currentrow = $currentrow + $data['showrows'];
	}
}

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 domains'];
else {
	//if more than 1 domain, 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="ip"<?=$chk_in['ip'];?>> <?=$T['IP Address'];?></option>
	      	<option value="host"<?=$chk_in['host'];?>> <?=$T['Hostname'];?></option>
	      	<option value="domain"<?=$chk_in['domain'];?>> <?=$T['Domain Name'];?></option>
	      	<option value="aliases"<?=$chk_in['aliases'];?>> <?=$T['Hostname Aliases'];?></option>
		<option value="email"<?=$chk_in['email'];?>> <?=$T['Email'];?></option>
		<option value="username"<?=$chk_in['username'];?>> <?=$T['Username'];?></option>
	      	<option value="id"<?=$chk_in['id'];?>> <?=$T['Domain ID'];?></option>
	      </select>
	      <td class="small"><?=$T['order by'];?></td>
		<td><select name="data[order]" class="small">
	      	<option value="default"<?=$chk_order['default'];?>> <?=$T['default'];?></option>
	      	<option value="domain"<?=$chk_order['username'];?>> <?=$T['Domain Name'];?></option>
	      	<option value="ip"<?=$chk_order['name'];?>> <?=$T['IP Address'];?></option>
	      	<option value="suspended"<?=$chk_order['suspended'];?>> <?=$T['State'];?></option>
	      	<option value="hdusage"<?=$chk_order['hdusage'];?>> <?=$T['Hard Disk Usage'];?></option>
	      	<option value="tfxusage"<?=$chk_order['tfxusage'];?>> <?=$T['Transfer Usage'];?></option>
	      </select></td>
      	</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 '<br>'.$T['no results'];
?>
</div>
</form><br>
	<? } ?>


<div align="center">

<table border="0" cellpadding="0" cellspacing="0"><tr><td class="small">
<? if ($numrows > 25) { ?>
<!--
//by downsize
//15.03.2004 02:13 GMT -8
//apparently the javascript is not allowing for submit names to be sent to the
//server, therefore, using the registered global $next nor $previous will never be called
//for now, removing the submitonce javascript call
-->
 <!-- <form action="<?=$current_url;?>" method="post" name="webcp3" onSubmit="submitonce(this);"> -->
<form action="<?=$current_url;?>" method="post" name="webcp3">
<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">
<? }
//by downsize
//15.03.2004 02:13 GMT -8
//apparently the javascript is not allowing for submit names to be sent to the
//server, therefore, using the registered global $next will never be called
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>
<?
//by downsize
//15.03.2004 02:13 GMT -8
//apparently the javascript is not allowing for submit names to be sent to the
//server, therefore, using the registered global $next will never be called
if (($currentrow + $data['showrows']) < $numrows){
	echo '<input type="submit" name="next" value="'.$T['Next'].'" class="small">';
}else{
	//if there are not more rows to display than the selected 'showrows' at least put a submit button if
	//the user wants to go back to a small showrow number
	//need to add the text to the $T obj? array? - hard code for now
	echo '<input type="submit" name="next" value="Change" class="small">';
}

echo '<input type="hidden" name="currentrow" value="'.$currentrow.'">';
echo '<input type="hidden" name="data[oldrows]" value="'.$data['showrows'].'">';
?>
&nbsp;&nbsp;
<?
//by downsize
//15.03.2004 02:53 GMT -8
//the total records should display the last record when at the end
//eg: 51-68 / 68 and not 51-100 / 68
if(($currentrow+$data['showrows']) >= $numrows){
	echo $T['Total Records'].($currentrow+1)."-$numrows / ".$numrows;
}else{
	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 domain list
while ($domlist = mysql_fetch_array($dbp)) {
	// select cell bg color
	($i++ % 2) ? ($cell = "row1") : ($cell = "row2");
	
	// if the current domain is suspended, put no bg color
	if (($domlist['suspended'] == "true" AND $userlist['action'] != "unsuspend") OR $domlist['action'] == "suspend")
		$cell = "suspend";
	?>
	<tr>
		<? if ($numrows > 1) { ?><td class="<?=$cell;?>" width="10"><input type="checkbox" name="domid[]" value="<?=$domlist['id'];?>"></td><? } ?>
		<td class="<?=$cell;?>" width="500">
		<b><a href="./?cp=domain&url=useradmin&number=<?=$domlist['id'];?>" target='_top'><?=$domlist['host'].'.'.$domlist['domain'];?></a></b>
		&nbsp;
		(<?=$domlist['ip'];?>)
		&nbsp;
		<? if ($data['show'] == 'detailed') { ?>
		<br><div class="small"><?
		if (trim($domlist['aliases']))
			echo $T['Hostname Aliases'].": <i>".$domlist['aliases']."</i><br>\n";
		
		echo $T['Domain Contact'].": <i><a href='mailto:".$domlist['email']."'>".$domlist['email']."</a></i><br>\n";
		
		echo $T['Hard Disk Usage'].": <i>".$domlist['hd_used']." / ".$domlist['hd']." ".$T['mb']." (".(round($domlist['hd_used'] / $domlist['hd'] * 100,2))."%)</i><br>\n";
		
		$tmp = fetchdata("transfer","total",$domlist['id']);
		echo $T['Data Transfer'].": <i>".round($tmp['transfer'],2)." / ".$domlist['transfer']." ".$T['gb']." (".(round($tmp['transfer'] / $domlist['transfer'] * 100,2))."%)</i><br>\n";
		
		$dbp1 = mysql_query("SELECT username FROM users WHERE id = ".$domlist['id']." ORDER BY username");
		if (mysql_num_rows($dbp1)) {
			echo $T['Users'].": <i>";
			while ($tmp = mysql_fetch_array($dbp1))
				echo "<a href='./?cp=personal&url=userset&number=".$domlist['id']."&user=".$tmp['username']."' target='_top'>".$tmp['username']."</a> . ";
			echo "</i><br>\n";
		}
		
		$dbp1 = mysql_query("SELECT id,host,domain FROM domains WHERE type = 'subdomain' AND owner = ".$domlist['id']." ORDER BY host");
		if (mysql_num_rows($dbp1)) {
			echo $T['Subdomains'].": <i><br>";
			while ($tmp = mysql_fetch_array($dbp1))
				echo "- <a href='./?cp=domain&url=subpointer&number=".$domlist['id']."&domid=".$tmp['id']."' target='_top'>".$tmp['host'].".".$tmp['domain']."</a><br>\n";
			echo "</i><br>\n";
		}
		
		$dbp1 = mysql_query("SELECT id,host,domain,path FROM domains WHERE type = 'pointer' AND owner = ".$domlist['id']." ORDER BY host");
		if (mysql_num_rows($dbp1)) {
			echo $T['Domain Pointers'].": <i><br>";
			while ($tmp = mysql_fetch_array($dbp1)) {
				$root = trim(str_replace($cfg['webdir']."/".$domlist['id'],"",$tmp['path']));
				echo ". <a href='./?cp=domain&url=subpointer&number=".$domlist['id']."&domid=".$tmp['id']."' target='_top'>".$tmp['host'].".".$tmp['domain']."</a> &raquo; $root<br>\n";
			}
			echo "</i>\n";
		}
		?>
		</div>
		<? } 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[<?=$domlist['id'];?>][hostname]" size="6" maxlength="255" value="<?=$domlist['host'];?>"></td>
		<td class="small">.
		<input type="text" name="data[<?=$domlist['id'];?>][domain]" size="30" maxlength="255" value="<?=$domlist['domain'];?>"></td></tr>
			<?
			if (strstr($cfg['sslang'],","))
				$sslang = explode(",",$cfg['sslang']);
			else
				$sslang[0] = $cfg['sslang'];
			
			// get domain serverside
			$tmpdata = fetchdata('serverside','domain',$domlist['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'>\n";
				

				echo '&nbsp;<input type="radio" name="data['.$domlist['id'].'][serverside]['.$tmp.']" value="na"'.$check['na'].'>'.$T['na'];
				echo '&nbsp;<input type="radio" name="data['.$domlist['id'].'][serverside]['.$tmp.']" value="on"'.$check['on'].'>'.$T['on'];
				echo '&nbsp;<input type="radio" name="data['.$domlist['id'].'][serverside]['.$tmp.']" value="off"'.$check['off'].'>'.$T['off'];
				echo "\n</td></tr>\n";
				++$j;
			}
		?></table></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">&nbsp;<?=$T['HD Quota'];?>&nbsp;</td>
		<td class="small">&nbsp;<input type="text" name="data[<?=$domlist['id'];?>][hd]" size="5" maxlength="255" value="<?=$domlist['hd'];?>"> <?=$T['mb'];?>&nbsp;</td>
		</tr>
		<tr>
		<td class="small">&nbsp;<?=$T['Transfer Quota'];?>&nbsp;</td>
		<td class="small">&nbsp;<input type="text" name="data[<?=$domlist['id'];?>][transfer]" size="5" maxlength="255" value="<?=$domlist['transfer'];?>"> <?=$T['gb'];?>&nbsp;</td>
		</tr>
		<tr>
		<td class="small">&nbsp;<?=$T['Num Users'];?>&nbsp;</td>
		<td class="small">&nbsp;<input type="text" name="data[<?=$domlist['id'];?>][users]" size="5" maxlength="255" value="<?=$domlist['users'];?>">&nbsp;</td>
		</tr>
		</table></td>
		</tr></table>
		<? } ?></td>
		<td class="<?=$cell;?>" width="50"><nobr>&nbsp;
		<? // select suspend or unsuspend icon/link
		if ($cell == 'suspend') { ?>
		<a href="<?=$current_url;?>&action=unsuspend&confirm=true&domid=<?=$domlist['id'];?>"><img src="icon/unsuspend.gif" border="0" width="16" height="16" alt="Unsuspend"></a><? } else { ?>
		<a href="<?=$current_url;?>&action=suspend&domid=<?=$domlist['id'];?>"><img src="icon/suspend.gif" border="0" width="16" height="16" alt="Suspend"></a><? } ?>
		<a href="<?=$current_url;?>&action=remove&domid=<?=$domlist['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[order]" value="<?=$data['order'];?>">
	<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 Domains'];?></option><? } ?>
	<option value="suspend"> <?=$T['Suspend Domains'];?></option>
	<option value="unsuspend"> <?=$T['Reactivate Domains'];?></option>
	<option value="remove"> <?=$T['Remove Domains'];?></option>
</select>
&nbsp;
<input type="submit" value="<?=$T['Apply'];?>"></div><? } ?>
</td></tr></table>
</form>
</div>
<? } ?>
Return current item: web-cp - Web Hosting Control Panel