
#######
Request
#######


****
NAME
****


Kernel::System::Web::Request - global CGI interface


***********
DESCRIPTION
***********


All cgi param functions.


****************
PUBLIC INTERFACE
****************


new()
=====


create param object. Do not use it directly, instead use:


.. code-block:: perl

     use Kernel::System::ObjectManager;
     local $Kernel::OM = Kernel::System::ObjectManager->new(
         'Kernel::System::Web::Request' => {
             WebRequest   => CGI::Fast->new(), # optional, e. g. if fast cgi is used
         }
     );
     my $ParamObject = $Kernel::OM->Get('Kernel::System::Web::Request');


If Kernel::System::Web::Request is instantiated several times, they will share the
same CGI data (this can be helpful in filters which do not have access to the
ParamObject, for example.

If you need to reset the CGI data before creating a new instance, use


.. code-block:: perl

     CGI::initialize_globals();


before calling Kernel::System::Web::Request->new();


Error()
=======


to get the error back


.. code-block:: perl

     if ( $ParamObject->Error() ) {
         print STDERR $ParamObject->Error() . "\n";
     }



GetParam()
==========


to get single request parameters. By default, trimming is performed on the data.


.. code-block:: perl

     my $Param = $ParamObject->GetParam(
         Param => 'ID',
         Raw   => 1,       # optional, input data is not changed
     );


Returns:


.. code-block:: perl

     my $Param = '123';



GetParams()
===========


Get all request parameters, Strings and Arrays.


.. code-block:: perl

     my %Params = $ParamObject->GetParams(
         Params           => [ 'TicketID', 'Queue', ]      # optional, only these parameters are fetched and returned
         Raw              => 1,                            # optional, input data is not changed
         JSONDecodeParams => ['ParamNameWithJSONData1',]   # optional, this JSON-decodes the given parameters
     );


Returns:


.. code-block:: perl

     my %Params = (
         TicketID => 1,
         Queue    => 'Raw',
         Array    => [
             1,
             2,
         ],
         'ParamNameWithJSONData1' => {
             'jsonkey' => 'jsonvalue'
         },
     );



GetParamNames()
===============


to get names of all parameters passed to the script.


.. code-block:: perl

     my @ParamNames = $ParamObject->GetParamNames();


Example:

Called URL: index.pl?Action=AdminSystemConfiguration;Subaction=Save;Name=Config::Option::Valid


.. code-block:: perl

     my @ParamNames = $ParamObject->GetParamNames();
 
     print join " :: ", @ParamNames;
     # prints Action :: Subaction :: Name


Returns:


.. code-block:: perl

     my @ParamNames = (
         'Array',
         'TicketID',
         'Queue',
     );



GetArray()
==========


to get array request parameters.
By default, trimming is performed on the data.


.. code-block:: perl

     my @Param = $ParamObject->GetArray(
         Param => 'ID',
         Raw   => 1,     # optional, input data is not changed
     );


Returns:


.. code-block:: perl

     my @Param = (
         1,
         2,
     );



GetUploadAll()
==============


gets file upload data.


.. code-block:: perl

     my %File = $ParamObject->GetUploadAll(
         Param  => 'FileParam',  # the name of the request parameter containing the file data
     );


Returns:


.. code-block:: perl

     my %File = (
         Filename    => 'abc.txt',
         ContentType => 'text/plain',
         Content     => 'Some text',
     );



SetCookie()
===========


set a cookie


.. code-block:: perl

     $ParamObject->SetCookie(
         Key     => ID,
         Value   => 123456,
         Expires => '+3660s',
         Path    => 'otrs/',     # optional, only allow cookie for given path
         Secure  => 1,           # optional, set secure attribute to disable cookie on HTTP (HTTPS only)
         HTTPOnly => 1,          # optional, sets HttpOnly attribute of cookie to prevent access via JavaScript
     );



GetCookie()
===========


get a cookie


.. code-block:: perl

     my $String = $ParamObject->GetCookie(
         Key => ID,
     );



IsAJAXRequest()
===============


checks if the current request was sent by AJAX


.. code-block:: perl

     my $IsAJAXRequest = $ParamObject->IsAJAXRequest();



LoadFormDraft()
===============


Load specified draft.
This will read stored draft data and inject it into the param object
for transparent use by frontend module.


.. code-block:: perl

     my $FormDraftID = $ParamObject->LoadFormDraft(
         FormDraftID => 123,
         UserID  => 1,
     );



SaveFormDraft()
===============


Create or replace draft using data from param object and upload cache.
Specified params can be overwritten if necessary.


.. code-block:: perl

     my $FormDraftID = $ParamObject->SaveFormDraft(
         UserID         => 1,
         ObjectType     => 'Ticket',
         ObjectID       => 123,
         OverrideParams => {               # optional, can contain strings and array references
             Subaction   => undef,
             UserID      => 1,
             CustomParam => [ 1, 2, 3, ],
             # ...
         },
     );





