<commit_before><?php

/**
Copyright (C) 2010-2016 by the FusionInventory Development Team.
Copyright (C) 2016 Teclib'

This file is part of Armadito Plugin for GLPI.

Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Armadito Plugin for GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.

**/

include_once("inc/toolbox.class.php");

function setDefaultDisplayPreferences( $classes)
{
    $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,
                        `users_id`) VALUES ";

    foreach ( $classes as $class => $rounds ){
        $query .= getDefaultDisplayPreferences($class, $rounds);
    }

    $query = rtrim($query, ",");

    if (!PluginArmaditoToolbox::ExecQuery($query)) {
        die();
    }
}

function getDefaultDisplayPreferences( $class, $rounds )
{
    $prefs      = "";
    for ($i = 1; $i <= $rounds; $i++) {
        $prefs .= "(NULL, '".$class."', '" . $i . "', '" . $i . "', '0'),";
    }
    return $prefs;
}

function cleanDefaultDisplayPreferences($class)
{
    $query = "DELETE FROM `glpi_displaypreferences`
      WHERE `itemtype`='".$class."'";

    PluginArmaditoToolbox::ExecQuery($query);
}

function cleanAllDisplayPreferences( $classes )
{
    foreach ( $classes as $class => $rounds ){
        cleanDefaultDisplayPreferences($class);
    }
}

function plugin_armadito_install()
{
    ini_set("max_execution_time", "0");

    if (basename($_SERVER['SCRIPT_NAME']) != "cli_install.php") {
        Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "plugins");
        $migrationname = 'Migration';
    } else {
        $migrationname = 'CliMigration';
    }

    require_once(GLPI_ROOT . "/plugins/armadito/install/update.php");
    $version_detected = pluginArmaditoGetCurrentVersion();

    if (isset($version_detected) &&
        (defined('FORCE_UPGRADE') || ($version_detected != PLUGIN_ARMADITO_VERSION && $version_detected != '0'))) {
        pluginArmaditoUpdate($version_detected, $migrationname);
    } else if ((isset($version_detected)) && ($version_detected == PLUGIN_ARMADITO_VERSION)) {
        //Same version : Nothing to do
    } else {
        require_once(GLPI_ROOT . "/plugins/armadito/install/install.php");
        pluginArmaditoInstall(PLUGIN_ARMADITO_VERSION, $migrationname);
    }

    // erase user display preferences and set default instead
    $classes = array( 'PluginArmaditoAgent' => 10,
                      'PluginArmaditoJob' => 10,
                      'PluginArmaditoState' => 10,
                      'PluginArmaditoAlert' => 10,
                      'PluginArmaditoScan' => 10,
                      'PluginArmaditoScanConfig' => 10,
                      'PluginArmaditoStateDetail' => 10,
                      'PluginArmaditoAVConfig' => 10,
                      'PluginArmaditoAntivirus' => 10
                     );

    cleanAllDisplayPreferences($classes);
    setDefaultDisplayPreferences($classes);

    return true;
}

function plugin_armadito_uninstall()
{
    require_once(GLPI_ROOT . "/plugins/armadito/inc/setup.class.php");
    require_once(GLPI_ROOT . "/plugins/armadito/inc/profile.class.php");
    return PluginArmaditoSetup::uninstall();
}

/**
 * Add massive actions to GLPI itemtypes
 */
function plugin_armadito_MassiveActions($type)<commit_msg>Increase default display preferences for alerts<commit_after><?php

/**
Copyright (C) 2010-2016 by the FusionInventory Development Team.
Copyright (C) 2016 Teclib'

This file is part of Armadito Plugin for GLPI.

Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Armadito Plugin for GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.

**/

include_once("inc/toolbox.class.php");

function setDefaultDisplayPreferences( $classes)
{
    $query = "INSERT INTO `glpi_displaypreferences` (`id`, `itemtype`, `num`, `rank`,
                        `users_id`) VALUES ";

    foreach ( $classes as $class => $rounds ){
        $query .= getDefaultDisplayPreferences($class, $rounds);
    }

    $query = rtrim($query, ",");

    if (!PluginArmaditoToolbox::ExecQuery($query)) {
        die();
    }
}

function getDefaultDisplayPreferences( $class, $rounds )
{
    $prefs      = "";
    for ($i = 1; $i <= $rounds; $i++) {
        $prefs .= "(NULL, '".$class."', '" . $i . "', '" . $i . "', '0'),";
    }
    return $prefs;
}

function cleanDefaultDisplayPreferences($class)
{
    $query = "DELETE FROM `glpi_displaypreferences`
      WHERE `itemtype`='".$class."'";

    PluginArmaditoToolbox::ExecQuery($query);
}

function cleanAllDisplayPreferences( $classes )
{
    foreach ( $classes as $class => $rounds ){
        cleanDefaultDisplayPreferences($class);
    }
}

function plugin_armadito_install()
{
    ini_set("max_execution_time", "0");

    if (basename($_SERVER['SCRIPT_NAME']) != "cli_install.php") {
        Html::header(__('Setup'), $_SERVER['PHP_SELF'], "config", "plugins");
        $migrationname = 'Migration';
    } else {
        $migrationname = 'CliMigration';
    }

    require_once(GLPI_ROOT . "/plugins/armadito/install/update.php");
    $version_detected = pluginArmaditoGetCurrentVersion();

    if (isset($version_detected) &&
        (defined('FORCE_UPGRADE') || ($version_detected != PLUGIN_ARMADITO_VERSION && $version_detected != '0'))) {
        pluginArmaditoUpdate($version_detected, $migrationname);
    } else if ((isset($version_detected)) && ($version_detected == PLUGIN_ARMADITO_VERSION)) {
        //Same version : Nothing to do
    } else {
        require_once(GLPI_ROOT . "/plugins/armadito/install/install.php");
        pluginArmaditoInstall(PLUGIN_ARMADITO_VERSION, $migrationname);
    }

    // erase user display preferences and set default instead
    $classes = array( 'PluginArmaditoAgent' => 10,
                      'PluginArmaditoJob' => 10,
                      'PluginArmaditoState' => 10,
                      'PluginArmaditoAlert' => 15,
                      'PluginArmaditoScan' => 10,
                      'PluginArmaditoScanConfig' => 10,
                      'PluginArmaditoStateDetail' => 10,
                      'PluginArmaditoAVConfig' => 10,
                      'PluginArmaditoAntivirus' => 10
                     );

    cleanAllDisplayPreferences($classes);
    setDefaultDisplayPreferences($classes);

    return true;
}

function plugin_armadito_uninstall()
{
    require_once(GLPI_ROOT . "/plugins/armadito/inc/setup.class.php");
    require_once(GLPI_ROOT . "/plugins/armadito/inc/profile.class.php");
    return PluginArmaditoSetup::uninstall();
}

/**
 * Add massive actions to GLPI itemtypes
 */
function plugin_armadito_MassiveActions($type)
{'fraction_non_alphanumeric': 0.12480539699014011, 'fraction_numerical': 0.00908147379346134, 'mean_word_length': 3.1851248642779586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4052869', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2231, 'n_words': 576}