addproperty.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * ownCloud - Addressbook
  4. *
  5. * @author Jakob Sack
  6. * @copyright 2011 Jakob Sack mail@jakobsack.de
  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. require_once('../../../lib/base.php');
  24. $id = $_POST['id'];
  25. $l10n = new OC_L10N('contacts');
  26. // Check if we are a user
  27. OC_JSON::checkLoggedIn();
  28. OC_JSON::checkAppEnabled('contacts');
  29. $card = OC_Contacts_VCard::find( $id );
  30. if( $card === false ){
  31. OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
  32. exit();
  33. }
  34. $addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
  35. if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
  36. OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
  37. exit();
  38. }
  39. $vcard = OC_Contacts_VCard::parse($card['carddata']);
  40. // Check if the card is valid
  41. if(is_null($vcard)){
  42. OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
  43. exit();
  44. }
  45. $name = $_POST['name'];
  46. $value = $_POST['value'];
  47. $parameters = isset($_POST['parameteres'])?$_POST['parameters']:array();
  48. $property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters);
  49. $line = count($vcard->children) - 1;
  50. $checksum = md5($property->serialize());
  51. OC_Contacts_VCard::edit($id,$vcard->serialize());
  52. $tmpl = new OC_Template('contacts','part.property');
  53. $tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line));
  54. $page = $tmpl->fetchPage();
  55. OC_JSON::success(array('data' => array( 'page' => $page )));