Permalink
Browse files

initial commit

  • Loading branch information...
Christian Putzke
Christian Putzke committed Sep 12, 2011
0 parents commit a8a725bcc3ee47e00004e4ea8a78165f14c67244
Showing with 1,073 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 CHANGELOG
  3. +339 −0 LICENSE
  4. +26 −0 README
  5. +24 −0 SQL/mysql.sql
  6. +234 −0 carddav.php
  7. +367 −0 carddav_backend.php
  8. +42 −0 carddav_settings.js
  9. +7 −0 config.inc.php.dist
  10. +14 −0 localization/de_DE.inc
  11. +14 −0 localization/en_US.inc
@@ -0,0 +1 @@
+config.inc.php
@@ -0,0 +1,5 @@
+release 0.1
+- save / delete cardDAV-Server settings
+- realtime cardDAV-Server check
+- multiple cardDAV-Server for each user
+- English and German translations
339 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
26 README
@@ -0,0 +1,26 @@
+Description
+-----------
+This is a cardDAV implementation for roundcube 0.6 or higher
+
+
+Features
+--------
+* add multiple cardDAV-Server for each user
+* cardDAV contacts will be synchronized automaticly (not implemented yet)
+* 2-way synchronization (no implemented yet)
+* cardDAV-Contacts are stored in the local database which provides great performance
+
+
+Installation
+------------
+* execute SQL-Statements from /plugins/carddav/SQL/
+* add 'carddav' to the plugins-array in /config/main.inc.php
+* copy /plugins/carddav/config.inc.php.dist to /plugins/carddav/config.inc.php
+* login into your roundcube webmail and add your cardDAV-Server in the settings
+
+
+Contact
+-------
+* Author: Christian Putzke <cputzke@graviox.de>
+* Report feature requests and bugs here: https://github.com/graviox/Roundcube-cardDAV/issues
+* Visit Graviox Studios: http://www.graviox.de/
@@ -0,0 +1,24 @@
+CREATE TABLE IF NOT EXISTS `carddav_server` (
+ `carddav_server_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `user_id` int(10) unsigned NOT NULL,
+ `url` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `username` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
+ `password` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
+ `label` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`carddav_server_id`),
+ KEY `user_id` (`user_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
+
+ALTER TABLE `carddav_server` ADD CONSTRAINT `carddav_server_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE;
+
+CREATE TABLE IF NOT EXISTS `carddav_contacts` (
+ `carddav_contact_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `carddav_server_id` int(10) unsigned NOT NULL,
+ `etag` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
+ `vcard` text COLLATE utf8_unicode_ci NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `email` text COLLATE utf8_unicode_ci,
+ PRIMARY KEY (`carddav_contact_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
+
+ALTER TABLE `carddav_contacts` ADD CONSTRAINT `carddav_contacts_ibfk_1` FOREIGN KEY (`carddav_server_id`) REFERENCES `carddav_server` (`carddav_server_id`) ON DELETE CASCADE;
@@ -0,0 +1,234 @@
+<?php
+
+/**
+ * include required carddav classes
+ */
+require_once dirname(__FILE__).'/carddav_backend.php';
+
+
+/**
+ * Roundcube cardDAV implementation
+ *
+ * This is a cardDAV implementation for roundcube 0.6 or higher. It allows every user to add
+ * multiple cardDAV server in their settings. The cardDAV contacts will be synchronized
+ * automaticly with their addressbook.
+ *
+ *
+ * @author Christian Putzke <cputzke@graviox.de>
+ * @copyright Graviox Studios
+ * @since 06.09.2011
+ * @version 0.1
+ * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
+ *
+ */
+class carddav extends rcube_plugin
+{
+ public $task = 'settings|addressbook';
+
+ public function init()
+ {
+ $rcmail = rcmail::get_instance();
+ $this->add_texts('localization/', true);
+
+ switch ($rcmail->task)
+ {
+ case 'settings':
+ $this->register_action('plugin.carddav-server', array($this, 'carddav_server'));
+ $this->register_action('plugin.carddav-server-check', array($this, 'carddav_server_check'));
+ $this->register_action('plugin.carddav-server-save', array($this, 'carddav_server_save'));
+ $this->register_action('plugin.carddav-server-delete', array($this, 'carddav_server_delete'));
+ $this->include_script('carddav_settings.js');
+ break;
+ }
+ }
+
+ protected function get_carddav_server()
+ {
+ $servers = array();
+ $rcmail = rcmail::get_instance();
+ $user_id = $rcmail->user->data['user_id'];
+
+ $query = "
+ SELECT
+ *
+ FROM
+ ".get_table_name('carddav_server')."
+ WHERE
+ user_id = ?
+ ";
+
+ $result = $rcmail->db->query($query, $user_id);
+
+ while($server = $rcmail->db->fetch_assoc($result))
+ {
+ $servers[] = $server;
+ }
+
+ return $servers;
+ }
+
+ public function carddav_server()
+ {
+ $this->register_handler('plugin.body', array($this, 'carddav_server_form'));
+
+ $rcmail = rcmail::get_instance();
+ $rcmail->output->set_pagetitle($this->gettext('settings'));
+ $rcmail->output->send('plugin');
+ }
+
+ public function carddav_server_check()
+ {
+ $rcmail = rcmail::get_instance();
+ $url = get_input_value('_server_url', RCUBE_INPUT_POST);
+ $username = get_input_value('_username', RCUBE_INPUT_POST);
+ $password = get_input_value('_password', RCUBE_INPUT_POST);
+
+ $carddav_backend = new carddav_backend($url);
+ $carddav_backend->set_auth($username, $password);
+
+ if ($carddav_backend->check_connection() === true)
+ {
+ $rcmail->output->command('plugin.carddav_server_check', array('check' => 'true'));
+ }
+ else
+ {
+ $rcmail->output->command('plugin.carddav_server_check', array('check' => 'false'));
+ }
+ }
+
+ public function carddav_server_form()
+ {
+ $rcmail = rcmail::get_instance();
+ $servers = $this->get_carddav_server();
+
+ $table = new html_table(array('cols' => 5));
+ $table->add('title', $this->gettext('settings_label'));
+ $table->add('title', $this->gettext('server'));
+ $table->add('title', $this->gettext('username'));
+ $table->add('title', $this->gettext('password'));
+ $table->add(null, null);
+
+ if (!empty($servers))
+ {
+ foreach ($servers as $server)
+ {
+ $table->add(null, $server['label']);
+ $table->add(null, $server['url']);
+ $table->add(null, $server['username']);
+ $table->add(null, '**********');
+ $table->add(null, html::a(array('href' => './?_task=settings&_action=plugin.carddav-server-delete&id='.$server['carddav_server_id']), 'delete'));
+ }
+ }
+
+ $input_label = new html_inputfield(array(
+ 'name' => '_label',
+ 'id' => '_label',
+ 'size' => '20'
+ ));
+
+ $input_server_url = new html_inputfield(array(
+ 'name' => '_server_url',
+ 'id' => '_server_url',
+ 'size' => '50'
+ ));
+
+ $input_username = new html_inputfield(array(
+ 'name' => '_username',
+ 'id' => '_username',
+ 'size' => '20'
+ ));
+
+ $input_password = new html_passwordfield(array(
+ 'name' => '_password',
+ 'id' => '_password',
+ 'size' => '20'
+ ));
+
+ $input_submit = $rcmail->output->button(array(
+ 'command' => 'plugin.carddav-server-save',
+ 'type' => 'input',
+ 'class' => 'button mainaction',
+ 'label' => 'save'
+ ));
+
+ $table->add(null, $input_label->show());
+ $table->add(null, $input_server_url->show());
+ $table->add(null, $input_username->show());
+ $table->add(null, $input_password->show());
+ $table->add(null, $input_submit);
+
+ $rcmail->output->add_gui_object('carddavserverform', 'carddav-server-form');
+
+ $out = html::div(
+ array('class' => 'box'),
+ html::div(array('class' => 'boxtitle'), $this->gettext('settings')).
+ html::div(array('class' => 'boxcontent'), $table->show())
+ );
+
+ return $rcmail->output->form_tag(array(
+ 'id' => 'carddav-server-form',
+ 'name' => 'carddav-server-form',
+ 'method' => 'post',
+ 'action' => './?_task=settings&_action=plugin.carddav-server-save',
+ ), $out);
+ }
+
+ public function carddav_server_save()
+ {
+ $rcmail = rcmail::get_instance();
+ $user_id = $rcmail->user->data['user_id'];
+ $url = get_input_value('_server_url', RCUBE_INPUT_POST);
+ $username = get_input_value('_username', RCUBE_INPUT_POST);
+ $password = get_input_value('_password', RCUBE_INPUT_POST);
+ $label = get_input_value('_label', RCUBE_INPUT_POST);
+
+ $query = "
+ INSERT INTO
+ ".get_table_name('carddav_server')." (user_id, url, username, password, label)
+ VALUES
+ (?, ?, ?, ?, ?)
+ ";
+
+ $rcmail->db->query($query, $user_id, $url, $username, $rcmail->encrypt($password), $label);
+
+ if ($rcmail->db->affected_rows())
+ {
+ $rcmail->output->show_message($this->gettext('settings_saved'), 'confirmation');
+ }
+ else
+ {
+ $rcmail->output->show_message($this->gettext('settings_save_failed'), 'error');
+ }
+
+ return $this->carddav_server();
+ }
+
+ public function carddav_server_delete()
+ {
+ $rcmail = rcmail::get_instance();
+ $user_id = $rcmail->user->data['user_id'];
+ $carddav_server_id = $_GET['id'];
+
+ $query = "
+ DELETE FROM
+ ".get_table_name('carddav_server')."
+ WHERE
+ user_id = ?
+ AND
+ carddav_server_id = ?
+ ";
+
+ $rcmail->db->query($query, $user_id, $carddav_server_id);
+
+ if ($rcmail->db->affected_rows())
+ {
+ $rcmail->output->show_message($this->gettext('settings_deleted'), 'confirmation');
+ }
+ else
+ {
+ $rcmail->output->show_message($this->gettext('settings_delete_failed'), 'error');
+ }
+
+ return $this->carddav_server();
+ }
+}
Oops, something went wrong.

0 comments on commit a8a725b

Please sign in to comment.