示例#1
0
 public static function getCalenderSources($parameters)
 {
     $base_url = OCP\Util::linkTo('calendar', 'ajax/events.php') . '?calendar_id=';
     foreach (OC_Contacts_Addressbook::all(OCP\USER::getUser()) as $addressbook) {
         $parameters['sources'][] = array('url' => $base_url . 'birthday_' . $addressbook['id'], 'backgroundColor' => '#cccccc', 'borderColor' => '#888', 'textColor' => 'black', 'cache' => true, 'editable' => false);
     }
 }
示例#2
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     // 		if(count($calendars)==0 || !OCP\App::isEnabled('contacts')){
     // 			//return false;
     // 		}
     // NOTE: Does the following do anything
     $results = array();
     $searchquery = array();
     if (substr_count($query, ' ') > 0) {
         $searchquery = explode(' ', $query);
     } else {
         $searchquery[] = $query;
     }
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '?id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
 /**
  * @brief Deletes all Addressbooks of a certain user
  * @param paramters parameters from postDeleteUser-Hook
  * @return array
  */
 public function deleteUser($parameters)
 {
     $addressbooks = OC_Contacts_Addressbook::all($parameters['uid']);
     foreach ($addressbooks as $addressbook) {
         OC_Contacts_Addressbook::delete($addressbook['id']);
     }
     return true;
 }
示例#4
0
 /**
  * @brief Get a unique name of the item for the specified user
  * @param string Item
  * @param string|false User the item is being shared with
  * @param array|null List of similar item names already existing as shared items
  * @return string Target name
  *
  * This function needs to verify that the user does not already have an item with this name.
  * If it does generate a new name e.g. name_#
  */
 public function generateTarget($itemSource, $shareWith, $exclude = null)
 {
     $calendar = OC_Calendar_App::getCalendar($itemSource);
     $user_calendars = array();
     foreach (OC_Contacts_Addressbook::all($calendar['userid']) as $user_calendar) {
         $user_calendars[] = $user_calendar['displayname'];
     }
     $name = $calendar['userid'] . "'s " . $calendar['displayname'];
     $suffix = '';
     while (in_array($name . $suffix, $user_calendars)) {
         $suffix++;
     }
     return $name . $suffix;
 }
示例#5
0
 function search($query)
 {
     $addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser(), 1);
     if (count($addressbooks) == 0 || !OCP\App::isEnabled('contacts')) {
         return array();
     }
     $results = array();
     $l = new OC_l10n('contacts');
     foreach ($addressbooks as $addressbook) {
         $vcards = OC_Contacts_VCard::all($addressbook['id']);
         foreach ($vcards as $vcard) {
             if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) {
                 $link = OCP\Util::linkTo('contacts', 'index.php') . '&id=' . urlencode($vcard['id']);
                 $results[] = new OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact'));
                 //$name,$text,$link,$type
             }
         }
     }
     return $results;
 }
示例#6
0
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG);
    exit;
}
function debug($msg)
{
    OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG);
}
$categories = isset($_POST['categories']) ? $_POST['categories'] : null;
if (is_null($categories)) {
    bailOut(OC_Contacts_App::$l10n->t('No categories selected for deletion.'));
}
debug(print_r($categories, true));
$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
if (count($addressbooks) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
}
$addressbookids = array();
foreach ($addressbooks as $addressbook) {
    $addressbookids[] = $addressbook['id'];
}
$contacts = OC_Contacts_VCard::all($addressbookids);
if (count($contacts) == 0) {
    bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
}
$cards = array();
foreach ($contacts as $contact) {
    $cards[] = array($contact['id'], $contact['carddata']);
}
示例#7
0
<?php

$tmpl = new OCP\Template('contacts', 'settings');
$tmpl->assign('addressbooks', OC_Contacts_Addressbook::all(OCP\USER::getUser()));
$tmpl->printPage();
示例#8
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 $vcaddressbookids[] = $vcaddressbook['id'];
             }
             $vccontacts = OC_Contacts_VCard::all($vcaddressbookids);
         }
     }
     if (is_array($vccontacts) && count($vccontacts) > 0) {
         $cards = array();
         foreach ($vccontacts as $vccontact) {
             $cards[] = $vccontact['carddata'];
         }
         self::$categories->rescan($cards);
     }
 }
	<th><?php 
echo $l->t('Select address book to import to:');
?>
</th>
	<td>
		<form id="import_upload_form" action="<?php 
echo OCP\Util::linkTo('contacts', 'ajax/uploadimport.php');
?>
" method="post" enctype="multipart/form-data" target="import_upload_target">
			<input type="hidden" name="requesttoken" value="<?php 
echo $_['requesttoken'];
?>
">
			<select id="book" name="book" class="float">
			<?php 
