<commit_before><?php
/*
* Copyright 2019 Centreon (http://www.centreon.com/)
*
* Centreon is a full-fledged industry-strength solution that meets
* the needs in IT infrastructure and application monitoring for
* service performance.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ItopProvider extends AbstractProvider
{
    protected $proxy_enabled = 1;
    protected $close_advanced = 1;

    public const ITOP_ORGANIZATION_TYPE = 10;
    public const ITOP_CALLER_TYPE = 11;
    public const ITOP_SERVICE_TYPE = 12;
    public const ITOP_SERVICE_SUBCATEGORY_TYPE = 13;

    public const ARG_CONTENT = 1;
    public const ARG_TITLE = 2;
    public const ARG_ORGANIZATION = 3;
    public const ARG_CALLER = 4;
    public const ARG_ORIGIN = 5;
    public const ARG_SERVICE = 6;
    public const ARG_SERVICE_SUBCATEGORY = 7;
    public const ARG_IMPACT = 8;
    public const ARG_URGENCY = 9;

    protected $internal_arg_name = [
        self::ARG_CONTENT => 'content',
        self::ARG_TITLE => 'title',
        self::ARG_ORGANIZATION => 'organization',
        self::ARG_CALLER => 'caller',
        self::ARG_ORIGIN => 'origin',
        self::ARG_SERVICE => 'service',
        self::ARG_SERVICE_SUBCATEGORY => 'service_subcategory',
        self::ARG_IMPACT => 'impact',
        self::ARG_URGENCY => 'urgency'
    ];

    /*
    * Set default values for our rule form options
    *
    * @return {void}
    */
    protected function setDefaultValueExtra()
    {
        $this->default_data['address'] = '10.30.2.22/itop/web';
        $this->default_data['api_version'] = '1.4';
        $this->default_data['username'] = '';
        $this->default_data['password'] = '';
        $this->default_data['protocol'] = 'https';
        $this->default_data['timeout'] = 60;

        $this->default_data['clones']['mappingTicket'] = array(
            array(
                'Arg' => self::ARG_CONTENT,
                'Value' => '{$body}'
            ),
            array(
                'Arg' => self::ARG_TITLE,
                'Value' => 'Issue {include file="file:$centreon_open_tickets_path/providers' .
                    '/Abstract/templates/display_title.ihtml"}'
            ),
            array(
                'Arg' => self::ARG_ORGANIZATION,
                'Value' => '{$select.itop_organization.id}'
            ),
            array(
                'Arg' => self::ARG_CALLER,
                'Value' => '{$select.itop_caller.id}'
            ),
            array(
                'Arg' => self::ARG_ORIGIN,
                'Value' => '{$select.itop_origin.value}'
            ),
            array(
                'Arg' => self::ARG_SERVICE,
                'Value' => '{$select.itop_service.id}'
            ),
            array(
                'Arg' => self::ARG_SERVICE_SUBCATEGORY,
                'Value' => '{$select.itop_service_subcategory.id}'
            ),
            array(
                'Arg' => self::ARG_IMPACT,
                'Value' => '{$select.itop_impact.value}'
            ),
            array(
                'Arg' => self::ARG_URGENCY,
                'Value' => '{$select.itop_urgency.value}'
            )
        );
    }

    /*
    * Set default values for the widget popup when opening a ticket
    *
    * @return {void}
    */
    protected function setDefaultValueMain($body_html = 0)
    {
        parent::setDefaultValueMain($body_html = 0);

        $this->default_data['url'] = '{$protocol}://{$address}/webservices/rest.php?version={$version}';

        $this->default_data['format_popup'] = '
<table class="table"><commit_msg>fix itop ticket url (#247)<commit_after><?php
/*
* Copyright 2019 Centreon (http://www.centreon.com/)
*
* Centreon is a full-fledged industry-strength solution that meets
* the needs in IT infrastructure and application monitoring for
* service performance.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ItopProvider extends AbstractProvider
{
    protected $proxy_enabled = 1;
    protected $close_advanced = 1;

    public const ITOP_ORGANIZATION_TYPE = 10;
    public const ITOP_CALLER_TYPE = 11;
    public const ITOP_SERVICE_TYPE = 12;
    public const ITOP_SERVICE_SUBCATEGORY_TYPE = 13;

    public const ARG_CONTENT = 1;
    public const ARG_TITLE = 2;
    public const ARG_ORGANIZATION = 3;
    public const ARG_CALLER = 4;
    public const ARG_ORIGIN = 5;
    public const ARG_SERVICE = 6;
    public const ARG_SERVICE_SUBCATEGORY = 7;
    public const ARG_IMPACT = 8;
    public const ARG_URGENCY = 9;

    protected $internal_arg_name = [
        self::ARG_CONTENT => 'content',
        self::ARG_TITLE => 'title',
        self::ARG_ORGANIZATION => 'organization',
        self::ARG_CALLER => 'caller',
        self::ARG_ORIGIN => 'origin',
        self::ARG_SERVICE => 'service',
        self::ARG_SERVICE_SUBCATEGORY => 'service_subcategory',
        self::ARG_IMPACT => 'impact',
        self::ARG_URGENCY => 'urgency'
    ];

    /*
    * Set default values for our rule form options
    *
    * @return {void}
    */
    protected function setDefaultValueExtra()
    {
        $this->default_data['address'] = '10.30.2.22/itop/web';
        $this->default_data['api_version'] = '1.4';
        $this->default_data['username'] = '';
        $this->default_data['password'] = '';
        $this->default_data['protocol'] = 'https';
        $this->default_data['timeout'] = 60;

        $this->default_data['clones']['mappingTicket'] = array(
            array(
                'Arg' => self::ARG_CONTENT,
                'Value' => '{$body}'
            ),
            array(
                'Arg' => self::ARG_TITLE,
                'Value' => 'Issue {include file="file:$centreon_open_tickets_path/providers' .
                    '/Abstract/templates/display_title.ihtml"}'
            ),
            array(
                'Arg' => self::ARG_ORGANIZATION,
                'Value' => '{$select.itop_organization.id}'
            ),
            array(
                'Arg' => self::ARG_CALLER,
                'Value' => '{$select.itop_caller.id}'
            ),
            array(
                'Arg' => self::ARG_ORIGIN,
                'Value' => '{$select.itop_origin.value}'
            ),
            array(
                'Arg' => self::ARG_SERVICE,
                'Value' => '{$select.itop_service.id}'
            ),
            array(
                'Arg' => self::ARG_SERVICE_SUBCATEGORY,
                'Value' => '{$select.itop_service_subcategory.id}'
            ),
            array(
                'Arg' => self::ARG_IMPACT,
                'Value' => '{$select.itop_impact.value}'
            ),
            array(
                'Arg' => self::ARG_URGENCY,
                'Value' => '{$select.itop_urgency.value}'
            )
        );
    }

    /*
    * Set default values for the widget popup when opening a ticket
    *
    * @return {void}
    */
    protected function setDefaultValueMain($body_html = 0)
    {
        parent::setDefaultValueMain($body_html = 0);

        $this->default_data['url'] = '{$protocol}://{$address}/pages/UI.php?operation=details'
            . '&class=UserRequest&id={$ticket_id}';

        $this->default_data['format_popup'] = '
<table class="table">
{'fraction_non_alphanumeric': 0.12777845256892992, 'fraction_numerical': 0.010081379812947893, 'mean_word_length': 2.2113884555382217, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4231841', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2424, 'n_words': 566}