Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/statistiques/Accounting.php
<?php
include('include/divers/acctshow.php');

if (isset($_POST['queryflag'])) $queryflag=$_POST['queryflag'];
if (isset($_POST['maxresults'])) $sql_row_limit=$maxresults=$_POST['maxresults'];
if (isset($_POST['order_by'])) $order_by=$_POST['order_by'];
if (isset($_POST['add'])) $add=$_POST['add'];
if (isset($_POST['item_name'])) $item_name=$_POST['item_name'];
if (isset($_POST['accounting_show_attrs'])) $accounting_show_attrs=$_POST['accounting_show_attrs'];
if (isset($_POST['item_of_w'])) $item_of_w=$_POST['item_of_w'];
if (isset($_POST['item_of'])) $item_of=$_POST['item_of'];
if (isset($_POST['value_of'])) $value_of=$_POST['value_of'];
if (isset($_POST['w'])) $w=$_POST['w'];

$number=1;
while (isset($_POST["item_of_w$number"])) {
	${"w$number"}=new Qi($_POST["item_of_w$number"],$_POST["value_of_w$number"],$_POST["operator_of_w$number"]);
	$number++;
}


$operators=array( '=','<', '>', '<=', '>=', 'regexp', 'like' );
$fields = $oreon->database->database->list_fields('radacct');
$no_fields = $oreon->database->database->num_fields($fields);

unset($items);
for($i=0;$i<$no_fields;$i++){
	$key = strtolower($oreon->database->database->field_name($fields,$i));
	$val = $sql_attrs[$key]['desc'];
	if ($val == '')
		continue;
	$show = $sql_attrs[$key]['show'];
	$selected[$key] = ($show == 'yes') ? 'selected' : '';
	$items[$key] = "$val";
}
asort($items);

class Qi {
	var $name;
	var $item;
	var $_item;
	var $operator;
	var $type;
	var $typestr;
	var $value;
	function Qi($name,$item,$operator) {
				$this->name=$name;
				$this->item=$item;
				$this->operator=$operator;
	}

	function show() {	
		global $operators;
		global $items;
		$nam = $this->item;
		print "<tr><td align=left>
		<i>$items[$nam]</i>
		<input type=hidden name=\"item_of_$this->name\" value=\"$this->item\">
		</td><td align=left>
		<select name=\"operator_of_$this->name\">";
		foreach($operators as $operator){
        		if($this->operator == $operator)
				$selected=" selected ";
			else
				$selected='';
		print("<option value=\"$operator\" $selected>$operator</option>\n");
      	        }
		print "</select>
		</td><td align=left>
		<input name=\"value_of_$this->name\" type=text value=\"$this->value\">
		</td><td align=left>
		<input type=hidden name=\"delete_$this->name\" value=0>
		<input type=submit class=button size=5 value=del onclick=\"this.form.delete_$this->name.value=1\">
		</td></tr>";
	}

	function get($designator) {  	
		global ${"item_of_$designator"};
		global ${"value_of_$designator"};
		global ${"operator_of_$designator"};
		$it=$_POST["item_of_$designator"];
		$val=$_POST["value_of_$designator"];
		$op=$_POST["op_of_$designator"];
		if($it){
			$this->value= $val;
			$this->operator=$op;
			$this->item=$it;
		}
	}

function query(){
		global $operators;
		global $items;
		return $items[$this->item]."  $this->operator  '$this->value'";
	}
}

