Location: PHPKode > scripts > Anope_php > anope_php/class.anope_php.php
<?php
/*

Class name: class.anope_php.php
Class description: grab and display anope irc service statistics
Class release date: 11-04-09
Class updated: 
Class site: www.freakcms.com
Class author: lee johnstone
Class contact: hide@address.com
Class license: 
http://www.freakcms.com 
http://creativecommons.org/licenses/by-sa/3.0/

*/
 class Anope_Connect {
/**
 * MySQL DB host
 *
 */
private $db_host = "";
/**
 * MySQL DB user
 *
 */
private $db_user = ""; 
/**
 * MySQL DB pass
 *
 */
private $db_password = "";
/**
 * MySQL DB name
 *
 */
private $db_name = "";
/**
 * irc server name
 *
 */
private $irc_serv = '';
/**
 * global html header
 *
 */

public $html_head = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Anope_php statistics version 1</title>
<link href="data/css.css" rel="stylesheet" type="text/css" />
</head>
<body>';
/**
 * global html footer
 *
 */
public $html_foot = '<p align="center">Powered by Anope_php 1.0<br/>by: <a target="_blank" href="http://www.freakcms.com">freakcms.com</a></p></body>
</html>';
/**
 * check if a mysql connection is open if so close it
 *
 */
private function CheckDb(){
if(!isset($this->g_link)){
	$this->g_link = false;
	}
}
/**
 * open the mysql database connection
 *
 */
private function OpenDb(){
if($this->g_link)
	return $this->g_link;
	$this->g_link = mysql_connect($this->db_host, $this->db_user, $this->db_password) or die('Could not connect to mysql server.' );
	mysql_select_db($this->db_name) or die('Could not select database "'.$this->db_name.'"');
	return $this->g_link;
}
/**
 * close the mysql database connection if its open
 *
 */
private function CloseDb(){
if($this->g_link!=false)
	mysql_close($this->g_link);
	$this->g_link = false;
}
/**
 * check if a feature/user is active or not
 *
 */
private function is_active($data){
if($data=='0'){
	$output = 'no';
	}else{
	$output = 'yes';}
	return $output;
}
/**
 * check if a feature/user is active or not
 *
 */
private function check_rows($data){
if(mysql_num_rows($data)==0) {
	$output .= ' no results ';
	}
	return $output;
}
/**
 * Count anope db data
 *
 */
public function Count_data($data, $extra){
	$this->CheckDb();
	if($extra =="active"){
	$sql = mysql_query("SELECT COUNT(*) FROM $data WHERE active='1'",$this->OpenDb()) or die('Error : ' . mysql_error());
	}else{
	$sql = mysql_query("SELECT COUNT(*) FROM $data",$this->OpenDb()) or die('Error : ' . mysql_error());
	}
while(list($Count) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= $Count; 
	$this->CloseDb();
	}
	return $output;
}
/**
 * check if a feature/user is active or not
 *
 */
public function GenList($type){
	$this->CheckDb();
if($type=="bots"){
	$output .= '<h1 class="title">'.$this->irc_serv.' BOTSERV Registered bots Lists</h1>';
	$sql = mysql_query("SELECT bs_id, nick, active FROM anope_bs_core",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $nick, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Name: <a href="index.php?bot='.$id.'">'.$nick.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="channels"){
	$output .= '<h1 class="title">'.$this->irc_serv.' CHANSERV Registered Channels Lists</h1>';
	$sql = mysql_query("SELECT ci_id, name, active FROM anope_cs_info",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $name, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Name: <a href="index.php?chn='.$id.'">'.$name.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="users"){
	$output .= '<h1 class="title">'.$this->irc_serv.' NICKSERV Registered User Lists</h1>';
	$sql = mysql_query("SELECT nc_id, display, active FROM anope_ns_core",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $display, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Name: <a href="index.php?usr='.$id.'">'.$display.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="badwords"){
	$output .= '<h1 class="title">'.$this->irc_serv.' CHANSERV Bad Words Lists</h1>';
	$sql = mysql_query("SELECT cw_id, word, active FROM anope_cs_badwords",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $word, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Word: <a href="index.php?badword='.$id.'">'.$word.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="akicks"){
	$output .= '<h1 class="title">'.$this->irc_serv.' CHANSERV AKicks Lists</h1>';
	$sql = mysql_query("SELECT ck_id, dmask, active FROM anope_cs_akicks",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $dmask, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>D Mask: <a href="index.php?akick='.$id.'">'.$dmask.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="chaccess"){
	$output .= '<h1 class="title">'.$this->irc_serv.' CHANSERV Access Lists</h1>';
	$sql = mysql_query("SELECT ca_id, display, active FROM anope_cs_access",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $display, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Access: <a href="index.php?chanaccess='.$id.'">'.$display.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="memos"){
	$output .= '<h1 class="title">'.$this->irc_serv.' MEMOSERV memos Lists</h1>';
	$sql = mysql_query("SELECT nm_id, sender, active FROM anope_ms_info",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $sender, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>memo: <a href="index.php?memo='.$id.'">'.$sender.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="osnews"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV News Lists</h1>';
	$sql = mysql_query("SELECT on_id, ntext, active FROM anope_os_news",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $ntext, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>News: <a href="index.php?news='.$id.'">'.$ntext.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="nsrequest"){
	$output .= '<h1 class="title">'.$this->irc_serv.' NICKSERV Requests Lists</h1>';
	$sql = mysql_query("SELECT nr_id, nick, active FROM anope_ns_request",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $nick, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>Request: <a href="index.php?requests='.$id.'">'.$nick.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="expts"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV exceptions Lists</h1>';
	$sql = mysql_query("SELECT oe_id, mask, active FROM anope_os_exceptions",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $mask, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>exception: <a href="index.php?expts='.$id.'">'.$mask.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="akills"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV AKills Lists</h1>';
	$sql = mysql_query("SELECT ok_id, user, active FROM anope_os_akills",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $user, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>akill: <a href="index.php?akill='.$id.'">'.$user.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="sglines"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV SGLines Lists</h1>';
	$sql = mysql_query("SELECT og_id, mask, active FROM anope_os_sglines",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $mask, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>sgline: <a href="index.php?sgline='.$id.'">'.$mask.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="sqlines"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV SQLines Lists</h1>';
	$sql = mysql_query("SELECT og_id, mask, active FROM anope_os_sqlines",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $mask, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>sqline: <a href="index.php?sqline='.$id.'">'.$mask.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
if($type=="szlines"){
	$output .= '<h1 class="title">'.$this->irc_serv.' OPERSERV SZLines Lists</h1>';
	$sql = mysql_query("SELECT og_id, mask, active FROM anope_os_szlines",$this->OpenDb()) or die('Error:' .mysql_error());
	$output .= $this->check_rows($sql);
	$output .= '<ul>';
while(list($id, $mask, $act) = mysql_fetch_array($sql, MYSQL_NUM)){
	$output .= '<li>szline: <a href="index.php?szline='.$id.'">'.$mask.'</a> active: '.$this->is_active($act).'</li>';
	}
	$output .= '<ul>';
}
$this->CloseDb();
	return $output;
}
 /**
 * Grab and display core information
 *
 */
public function Core($table, $data){
	$sql = mysql_query("SELECT * FROM $table",$this->OpenDb()) or die('Error : ' . mysql_error());
	$this->Dets = mysql_fetch_array($sql);
	$this->CloseDb();
	return $this->Dets[$data];
}
/**
 * get individual informational details
 *
 */
public function Get_Details($table, $col, $match, $row){
	$sql = mysql_query("SELECT * FROM $table where $col = '$match'",$this->OpenDb()) or die('Error : ' . mysql_error());
	$this->Dets = mysql_fetch_array($sql);
	$this->CloseDb();
	return $this->Dets[$row];
}


}
?>	
Return current item: Anope_php