/** * @NoAdminRequired * @NoCSRFRequired */ public function index() { \OCP\Util::addscript('core', 'tags'); \OCP\Util::addStyle($this->appName, 'style'); \OCP\Util::addStyle($this->appName, 'jquery.Jcrop'); \OCP\Util::addStyle($this->appName, '3rdparty/fontello/css/animation'); \OCP\Util::addStyle($this->appName, '3rdparty/fontello/css/fontello'); \OCP\Util::addStyle($this->appName, '3rdparty/jquery.webui-popover'); \OCP\Util::addscript($this->appName, 'app'); \OCP\Util::addscript($this->appName, '3rdparty/jquery.webui-popover'); \OCP\Util::addscript($this->appName, 'settings'); \OCP\Util::addscript($this->appName, 'loader'); \OCP\Util::addscript($this->appName, 'jquery.scrollTo.min'); \OCP\Util::addscript($this->appName, 'jquery.nicescroll.min'); \OCP\Util::addscript('files', 'jquery.fileupload'); \OCP\Util::addscript($this->appName, 'jquery.Jcrop'); $iosSupport = $this->configInfo->getUserValue($this->userId, $this->appName, 'iossupport'); $maxUploadFilesize = \OCP\Util::maxUploadFilesize('/'); $addressbooks = Addressbook::all($this->userId); if (count($addressbooks) == 0) { Addressbook::addDefault($this->userId); $addressbooks = Addressbook::all($this->userId); } //ContactsApp::addingDummyContacts(50); $params = ['uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'iossupport' => $iosSupport, 'addressbooks' => $addressbooks]; $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); $csp->addAllowedImageDomain('*'); $csp->addAllowedFrameDomain('*'); $response = new TemplateResponse($this->appName, 'index'); $response->setContentSecurityPolicy($csp); $response->setParams($params); return $response; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $createprincipal = $this->getOwner(); $deleteprincipal = $this->getOwner(); $uid = AddrBook::extractUserID($this->getOwner()); //\OCP\Config::setUserValue($uid, 'contactsplus', 'syncaddrbook', $this->addressBookInfo['uri']); $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . \OCP\User::getUser(), 'protected' => true)); if ($uid !== \OCP\USER::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']); if ($sharedAddressbook) { if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { return $readWriteACL; } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE) { $createprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE) { $deleteprincipal = 'principals/' . \OCP\USER::getUser(); } } } else { return parent::getACL(); } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true)); }
/** * @brief Converts the shared item sources back into the item in the specified format * @param array Shared items * @param int Format * @return ? * * The items array is a 3-dimensional array with the item_source as the first key and the share id as the second key to an array with the share info. * The key/value pairs included in the share info depend on the function originally called: * If called by getItem(s)Shared: id, item_type, item, item_source, share_type, share_with, permissions, stime, file_source * If called by getItem(s)SharedWith: id, item_type, item, item_source, item_target, share_type, share_with, permissions, stime, file_source, file_target * This function allows the backend to control the output of shared items with custom formats. * It is only called through calls to the public getItem(s)Shared(With) functions. */ public function formatItems($items, $format, $parameters = null) { $addressbooks = array(); if ($format == self::FORMAT_ADDRESSBOOKS) { foreach ($items as $item) { $addressbook = AddrBook::find($item['item_source']); if ($addressbook) { $addressbook['displayname'] = $item['item_target']; $addressbook['permissions'] = $item['permissions']; $addressbooks[] = $addressbook; } } } return $addressbooks; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = AddrBook::extractUserID($this->getOwner()); if ($uid !== \OCP\USER::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(ContactsApp::SHAREADDRESSBOOK, ContactsApp::SHAREADDRESSBOOKPREFIX . $this->addressBookInfo['id']); if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_READ) { $readprincipal = 'principals/' . \OCP\USER::getUser(); } if ($sharedAddressbook && $sharedAddressbook['permissions'] & \OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . \OCP\USER::getUser(); } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true)); }
/** * @NoAdminRequired * @NoCSRFRequired */ public function index() { $iosSupport = $this->configInfo->getUserValue($this->userId, $this->appName, 'iossupport'); $activeView = $this->configInfo->getUserValue($this->userId, $this->appName, 'view', 'listview'); $lastSelectedBook = $this->configInfo->getUserValue($this->userId, $this->appName, 'currentbook', 0); $maxUploadFilesize = \OCP\Util::maxUploadFilesize('/'); $addressbooks = Addressbook::all($this->userId); if (count($addressbooks) == 0) { Addressbook::addDefault($this->userId); $addressbooks = Addressbook::all($this->userId); } //ContactsApp::addingDummyContacts(1000); $params = ['uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'iossupport' => $iosSupport, 'addressbooks' => $addressbooks, 'activeView' => $activeView, 'lastSelectedBook' => $lastSelectedBook]; $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); $csp->addAllowedImageDomain('*'); $csp->addAllowedFrameDomain('*'); $response = new TemplateResponse($this->appName, 'index'); $response->setContentSecurityPolicy($csp); $response->setParams($params); return $response; }
/** * @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) { $addressbook = Addressbook::find($aid); if ($addressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) { throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts into this address book')); } } if (is_array($id)) { // NOTE: This block is currently not used and need rewrite if used! foreach ($id as $index => $cardId) { $card = self::find($cardId); if (!$card) { unset($id[$index]); } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedContact = \OCP\Share::getItemSharedWithBySource(App::SHARECONTACT, App::SHARECONTACTPREFIX . $cardId, \OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & \OCP\PERMISSION_DELETE)) { unset($id[$index]); } } } $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE `' . App::ContactsTable . '` 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); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('Database error during move.')); } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog(App::$appname, __METHOD__ . ', ids: ' . join(',', $vals), \OCP\Util::DEBUG); \OCP\Util::writeLog(App::$appname, __METHOD__ . ', SQL:' . $prep, \OCP\Util::DEBUG); throw new \Exception(App::$l10n->t('Database error during move.')); } } else { $stmt = null; if ($isAddressbook) { $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `addressbookid` = ?'); } else { $card = self::find($id); if (!$card) { throw new \Exception(App::$l10n->t('Error finding card to move.')); } $oldAddressbook = Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $oldAddressbook['id']); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You don\'t have permissions to move contacts from this address book')); } } Addressbook::touch($oldAddressbook['id']); $stmt = \OCP\DB::prepare('UPDATE `' . App::ContactsTable . '` SET `addressbookid` = ? WHERE `id` = ?'); } try { $result = $stmt->execute(array($aid, $id)); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('Database error during move.')); } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::DEBUG); \OCP\Util::writeLog(App::$appname, __METHOD__ . ' id: ' . $id, \OCP\Util::DEBUG); throw new \Exception(App::$l10n->t('Database error during move.')); } } //\OC_Hook::emit('\OCA\Contacts\VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id)); Addressbook::touch($aid); return true; }
/** * @NoAdminRequired */ public function checkAddressbookExists() { $pAddressbook = $this->params('addrbookname'); $id = Addressbook::checkIfExist($pAddressbook); //\OCP\Util::writeLog($this->appName,'CHECK: '.$id, \OCP\Util::DEBUG); if ($id) { $params = ['status' => 'success', 'message' => 'exists']; $response = new JSONResponse($params); return $response; } }
public static function addingDummyContacts($iNum) { $active_addressbooks = array(); $active_addressbooks = Addressbook::active(\OCP\USER::getUser()); $contacts_addressbook = array(); $ids = array(); foreach ($active_addressbooks as $addressbook) { $ids[] = $addressbook['id']; } for ($i = 0; $i < $iNum; $i++) { //$dummyName=self::generateFnDummy(); $dummySure = self::generateFnDummy(10); $dummyLast = self::generateFnDummy(10); $uid = substr(md5(rand() . time()), 0, 10); $aid = $ids[0]; $vcard = new VObject\Component\VCard(array('N' => array($dummySure, $dummyLast, '', '', ''), 'UID' => $uid)); $vcard->FN = $dummySure . ' ' . $dummyLast; $vcard->CATEGORIES = 'familie'; $vcard->add('TEL', '+1 555 34567 456', array('type' => 'fax')); $vcard->add('TEL', '+1 555 34567 457', array('type' => 'voice', 'pref' => 1)); $vcard->add('EMAIL', '*****@*****.**', array('type' => 'work')); $vcard->add('EMAIL', '*****@*****.**', array('type' => 'private', 'pref' => 1)); $id = VCard::add($aid, $vcard, null, true); } }
/** * @NoAdminRequired * @NoCSRFRequired */ public function exportBirthdays() { $bookid = $this->params('aid'); $bookid = isset($bookid) ? $bookid : null; if (!is_null($bookid)) { $addressbook = Addressbook::find($bookid); $aDefNArray = array('0' => 'fname', '1' => 'lname', '3' => 'title', '4' => ''); foreach (VCard::all($bookid) as $contact) { try { $vcard = VObject\Reader::read($contact['carddata']); } catch (Exception $e) { continue; } $birthday = $vcard->BDAY; if ((string) $birthday) { $details = VCard::structureContact($vcard); $BirthdayTemp = new \DateTime($birthday); $checkForm = $BirthdayTemp->format('d-m-Y'); $temp = explode('-', $checkForm); $getAge = $this->getAgeCalc($temp[2], $temp[1], $temp[0]); //$getAge=$BirthdayTemp->format('d-m-Y'); $title = isset($vcard->FN) ? strtr($vcard->FN->getValue(), array('\\,' => ',', '\\;' => ';')) : ''; $sNameOutput = ''; if (isset($details['N'][0]['value']) && count($details['N'][0]['value']) > 0) { foreach ($details['N'][0]['value'] as $key => $val) { if ($val != '') { $aNameOutput[$aDefNArray[$key]] = $val; } } //$sNameOutput=isset($aNameOutput['title'])?$aNameOutput['title'].' ':''; $sNameOutput .= isset($aNameOutput['lname']) ? $aNameOutput['lname'] . ' ' : ''; $sNameOutput .= isset($aNameOutput['fname']) ? $aNameOutput['fname'] . ' ' : ''; unset($aNameOutput); } if ($sNameOutput == '') { $sNameOutput = $title; } $sTitle1 = (string) $this->l10n->t('%1$s (%2$s)', array($sNameOutput, $getAge)); $aktYear = $BirthdayTemp->format('d-m'); $aktYear = $aktYear . date('-Y'); $start = new \DateTime($aktYear); $end = new \DateTime($aktYear . ' +1 day'); $vcalendar = new VObject\Component\VCalendar(); $vevent = $vcalendar->createComponent('VEVENT'); $vevent->add('DTSTART'); $vevent->DTSTART->setDateTime($start); $vevent->DTSTART['VALUE'] = 'date'; $vevent->add('DTEND'); $vevent->DTEND->setDateTime($end); $vevent->DTEND['VALUE'] = 'date'; $vevent->{'SUMMARY'} = (string) $sTitle1; $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10); $params['events'][] = $vevent->serialize(); } } if (is_array($params['events'])) { $return = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud Calendar " . \OCP\App::getAppVersion('calendar') . "\nX-WR-CALNAME: export-bday-" . $bookid . "\n"; foreach ($params['events'] as $event) { $return .= $event; } $return .= "END:VCALENDAR"; $name = str_replace(' ', '_', $addressbook['displayname']) . '_birthdays' . '.ics'; $response = new DataDownloadResponse($return, $name, 'text/calendar'); return $response; } } }
/** * Deletes an entire addressbook and all its contents * * @param int $addressbookid * @return void */ public function deleteAddressBook($addressbookid) { AddrBook::delete($addressbookid); }
/** * @NoAdminRequired */ public function delete() { $pId = $this->params('id'); if (!$pId) { $msg = (string) $this->l10n->t('id is not set.'); } try { Addressbook::delete($pId); } catch (Exception $e) { //bailOut($e->getMessage()); } $params = ['status' => 'success', 'data' => ['id' => $pId]]; $response = new JSONResponse($params); return $response; }
public static function getBirthdayEvents($params) { if (\OCP\Config::getUserValue(\OCP\USER::getUser(), 'calendarplus', 'calendar_birthday_' . \OCP\USER::getUser())) { $name = $params['calendar_id']; if (strpos($name, 'birthday_') != 0) { return; } $info = explode('_', $name); $aid = $info[1]; $aDefNArray = array('0' => 'fname', '1' => 'lname', '3' => 'title', '4' => ''); foreach (Addressbook::all($aid) as $addressbook) { foreach (VCard::all($addressbook['id']) as $contact) { try { $vcard = VObject\Reader::read($contact['carddata']); } catch (Exception $e) { continue; } $birthday = $vcard->BDAY; if ((string) $birthday) { $details = VCard::structureContact($vcard); $BirthdayTemp = new \DateTime($birthday); $checkForm = $BirthdayTemp->format('d-m-Y'); $temp = explode('-', $checkForm); $getAge = self::getAge($temp[2], $temp[1], $temp[0]); //$getAge=$BirthdayTemp->format('d-m-Y'); $title = isset($vcard->FN) ? strtr($vcard->FN->getValue(), array('\\,' => ',', '\\;' => ';')) : ''; $sNameOutput = ''; if (isset($details['N'][0]['value']) && count($details['N'][0]['value']) > 0) { foreach ($details['N'][0]['value'] as $key => $val) { if ($val != '') { $aNameOutput[$aDefNArray[$key]] = $val; } } //$sNameOutput=isset($aNameOutput['title'])?$aNameOutput['title'].' ':''; $sNameOutput .= isset($aNameOutput['lname']) ? $aNameOutput['lname'] . ' ' : ''; $sNameOutput .= isset($aNameOutput['fname']) ? $aNameOutput['fname'] . ' ' : ''; unset($aNameOutput); } if ($sNameOutput == '') { $sNameOutput = $title; } $sTitle1 = (string) App::$l10n->t('%1$s (%2$s)', array($sNameOutput, $getAge)); $aktYear = $BirthdayTemp->format('d-m'); $aktYear = $aktYear . date('-Y'); $start = new \DateTime($aktYear); $end = new \DateTime($aktYear . ' +1 day'); $vcalendar = new VObject\Component\VCalendar(); $vevent = $vcalendar->createComponent('VEVENT'); $vevent->add('DTSTART'); $vevent->DTSTART->setDateTime($start); $vevent->DTSTART['VALUE'] = 'date'; $vevent->add('DTEND'); $vevent->DTEND->setDateTime($end); $vevent->DTEND['VALUE'] = 'date'; $vevent->{'SUMMARY'} = (string) $sTitle1; $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10); // DESCRIPTION? $aktYear1 = $BirthdayTemp->format('-m-d'); $aktYear1 = date('Y') . $aktYear1; $params['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'calendarid' => $params['calendar_id'], 'privat' => false, 'bday' => true, 'shared' => false, 'isalarm' => false, 'summary' => $sTitle1, 'start' => $aktYear1, 'allDay' => true, 'startlist' => $aktYear1, 'editable' => false, 'className' => 'birthdayevent', 'startEditable ' => false, 'durationEditable ' => false); } } } } return true; }
/** * @NoAdminRequired */ public function getContactCards() { $grpId = $this->params('grpid'); $addrbookId = intval($this->params('ardbid')); $grpId = isset($grpId) ? $grpId : 'all'; if ($addrbookId == 0) { $active_addressbooks = Addressbook::all($this->userId); $ids = array(); foreach ($active_addressbooks as $addressbook) { $ids[] = $addressbook['id']; } $addrbookId = $ids[0]; } $this->configInfo->setUserValue($this->userId, $this->appName, 'currentbook', $addrbookId); $cardslist = ContactsApp::renderOutput($addrbookId, $grpId); return $cardslist; }