Location: PHPKode > projects > Electronic Design Automation - Index > eda-index-1.0MLH/web/xmlgenerator.php
<?php
require("config.inc.php");
require("top.inc.php");

#########################################################################
# Electronic Design Automation - Index (EDA - Index)			#
#########################################################################
#									#
# Copyright (c) 2003 by Bruno Thomsen (hide@address.com)	#
# My Homepage: http://www.spacecave.dk/					#
# Project Homepage: http://eda-index.sourceforge.net/			#
# Project @ SourceForge.net: http://sourceforge.net/projects/eda-index/	#
# Project @ Freshmeat.net: http://freshmeat.net/projects/eda-index/	#
# Project Demo: http://eda-index.sourceforge.net/demo/			#
#									#
# This program is free software; you can redistribute it and/or modify	#
# it under the terms of the GNU General Public License as published by	#
# the Free Software Foundation; either version 2 of the License, or	#
# (at your option) any later version.					#
#									#
# This program is distributed in the hope that it will be useful,	#
# but WITHOUT ANY WARRANTY; without even the implied warranty of	#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the		#
# GNU General Public License for more details.				#
#									#
#########################################################################

?>

<font size="3"> 
<br/>

<?php

# chmod 666 edadata.xml
# w = Open for writing only, place the file pointer at the beginning of the file and truncate the file to zero length.
# a = Open for writing only, place the file pointer at the end of the file.

$file = "edadata.xml";
$day = date(d);
$month = date(m);
$year = date(Y);
$date = "$day-$month-$year";
$a = "  ";
$b = "    ";
$c = "      ";

$xmltop = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n\n<data>";

$xmlgen = "
\n$a<generator>
$b<title>$title</title>
$b<version>$version</version>
$b<created>$date</created>
$a</generator>\n";
$xmlbottom = "\n</data>\n";

