-
Notifications
You must be signed in to change notification settings - Fork 1
/
tables.php
executable file
·119 lines (112 loc) · 2.78 KB
/
tables.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
116
117
<?php
require_once('block.php');
require_once('csvreader.php');
class tables extends block
{
function showTable($fn)
{
$units=array();
$f=file($fn);
$str="";
$cnt=0;
foreach($f as $linea)
{
$linea=str_replace("\"","",$linea);
$linea=str_replace(",","\t",$linea);
if($cnt==0)
{
$units=$this->units($linea);
$linea=str_replace(".","_",$linea);
$cnt2=1;
foreach($units as $u)
{
if(strlen($u)>0)
{
$linea.="(".$u.")";
}
if($cnt2 < count($units)){$linea.="\t";}else{$linea.="\n";}
$cnt2++;
}
}else
{
$linea=str_replace(".",",",$linea);
}
$cnt++;
$str.=$linea;
}
$SS=serialize($str);
echo "<div class='downdata'>\n";
echo " <form method='post' action=send.php target='_new'>\n";
echo " <input class='downdata' type='submit' value='".$this->text('tables_Download')."'>\n";
echo " <input id='data' name='data' type='hidden' value='".$SS."'>\n";
echo " </form>\n";
echo "</div>\n";
echo " <table class='outputs'>\n";
$cnt=0;
foreach($f as $linea)
{
echo " <tr class='outputs'>\n";
$linea=str_replace("\n","",$linea);
$datos=explode(",",$linea);
foreach($datos as $d)
{
if(strlen($d)<1){continue;}
if(is_numeric($d))
{
echo " <td class='outputs'>".number_format($d,3,".","")."</td>\n";
}else
{
echo " <td class='outputsTitle'>".str_replace("\"","",$d)."</td>\n";
}
}
echo " </tr>\n";
$cnt++;
if($cnt<2)
{
echo " <tr class='outputs'>\n";
foreach($units as $d)
{
if(strlen($d)>0)
{
echo " <td class='outputsTitle'>(".str_replace("\"","",$d).")</td>\n";
}else
{
echo " <td class='outputsTitle'></td>\n";
}
}
echo " </tr>\n";
}
$cnt++;
}
echo " </table>\n";
}
function units($csvLine)
{
$str="";
$units=array();
$vars=explode("\t",$csvLine);
foreach($vars as $Var)
{
$sql="SELECT * FROM variables WHERE model_id='".$this->model_id()."' AND modelicaname='".$Var."'";
$result=mysqli_query($this->link,$sql) or die(mysqli_error($this->link).": ".$sql);
if($result and mysqli_num_rows($result)>0)
{
while($linea=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$units[$linea['modelicaname']]=$linea['units'];
}
}
}
return $units;
}
function display()
{
$model_id=$this->model_id();
if($model_id==0 or !isset($_POST['res_file']))
{
return;
}
$this->showTable($_POST['res_file']);
}
}
?>