Location: PHPKode > projects > web-cp - Web Hosting Control Panel > webcp/web/server/logs.phps
<?
if (is_numeric($start)) {
	$start = intval($start);
} else {
	$start = 0;
}

if ($action == "remove" && $userdata['type'] != 'demo') {
	if (is_array($lid)) {
		for ($i=0; $i<sizeOf($lid); $i++) {
			$SQL = "DELETE FROM log WHERE UNIX_TIMESTAMP(time) = '".$lid[$i]."'";
			mysql_query($SQL);
		}
	} else {
		$SQL = "DELETE FROM log WHERE UNIX_TIMESTAMP(time) = '".$lid."'";
		mysql_query($SQL);
	}
} elseif ($action == "remove") {
	echo "<center>".$T['err']['demo user']."</center>";
}

// If $search, do it; create appropriate SQL query.
if ($search == 'true') {
	// remove spaces
	foreach($data AS $key=>$val)
		$data[$key] = trim($val);
	
	// prepare sql command
	$sql_query = " log WHERE ";
	if ($data['searchin'] != 'all') {
		$sql_query .= $data['searchin']." LIKE '%".$data['search']."%' ";
	} else {
		$sql_query .= "(error_level LIKE '%".$data['search']."%' OR id LIKE '%".
				$data['search']."%' OR extra LIKE '%".$data['search'].
				"%' OR log_msg LIKE '%".$data['search']."%' OR remote_ip LIKE '%".$data['search']."%' OR time LIKE '%".$data['search']."%') ";
	}
	if ($data['order'] != "") {
		$sql_query .= "ORDER BY ".$data['order'];
	} else {
		$sql_query .= "ORDER BY UNIX_TIMESTAMP(time) desc";
	}
} else {	// Else get log list
	$sql_query = " log ORDER BY UNIX_TIMESTAMP(time) desc";
}

$dbcount = mysql_query("SELECT count(id) as RecordCount FROM ".$sql_query);
$row = mysql_fetch_array($dbcount);

$sql_query .= " LIMIT $start, 25";
$dbp = mysql_query("SELECT UNIX_TIMESTAMP(time) as time, id, error_level, log_msg, extra, remote_ip FROM ".$sql_query);

// check for log entries, else display message
$numrows = mysql_num_rows($dbp);
?>
<div align="center">
<?
if (!$numrows AND $search != 'true') {
	echo $T['No log entries.'];
} else {
	//if more than 1 log entry, 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';
		?>

<form action="<?=$current_url;?>" method="post" name="webcp2" onSubmit="submitonce(this);">
<input type="hidden" name="search" value="true">
<table border="0" cellpadding="0" cellspacing="1" 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="error_level"<?=$chk_in['error_level'];?>> <?=$T['Error Level'];?></option>
	      	<option value="id"<?=$chk_in['id'];?>> <?=$T['Domain ID'];?></option>
	      	<option value="log_msg"<?=$chk_in['log_msg'];?>> <?=$T['Log Message'];?></option>
	      	<option value="extra"<?=$chk_in['extra'];?>> <?=$T['Additional Info'];?></option>
	      	<option value="remote_ip"<?=$chk_in['remote_ip'];?>> <?=$T['Remote IP Address'];?></option>
	      	<option value="time"<?=$chk_in['time'];?>> <?=$T['Time'];?></option>
	      </select></td>
	        <td class="small"><?=$T['order by'];?></td>
		<td><select name="data[order]" class="small">
	      	<option value=""<?=$chk_order['default'];?>> <?=$T['default'];?></option>
	      	<option value="time"<?=$chk_order['time'];?>> <?=$T['Time'];?></option>
	      	<option value="log_msg"<?=$chk_order['log_msg'];?>> <?=$T['Log Message'];?></option>
	      	<option value="remote_ip"<?=$chk_order['remote_ip'];?>> <?=$T['Remote IP Address'];?></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>
	      </select></td>
		<td><input type="submit" value="<?=$T['Search'];?>" class="small"></td>
	</tr>
</table></td>
	</tr>
</table></td>
	</tr>
</table>
</div>
</form>
	<? }
} 
?>
<div align="center">
<?
if (!$numrows AND $search == 'true') {
	echo '<br>'.$T['no results'];
} else {
	echo "<div align=center>".($start+1).$T[' through '].((($start+25) > $row["RecordCount"]) ? $row["RecordCount"] : ($start+25)).$T[' of '].$row["RecordCount"].$T[' matching records']."</div>";
}
?>

