if (!$view->unlink('/imports/' . $_POST['file'])) { OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR); } } exit; } foreach ($parts as $part) { $card = OC_VObject::parse($part); if (!$card) { $failed += 1; OCP\Util::writeLog('contacts', 'Import: skipping card. Error parsing VCard: ' . $part, OCP\Util::ERROR); continue; // Ditch cards that can't be parsed by Sabre. } try { OC_Contacts_VCard::add($id, $card); $imported += 1; } catch (Exception $e) { OCP\Util::writeLog('contacts', 'Error importing vcard: ' . $e->getMessage() . $nl . $card, OCP\Util::ERROR); $failed += 1; } } //done the import writeProgress('100'); sleep(3); OC_Cache::remove($progresskey); if (isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') { if (!$view->unlink('/imports/' . $_POST['file'])) { OCP\Util::writeLog('contacts', 'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR); } }
function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/addcontact.php: ' . $msg, OCP\Util::DEBUG); exit; } // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); $aid = isset($_POST['aid']) ? $_POST['aid'] : null; if (!$aid) { $aid = min(OC_Contacts_Addressbook::activeIds()); // first active addressbook. } OC_Contacts_App::getAddressbook($aid); // is owner access check $isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false; $fn = trim($_POST['fn']); $n = trim($_POST['n']); $vcard = new OC_VObject('VCARD'); $vcard->setUID(); $vcard->setString('FN', $fn); $vcard->setString('N', $n); $id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew); if (!$id) { OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.')))); OCP\Util::writeLog('contacts', 'ajax/addcontact.php: Recieved non-positive ID on adding card: ' . $id, OCP\Util::ERROR); exit; } OCP\JSON::success(array('data' => array('id' => $id)));
OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('contacts'); $addressbook = OC_Contacts_Addressbook::find($aid); if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) { OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved? exit; } $fn = $_POST['fn']; $values = $_POST['value']; $parameters = $_POST['parameters']; $vcard = new Sabre_VObject_Component('VCARD'); $vcard->add(new Sabre_VObject_Property('FN', $fn)); $vcard->add(new Sabre_VObject_Property('UID', OC_Contacts_VCard::createUID())); foreach (array('ADR', 'TEL', 'EMAIL', 'ORG') as $propname) { $value = $values[$propname]; if (isset($parameters[$propname])) { $prop_parameters = $parameters[$propname]; } else { $prop_parameters = array(); } OC_Contacts_VCard::addVCardProperty($vcard, $propname, $value, $prop_parameters); } $id = OC_Contacts_VCard::add($aid, $vcard->serialize()); $details = OC_Contacts_VCard::structureContact($vcard); $name = $details['FN'][0]['value']; $tmpl = new OC_Template('contacts', 'part.details'); $tmpl->assign('details', $details); $tmpl->assign('id', $id); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array('id' => $id, 'name' => $name, 'page' => $page)));