showsetproperty.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = $_GET['id'];
  25. $checksum = $_GET['checksum'];
  26. $l10n = new OC_L10N('contacts');
  27. // Check if we are a user
  28. OC_JSON::checkLoggedIn();
  29. OC_JSON::checkAppEnabled('contacts');
  30. $card = OC_Contacts_VCard::find( $id );
  31. if( $card === false ){
  32. OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
  33. exit();
  34. }
  35. $addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
  36. if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
  37. OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
  38. exit();
  39. }
  40. $vcard = OC_Contacts_VCard::parse($card['carddata']);
  41. // Check if the card is valid
  42. if(is_null($vcard)){
  43. OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
  44. exit();
  45. }
  46. $line = null;
  47. for($i=0;$i<count($vcard->children);$i++){
  48. if(md5($vcard->children[$i]->serialize()) == $checksum ){
  49. $line = $i;
  50. }
  51. }
  52. if(is_null($line)){
  53. OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
  54. exit();
  55. }
  56. $adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
  57. $phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
  58. $tmpl = new OC_Template('contacts','part.setpropertyform');
  59. $tmpl->assign('id',$id);
  60. $tmpl->assign('checksum',$checksum);
  61. $tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line]));
  62. $tmpl->assign('adr_types',$adr_types);
  63. $tmpl->assign('phone_types',$phone_types);
  64. $page = $tmpl->fetchPage();
  65. OC_JSON::success(array('data' => array( 'page' => $page )));