$contacts_options = OC_Contacts_Addressbook::all(OCP\USER::getUser());
echo OCP\html_select_options($contacts_options, $contacts_options[0]['id'], array('value' => 'id', 'label' => 'displayname'));
?>
			</select>
			<span id="import_drop_target" class="droptarget float"><?php 
echo $l->t("Drop a VCF file<br />to import contacts.");
?>
 (Max. <?php 
echo $_['uploadMaxHumanFilesize'];
?>
)</span>
			<a class="svg upload float" title="<?php 
echo $l->t('Select from HD');
?>
">
			<input class="float" id="import_upload_start" type="file" accept="text/*" name="importfile" /></a>
示例#10
0
 /**
  * @brief Get active addressbooks for a user.
  * @param integer $uid User id. If null current user will be used.
  * @return array
  */
 public static function activeIds($uid = null)
 {
     if (is_null($uid)) {
         $uid = OCP\USER::getUser();
     }
     $prefbooks = OCP\Config::getUserValue($uid, 'contacts', 'openaddressbooks', null);
     $prefbooks = explode(';', $prefbooks);
     for ($i = 0; $i < count($prefbooks); $i++) {
         if (!$prefbooks[$i] || !self::find($prefbooks[$i])) {
             unset($prefbooks[$i]);
         }
     }
     if (!$prefbooks) {
         OCP\Util::writeLog('contacts', 'OC_Contacts_Addressbook:activeIds:, No active addressbooks', OCP\Util::DEBUG);
         $addressbooks = OC_Contacts_Addressbook::all($uid);
         if (count($addressbooks) == 0) {
             OCP\Util::writeLog('contacts', 'OC_Contacts_Addressbook:activeIds:, No addressbooks', OCP\Util::DEBUG);
             $id = self::add($uid, 'default', 'Default Address Book');
             OCP\Util::writeLog('contacts', 'OC_Contacts_Addressbook:activeIds:, Created addressbook: ' . $id, OCP\Util::DEBUG);
             self::setActive($id, true);
             $addressbooks = OC_Contacts_Addressbook::all($uid);
         }
         $prefbooks[] = $addressbooks[0]['id'];
         OCP\Config::setUserValue($uid, 'contacts', 'openaddressbooks', implode(';', $prefbooks));
     }
     return $prefbooks;
 }
 /**
  * @brief Get active addressbooks for a user.
  * @param integer $uid User id. If null current user will be used.
  * @return array
  */
 public static function activeIds($uid = null)
 {
     if (is_null($uid)) {
         $uid = OCP\USER::getUser();
     }
     $prefbooks = OCP\Config::getUserValue($uid, 'contacts', 'openaddressbooks', null);
     if (!$prefbooks) {
         $addressbooks = OC_Contacts_Addressbook::all($uid);
         if (count($addressbooks) == 0) {
             OC_Contacts_Addressbook::add($uid, 'default', 'Default Address Book');
             $addressbooks = OC_Contacts_Addressbook::all($uid);
         }
         $prefbooks = $addressbooks[0]['id'];
         OCP\Config::setUserValue($uid, 'contacts', 'openaddressbooks', $prefbooks);
     }
     return explode(';', $prefbooks);
 }
示例#12
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 $vcaddressbookids[] = $vcaddressbook['id'];
             }
             $start = 0;
             $batchsize = 10;
             while ($vccontacts = OC_Contacts_VCard::all($vcaddressbookids, $start, $batchsize)) {
                 $cards = array();
                 foreach ($vccontacts as $vccontact) {
                     $cards[] = $vccontact['carddata'];
                 }
                 OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, OCP\Util::DEBUG);
                 // only reset on first batch.
                 self::getVCategories()->rescan($cards, true, $start == 0 ? true : false);
                 $start += $batchsize;
             }
         }
     }
 }
 *
 */
function contacts_namesort($a, $b)
{
    return strcmp($a['name'], $b['name']);
}
// Init owncloud
require_once '../../lib/base.php';
// Check if we are a user
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
// Check if the user has an addressbook
$addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
if (count($addressbooks) == 0) {
    OC_Contacts_Addressbook::add(OC_User::getUser(), 'default', 'Default Address Book');
    $addressbooks = OC_Contacts_Addressbook::all(OC_User::getUser());
}
$prefbooks = OC_Preferences::getValue(OC_User::getUser(), 'contacts', 'openaddressbooks', null);
if (is_null($prefbooks)) {
    $prefbooks = $addressbooks[0]['id'];
    OC_Preferences::setValue(OC_User::getUser(), 'contacts', 'openaddressbooks', $prefbooks);
}
// Load the files we need
OC_App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
// sort addressbooks  (use contactsort)
usort($addressbooks, 'contacts_namesort');
// Addressbooks to load
$openaddressbooks = explode(';', $prefbooks);
$contacts = array();