addcontact.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Thomas Tanghus
  6. * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. // Init owncloud
  23. function bailOut($msg) {
  24. OCP\JSON::error(array('data' => array('message' => $msg)));
  25. OCP\Util::writeLog('contacts','ajax/addcontact.php: '.$msg, OCP\Util::DEBUG);
  26. exit();
  27. }
  28. // Check if we are a user
  29. OCP\JSON::checkLoggedIn();
  30. OCP\JSON::checkAppEnabled('contacts');
  31. OCP\JSON::callCheck();
  32. $aid = isset($_POST['aid'])?$_POST['aid']:null;
  33. if(!$aid) {
  34. $aid = min(OC_Contacts_Addressbook::activeIds()); // first active addressbook.
  35. }
  36. OC_Contacts_App::getAddressbook( $aid ); // is owner access check
  37. $isnew = isset($_POST['isnew'])?$_POST['isnew']:false;
  38. $fn = trim($_POST['fn']);
  39. $n = trim($_POST['n']);
  40. $vcard = new OC_VObject('VCARD');
  41. $vcard->setUID();
  42. $vcard->setString('FN',$fn);
  43. $vcard->setString('N',$n);
  44. $id = OC_Contacts_VCard::add($aid,$vcard, null, $isnew);
  45. if(!$id) {
  46. OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
  47. OCP\Util::writeLog('contacts','ajax/addcontact.php: Recieved non-positive ID on adding card: '.$id, OCP\Util::ERROR);
  48. exit();
  49. }
  50. OCP\JSON::success(array('data' => array( 'id' => $id )));