if(!$queryflag) {
print "<form method=\"post\" action=\"phpmyprepaid.php\">
<table border=0 width=740 cellpadding=1 cellspacing=1>
<tr>
<td>
<b>Show the following attributes:</b><br>
<select name=\"accounting_show_attrs[]\" size=5 multiple>";

foreach($items as $key => $val)
print "<option $selected[$key] value=\"$key\">$val</option>";

print '</select>
<br><br>
<b>Order by:</b><br>
<select name="order_by">';

foreach($items as $key => $val)
	if ($val == 'username')
	print "<option selected value=\"$key\">$val</option>";
	else
print "<option value=\"$key\">$val</option>";

print "</select>
<br><br>
<b>Max results returned:</b><br>
<input name=maxresults value=$sql_row_limit size=5>
</td>
<td valign=top>
<input type=hidden name=add value=0>
<table border=0 width=340 cellpadding=1 cellspacing=1>
<tr><td>
<b>Selection criteria:</b>
</td></tr>
<tr><td>
<select name=item_name onchange=\"this.form.add.value=1;this.form.submit()\">
<option>--Attribute--</option>";

foreach($items as $key => $val)
	print("<option value=\"$key\">$val</option>");

print '</select>
</td></tr>';

$number=1;
$offset=0;

while (isset($_POST["item_of_w$number"])) {
	if($_POST["delete_w$number"]==1) {$offset=1;$number++;}
	else {

		$designator=$number-$offset;
		${"w$designator"} = new Qi("w$designator","","");
		${"w$designator"}->get("w$number");
		${"w$designator"}->show();
		$number++;
		}
}
if($add==1) {
	${"w$number"} = new Qi("w$number","$item_name","$operators[0]");
	${"w$number"}->show();
	}
print "</table>
</td>
<tr>
<td>
<input type=hidden name=queryflag value=0>
<br><input type=submit class=smallButton onclick=\"this.form.queryflag.value=1\">
</td>
</tr>
</table>
</form>";

}

if ($queryflag == 1){
$i = 1;
while (isset($_POST["item_of_w$i"])){
	$op_found = 0;
	foreach ($operators as $operator){
		if ($_POST["operator_of_w$i"] == $operator){
			$op_found = 1;
			break;
		}
	}
	if (!$op_found)
		die("Operator passed is not valid. Exiting abnormaly.");
	$_POST["item_of_w$i"] = preg_replace('/\s/','',$_POST["item_of_w$i"]);
	$_POST["value_of_w$i"] = $oreon->database->database->escape_string($_POST["value_of_w$i"]);
	$where .= ($i == 1) ? ' WHERE ' . $_POST["item_of_w$i"] . ' ' . $_POST["operator_of_w$i"] . " '" . $_POST["value_of_w$i"] . "'" :
				' AND ' . $_POST["item_of_w$i"] . ' ' . $_POST["operator_of_w$i"] . " '" . $_POST["value_of_w$i"] . "'" ;
	$i++;
}

$order = ($order_by != '') ? "$order_by" : 'username';

if (preg_match("/[\s;]/",$order))
	die("ORDER BY pattern is illegal. Exiting abnornally.");

if (!is_numeric($maxresults))
	die("Max Results is not in numeric form. Exiting abnormally.");

unset($query_view);
foreach ($accounting_show_attrs as $val)
	$query_view .= $val . ',';
$query_view = ereg_replace(',$','',$query_view);
$query="SELECT  $query_view FROM radacct
	$where $sql_extra_query " . 
	" ORDER BY $order " .$limit.  ";";

print '<table border=0 width=800 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=740></td>
<td bgcolor="888888" width=35%>
        <table border=0 width=100% cellpadding=2 cellspacing=0>
	        <tr bgcolor="#aaaaaa" align=right valign=top><th>
	<font color="white">Accounting Report Generator</font>&nbsp;
	</th></tr>
	</table>
</td></tr>
<tr bgcolor="black" valign=top><td colspan=2>
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
	<tr><td>
	<p>

	<table border=0 bordercolordark=#e6e6e6 bordercolorlight=#000000 width=800px cellpadding=2 cellspacing=0 bgcolor="#e6e6e6" valign=top>
	        <tr bgcolor="#e6e6e6">
	</tr>';

foreach($accounting_show_attrs as $val){
	$desc = $sql_attrs[$val][desc];
	echo "<th>$desc</th>\n";
}
echo "</tr>\n";

	$search = $oreon->database->database->query($query);
		while( $row = $oreon->database->database->fetch_array($search) ){
			$num++;
			echo "<tr align=center>\n";
			foreach($accounting_show_attrs as $val){
				$info = $row[$val];
				if ($info == '')
					$info = '-';
				$info = $sql_attrs[$val]['func']($info);
				if ($val == 'username'){
					$Info = urlencode($info);
					$info = '<input type="button" class="smallButton" name="UserSelected" value="'.$Info.'" onClick="window.open(\'include/divers/sexyTabs.php?phpmyprepaid='.session_id.'&usr='.$Info.'\',\'User informations\',\'width=800,height=600,status=yes,resizable=yes,menubar=yes,scrollbars=yes\');" >';
				}
			print "<td>$info</td>";
			}
			echo "</tr>\n";
		}
	print "</table>
	</td></tr>
	</table>
</td></tr>
</table>";
}
?>
Return current item: phpMyPrepaid