*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); require_once(DOKU_PLUGIN.'admin.php'); class admin_plugin_webdavclient extends DokuWiki_Admin_Plugin { protected $hlp = null; protected $error = false; protected $errmsg = ''; protected $action = null; protected $result = null; /** * Constructor. Load helper plugin */ function admin_plugin_webdavclient(){ $this->hlp =& plugin_load('helper', 'webdavclient'); if(is_null($this->hlp)) msg('Error loading WebDAV Client helper module!'); } function getMenuSort() { return 501; } function handle() { global $INPUT; if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do if (!checkSecurityToken()) return; if (!is_array($_REQUEST['cmd'])) return; $fn = $_REQUEST['cmd']; if (is_array($fn)) { $cmd = key($fn); $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; } else { $cmd = $fn; $param = null; } $this->action = $cmd; // Parse the command and react accordingly switch($cmd) { case 'forcesync': $connid = $param; if($this->hlp->syncConnection($connid, true, true) === false) { $this->error = true; $this->errmsg = $this->hlp->getLastError(); } break; case 'forceresync': $connid = $param; if($this->hlp->syncConnection($connid, true, true, true) === false) { $this->error = true; $this->errmsg = $this->hlp->getLastError(); } break; case 'delete': $connid = $param; $this->hlp->deleteConnection($connid); break; case 'modify': $connid = $param; $dn = $_REQUEST['moddn'][$connid]; $permission = $_REQUEST['modperm'][$connid]; $syncinterval = $_REQUEST['modsyncinterval'][$connid]; $write = $_REQUEST['modwrite'][$connid]; $active = $_REQUEST['modactive'][$connid]; $this->hlp->modifyConnection($connid, $permission, $dn, $syncinterval, $write, $active); break; case 'add': // FIXME: Should we sanity-check the settings and query the server for correctness first? $uri = $_REQUEST['manuri']; $dn = $_REQUEST['mandn']; $username = $_REQUEST['manusername']; $password = $_REQUEST['manpassword']; $type = $_REQUEST['mantype']; $this->hlp->addConnection($uri, $username, $password, $dn, $dn, $type, '3600', false, false); break; case 'addselected': $calendars = $_REQUEST['cb']['calendar']; $addressbooks = $_REQUEST['cb']['addressbook']; if(count($calendars) == 0 && count($addressbooks) == 0) { $this->error = true; $this->errmsg = $this->getLang('nothing_selected'); return; } foreach($calendars as $cal) { $idx = intval($cal); $this->hlp->addConnection($_REQUEST['calendar'][$idx], $_REQUEST['addusername'], $_REQUEST['addpassword'], $_REQUEST['calendardn'][$idx], $_REQUEST['calendardn'][$idx], 'calendar', '3600', false, false); } foreach($addressbooks as $addr) { $idx = intval($addr); $this->hlp->addConnection($_REQUEST['addressbook'][$idx], $_REQUEST['addusername'], $_REQUEST['addpassword'], $_REQUEST['addressbookdn'][$idx], $_REQUEST['addressbookdn'][$idx], 'contacts', '3600', false, false); } break; case 'empty': $this->result['connid'] = $param; break; case 'reallyempty': $connid = $param; $this->hlp->deleteAllEntries($connid); break; case 'discover': $username = $INPUT->str('username', ''); $password = $INPUT->str('password', ''); $uri = $INPUT->str('uri', ''); if(($username === '') || ($password === '') || ($uri === '')) { $this->error = true; $this->errmsg = $this->getLang('empty_input'); return; } $this->result = $this->hlp->queryServer($uri, $username, $password); $this->result['username'] = $username; $this->result['password'] = $password; $this->result['uri'] = $uri; break; default: break; } } function html() { ptln('

WebDAV Client

'); ptln('

'.$this->getLang('existing_connections').'

'); ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); formSecurityToken(); if($this->error === true) { ptln($this->errmsg); } else { switch($this->action) { case 'empty': ptln($this->getLang('reallyempty')); ptln(''); break; case 'discover': if(count($this->result['calendars']) == 0 && count($this->result['addressbooks']) == 0) { ptln($this->getLang('nothing_found')); break; } ptln('

'.$this->getLang('calendars_found').'

'); ptln(''); ptln(''); $idx = 0; foreach($this->result['calendars'] as $href => $dn) { ptln(''); $idx++; } ptln('
'.$this->getLang('select').''. $this->getLang('name').''.$this->getLang('uri').'
'. ''. ''. hsc($dn).''.hsc($href).'
'); ptln('

'.$this->getLang('addressbooks_found').'

'); ptln(''); ptln(''); $idx = 0; foreach($this->result['addressbooks'] as $href => $dn) { ptln(''); $idx++; } ptln('
'.$this->getLang('select').''. $this->getLang('name').''.$this->getLang('uri').'
'. ''. ''. hsc($dn).''.hsc($href).'
'); ptln(''); ptln(''); ptln(''); } } ptln(''); $connections = $this->hlp->getConnections(); ptln(''); ptln(''); ptln(''); foreach($connections as $conn) { ptln(''); ptln(' '); ptln(''); } ptln('
'.$this->getLang('id').''.$this->getLang('name').''. $this->getLang('syncinterval').''.$this->getLang('active'). ''.$this->getLang('write').''.$this->getLang('permission').''.$this->getLang('action').'
'.hsc($conn['id']). ''. ''. ''. ''. ''. '
'); ptln('
'); ptln('

'.$this->getLang('add_connection').'

'); ptln($this->getLang('discovery_text')); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln('
'.$this->getLang('uri').'
'.$this->getLang('username').'
'.$this->getLang('password').'
'. '
'); ptln('
'); ptln('
'); ptln('

'.$this->getLang('add_connection_manual').'

'); ptln($this->getLang('add_text')); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln(''); ptln('
'.$this->getLang('uri').'
'.$this->getLang('name').'
'.$this->getLang('type').'
'.$this->getLang('username').'
'.$this->getLang('password').'
'. '
'); ptln('
'); ptln('
'); } } // vim:ts=4:sw=4:et:enc=utf-8: