Updated users model and controllers

This commit is contained in:
Cliff Ingham 2014-08-18 16:26:14 -04:00
parent c278305473
commit d52a8c277f
21 changed files with 191 additions and 426 deletions

View File

@ -1,54 +0,0 @@
<?php
/**
* @copyright 2006-2012 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
?>
<h2>New User Account</h2>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<fieldset><legend>Login Info</legend>
<table>
<tr><td><label for="user-authenticationMethod">Authentication</label></td>
<td><select name="user[authenticationMethod]" id="user-authenticationMethod">
<?php
foreach (User::getAuthenticationMethods() as $method) {
$selected = (isset($_POST['user']['authenticationMethod']) && $_POST['user']['authenticationMethod']==$method)
? 'selected="selected"'
: '';
echo "<option $selected>$method</option>";
}
?>
</select>
</td>
</tr>
<tr><td><label for="user-username">Username</label></td>
<td><input name="user[username]" id="user-username" value="<?php if(isset($_POST['user']['username'])) echo View::escape($_POST['user']['username']); ?>" />
</td>
</tr>
<tr><td><label for="user-password">Password</label></td>
<td><input name="user[password]" id="user-password" /></td>
</tr>
<tr><td><label for="user[roles]">Roles</label></td>
<td><select name="user[roles][]" id="user-roles" size="5" multiple="multiple">
<?php
$roles = new RoleList();
$roles->find();
foreach ($roles as $role) {
$selected = (isset($_POST['user']['roles']) && in_array($role,$_POST['user']['roles']))
? 'selected="selected"'
: '';
echo "<option $selected>$role</option>";
}
?>
</select>
</td>
</tr>
</table>
<button type="submit" class="submit">Submit</button>
<button type="button" class="cancel" onclick="document.location.href='<?php echo BASE_URL; ?>/users';">
Cancel
</button>
</fieldset>
</form>

View File

@ -0,0 +1,63 @@
<?php
/**
* @copyright 2007-2014 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param Zend\Db\Sql\Select $users
*/
use Application\Models\Person;
use Blossom\Classes\View;
?>
<div class="interfaceBox">
<h2><?php
echo $this->_(['user','users',2]);
$helper = $this->template->getHelper('buttonLink');
if (Person::isAllowed('users')) {
echo $helper->buttonLink(BASE_URI.'/users/update', $this->_('create_account'), 'add');
}
?>
</h2>
<table>
<thead>
<tr><th></th>
<th><?php echo $this->_('username'); ?></th>
<th><?php echo $this->_('name'); ?></th>
<th><?php echo $this->_('authenticationMethod'); ?></th>
<th><?php echo $this->_('role'); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($this->users as $user) {
$editButton = '';
$deleteButton = '';
if (Person::isAllowed('users')) {
$editButton = $helper->buttonLink(
BASE_URI.'/users/update?user_id='.$user->getId(),
$this->_('edit_account'),
'edit'
);
$deleteButton = $helper->buttonLink(
BASE_URI.'/users/delete?user_id='.$user->getId(),
$this->_('delete_account'),
'delete'
);
}
$name = View::escape($user->getFullname());
echo "
<tr><td>$editButton</td>
<td>{$user->getUsername()}</td>
<td>$name</td>
<td>{$user->getAuthenticationMethod()}</td>
<td>{$user->getRole()}</td>
<td>$deleteButton</td>
</tr>
";
}
?>
</tbody>
</table>
</div>

View File

