/
DB_Func_olap.php
115 lines (97 loc) · 2.43 KB
/
DB_Func_olap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/****************************************************************************
Functions to manage DB queries
****************************************************************************/
function htmlTable($mat, $header=false, $format=NULL){
$html.='<table class="sortable">';
$r=0;
foreach( $mat as $qRow ){
$c=0;
$html .= "<tr>";
foreach( $qRow as $val){
if($header && ($r==0 || $c==0) ){
$html .= "<th>" . $val . "</th>";
}
else {
if($format!=null){
//call_function(format,Array($val));
$html .= $format($val);
}
else{
$html .= "<td>" . $val . "</td>";
}
}
$c++;
}
$html .= "</td>";
$r++;
}
$html.='</table>';
return $html;
}
function htmlCell($val, $styles, $decimal=0){
foreach($styles as $s){
if($val >= $s[0] && $val <$s[1]){
return '<td class="'.$s[2].'">'. number_format($val,$decimal,'.',',') .'</td>';
}
}
return '<td>'.number_format($val,$decimal,'.',',').'</td>';
}
/*
* Prende una matrice di stringhe con tre colonne: la prima la mette sulle righe, la seconda sulle colonne ela terza come valore
*/
function olap ($mat, $val_pos=2, $row_pos=0, $col_pos=1 ){
$rows= Array();
$cols= Array();
$res = Array();
foreach( $mat as $Row ){
if ( ! isset($rows[$Row[$row_pos]] )){
$rows[$Row[$row_pos]]='';
}
if ( ! isset($cols[$Row[$col_pos]])){
$cols[$Row[$col_pos]]='';
}
$res[$Row[$row_pos]][$Row[$col_pos]]=$Row[$val_pos];
}
$ret = Array();
$ret[0][0]='';
$r=1;
foreach( array_keys($rows) as $row ){
$ret[$r][0]=$row;
$c=1;
foreach( array_keys($cols) as $col ){
if($r==1){
$ret[0][$c]=$col;
}
$ret[$r][$c]=$res[$row][$col];
$c++;
}
$r++;
}
return $ret;
}
function exeQueryA( $SQL, &$aData, &$Errors, $printFields=false )
{
$aData = array();
$nData = 0;
$Errors = "";
$result = PG_QueryStart( $SQL, $aFields, $link, $Errors );
if( !($result === false) )
{
while( $qRow = pg_fetch_array( $result, null, PGSQL_NUM ) )
{
$aData[$qRow[0]] = $qRow; $nData++;
}
}
PG_QueryEnd( $link, $result );
if( $Errors != "" )
$nData = -1;
// echo "\n<!-- $SQL ==> $nData -->\n";
return( $nData );
}
function starts_with($string, $search)
{
//echo('|'.strtolower($string).'-'.$search.'='.(strncmp(strtolower($string), $search, strlen($search)) == 0).'|');
return (strncmp(strtolower($string), $search, strlen($search)) == 0);
}
?>