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
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 #4
0
 /**
  * @NoAdminRequired
  */
 public function setReminderDate()
 {
     $taskId = $this->params('taskID');
     $type = $this->params('type');
     $action = $this->params('action');
     // $date = $this->params('date');
     $response = new JSONResponse();
     $types = array('DATE-TIME', 'DURATION');
     $vcalendar = \OC_Calendar_App::getVCalendar($taskId);
     $vtodo = $vcalendar->VTODO;
     $valarm = $vtodo->VALARM;
     if ($type == false) {
         unset($vtodo->VALARM);
         $vtodo->setDateTime('LAST-MODIFIED', 'now', \Sabre\VObject\Property\DateTime::UTC);
         $vtodo->setDateTime('DTSTAMP', 'now', \Sabre\VObject\Property\DateTime::UTC);
         \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
     } elseif (in_array($type, $types)) {
         try {
             if ($valarm == null) {
                 $valarm = new \OC_VObject('VALARM');
                 $valarm->setString('ACTION', $action);
                 $valarm->setString('DESCRIPTION', 'Default Event Notification');
                 $valarm->setString('');
                 $vtodo->add($valarm);
             } else {
                 unset($valarm->TRIGGER);
             }
             $tv = '';
             $related = null;
             if ($type == 'DATE-TIME') {
                 $date = new \DateTime('@' . $this->params('date'));
                 $tv = $date->format('Ymd\\THis\\Z');
             } elseif ($type == 'DURATION') {
                 $invert = $this->params('invert');
                 $related = $this->params('related');
                 $week = (int) $this->params('week');
                 $day = (int) $this->params('day');
                 $hour = (int) $this->params('hour');
                 $minute = (int) $this->params('minute');
                 $second = (int) $this->params('second');
                 // Create duration string
                 if ($week || $day || $hour || $minute || $second) {
                     if ($invert) {
                         $tv .= '-';
                     }
                     $tv .= 'P';
                     if ($week) {
                         $tv .= $week . 'W';
                     }
                     if ($day) {
                         $tv .= $day . 'D';
                     }
                     $tv .= 'T';
                     if ($hour) {
                         $tv .= $hour . 'H';
                     }
                     if ($minute) {
                         $tv .= $minute . 'M';
                     }
                     if ($second) {
                         $tv .= $second . 'S';
                     }
                 } else {
                     $tv = 'PT0S';
                 }
             }
             if ($related == 'END') {
                 $valarm->addProperty('TRIGGER', $tv, array('VALUE' => $type, 'RELATED' => $related));
             } else {
                 $valarm->addProperty('TRIGGER', $tv, array('VALUE' => $type));
             }
             $vtodo->setDateTime('LAST-MODIFIED', 'now', \Sabre\VObject\Property\DateTime::UTC);
             $vtodo->setDateTime('DTSTAMP', 'now', \Sabre\VObject\Property\DateTime::UTC);
             \OC_Calendar_Object::edit($taskId, $vcalendar->serialize());
         } catch (\Exception $e) {
         }
     }
     return $response;
 }