/
CedarGenerator.php
166 lines (154 loc) · 4.25 KB
/
CedarGenerator.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
global $catalog_systems ;
$catalog_systems['cedar_gen'] = "CedarGenerator" ;
class CedarGenerator extends AbstractCatalog
{
public function CedarGenerator()
{
$this->catalog_functions['instruments'] = 'genInstruments' ;
$this->catalog_functions['parameters'] = 'genParameters' ;
$this->catalog_functions['opmodes'] = 'genOpModes' ;
$this->catalog_functions['opmodeparams'] = 'genOpModeParams' ;
}
private function cedarconnect()
{
return parent::dbconnect( "db.hao.ucar.edu:3306","root","c@shit","CEDARCATALOG" );
}
/*
*/
protected function genInstruments()
{
// need to connect to the database here in order to run the
// function mysql_real_escape_string
$isconnected = $this->cedarconnect() ;
if( $isconnected != "good" )
{
print( "Failed to connect to the database: $isconnected\n" ) ;
exit( 0 ) ;
}
$query = "SELECT DISTINCT tbl_instrument.KINST as kinst, tbl_instrument.INST_NAME as inst_name, tbl_instrument.PREFIX as prefix FROM tbl_instrument";
$result = parent::dbquery( $query ) ;
$num_rows = mysql_num_rows( $result ) ;
if( $num_rows != 0 )
{
while( $line = mysql_fetch_row( $result ) )
{
if( $line )
{
$colnum = 0 ;
foreach( $line as $value )
{
if( $colnum > 0 ) echo "," ;
echo $value ;
$colnum++ ;
}
echo "\n" ;
}
}
}
parent::dbclose( $result ) ;
}
/*
*/
protected function genParameters()
{
// need to connect to the database here in order to run the
// function mysql_real_escape_string
$isconnected = $this->cedarconnect() ;
if( $isconnected != "good" )
{
print( "Failed to connect to the database: $isconnected\n" ) ;
exit( 0 ) ;
}
$query = "SELECT DISTINCT tbl_parameter_code.PARAMETER_ID as parameter_id, tbl_parameter_code.LONG_NAME as long_name, tbl_parameter_code.SHORT_NAME as short_name, tbl_parameter_code.MADRIGAL_NAME as madrigal_name FROM tbl_parameter_code";
$result = parent::dbquery( $query ) ;
$num_rows = mysql_num_rows( $result ) ;
if( $num_rows != 0 )
{
while( $line = mysql_fetch_row( $result ) )
{
if( $line )
{
$colnum = 0 ;
foreach( $line as $value )
{
if( $colnum > 0 ) echo "," ;
echo $value ;
$colnum++ ;
}
echo "\n" ;
}
}
}
parent::dbclose( $result ) ;
}
/*
*/
protected function genOpModes()
{
// need to connect to the database here in order to run the
// function mysql_real_escape_string
$isconnected = $this->cedarconnect() ;
if( $isconnected != "good" )
{
print( "Failed to connect to the database: $isconnected\n" ) ;
exit( 0 ) ;
}
$query = "SELECT DISTINCT tbl_record_type.RECORD_TYPE_ID as record_type_id, tbl_record_type.KINST as kinst, tbl_record_type.KINDAT as kindat, tbl_record_type.DESCRIPTION as description FROM tbl_record_type";
$result = parent::dbquery( $query ) ;
$num_rows = mysql_num_rows( $result ) ;
if( $num_rows != 0 )
{
while( $line = mysql_fetch_row( $result ) )
{
if( $line )
{
$colnum = 0 ;
foreach( $line as $value )
{
if( $colnum > 0 ) echo "," ;
echo $value ;
$colnum++ ;
}
echo "\n" ;
}
}
}
parent::dbclose( $result ) ;
}
/*
*/
protected function genOpModeParams()
{
// need to connect to the database here in order to run the
// function mysql_real_escape_string
$isconnected = $this->cedarconnect() ;
if( $isconnected != "good" )
{
print( "Failed to connect to the database: $isconnected\n" ) ;
exit( 0 ) ;
}
$query = "SELECT DISTINCT tbl_record_type.KINST as kinst, tbl_record_type.KINDAT as kindat, tbl_record_info.PARAMETER_ID as parameter_id FROM tbl_record_type, tbl_record_info, tbl_parameter_code WHERE tbl_record_type.RECORD_TYPE_ID=tbl_record_info.RECORD_TYPE_ID AND tbl_parameter_code.PARAMETER_ID=tbl_record_info.PARAMETER_ID AND NOT (tbl_parameter_code.LONG_NAME='UNDEFINED');";
$result = parent::dbquery( $query ) ;
$num_rows = mysql_num_rows( $result ) ;
if( $num_rows != 0 )
{
while( $line = mysql_fetch_row( $result ) )
{
if( $line )
{
$colnum = 0 ;
foreach( $line as $value )
{
if( $colnum > 0 ) echo "," ;
echo $value ;
$colnum++ ;
}
echo "\n" ;
}
}
}
parent::dbclose( $result ) ;
}
} ;
?>