diff --git a/ajax.php b/ajax.php index bfa481a20aed7cf8c1d6134ff835a46584dcbb0e..8ea5226439f971b9cd917a13f53c099579394ed1 100644 --- a/ajax.php +++ b/ajax.php @@ -31,6 +31,7 @@ $dispatcher = patterns('', )), url('^/draft/', patterns('ajax.draft.php:DraftAjaxAPI', url_post('^(?P<id>\d+)$', 'updateDraftClient'), + url_delete('^(?P<id>\d+)$', 'deleteDraftClient'), url_post('^(?P<id>\d+)/attach$', 'uploadInlineImageClient'), url_get('^(?P<namespace>[\w.]+)$', 'getDraftClient'), url_post('^(?P<namespace>[\w.]+)$', 'createDraftClient') diff --git a/include/ajax.draft.php b/include/ajax.draft.php index 41fde2be24ff955b793f1fbf773b9d8372616c0b..f727e2cc9a10040786f6abb3502a8a21f7e04806 100644 --- a/include/ajax.draft.php +++ b/include/ajax.draft.php @@ -186,6 +186,23 @@ class DraftAjaxAPI extends AjaxController { return self::_updateDraft($draft); } + function deleteDraftClient($id) { + global $thisclient; + + if (!($draft = Draft::lookup($id))) + Http::response(205, "Draft not found. Create one first"); + elseif ($thisclient) { + if ($draft->getStaffId() != $thisclient->getId()) + Http::response(404, "Draft not found"); + } + else { + if (substr(session_id(), -12) != substr($draft->getNamespace(), -12)) + Http::response(404, "Draft not found"); + } + + $draft->delete(); + } + function uploadInlineImageClient($id) { global $thisclient;