示例#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;
 }
示例#3
0
 function import()
 {
     switch ($this->appinfo->version) {
         default:
             // All versions of the app have had the same db structure, so all can use the same import function
             $query = $this->content->prepare('SELECT * FROM `contacts_addressbooks` WHERE `userid` LIKE ?');
             $results = $query->execute(array($this->olduid));
             $idmap = array();
             while ($row = $results->fetchRow()) {
                 // Import each addressbook
                 $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
                 $addressbookquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag']));
                 // Map the id
                 $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
                 // Make the addressbook active
                 OC_Contacts_Addressbook::setActive($idmap[$row['id']], true);
             }
             // Now tags
             foreach ($idmap as $oldid => $newid) {
                 $query = $this->content->prepare('SELECT * FROM `contacts_cards` WHERE `addressbookid` LIKE ?');
                 $results = $query->execute(array($oldid));
                 while ($row = $results->fetchRow()) {
                     // Import the contacts
                     $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
                     $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified']));
                 }
             }
             // All done!
             break;
     }
     return true;
 }
 /**
  * @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;
 }
示例#5
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;
 }
示例#6
0
 /**
  * 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 = OC_Contacts_Addressbook::extractUserID($this->getOwner());
     if ($uid != OCP\USER::getUser()) {
         $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']);
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & OCP\Share::PERMISSION_READ) {
             $readprincipal = 'principals/' . OCP\USER::getUser();
         }
         if ($sharedAddressbook && $sharedAddressbook['permissions'] & OCP\Share::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));
 }
示例#7
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;
 }
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Init owncloud
require_once '../../../lib/base.php';
$aid = $_POST['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('contacts');
$addressbook = OC_Contacts_Addressbook::find($aid);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    OC_JSON::error(array('data' => array('message' => $l10n->t('This is not your addressbook.'))));
    // Same here (as with the contact error). Could this error be improved?
    exit;
}
$fn = $_POST['fn'];
$values = $_POST['value'];
$parameters = $_POST['parameters'];
$vcard = new Sabre_VObject_Component('VCARD');
$vcard->add(new Sabre_VObject_Property('FN', $fn));
$vcard->add(new Sabre_VObject_Property('UID', OC_Contacts_VCard::createUID()));
foreach (array('ADR', 'TEL', 'EMAIL', 'ORG') as $propname) {
    $value = $values[$propname];
    if (isset($parameters[$propname])) {
        $prop_parameters = $parameters[$propname];
示例#9
0
 *
 */
