.. ==================================================
.. ==================================================
.. ==================================================
.. Header hierarchy
.. ==
..  --
..   ^^
..    ""
..     ;;
..      ,,
..
.. --------------------------------------------used to the update the records specified ------
.. Best Practice T3 reST: https://docs.typo3.org/m/typo3/docs-how-to-document/master/en-us/WritingReST/CheatSheet.html
..             Reference: https://docs.typo3.org/m/typo3/docs-how-to-document/master/en-us/WritingReST/Index.html
.. Italic *italic*
.. Bold **bold**
.. Code ``text``
.. External Links: `Bootstrap <http://getbootstrap.com/>`_
.. Internal Link: :ref:downloadButton (default url text) or :ref:`download Button<downloadButton>` (explicit url text)
.. Add Images:    .. image:: ../Images/a4.jpg
..
..
.. Admonitions
..           .. note::   .. important::     .. tip::     .. warning::
.. Color:   (blue)       (orange)           (green)      (red)
..
.. Definition:
.. some text becomes strong (only one line)
..      description has to indented

.. -*- coding: utf-8 -*- with BOM.

.. include:: Includes.txt


.. _help:

General Tips
============

Typo3 Debug Mode
----------------

Manual to always display Exceptions and Errors in the backend and frontend of Typo3:

`Typo3: Debugging and Development Setup <https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/ErrorAndExceptionHandling/Examples/Index.html#debugging-and-development-setup>`_

Errors
------

* Does the error happens on every *page* or only on a specific one?
* Does the error happens on every *form* or only on a specific one?

Tips:

* On general errors:

  * Always check the Javascript console of your browser, see :ref:`javascriptProblem`.
  * Always check the Webserver log files.

Procedure to Find an Irreproducible Error
-----------------------------------------

* Find out the date and time on which the error occurred as precisely as possible
* Find out the user-name of the person who experienced the error
* Search the logs at the time of the Error:

  * qfq.log

    * location: fileadmin/protected/log/qfq.log
    * Look for error messages which were sent to the user at that time. (search for user-name in file)
    * Look at actions performed during the time of Error

  * FormSubmitLog

    * location: table named 'FormSubmitLog' in the qfq database
    * In the SQL Table FormSubmitLog search the column FEUser for the user-name
    * does the data (in the column formData) submitted at the time of the error coincide with the data saved in the database?

  * sql.log

    * location: fileadmin/protected/log/sql.og
    * search for the form that was active when the error occurred:

      * e.g.: If the form is named 'requestGreview' search for 'form:requestGreview'

Caching
-------

Content, generated by QFQ, is generally not cached. But the QFQ content records are cached by Typo3. This means if there is
a content element 'Insert Records' on a page 'A' which includes a QFQ record from page 'B' and such QFQ record is modified (the SQL
definition, not the delivered output), the new definition becomes by default only visible if the cached is cleared.

To simplify the situation, set on the page of the QFQ record (B) in Page TS Config: ::

  TCEMAIN.clearCacheCmd = pages


QFQ specific
------------

A variable {{<var>}} is empty
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The sanitize rule is violated and therefore the value has been removed. Set {{<var>:<store>:all}} as a test.

Page is white: no HTML code at all
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This should not happen.

The PHP process stopped at all. Check the Apache error logfile, look for a stacktrace to find the latest function. Send
a bug report.

Problem with query or variables
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Specify the required sanitize class. Remember: for STORE_FORM and STORE_CLIENT the default is sanitize class is `digit`.
This means if the variable content is a string, this violates the sanitize class and the variable will not be replaced.

Tip on Form: put the problematic variable or SQL statement in the 'title' or note 'field' of a `FormElement`. This should show
the content. For SQL statements, remove the outer token (e.g. only one curly brace) to avoid triggering SQL: ::

  FE.title: Person { SELECT ... WHERE id={{buggyVar:alnumx}} }

Tip on Report: In case the query did not contain any double ticks, just wrap all but 'SELECT' in double ticks::

 Buggy query:  10.sql = SELECT id, ... FROM MyTable WHERE status={{myVar}} ORDER BY status
 Debug query:  10.sql = SELECT "id, ... FROM MyTable WHERE status={{myVar}} ORDER BY status"

Error read file config.qfq.php: syntax error on line xx
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check the given line number. If it's an SQL statement, enclose it in single or double ticks.


