delete.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. OCP\JSON::checkLoggedIn();
  9. OCP\JSON::checkAppEnabled('contacts');
  10. foreach ($_POST as $key=>$element) {
  11. debug('_POST: '.$key.'=>'.print_r($element, true));
  12. }
  13. function bailOut($msg) {
  14. OCP\JSON::error(array('data' => array('message' => $msg)));
  15. OCP\Util::writeLog('contacts','ajax/categories/delete.php: '.$msg, OCP\Util::DEBUG);
  16. exit();
  17. }
  18. function debug($msg) {
  19. OCP\Util::writeLog('contacts','ajax/categories/delete.php: '.$msg, OCP\Util::DEBUG);
  20. }
  21. $categories = isset($_POST['categories'])?$_POST['categories']:null;
  22. if(is_null($categories)) {
  23. bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.'));
  24. }
  25. debug(print_r($categories, true));
  26. $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
  27. if(count($addressbooks) == 0) {
  28. bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
  29. }
  30. $addressbookids = array();
  31. foreach($addressbooks as $addressbook) {
  32. $addressbookids[] = $addressbook['id'];
  33. }
  34. $contacts = OC_Contacts_VCard::all($addressbookids);
  35. if(count($contacts) == 0) {
  36. bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
  37. }
  38. $cards = array();
  39. foreach($contacts as $contact) {
  40. $cards[] = array($contact['id'], $contact['carddata']);
  41. }
  42. debug('Before delete: '.print_r($categories, true));
  43. $catman = new OC_VCategories('contacts');
  44. $catman->delete($categories, $cards);
  45. debug('After delete: '.print_r($catman->categories(), true));
  46. OC_Contacts_VCard::updateDataByID($cards);
  47. OCP\JSON::success(array('data' => array('categories'=>$catman->categories())));
  48. ?>