function plugin_install($id, $version, &$errors)
{
    global $conf;
    /* ****************************************************************** */
    /* **************** BEGIN - Data preparation in vars **************** */
    /* ****************************************************************** */
    $defaultPH = array();
    // Set current plugin version in config table
    $plugin = PHInfos(PH_PATH);
    $version = $plugin['version'];
    // Default global parameters for Prune History conf
    // -------------------------------------------------
    $defaultPH = array('PHVersion' => $version, 'AUTOPRUNE' => 'false', 'RANGEVALUE' => '0', 'RANGE' => '0');
    // Create Prune History conf if not already exists
    // ------------------------------------------------
    $query = '
SELECT param
  FROM ' . CONFIG_TABLE . '
WHERE param = "PruneHistory"
;';
    $count = pwg_db_num_rows(pwg_query($query));
    if ($count == 0) {
        $q = '
INSERT INTO ' . CONFIG_TABLE . ' (param, value, comment)
VALUES ("PruneHistory","' . pwg_db_real_escape_string(serialize($defaultPH)) . '","Prune History parameters")
  ;';
        pwg_query($q);
    }
}
/**
 * PH specific database dump
 * Creates an SQL dump of history table for safety before manual prune
 * 
 * @returns  : Boolean to manage appropriate message display
 * 
 */
function PH_dump($download)
{
    global $conf;
    $plugin = PHInfos(PH_PATH);
    $version = $plugin['version'];
    // Initial backup folder creation and file initialisation
    // ------------------------------------------------------
    if (!is_dir(PH_PATH . '/include/backup')) {
        mkdir(PH_PATH . '/include/backup');
    }
    $Backup_File = PH_PATH . '/include/backup/PH_Historybackup.sql';
    $fp = fopen($Backup_File, 'w');
    // Writing plugin version
    $insertions = "-- " . $version . " --\n\n";
    fwrite($fp, $insertions);
    // Saving History table
    // --------------------
    $ListTables = array(HISTORY_TABLE);
    $j = 0;
    while ($j < count($ListTables)) {
        $sql = 'SHOW CREATE TABLE ' . $ListTables[$j];
        $res = pwg_query($sql);
        if ($res) {
            $insertions = "-- -------------------------------------------------------\n";
            $insertions .= "-- Create " . $ListTables[$j] . " table\n";
            $insertions .= "-- ------------------------------------------------------\n\n";
            $insertions .= "DROP TABLE IF EXISTS " . $ListTables[$j] . ";\n\n";
            $array = pwg_db_fetch_row($res);
            $array[1] .= ";\n\n";
            $insertions .= $array[1];
            $req_table = pwg_query('DESCRIBE ' . $ListTables[$j] . ';') or die(my_error());
            $nb_fields = pwg_db_num_rows($req_table);
            $req_table2 = pwg_query('SELECT * FROM ' . $ListTables[$j]) or die(my_error());
            while ($line = pwg_db_fetch_row($req_table2)) {
                $insertions .= 'INSERT INTO ' . $ListTables[$j] . ' VALUES (';
                for ($i = 0; $i < $nb_fields; $i++) {
                    $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', ';
                }
                $insertions = substr($insertions, 0, -2);
                $insertions .= ");\n";
            }
            $insertions .= "\n\n";
        }
        fwrite($fp, $insertions);
        $j++;
    }
    fclose($fp);
    // Download generated dump file
    // ----------------------------
    if ($download == 'true') {
        if (@filesize($Backup_File)) {
            $http_headers = array('Content-Length: ' . @filesize($Backup_File), 'Content-Type: text/x-sql', 'Content-Disposition: attachment; filename="PH_Historybackup.sql";', 'Content-Transfer-Encoding: binary');
            foreach ($http_headers as $header) {
                header($header);
            }
            @readfile($Backup_File);
            exit;
        }
    }
    return true;
}
}
// +-----------------------------------------------------------------------+
// | Check Access and exit when user status is not ok                      |
// +-----------------------------------------------------------------------+
check_status(ACCESS_ADMINISTRATOR);
if (!defined('PH_PATH')) {
    define('PH_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
}
load_language('plugin.lang', PH_PATH);
$page['global'] = array();
$range = array();
$dump_download = '';
// +-------------------------------------------------------------------+
// |                      Get plugin version and name                  |
// +-------------------------------------------------------------------+
$plugin = PHInfos(PH_PATH);
$version = $plugin['version'];
$name = $plugin['name'];
// +-----------------------------------------------------------------------+
// |                      Saving new configuration                         |
// +-----------------------------------------------------------------------+
if (isset($_POST['submit']) and isset($_POST['PH_AutoPrune']) and isset($_POST['PH_Range_Value']) and isset($_POST['PH_Range'])) {
    $newconf_PH['PHVersion'] = $version;
    $newconf_PH['AUTOPRUNE'] = isset($_POST['PH_AutoPrune']) ? $_POST['PH_AutoPrune'] : 'false';
    $newconf_PH['RANGEVALUE'] = isset($_POST['PH_Range_Value']) ? $_POST['PH_Range_Value'] : '0';
    $newconf_PH['RANGE'] = isset($_POST['PH_Range']) ? $_POST['PH_Range'] : '0';
    $conf['PruneHistory'] = serialize($newconf_PH);
    conf_update_param('PruneHistory', pwg_db_real_escape_string($conf['PruneHistory']));
    array_push($page['infos'], l10n('PH_save_config'));
}
// +--------------------------------------------------------------------+