if (is_writable($file)) {
  if (!$top = fopen($file, "w")) {
    echo "<font color=\"red\">Unable to open file: $file!</font><br/>";
    exit;
  }
  if (fwrite($top, $xmltop) === FALSE) {
    echo "<font color=\"red\">Cannot write to file: $file!</font><br/>";
    exit;
  }

echo "<font color=\"green\">Successfully</font> created xml file ($file), appending xml file top!<br/>";
fclose($top);

$gen = fopen($file, "a");
  if (fwrite($gen, $xmlgen) === FALSE) {
    echo "<font color=\"red\">Cannot write generator info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added generator info to xml file.<br/>";
fclose($gen);

$xmlprj = "\n$a<projects>\n";
$prj = fopen($file, "a");
fwrite($prj, $xmlprj);
fclose($prj);

opendb($dbhost,$dbuser,$dbpass,$dbname);
$sql = "SELECT *,DATE_FORMAT(date,'$dateformat') as newdate FROM `$tabels[0]` ORDER BY date DESC";
$result = getdata($sql);
while ($data = mysql_fetch_array($result)) {
   extract($data);

$xmlprj = "
$b<pid>$pid</pid>
$c<description>$description</description>
$c<name>$name</name>
$c<date>$date</date>
$c<note>$note</note>\n";

$prj = fopen($file, "a");
fwrite($prj, $xmlprj);
fclose($prj);

}

$xmlprj = "\n$a</projects>\n";
$prj = fopen($file, "a");
  if (fwrite($prj, $xmlprj) === FALSE) {
    echo "<font color=\"red\">Cannot write project info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added project info to xml file.<br/>";
fclose($prj);
closedb();

$xmlsch = "\n$a<schematics>\n";
$sch = fopen($file, "a");
fwrite($sch, $xmlsch);
fclose($sch);

opendb($dbhost,$dbuser,$dbpass,$dbname);
$sql = "SELECT *,DATE_FORMAT(date,'$dateformat') as newdate FROM `$tabels[1]` ORDER BY date DESC";
$result = getdata($sql);
while ($data = mysql_fetch_array($result)) {
   extract($data);

$xmlsch = "
$b<id>$id</id>
$c<idref>$idref</idref>
$c<nr>$nr</nr>
$c<rev>$rev</rev>
$c<description>$description</description>
$c<pcbref>$pcbref</pcbref>
$c<pcbrev>$pcbrev</pcbrev>
$c<fpref>$fpref</fpref>
$c<fprev>$fprev</fprev>
$c<name>$name</name>
$c<date>$date</date>
$c<note>$note</note>
$c<cad>$cad</cad>\n";

$sch = fopen($file, "a");
fwrite($sch, $xmlsch);
fclose($sch);

}

$xmlsch = "\n$a</schematics>\n";
$sch = fopen($file, "a");
  if (fwrite($sch, $xmlsch) === FALSE) {
    echo "<font color=\"red\">Cannot write schematic info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added schmatic info to xml file.<br/>";
fclose($sch);
closedb();

$xmlpcb = "\n$a<pcbs>\n";
$pcb = fopen($file, "a");
fwrite($pcb, $xmlpcb);
fclose($pcb);

opendb($dbhost,$dbuser,$dbpass,$dbname);
$sql = "SELECT *,DATE_FORMAT(date,'$dateformat') as newdate FROM `$tabels[2]` ORDER BY date DESC";
$result = getdata($sql);
while ($data = mysql_fetch_array($result)) {
   extract($data);

$xmlpcb = "
$b<id>$id</id>
$b<idref>$idref</idref>
$b<nr>$nr</nr>
$b<rev>$rev</rev>
$b<description>$description</description>
$b<schref>$schref</schref>
$b<schrev>$schrev</schrev>
$b<fpref>$fpref</fpref>
$b<fprev>$fprev</fprev>
$b<name>$name</name>
$b<date>$date</date>
$b<note>$note</note>
$b<cad>$cad</cad>\n";

$pcb = fopen($file, "a");
fwrite($pcb, $xmlpcb);
fclose($pcb);

}

$xmlpcb = "\n$a</pcbs>\n";
$pcb = fopen($file, "a");
  if (fwrite($pcb, $xmlpcb) === FALSE) {
    echo "<font color=\"red\">Cannot write pcb info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added pcb info to xml file.<br/>";
fclose($pcb);
closedb();

$xmlfp = "\n$a<front-plates>\n";
$fp = fopen($file, "a");
fwrite($fp, $xmlfp);
fclose($fp);

opendb($dbhost,$dbuser,$dbpass,$dbname);
$sql = "SELECT *,DATE_FORMAT(date,'$dateformat') as newdate FROM `$tabels[3]` ORDER BY date DESC";
$result = getdata($sql);
while ($data = mysql_fetch_array($result)) {
   extract($data);

$xmlfp = "
$b<id>$id</id>
$b<idref>$idref</idref>
$b<nr>$nr</nr>
$b<rev>$rev</rev>
$b<description>$description</description>
$b<schref>$schref</schref>
$b<schrev>$schrev</schrev>
$b<pcbref>$pcbref</pcbref>
$b<pcbrev>$pcbrev</pcbrev>
$b<name>$name</name>
$b<date>$date</date>
$b<note>$note</note>
$b<cad>$cad</cad>\n";

$fp = fopen($file, "a");
fwrite($fp, $xmlfp);
fclose($fp);

}

$xmlfp = "\n$a</front-plates>\n";
$fp = fopen($file, "a");
  if (fwrite($fp, $xmlfp) === FALSE) {
    echo "<font color=\"red\">Cannot write front plate info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added front plate info to xml file.<br/>";
fclose($fp);
closedb();

$xmlpld = "\n$a<plds>\n";
$pld = fopen($file, "a");
fwrite($pld, $xmlpld);
fclose($pld);

opendb($dbhost,$dbuser,$dbpass,$dbname);
$sql = "SELECT *,DATE_FORMAT(date,'$dateformat') as newdate FROM `$tabels[4]` ORDER BY date DESC";
$result = getdata($sql);
while ($data = mysql_fetch_array($result)) {
   extract($data);

$xmlpld = "
$b<id>$id</id>
$b<idref>$idref</idref>
$b<nr>$nr</nr>
$b<rev>$rev</rev>
$b<description>$description</description>
$b<schref>$schref</schref>
$b<schrev>$schrev</schrev>
$b<pcbref>$pcbref</pcbref>
$b<pcbrev>$pcbrev</pcbrev>
$b<name>$name</name>
$b<date>$date</date>
$b<note>$note</note>
$b<cad>$cad</cad>\n";

$pld = fopen($file, "a");
fwrite($pld, $xmlpld);
fclose($pld);

}

$xmlpld = "\n$a</plds>\n";
$pld = fopen($file, "a");
  if (fwrite($pld, $xmlpld) === FALSE) {
    echo "<font color=\"red\">Cannot write pld info to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> added pld info to xml file.<br/>";
fclose($pld);
closedb();

$bottom = fopen($file, "a");
  if (fwrite($bottom, $xmlbottom) === FALSE) {
    echo "<font color=\"red\">Cannot write bottom to xml file</font><br/>";
    exit;
  }
echo "<font color=\"green\">Successfully</font> appending xml file bottom.<br/>";
fclose($bottom);

echo "<font color=\"green\">Successfully completed xml file.</font> <a href=\"$path$file\">Download it!</a><br/>";
} else {
  echo "<font color=\"red\">The file $file is not writable!</font><br/>";
}

?>

</font>

<?php
require("bottom.inc.php");
?>
Return current item: Electronic Design Automation - Index