add.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. require_once('../../../lib/base.php');
  17. OC_JSON::checkLoggedIn();
  18. $category = isset($_GET['category'])?strip_tags($_GET['category']):null;
  19. $app = isset($_GET['app'])?$_GET['app']:null;
  20. if(is_null($app)) {
  21. bailOut(OC_Contacts_App::$l10n->t('Application name not provided.'));
  22. }
  23. OC_JSON::checkAppEnabled($app);
  24. if(is_null($category)) {
  25. bailOut(OC_Contacts_App::$l10n->t('No category to add?'));
  26. }
  27. debug(print_r($category, true));
  28. $categories = new OC_VCategories($app);
  29. if($categories->hasCategory($category)) {
  30. bailOut(OC_Contacts_App::$l10n->t('This category already exists: '.$category));
  31. } else {
  32. $categories->add($category, true);
  33. }
  34. OC_JSON::success(array('data' => array('categories'=>$categories->categories())));