par
davidb » 12 mai 2010, 10:44
je laisse tel quel mais en mettant le php apres le ? il y a une fatal error ligne 5 qui n y etais pas
<?
include('../lib/GeneralUtils.inc');
$gerico = varfromget('gerico', 0);
$source = varfrompost('source', '');
if (is_dir($source)){ // the source folder exists
switch ($gerico) {
case 0:
$packname = varfrompost('title', '');
// list of accepted file types (in case of gerico = 0)
$types = array();
if(varfrompost('pdf', 0)){
$types[] = "pdf";
$types[] = "PDF";
}
if(varfrompost('doc', 0)){
$types[] = "doc";
$types[] = "DOC";
}
if(varfrompost('xls', 0)){
$types[] = "xls";
$types[] = "XLS";
}
if(varfrompost('ppt', 0)){
$types[] = "ppt";
$types[] = "PPT";
}
if(varfrompost('htm', 0)){
$types[] = "htm";
$types[] = "html";
}
if(varfrompost('jpg', 0)){
$types[] = "jpg";
$types[] = "JPG";
}
if(varfrompost('gif', 0)){
$types[] = "gif";
$types[] = "GIF";
}
if(varfrompost('tif', 0)){
$types[] = "tif";
$types[] = "tiff";
}
if(varfrompost('zip', 0)){
$types[] = "zip";
$types[] = "ZIP";
}
if(varfrompost('exe', 0)){
$types[] = "exe";
$types[] = "EXE";
}
$destination = $source;
$docsTOC = array();// this array will contain the data for the html table of contents
// We read the folder and prepare the TOC data
if (PrepareTOCData($source, $types)){
// showarray($docsTOC);
// We write the TOC
$ndocsintoc = WriteTOC("$destination/_TableOfContents.htm", 0);
// We claim victory
$plural = ($ndocsintoc > 1)?'s':'';
echo "<p style=\"font-family:Arial;font-size:10pt\">La table des matières a été générée dans '$destination' ($ndocsintoc document$plural dans le sommaire).</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">La table des matières n'a pas pu être générée à partir de '$destination'.</p>";
break;
case 1:
$extension = varfrompost('extension', '');
$toconly = varfrompost('toconly', 0);
$pack = basename($source);
$destination = "$source$extension";
$parts = $source.'/parts/';
$packname = '';
$ndocscopied = 0;
if (is_dir($parts)){ // the source folder contains a subfolder named 'parts'
if ($xmlTOC = GetXMLTOCFile($source)){ // the source folder contains a .xml file
if (!is_dir($destination)){ // the destination folder does not already exist
// First, we create the destination folder
mkdir($destination, 0700);
// Second, we prepare the table of contents
$docsTOC = array();// this array will contain the data for the html table of contents
ReadMainXMLTOC("$source/$xmlTOC");
foreach($docsTOC as $n => $data){
set_time_limit(0);
if ($data['ObjectType'] == 'Document')
ReadXMLFileData($n);
// showarray($docsTOC);
} // foreach
$ndocsintoc = WriteTOC("$destination/_TableOfContents.htm", 1);
// WriteTOC("$destination/_TableOfFiles.htm", 1);
// Third, we copy the pdf files
if ($toconly != 1){ // if we want only the TOC then no need to copy the files
foreach($docsTOC as $n => $data){
if ($data['ObjectType'] == 'Document'){
set_time_limit(0);
$pi = pathinfo($data['FileInfo']);
$file = isset($data['FILENAME'])?$data['FILENAME']:0;
if ($file && file_exists("$destination/$file"))
echo "<p style=\"font-family:Arial;font-size:10pt\">Attention, ce fichier est déjà copié: $file/".$data['LIBELLE'].'</p>';
if($file && !file_exists("$destination/$file") && copy($pi['dirname']."/files/$file" , "$destination/$file"))
$ndocscopied++;
} // if
} // foreach
} // if
// Fourth, we claim victory
$plural1 = ($ndocsintoc > 1)?'s':'';
$plural2 = ($ndocscopied > 1)?'s':'';
echo "<p style=\"font-family:Arial;font-size:10pt\">Le dossier '$pack$extension' est prêt ($ndocsintoc document$plural1 dans le sommaire, $ndocscopied document$plural2 copiés).</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier de destination existe déjà.</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Il n'y a pas de fichier XML dans le dossier source.</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier désigné n'est pas au bon format.</p>";
} // switch
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier désigné n'existe pas.</p>";
function WriteTOC($tocpath, $gerico = 0){
global $docsTOC, $packname;
$ndocs = 0;
$toc = fopen($tocpath, 'w+');
fwrite($toc, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
fwrite($toc, '<html>');
fwrite($toc, ' <style type="text/css">
a:hover {background-color:#DDDDFF;}
</style>');
fwrite($toc, "<body style=\"font-family:Arial;font-size:10pt\">");
fwrite($toc, "<p style=\"text-align:center;font-weight:bold;font-size:10pt;border-bottom:solid 1px black\">$packname</p>");
$headerstyle = 'style="padding:5px;height:20pt;font-size:11pt;color:white;background:blue;font-weight:bold;text-align:center"';
if ($gerico){
fwrite($toc, '<center><table style="width:100%;border:solid 1px lightgrey">');
fwrite($toc, "<tr><td width=\"60%\" $headerstyle>Title</td><td $headerstyle>File</td><td $headerstyle>Reference</td><td $headerstyle>Version</td><td $headerstyle>Date</td></tr>");
}
else {
fwrite($toc, '<center><table style="width:70%;border:solid 1px lightgrey">');
fwrite($toc, "<tr><td width=\"60%\" $headerstyle>Title</td><td $headerstyle>Reference</td><td $headerstyle>Version</td><td $headerstyle>Date</td></tr>");
}
$cellstyle = 'style="font-size:8pt;border-bottom:solid 1px lightgrey;padding:2px"';
$chapterstyle = 'style="background-color:lightyellow;font-weight:bold;font-size:9pt;border-bottom:solid 1px lightgrey"';
foreach($docsTOC as $n => $docdata){
fwrite($toc, '<tr>');
if ($docdata['ObjectType'] == 'Document'){
if (!isset($docdata['FILENAME'])){
$docfile = '';
echo '<p style=\"font-family:Arial;font-size:10pt\">Attention: pas de PDF pour le document '.$docdata['Label'].'</p>';
}
else {
$docfile = $docdata['FILENAME'];
$doclabel = $docdata['LIBELLE'];
if ($gerico)
fwrite($toc, "<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$doclabel."</a></td>
<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$docfile."</a></td>
<td $cellstyle align=\"center\">".$docdata['REF']."</td>
<td $cellstyle align=\"center\">".$docdata['INDMAJ'].'-'.$docdata['INDMIN']."</td>
<td $cellstyle align=\"center\">".$docdata['DATEVERSION'].'</td>');
else
fwrite($toc, "<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$doclabel."</a></td>
<td $cellstyle align=\"center\">".$docdata['REF']."</td>
<td $cellstyle align=\"center\">".$docdata['INDMAJ'].'-'.$docdata['INDMIN']."</td>
<td $cellstyle align=\"center\">".$docdata['DATEVERSION'].'</td>');
$ndocs++;
}
}
else
fwrite($toc, "<td colspan=\"5\" $chapterstyle>".$docdata['Label'].'</td>');
fwrite($toc, '</tr>');
} // foreach
fwrite($toc, '</table></center>');
$plural = ($ndocs>1)?'s':'';
fwrite($toc, '<br /><br /><p style="text-align:right;font-size:8pt;" colspan="4">Generated on '.date('r', time()).'<br />('.$ndocs.' document'.$plural.')</p>');
fwrite($toc, '<p style="text-align:center;font-size:8pt; border-top:solid 1px black">©Thales Alenia Space 2007</p>');
fwrite($toc, '</body>');
fwrite($toc, '</html>');
fclose($toc);
return $ndocs;
} // function WriteTOC
function PrepareTOCData ($source, $types){
global $docsTOC;
if (is_dir($source)){
$dh = opendir($source);
$n = 0;
while($file = readdir($dh)){
$info = pathinfo("$source/$file");
$ext = $info['extension'];
if (is_file("$source/$file") && in_array($ext, $types)){
$docsTOC[$n] = array( 'Label' => $file,
'ObjectType' => 'Document',
'LIBELLE' => $file,
'FILENAME' => $file,
'REF' => '-',
'INDMAJ' => '',
'INDMIN' => '',
'DATEVERSION' => date("d/m/Y", filemtime("$source/$file")));
$n++;
} // if
} // while
return true;
}
else
return false;
} // function PrepareTOCData
function TOCStartElement ($parser, $name, $attrs){
global $docsTOC, $source, $packname;
if ($name == 'CONFNODE'){
$docsTOC[] = array( 'Label' => CleanUpLabel($attrs['LABEL']),
'FileInfo' => "$source/". CleanUpLocation($attrs['RELATIVELOCATION']),
'ObjectType' => $attrs['OBJECTTYPE']
);
if ($attrs['OBJECTTYPE'] == 'Data Package')
$packname = CleanUpLabel($attrs['LABEL']);
} // if
} // function TOCStartElement
function endElement ($parser, $name){
} // function endElement
function ReadMainXMLTOC ($XMLFile) {
global $docsTOC ;
$xml_TOCparser = xml_parser_create();
xml_set_element_handler($xml_TOCparser, "TOCstartElement", "endElement");
if ($xmlp = fopen($XMLFile, "r")){
while ($data = fread($xmlp, 4096))
xml_parse($xml_TOCparser, $data, feof($xmlp));
fclose($xmlp);
}
else
echo "Le fichier '$XMLFile' n'existe pas.";
}//function ReadMainXML
function FILEStartElement ($parser, $name, $attrs){
global $docsTOC, $n ;
switch($name) {
case 'PROP':
switch($attrs['INTERNALNAME']){
case 'LIBELLE':
case 'REF':
case 'INDMAJ':
case 'INDMIN':
case 'DATEVERSION':
$docsTOC[$n][$attrs['INTERNALNAME']] = $attrs['VALUE'];
} // switch
break;
case 'DOC':
$file = $attrs['NAME'];
$path = pathinfo($file);
$ext = $path['extension'];
//if (($ext == 'pdf')||($ext == 'PDF'))
$docsTOC[$n]['FILENAME'] = $file;
} // switch
} // function FILEStartElement
function ReadXMLFileData ($n) {
global $docsTOC ;
$XMLFile = $docsTOC[$n]['FileInfo'];
$xml_TOCparser = xml_parser_create();
xml_set_element_handler($xml_TOCparser, "FILEstartElement", "endElement");
if ((file_exists($XMLFile)) && ($xmlp = fopen($XMLFile, "r"))){
while ($data = fread($xmlp, 4096))
xml_parse($xml_TOCparser, $data, feof($xmlp));
fclose($xmlp);
}
else
echo "Le fichier '$XMLFile' n'a pas pu être ouvert.";
}//function ReadMainXML
function GetXMLTOCFile ($path){
$h = opendir($path);
$result = '';
while((($file = readdir($h)) !== false) && ($result == '')) {
$info = pathinfo($file);
if (isset($info['extension']) &&($info['extension']== 'xml')){
$result = $info['basename'];
}
} // while
return $result;
} // function GetXMLTOCFile
function CleanUpLocation($filename){
$result = str_replace('%7B', '{', $filename);
$result = str_replace('%7D', '}', $result);
return $result;
} // function CleanUpLocation
function CleanUpLabel($label){
$result = ereg_replace('^[a-zA-Z0-9]+ \(', '', $label);
$result = str_replace(')', '', $result);
return $result;
} // function CleanUpLabel
?>
je laisse tel quel mais en mettant le php apres le ? il y a une fatal error ligne 5 qui n y etais pas
[php]
<?
include('../lib/GeneralUtils.inc');
$gerico = varfromget('gerico', 0);
$source = varfrompost('source', '');
if (is_dir($source)){ // the source folder exists
switch ($gerico) {
case 0:
$packname = varfrompost('title', '');
// list of accepted file types (in case of gerico = 0)
$types = array();
if(varfrompost('pdf', 0)){
$types[] = "pdf";
$types[] = "PDF";
}
if(varfrompost('doc', 0)){
$types[] = "doc";
$types[] = "DOC";
}
if(varfrompost('xls', 0)){
$types[] = "xls";
$types[] = "XLS";
}
if(varfrompost('ppt', 0)){
$types[] = "ppt";
$types[] = "PPT";
}
if(varfrompost('htm', 0)){
$types[] = "htm";
$types[] = "html";
}
if(varfrompost('jpg', 0)){
$types[] = "jpg";
$types[] = "JPG";
}
if(varfrompost('gif', 0)){
$types[] = "gif";
$types[] = "GIF";
}
if(varfrompost('tif', 0)){
$types[] = "tif";
$types[] = "tiff";
}
if(varfrompost('zip', 0)){
$types[] = "zip";
$types[] = "ZIP";
}
if(varfrompost('exe', 0)){
$types[] = "exe";
$types[] = "EXE";
}
$destination = $source;
$docsTOC = array();// this array will contain the data for the html table of contents
// We read the folder and prepare the TOC data
if (PrepareTOCData($source, $types)){
// showarray($docsTOC);
// We write the TOC
$ndocsintoc = WriteTOC("$destination/_TableOfContents.htm", 0);
// We claim victory
$plural = ($ndocsintoc > 1)?'s':'';
echo "<p style=\"font-family:Arial;font-size:10pt\">La table des matières a été générée dans '$destination' ($ndocsintoc document$plural dans le sommaire).</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">La table des matières n'a pas pu être générée à partir de '$destination'.</p>";
break;
case 1:
$extension = varfrompost('extension', '');
$toconly = varfrompost('toconly', 0);
$pack = basename($source);
$destination = "$source$extension";
$parts = $source.'/parts/';
$packname = '';
$ndocscopied = 0;
if (is_dir($parts)){ // the source folder contains a subfolder named 'parts'
if ($xmlTOC = GetXMLTOCFile($source)){ // the source folder contains a .xml file
if (!is_dir($destination)){ // the destination folder does not already exist
// First, we create the destination folder
mkdir($destination, 0700);
// Second, we prepare the table of contents
$docsTOC = array();// this array will contain the data for the html table of contents
ReadMainXMLTOC("$source/$xmlTOC");
foreach($docsTOC as $n => $data){
set_time_limit(0);
if ($data['ObjectType'] == 'Document')
ReadXMLFileData($n);
// showarray($docsTOC);
} // foreach
$ndocsintoc = WriteTOC("$destination/_TableOfContents.htm", 1);
// WriteTOC("$destination/_TableOfFiles.htm", 1);
// Third, we copy the pdf files
if ($toconly != 1){ // if we want only the TOC then no need to copy the files
foreach($docsTOC as $n => $data){
if ($data['ObjectType'] == 'Document'){
set_time_limit(0);
$pi = pathinfo($data['FileInfo']);
$file = isset($data['FILENAME'])?$data['FILENAME']:0;
if ($file && file_exists("$destination/$file"))
echo "<p style=\"font-family:Arial;font-size:10pt\">Attention, ce fichier est déjà copié: $file/".$data['LIBELLE'].'</p>';
if($file && !file_exists("$destination/$file") && copy($pi['dirname']."/files/$file" , "$destination/$file"))
$ndocscopied++;
} // if
} // foreach
} // if
// Fourth, we claim victory
$plural1 = ($ndocsintoc > 1)?'s':'';
$plural2 = ($ndocscopied > 1)?'s':'';
echo "<p style=\"font-family:Arial;font-size:10pt\">Le dossier '$pack$extension' est prêt ($ndocsintoc document$plural1 dans le sommaire, $ndocscopied document$plural2 copiés).</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier de destination existe déjà.</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Il n'y a pas de fichier XML dans le dossier source.</p>";
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier désigné n'est pas au bon format.</p>";
} // switch
}
else
echo "<p style=\"font-family:Arial;font-size:10pt\">Impossible de continuer: Le dossier désigné n'existe pas.</p>";
function WriteTOC($tocpath, $gerico = 0){
global $docsTOC, $packname;
$ndocs = 0;
$toc = fopen($tocpath, 'w+');
fwrite($toc, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
fwrite($toc, '<html>');
fwrite($toc, ' <style type="text/css">
a:hover {background-color:#DDDDFF;}
</style>');
fwrite($toc, "<body style=\"font-family:Arial;font-size:10pt\">");
fwrite($toc, "<p style=\"text-align:center;font-weight:bold;font-size:10pt;border-bottom:solid 1px black\">$packname</p>");
$headerstyle = 'style="padding:5px;height:20pt;font-size:11pt;color:white;background:blue;font-weight:bold;text-align:center"';
if ($gerico){
fwrite($toc, '<center><table style="width:100%;border:solid 1px lightgrey">');
fwrite($toc, "<tr><td width=\"60%\" $headerstyle>Title</td><td $headerstyle>File</td><td $headerstyle>Reference</td><td $headerstyle>Version</td><td $headerstyle>Date</td></tr>");
}
else {
fwrite($toc, '<center><table style="width:70%;border:solid 1px lightgrey">');
fwrite($toc, "<tr><td width=\"60%\" $headerstyle>Title</td><td $headerstyle>Reference</td><td $headerstyle>Version</td><td $headerstyle>Date</td></tr>");
}
$cellstyle = 'style="font-size:8pt;border-bottom:solid 1px lightgrey;padding:2px"';
$chapterstyle = 'style="background-color:lightyellow;font-weight:bold;font-size:9pt;border-bottom:solid 1px lightgrey"';
foreach($docsTOC as $n => $docdata){
fwrite($toc, '<tr>');
if ($docdata['ObjectType'] == 'Document'){
if (!isset($docdata['FILENAME'])){
$docfile = '';
echo '<p style=\"font-family:Arial;font-size:10pt\">Attention: pas de PDF pour le document '.$docdata['Label'].'</p>';
}
else {
$docfile = $docdata['FILENAME'];
$doclabel = $docdata['LIBELLE'];
if ($gerico)
fwrite($toc, "<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$doclabel."</a></td>
<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$docfile."</a></td>
<td $cellstyle align=\"center\">".$docdata['REF']."</td>
<td $cellstyle align=\"center\">".$docdata['INDMAJ'].'-'.$docdata['INDMIN']."</td>
<td $cellstyle align=\"center\">".$docdata['DATEVERSION'].'</td>');
else
fwrite($toc, "<td $cellstyle> <a style=\"text-decoration:none;\" href=\"".$docfile.'" title="open the document">'.$doclabel."</a></td>
<td $cellstyle align=\"center\">".$docdata['REF']."</td>
<td $cellstyle align=\"center\">".$docdata['INDMAJ'].'-'.$docdata['INDMIN']."</td>
<td $cellstyle align=\"center\">".$docdata['DATEVERSION'].'</td>');
$ndocs++;
}
}
else
fwrite($toc, "<td colspan=\"5\" $chapterstyle>".$docdata['Label'].'</td>');
fwrite($toc, '</tr>');
} // foreach
fwrite($toc, '</table></center>');
$plural = ($ndocs>1)?'s':'';
fwrite($toc, '<br /><br /><p style="text-align:right;font-size:8pt;" colspan="4">Generated on '.date('r', time()).'<br />('.$ndocs.' document'.$plural.')</p>');
fwrite($toc, '<p style="text-align:center;font-size:8pt; border-top:solid 1px black">©Thales Alenia Space 2007</p>');
fwrite($toc, '</body>');
fwrite($toc, '</html>');
fclose($toc);
return $ndocs;
} // function WriteTOC
function PrepareTOCData ($source, $types){
global $docsTOC;
if (is_dir($source)){
$dh = opendir($source);
$n = 0;
while($file = readdir($dh)){
$info = pathinfo("$source/$file");
$ext = $info['extension'];
if (is_file("$source/$file") && in_array($ext, $types)){
$docsTOC[$n] = array( 'Label' => $file,
'ObjectType' => 'Document',
'LIBELLE' => $file,
'FILENAME' => $file,
'REF' => '-',
'INDMAJ' => '',
'INDMIN' => '',
'DATEVERSION' => date("d/m/Y", filemtime("$source/$file")));
$n++;
} // if
} // while
return true;
}
else
return false;
} // function PrepareTOCData
function TOCStartElement ($parser, $name, $attrs){
global $docsTOC, $source, $packname;
if ($name == 'CONFNODE'){
$docsTOC[] = array( 'Label' => CleanUpLabel($attrs['LABEL']),
'FileInfo' => "$source/". CleanUpLocation($attrs['RELATIVELOCATION']),
'ObjectType' => $attrs['OBJECTTYPE']
);
if ($attrs['OBJECTTYPE'] == 'Data Package')
$packname = CleanUpLabel($attrs['LABEL']);
} // if
} // function TOCStartElement
function endElement ($parser, $name){
} // function endElement
function ReadMainXMLTOC ($XMLFile) {
global $docsTOC ;
$xml_TOCparser = xml_parser_create();
xml_set_element_handler($xml_TOCparser, "TOCstartElement", "endElement");
if ($xmlp = fopen($XMLFile, "r")){
while ($data = fread($xmlp, 4096))
xml_parse($xml_TOCparser, $data, feof($xmlp));
fclose($xmlp);
}
else
echo "Le fichier '$XMLFile' n'existe pas.";
}//function ReadMainXML
function FILEStartElement ($parser, $name, $attrs){
global $docsTOC, $n ;
switch($name) {
case 'PROP':
switch($attrs['INTERNALNAME']){
case 'LIBELLE':
case 'REF':
case 'INDMAJ':
case 'INDMIN':
case 'DATEVERSION':
$docsTOC[$n][$attrs['INTERNALNAME']] = $attrs['VALUE'];
} // switch
break;
case 'DOC':
$file = $attrs['NAME'];
$path = pathinfo($file);
$ext = $path['extension'];
//if (($ext == 'pdf')||($ext == 'PDF'))
$docsTOC[$n]['FILENAME'] = $file;
} // switch
} // function FILEStartElement
function ReadXMLFileData ($n) {
global $docsTOC ;
$XMLFile = $docsTOC[$n]['FileInfo'];
$xml_TOCparser = xml_parser_create();
xml_set_element_handler($xml_TOCparser, "FILEstartElement", "endElement");
if ((file_exists($XMLFile)) && ($xmlp = fopen($XMLFile, "r"))){
while ($data = fread($xmlp, 4096))
xml_parse($xml_TOCparser, $data, feof($xmlp));
fclose($xmlp);
}
else
echo "Le fichier '$XMLFile' n'a pas pu être ouvert.";
}//function ReadMainXML
function GetXMLTOCFile ($path){
$h = opendir($path);
$result = '';
while((($file = readdir($h)) !== false) && ($result == '')) {
$info = pathinfo($file);
if (isset($info['extension']) &&($info['extension']== 'xml')){
$result = $info['basename'];
}
} // while
return $result;
} // function GetXMLTOCFile
function CleanUpLocation($filename){
$result = str_replace('%7B', '{', $filename);
$result = str_replace('%7D', '}', $result);
return $result;
} // function CleanUpLocation
function CleanUpLabel($label){
$result = ereg_replace('^[a-zA-Z0-9]+ \(', '', $label);
$result = str_replace(')', '', $result);
return $result;
} // function CleanUpLabel
?>
[/php]