Rev 16 | Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
/*
Copyright (c) 2021, Daily Data, Inc. Redistribution and use in
source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Let's make sure we have the Users class loaded.
require_once( 'Users.class.php' );
/**
* User Permissions Login class
*
* IMPORTANT: Requires a data source. See UsersDataSourceMySQLi.class.php
* for code which provides this for MySQLi
*
* UsersPermissions extends the Users class to include boolean
* permissions.
*
* @author R. W. Rodolico <rodo@unixservertech.com>
*
* @version 0.9.0 (beta)
* @copyright 2021 Daily Data, Inc.
*
*/
class UsersPermissions extends Users {
public function __construct( $customFields = array() ) {
parent::__construct( $customFields );
} // constructor
protected function validate( $username, $password, $connection ) {
if ( parent::validate( $username, $password, $connection ) ) {
$this->data['permissions'] = $connection->getPermissions( $this->data['id'] );
}
}
public function editScreen( $connection ) {
$divDef = "<div class='category'>\n";
$return = array();
$return[] = parent::editScreen( $connection );
if ( $this->isAdmin() ) {
$values = $connection->getFullPermissions( $this->workingOn['id'] );
$category = array();
foreach ( $values as $thisEntry ) {
$field = $thisEntry['permission'];
$temp = sprintf( $this->configuration['html input fields']['boolean'],
$thisEntry['description'],
$this->configuration['input prefix'] . $field,
'Place a check here to give the user permission',
'',
$field
);
$category[$thisEntry['category']][] = preg_replace( "/~~$field~~/", $thisEntry['value'] ? 'checked' : '', $temp );
}
foreach ( $category as $name => $entries ) {
$return[] = $divDef . "<h3>$name</h3>" . implode( "\n", $entries ) . "</div>";
}
}
return implode( "\n", $return );
}
protected function addEdit( $connection ) {
$return = parent::addEdit( $connection );
return $return;
$data = array();
// now we process all of the permissions
if ( $return != 'Error' ) {
foreach ( $this->workingOn['permissions'] as $name => $value ) {
$htmlFieldName = $this->configuration['input prefix'] . $name;
if ( $this->workingOn['id'] == -1 || ( isset( $_REQUEST[$htmlFieldName] ) != $this->workingOn[$name] ) ) {
$data[$name] = isset( $_REQUEST[$htmlFieldName] ) ? 1 : 0;
}
} // foreach
$connection->updatePermissions( $this->workingOn['id'],$data );
} // if not an error
return $return;
} // addEdit
}
?>