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() 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() function change()
{ {
@ -34,7 +123,7 @@ class ClubsControllerUser extends BaseController
// Check the input data // Check the input data
$error = false; $error = false;
if(isset($user)) if(! empty($user))
{ {
if(! $this->checkUserName(trim($user), $id)) if(! $this->checkUserName(trim($user), $id))
{ {
@ -70,7 +159,7 @@ class ClubsControllerUser extends BaseController
foreach ($fields as $f => $fname) foreach ($fields as $f => $fname)
{ {
$fvalue = $$f; $fvalue = $$f;
if(! isset($fvalue) || strlen(trim($fvalue)) == 0) if(! isset($fvalue) || empty(trim($fvalue)))
{ {
$app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error'); $app->enqueueMessage("Das Feld $fname ist obligatorisch.", 'error');
$error = true; $error = true;
@ -100,6 +189,16 @@ class ClubsControllerUser extends BaseController
$this->setRedirect(Route::_('index.php?option=com_clubs&view=users', false)); $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) private function checkUserName($username, $id = -1)
{ {
return ClubsUser::isUserNameFree($username, $id); return ClubsUser::isUserNameFree($username, $id);

View File

@ -1,5 +1,7 @@
<?php <?php
use Joomla\CMS\Router\Route;
// No direct access. // No direct access.
defined('_JEXEC') or die; defined('_JEXEC') or die;
@ -53,5 +55,5 @@ defined('_JEXEC') or die;
<?php endif; ?> <?php endif; ?>
</table> </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> </form>

View File

@ -18,7 +18,7 @@ class ClubsViewUser extends HtmlView
if($id === 'new') 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->user = ClubsUser::createUser();
$this->isNew = true; $this->isNew = true;
} }
@ -47,7 +47,7 @@ class ClubsViewUser extends HtmlView
} }
ToolbarHelper::title('Club-Management'); ToolbarHelper::title('Club-Management - Person');
parent::display($tpl); parent::display($tpl);
} }

View File

@ -10,23 +10,24 @@ defined('_JEXEC') or die;
<table width='100%' class='table table-stiped, table-hover'> <table width='100%' class='table table-stiped, table-hover'>
<thead> <thead>
<tr> <tr>
<th></th>
<th width='30%'>Benutzername</th> <th width='30%'>Benutzername</th>
<th width='30%'>Ort</th> <th width='30%'>Ort</th>
<th width='30%'>E-Mail</th> <th width='30%'>E-Mail</th>
<th width='5%'>L&ouml;schen?</th>
<th width='5%'>id</th> <th width='5%'>id</th>
</tr> </tr>
</thead> </thead>
<?php foreach($this->users as $user): ?> <?php foreach($this->users as $user): ?>
<?php $link = Route::_('index.php?option=com_clubs&view=user&id=' . $user->getId()); ?> <?php $link = Route::_('index.php?option=com_clubs&view=user&id=' . $user->getId()); ?>
<tr> <tr>
<td></td>
<td><a href='<?php echo $link; ?>'><?php echo htmlentities($user->getName()); ?></a></td> <td><a href='<?php echo $link; ?>'><?php echo htmlentities($user->getName()); ?></a></td>
<td><?php echo htmlentities($user->getCity()); ?></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='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> <td><?php echo htmlentities($user->getId()); ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </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(); $this->users = ClubsUser::loadUsers();
ToolbarHelper::title('Club-Management'); ToolbarHelper::title('Club-Management - Personen', 'user');
parent::display($tpl); parent::display($tpl);
} }