donew.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php // php pages made with phpMyBuilder <http://kyber.dk/phpMyBuilder> ?>
  2. <?php
  3. // (C) Copyright 2001
  4. // Murray Jensen <Murray.Jensen@cmst.csiro.au>
  5. // CSIRO Manufacturing Science and Technology, Preston Lab
  6. // doedit page (hymod_bddb / boards)
  7. require("defs.php");
  8. pg_head("$bddb_label - Board Registration Results");
  9. if (($serno=intval($serno)) != 0)
  10. die("serial number must not be set ($serno) when Creating!");
  11. $query="update boards set";
  12. list($y, $m, $d) = split("-", $date);
  13. if (!checkdate($m, $d, $y) || $y < 1999)
  14. die("date is invalid (input '$date', yyyy-mm-dd '$y-$m-$d')");
  15. $query.=" date='$date'";
  16. if ($batch != '') {
  17. if (strlen($batch) > 32)
  18. die("batch field too long (>32)");
  19. $query.=", batch='$batch'";
  20. }
  21. if (!in_array($type, $type_vals))
  22. die("Invalid type ($type) specified");
  23. $query.=", type='$type'";
  24. if (($rev = intval($rev)) <= 0 || $rev > 255)
  25. die("Revision number is invalid ($rev)");
  26. $query.=sprintf(", rev=%d", $rev);
  27. $query.=gather_enum_multi_query("sdram", 4);
  28. $query.=gather_enum_multi_query("flash", 4);
  29. $query.=gather_enum_multi_query("zbt", 16);
  30. $query.=gather_enum_multi_query("xlxtyp", 4);
  31. $nxlx = count_enum_multi("xlxtyp", 4);
  32. $query.=gather_enum_multi_query("xlxspd", 4);
  33. if (count_enum_multi("xlxspd", 4) != $nxlx)
  34. die("number of xilinx speeds not same as number of types");
  35. $query.=gather_enum_multi_query("xlxtmp", 4);
  36. if (count_enum_multi("xlxtmp", 4) != $nxlx)
  37. die("number of xilinx temps. not same as number of types");
  38. $query.=gather_enum_multi_query("xlxgrd", 4);
  39. if (count_enum_multi("xlxgrd", 4) != $nxlx)
  40. die("number of xilinx grades not same as number of types");
  41. if ($cputyp == '') {
  42. if ($cpuspd != '')
  43. die("can't specify cpu speed if there is no cpu");
  44. if ($cpmspd != '')
  45. die("can't specify cpm speed if there is no cpu");
  46. if ($busspd != '')
  47. die("can't specify bus speed if there is no cpu");
  48. }
  49. else {
  50. $query.=", cputyp='$cputyp'";
  51. if ($cpuspd == '')
  52. die("must specify cpu speed if cpu type is defined");
  53. $query.=", cpuspd='$cpuspd'";
  54. if ($cpmspd == '')
  55. die("must specify cpm speed if cpu type is defined");
  56. $query.=", cpmspd='$cpmspd'";
  57. if ($busspd == '')
  58. die("must specify bus speed if cpu type is defined");
  59. $query.=", busspd='$busspd'";
  60. }
  61. if (($hschin = intval($hschin)) < 0 || $hschin > 4)
  62. die("Invalid number of hs input chans ($hschin)");
  63. if (($hschout = intval($hschout)) < 0 || $hschout > 4)
  64. die("Invalid number of hs output chans ($hschout)");
  65. if ($hstype == '') {
  66. if ($hschin != 0)
  67. die("number of high-speed input channels must be zero"
  68. . " if high-speed chip is not present");
  69. if ($hschout != 0)
  70. die("number of high-speed output channels must be zero"
  71. . " if high-speed chip is not present");
  72. }
  73. else
  74. $query.=", hstype='$hstype'";
  75. $query.=", hschin='$hschin'";
  76. $query.=", hschout='$hschout'";
  77. // echo "final query = '$query'<br>\n";
  78. $quant = intval($quant);
  79. if ($quant <= 0) $quant = 1;
  80. $sernos = array();
  81. if ($geneths)
  82. $ethaddrs = array();
  83. $sqlerr = '';
  84. while ($quant-- > 0) {
  85. mysql_query("insert into boards (serno) values (null)");
  86. if (mysql_errno()) {
  87. $sqlerr = mysql_error();
  88. break;
  89. }
  90. $serno = mysql_insert_id();
  91. if (!$serno) {
  92. $sqlerr = "couldn't allocate new serial number";
  93. break;
  94. }
  95. mysql_query($query . " where serno=$serno");
  96. if (mysql_errno()) {
  97. $sqlerr = mysql_error();
  98. break;
  99. }
  100. array_push($sernos, $serno);
  101. if ($geneths) {
  102. $ethaddr = gen_eth_addr($serno);
  103. mysql_query("update boards set ethaddr='$ethaddr'" .
  104. " where serno=$serno");
  105. if (mysql_errno()) {
  106. $sqlerr = mysql_error();
  107. array_push($ethaddrs,
  108. "<font color=#ff0000><b>" .
  109. "db save fail" .
  110. "</b></font>");
  111. break;
  112. }
  113. array_push($ethaddrs, $ethaddr);
  114. }
  115. }
  116. $nsernos = count($sernos);
  117. if ($nsernos > 0) {
  118. write_eeprom_cfg_file();
  119. echo "<font size=+2>\n";
  120. echo "\t<p>\n";
  121. echo "\t\tThe following board serial numbers were"
  122. . " successfully allocated";
  123. if ($numerrs > 0)
  124. echo " (but with $numerrs cfg file error" .
  125. ($numerrs > 1 ? "s" : "") . ")";
  126. echo ":\n";
  127. echo "\t</p>\n";
  128. echo "</font>\n";
  129. echo "<table align=center width=\"100%\">\n";
  130. echo "<tr>\n";
  131. echo "\t<th>Serial Number</th>\n";
  132. if ($numerrs > 0)
  133. echo "\t<th>Cfg File Errs</th>\n";
  134. if ($geneths)
  135. echo "\t<th>Ethernet Address</th>\n";
  136. echo "</tr>\n";
  137. for ($i = 0; $i < $nsernos; $i++) {
  138. $serno = sprintf("%010d", $sernos[$i]);
  139. echo "<tr>\n";
  140. echo "\t<td align=center><font size=+2>" .
  141. "<b>$serno</b></font></td>\n";
  142. if ($numerrs > 0) {
  143. if (($errstr = $cfgerrs[$i]) == '')
  144. $errstr = '&nbsp;';
  145. echo "\t<td align=center>" .
  146. "<font size=+2 color=#ff0000><b>" .
  147. $errstr .
  148. "</b></font></td>\n";
  149. }
  150. if ($geneths) {
  151. echo "\t<td align=center>" .
  152. "<font size=+2 color=#00ff00><b>" .
  153. $ethaddrs[$i] .
  154. "</b></font></td>\n";
  155. }
  156. echo "</tr>\n";
  157. }
  158. echo "</table>\n";
  159. }
  160. if ($sqlerr != '') {
  161. echo "\t<font size=+4>\n";
  162. echo "\t\t<p>\n";
  163. echo "\t\t\tThe following SQL error was encountered:\n";
  164. echo "\t\t</p>\n";
  165. echo "\t\t<center>\n";
  166. printf("\t\t\t<b>%s</b>\n", $sqlerr);
  167. echo "\t\t</center>\n";
  168. echo "\t</font>\n";
  169. }
  170. ?>
  171. <p>
  172. <table align=center width="100%">
  173. <tr>
  174. <td align=center><a href="browse.php">Go to Browse</a></td>
  175. <td align=center><a href="index.php">Back to Start</a></td>
  176. </tr>
  177. </table>
  178. <?php
  179. pg_foot();
  180. ?>