@ -0,0 +1,58 @@
<?php
/**
* @copyright 2006-2013 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param User $this->user
*/
use Application\Models\Person;
use Blossom\Classes\View;
?>
<div class="updateUserForm">
<form method="post" action="<?php echo BASE_URI; ?>/users/update">
<fieldset><legend><?php echo $this->_(['user','users',2]); ?></legend>
<input name="user_id" type="hidden" value="<?php echo $this->user->getId(); ?>" />
<table>
<tr><td><label for="authenticationMethod"><?php echo $this->_('authenticationMethod'); ?></label></td>
<td><select name="authenticationMethod" id="authenticationMethod">
<?php
foreach (Person::getAuthenticationMethods() as $method) {
$selected = $this->user->getAuthenticationMethod()==$method
? 'selected="selected"'
: '';
echo "<option $selected>$method</option>";
}
?>
</select>
</td>
</tr>
<tr><td><label for="username"><?php echo $this->_('username'); ?></label></td>
<td><input name="username" id="username" value="<?php echo View::escape($this->user->getUsername()); ?>" />
</td>
</tr>
<tr><td><label for="password"><?php echo $this->_('password'); ?></label></td>
<td><input name="password" id="password" /></td>
</tr>
<tr><td><label for="role"><?php echo $this->_('role'); ?></label></td>
<td><select name="role" id="role"><option></option>
<?php
global $ZEND_ACL;
foreach (array_reverse($ZEND_ACL->getRoles()) as $role) {
$selected = $this->user->getRole()==$role
? 'selected="selected"'
: '';
echo "<option $selected>$role</option>";
}
?>
</select>
</td>
</tr>
</table>
<?php
$helper = $this->template->getHelper('saveAndCancelButtons');
echo $helper->saveAndCancelButtons(BASE_URI.'/users');
?>
</fieldset>
</form>
</div>

View File

@ -1,55 +0,0 @@
<?php
/**
* @copyright 2006-2012 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param User $this->user
*/
?>
<h2>Edit <?php echo $this->user->getUsername(); ?></h2>
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
<fieldset><legend>Login Info</legend>
<input name="user_id" type="hidden" value="<?php echo $this->user->getId(); ?>" />
<table>
<tr><td><label for="user-authenticationMethod">Authentication</label></td>
<td><select name="user[authenticationMethod]" id="user-authenticationMethod">
<?php
foreach (User::getAuthenticationMethods() as $method) {
$selected = $this->user->getAuthenticationMethod()==$method
? 'selected="selected"'
: '';
echo "<option $selected>$method</option>";
}
?>
</select>
</td>
</tr>
<tr><td><label for="user-username">Username</label></td>
<td><input name="user[username]" id="user-username" value="<?php echo View::escape($this->user->getUsername()); ?>" />
</td>
</tr>
<tr><td><label for="user-password">Password</label></td>
<td><input name="user[password]" id="user-password" /></td>
</tr>
<tr><td><label for="user-roles">Roles</label></td>
<td><select name="user[roles][]" id="user-roles" size="5" multiple="multiple">
<?php
$roles = new RoleList();
$roles->find();
foreach ($roles as $role) {
$selected = in_array($role,$this->user->getRoles())
? 'selected="selected"'
: '';
echo "<option $selected>$role</option>";
}
?>
</select>
</td>
</tr>
</table>
<button type="submit" class="submit">Submit</button>
<button type="button" class="cancel" onclick="document.location.href='<?php echo BASE_URL; ?>/users';">
Cancel
</button>
</fieldset>
</form>

View File

@ -1,57 +0,0 @@
<?php
/**
* @copyright 2007-2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param UserList $this->userList
*/
?>
<div class="interfaceBox">
<h2><?php
if (userIsAllowed('Users')) {
echo "
<button type=\"button\" class=\"add\" onclick=\"document.location.href='".BASE_URL."/users/addUser.php';\">
Add User Account
</button>
";
}
?>
User Accounts
</h2>
<table>
<?php
foreach ($this->userList as $user) {
$editButton = '';
$deleteButton = '';
if (userIsAllowed('Users')) {
$editButton = "
<button type=\"button\" class=\"edit\" onclick=\"document.location.href='".BASE_URL."/users/updateUser.php?user_id={$user->getId()}';\">
Edit User Account
</button>
";
$deleteButton = "
<button type=\"button\" class=\"delete\" onclick=\"document.location.href='".BASE_URL."/users/deleteUser.php?user_id={$user->getId()}';\">
Delete User Account
</button>
";
}
echo "
<tr><td>$editButton</td>
<td>{$user->getUsername()}</td>
<td>{$user->getFirstname()} {$user->getLastname()}</td>
<td>{$user->getAuthenticationMethod()}</td>
<td>
";
foreach ($user->getRoles() as $role) {
echo "$role ";
}
echo "
</td>
</tr>
";
}
?>
</table>
</div>

