Location: PHPKode > projects > Mocovie web framework > backend/ajax.php
<?php
require 'pre.php';

// <header>
	$GLOBALS['header'] = Header::getInstance();
	$GLOBALS['header']->contentType('text/plain; charset=utf-8');

	function errorHandler($errno, $errstr, $errfile = '', $errline = '', $errcontext = '')
	{
		$GLOBALS['header']->status(500);
		die($errno.' '.$errstr.' in '.$errfile.' at line '.$errline);
	}

	function exceptionHandler(Exception $e)
	{
		$GLOBALS['header']->status(500);
		die(get_class($e).': '.$e->getMessage().' in '.$e->getFile().' at line '.$e->getLine());
	}

	function filled()
	{
		foreach(func_get_args() as $arg)
			if(strlen($arg) <= 0) return false;
		return true;
	}
	set_error_handler('errorHandler', E_ALL | E_NOTICE | E_STRICT);
	set_exception_handler('exceptionHandler');
// </header>

//print_r($_POST);
if(isset($_POST['options']) && count($_POST['options']) > 0)
{
	foreach($_POST['options'] as $option)
	{
		$control = $GLOBALS['filesystem']
			->file($option['file'])
			->control($option['xpath']);
		if($option['name'] == 'continuoustext')
			$control->setText($option['value']);
		else
			$control->setOption($option['name'], $option['value']);
	}
	$GLOBALS['filesystem']->save();
	die(json_encode('done'));
}
if(isset($_POST['addControl'], $_POST['method'], $_POST['file'], $_POST['xpath']) && filled($_POST['addControl'], $_POST['method'], $_POST['file'], $_POST['xpath']))
{
	$control = $GLOBALS['filesystem']
		->file($_POST['file'])
		->newControl($_POST['addControl'])
	;
	switch($_POST['method'])
	{
		case 'before':
			if($control->canMoveBefore($_POST['xpath']))
				$control->moveBefore($_POST['xpath']);
			else
			{
				$GLOBALS['header']->status(403);
				die('Forbidden');
			}
		break;
		case 'after':
			if($control->canMoveAfter($_POST['xpath']))
				$control->moveAfter($_POST['xpath']);
			else
			{
				$GLOBALS['header']->status(403);
				die('Forbidden');
			}
		break;
		default:
			if($control->canMove($_POST['xpath']))
				$control->move($_POST['xpath']);
			else
			{
				$GLOBALS['header']->status(403);
				die('Forbidden');
			}
	}

	ob_start();
	FSHelper::createControl($control);
	$html = preg_replace('/[\s]{2,}/', '', ob_get_contents());
	ob_end_clean();

	$GLOBALS['filesystem']->save();

	echo json_encode
	( array('html'	=> $html)
	);
}
if(isset($_POST['deleteControl'], $_POST['file'], $_POST['xpath']) && filled($_POST['deleteControl'], $_POST['file'], $_POST['xpath']))
{
	$GLOBALS['filesystem']->file($_POST['file'])->control($_POST['xpath'])->delete();
	$GLOBALS['filesystem']->save();
	die(json_encode('done'));
}
Return current item: Mocovie web framework