2012-02-05 18:37:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
class Page_TasksUsers
|
|
|
|
extends AuthenticatedPage
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
public function __construct( )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
parent::__construct( array(
|
|
|
|
'' => 'users_list' ,
|
2012-02-06 17:22:58 +01:00
|
|
|
'view' => 'users_view' ,
|
2012-02-06 00:09:21 +01:00
|
|
|
'add' => 'users_add_form' ,
|
2012-02-06 10:03:11 +01:00
|
|
|
'edit' => 'users_edit_form' ,
|
2012-02-06 00:09:21 +01:00
|
|
|
) );
|
|
|
|
$this->setTitle( 'Users' );
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_UsersList
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$dao = Loader::DAO( 'users' );
|
|
|
|
return Loader::View( 'box' , null , Loader::View( 'users_list' , $dao->getUsers( ) ) )
|
|
|
|
->setClass( 'list' )
|
|
|
|
->addButton( BoxButton::create( 'Add user' , 'users/add' )
|
|
|
|
->setClass( 'list-add' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
class View_UsersList
|
|
|
|
extends BaseURLAwareView
|
|
|
|
{
|
|
|
|
private $users;
|
|
|
|
|
|
|
|
public function __construct( $users )
|
|
|
|
{
|
|
|
|
$this->users = $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$table = HTML::make( 'table' )
|
|
|
|
->appendElement( HTML::make( 'tr' )
|
|
|
|
->setAttribute( 'class' , 'header' )
|
|
|
|
->appendElement( HTML::make( 'th' )
|
|
|
|
->appendText( 'E-mail address' ) )
|
|
|
|
->appendElement( HTML::make( 'th' )
|
|
|
|
->appendText( 'Display name' ) ) );
|
|
|
|
|
|
|
|
foreach ( $this->users as $user ) {
|
|
|
|
$table->appendElement( $this->makeUserRow( $user ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function makeUserRow( $user )
|
|
|
|
{
|
|
|
|
$row = HTML::make( 'tr' )
|
|
|
|
->appendElement( HTML::make( 'td' )
|
|
|
|
->appendElement( $editLink = HTML::make( 'a' ) ) );
|
|
|
|
|
2012-02-06 17:22:58 +01:00
|
|
|
$editLink->setAttribute( 'href' , $this->base . '/users/view?id=' . $user->user_id )
|
2012-02-06 10:03:11 +01:00
|
|
|
->appendText( $user->user_email );
|
|
|
|
|
|
|
|
$nameColumn = HTML::make( 'td' );
|
|
|
|
if ( $user->user_display_name !== null ) {
|
|
|
|
$nameColumn->appendText( $user->user_display_name );
|
|
|
|
} else {
|
|
|
|
$nameColumn->appendElement( HTML::make( 'em' )->appendText( 'N/A' ) );
|
|
|
|
}
|
|
|
|
$row->appendElement( $nameColumn );
|
|
|
|
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-06 17:22:58 +01:00
|
|
|
class Ctrl_UsersView
|
|
|
|
extends Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$id = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'users';
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = Loader::DAO( 'users' )->getUserById( $id );
|
|
|
|
if ( $user === null ) {
|
|
|
|
return 'users';
|
|
|
|
}
|
|
|
|
|
2012-02-06 18:12:07 +01:00
|
|
|
$page->setTitle( $user->user_view_name );
|
|
|
|
|
|
|
|
return array(
|
|
|
|
Loader::View( 'box' , 'User information' , Loader::View( 'users_view' , $user ) )
|
|
|
|
->addButton( BoxButton::create( 'Edit user' , 'users/edit?id=' . $id )
|
|
|
|
->setClass( 'icon edit' ) ) ,
|
|
|
|
Loader::View( 'box' , 'Assigned tasks' , Loader::View( 'tasks_list' ,
|
|
|
|
Loader::DAO( 'tasks' )->getUserTasks( $user ) , array( 'deps' , 'item' ) ) ) );
|
2012-02-06 17:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class View_UsersView
|
|
|
|
implements View
|
|
|
|
{
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
public function __construct( $user )
|
|
|
|
{
|
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( )
|
|
|
|
{
|
|
|
|
$fields = array( );
|
|
|
|
|
|
|
|
$fields[] = HTML::make( 'dt' )->appendText( 'E-mail address:' );
|
|
|
|
$fields[] = HTML::make( 'dd' )->appendText( $this->user->user_email );
|
|
|
|
$fields[] = HTML::make( 'dt' )->appendText( 'Display name:' );
|
|
|
|
if ( $this->user->user_display_name === null ) {
|
|
|
|
$fields[] = HTML::make( 'dd' )->appendElement(
|
|
|
|
HTML::make( 'em' )->appendText( 'None defined at this time' ) );
|
|
|
|
} else {
|
|
|
|
$fields[] = HTML::make( 'dd' )->appendText( $this->user->user_display_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
return HTML::make( 'dl' )
|
|
|
|
->append( $fields );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
class Ctrl_UsersAddForm
|
|
|
|
extends Controller
|
|
|
|
{
|
2012-02-06 00:28:07 +01:00
|
|
|
private $initial;
|
|
|
|
|
|
|
|
public function __construct( $initial = false )
|
|
|
|
{
|
|
|
|
$this->initial = $initial;
|
|
|
|
}
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
2012-02-06 00:28:07 +01:00
|
|
|
$form = Loader::Create( 'Form' , 'Create user' , 'user-add' )
|
2012-02-06 00:09:21 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'email' , 'text' )
|
|
|
|
->setDescription( 'E-mail address:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_Email' , 'Invalid address.' ) ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass' , 'password' )
|
|
|
|
->setDescription( 'Password:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This password' , 8 ) ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass2' , 'password' )
|
|
|
|
->setDescription( 'Confirm password:' ) )
|
2012-02-06 08:36:01 +01:00
|
|
|
->addField( Loader::Create( 'Field' , 'display-name' , 'text' )
|
|
|
|
->setDescription( 'Display name:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This display name',
|
|
|
|
5 , 256 , true ) ) )
|
2012-02-06 00:28:07 +01:00
|
|
|
->addController( Loader::Ctrl( 'users_add' , $this->initial ) );
|
|
|
|
|
|
|
|
if ( $this->initial ) {
|
|
|
|
$form->setSuccessURL( 'home' );
|
|
|
|
$page->setTitle( 'Initial user' );
|
|
|
|
} else {
|
|
|
|
$form->setURL( 'users' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $form->controller( );
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
class Ctrl_UsersAdd
|
|
|
|
extends Controller
|
|
|
|
implements FormAware
|
|
|
|
{
|
|
|
|
private $form;
|
2012-02-06 00:28:07 +01:00
|
|
|
private $initial;
|
|
|
|
|
|
|
|
public function __construct( $initial )
|
|
|
|
{
|
|
|
|
$this->initial = $initial;
|
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
public function setForm( Form $form )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
$this->form = $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$p1 = $this->form->field( 'pass' );
|
|
|
|
$p2 = $this->form->field( 'pass2' );
|
|
|
|
if ( $p1->value( ) != $p2->value( ) ) {
|
|
|
|
$p1->putError( 'Passwords did not match.' );
|
2012-02-05 18:37:25 +01:00
|
|
|
return null;
|
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
$email = $this->form->field( 'email' );
|
2012-02-06 08:36:01 +01:00
|
|
|
$name = $this->form->field( 'display-name' );
|
2012-02-06 00:09:21 +01:00
|
|
|
$error = Loader::DAO( 'users' )->addUser( $email->value( ) ,
|
2012-02-06 08:36:01 +01:00
|
|
|
$p1->value( ) , $name->value( ) );
|
2012-02-06 00:09:21 +01:00
|
|
|
|
|
|
|
switch ( $error ) {
|
|
|
|
|
|
|
|
case 0:
|
2012-02-06 00:28:07 +01:00
|
|
|
if ( $this->initial ) {
|
|
|
|
session_start( );
|
|
|
|
$_SESSION[ 'uid' ] = Loader::DAO( 'users' )->getUser( $email->value( ) )->user_id;
|
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
$email->putError( 'This e-mail address is already in use.' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$email->putError( 'Some unknown error has occurred (' . $error . ')' );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return null;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
|
2012-02-05 18:37:25 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
class Ctrl_UsersEditForm
|
|
|
|
extends Controller
|
|
|
|
{
|
2012-02-06 00:09:21 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$userId = (int) $this->getParameter( 'id' );
|
|
|
|
} catch ( ParameterException $e ) {
|
|
|
|
return 'users';
|
|
|
|
}
|
|
|
|
$user = Loader::DAO( 'users' )->getUserById( $userId );
|
|
|
|
if ( $user === null ) {
|
|
|
|
return 'users';
|
|
|
|
}
|
|
|
|
|
|
|
|
$page->setTitle( 'Modify user ' . $user->user_view_name );
|
|
|
|
|
|
|
|
$details = Loader::Create( 'Form' , 'Modify user' , 'user-edit' , 'Account details' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $user->user_id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'email' , 'text' )
|
|
|
|
->setDescription( 'E-mail address:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_Email' , 'Invalid address.' ) )
|
|
|
|
->setDefaultValue( $user->user_email ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'display-name' , 'text' )
|
|
|
|
->setDescription( 'Display name:' )
|
|
|
|
->setMandatory( false )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This display name',
|
|
|
|
5 , 256 , true ) )
|
|
|
|
->setDefaultValue( $user->user_display_name ) )
|
|
|
|
->addController( Loader::Ctrl( 'users_edit' ) )
|
2012-02-06 17:22:58 +01:00
|
|
|
->setURL( 'users/view?id=' . $userId );
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
$password = Loader::Create( 'Form' , 'Modify password' , 'user-set-password' , 'Account password' )
|
|
|
|
->addField( Loader::Create( 'Field' , 'id' , 'hidden' )
|
|
|
|
->setDefaultValue( $user->user_id ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass' , 'password' )
|
|
|
|
->setDescription( 'New password:' )
|
|
|
|
->setValidator( Loader::Create( 'Validator_StringLength' , 'This password' , 8 ) ) )
|
|
|
|
->addField( Loader::Create( 'Field' , 'pass2' , 'password' )
|
|
|
|
->setDescription( 'Confirm new password:' ) )
|
|
|
|
->addController( Loader::Ctrl( 'users_set_password' ) )
|
2012-02-06 17:22:58 +01:00
|
|
|
->setURL( 'users/view?id=' . $userId );
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
return array( $details->controller( ) , $password->controller( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Ctrl_UsersEdit
|
|
|
|
extends Controller
|
|
|
|
implements FormAware
|
2012-02-06 00:09:21 +01:00
|
|
|
{
|
2012-02-06 10:03:11 +01:00
|
|
|
private $form;
|
2012-02-06 00:09:21 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
public function setForm( Form $form )
|
2012-02-05 18:37:25 +01:00
|
|
|
{
|
2012-02-06 10:03:11 +01:00
|
|
|
$this->form = $form;
|
2012-02-06 00:09:21 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
public function handle( Page $page )
|
2012-02-06 00:09:21 +01:00
|
|
|
{
|
2012-02-06 10:03:11 +01:00
|
|
|
$id = $this->form->field( 'id' )->value( );
|
|
|
|
$name = $this->form->field( 'display-name' )->value( );
|
|
|
|
$emailField = $this->form->field( 'email' );
|
|
|
|
$email = $emailField->value( );
|
2012-02-06 00:09:21 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
$error = Loader::DAO( 'users' )->modify( $id , $email , $name );
|
|
|
|
switch ( $error ) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
$email->putError( 'Duplicate address.' );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$email->putError( 'An unknown error occurred (' . $error . ')' );
|
|
|
|
break;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-06 00:09:21 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
return null;
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|
2012-02-06 10:03:11 +01:00
|
|
|
}
|
2012-02-06 08:36:01 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
class Ctrl_UsersSetPassword
|
|
|
|
extends Controller
|
|
|
|
implements FormAware
|
|
|
|
{
|
|
|
|
private $form;
|
|
|
|
|
|
|
|
|
|
|
|
public function setForm( Form $form )
|
2012-02-06 08:36:01 +01:00
|
|
|
{
|
2012-02-06 10:03:11 +01:00
|
|
|
$this->form = $form;
|
|
|
|
}
|
2012-02-06 08:36:01 +01:00
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
|
|
|
|
public function handle( Page $page )
|
|
|
|
{
|
|
|
|
$p1 = $this->form->field( 'pass' );
|
|
|
|
$p2 = $this->form->field( 'pass2' );
|
|
|
|
if ( $p1->value( ) != $p2->value( ) ) {
|
|
|
|
$p1->putError( 'Passwords did not match.' );
|
|
|
|
return null;
|
2012-02-06 08:36:01 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 10:03:11 +01:00
|
|
|
$id = $this->form->field( 'id' )->value( );
|
|
|
|
Loader::DAO( 'users' )->setPassword( $id , $p1->value( ) );
|
|
|
|
return true;
|
2012-02-06 08:36:01 +01:00
|
|
|
}
|
2012-02-05 18:37:25 +01:00
|
|
|
}
|