<?php

$s = Alfred_Hod::table('Acl_Role','Access')->getFilterSelect(array(),array('label ASC'));
$rolelist = Alfred_Hod::table('Acl_Role','Access')->fetchAll($s)->multiOptions(null);
?>    
    <table class="table table-striped table-bordered table-condensed" style="max-width: 800px">
        <thead>
            <tr>
                <td colspan="3">
                    <span class="pull-right">
                        <a href="<?php echo $this->url( array( 'action' => 'save' ) ); ?>" class="btn btn-primary" title="<?php echo $this->translate( '#create#' ); ?>">
                            <span class="fa fa-plus"></span>
                        </a>                       
                    </span>

                    <?php echo $this->paginationControl( $this->paginator ); ?>
                </td>
            </tr>
            
            <tr>
                <th><?php echo $this->translate( '#username#' ); ?></th>
                <th><?php echo $this->translate( '#role#' ); ?></th>
                <th width="200">&nbsp;</th>
            </tr>
            <form id="searchForm">
            <tr class="search-row">
                <td><?php echo $this->formText( 'username', $this->search['username'], array( 'style' => 'width:96%' ) ); ?></td>
            	
                <td>
                    <?= $this->formSelect('role',$this->search['role'], array( 'style' => 'width:96%' ),array(''=>'')+ $rolelist) ?>
                </td>
            	<td><button class="btn btn-default" title="<?= $this->translate('#search#')?>"><i class="fa fa-search"></i></button></td>

            </tr>
            </form>
        </thead>

        <tbody>
<?php       
        if ( count( $this->paginator ) ) { 

            foreach ( $this->paginator as $item ) {
                if ( $item->role != 'God' || $this->identity()->role == 'God' ) {
                    $class = $this->cycle( array( 'odd', 'even' ) )->next();
                    $class.= $item->isBlocked == 1 ? ' blocked' : ''; ?>
            <tr class="<?php echo $class; ?>">
                <td><?php echo $item->username; ?></td>

                <td><?php echo $item->role; ?></td>
               

                <td class="actions">
                    <span class="btn-group">
<?php               if ( $this->identity()->id != $item->id ) {
                        if ( $item->isBlocked == 0 ) { ?>
                    <a href="<?php echo $this->url( array( 'action' => 'block', 'id' => $item->id ) ); ?>" class="btn btn-default">
                        <span class="fa fa-lock" title="<?php echo $this->translate( '#block#' ); ?>" ></span>
                        
                    </a>
<?php                   } else { ?>
                    <a href="<?php echo $this->url( array( 'action' => 'unblock', 'id' => $item->id ) ); ?>" class="btn btn-default">
                        <span class="fa fa-unlock" title="<?php echo $this->translate( '#unblock#' ); ?>" ></span>
                        
                    </a>
<?php                   }

						if ( $item->role != 'God' && $item->role != 'Admin' ) { ?>

					<a href="<?php echo $this->url( array( 'action' => 'set-rules', 'id' => $item->id ) ); ?>" class="btn btn-default">
                        <span class="fa fa-key" title="<?php echo $this->translate( '#rules for this account#' ); ?>" ></span>
                        
                    </a>

<?php               	}
					} ?>

                    <a href="<?php echo $this->url( array( 'action' => 'save', 'id' => $item->id ) ); ?>" class="btn btn-default">
                        <span class="fa fa-pencil" title=" <?php echo $this->translate( '#edit#' ); ?>" ></span>
                       
                    </a>

<?php               if ( $this->identity()->id != $item->id ) { ?>
                    <a href="<?php echo $this->url( array( 'action' => 'delete', 'id' => $item->id ) ); ?>" class="btn btn-danger">
                        <span class="fa fa-trash-o" title="<?php echo $this->translate( '#delete#' ); ?>"></span>
                        
                    </a>
<?php               } ?>

                    <?php if( $item->role == 'Anonymous'): ?>
                    <a href="<?= $this->url(array('action'=>'validate','id'=>$item->id,'role'=>'ReaderLevel1')) ?>" title="activate" class="btn btn-success"><i class="fa fa-check"></i></a>
                    <?php endif; ?>
                    </span>
                </td>
            </tr>
<?php           }
            } 
        }else{
            echo '<tr><td rowspan="3">'.$this->translate( '#this list is empty#' ).'</td><tr>';
        }?>

        </tbody>

        <tfoot>
            <tr>
                <td colspan="3">
                    <span class="pull-right">
                        <a href="<?php echo $this->url( array( 'action' => 'save' ) ); ?>" class="btn btn-primary" title="<?php echo $this->translate( '#create#' ); ?>">
                            <span class="fa fa-plus"></span>
                        </a>                       
                    </span>

                    <?php echo $this->paginationControl( $this->paginator ); ?>
                </td>
            </tr>
        </tfoot>
    </table>

