noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 33/38: CARD : add button to epxort to PDF


From: dwm
Subject: [Noalyss-commit] [noalyss] 33/38: CARD : add button to epxort to PDF
Date: Sun, 18 Feb 2024 07:30:48 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit d9cf4cf71c5072b285a768f85545a2bd6a29db29
Author: Dany wm <danydb@noalyss.eu>
AuthorDate: Sat Feb 17 15:47:57 2024 +0100

    CARD : add button to epxort to PDF
---
 include/ajax/ajax_card.php         |  6 ++++
 include/class/card_pdf.class.php   | 71 ++++++++++++++++++++++++++++++++++++++
 include/export/export_card_pdf.php | 16 +++++++++
 include/lib/ac_common.php          | 26 ++++++++++++++
 sql/upgrade.sql                    |  5 ++-
 5 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index 22ca1c2e5..f354f4f33 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -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)
             {
diff --git a/include/class/card_pdf.class.php b/include/class/card_pdf.class.php
new file mode 100644
index 000000000..3618d4431
--- /dev/null
+++ b/include/class/card_pdf.class.php
@@ -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");
+    }
+
+}
\ No newline at end of file
diff --git a/include/export/export_card_pdf.php 
b/include/export/export_card_pdf.php
new file mode 100644
index 000000000..795f979d5
--- /dev/null
+++ b/include/export/export_card_pdf.php
@@ -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();
\ No newline at end of file
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 88e95ed7f..cf1fc109d 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -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;
 }
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 38c2e620c..37c18bc69 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]