48 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This is the callable library for the license module.
|
|
|
5 |
* routines are assumed to be called from other modules, returning
|
|
|
6 |
* HTML data.
|
|
|
7 |
* All routines will receive one array containing the parameters to
|
|
|
8 |
* be used. Parameters may be
|
|
|
9 |
* client_id - A client_id to be used for queries
|
|
|
10 |
* device_id - A device_id to be used for queries
|
|
|
11 |
* site_id - A site_id to be used for queries
|
|
|
12 |
* htmlDirectory - the HTML path to the module
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
function view ( $parameters ) {
|
|
|
16 |
// this is an array containing the columns we will display in the
|
|
|
17 |
// query. The query will be generated as
|
|
|
18 |
// select $key '$value', $key '$value
|
|
|
19 |
$reportColumns = array(
|
|
|
20 |
'license_id' => 'ID',
|
|
|
21 |
'license_product.name' => 'Product',
|
|
|
22 |
'license.license' => 'License',
|
|
|
23 |
'license.added_date' => 'Installed',
|
|
|
24 |
'device_id' => 'Machine',
|
|
|
25 |
);
|
|
|
26 |
// first, let's remove any fields from $report_columns which are
|
|
|
27 |
// listed in the $parameters, and add them to the where clause
|
|
|
28 |
$whereClause = array( 'license.removed_date is null' );
|
|
|
29 |
foreach ( $parameters as $key => $value ) {
|
|
|
30 |
if ( isset( $reportColumns[ $key ] ) ) {
|
|
|
31 |
unset( $reportColumns[ $key ] );
|
|
|
32 |
$whereClause[] = "$key = $value";
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
$columnList = array();
|
|
|
36 |
foreach ( $reportColumns as $key => $value ) {
|
|
|
37 |
$columnList[] = "$key '$value'";
|
|
|
38 |
}
|
|
|
39 |
$query = 'select ' . implode( ',', $columnList );
|
|
|
40 |
$query .= 'from
|
|
|
41 |
license join license_product using (license_product_id)
|
|
|
42 |
left outer join device using (device_id)
|
|
|
43 |
join client using ( client_id )';
|
|
|
44 |
$query .= ' where ' . implode ( ' and ', $whereClause );
|
|
|
45 |
return queryToTable( $query );
|
|
|
46 |
//return "Parameters are<br /><pre>" . print_r( $parameters, true ) . "</pre><br />\n<pre>$query</pre>\n";
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
?>
|
|
|
50 |
|