summaryrefslogtreecommitdiffstats
path: root/tools/bddb/donew.php
blob: 0f6e0d75ece6ce38032322cd80871f14840180a6 (plain)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?>
<?php
	// (C) Copyright 2001
	// Murray Jensen <Murray.Jensen@cmst.csiro.au>
	// CSIRO Manufacturing Science and Technology, Preston Lab

	// doedit page (hymod_bddb / boards)

	require("defs.php");

	pg_head("$bddb_label - Board Registration Results");

	if (($serno=intval($serno)) != 0)
		die("serial number must not be set ($serno) when Creating!");

	$query="update boards set";

	list($y, $m, $d) = split("-", $date);
	if (!checkdate($m, $d, $y) || $y < 1999)
		die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')");
	$query.=" date='$date'";

	if ($batch != '') {
		if (strlen($batch) > 32)
			die("batch field too long (>32)");
		$query.=", batch='$batch'";
	}

	if (!in_array($type, $type_vals))
		die("Invalid type ($type) specified");
	$query.=", type='$type'";

	if (($rev = intval($rev)) <= 0 || $rev > 255)
		die("Revision number is invalid ($rev)");
	$query.=sprintf(", rev=%d", $rev);

	$query.=gather_enum_multi_query("sdram", 4);

	$query.=gather_enum_multi_query("flash", 4);

	$query.=gather_enum_multi_query("zbt", 16);

	$query.=gather_enum_multi_query("xlxtyp", 4);
	$nxlx = count_enum_multi("xlxtyp", 4);

	$query.=gather_enum_multi_query("xlxspd", 4);
	if (count_enum_multi("xlxspd", 4) != $nxlx)
		die("number of xilinx speeds not same as number of types");

	$query.=gather_enum_multi_query("xlxtmp", 4);
	if (count_enum_multi("xlxtmp", 4) != $nxlx)
		die("number of xilinx temps. not same as number of types");

	$query.=gather_enum_multi_query("xlxgrd", 4);
	if (count_enum_multi("xlxgrd", 4) != $nxlx)
		die("number of xilinx grades not same as number of types");

	if ($cputyp == '') {
		if ($cpuspd != '')
			die("can't specify cpu speed if there is no cpu");
		if ($cpmspd != '')
			die("can't specify cpm speed if there is no cpu");
		if ($busspd != '')
			die("can't specify bus speed if there is no cpu");
	}
	else {
		$query.=", cputyp='$cputyp'";
		if ($cpuspd == '')
			die("must specify cpu speed if cpu type is defined");
		$query.=", cpuspd='$cpuspd'";
		if ($cpmspd == '')
			die("must specify cpm speed if cpu type is defined");
		$query.=", cpmspd='$cpmspd'";
		if ($busspd == '')
			die("must specify bus speed if cpu type is defined");
		$query.=", busspd='$busspd'";
	}

	if (($hschin = intval($hschin)) < 0 || $hschin > 4)
		die("Invalid number of hs input chans ($hschin)");
	if (($hschout = intval($hschout)) < 0 || $hschout > 4)
		die("Invalid number of hs output chans ($hschout)");
	if ($hstype == '') {
		if ($hschin != 0)
			die("number of high-speed input channels must be zero"
				. " if high-speed chip is not present");
		if ($hschout != 0)
			die("number of high-speed output channels must be zero"
				. " if high-speed chip is not present");
	}
	else
		$query.=", hstype='$hstype'";
	$query.=", hschin='$hschin'";
	$query.=", hschout='$hschout'";

	// echo "final query = '$query'<br>\n";

	$quant = intval($quant);
	if ($quant <= 0) $quant = 1;

	$sernos = array();
	if ($geneths)
		$ethaddrs = array();

	$sqlerr = '';

	while ($quant-- > 0) {

		mysql_query("insert into boards (serno) values (null)");
		if (mysql_errno()) {
			$sqlerr = mysql_error();
			break;
		}

		$serno = mysql_insert_id();
		if (!$serno) {
			$sqlerr = "couldn't allocate new serial number";
			break;
		}

		mysql_query($query . " where serno=$serno");
		if (mysql_errno()) {
			$sqlerr = mysql_error();
			break;
		}

		array_push($sernos, $serno);

		if ($geneths) {

			$ethaddr = gen_eth_addr($serno);

			mysql_query("update boards set ethaddr='$ethaddr'" .
			    " where serno=$serno");
			if (mysql_errno()) {
				$sqlerr = mysql_error();

				array_push($ethaddrs,
					"<font color=#ff0000><b>" .
					"db save fail" .
					"</b></font>");
				break;
			}

			array_push($ethaddrs, $ethaddr);
		}
	}

	$nsernos = count($sernos);

	if ($nsernos > 0) {

		write_eeprom_cfg_file();

		echo "<font size=+2>\n";
		echo "\t<p>\n";
		echo "\t\tThe following board serial numbers were"
			. " successfully allocated";
		if ($numerrs > 0)
			echo " (but with $numerrs cfg file error" .
				($numerrs > 1 ? "s" : "") . ")";
		echo ":\n";
		echo "\t</p>\n";

		echo "</font>\n";

		echo "<table align=center width=\"100%\">\n";
		echo "<tr>\n";
		echo "\t<th>Serial Number</th>\n";
		if ($numerrs > 0)
			echo "\t<th>Cfg File Errs</th>\n";
		if ($geneths)
			echo "\t<th>Ethernet Address</th>\n";
		echo "</tr>\n";

		for ($i = 0; $i < $nsernos; $i++) {

			$serno = sprintf("%010d", $sernos[$i]);

			echo "<tr>\n";

			echo "\t<td align=center><font size=+2>" .
				"<b>$serno</b></font></td>\n";

			if ($numerrs > 0) {
				if (($errstr = $cfgerrs[$i]) == '')
					$errstr = '&nbsp;';
				echo "\t<td align=center>" .
					"<font size=+2 color=#ff0000><b>" .
					$errstr .
					"</b></font></td>\n";
			}

			if ($geneths) {
				echo "\t<td align=center>" .
					"<font size=+2 color=#00ff00><b>" .
					$ethaddrs[$i] .
					"</b></font></td>\n";
			}

			echo "</tr>\n";
		}

		echo "</table>\n";
	}

	if ($sqlerr != '') {
		echo "\t<font size=+4>\n";
		echo "\t\t<p>\n";
		echo "\t\t\tThe following SQL error was encountered:\n";
		echo "\t\t</p>\n";
		echo "\t\t<center>\n";
		printf("\t\t\t<b>%s</b>\n", $sqlerr);
		echo "\t\t</center>\n";
		echo "\t</font>\n";
	}

?>
<p>
<table align=center width="100%">
<tr>
  <td align=center><a href="browse.php">Go to Browse</a></td>
  <td align=center><a href="index.php">Back to Start</a></td>
</tr>
</table>
<?php
	pg_foot();
?>