Play images and video from Synology PhotoStation server

category.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <?php
  2. require_once('category.inc.php');
  3. require_once('albumutil.php');
  4. class CategoryAPI extends WebAPI {
  5. function __construct() {
  6. parent::__construct(SZ_WEBAPI_API_DESCRIPTION_PATH);
  7. }
  8. protected function Process() {
  9. if (!strcasecmp($this->method, "list")) {
  10. session_write_close();
  11. $this->CategoryList();
  12. } elseif (!strcasecmp($this->method, "getinfo")) {
  13. session_write_close();
  14. $this->GetInfo();
  15. } elseif (!strcasecmp($this->method, "listitem")) {
  16. csSYNOPhotoDB::GetDBInstance()->SetSessionCache();
  17. session_write_close();
  18. $this->ListItem();
  19. } else {
  20. csSYNOPhotoDB::GetDBInstance()->SetSessionCache(true);
  21. csSYNOPhotoMisc::CheckSessionTimeOut();
  22. if (!strcasecmp($this->method, "create")) {
  23. $this->Create();
  24. } elseif (!strcasecmp($this->method, "delete")) {
  25. $this->Delete();
  26. } elseif (!strcasecmp($this->method, "edit")) {
  27. $this->Edit();
  28. } elseif (!strcasecmp($this->method, "arrangecategory")) {
  29. $this->ArrangeCategory();
  30. } elseif (!strcasecmp($this->method, "additem")) {
  31. $this->AddItem();
  32. } elseif (!strcasecmp($this->method, "removeitem")) {
  33. $this->RemoveItem();
  34. } elseif (!strcasecmp($this->method, "arrangeitem")) {
  35. $this->ArrangeItem();
  36. }
  37. }
  38. }
  39. private function BooleanUniform($data) {
  40. if (true === $data || 't' === $data) {
  41. return true;
  42. } elseif (false === $data || 'f' === $data) {
  43. return false;
  44. }
  45. return false;
  46. }
  47. private function GetCategoryDatabaseID($data) {
  48. $arr = explode('category_', $data);
  49. $id = $arr[1];
  50. if (empty($id)) {
  51. return false;
  52. }
  53. if (!is_numeric($id)) {
  54. return false;
  55. }
  56. return $id;
  57. }
  58. private function CheckItemID($data) {
  59. $items = explode(',', $data);
  60. foreach ($items as $item) {
  61. $arr = explode('_', $item);
  62. if (!in_array($arr[0], array('album', 'tag', 'smart'))) {
  63. return false;
  64. }
  65. }
  66. return $items;
  67. }
  68. private function CheckOffsetLimit($offset, $limit) {
  69. if (!is_numeric($offset) || !is_numeric($limit)) {
  70. return false;
  71. }
  72. if (0 > (int)$offset || -1 > (int)$limit) {
  73. return false;
  74. }
  75. return true;
  76. }
  77. private function IsAccessible($id) {
  78. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  79. $hidden = csSYNOPhotoDB::GetDBInstance()->IsCategoryAccessible($id);
  80. if (false === $isAdmin && true === $hidden) {
  81. return false;
  82. }
  83. return true;
  84. }
  85. private function GetItemID($type, $id) {
  86. switch ($type) {
  87. case 'album':
  88. $row = csSYNOPhotoDB::GetDBInstance()->GetFieldByKeyValue('sharename', 'photo_share', 'shareid', $id);
  89. $albumID = bin2hex($row['sharename']);
  90. $itemID = "album_{$albumID}";
  91. break;
  92. case 'tag':
  93. $itemID = "tag_{$id}";
  94. break;
  95. case 'smart':
  96. $itemID = "smart_{$id}";
  97. break;
  98. default:
  99. return false;
  100. break;
  101. }
  102. return $itemID;
  103. }
  104. private function GetItemName($itemID) {
  105. $arr = explode('_', $itemID );
  106. if (2 != count($arr)) {
  107. return false;
  108. }
  109. if (!in_array($arr[0], array('album', 'smart', 'tag'))) {
  110. return false;
  111. }
  112. switch ($arr[0]) {
  113. case 'album':
  114. $name = @pack('H*', $arr[1]);
  115. break;
  116. case 'smart':
  117. $name = @pack('H*', $arr[1]);
  118. break;
  119. case 'tag':
  120. $row = csSYNOPhotoDB::GetDBInstance()->GetFieldByKeyValue('name', 'photo_label', 'id', $arr[1]);
  121. $name = $row['name'];
  122. break;
  123. default:
  124. break;
  125. }
  126. return $name;
  127. }
  128. private function CategoryList() {
  129. if (!isset($_REQUEST['offset']) || !isset($_REQUEST['limit'])) {
  130. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  131. goto End;
  132. }
  133. if (!$this->CheckOffsetLimit($_REQUEST['offset'], $_REQUEST['limit'])) {
  134. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  135. goto End;
  136. }
  137. // check if admin
  138. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  139. // database query, +0 => convert to int
  140. $dbCategories = Category::ListItem($_REQUEST['offset']+0, $_REQUEST['limit']+0, $isAdmin);
  141. // form to webapi format
  142. $categories = array();
  143. foreach ($dbCategories as $dbCategory) {
  144. $category = Decorator::CategoryFormula($dbCategory);
  145. $categories[] = $category;
  146. }
  147. $resp['total'] = (int)csSYNOPhotoDB::GetDBInstance()->GetTotalCategory($isAdmin);
  148. $offset = (0 > $_REQUEST['limit']) ? $resp['total'] : (int)($_REQUEST['offset'] + $_REQUEST['limit']);
  149. $resp['offset'] = ($offset > $resp['total']) ? $resp['total'] : $offset;
  150. $resp['categories'] = $categories;
  151. $this->SetResponse($resp);
  152. End:
  153. return;
  154. }
  155. private function GetInfo() {
  156. if (!isset($_REQUEST['id'])) {
  157. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  158. goto End;
  159. }
  160. // get and check category id
  161. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  162. if (false === $id) {
  163. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  164. goto End;
  165. }
  166. // check accessible
  167. if (!$this->IsAccessible($id)) {
  168. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  169. goto End;
  170. }
  171. // datebase query
  172. $objs = Category::GetByIds(array($id));
  173. $info = $objs[$id];
  174. if (!$info) {
  175. $this->SetError(PHOTOSTATION_CATEGORY_GETINFO_FAIL);
  176. goto End;
  177. }
  178. // form to webapi format
  179. $categories = array();
  180. $category['id'] = 'category_'.$info['id'];
  181. $category['name'] = $info['name'];
  182. $category['hidden'] = $info['hidden'];
  183. $category['home'] = $category['id'] === csSYNOPhotoMisc::GetConfigDB("album", "home_category", "photo_config");
  184. array_push($categories, $category);
  185. $resp['categories'] = $categories;
  186. $this->SetResponse($resp);
  187. End:
  188. return;
  189. }
  190. private function Create() {
  191. // check if admin
  192. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  193. if (!$isAdmin) {
  194. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  195. goto End;
  196. }
  197. $name = trim($_REQUEST['name']);
  198. if (!isset($_REQUEST['name']) || '' === $name) {
  199. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  200. goto End;
  201. }
  202. $hidden = 'true' === $_REQUEST['hidden'] ? true : false;
  203. if (Category::CheckNameExists($name)) {
  204. $this->SetError(PHOTOSTATION_CATEGORY_DUPLICATE);
  205. goto End;
  206. }
  207. // database query
  208. $createId = Category::Add($name, $hidden);
  209. if (!$createId) {
  210. $this->SetError(PHOTOSTATION_CATEGORY_CREATE_FAIL);
  211. goto End;
  212. }
  213. $resp['id'] = 'category_'.$createId;
  214. $this->SetResponse($resp);
  215. End:
  216. return;
  217. }
  218. private function Delete() {
  219. // check if admin
  220. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  221. if (!$isAdmin) {
  222. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  223. goto End;
  224. }
  225. if (!isset($_REQUEST['id'])) {
  226. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  227. goto End;
  228. }
  229. // get and check category id
  230. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  231. if (!$id) {
  232. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  233. goto End;
  234. }
  235. // database query
  236. if (!Category::DeleteByIds(array($id))) {
  237. $this->SetError(PHOTOSTATION_CATEGORY_DELETE_FAIL);
  238. goto End;
  239. }
  240. $homeVal = csSYNOPhotoMisc::GetConfigDB("album", "home_category", "photo_config");
  241. if ($homeVal === $_REQUEST['id']) {
  242. csSYNOPhotoMisc::UpdateConfigDB("album", "home_category", '', "photo_config");
  243. }
  244. $this->SetResponse($resp);
  245. End:
  246. return;
  247. }
  248. private function Edit() {
  249. // check if admin
  250. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  251. if (!$isAdmin) {
  252. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  253. goto End;
  254. }
  255. if (!isset($_REQUEST['id'])) {
  256. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  257. goto End;
  258. }
  259. // get and check category id
  260. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  261. if (!$id) {
  262. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  263. goto End;
  264. }
  265. $name = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : NULL;
  266. $hidden = isset($_REQUEST['hidden']) ?
  267. ('true' === $_REQUEST['hidden'] ? true : false) : NULL;
  268. if (NULL === $hidden && ('' === $name || NULL === $name)) {
  269. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  270. goto End;
  271. }
  272. if (Category::isDuplicated($id, $name)) {
  273. $this->SetError(PHOTOSTATION_CATEGORY_DUPLICATE);
  274. goto End;
  275. }
  276. // database query
  277. if (!Category::EditById($id, $name, $hidden)) {
  278. $this->SetError(PHOTOSTATION_CATEGORY_EDIT_FAIL);
  279. goto End;
  280. }
  281. $setHome = isset($_REQUEST['home']) ? 'true' === $_REQUEST['home'] : false;
  282. $homeVal = csSYNOPhotoMisc::GetConfigDB("album", "home_category", "photo_config");
  283. if ($setHome) {
  284. csSYNOPhotoMisc::UpdateConfigDB("album", "home_category", $_REQUEST['id'], "photo_config");
  285. } elseif ($homeVal === $_REQUEST['id']) {
  286. csSYNOPhotoMisc::UpdateConfigDB("album", "home_category", '', "photo_config");
  287. }
  288. $this->SetResponse($resp);
  289. End:
  290. return;
  291. }
  292. private function ArrangeCategory() {
  293. // check if admin
  294. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  295. if (!$isAdmin) {
  296. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  297. goto End;
  298. }
  299. if (!isset($_REQUEST['offset']) || !isset($_REQUEST['limit']) || !isset($_REQUEST['category_id'])) {
  300. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  301. goto End;
  302. }
  303. if (!$this->CheckOffsetLimit($_REQUEST['offset'], $_REQUEST['limit'])) {
  304. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  305. goto End;
  306. }
  307. // get and check category id
  308. $ids = array();
  309. $categoryIDs = array();
  310. $categoryIDs = explode(',', $_REQUEST['category_id']);
  311. foreach ($categoryIDs as $categoryID) {
  312. if (false === ($id = $this->GetCategoryDatabaseID($categoryID))) {
  313. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  314. goto End;
  315. }
  316. array_push($ids, $id);
  317. }
  318. // database query
  319. if (!csSYNOPhotoDB::GetDBInstance()->ArrangeCategory($ids, $_REQUEST['offset'], $_REQUEST['limit'])) {
  320. $this->SetError(PHOTOSTATION_CATEGORY_ARRANGE_FAIL);
  321. goto End;
  322. }
  323. $this->SetResponse($resp);
  324. End:
  325. return;
  326. }
  327. private function AddItem() {
  328. // check if admin
  329. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  330. if (!$isAdmin) {
  331. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  332. goto End;
  333. }
  334. if (!isset($_REQUEST['id']) || !isset($_REQUEST['item_id'])) {
  335. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  336. goto End;
  337. }
  338. // get and check category id
  339. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  340. if (!$id) {
  341. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  342. goto End;
  343. }
  344. // check item id
  345. $itemIDs = $this->CheckItemID($_REQUEST['item_id']);
  346. if (!$itemIDs) {
  347. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  348. goto End;
  349. }
  350. if (!csSYNOPhotoDB::GetDBInstance()->AddCategoryItem($id, $itemIDs)) {
  351. $this->SetError(PHOTOSTATION_CATEGORY_ADD_ITEM_FAIL);
  352. goto End;
  353. }
  354. $this->SetResponse($resp);
  355. End:
  356. return;
  357. }
  358. private function FormAlbumInfo($itemID)
  359. {
  360. $query = "select * from photo_share where shareid=?";
  361. $sqlParam = array($itemID);
  362. $db_result = PHOTO_DB_Query($query, $sqlParam);
  363. if (false === ($db_result = PHOTO_DB_Query($query, $sqlParam))) {
  364. return false;
  365. }
  366. if (false === ($row = PHOTO_DB_FetchRow($db_result))) {
  367. return false;
  368. }
  369. $info['sharepath'] = $row['sharename'];
  370. $info['name'] = basename($row['sharename']);
  371. $info['title'] = empty($row['title']) ? $info['name'] : $row['title'];
  372. $info['description'] = $row['description'];
  373. $info['hits'] = $row['hits'];
  374. if (PHOTO_DB_IsTrue($row['public'])) {
  375. $albumPermission = 'public';
  376. } else {
  377. $albumPermission = empty($row['password']) ? 'private' : 'password';
  378. }
  379. $info['type'] = $albumPermission;
  380. return $info;
  381. }
  382. private function FormAdditional($type, $additional, $itemID)
  383. {
  384. if ('album' === $type && in_array('album_permission', $additional)) {
  385. $arr = explode('album_', $itemID);
  386. if (2 === count($arr)) {
  387. $albumName = @pack('H*', $arr[1]);
  388. $data['album_permission'] = AlbumAPIUtil::GetAlbumPermission($albumName);
  389. }
  390. }
  391. return $data;
  392. }
  393. private function IsAlbumPassword($albumName)
  394. {
  395. $query = 'SELECT * FROM photo_share WHERE sharename=?';
  396. $sqlParam = array($albumName);
  397. if (false === ($db_result = PHOTO_DB_Query($query, $sqlParam))) {
  398. return false;
  399. }
  400. if (false === ($row = PHOTO_DB_FetchRow($db_result))) {
  401. return false;
  402. }
  403. if (false == PHOTO_DB_IsTrue($row['public']) && !empty($row['password'])) {
  404. return true;
  405. }
  406. return false;
  407. }
  408. private function ListItem() {
  409. if (!isset($_REQUEST['id']) || !isset($_REQUEST['offset']) || !isset($_REQUEST['limit'])) {
  410. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  411. goto End;
  412. }
  413. $additionalParams = explode(',', $_REQUEST['additional']);
  414. $needThumbSize = in_array('thumb_size', $additionalParams);
  415. if (!$this->CheckOffsetLimit($_REQUEST['offset'], $_REQUEST['limit'])) {
  416. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  417. goto End;
  418. }
  419. // get and check category id
  420. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  421. if (!$id) {
  422. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  423. goto End;
  424. }
  425. // check accessible
  426. if (!$this->IsAccessible($id)) {
  427. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  428. goto End;
  429. }
  430. // database query
  431. $dbItems = csSYNOPhotoDB::GetDBInstance()->ListCategoryItem($id, $_REQUEST['offset'], $_REQUEST['limit']);
  432. if (false === $dbItems) {
  433. $this->SetError(PHOTOSTATION_CATEGORY_LIST_ITEM_FAIL);
  434. goto End;
  435. }
  436. $allow_comment = AlbumAPIUtil::IsAlbumCommentalbGlobal();
  437. // form to webapi format
  438. $items = array();
  439. $denyCount = 0;
  440. foreach ($dbItems as $dbItem) {
  441. unset($item);
  442. if ('album' === $dbItem['type']) {
  443. $typeID = $dbItem['album_id'];
  444. } elseif ('tag' === $dbItem['type']) {
  445. $typeID = $dbItem['tag_id'];
  446. } elseif ('smart' === $dbItem['type']) {
  447. $typeID = $dbItem['smart_id'];
  448. }
  449. if (false === ($itemID = $this->GetItemID($dbItem['type'], $typeID))) {
  450. continue;
  451. }
  452. // private can't show
  453. if ('album' === $dbItem['type']) {
  454. $arr = explode('album_', $itemID);
  455. $albumName = @pack('H*', $arr[1]);
  456. if (!csSYNOPhotoMisc::CheckAlbumAccessible($albumName) && !$this->IsAlbumPassword($albumName)) {
  457. $denyCount++;
  458. continue;
  459. }
  460. }
  461. $item['id'] = $itemID;
  462. $item['type'] = $dbItem['type'];
  463. $item['name'] = $this->GetItemName($itemID);
  464. $additional = $this->FormAdditional($dbItem['type'], $additionalParams, $itemID);
  465. $coverPath = '';
  466. if ('album' === $dbItem['type']) {
  467. $arr = explode('album_', $itemID);
  468. if (2 === count($arr)) {
  469. $albumName = @pack('H*', $arr[1]);
  470. $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetAlbumCover($albumName);
  471. $coverPath = $result['coverPath'];
  472. $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  473. $dirname = dirname($relativePath);
  474. $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
  475. }
  476. $item['info'] = $this->FormAlbumInfo($typeID);
  477. $item['info']['allow_comment'] = $allow_comment;
  478. if (null !== $additional) {
  479. $item['additional']['album_permission'] = $additional['album_permission'];
  480. }
  481. } elseif ('tag' === $dbItem['type']) {
  482. $arr = explode('tag_', $itemID);
  483. if (2 === count($arr)) {
  484. $result = csSYNOPhotoAlbum::GetAlbumInstance()->GetLabelAlbumCover($arr[1]);
  485. $coverPath = $result['coverPath'];
  486. $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  487. $dirname = dirname($relativePath);
  488. $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
  489. }
  490. } elseif ('smart' === $dbItem['type']) {
  491. $arr = explode('smart_', $itemID);
  492. if (2 === count($arr)) {
  493. $smartName = @pack('H*', $arr[1]);
  494. $album = SmartAlbum::GetSmartAlbumInstance()->GetCoverOfSmartAlbumByName($smartName);
  495. $coverPath = '';
  496. if ($album['success'] && $album['cover']) {
  497. $coverPath = $album['cover']['dbPath'];
  498. }
  499. $relativePath = substr($coverPath, strlen(SYNOPHOTO_SERVICE_REAL_DIR_PATH));
  500. $dirname = dirname($relativePath);
  501. $sharename = in_array($dirname, array('.', ''), true) ? '/' : $dirname;
  502. }
  503. }
  504. $blConversion = csSYNOPhotoMisc::IsAlbumAllowConversion($sharename);
  505. list($orig_resolutionx, $orig_resolutiony, $blThumbRotated) = AlbumAPIUtil::GetCoverResolutionRotation($coverPath);
  506. AlbumAPIUtil::FillThumbStatus($item, $coverPath, $needThumbSize, $orig_resolutionx, $orig_resolutiony, $blThumbRotated, $blConversion);
  507. array_push($items, $item);
  508. }
  509. // fixme
  510. $resp['total'] = (int)csSYNOPhotoDB::GetDBInstance()->GetTotalCategoryItem($id) - $denyCount;
  511. $offset = (0 > (int)$_REQUEST['limit']) ? $resp['total'] : (int)($_REQUEST['offset'] + $_REQUEST['limit']);
  512. $resp['offset'] = ($offset > $resp['total']) ? $resp['total'] : $offset;
  513. $resp['items'] = $items;
  514. $this->SetResponse($resp);
  515. End:
  516. return;
  517. }
  518. private function RemoveItem() {
  519. // check if admin
  520. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  521. if (!$isAdmin) {
  522. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  523. goto End;
  524. }
  525. if (!isset($_REQUEST['id']) || !isset($_REQUEST['item_id'])) {
  526. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  527. goto End;
  528. }
  529. // get and check category id
  530. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  531. if (!$id) {
  532. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  533. goto End;
  534. }
  535. // check item id
  536. $itemIDs = $this->CheckItemID($_REQUEST['item_id']);
  537. if (!$itemIDs) {
  538. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  539. goto End;
  540. }
  541. // database query
  542. if (!csSYNOPhotoDB::GetDBInstance()->RemoveCategoryItem($id, $itemIDs)) {
  543. $this->SetError(PHOTOSTATION_CATEGORY_REMOVE_ITEM_FAIL);
  544. goto End;
  545. }
  546. $this->SetResponse($resp);
  547. End:
  548. return;
  549. }
  550. private function ArrangeItem() {
  551. // check if admin
  552. $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  553. if (!$isAdmin) {
  554. $this->SetError(PHOTOSTATION_CATEGORY_ACCESS_DENY);
  555. goto End;
  556. }
  557. if (!isset($_REQUEST['id']) || !isset($_REQUEST['offset']) || !isset($_REQUEST['limit'])) {
  558. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  559. goto End;
  560. }
  561. if (!$this->CheckOffsetLimit($_REQUEST['offset'], $_REQUEST['limit'])) {
  562. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  563. goto End;
  564. }
  565. // get and check category id
  566. $id = $this->GetCategoryDatabaseID($_REQUEST['id']);
  567. if (!$id) {
  568. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  569. goto End;
  570. }
  571. // check item id
  572. $itemIDs = $this->CheckItemID($_REQUEST['item_id']);
  573. if (!$itemIDs) {
  574. $this->SetError(PHOTOSTATION_CATEGORY_WRONG_ID_FORMAT);
  575. goto End;
  576. }
  577. // database query
  578. if (!csSYNOPhotoDB::GetDBInstance()->ArrangeCategoryItem($id, $itemIDs, $_REQUEST['offset'], $_REQUEST['limit'])) {
  579. $this->SetError(PHOTOSTATION_CATEGORY_ARRANGE_ITEM_FAIL);
  580. goto End;
  581. }
  582. $this->SetResponse($resp);
  583. End:
  584. return;
  585. }
  586. }
  587. $api = new CategoryAPI();
  588. $api->Run();
  589. ?>