mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-14 13:42:04 +00:00
add more response codes
This commit is contained in:
parent
21518adecc
commit
d1ea639431
|
@ -427,6 +427,7 @@ function createFolder($id) { /* {{{ */
|
||||||
if($folder = $parent->addSubFolder($name, $comment, $userobj, 0, $newattrs)) {
|
if($folder = $parent->addSubFolder($name, $comment, $userobj, 0, $newattrs)) {
|
||||||
|
|
||||||
$rec = __getFolderData($folder);
|
$rec = __getFolderData($folder);
|
||||||
|
$app->response()->status(201);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$rec));
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$rec));
|
||||||
} else {
|
} else {
|
||||||
|
@ -582,8 +583,8 @@ function uploadDocument($id) { /* {{{ */
|
||||||
// $categories = $app->request()->params('categories') ? $app->request()->params('categories') : [];
|
// $categories = $app->request()->params('categories') ? $app->request()->params('categories') : [];
|
||||||
// $attributes = $app->request()->params('attributes') ? $app->request()->params('attributes') : [];
|
// $attributes = $app->request()->params('attributes') ? $app->request()->params('attributes') : [];
|
||||||
$origfilename = $app->request()->params('origfilename');
|
$origfilename = $app->request()->params('origfilename');
|
||||||
if (count($_FILES) == 0)
|
if (count($_FILES) == 0) {
|
||||||
{
|
$app->response()->status(400);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
|
||||||
return;
|
return;
|
||||||
|
@ -712,8 +713,8 @@ function uploadDocumentFile($documentId) { /* {{{ */
|
||||||
$comment = $app->request()->params('comment');
|
$comment = $app->request()->params('comment');
|
||||||
$version = $app->request()->params('version') == '' ? 0 : $app->request()->params('version');
|
$version = $app->request()->params('version') == '' ? 0 : $app->request()->params('version');
|
||||||
$public = $app->request()->params('public') == '' ? 'false' : $app->request()->params('public');
|
$public = $app->request()->params('public') == '' ? 'false' : $app->request()->params('public');
|
||||||
if (count($_FILES) == 0)
|
if (count($_FILES) == 0) {
|
||||||
{
|
$app->response()->status(400);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'No file detected', 'data'=>''));
|
||||||
return;
|
return;
|
||||||
|
@ -733,17 +734,24 @@ function uploadDocumentFile($documentId) { /* {{{ */
|
||||||
$fileType, $userfiletype, $version, $public);
|
$fileType, $userfiletype, $version, $public);
|
||||||
unlink($temp);
|
unlink($temp);
|
||||||
if($res) {
|
if($res) {
|
||||||
|
$app->response()->status(201);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$res));
|
echo json_encode(array('success'=>true, 'message'=>'Upload succeded', 'data'=>$res));
|
||||||
} else {
|
} else {
|
||||||
|
$app->response()->status(500);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Upload failed', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Upload failed', 'data'=>''));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$app->response()->status(403);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'No access', 'data'=>''));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if($document === null)
|
||||||
|
$app->response()->status(400);
|
||||||
|
else
|
||||||
|
$app->response()->status(500);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'No such document', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'No such document', 'data'=>''));
|
||||||
}
|
}
|
||||||
|
@ -1392,12 +1400,14 @@ function createUser() { /* {{{ */
|
||||||
|
|
||||||
$newAccount = $dms->addUser($userName, $password, $fullname, $email, $language, $theme, $comment, $roleid);
|
$newAccount = $dms->addUser($userName, $password, $fullname, $email, $language, $theme, $comment, $roleid);
|
||||||
if ($newAccount === false) {
|
if ($newAccount === false) {
|
||||||
|
$app->response()->status(500);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Account could not be created, maybe it already exists', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Account could not be created, maybe it already exists', 'data'=>''));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = __getUserData($newAccount);
|
$result = __getUserData($newAccount);
|
||||||
|
$app->response()->status(201);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$result));
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$result));
|
||||||
return;
|
return;
|
||||||
|
@ -1518,12 +1528,14 @@ function createGroup() { /* {{{ */
|
||||||
|
|
||||||
$newGroup = $dms->addGroup($groupName, $comment);
|
$newGroup = $dms->addGroup($groupName, $comment);
|
||||||
if ($newGroup === false) {
|
if ($newGroup === false) {
|
||||||
|
$app->response()->status(500);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Group could not be created, maybe it already exists', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Group could not be created, maybe it already exists', 'data'=>''));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array('id'=>(int)$newGroup->getID());
|
$result = array('id'=>(int)$newGroup->getID());
|
||||||
|
$app->response()->status(201);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$result));
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>$result));
|
||||||
return;
|
return;
|
||||||
|
@ -1799,6 +1811,7 @@ function createCategory() { /* {{{ */
|
||||||
|
|
||||||
$category = $app->request()->params("category");
|
$category = $app->request()->params("category");
|
||||||
if ($category == null) {
|
if ($category == null) {
|
||||||
|
$app->response()->status(400);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Need a category.', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Need a category.', 'data'=>''));
|
||||||
return;
|
return;
|
||||||
|
@ -1806,13 +1819,16 @@ function createCategory() { /* {{{ */
|
||||||
|
|
||||||
$catobj = $dms->getDocumentCategoryByName($category);
|
$catobj = $dms->getDocumentCategoryByName($category);
|
||||||
if($catobj) {
|
if($catobj) {
|
||||||
|
$app->response()->status(409);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Category already exists', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Category already exists', 'data'=>''));
|
||||||
} else {
|
} else {
|
||||||
if($data = $dms->addDocumentCategory($category)) {
|
if($data = $dms->addDocumentCategory($category)) {
|
||||||
|
$app->response()->status(201);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>array('id'=>(int)$data->getID())));
|
echo json_encode(array('success'=>true, 'message'=>'', 'data'=>array('id'=>(int)$data->getID())));
|
||||||
} else {
|
} else {
|
||||||
|
$app->response()->status(500);
|
||||||
$app->response()->header('Content-Type', 'application/json');
|
$app->response()->header('Content-Type', 'application/json');
|
||||||
echo json_encode(array('success'=>false, 'message'=>'Could not add category', 'data'=>''));
|
echo json_encode(array('success'=>false, 'message'=>'Could not add category', 'data'=>''));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user