noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 18/30: Follow Up : can use enrich text for Co


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 18/30: Follow Up : can use enrich text for Comment and description
Date: Sat, 3 Dec 2022 08:35:12 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 789f073f5d1f9c81becd1597d0a76582e4294a30
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Nov 27 16:57:52 2022 +0100

    Follow Up : can use enrich text for Comment and description
---
 html/js/nicEdit.js                                 |  7 +-
 include/class/follow_up.class.php                  | 80 +++++++++++++++----
 include/lib/http_input.class.php                   |  5 +-
 include/lib/itextarea.class.php                    | 89 ++++++++++++++++++----
 include/sql/patch/upgrade180.sql                   |  7 ++
 include/sql/patch/upgrade181.sql                   |  8 +-
 .../{detail-action.php => follow_up-display.php}   | 25 +++---
 7 files changed, 177 insertions(+), 44 deletions(-)

diff --git a/html/js/nicEdit.js b/html/js/nicEdit.js
index b1e3de13d..a4af59f60 100644
--- a/html/js/nicEdit.js
+++ b/html/js/nicEdit.js
@@ -1163,13 +1163,14 @@ var nicEditorFontFamilySelect = nicEditorSelect.extend({
 });
 
 var nicEditorFontFormatSelect = nicEditorSelect.extend({
-               sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h6' : 
'Heading&nbsp;6', 'h5' : 'Heading&nbsp;5', 'h4' : 'Heading&nbsp;4', 'h3' : 
'Heading&nbsp;3', 'h2' : 'Heading&nbsp;2', 'h1' : 'Heading&nbsp;1'},
-               
+       /** original selection up to 6*/
+       // sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h1' : '1 Heading ', 'h2' : 
'2 Heading', 'h3' : '3 Heading', 'h4' : '4 Heading', 'h5' : '5 Heading', 'p6' : 
'6 Heading'},
+       sel : {'p' : 'Paragraph', 'pre' : 'Pre', 'h1' : '1 Heading ', 'h2' : '2 
Heading', 'h3' : '3 Heading', 'h4' : '4 Heading'},
        init : function() {
                this.setDisplay('Font&nbsp;Format...');
                for(itm in this.sel) {
                        var tag = itm.toUpperCase();
-                       this.add('<'+tag+'>','<'+itm+' style="padding: 0px; 
margin: 0px;">'+this.sel[itm]+'</'+tag+'>');
+                       this.add('<'+tag+'>',this.sel[itm]);
                }
        }
 });
diff --git a/include/class/follow_up.class.php 
b/include/class/follow_up.class.php
index ef8ee514f..c1eedd534 100644
--- a/include/class/follow_up.class.php
+++ b/include/class/follow_up.class.php
@@ -63,7 +63,7 @@ class Follow_Up
     var $ag_contact;  /*!< $ag_contact contact */
     var $ag_remind_date;  /*!< $ag_contact contact */
     var $f_id_dest ; /*!< followup action recipient */
-    var $ag_description; /*!< description of the action */
+    var $ag_description; /*!< description of the action with HTML tag*/
     /**
      * @brief $operation string related operation
      */
@@ -90,6 +90,32 @@ class Follow_Up
         $this->f_dest_id=0;
         $this->f_id_dest=0;
     }
