Beispiel #1
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos('birthday_', $name) != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title);
         }
     }
 }
Beispiel #2
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     OC_Contacts_App::getAddressbook($aid);
     foreach (OC_Contacts_VCard::all($aid) as $card) {
         $vcard = OC_VObject::parse($card['carddata']);
         if (!$vcard) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new DateTime($birthday);
             $vevent = new OC_VObject('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
             $vevent->setString('DURATION', 'P1D');
             $vevent->setString('UID', substr(md5(rand() . time()), 0, 10));
             // DESCRIPTION?
             $vevent->setString('RRULE', 'FREQ=YEARLY');
             $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }
Beispiel #3
0
 /**
  * @brief Move card(s) to an address book
  * @param integer $aid Address book id
  * @param $id Array or integer of cards to be moved.
  * @return boolean
  *
  */
 public static function moveToAddressBook($aid, $id)
 {
     OC_Contacts_App::getAddressbook($aid);
     // check for user ownership.
     if (is_array($id)) {
         $id_sql = join(',', array_fill(0, count($id), '?'));
         $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN (' . $id_sql . ')';
         try {
             $stmt = OCP\DB::prepare($prep);
             //$aid = array($aid);
             $vals = array_merge((array) $aid, $id);
             $result = $stmt->execute($vals);
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, ids: ' . join(',', $vals), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', 'SQL:' . $prep, OCP\Util::DEBUG);
             return false;
         }
     } else {
         try {
             $stmt = OCP\DB::prepare('UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?');
             $result = $stmt->execute(array($aid, $id));
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, id: ' . $id, OCP\Util::DEBUG);
             return false;
         }
     }
     OC_Contacts_Addressbook::touch($aid);
     return true;
 }
Beispiel #4
0
<?php

/**
 * Copyright (c) 2011 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Bart Visscher <*****@*****.**>
 * 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');
OCP\JSON::callCheck();
$bookid = $_POST['bookid'];
$book = OC_Contacts_App::getAddressbook($bookid);
// is owner access check
if (!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
    OCP\Util::writeLog('contacts', 'ajax/activation.php: Error activating addressbook: ' . $bookid, OCP\Util::ERROR);
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'))));
    exit;
}
OCP\JSON::success(array('active' => OC_Contacts_Addressbook::isActive($bookid), 'bookid' => $bookid, 'book' => $book));
Beispiel #5
0
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)));
Beispiel #6
0
 /**
  * @brief Move card(s) to an address book
  * @param integer $aid Address book id
  * @param $id Array or integer of cards to be moved.
  * @return boolean
  *
  */
 public static function moveToAddressBook($aid, $id, $isAddressbook = false)
 {
     OC_Contacts_App::getAddressbook($aid);
     // check for user ownership.
     $addressbook = OC_Contacts_Addressbook::find($aid);
     if ($addressbook['userid'] != OCP\User::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid);
         if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) {
             return false;
         }
     }
     if (is_array($id)) {
         foreach ($id as $index => $cardId) {
             $card = self::find($cardId);
             if (!$card) {
                 unset($id[$index]);
             }
             $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != OCP\User::getUser()) {
                 $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true);
                 if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
                     unset($id[$index]);
                 }
             }
         }
         $id_sql = join(',', array_fill(0, count($id), '?'));
         $prep = 'UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')';
         try {
             $stmt = OCP\DB::prepare($prep);
             //$aid = array($aid);
             $vals = array_merge((array) $aid, $id);
             $result = $stmt->execute($vals);
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR);
             OCP\Util::writeLog('contacts', __METHOD__ . ', ids: ' . join(',', $vals), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', __METHOD__ . ', SQL:' . $prep, OCP\Util::DEBUG);
             return false;
         }
     } else {
         $stmt = null;
         if ($isAddressbook) {
             $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `addressbookid` = ?');
         } else {
             $card = self::find($id);
             if (!$card) {
                 return false;
             }
             $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
             if ($oldAddressbook['userid'] != OCP\User::getUser()) {
                 $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true);
                 if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) {
                     return false;
                 }
             }
             $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` = ?');
         }
         try {
             $result = $stmt->execute(array($aid, $id));
         } catch (Exception $e) {
             OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::DEBUG);
             OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id, OCP\Util::DEBUG);
             return false;
         }
     }
     OC_Hook::emit('OC_Contacts_VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id));
     OC_Contacts_Addressbook::touch($aid);
     return true;
 }
<?php

/**
 * Copyright (c) 2011 Bart Visscher <*****@*****.**>
 * 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');
$addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']);
$tmpl = new OCP\Template("contacts", "part.editaddressbook");
$tmpl->assign('new', false);
$tmpl->assign('addressbook', $addressbook);
$tmpl->printPage();