create a function to export an offer to XML
This commit is contained in:
parent
598c985d44
commit
78696ee551
6
export_offer.php
Normal file
6
export_offer.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
include 'functions.php';
|
||||||
|
header('Content-type: text/xml');
|
||||||
|
header('Content-Disposition: attachment; filename="downloaded.xml"');
|
||||||
|
export_offer();
|
||||||
|
?>
|
|
@ -213,7 +213,8 @@ function show_demand ()
|
||||||
echo "<form method= 'POST' action='add_offer.php'>
|
echo "<form method= 'POST' action='add_offer.php'>
|
||||||
<input type='hidden' name='demandId' value='$demand_rows->demandId'>
|
<input type='hidden' name='demandId' value='$demand_rows->demandId'>
|
||||||
<button>Post Offer</button>
|
<button>Post Offer</button>
|
||||||
</form>";
|
</form><br>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function post_offer()
|
function post_offer()
|
||||||
|
@ -266,8 +267,62 @@ function show_offer ()
|
||||||
echo "<br>
|
echo "<br>
|
||||||
<br>
|
<br>
|
||||||
<strong>Description:</strong><br>";
|
<strong>Description:</strong><br>";
|
||||||
echo $offer_rows->text . "<br>
|
echo $offer_rows->text . "<br><br>";
|
||||||
<hr>";
|
echo "<form method= 'POST' action='export_offer.php'>
|
||||||
|
<input type='hidden' name='offerId' value='$offer_rows->offerId'>
|
||||||
|
<button>Export this Offer</button>
|
||||||
|
</form><hr>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function export_offer ()
|
||||||
|
{
|
||||||
|
global $con;
|
||||||
|
$offerId = $_POST['offerId'];
|
||||||
|
|
||||||
|
$offer_export_query = "SELECT o.offerId,
|
||||||
|
o.text,
|
||||||
|
o.price,
|
||||||
|
o.date,
|
||||||
|
o.pieces,
|
||||||
|
q.qualityName,
|
||||||
|
d.demandTitle
|
||||||
|
FROM offers o
|
||||||
|
INNER JOIN demands d
|
||||||
|
on o.demandId = d.demandId
|
||||||
|
INNER JOIN quality q
|
||||||
|
on o.qualityId = q.qualityId
|
||||||
|
WHERE o.offerId = '$offerId';";
|
||||||
|
$query_result = mysqli_query($con, $offer_export_query) or
|
||||||
|
die(mysqli_error($con));
|
||||||
|
|
||||||
|
$export_rows = $query_result->fetch_object();
|
||||||
|
|
||||||
|
/* create a dom document with encoding utf8 */
|
||||||
|
$domtree = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
|
||||||
|
/* create the root element of the xml tree */
|
||||||
|
$xmlRoot = $domtree->createElement("offer");
|
||||||
|
/* append it to the document created */
|
||||||
|
$offer_export = $domtree->appendChild($xmlRoot);
|
||||||
|
|
||||||
|
/* you should enclose the following two lines in a cicle */
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('demand_title',$export_rows->demandTitle));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_id',$export_rows->offerId));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_text',$export_rows->text));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_price',$export_rows->price));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_pieces',$export_rows->pieces));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_quality',$export_rows->qualityName));
|
||||||
|
$offer_export->appendChild(
|
||||||
|
$domtree->createElement('offer_date',$export_rows->date));
|
||||||
|
|
||||||
|
/* get the xml printed */
|
||||||
|
echo $domtree->saveXML();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user