<?php

/**
 * Plugin CIBLOC
 * @copyright 2018 MTECT
 * @author Christophe IMBERTI (cf. CPI art L121-1)
 * @license GNU/GPLv3
 */

if (!defined(
	'_ECRIRE_INC_VERSION'
)) {
	return;
}

include_spip('inc/cibloc_commun');

function formulaires_cibloc_export_config_charger_dist() {
	if (!autoriser('configurer configuration')) {
		return false;
	}

	$valeurs = ['choix_export' => 'oui'];

	return $valeurs;
}

function formulaires_cibloc_export_config_verifier_dist() {
	$erreurs = [];

	if (!_request('choix_export')) {
		$erreurs['choix_export'] = _T('cibloc:valeur_incorrecte');
	}

	return $erreurs;
}

function formulaires_cibloc_export_config_traiter_dist() {
	include_spip('inc/actions');

	$arg = implode('-', _request('choix_export'));
	if ($arg) {
		$type = _request('type_export');
		if ($type == 'type_php') {
			$arg .= '-type_php';
		} else {
			$arg .= '-type_txt';
		}
	}

	if ($arg) {
		// on lance l'action puis une redirection
		include_spip('inc/actions');
		$redirect = generer_action_auteur('cibloc_export_config', $arg);

		return ['message_ok' => 'ok', 'redirect' => $redirect];
	}
	return ['message_erreur' => 'erreur'];

}
