Benutzer hinzufuegen und loeschen realisiert.

This commit is contained in:
Christian Wolf 2019-04-16 15:16:24 +02:00
parent 604ac0e84f
commit 5f91d76147
5 changed files with 111 additions and 9 deletions

View File

@ -11,7 +11,96 @@ class ClubsControllerUser extends BaseController
{
function new()
{}
{
$app = Factory::getApplication();
$input = $app->input;
$u = ClubsUser::createUser();
// Fetch the posted data
$user = $input->post->getCmd('user');
$pwd = $input->post->getCmd('pwd');
$pwdConfirm = $input->post->getCmd('pwd-confirm');
$name = $input->post->getString('name');
$address = $input->post->getString('address');
$city = $input->post->getString('city');
$mail = $input->post->getString('mail');
$phone = $input->post->getString('phone');
$mobile = $input->post->getString('mobile');
// Check the input data
$error = false;
if(empty($user))
{
$app->enqueueMessage("Es muss ein Benutzername angegeben werden.", 'error');
$error = true;
}
else
{
if(! $this->checkUserName(trim($user)))
{
$app->enqueueMessage('Username ' . $user . ' ist nicht gültig.', 'error');
$error = true;
}
else
$u->setUser($user);
}
$pwderr = false;
if(isset($pwd))
{
if(trim($pwd) != trim($pwdConfirm))
{
$app->enqueueMessage('Die Passwörter stimmen nicht überein.', 'error');
$error = true;
$pwderr = true;
}
if(! $u->checkPassword(trim($pwd)))
{
$app->enqueueMessage('Das Passwort ist nicht zulässig.', 'error');
$error = true;
$pwderr = true;
}
if(! $pwderr)
$u->setPassword(trim($pwd));
}
// Check existence of the other fields
$fields = array('name'=>'Bürgerlicher Name', 'address'=>'Adresse', 'city'=>"Stadt", 'mail'=>'E-Mail');
foreach ($fields as $f => $fname)
{
$fvalue = $$f;
if(! isset($fvalue) || empty(trim($fvalue)))
{
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
$error = true;
}
}
$u->setName($name);
$u->setAddress($address);
$u->setCity($city);
$u->setMail($mail);
$u->setPhone($phone);
$u->setMobile($mobile);
if($error)
{
$data = array();
foreach(array('user', 'name', 'address', 'city', 'mail', 'phone', 'mobile') as $i)
$data[$i] = $$i;
$urldata = urlencode(json_encode($data));
$this->setRedirect(Route::_('index.php?option=com_clubs&view=user&id=new&data=' . $urldata, false));
return;
}
// Do the actual work
$u->save();
$this->setRedirect(Route::_('index.php?option=com_clubs&view=users', false));
}
function change()
{
@ -34,7 +123,7 @@ class ClubsControllerUser extends BaseController
// Check the input data
$error = false;
if(isset($user))
if(! empty($user))
{
if(! $this->checkUserName(trim($user), $id))
{
@ -70,7 +159,7 @@ class ClubsControllerUser extends BaseController
foreach ($fields as $f => $fname)
{
$fvalue = $$f;
if(! isset($fvalue) || strlen(trim($fvalue)) == 0)
if(! isset($fvalue) || empty(trim($fvalue)))
{
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
$error = true;
@ -100,6 +189,16 @@ class ClubsControllerUser extends BaseController
$this->setRedirect(Route::_('index.php?option=com_clubs&view=users', false));
}
function delete()
{
$app = Factory::getApplication();
$id = $app->input->get->getInt('id');
$app->enqueueMessage("Removal of user with id $id.");
$user = ClubsUser::loadUser($id);
$user->delete();
$this->setRedirect(Route::_('index.php?option=com_clubs&view=users', false));
}
private function checkUserName($username, $id = -1)
{
return ClubsUser::isUserNameFree($username, $id);

View File

@ -1,5 +1,7 @@
<?php
use Joomla\CMS\Router\Route;
// No direct access.
defined('_JEXEC') or die;
@ -53,5 +55,5 @@ defined('_JEXEC') or die;
<?php endif; ?>
</table>
<input type='submit' value='Speichern'>
<input type='submit' value='Speichern'> <br /><a href='<?php echo Route::_('index.php?option=com_clubs&view=users'); ?>'>Zur&uuml;ck zur &Uuml;bersicht</a>
</form>

View File

@ -18,7 +18,7 @@ class ClubsViewUser extends HtmlView
if($id === 'new')
{
$this->address = Route::_('index.php?option-com_clubs&task=user.new');
$this->address = Route::_('index.php?option=com_clubs&task=user.new');
$this->user = ClubsUser::createUser();
$this->isNew = true;
}
@ -47,7 +47,7 @@ class ClubsViewUser extends HtmlView
}
ToolbarHelper::title('Club-Management');
ToolbarHelper::title('Club-Management - Person');
parent::display($tpl);
}

View File

@ -10,23 +10,24 @@ defined('_JEXEC') or die;
<table width='100%' class='table table-stiped, table-hover'>
<thead>
<tr>
<th></th>
<th width='30%'>Benutzername</th>
<th width='30%'>Ort</th>
<th width='30%'>E-Mail</th>
<th width='5%'>L&ouml;schen?</th>
<th width='5%'>id</th>
</tr>
</thead>
<?php foreach($this->users as $user): ?>
<?php $link = Route::_('index.php?option=com_clubs&view=user&id=' . $user->getId()); ?>
<tr>
<td></td>
<td><a href='<?php echo $link; ?>'><?php echo htmlentities($user->getName()); ?></a></td>
<td><?php echo htmlentities($user->getCity()); ?></td>
<td><a href='mailto:<?php echo htmlentities($user->getMail()); ?>'><?php echo htmlentities($user->getMail()); ?></a></td>
<td><a href='<?php echo Route::_('index.php?option=com_clubs&task=user.delete&id=' . $user->getId()); ?>'>Del</a></td>
<td><?php echo htmlentities($user->getId()); ?></td>
</tr>
<?php endforeach; ?>
</table>
<div><a href='<?php echo Route::_('index.php?option=com_clubs&view=user&id=new'); ?>'>Neuen Benutzer anlegen</a></div>

View File

@ -14,7 +14,7 @@ class ClubsViewUsers extends HtmlView
{
$this->users = ClubsUser::loadUsers();
ToolbarHelper::title('Club-Management');
ToolbarHelper::title('Club-Management - Personen', 'user');
parent::display($tpl);
}