Output a text, substitute embedded QFQ variables
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The content will be copied to '_text'. In `10.tail` than the '{{text:R}}' will be substituted with all known variables.
Note the '-' in '{{text:RE::-}}', this will prevent that QFQ escapes any character from the content. ::

    10 {
      sql = SELECT no.text AS _text
               FROM Note AS no
               WHERE id=...
      tail = {{text:RE::-}}
    }

TypeAhead list with T3 page alias names - use of the T3 DB
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To define a typeahead list of T3 page alias names::

    FE.type = text
    FE.parameter.typeAheadSql = SELECT p.alias FROM {{dbNameT3:Y}}.Pages AS p WHERE p.deleted=0 AND p.alias!='' AND p.alias LIKE ? ORDER BY p.alias LIMIT 20
    FE.parameter.typeAheadMinLength = 1

.. _setFeUserPassword:

Set FE-User password
^^^^^^^^^^^^^^^^^^^^

To offer an FE User the possibility to change the own T3 FE password, create a form: ::

    f.name = changeFePassword
    f.title = Change Password
    f.table = Person   (QFQ Table, not T3)
    f.permitNew = never
    f.permitEdit = sip

    fe[1].name = myPassword
    fe[1].title = Password
    fe[1].class = native
    fe[1].type = password
    fe[1].mode = required
    fe[1].parameter = retype

    fe[2].class = action
    fe[2].type = afterSave
    fe[2].parameter = sqlAfter={{UPDATE {{dbNameT3:Y}}.fe_users SET password='{{myPassword:FE:all:p}}' WHERE username='{{feUser:T}}' AND deleted=0

Call the form via SIP on an existing record. Often QFQ has an own table for persons and also the current user exist in T3
fe_users table.


Logging
-------

General webserver error log
^^^^^^^^^^^^^^^^^^^^^^^^^^^

For apache: `/var/log/apache2/error_log`

Especially if you got a blank page (no rendering at all), this is typically an uncaught PHP error. Check the error message
and report the bug (https://qfq.io > Contact).

Call to undefined function qfq\\mb_internal_encoding()
""""""""""""""""""""""""""""""""""""""""""""""""""""""

Check that all required php modules are installed. See :ref:`preparation`.


Error Messages
--------------

Internal Server Error
^^^^^^^^^^^^^^^^^^^^^

The browser shows a red popup with 'Internal Server Error'. The message is generated in the browser. Happens e.g. an AJAX
request response of QFQ (=Server) is broken. This might happen e.g. if PHP can't start successfully or PHP fails to run
due to  a missing php module or broken configuration.

Oops, an error occurred! Code: 20180612205917761fc593
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You see this message on all places where a QFQ content record should produce some output. Typically the extension fails
to load. If the error message disappears when the QFQ extension is disabled (instead a message `qfq_qfq can't be rendered`
is shown), than QFQ is the problem.

Search the given code in `typo3temp/logs/*`, in this example 20180612205917761fc593. You'll should find a stacktrace with
a more detailed message.

The error might occur if there are problematic characters in config.qfq.php, like single or double ticks inside strings,
wich are not enclosed (correctly).

.. _`sendEmailProblem`:

sendEmail: Error => TLS setup failed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Switch off the TLS encryption. In :ref:`configuration` specify for *config.sendEMailOptions*: ::

   -o tls=no

.. _`javascriptProblem`:

Javascript problem
------------------

Open the 'Webdeveloper Tools' (FF: F12, Chrome/Opera: Right mouse click > Inspect Element) in your browser, switch to
'console' and reload the page. Inspect the messages.

TinyMCE
-------

Glyph Icons in '<span>'
^^^^^^^^^^^^^^^^^^^^^^^

TinyMCE forbids by default HTML tag 'span' with 'class' attribute. E.g.: ::

    <span class="glyphicon glyphicon-user"></span>

To allow it, add 'span' to the valid elements in the FormElement.parameter field: ::

    editor-extended_valid_elements = span[class|style]

The HTML span tag has to be added via 'source' view. At least in TinyMCE 4.7.13, the glyph is still not shown in the
editor.

FE User
-------

The FE User record (table: fe_users)

  * Has to exist.
  * Has to be assigned to at least one FE Group. Check ``fe_users.usergroup``.
  * Has to be assigned to a T3 page ``fe_users.pid``.
  * The T3 page has to be configured as ``record store`` on the T3 Plugin login box.
  * Access time has to be zero or a currently valid period.