Le fichier monfichier.odt sera proposé en téléchargement.<?
// connexion base de données
$db_server = "localhost";
$db_user = "root";
$db_pass = "motdepasse";
$db_name = "mabase";
function connect($db_server, $db_user, $db_pass, $db) {
if (!($link=mysql_connect($db_server,$db_user,$db_pass))) {
exit();
}
if (!(mysql_select_db($db,$link))) {
exit();
}
return $link;
}
$connexion=connect($db_server,$db_user,$db_pass,$db_name);// requete
$sql = mysql_query("SELECT * FROM matable ORDER BY titre",$connexion);// début ODT
$monxml="<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:ooo=\"http://openoffice.org/2004/office\" xmlns:ooow=\"http://openoffice.org/2004/writer\" xmlns:oooc=\"http://openoffice.org/2004/calc\" xmlns:dom=\"http://www.w3.org/2001/xml-events\" xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" office:version=\"1.1\"><office:scripts/><office:font-face-decls><style:font-face style:name=\"Garamond 3\" svg:font-family=\"Garamond 3;\"/><style:font-face style:name=\"Lucida Sans\" svg:font-family=\"Lucida Sans\"/><style:font-face style:name=\"Lucidasans1\" svg:font-family=\"Lucidasans\"/><style:font-face style:name=\"HG Mincho Light J\" svg:font-family=\"HG Mincho Light J\" style:font-family-generic=\"system\" style:font-pitch=\"variable\"/><style:font-face style:name=\"Lucidasans\" svg:font-family=\"Lucidasans\" style:font-family-generic=\"system\" style:font-pitch=\"variable\"/><style:font-face style:name=\"Nimbus Sans L\" svg:font-family=\"Nimbus Sans L\" style:font-family-generic=\"system\" style:font-pitch=\"variable\"/></office:font-face-decls><office:automatic-styles><style:style style:name=\"P1\" style:family=\"paragraph\" style:parent-style-name=\"Footer\"><style:paragraph-properties fo:text-align=\"center\" style:justify-single-word=\"false\"/></style:style>
<style:style style:name=\"P2\" style:family=\"paragraph\" style:parent-style-name=\"Header\"><style:paragraph-properties fo:text-align=\"center\" style:justify-single-word=\"false\"/></style:style><style:style style:name=\"T1\" style:family=\"text\"><style:text-properties fo:font-weight=\"bold\" style:font-weight-asian=\"bold\" style:font-weight-complex=\"bold\"/></style:style></office:automatic-styles><office:body><office:text><office:forms form:automatic-focus=\"false\" form:apply-design-mode=\"false\"/><text:sequence-decls><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Illustration\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Table\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Text\"/><text:sequence-decl text:display-outline-level=\"0\" text:name=\"Drawing\"/></text:sequence-decls>";
// on boucle
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$titre = htmlspecialchars($row["titre"]);
$description = htmlspecialchars($row["description"]);
// traitement du content.xml
// les donnees...
$monxml = $monxml."<text:p text:style-name=\"Standard\"><text:span text:style-name=\"T1\">$titre</text:span></text:p><text:p text:style-name=\"Standard\">$description</text:p><text:p text:style-name=\"Standard\"></text:p>";
}
// fin du content.xml
$monxml = $monxml."</office:text></office:body></office:document-content>";
$ficin="../monsite/odt/content.xml";
$monfic = fopen($ficin, "w");
fwrite($monfic, $monxml);
fclose($monfic);
// si le fichier existe, on supprime
@unlink('monfichier.odt');
// on se deplace dans le repertoire de l'odt et on zippe pour recreer le fichier odt
$creation_odt="cd ../monsite/odt/;zip -r ../monfichier.odt *";
$out=shell_exec($creation_odt);
// on envoie vers le navigateur
header("location:monfichier.odt");
?>