Ejemplo n.º 1
0
 /**
  * @brief edits a card
  * @param integer $id id of card
  * @param OC_VObject $card  vCard file
  * @return boolean
  */
 public static function edit($id, OC_VObject $card)
 {
     $oldcard = self::find($id);
     if (is_null($card)) {
         return false;
     }
     OC_Contacts_App::loadCategoriesFromVCard($card);
     $fn = $card->getAsString('FN');
     if (empty($fn)) {
         $fn = null;
     }
     $now = new DateTime();
     $card->setString('REV', $now->format(DateTime::W3C));
     $data = $card->serialize();
     $stmt = OCP\DB::prepare('UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?');
     $result = $stmt->execute(array($fn, $data, time(), $id));
     OC_Contacts_Addressbook::touch($oldcard['addressbookid']);
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @brief edits a card
  * @param integer $id id of card
  * @param OC_VObject $card  vCard file
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function edit($id, OC_VObject $card)
 {
     $oldcard = self::find($id);
     if (!$oldcard) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', id: ' . $id . ' not found.', OCP\Util::DEBUG);
         throw new Exception(OC_Contacts_App::$l10n->t('Could not find the vCard with ID.' . $id));
     }
     if (is_null($card)) {
         return false;
     }
     // NOTE: Owner checks are being made in the ajax files, which should be done
     // inside the lib files to prevent any redundancies with sharing checks
     $addressbook = OC_Contacts_Addressbook::find($oldcard['addressbookid']);
     if ($addressbook['userid'] != OCP\User::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $oldcard['addressbookid'], OCP\Share::FORMAT_NONE, null, true);
         $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
         $addressbook_permissions = 0;
         $contact_permissions = 0;
         if ($sharedAddressbook) {
             $addressbook_permissions = $sharedAddressbook['permissions'];
         }
         if ($sharedContact) {
             $contact_permissions = $sharedEvent['permissions'];
         }
         $permissions = max($addressbook_permissions, $contact_permissions);
         if (!($permissions & OCP\Share::PERMISSION_UPDATE)) {
             throw new Exception(OC_Contacts_App::$l10n->t('You do not have the permissions to edit this contact.'));
         }
     }
     OC_Contacts_App::loadCategoriesFromVCard($card);
     $fn = $card->getAsString('FN');
     if (empty($fn)) {
         $fn = null;
     }
     $now = new DateTime();
     $card->setString('REV', $now->format(DateTime::W3C));
     $data = $card->serialize();
     $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `fullname` = ?,`carddata` = ?, `lastmodified` = ? WHERE `id` = ?');
     try {
         $result = $stmt->execute(array($fn, $data, time(), $id));
     } catch (Exception $e) {
         OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
         OCP\Util::writeLog('contacts', __METHOD__ . ', id' . $id, OCP\Util::DEBUG);
         return false;
     }
     OC_Contacts_Addressbook::touch($oldcard['addressbookid']);
     OC_Hook::emit('OC_Contacts_VCard', 'post_updateVCard', $id);
     return true;
 }