OCP\JSON::checkAppEnabled('contacts'); function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/editname.php: ' . $msg, OCP\Util::DEBUG); exit; } function debug($msg) { OCP\Util::writeLog('contacts', 'ajax/editname.php: ' . $msg, OCP\Util::DEBUG); } $tmpl = new OCP\Template("contacts", "part.edit_name_dialog"); $id = isset($_GET['id']) ? $_GET['id'] : ''; debug('id: ' . $id); if ($id) { $vcard = OC_Contacts_App::getContactVCard($id); $name = array('', '', '', '', ''); if ($vcard->__isset('N')) { $property = $vcard->__get('N'); if ($property) { $name = OC_Contacts_VCard::structureProperty($property); } } $tmpl->assign('name', $name); $tmpl->assign('id', $id); } else { bailOut(OC_Contacts_App::$l10n->t('Contact ID is missing.')); //$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser()); //$tmpl->assign('addressbooks', $addressbooks); } $tmpl->printpage();
if ($card === false) { OC_JSON::error(array('data' => array('message' => $l10n->t('Contact could not be found.')))); exit; } $addressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) { OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.')))); exit; } $vcard = OC_Contacts_VCard::parse($card['carddata']); // Check if the card is valid if (is_null($vcard)) { OC_JSON::error(array('data' => array('message' => $l10n->t('vCard could not be read.')))); exit; } $line = null; for ($i = 0; $i < count($vcard->children); $i++) { if (md5($vcard->children[$i]->serialize()) == $checksum) { $line = $i; } } if (is_null($line)) { OC_JSON::error(array('data' => array('message' => $l10n->t('Information about vCard is incorrect. Please reload the page.')))); exit; } $tmpl = new OC_Template('contacts', 'part.setpropertyform'); $tmpl->assign('id', $id); $tmpl->assign('checksum', $checksum); $tmpl->assign('property', OC_Contacts_VCard::structureProperty($vcard->children[$line])); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array('page' => $page)));
$l10n = new OC_L10N('contacts'); // Check if we are a user OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $card = OC_Contacts_VCard::find($id); if ($card === false) { OC_JSON::error(array('data' => array('message' => $l10n->t('Contact could not be found.')))); exit; } $addressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) { OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your contact.')))); exit; } $vcard = OC_Contacts_VCard::parse($card['carddata']); // Check if the card is valid if (is_null($vcard)) { OC_JSON::error(array('data' => array('message' => $l10n->t('vCard could not be read.')))); exit; } $name = $_POST['name']; $value = $_POST['value']; $parameters = isset($_POST['parameteres']) ? $_POST['parameters'] : array(); $property = OC_Contacts_VCard::addVCardProperty($vcard, $name, $value, $parameters); $line = count($vcard->children) - 1; $checksum = md5($property->serialize()); OC_Contacts_VCard::edit($id, $vcard->serialize()); $tmpl = new OC_Template('contacts', 'part.property'); $tmpl->assign('property', OC_Contacts_VCard::structureProperty($property, $line)); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array('page' => $page)));
* Copyright (c) 2011 Thomas Tanghus <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $id = $_GET['id']; $checksum = isset($_GET['checksum']) ? $_GET['checksum'] : ''; $vcard = OC_Contacts_App::getContactVCard($id); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); $tmpl = new OCP\Template("contacts", "part.edit_address_dialog"); if ($checksum) { $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); $element = $vcard->children[$line]; $adr = OC_Contacts_VCard::structureProperty($element); $types = array(); if (isset($adr['parameters']['TYPE'])) { if (is_array($adr['parameters']['TYPE'])) { $types = array_map('htmlspecialchars', $adr['parameters']['TYPE']); $types = array_map('strtoupper', $types); } else { $types = array(strtoupper(htmlspecialchars($adr['parameters']['TYPE']))); } } $tmpl->assign('types', $types, false); $adr = array_map('htmlspecialchars', $adr['value']); $tmpl->assign('adr', $adr, false); } $tmpl->assign('id', $id); $tmpl->assign('adr_types', $adr_types);