View File

@ -1,33 +0,0 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
if (isset($_POST['person'])) {
$person = new Person();
foreach ($_POST['person'] as $field=>$value) {
$set = 'set'.ucfirst($field);
$person->$set($value);
}
try {
$person->save();
header('Location: '.BASE_URL.'/people');
exit();
}
catch(Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$template = new Template();
$template->title = 'Add a person';
$template->blocks[] = new Block('people/addPersonForm.inc');
echo $template->render();

View File

@ -1,19 +0,0 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
$personList = new PersonList();
$personList->find();
$template = new Template();
$template->title = 'People';
$template->blocks[] = new Block('people/personList.inc',array('personList'=>$personList));
echo $template->render();

View File

@ -1,35 +0,0 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param Request person_id
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
$person = new Person($_REQUEST['person_id']);
if (isset($_POST['person'])) {
foreach ($_POST['person'] as $field=>$value) {
$set = 'set'.ucfirst($field);
$person->$set($value);
}
try {
$person->save();
header('Location: '.BASE_URL.'/people');
exit();
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$template = new Template();
$template->title = 'Update a person';
$template->blocks[] = new Block('people/updatePersonForm.inc',array('person'=>$person));
echo $template->render();

View File

@ -1,13 +0,0 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param GET person_id
*/
$person = new Person($_GET['person_id']);
$template = new Template();
$template->title = $person->getFullname();
$template->blocks[] = new Block('people/personInfo.inc',array('person'=>$person));
echo $template->render();

View File

@ -1,74 +0,0 @@
<?php
/**
* @copyright 2006-2012 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param GET person_id
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
if (isset($_REQUEST['person_id'])) {
try {
$person = new Person($_REQUEST['person_id']);
}
catch (Exception $e) {
}
}
if (isset($_POST['user'])) {
$user = new User();
foreach ($_POST['user'] as $field=>$value) {
$set = 'set'.ucfirst($field);
$user->$set($value);
}
if (isset($person)) {
$user->setPerson_id($person->getId());
}
else {
// Load their information from LDAP
if ($user->getAuthenticationMethod() != 'local') {
try {
$externalIdentity = $user->getAuthenticationMethod();
$identity = new $externalIdentity($user->getUsername());
try {
$person = new Person($identity->getEmail());
}
catch (Exception $e) {
$person = new Person();
$person->setFirstname($identity->getFirstname());
$person->setLastname($identity->getLastname());
$person->setEmail($identity->getEmail());
$person->save();
}
$user->setPerson($person);
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
}
try {
$user->save();
header('Location: '.BASE_URL.'/users');
exit();
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$template = new Template();
$template->title = 'Create a user account';
$template->blocks[] = new Block('users/addUserForm.inc');
if (isset($person)) {
$template->blocks[] = new Block('people/personInfo.inc',array('person'=>$person));
}
echo $template->render();

View File

@ -1,17 +0,0 @@
<?php
/**
* @copyright 2006-2008 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param GET user_id
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
$user = new User($_GET['user_id']);
$user->delete();
header('Location: '.BASE_URL.'/users');

View File

@ -1,20 +0,0 @@
<?php
/**
* @copyright 2006-2008 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
$template = new Template();
$template->title = 'User accounts';
$userList = new UserList();
$userList->find();
$template->blocks[] = new Block('users/userList.inc',array('userList'=>$userList));
echo $template->render();

View File

@ -1,35 +0,0 @@
<?php
/**
* @copyright 2009 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
* @param REQUEST user_id
*/
if (!userIsAllowed('Users')) {
$_SESSION['errorMessages'][] = new Exception('noAccessAllowed');
header('Location: '.BASE_URL);
exit();
}
$user = new User($_REQUEST['user_id']);
if (isset($_POST['user'])) {
foreach ($_POST['user'] as $field=>$value) {
$set = 'set'.ucfirst($field);
$user->$set($value);
}
try {
$user->save();
header('Location: '.BASE_URL.'/users');
exit();
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$template = new Template();
$template->blocks[] = new Block('users/updateUserForm.inc',array('user'=>$user));
$template->blocks[] = new BlocK('people/personInfo.inc',array('person'=>$user->getPerson()));
echo $template->render();

Binary file not shown.

View File

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: uReport 1.9\n"
"Report-Msgid-Bugs-To: dev@bloomington.in.gov\n"
"POT-Creation-Date: 2013-09-20 16:33-0400\n"
"PO-Revision-Date: 2014-08-11 13:43-0500\n"
"PO-Revision-Date: 2014-08-18 16:18-0500\n"
"Last-Translator: Cliff Ingham <inghamn@bloomington.in.gov>\n"
"Language-Team: City of Bloomington <dev@bloomington.in.gov>\n"
"MIME-Version: 1.0\n"

View File

@ -0,0 +1,27 @@
<?php
/**
* Provides markup for button links
*
* @copyright 2014 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
namespace Application\Templates\Helpers;
use Blossom\Classes\Template;
class ButtonLink
{
private $template;
public function __construct(Template $template)
{
$this->template = $template;
}
public function buttonLink($url, $label, $type)
{
$a = '<a href="%s" class="%s button">%s</a>';
return sprintf($a, $url, $type, $label);
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* @copyright 2013-2014 City of Bloomington, Indiana
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
* @author Cliff Ingham <inghamn@bloomington.in.gov>
*/
namespace Application\Templates\Helpers;
use Blossom\Classes\Template;
class SaveAndCancelButtons
{
private $template;
public function __construct(Template $template)
{
$this->template = $template;
}
public function saveAndCancelButtons($cancelURL)
{
return "
<button type=\"submit\" class=\"save\">{$this->template->_('labels.save')}</button>
<a href=\"$cancelURL\" class=\"cancel\">{$this->template->_('labels.cancel')}</a>
";
}
}

View File

@ -7,14 +7,14 @@ use Blossom\Classes\View;
$li = '<li><a href="%s">%s</a></li>';
if (isset($_SESSION['USER'])) {
echo sprintf($li, BASE_URI.'/login/logout', $this->translate('labels.logout'));
echo sprintf($li, BASE_URI.'/login/logout', $this->translate('logout'));
$name = View::escape($_SESSION['USER']->getFullname());
echo sprintf('<li>'.sprintf($this->translate('messages.signed_in_as'), $name).'</li>');
}
else {
$return_url = View::escape($_SERVER['REQUEST_URI']);
echo sprintf($li, BASE_URI.'/login?return_url='.$return_url, $this->translate('labels.login'));
echo sprintf($li, BASE_URI.'/login?return_url='.$return_url, $this->translate('login'));
}
?>
</ul>

View File

@ -1,6 +1,8 @@
<div id="footer">
<p>
<?php
global $startTime;
# Calculate the process time
$endTime = microtime(1);
$processTime = $endTime - $startTime;

View File

@ -14,7 +14,7 @@ use Application\Models\Person;
];
foreach ($routes as $singular=>$plural) {
if (Person::isAllowed($plural, 'index')) {
echo sprintf($a, BASE_URI.'/'.$plural, $this->_(["labels.$singular", "labels.$plural", 2]));
echo sprintf($a, BASE_URI.'/'.$plural, $this->_(["$singular", "$plural", 2]));
}
}
?>

View File

@ -40,8 +40,8 @@
</div>
<div id="cemeteryImages">
<div><img alt="Rose Hill Cemetery" src="<?php echo BASE_URL."/images/rosehill.png"; ?>" /></div>
<div><img alt="White Oak Cemetery" src="<?php echo BASE_URL."/images/whiteoakweb.jpg"; ?>" /></div>
<div><img alt="Rose Hill Cemetery" src="<?php echo BASE_URI."/images/rosehill.png"; ?>" /></div>
<div><img alt="White Oak Cemetery" src="<?php echo BASE_URI."/images/whiteoakweb.jpg"; ?>" /></div>
</div>
<?php
}