// Init owncloud
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);
示例#10
0
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
$bookid = $_POST['id'];
OC_Contacts_App::getAddressbook($bookid);
// is owner access check
$name = trim(strip_tags($_POST['name']));
if (!$name) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'))));
    OCP\Util::writeLog('contacts', 'ajax/updateaddressbook.php: Cannot update addressbook with an empty name: ' . strip_tags($_POST['name']), OCP\Util::ERROR);
    exit;
}
if (!OC_Contacts_Addressbook::edit($bookid, $name, null)) {
    OCP\JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/updateaddressbook.php: Error adding addressbook: ', OCP\Util::ERROR);
    //exit();
}
if (!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
    OCP\JSON::error(array('data' => array('message' => $l->t('Error (de)activating addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/updateaddressbook.php: Error (de)activating addressbook: ' . $bookid, OCP\Util::ERROR);
    //exit();
}
$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
OCP\JSON::success(array('page' => $tmpl->fetchPage(), 'addressbook' => $addressbook));
	<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>
示例#12
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;
 }
 /**
  * @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);
 }
示例#14
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));
示例#15
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);
     }
 }
 /**
  * @brief edits a card with the data provided by sabredav
  * @param integer $id Addressbook id
  * @param string $uri   the uri of the card
  * @param string $data  vCard file
  * @return boolean
  */
 public static function editFromDAVData($aid, $uri, $data)
 {
     $oldcard = self::findWhereDAVDataIs($aid, $uri);
     $fn = null;
     $card = self::parse($data);
     if (!is_null($card)) {
         foreach ($card->children as $property) {
             if ($property->name == 'FN') {
                 $fn = $property->value;
             }
         }
     }
     $stmt = OC_DB::prepare('UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?');
     $result = $stmt->execute(array($fn, $data, time(), $oldcard['id']));
     OC_Contacts_Addressbook::touch($oldcard['addressbookid']);
     return true;
 }
echo htmlspecialchars($_['addressbook']['displayname']);
?>
">
	</td>
</tr>
<?php 
if (!$_['new']) {
    ?>
<tr>
	<td></td>
	<td>
		<input id="edit_active_<?php 
    echo $_['addressbook']['id'];
    ?>
" type="checkbox"<?php 
    echo OC_Contacts_Addressbook::isActive($_['addressbook']['id']) ? ' checked="checked"' : '';
    ?>
>
		<label for="edit_active_<?php 
    echo $_['addressbook']['id'];
    ?>
">
			<?php 
    echo $l->t('Active');
    ?>
		</label>
	</td>
</tr>
<?php 
}
?>
 *
 */
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();
示例#19
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;
 }
示例#20
0
 * @copyright 2011 Jakob Sack mail@jakobsack.de
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once __DIR__ . '/../loghandler.php';
$id = $_POST['id'];
if (!$id) {
    bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
}
try {
    OC_Contacts_Addressbook::delete($id);
} catch (Exception $e) {
    bailOut($e->getMessage());
}
OCP\JSON::success(array('data' => array('id' => $id)));
示例#21
0
 /**
  * Deletes an entire addressbook and all its contents
  *
  * @param int $addressbookid
  * @return void
  */
 public function deleteAddressBook($addressbookid)
 {
     OC_Contacts_Addressbook::delete($addressbookid);
 }
示例#22
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;
             }
         }
     }
 }
 * Copyright (c) 2011-2012 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.
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$userid = OCP\USER::getUser();
$name = trim(strip_tags($_POST['name']));
if (!$name) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add addressbook with an empty name.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Cannot add addressbook with an empty name: ' . strip_tags($_POST['name']), OCP\Util::ERROR);
    exit;
}
$bookid = OC_Contacts_Addressbook::add($userid, $name, null);
if (!$bookid) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Error adding addressbook: ' . $_POST['name'], OCP\Util::ERROR);
    exit;
}
if (!OC_Contacts_Addressbook::setActive($bookid, 1)) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error activating addressbook.'))));
    OCP\Util::writeLog('contacts', 'ajax/createaddressbook.php: Error activating addressbook: ' . $bookid, OCP\Util::ERROR);
    //exit();
}
$addressbook = OC_Contacts_App::getAddressbook($bookid);
$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
$tmpl->assign('addressbook', $addressbook);
OCP\JSON::success(array('page' => $tmpl->fetchPage(), 'addressbook' => $addressbook));
示例#24
0
    $view = OCP\Files::getStorage('contacts');
    $file = $view->file_get_contents('/imports/' . $_POST['file']);
} else {
    $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
}
if (!$file) {
    OCP\JSON::error(array('data' => array('message' => 'Import file was empty.')));
    exit;
}
if (isset($_POST['method']) && $_POST['method'] == 'new') {
    $id = OC_Contacts_Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);
    if (!$id) {
        OCP\JSON::error(array('data' => array('message' => 'Error creating address book.')));
        exit;
    }
    OC_Contacts_Addressbook::setActive($id, 1);
} else {
    $id = $_POST['id'];
    if (!$id) {
        OCP\JSON::error(array('data' => array('message' => 'Error getting the ID of the address book.', 'file' => $_POST['file'])));
        exit;
    }
    OC_Contacts_App::getAddressbook($id);
    // is owner access check
}
//analyse the contacts file
writeProgress('40');
$file = str_replace(array("\r", "\n\n"), array("\n", "\n"), $file);
$lines = explode($nl, $file);
$inelement = false;
$parts = array();
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Init owncloud
require_once '../../lib/base.php';
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('contacts');
$id = $_GET['id'];
$l10n = new OC_L10N('contacts');
$card = OC_Contacts_VCard::find($id);
if ($card === false) {
    echo $l10n->t('Contact could not be found.');
    exit;
}
$addressbook = OC_Contacts_Addressbook::find($card['addressbookid']);
if ($addressbook === false || $addressbook['userid'] != OC_USER::getUser()) {
    echo $l10n->t('This is not your contact.');
    // This is a weird error, why would it come up? (Better feedback for users?)
    exit;
}
$content = OC_Contacts_VCard::parse($card['carddata']);
// invalid vcard
if (is_null($content)) {
    echo $l10n->t('This card is not RFC compatible.');
    exit;
}
// Photo :-)
foreach ($content->children as $child) {
    if ($child->name == 'PHOTO') {
        $mime = 'image/jpeg';
示例#26
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;
 }
示例#27
0
<?php

$tmpl = new OCP\Template('contacts', 'settings');
$tmpl->assign('addressbooks', OC_Contacts_Addressbook::all(OCP\USER::getUser()));
$tmpl->printPage();
示例#28
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * Copyright (c) 2011 Jakob Sack mail@jakobsack.de
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
// Check if we are a user
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
// Get active address books. This creates a default one if none exists.
$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$has_contacts = count(OC_Contacts_VCard::all($ids, 0, 1)) > 0 ? true : false;
// just to check if there are any contacts.
if ($has_contacts === false) {
    OCP\Util::writeLog('contacts', 'index.html: No contacts found.', OCP\Util::DEBUG);
}
// Load the files we need
OCP\App::setActiveNavigationEntry('contacts_index');
// Load a specific user?
$id = isset($_GET['id']) ? $_GET['id'] : null;
$impp_types = OC_Contacts_App::getTypesOfProperty('IMPP');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$email_types = OC_Contacts_App::getTypesOfProperty('EMAIL');
$ims = OC_Contacts_App::getIMOptions();
$im_protocols = array();
foreach ($ims as $name => $values) {
    $im_protocols[$name] = $values['displayname'];
}
示例#29
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']);
}
示例#30
0
{
    if ($a['displayname'] == $b['displayname']) {
        return 0;
    }
    return $a['displayname'] < $b['displayname'] ? -1 : 1;
}
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$start = isset($_GET['startat']) ? $_GET['startat'] : 0;
$aid = isset($_GET['aid']) ? $_GET['aid'] : null;
if (is_null($aid)) {
    // Called initially to get the active addressbooks.
    $active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
} else {
    // called each time more contacts has to be shown.
    $active_addressbooks = array(OC_Contacts_Addressbook::find($aid));
}
session_write_close();
// create the addressbook associate array
$contacts_addressbook = array();
$ids = array();
foreach ($active_addressbooks as $addressbook) {
    $ids[] = $addressbook['id'];
    if (!isset($contacts_addressbook[$addressbook['id']])) {
        $contacts_addressbook[$addressbook['id']] = array('contacts' => array('type' => 'book'));
        $contacts_addressbook[$addressbook['id']]['displayname'] = $addressbook['displayname'];
        $contacts_addressbook[$addressbook['id']]['permissions'] = $addressbook['permissions'];
        $contacts_addressbook[$addressbook['id']]['owner'] = $addressbook['userid'];
    }
}
$contacts_alphabet = array();