+
+    public function __toString(): string
+    {
+        $r  = " Follow_Up object =>";
+        $r .= 'ag_timestamp = ['. $this->ag_timestamp.']';
+        $r .= 'dt_id = ['. $this->dt_id.']';
+        $r .= 'ag_state = ['. $this->ag_state.']';
+        $r .= 'd_number = ['. $this->d_number.']';
+        $r .= 'd_filename = ['. $this->d_filename.']';
+        $r .= 'd_mimetype = ['. $this->d_mimetype.']';
+        $r .= 'ag_title = ['. $this->ag_title.']';
+        $r .= 'f_id = ['. $this->f_id.']';
+        $r .= 'ag_ref = ['. $this->ag_ref.']';
+        $r .= 'ag_hour = ['. $this->ag_hour.']';
+        $r .= 'ag_priority = ['. $this->ag_priority.']';
+        $r .= 'ag_dest = ['. $this->ag_dest.']';
+        $r .= 'ag_contact = ['. $this->ag_contact.']';
+        $r .= 'ag_remind_date = ['. $this->ag_remind_date.']';
+        $r .= 'f_id_dest = ['. $this->f_id_dest.']';
+        $r .= 'ag_description = ['. $this->ag_description.']';
+
+        return $r;
+
+    }
+
+
     /**
      * Create a filter based on the current user, 
      * @remark type $g_user Connected user
@@ -186,10 +212,11 @@ class Follow_Up
 
         // Description
         $desc=new ITextArea();
+        $desc->set_enrichText("enrich");
         $desc->style=' class="itextarea" style="width:80%;margin-left:0px"';
         $desc->name="ag_comment";
         $desc->readOnly=$readonly;
-        $acomment=$this->db->get_array("SELECT agc_id, ag_id, 
to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, tech_user
+        $acomment=$this->db->get_array("SELECT agc_id, ag_id, 
to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, 
agc_comment_raw,tech_user
                                 FROM action_gestion_comment where ag_id=$1 
order by agc_id", array($this->ag_id)
         );
 
@@ -422,7 +449,7 @@ class Follow_Up
         $menu=new Default_Menu();
         /* get template */
         ob_start();
-        require NOALYSS_TEMPLATE.'/detail-action.php';
+        require NOALYSS_TEMPLATE.'/follow_up-display.php';
         $content=ob_get_contents();
         ob_end_clean();
         $r.=$content;
@@ -581,13 +608,13 @@ class Follow_Up
         $doc->upload($this->ag_id);
         if (trim($this->ag_comment)!='' && 
Document_Option::can_add_comment($this->ag_id))
         {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
$this->ag_comment));
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3)"
+                , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
strip_tags($this->ag_description),$this->ag_comment));
         }
         if (trim($this->ag_description)!='' && 
Document_Option::can_add_comment($this->ag_id))
         {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
$this->ag_description));
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3)"
+                , array($this->ag_id, 
$_SESSION[SESSION_KEY.'g_user'],strip_tags($this->ag_description), 
$this->ag_description));
         }
         $this->insert_operation();
         $this->insert_action();
@@ -782,7 +809,31 @@ class Follow_Up
     }
 
     //----------------------------------------------------------------------
-    /*     * \brief Update the data into the database
+    /**
+     * \brief Update the data into the database, the field ag_description 
could contain some HTML tags and must be
+     * saved in 2 column : one without formatting , one with.
+     * @code
+    [p_jrn] =>
+    [sa] =>
+    [gDossier] => 25
+    [p_jrn_deb_max_line] => 10
+    [p_ech_lib] => echeance
+    [p_jrn_type] => FIN
+    [p_jrn_name] => Financier
+    [bank] => COMPTE
+    [min_row] => 5
+    [p_description] => Concerne tous les mouvements financiers (comptes en 
banque, caisses, visa...)
+    [jrn_def_pj_pref] => FIN
+    [jrn_def_pj_seq] => 0
+    [jrn_enable] => 1
+    [FIN_FICHEDEB] => (fd_id  )
+    [defaultCurrency]
+     *
+    [action_frm] => update
+     @endcode
+     *
+     * @note [defaultCurrency] => 0 exists in the array if the bank account 
has no operation and the currency can
+     * be set
      *
      * \return true on success otherwise false
      */
@@ -904,13 +955,14 @@ class Follow_Up
         }
         if (trim($this->ag_comment)!='')
         {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                    , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
$this->ag_comment));
+            $notag_comment=strip_tags($this->ag_comment);
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3,$4)"
+                    , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
$notag_comment,$this->ag_comment));
         }
         if (trim($this->ag_description)!='')
         {
-            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment) values ($1,$2,$3)"
-                    , array($this->ag_id, $_SESSION[SESSION_KEY.'g_user'], 
$this->ag_description));
+            $this->db->exec_sql("insert into action_gestion_comment 
(ag_id,tech_user,agc_comment,agc_comment_raw) values ($1,$2,$3,$4)"
+                    , array($this->ag_id, 
$_SESSION[SESSION_KEY.'g_user'],strip_tags($this->ag_description), 
$this->ag_description));
         }
         $this->insert_operation();
         $this->insert_action();
