add.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. function bailOut($msg) {
  9. OC_JSON::error(array('data' => array('message' => $msg)));
  10. OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
  11. exit();
  12. }
  13. function debug($msg) {
  14. OC_Log::write('core', 'ajax/vcategories/add.php: '.$msg, OC_Log::DEBUG);
  15. }
  16. OCP\JSON::checkLoggedIn();
  17. OCP\JSON::callCheck();
  18. $l = OC_L10N::get('core');
  19. $category = isset($_POST['category']) ? strip_tags($_POST['category']) : null;
  20. $type = isset($_POST['type']) ? $_POST['type'] : null;
  21. if(is_null($type)) {
  22. bailOut($l->t('Category type not provided.'));
  23. }
  24. if(is_null($category)) {
  25. bailOut($l->t('No category to add?'));
  26. }
  27. debug(print_r($category, true));
  28. $categories = new OC_VCategories($type);
  29. if($categories->hasCategory($category)) {
  30. bailOut($l->t('This category already exists: %s', array($category)));
  31. } else {
  32. $categories->add($category, true);
  33. }
  34. OC_JSON::success(array('data' => array('categories'=>$categories->categories())));