<form action="<?=$current_url;?>" method="post" name="webcp3" onSubmit="submitonce(this);">
<table border="0" cellpadding="0" cellspacing="1" width=650><tr><td>
<table border="0" cellspacing="1" width=650>
<?
// start displaying logs

$i = 0;
while (($loglist = mysql_fetch_array($dbp))) {
	foreach($loglist AS $key=>$val)
		$loglist[$key] = trim($val);
	
	// select cell bg color
	($i++ % 2) ? ($cell = "row1") : ($cell = "row2");

	?>
	<tr>
		<? if ($numrows > 1) { ?><td class="<?=$cell;?>" width="15"><input type="checkbox" name="lid[]" value="<?=$loglist['time'];?>"></td><? } ?>
		<td class="<?=$cell;?>">
		<b><?=$loglist['id'];?></b>
		</td>
		<td class="<?=$cell;?>">
		<b><?=$loglist['error_level'];?></b>
		</td>
		<td class="<?=$cell;?>">
		<? if ($data['show'] == 'detailed') { 
			echo "<nobr>".date("n/j/Y g:i:sa", $loglist['time'])."</nobr>";
		} else {
			echo "<nobr>".date("n/j g:ia", $loglist['time'])."</nobr>";
		} ?>
		</td>
		<td class="<?=$cell;?>">
		<nobr><?=$loglist['log_msg'];?></nobr>
		</td>
		
		<? if ($data['show'] == 'detailed') { ?>
		<td class="<?=$cell;?>">
		<nobr><?=$loglist['extra'];?></nobr>
		</td>
		<td class="<?=$cell;?>">
		<nobr><?=($userdata['type'] != 'demo') ? $loglist['remote_ip'] : "xx.xx.xx.xx";?></nobr>
		</td>
		<? } ?>
		<td class="<?=$cell;?>"><nobr>
		<a href="<?=$current_url;?>&action=remove&lid=<?=$loglist['time'];?>"><img src="icon/remove.gif" border="0" width="15" height="15" alt="Remove"></a>
		</nobr></td>
	</tr>
<? } ?>
	<tr>
		<td align=left>
			<? if ($start > 0) { ?>
				<a href="<?=$current_url;?>&search=<?=$search;?>&data[search]=<?=$data['search'];?>&data[searchin]=<?=$data['searchin'];?>&data[order]=<?=$data['order'];?>&data[show]=<?=$data['show'];?>&start=<?=(($start - 25) >= 0) ? ($start - 25) : "0";?>"><?=$T['Prev'];?></a>
			<? } ?>
		</td>
		<td colspan=8 align=right>
			<? if ($i > 24) { ?>
				<a href="<?=$current_url;?>&search=<?=$search;?>&data[search]=<?=$data['search'];?>&data[searchin]=<?=$data['searchin'];?>&data[order]=<?=$data['order'];?>&data[show]=<?=$data['show'];?>&start=<?=$start + 25;?>"><?=$T['Next'];?></a>
			<? } ?>
		</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" class="small">
	<option value=""> <?=$T['Select Action'];?></option>
	<option value="remove"> <?=$T['Remove Log Entries'];?></option>
</select>
&nbsp;
<input  class="small" type="submit" value="<?=$T['Apply'];?>"></div>
<? } ?>
</td></tr></table>
</form>
</div>

Return current item: web-cp - Web Hosting Control Panel