@@ -971,8 +1023,8 @@ class Follow_Up
         
$this->ag_dest=$http->extract("ag_dest","string",$g_user->get_profile());
         $this->ag_priority=$http->extract("ag_priority","string","2");
         $this->ag_contact=$http->extract("ag_contact","string","");
-        $this->ag_comment=$http->extract("ag_comment","string","");
-        $this->ag_description=$http->extract("ag_description","string","");
+        $this->ag_comment=$http->extract("ag_comment","raw","");
+        $this->ag_description=$http->extract("ag_description","raw","");
         $this->ag_remind_date=$http->extract("ag_remind_date","string",null);
         $this->operation=$http->extract("operation","string",null);
         $this->action=$http->extract("action","string",null);
diff --git a/include/lib/http_input.class.php b/include/lib/http_input.class.php
index 7525a4894..56a3676c0 100644
--- a/include/lib/http_input.class.php
+++ b/include/lib/http_input.class.php
@@ -119,6 +119,9 @@ class HttpInput
                 }
                 $this->array[$p_name]=h($this->array[$p_name]);
             }
+            else if ($p_type=="raw") {
+                /* NoOperation*/
+            }
             else if ($p_type=="array")
             {
                  if ( empty($this->array[$p_name]) )
@@ -159,7 +162,7 @@ class HttpInput
                 if (array_key_exists($p_name,$this->array) )
                 {
                     $this->check_type($p_name, $p_type);
-                   if ( is_string($this->array[$p_name]) ) return 
preg_replace("/</","< ", $this->array[$p_name]);
+                   if ($p_type != 'raw' && is_string($this->array[$p_name]) ) 
return preg_replace("/</","< ", $this->array[$p_name]);
                    return $this->array[$p_name];
                 }
                 else
diff --git a/include/lib/itextarea.class.php b/include/lib/itextarea.class.php
index e76b6a7d0..3d70aa61b 100644
--- a/include/lib/itextarea.class.php
+++ b/include/lib/itextarea.class.php
@@ -29,22 +29,73 @@
  */
 class ITextarea extends HtmlInput
 {
-    /*!\brief show the html  input of the widget*/
+    private $enrichText;
+    function __construct($p_name = "", $p_value = "", $p_id = "")
+    {
+        parent::__construct($p_name, $p_value, $p_id);
+        $this->style=' class="itextarea" ';
+        $this->enrichText="plain";
+    }
+
+    /**
+     * @brief return if enrichText is set to true or false
+     * @return mixed
+     */
+    public function get_enrichText()
+    {
+        return $this->enrichText;
+    }
+
+    /**
+     * @brief set enrichText  to plain or enrich , enrich for WYSIWYG 
function, plain, plain textarea and choose
+     * to display a button to switch to a WYSIWYG
+     * @param mixed $enrich
+     */
+    public function set_enrichText($enrich)
+    {
+        if ( ! in_array($enrich,['plain','enrich'])) {
+            throw new \Exception("IT57.Invalid option");
+        }
+        $this->enrichText = $enrich;
+        return $this;
+    }
+
+    /*!\brief show the html  input of the widget
+     * // style example style="height:15em;width: 80vw
+    */
     public function input($p_name=null,$p_value=null)
     {
-        $this->name=($p_name==null)?$this->name:$p_name;
-        $this->value=($p_value==null)?$this->value:$p_value;
-       if ( !isset ($this->style )) $this->style=' class="itextarea" ';
-       $this->id=($this->id=="")?$this->name:$this->id;
+        if ( $this->enrichText == "plain" ) {
+            $this->name=($p_name==null)?$this->name:$p_name;
+            $this->value=($p_value==null)?$this->value:$p_value;
+            $this->id=($this->id=="")?$this->name:$this->id;
 
-        if ( $this->readOnly==true) return $this->display();
+            if ( $this->readOnly==true) return $this->display();
 
-        $r="";
-        $r.='<TEXTAREA '.$this->style.'  name="'.$this->name.'" 
id="'.$this->id.'"';
-        $r.='>';
-        $r.=$this->value;
+            $r="";
+            $r.='<TEXTAREA '.$this->style.'  name="'.$this->name.'" 
id="'.$this->id.'"';
+            $r.='>';
+            $r.=$this->value;
+
+            $r.="</TEXTAREA>";
+        } elseif ($this->enrichText=='enrich') {
+            if ( empty($this->id)) $this->id=$this->name;
+
+            $r=<<<EOF
+            <textarea name="{$this->name}" id="{$this->id}" 
{$this->style}>{$this->value}</textarea>
+<script type="text/javascript">
+                (function() {
+                    new nicEditor({
+                        buttonList : 
['fontSize','fontFamily','fontFormat','bold','italic','underline',
+                        
'strikethrough','subscript','superscript','link','unlink','bgcolor','forecolor','indent','outdent','ol',
+                        
'ul','left','center','right','justify','hr','removeformat'],
+                        'iconsPath': 'image/nicEditorIcons.gif'
+                    }).panelInstance('{$this->id}');
+                })();
+            </script>
+EOF;
+        }
 
-        $r.="</TEXTAREA>";
         return $r;
     }
 
@@ -52,11 +103,17 @@ class ITextarea extends HtmlInput
     /*!\brief print in html the readonly value of the widget*/
     public function display()
     {
-        $r='<p>';
-        $r.=h($this->value);
-        $r.=sprintf('<input type="hidden" name="%s" value="%s">',
-                    $this->name,h($this->value));
-        $r.='</p>';
+        if ( $this->enrichText=="plain")
+        {
+            $r='<p>';
+            $r.=h($this->value);
+            $r.=sprintf('<input type="hidden" name="%s" value="%s">',
+                        $this->name,h($this->value));
+            $r.='</p>';
+        } elseif ($this->enrichText=='enrich')  {
+            $r=$this->value;
+        }
+        return $r;
 
     }
     static public function test_me()
diff --git a/include/sql/patch/upgrade180.sql b/include/sql/patch/upgrade180.sql
index 0ba2b9712..f556cb3ab 100644
--- a/include/sql/patch/upgrade180.sql
+++ b/include/sql/patch/upgrade180.sql
@@ -1,5 +1,12 @@
 begin;
 insert into menu_default (md_code,me_code)values 
('code_feenote','COMPTA/MENUACH/ACH');
 
+insert into document_option (do_code,document_type_id,do_enable)
+select 'make_feenote',10,1 from "document_type" where dt_id=10
+on conflict on constraint document_option_un
+    do update set do_enable=1
+;
+
+
 insert into version (val,v_description) values (181,'Make feenote from 
Management');
 commit;
diff --git a/include/sql/patch/upgrade181.sql b/include/sql/patch/upgrade181.sql
index 137335a52..ccf445a60 100644
--- a/include/sql/patch/upgrade181.sql
+++ b/include/sql/patch/upgrade181.sql
@@ -7,5 +7,11 @@ alter table operation_tag add constraint tag_operation_uq 
unique (jrn_id,tag_id)
 -- remove duplicate
 delete from operation_tag where opt_id in (select a.opt_id from operation_tag 
a join operation_tag b on (a.jrn_id=b.jrn_id and a.tag_id=b.tag_id) where 
a.opt_id  < b.opt_id );
 
-insert into version (val,v_description) values (182,'Prevent to add several 
time same tag on an operation');
+
+alter table action_gestion_comment add agc_comment_raw text;
+
+update action_gestion_comment set agc_comment_raw =agc_comment;
+
+
+insert into version (val,v_description) values (182,'Prevent to add several 
time same tag on an operation, action_comment formatting');
 commit;
\ No newline at end of file
diff --git a/include/template/detail-action.php 
b/include/template/follow_up-display.php
similarity index 95%
rename from include/template/detail-action.php
rename to include/template/follow_up-display.php
index 8bcab2cfb..faf7b8e78 100644
--- a/include/template/detail-action.php
+++ b/include/template/follow_up-display.php
@@ -260,7 +260,7 @@ function small(p_id_textarea){
     <?php echo $title->input();
     ?>
 </p>
-    <div>
+    <div class="nicEdit-main">
         <?php 
 
/**********************************************************************************************************************
  * Start BLOCK Comment and description
@@ -270,6 +270,7 @@ function small(p_id_textarea){
    $style_enl='style="display:inline"';$style_small='style="display:none"';
    // description
    $description = new ITextarea("ag_description");
+   $description->set_enrichText("enrich");
    $description->id="ag_description";
    $has_description = false;
     //---------------------------------- Description 
-------------------------------------------------------------------
@@ -298,15 +299,18 @@ function small(p_id_textarea){
             elseif ($p_view == 'READ' || $editable_description == false)
             {
                 echo h2(_("Description"));
-                echo '<pre class="field_follow_up">';
-                $comment_http= h($acomment[0]['agc_comment']);
-                $comment_http=add_http_link($comment_http);
-                echo $comment_http;
+                echo '<div class="nicEdit-main field_follow_up">';
+                echo $acomment[0]['agc_comment_raw'];
+                echo '</div>';
                 echo '</pre>';
             }
     } else {
           echo h2(_("Description"));
+          $description->set_enrichText('enrich');
+          $description->style='style="height:250px;width:90%;"';
+          echo '<div class="textarea" style="margin-left:5%;margin-right:5%">';
           echo $description->input();
+          echo '</div>';
    }
 
 
@@ -340,10 +344,13 @@ function small(p_id_textarea){
                 echo $comment->display();
             }
         } else {
+            // new comment
             echo '<span class="noprint">';
             if (  $p_view == 'UPD' &&  $has_description && 
Document_Option::can_add_comment($ag_id) )  {
                 echo h2(_("Commentaire"));
                 echo '<p></p>';
+                // if comment are editable it will be in
+                if ( Document_Option::option_comment($this->dt_id) == 
"ONE_EDIT") $desc->set_enrichText("plain");
                 echo $desc->input();
 
             }
@@ -368,8 +375,8 @@ function small(p_id_textarea){
                 $js=Icon_Action::trash("accom".$acomment[$c]['agc_id'], 
$rmComment);
                 $comment= h($m_desc.' 
'.$acomment[$c]['agc_id'].'('.$acomment[$c]['tech_user']." ".
                         $acomment[$c]['str_agc_date'].')').$js.
-                                '<pre class="field_follow_up" 
id="com'.$acomment[$c]['agc_id'].'"> '.
-                                " 
".add_http_link(h($acomment[$c]['agc_comment'])).'</pre>'
+                                '<div class="nicEdit-main field_follow_up" 
id="com'.$acomment[$c]['agc_id'].'"> '.
+                                " ".$acomment[$c]['agc_comment_raw'].'</div>'
                                 ;
 
             }
@@ -377,8 +384,8 @@ function small(p_id_textarea){
             {
                     $comment=h($m_desc.' 
'.$acomment[$c]['agc_id'].'('.$acomment[$c]['tech_user']." ".
                             $acomment[$c]['str_agc_date'].')').
-                                    '<pre class="field_follow_up" 
id="com'.$acomment[$c]['agc_id'].'"> '.
-                                    " 
".add_http_link(h($acomment[$c]['agc_comment'])).'</pre>'
+                                    '<div class="field_follow_up" 
id="com'.$acomment[$c]['agc_id'].'"> '.
+                                    " 
".$acomment[$c]['agc_comment_raw'].'</div>'
                                     ;
 
 



reply via email to

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