CARD : add button to epxort to PDF
This commit is contained in:
parent
b6b8c88041
commit
d9cf4cf71c
5 changed files with 123 additions and 1 deletions
|
|
@ -168,6 +168,12 @@ case 'dc':
|
|||
$html.=HtmlInput::submit('save',_('Sauver'));
|
||||
}
|
||||
if ( ! isset ($nohistory))$html.=HtmlInput::history_card_button($f->id,_('Historique'));
|
||||
$button_pdf=HtmlInput::button_anchor(_("PDF"),"export.php?".http_build_query([
|
||||
"act"=>"PDF:card",
|
||||
"card_id"=>$f->id,
|
||||
"gDossier"=>Dossier::id()
|
||||
]));
|
||||
$html.=$button_pdf;
|
||||
// Display a remove button if not used and can modify card
|
||||
if ( $can_modify == 1 && $f->is_used()==FALSE)
|
||||
{
|
||||
|
|
|
|||
71
include/class/card_pdf.class.php
Normal file
71
include/class/card_pdf.class.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @class
|
||||
* @brief Class Card_PDF
|
||||
*/
|
||||
class Card_PDF extends \PDF
|
||||
{
|
||||
private $card;
|
||||
function __construct($p_card_id)
|
||||
{
|
||||
global $cn;
|
||||
$this->card=new \Fiche ($cn,$p_card_id);
|
||||
$this->card->load();
|
||||
parent::__construct($cn, "P");
|
||||
$this->setDossierInfo($this->card->strAttribut(ATTR_DEF_QUICKCODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCardId()
|
||||
{
|
||||
return $this->card->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $card_id
|
||||
*/
|
||||
public function setCardId($card_id)
|
||||
{
|
||||
$this->card->set_id($card_id);
|
||||
$this->card->load();
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$nb_attribut = count($this->card->attribut);
|
||||
// var_dump(
|
||||
// $this->card->attribut
|
||||
// );
|
||||
if ($nb_attribut == 0) {
|
||||
throw new \Exception(_("card_pdf.044 , card_inexistante"));
|
||||
}
|
||||
$this->setTitle($this->card->get_quick_code()." ".strtoupper($this->card->strAttribut(1))
|
||||
." ".$this->card->strAttribut(32), true);
|
||||
$this->SetAuthor('NOALYSS');
|
||||
$this->AliasNbPages();
|
||||
$this->AddPage();
|
||||
|
||||
$this->setFont("DejaVu", '', 7);
|
||||
$this->SetDrawColor(214, 209, 209);
|
||||
for ($i=0;$i<$nb_attribut;$i++)
|
||||
{
|
||||
$border="B";
|
||||
$this->write_cell(60,5,$this->card->attribut[$i]->ad_text,$border);
|
||||
$this->write_cell(100,5,$this->card->attribut[$i]->av_text,$border);
|
||||
$this->line_new(5);
|
||||
}
|
||||
|
||||
|
||||
$filename=$this->card->strAttribut(1)."-".$this->card->strAttribut(32).".pdf";
|
||||
$filename=sanitize_filename($filename);
|
||||
$this->Output($filename,"D");
|
||||
}
|
||||
|
||||
}
|
||||
16
include/export/export_card_pdf.php
Normal file
16
include/export/export_card_pdf.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/***
|
||||
* @file
|
||||
* @brief output a PDF with card info
|
||||
*
|
||||
*/
|
||||
try {
|
||||
$http=new \HttpInput();
|
||||
$card_id=$http->get("card_id");
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage();
|
||||
die();
|
||||
}
|
||||
|
||||
$card_pdf=new \Card_PDF($card_id);
|
||||
$card_pdf->export();
|
||||
|
|
@ -1773,4 +1773,30 @@ function generate_random_password($car):string
|
|||
// echo $string."\n";
|
||||
}while ( count(check_password_strength($string)['msg'])> 0 && $loop<$max_loop);
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief removed invalid character when computing a filename, the suffix is kept
|
||||
* @param $filename String filename to sanitize
|
||||
* @return string without offending char
|
||||
*/
|
||||
function sanitize_filename($filename)
|
||||
{
|
||||
// save the suffix
|
||||
$pos_prefix=strrpos($filename, ".");
|
||||
if ($pos_prefix==0)
|
||||
{
|
||||
$filename_suff=".pdf";
|
||||
$filename.=$filename_suff;
|
||||
$pos_prefix=strrpos($filename, ".");
|
||||
}
|
||||
else
|
||||
$filename_suff=substr($filename, $pos_prefix, strlen($filename));
|
||||
|
||||
$filename=str_replace(array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']'), "-", $filename);
|
||||
|
||||
$filename_no=substr($filename, 0, $pos_prefix);
|
||||
|
||||
$new_filename=strtolower($filename_no)."-".date("Ymd-Hi").$filename_suff;
|
||||
return $new_filename;
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ begin
|
|||
end;
|
||||
$function$
|
||||
;
|
||||
|
||||
²
|
||||
|
||||
create trigger t_remove_script_tag before
|
||||
insert
|
||||
|
|
@ -20,4 +20,7 @@ create trigger t_remove_script_tag before
|
|||
on
|
||||
public.action_gestion_comment for each row execute function comptaproc.trg_remove_script_tag();
|
||||
|
||||
INSERT INTO public.menu_ref (me_code,me_menu,me_file,me_url,me_description,me_parameter,me_javascript,me_type,me_description_etendue) VALUES
|
||||
('PDF:card','export Fiche détail PDF','export_card_pdf.php',NULL,NULL,NULL,NULL,'PR',NULL);
|
||||
|
||||
insert into public.profile_menu (me_code,p_id,p_type_display) select 'PDF:card',p_id,'P' from profile;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue