move.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * @author Victor Dubiniuk
  4. * Copyright (c) 2012 Victor Dubiniuk <victor.dubiniuk@gmail.com>
  5. * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
  6. * This file is licensed under the Affero General Public License version 3 or
  7. * later.
  8. * See the COPYING-README file.
  9. */
  10. OCP\JSON::checkLoggedIn();
  11. OCP\JSON::checkAppEnabled('contacts');
  12. OCP\JSON::callCheck();
  13. $ids = $_POST['ids'];
  14. $aid = intval($_POST['aid']);
  15. OC_Contacts_App::getAddressbook($aid);
  16. if(!is_array($ids)) {
  17. $ids = array($ids,);
  18. }
  19. $goodids = array();
  20. foreach ($ids as $id){
  21. try {
  22. $card = OC_Contacts_App::getContactObject( intval($id) );
  23. if($card) {
  24. $goodids[] = $id;
  25. }
  26. } catch (Exception $e) {
  27. OCP\Util::writeLog('contacts', 'Error moving contact "'.$id.'" to addressbook "'.$aid.'"'.$e->getMessage(), OCP\Util::ERROR);
  28. }
  29. }
  30. try {
  31. OC_Contacts_VCard::moveToAddressBook($aid, $ids);
  32. } catch (Exception $e) {
  33. $msg = $e->getMessage();
  34. OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $ids).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
  35. OC_JSON::error(array('data' => array('message' => $msg,)));
  36. }
  37. OC_JSON::success(array('data' => array('ids' => $goodids,)));