Topic: Single, double quotes and other special characters replacements

The way fa insets/updates data in the database is by replacing special characters with their HTML entities equivalents, for example:
& will be converted to &
> will be converted to >
" will be converted to "
The problem is that when the data containing these html entities is pulled from the database for reporting, the output pdf file is using these HTML entities and not the original characters.
Every single quote is becoming ' so for example the item description: a package of 100' hose becomes: package of 100' hose.
any ideas hoe this can be solved?
I'm using version 2.3.25

2 (edited by apmuthu 06/04/2016 06:01:32 am)

Re: Single, double quotes and other special characters replacements

A full list is here.

A complete search and replace in the database is in order for such fields.
This is a known issue atleast in FA 2.3.

Re: Single, double quotes and other special characters replacements

Yes I was afraid that this will be the sole solution.
Any available script to do the job?

Re: Single, double quotes and other special characters replacements

There is some code in FA where Polish characters are spared. Checkout includes/session.inc lines 312-332 in FA 2.3:

function html_cleanup(&$parms)
{
    foreach($parms as $name => $value) {
//        $value = @html_entity_decode($value, ENT_QUOTES, $_SESSION['language']->encoding);
        if (is_array($value))
            html_cleanup($parms[$name]);
        else
            $parms[$name] = @htmlspecialchars($value, ENT_QUOTES, $_SESSION['language']->encoding=='iso-8859-2' ? 'ISO-8859-1' : $_SESSION['language']->encoding);
    }
    reset($parms); // needed for direct key() usage later throughout the sources
}

Re: Single, double quotes and other special characters replacements

Thanks.
I solved it by alternating some code in pdf_report.inc, using  html_entity_decode

6 (edited by apmuthu 06/12/2016 05:38:12 pm)

Re: Single, double quotes and other special characters replacements

Kindly provide code changes that worked.
It may be necessary to make the storage in the tables proper so that they do not get encoded multiple times like & => & amp; => & amp;amp; etc.

Re: Single, double quotes and other special characters replacements

Several steps:

1. Make sure the data in the database is inserted as utf8 so it'll be readable.
In includes/db/connect_db.inc:
In function set_global_connection() line #13 before returning $db:
+ mysql_set_charset("utf8", $db);

2. In order to get rid of all the HTML entities.
In reporting/includes/pdf_report.inc:

In function Text() line #732 at first line of the fubction:
+ $txt = html_entity_decode($txt);

In function function TextWrap() about line #743, after $str = strtr($str array("\r"=>''));
+ $str = html_entity_decode($str);

In function End() about line #953:

In about line #953:
- $mail = new email(str_replace(",", "", $this->company['coy_name']),
              $this->company['email']);

+ $mail = new email(str_replace(",", "", html_entity_decode($this->company['coy_name'])),
              $this->company['email']);
             
In about line #1036:         

- $sender = $this->user . "\n" . $this->company['coy_name'] . "\n" . $this->company['postal_address'] . "\n" . $this->company['email'] . "\n" . $this->company['phone'];

+ $sender = html_entity_decode($this->user) . "\n" . html_entity_decode($this->company['coy_name']) . "\n" . html_entity_decode($this->company['postal_address']) . "\n" . $this->company['email'] . "\n" . html_entity_decode($this->company['phone']);

I hope it'll help.

Re: Single, double quotes and other special characters replacements

@joe: what parts need to make it to the core?

Re: Single, double quotes and other special characters replacements

@apmuthu.
Please address this to Janusz. I am out of office until June 18.

Joe