<?php
$aliases_arr	= $_SERVER['REQUEST_URI'];
$aliases_arrX 	= $_SERVER['REQUEST_URI'];
$aliases_arr 	= explode("/", $_SERVER['REQUEST_URI']);
$aliases_arrX 	= explode("?", $_SERVER['REQUEST_URI']);

array_shift($aliases_arr);
array_shift($aliases_arrX);

$folder = $aliases_arr[0]; // Директория расположения системы
$module = $aliases_arr[1]; // Модуль системы

define('ROOT', $_SERVER['DOCUMENT_ROOT'] . '/' . $folder . '/');

$baseTMPL 	= ROOT . 'crmdata/database/templs.xml';

$templID 	= $_POST['templid'];

$dom = new DOMDocument;
$dom->load($baseTMPL);
$xpath = new DOMXPath($dom);
$templs = $xpath->query('/templs/templ[@id="'.$templID.'"]');
$el = $templs->item(0);
$el->parentNode->removeChild($el);
$dom->save($baseTMPL);

if($templs->length < 1){
	$answer = [
		'status' 	=> 'error'
	];
	echo json_encode($answer);
} else {
	$answer = [
		'status' 	=> 'ok'
	];
	echo json_encode($answer);
}