updateaddressbook.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright (c) 2011-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. // Check if we are a user
  9. OCP\JSON::checkLoggedIn();
  10. OCP\JSON::checkAppEnabled('contacts');
  11. OCP\JSON::callCheck();
  12. $bookid = $_POST['id'];
  13. OC_Contacts_App::getAddressbook($bookid); // is owner access check
  14. $name = trim(strip_tags($_POST['name']));
  15. if(!$name) {
  16. OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'))));
  17. OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Cannot update addressbook with an empty name: '.strip_tags($_POST['name']), OCP\Util::ERROR);
  18. exit();
  19. }
  20. if(!OC_Contacts_Addressbook::edit($bookid, $name, null)) {
  21. OCP\JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
  22. OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OCP\Util::ERROR);
  23. //exit();
  24. }
  25. if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
  26. OCP\JSON::error(array('data' => array('message' => $l->t('Error (de)activating addressbook.'))));
  27. OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Error (de)activating addressbook: '.$bookid, OCP\Util::ERROR);
  28. //exit();
  29. }
  30. $addressbook = OC_Contacts_App::getAddressbook($bookid);
  31. $tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
  32. $tmpl->assign('addressbook', $addressbook);
  33. OCP\JSON::success(array(
  34. 'page' => $tmpl->fetchPage(),
  35. 'addressbook' => $addressbook,
  36. ));