New: La fonction supprimer le PDF généré, depuis le cartouche des fichiers, est ok (Nécessite droit supprimer sur l'objet).

This commit is contained in:
Laurent Destailleur 2006-06-10 18:43:11 +00:00
parent f9b097dfde
commit 9e7499d522
5 changed files with 83 additions and 61 deletions

View File

@ -219,13 +219,6 @@ if ($_POST['action'] == 'add')
} }
} }
if ($_GET['action'] == 'builddoc')
{
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
}
/* /*
* Cloture de la propale * Cloture de la propale
*/ */
@ -428,11 +421,15 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
} }
if ($_POST['action'] == 'builddoc' && $user->rights->propale->creer) /*
* Generation doc (depuis lien ou depuis cartouche doc)
*/
if ($_REQUEST['action'] == 'builddoc' && $user->rights->propale->creer)
{ {
$propal = new Propal($db, 0, $_GET['propalid']); $propal = new Propal($db);
$propal->set_pdf_model($user, $_POST['model']); $propal->fetch($_GET['propalid']);
propale_pdf_create($db, $_GET['propalid'], $_POST['model']); if ($_POST['model']) $propal->set_pdf_model($user, $_POST['model']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
} }
@ -831,7 +828,6 @@ if ($_GET['propalid'] > 0)
/* /*
* Lignes de propale * Lignes de propale
*
*/ */
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';

View File

@ -2047,8 +2047,7 @@ else
$filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref); $filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
$urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id; $urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
$genallowed=($fac->statut == 1 && $user->rights->facture->creer); $genallowed=($fac->statut == 1 && $user->rights->facture->creer);
// $delallowed=$user->rights->facture->supprimer; $delallowed=$user->rights->facture->supprimer;
$delallowed=0;
$var=true; $var=true;

View File

@ -36,8 +36,10 @@ require_once("main.inc.php");
function llxHeader() { } function llxHeader() { }
$action = $_GET["action"];
$original_file = urldecode($_GET["file"]); $original_file = urldecode($_GET["file"]);
$modulepart = urldecode($_GET["modulepart"]); $modulepart = urldecode($_GET["modulepart"]);
$urlsource = urldecode($_GET["urlsource"]);
// Défini type et attachment // Défini type et attachment
$type = urldecode($_GET["type"]); $attachment = true; $type = urldecode($_GET["type"]); $attachment = true;
if (eregi('\.html',$original_file)) { $type='text/html'; $attachment = false; } if (eregi('\.html',$original_file)) { $type='text/html'; $attachment = false; }
@ -260,28 +262,53 @@ if (! $accessallowed)
} }
// Ouvre et renvoi fichier if ($action == 'remove_file')
clearstatcache();
$filename = basename($original_file);
dolibarr_syslog("document.php download $original_file $filename content-type=$type");
if (! file_exists($original_file))
{ {
/*
* Suppression fichier
*/
clearstatcache();
$filename = basename($original_file);
dolibarr_syslog("document.php remove $original_file $filename $urlsource");
if (! file_exists($original_file))
{
dolibarr_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); dolibarr_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
exit; exit;
}
unlink($original_file);
Header("Location: ".urldecode($urlsource));
return;
}
else
{
/*
* Ouvre et renvoi fichier
*/
clearstatcache();
$filename = basename($original_file);
dolibarr_syslog("document.php download $original_file $filename content-type=$type");
if (! file_exists($original_file))
{
dolibarr_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file));
exit;
}
// Les drois sont ok et fichier trouvé, on l'envoie
if ($type) header('Content-type: '.$type);
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
// Ajout directives pour résoudre bug IE
header('Cache-Control: Public, must-revalidate');
header('Pragma: public');
readfile($original_file);
} }
// Les drois sont ok et fichier trouvé, on l'envoie
if ($type) header('Content-type: '.$type);
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
// Ajout directives pour résoudre bug IE
header('Cache-Control: Public, must-revalidate');
header('Pragma: public');
readfile($original_file);
?> ?>

View File

@ -2537,7 +2537,7 @@ class Form
if ($delallowed) if ($delallowed)
{ {
print '<td><a href="'.$urlsource.'&action=remove_file&modulepart='.$modulepart.'&file='.urlencode($relativepath).'">'.img_delete().'</a></td>'; print '<td><a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&modulepart='.$modulepart.'&file='.urlencode($relativepath).'&urlsource='.urlencode($urlsource).'">'.img_delete().'</a></td>';
} }
print '</tr>'; print '</tr>';

View File

@ -1141,22 +1141,22 @@ class Propal
} }
} }
/* /**
* * \brief Positionne modele derniere generation
* * \param user Objet use qui modifie
* * \param modelpdf Nom du modele
*/ */
function set_pdf_model($user, $modelpdf) function set_pdf_model($user, $modelpdf)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET model_pdf = '".$modelpdf."'";
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET model_pdf = '$modelpdf'"; if ($this->db->query($sql))
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) )
{ {
$this->modelpdf=$modelpdf;
return 1; return 1;
} }
else else