Location: PHPKode > scripts > php-ftpmonitor > list.php
<?php

function chkftp($server,$uname,$pass,$port){

$conn_id = ftp_connect($server,$port); 

$login_result = ftp_login($conn_id, $uname, $pass); 

if (!$conn_id) { 
       return "Could not connect";
       exit; 
   } if(!$login_result){
       return "Could not login";
   }
return "login successful";	
}



function setops($fid){
 /*
	$htmlv = "<form action='do.php' method='get'>";
	$htmlv.= "<select name='opt'>";
	$htmlv.= "<option value=1>-</option>";
	$htmlv.= "<option value=2>Edit</option>";
	$htmlv.= "<option value=3>Remove</option>";
	$htmlv.= "</select>";
	$htmlv.= "<input name=entry type=hidden value=".$fid.">";
	$htmlv.= "</form>";
	
 */
   $htmlv = "<input type=checkbox name=frows[] value=$fid>";
	
	return $htmlv;
	
}


$link = mysql_connect($db_server, $db_user, $db_pass)
   or die("Could not connect to mysql server ".mysql_error());

mysql_select_db($ftpmonitor_db) or die("Could not select database ".mysql_error());

if(isset($doaction) && $doaction='remove'){
	$selected_rows = isset($_REQUEST['frows'])?$_REQUEST['frows']:0;
	
	switch(is_array($selected_rows)){
			case 1:
			foreach($selected_rows as $rw){
				$delete_query="DELETE from $ftpmonitor_tbl WHERE ftpid=$rw";
				$rs = mysql_query($delete_query)? 1 : 0;
				if(!isset($rs)){
					display_message("A problem was encountered Removing server $row",2);
					return;
					}
				else{
					mysql_free_result($rs);	
					}
				if($rw==$selected_rows[count($selected_rows)-1]){
						display_message("successfully Removed ".count($selected_rows)." server(s)",0);
						}
				}
				break;
			 case 0:
			 display_message("Unexpected error in form data submitted",2);
			
			}
	
	}



//get list of ftp servers
$where_clause = isset($where_clause)?substr($where_clause,0,-4):"";
$ftplist = "select * from $ftpmonitor_tbl $where_clause";
$rs = mysql_query($ftplist);
$total = mysql_num_rows($rs);
$pages = ceil($total/$row_limit);
mysql_free_result($rs);

$page = isset($_REQUEST['page'])? $_REQUEST['page']-1: 0;
	if(!is_numeric($page) || $page > $pages){
	   $page = 0 ;
       }
     
//echo gettype($page);
$start = ($page) * $row_limit;	
$getlist = "select ftpid,ftp_name,ftp_url,ftp_username,ftp_password,ftp_uptime from $ftpmonitor_tbl $where_clause ";
$getlist.= "LIMIT $start, $row_limit";
$rs = mysql_query($getlist) or die($getlist."/".mysql_error($link));	
if(isset($_REQUEST['m']) && $_REQUEST['m']==1 && isset($_REQUEST['sname'])){
		display_message("Server '".$_REQUEST['sname']."' Was Successfully updated",0);
		}
if(isset($_REQUEST['m']) && $_REQUEST['m']==2 && isset($_REQUEST['sname'])){
		display_message("Server '".$_REQUEST['sname']."' Was Successfully added to server list",0);
		}
if(isset($_REQUEST['do']) && $_REQUEST['do']='search'){
		display_message("Search Results.........found $total matching servers",0);
		}

	
echo "<form id='frmRows' action='index.php' method='post'>";
//echo "<input type=hidden name=action value=''>"; //may confuse javascript..theoretically
echo "<table cellspacing=0 cellpadding=3 id=serverlist>\n";
echo "\t\t<tr>\n";
echo "\t\t<td class=header>Id</td>\n";
echo "\t\t<td class=header>Name</td>\n";
echo "\t\t<td class=header>Url</td>\n";
echo "\t\t<td class=header>Username</td>\n";
echo "\t\t<td class=header>Uptime</td>\n";
echo "\t\t<td class=header>Result</td>\n";
echo "\t\t<td class=header>Select</td>\n";
echo "\t\t</tr>\n";
while ($line = mysql_fetch_array($rs, MYSQL_ASSOC)) {
	
	$color_start ++;
	if($color_start>1){
		$color_start = 0;
		}
   echo "\t<tr>\n";
    //output ftp list in nicely formated cells
    echo "\t\t<td class=$colors[$color_start]>$line[ftpid]</td>\n";
	echo "\t\t<td class=$colors[$color_start]>$line[ftp_name]</td>\n";
	echo "\t\t<td class=$colors[$color_start]>$line[ftp_url]</td>\n";
	echo "\t\t<td class=$colors[$color_start]>$line[ftp_username]</td>\n";
	echo "\t\t<td class=$colors[$color_start]>$line[ftp_uptime]</td>\n";
       
   echo "\t\t<td class=$colors[$color_start] >".chkftp($line[ftp_url],$line[ftp_username],$line[ftp_password],$line[ftp_port])."</td>\n";
   echo "\t\t<td class=$colors[$color_start] >".setops($line[ftpid])."</td>\n";
   echo "\t</tr>\n";
  
}
  echo "\t\t<tr>\n";
  echo "\t\t<td colspan=5>\n";
  $s_string = isset($s_string)?$s_string:"";
for($x=0;$x<$pages;$x++){
	$adjust = $x+1;
	$pg = $page + 1;
	switch($adjust){
		case $pg:
		echo "<font color='red'>$adjust</font>&nbsp;&nbsp";
		break;
		default:
		printf("<a href='index.php?section=ls&page=%s%s'>%s</a>&nbsp;&nbsp;",$adjust,$s_string,$adjust);
		}
	}
    echo "\t\t</td>\n";
    echo "\t\t<td colspan=2 align=right>\n";
	echo "<select onChange='doSubmit(this.value)' name='doaction'>";
	echo "<option value=0>With Selected</option>";
	echo "<option value=edit>Edit</option>";
	echo "<option value=remove>Remove</option>";
	echo "</select>";
	echo "</form>";
	echo "\t\t</td>\n";
	echo "\t\t</tr>\n";
 echo "</table>\n";
// Free resultset
mysql_free_result($rs);

// Closing connection
mysql_close($link);

?>
Return current item: php-ftpmonitor