<?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/filtres');

function action_supprimer_cibloc_multi($id = null) {

	if ($id === null) {
		$securiser_action = charger_fonction('securiser_action', 'inc');
		$id = $securiser_action();
	}

	if (autoriser('configurer')) {
		if (ctype_alnum(str_replace('|', '', $id))) {
			$row = sql_fetsel('*', 'spip_cibloc_objets', "type='multi' AND id='" . $id . "' AND source='creation'");
			if ($row) {
				if ($row['statut'] != 'desactive') {
					$purger_cache_css = true;
				} else {
					$purger_cache_css = false;
				}

				sql_delete('spip_cibloc_objets', "type='multi' AND id='" . $id . "' AND source='creation'");

				include_spip('inc/cibloc_commun');
				cibloc_purger_definition_cache();
				cibloc_purger_cache_js();

				if ($purger_cache_css) {
					include_spip('inc/cibloc_commun');
					cibloc_purger_cache_css();
				}
			}
		}
	} else {
		spip_log("action_supprimer_cibloc_multi $id interdit", _LOG_INFO_IMPORTANTE);
	}
}
