Skip to content
Snippets Groups Projects
Commit 7b0253cf authored by Michael Herold's avatar Michael Herold
Browse files

Adds complete jabber module

parent 65fea616
No related branches found
Tags v0.0.3
No related merge requests found
Showing
with 505 additions and 21 deletions
......@@ -44,4 +44,16 @@ class ModuleDb {
$this->pdo->commit();
}
public function availableDomains(array $services) {
if (count($services) > 1)
throw new exception\Error('Multiple services not implemented.');
$stmt = new sql\QuerySelectFunction(
$this->pdo, 'dns.sel_available_service'
);
$stmt->options('WHERE service = :service');
return $stmt->execute(['service' => $services[0]]);
}
}
......@@ -45,12 +45,18 @@ class FieldEmailWithSelect extends \hemio\form\Container {
return $this['p']['text'];
}
public function __construct() {
public function __construct($name1 = 'localpart', $name2 = 'domain', $title1 = null, $title2 = null) {
if ($title1 === null)
$title1 = _('Local Part');
if ($title2 === null)
$title2 = _('Domain');
$p = new html\P();
$p->addCssClass('multiple');
$this['p'] = $p;
$p['text'] = new form\FieldText('localpart', _('Local Part'));
$p['text'] = new form\FieldText($name1, $title1);
$p['text']->setRequired(true);
$p['text']->getControlElement()->setAttribute('autofocus', true);
$p['text']->addInheritableAppendage(
......@@ -63,7 +69,7 @@ class FieldEmailWithSelect extends \hemio\form\Container {
$p['select'] = new html\Span();
$p['select']->addCssClass('select');
$p['select']['select'] = new form\FieldSelect('domain', _('Domain'));
$p['select']['select'] = new form\FieldSelect($name2, $title2);
$p['select']['select']->addInheritableAppendage(
form\FormPost::FORM_FIELD_TEMPLATE . '_SELECT', new form\template\FormPlainControl
);
......
......@@ -42,6 +42,14 @@ class LinkButton extends form\Container {
$this['form']['button'] = new html\Button();
$this['form']['button']['text'] = new html\String($text);
}
/**
*
* @return html\Button
*/
public function getButton() {
return $this['form']['button'];
}
public function setSuggested($suggested = true) {
if ($suggested)
......
......@@ -49,9 +49,12 @@ class Message extends form\Container {
else
$backUrl = new \hemio\edentata\Request();
$button = new LinkButton($backUrl, _('OK'));
$button->getButton()->setAttribute('autofocus', true);
$button->setSuggested();
$this['article']
->addChild(new ButtonGroup())
->addChild(new LinkButton($backUrl, _('OK')));
->addChild($button);
}
}
......@@ -27,7 +27,7 @@ require_once 'vendor/autoload.php';
# external data
$request = new Request($_GET, $_POST);
$modulesNavi = ['email', 'email_list'];
$modulesNavi = ['email', 'email_list', 'jabber'];
$i10 = new I10n();
......
......@@ -33,9 +33,9 @@ class AddressCreate extends Window {
$selecting = new gui\Selecting(_('Delivery for new Address'));
$reqAccount = $this->module->request->derive('mailbox_create');
$strAccount = _('Create new mailbox for incoming emails');
$linkAccount = $selecting->addLink($reqAccount, $strAccount);
$reqMailbox = $this->module->request->derive('mailbox_create');
$strMailbox = _('Create new mailbox for incoming emails');
$linkMailbox = $selecting->addLink($reqMailbox, $strMailbox);
$reqAlias = $this->module->request->derive('alias_create');
$strAlias = _('Deliver emails to existing mailbox (alias)');
......@@ -47,8 +47,10 @@ class AddressCreate extends Window {
if ($this->db->mailboxSelect()->fetch()) {
$linkAlias->setSuggested();
$linkAlias->getButton()->setAttribute('autofocus', true);
} else {
$linkAccount->setSuggested();
$linkMailbox->setSuggested();
$linkMailbox->getButton()->setAttribute('autofocus', true);
$linkAlias->setDisabled();
}
......
......@@ -109,13 +109,4 @@ class Db extends \hemio\edentata\ModuleDb {
return $stmt->execute();
}
public function availableDomains() {
$stmt = new sql\QuerySelectFunction(
$this->pdo, 'dns.sel_available_service'
);
$stmt->options('WHERE service = :service');
return $stmt->execute(['service' => 'email__list']);
}
}
......@@ -48,7 +48,7 @@ class ListCreate extends Window {
$window->getForm()->addChild(new gui\Hint($hint));
foreach ($this->db->availableDomains() as $domain) {
foreach ($this->db->availableDomains(['email__list']) as $domain) {
$address->getDomain()->addOption($domain['domain']);
}
......
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\gui;
/**
* Description of AccountCreate
*
* @author Michael Herold <quabla@hemio.de>
*/
class AccountCreate extends Window {
public function content() {
$window = $this->newFormWindow(
'account_create'
, _('New Account')
, null
, _('Create')
);
$account = new gui\FieldEmailWithSelect('node', 'domain', _('Node'));
$password = new gui\FieldNewPassword('password');
$window->getForm()->addChild($account);
$window->getForm()->addChild($password);
$domains = $this->db->availableDomains(['jabber'])->fetchAll();
foreach ($domains as $domain) {
$account->getDomain()->addOption($domain['domain']);
}
$this->handleSubmit($window->getForm());
return $window;
}
protected function handleSubmit(gui\FormPost $form) {
if ($form->correctSubmitted()) {
$params = $form->getVal(['node', 'domain', 'password']);
$this->db->accountCreate($params);
throw new \hemio\edentata\exception\Successful;
}
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\gui;
/**
* Description of AccountDelete
*
* @author Michael Herold <quabla@hemio.de>
*/
class AccountDelete extends Window {
public function content($account) {
$message = _('Do you really want to delete this jabber account?');
$window = $this->newDeleteWindow(
'account_delete'
, _('Delete Account')
, $account
, $message
, _('Delete Account')
);
$this->handleSubmit($window->getForm(), $account);
return $window;
}
protected function handleSubmit(gui\FormPost $form, $account) {
if ($form->correctSubmitted()) {
$params = Db::accountToArgs($account);
$this->db->accountDelete($params);
throw new \hemio\edentata\exception\Successful;
}
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
/**
* Description of AccountDetails
*
* @author Michael Herold <quabla@hemio.de>
*/
class AccountDetails extends Window {
public function content($account) {
$window = $this->newWindow(_('Jabber Account'), $account);
$selecting = new \hemio\edentata\gui\Selecting(_('Possible Actions'));
$selecting->addLink(
$this->request->derive('password', $account)
, _('Change password')
);
$selecting->addLink($this->request->derive('delete', $account)
, _('Delete account')
);
$window->addChild($selecting);
return $window;
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\gui;
/**
* Description of AccountPassword
*
* @author Michael Herold <quabla@hemio.de>
*/
class AccountPassword extends Window {
public function content($account) {
$window = $this->newFormWindow(
'account_password'
, _('Account Password')
, $account
, _('Change')
);
$password = new gui\FieldNewPassword('password');
$window->getForm()->addChild($password);
$this->handleSubmit($window->getForm(), $account);
return $window;
}
protected function handleSubmit(gui\FormPost $form, $account) {
if ($form->correctSubmitted()) {
$params = Db::accountToArgs($account);
$params+= $form->getVal(['password']);
$this->db->accountPassword($params);
$e = new \hemio\edentata\exception\Successful(
_('Your password has been changed successfully.')
);
$e->backTo = $this->request->derive('details', $account);
throw $e;
}
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\sql;
/**
* Description of Db
*
* @author Michael Herold <quabla@hemio.de>
*/
class Db extends \hemio\edentata\ModuleDb {
public static function accountToArgs($address) {
return [
'p_node' => explode('@', $address)[0],
'p_domain' => explode('@', $address)[1]
];
}
public function accountDelete($params) {
(new sql\QuerySelectFunction(
$this->pdo
, 'jabber.del_account'
, $params
))->execute();
}
public function accountCreate($params) {
(new sql\QuerySelectFunction(
$this->pdo
, 'jabber.ins_account'
, $params
))->execute();
}
public function accountPassword($params) {
(new sql\QuerySelectFunction(
$this->pdo
, 'jabber.upd_account'
, $params
))->execute();
}
public function accountSelect() {
return
(new sql\QuerySelectFunction(
$this->pdo
, 'jabber.sel_account'
))->execute();
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\exception;
use hemio\edentata\exception\UnknownOperation;
use hemio\edentata;
/**
* Description of ModuleJabber
*
* @author Michael Herold <quabla@hemio.de>
*/
class ModuleJabber extends \hemio\edentata\Module {
/**
*
* @var Db
*/
public $db;
protected function constructHook() {
$this->db = new Db($this->pdo);
}
public function getContent() {
switch ($this->request->action) {
case '':
$content = (new Overview($this))->content();
break;
case 'create':
try {
$content = (new AccountCreate($this))->content();
} catch (exception\Successful $e) {
edentata\Utils::htmlRedirect($this->request->derive());
}
break;
case 'delete':
try {
$content = (new AccountDelete($this))->content($this->request->subject);
} catch (exception\Successful $e) {
edentata\Utils::htmlRedirect($this->request->derive());
}
break;
case 'details':
$content = (new AccountDetails($this))->content($this->request->subject);
break;
case 'password':
$content = (new AccountPassword($this))->content($this->request->subject);
break;
default:
throw UnknownOperation::unknownAction($this->request->action);
}
return $content;
}
public static function getDir() {
return __DIR__;
}
public static function getName() {
return _('Jabber');
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\jabber;
use hemio\edentata\gui;
use hemio\edentata\module\email;
/**
* Description of Overview
*
* @author Michael Herold <quabla@hemio.de>
*/
class Overview extends Window {
public function content() {
$window = $this->newWindow(_('Jabber Accounts'), null, false);
$window->addButtonRight(
new gui\LinkButton(
$this->request->derive('create')
, _('Create Account')
)
, true
);
$window->addChild($this->accounts());
return $window;
}
protected function accounts() {
$accounts = $this->db->accountSelect()->fetchAll();
if (empty($accounts)) {
return new gui\Hint(
_('You do not own any jabber accounts right now.')
);
} else {
$list = new gui\Listbox();
foreach ($accounts as $account) {
$addr = $account['node'] . '@' . $account['domain'];
$list->addLinkEntry(
$this->request->derive('details', $addr)
, new \hemio\html\String($addr)
, $account['backend_status']
);
}
return $list;
}
}
}
......@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace hemio\edentata\module\email_list;
namespace hemio\edentata\module\jabber;
/**
* Description of Window
......@@ -28,7 +28,7 @@ class Window extends \hemio\edentata\Window {
/**
*
* @var ModuleEmail_list
* @var ModuleJabber
*/
protected $module;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment