2021-05-28 15:49:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2021-05-28 16:01:42 +00:00
|
|
|
* plugins/abook_carddav/abook_class.php -- main class
|
2021-05-28 15:49:42 +00:00
|
|
|
*
|
2021-05-28 16:01:42 +00:00
|
|
|
* SquirrelMail Address Book CardDAV Backend
|
|
|
|
* Copyright (C) 2021 Aleksei Shpakovsky
|
|
|
|
* This program is licensed under GPLv3. See COPYING for details
|
|
|
|
* based on:
|
2021-05-28 15:49:42 +00:00
|
|
|
* SquirrelMail Address Book Backend template
|
|
|
|
* Copyright (C) 2004 Tomas Kuliavas <tokul@users.sourceforge.net>
|
|
|
|
* This program is licensed under GPL. See COPYING for details
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-05-28 16:01:42 +00:00
|
|
|
* address book carddav backend class
|
2021-05-28 15:49:42 +00:00
|
|
|
*/
|
2021-05-28 16:01:42 +00:00
|
|
|
class abook_carddav extends addressbook_backend {
|
2021-05-28 15:49:42 +00:00
|
|
|
var $btype = 'local';
|
2021-05-28 16:01:42 +00:00
|
|
|
var $bname = 'carddav';
|
2021-05-28 15:49:42 +00:00
|
|
|
|
|
|
|
var $writeable = true;
|
|
|
|
|
|
|
|
/* ========================== Private ======================= */
|
|
|
|
|
|
|
|
/* Constructor */
|
2021-05-28 16:01:42 +00:00
|
|
|
function abook_carddav($param) {
|
2021-05-28 15:49:42 +00:00
|
|
|
$this->sname = _("New address book");
|
|
|
|
|
|
|
|
if (is_array($param)) {
|
|
|
|
if (!empty($param['name'])) {
|
|
|
|
$this->sname = $param['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($param['writeable'])) {
|
|
|
|
$this->writeable = $param['writeable'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($param['listing'])) {
|
|
|
|
$this->listing = $param['listing'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->open(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $this->set_error('Invalid argument to constructor');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function open() {
|
|
|
|
// ADDME: backend open function
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function close() {
|
|
|
|
// ADDME: backend close function
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ========================== Public ======================== */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search address function
|
|
|
|
* @param expr string search expression
|
|
|
|
*/
|
|
|
|
function search($expr) {
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
// ADDME: search by nickname function
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup alias
|
|
|
|
* @param alias string
|
|
|
|
*/
|
|
|
|
function lookup($alias) {
|
|
|
|
if (empty($alias)) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$alias = strtolower($alias);
|
|
|
|
|
|
|
|
// ADDME: address lookup function
|
|
|
|
|
|
|
|
$ret = array('nickname' => "nickname",
|
|
|
|
'name' => "firstname lastname",
|
|
|
|
'firstname' => "firstname",
|
|
|
|
'lastname' => "lastname",
|
|
|
|
'email' => "email@address",
|
|
|
|
'label' => "info",
|
|
|
|
'backend' => $this->bnum,
|
|
|
|
'source' => $this->sname);
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List all addresses
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function list_addr() {
|
|
|
|
$ret = array();
|
|
|
|
|
|
|
|
// ADDME: list all addresses function
|
|
|
|
|
|
|
|
array_push($ret,array('nickname' => "nickname",
|
|
|
|
'name' => "firstname lastname",
|
|
|
|
'firstname' => "firstname",
|
|
|
|
'lastname' => "lastname",
|
|
|
|
'email' => "email@address",
|
|
|
|
'label' => "info",
|
|
|
|
'backend' => $this->bnum,
|
|
|
|
'source' => $this->sname));
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add address
|
|
|
|
* @param userdata
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function add($userdata) {
|
|
|
|
if (!$this->writeable) {
|
|
|
|
return $this->set_error(_("Addressbook is read-only"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if user exist already */
|
|
|
|
$ret = $this->lookup($userdata['nickname']);
|
|
|
|
if (!empty($ret)) {
|
|
|
|
return $this->set_error(sprintf(_("User '%s' already exist"),
|
|
|
|
$ret['nickname']));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ADDME: insert address function
|
|
|
|
|
|
|
|
// FIXME:
|
|
|
|
// return true if operation is succesful.
|
|
|
|
return true;
|
|
|
|
// Return error message if operation fails
|
|
|
|
return $this->set_error(_("Address add operation failed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete address
|
|
|
|
* @param alias
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function remove($alias) {
|
|
|
|
if (!$this->writeable) {
|
|
|
|
return $this->set_error(_("Addressbook is read-only"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ADD: delete address function
|
|
|
|
|
|
|
|
// FIXME:
|
|
|
|
// return true if operation is succesful.
|
|
|
|
return true;
|
|
|
|
// Return error message if operation fails
|
|
|
|
return $this->set_error(_("Address delete operation failed"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify address
|
|
|
|
* @param alias
|
|
|
|
* @param userdata
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function modify($alias, $userdata) {
|
|
|
|
if (!$this->writeable) {
|
|
|
|
return $this->set_error(_("Addressbook is read-only"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* See if user exist */
|
|
|
|
$ret = $this->lookup($alias);
|
|
|
|
if (empty($ret)) {
|
|
|
|
return $this->set_error(sprintf(_("User '%s' does not exist"),
|
|
|
|
$alias));
|
|
|
|
}
|
|
|
|
// ADD: modify address function
|
|
|
|
|
|
|
|
// FIXME:
|
|
|
|
// return true if operation is succesful.
|
|
|
|
return true;
|
|
|
|
// Return error message if operation fails
|
|
|
|
return $this->set_error(_("Address modify operation failed"));
|
|
|
|
}
|
2021-05-28 16:01:42 +00:00
|
|
|
} /* End of class abook_carddav */
|
|
|
|
?>
|