<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Modules :: NitroBOSubModule :: UserSecurity |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems B.V. |
// +---------------------------------------------------------------------------+
// | This source file is copyrighted by June Systems BV, the Netherlands |
// | If you would like to use this file in your projects, please contact |
// | hide@address.com |
// +---------------------------------------------------------------------------+
// | Authors: Jesper Avôt <hide@address.com> |
// +---------------------------------------------------------------------------+
//
// $Id: Module.inc.php 229 2008-04-17 09:20:31Z oli $
//
/**
* Include Form controls and Listing classes
*/
require_once "Nitro/Libraries/Form.inc.php";
require_once "Nitro/Libraries/Listing.inc.php";
/**
* UserSecurity
*
* @author Jesper Avôt <hide@address.com>
* @copyright 2006 June Systems B.V.
* @package Modules
* @subpackage NitroBO
*/
class NitroBO_UserSecurity extends NitroBOSubModule {
/**
* Define some Module things
*/
var $ModuleName = "NitroBO_UserSecurtiy";
var $ModuleVersion = "1.0";
var $ModuleAuthor = Array("Jesper Avôt");
/**
* Does Nothing
*/
function NitroBO_UserSecurity() { }
/**
* GetSettingsDefinition function
*
* Which Settings are allowed in this Module?
*/
function GetSettingsDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
if (!isset($this->_ModuleSettings)) {
$this->_ModuleSettings = Array(
'P' => Array('SessionVariable' => FALSE, 'FormVariable' => 'P', 'Default' => NULL),
'UserID' => Array('SessionVariable' => FALSE, 'FormVariable' => 'UserID', 'Default' => NULL),
'SecurityID' => Array('SessionVariable' => FALSE, 'FormVariable' => 'SecurityID', 'Default' => NULL),
'Action' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Action', 'Default' => NULL),
'ModFilter' => Array('SessionVariable' => FALSE, 'FormVariable' => 'ModFilter/', 'Default' => NULL),
'Start' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Start', 'Default' => 0)
);
}
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_ModuleSettings;
}
/**
* GetSettingsDefinition function
*
* Which Settings are allowed in this Module for XML Requests?
*/
function GetXMLDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
if (!isset($this->_XMLDefinition)) {
$this->_XMLDefinition = Array(
'ChangeUserRight' => Array('Type' => "HTML",
'Name' => 'Change User Rights',
'DivID' => "UserField",
'FunctionName' => "ChangeUserRight"),
'FilterMod' => Array('Type' => "HTML",
'Name' => 'Filter UserSecurity List',
'DivID' => "UserField",
'FunctionName' => "ShowUserRightsList"),
'ShowUserRightsList' => Array('Type' => "HTML",
'Name' => 'Change User Rights',
'DivID' => "UserField",
'FunctionName' => "ShowUserRightsList")
);
}
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_XMLDefinition;
}
/**
* GetObjectsDefinition function
*
* Which Objects are allowed ?
*/
function GetObjectsDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$this->_ModuleObjects = Array(
'Draw' => Array('Type' => 'HTML',
'Name' => 'Text',
'FunctionName' => 'Draw',
'Default' => TRUE)
);
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_ModuleObjects;
}
function Draw()
{
$RV = "<h2>". Language('User Security') . "</h2>";
$RV.= $this->ShowUserRightsList(TRUE);
return $RV;
}
/**
* ChangeUserRight function
*/
function ChangeUserRight()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$updateID = "UserID" . (int)$this->GetSetting( 'UserID' ) . "SecurityID" . (int)$this->GetSetting( 'SecurityID' );
$UserID = (int)$this->GetSetting('UserID');
$SecurityID = (int)$this->GetSetting('SecurityID');
$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
if ($this->GetSetting('Action') == "Activate") {
$Transaction->addData('User_SecurityGroup',
Array('UserID' => $UserID,
'SecurityGroupID' => $SecurityID),
FALSE,
'INSERT');
$IMG = "<div id=\"" . $updateID . "\"><img src=\"./GetObject.php?NitroDefault=Images/checked.gif\" width=\"16\" height=\"16\" alt\"Active\" border=\"0\" style=\"cursor: pointer;\" title=\"Deactivate\" onclick=\"ModuleXMLRequest('ChangeUserRight', '&Action=Deactivate&UserID=" . $UserID . "&SecurityID=" . $SecurityID . "'); return false;\" /></div>";
} else {
$Transaction->addData('User_SecurityGroup',
Array('UserID' => $UserID,
'SecurityGroupID' => $SecurityID),
Array('UserID' => $UserID,
'SecurityGroupID' => $SecurityID),
'DELETE');
$IMG = "<div id=\"" . $updateID . "\"><img src=\"./GetObject.php?NitroDefault=Images/unchecked.gif\" width=\"16\" height=\"16\" alt\"Not Active\" border=\"0\" style=\"cursor: pointer;\" title=\"Activate\" onclick=\"ModuleXMLRequest('ChangeUserRight', '&Action=Activate&UserID=" . $UserID . "&SecurityID=" . $SecurityID . "'); return false;\" /></div>";
}
$RV = ($Transaction->Commit() !== FALSE) ? Array($updateID => $IMG) : "";
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* ShowUserRightsList function
**/
function ShowUserRightsList($inDiv = FALSE)
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$Start = Array(TRUE, (strlen($this->GetSetting('Start')) && $this->GetSetting('Start') !== 0 ? $this->GetSetting('Start') : 0));
$Filter = Array(TRUE, (strlen($this->GetSetting('ModFilter')) && $this->GetSetting('ModFilter') !== 0 ? $this->GetSetting('ModFilter') : FALSE));
$List = new Listing2( "", "UsersSecurity_" . $this->GetSetting( 'P' ), ($inDiv !== FALSE ? "UserField" : FALSE), $Start, $Filter, "UsersSecurities_" );
$List->EnableRowHighlighting = TRUE;
$List->AddColumn(Language('User'), "User");
$List->SetColumnWidth("90%", "User");
// SecuurityGroups
$SecurityGroups = array();
$Query = "SELECT
SecurityGroupID,
Name
FROM
`SecurityGroup`
ORDER BY
Name";
$Result = $this->DB->query($Query);
if( $Result->numRows() ) {
while( $Data = $Result->fetchArray() ) {
$SecurityGroups[$Data["SecurityGroupID"]] = $Data;
}
}
$Result->free();
// User Stuff
$Users = array();
$Query = "SELECT
SQL_CALC_FOUND_ROWS
UserID,
Name
FROM
User
" . ($List->Filter['User'] ? "WHERE " : "") . "
" . ($List->Filter['User'] ? "Name LIKE " . NitroPrepareDB("%" . $List->Filter['User'] . "%") . " " : "") . "
ORDER BY
Username
" . ($List->usePages !== FALSE ? "LIMIT " . (int)$List->Start . ", " . (int)$List->maxPerPage : "");
$Result = $this->DB->query($Query);
$List->allPages = $this->DB->getOne("SELECT FOUND_ROWS()");
$List->onChange = "ShowUserRightsList";
if ($Result->numRows()) {
while ($Data = $Result->fetchRow()) {
$Users[$Data["UserID"]] = $Data;
}
}
$Result->free();
// User Security Stuff
$UsersSecurity = Array();
$Query = "SELECT
UserID,
SecurityGroupID
FROM
`User_SecurityGroup`";
$Result = $this->DB->query($Query);
if ($Result->numRows()) {
while ($Data = $Result->fetchArray()) {
$UsersSecurity[$Data["UserID"]][$Data["SecurityGroupID"]] = TRUE;
}
}
$Result->free();
foreach ($SecurityGroups AS $ID => $Row) {
$List->AddColumn("<span style='writing-mode: tb-rl'>" . $Row["Name"] . "</span>", $ID, TRUE);
$List->hideFilter[] = $ID;
}
$n = 1;
foreach ($Users AS $ID => $Row) {
$ListRow = new ListingRow2();
$ListRow->AddData("User", $Row["Name"]);
foreach ($SecurityGroups AS $SGID => $SGRow) {
if ($UsersSecurity[$ID][$SGID]) {
$IMG = "<div id=\"UserID" . $ID . "SecurityID" . $SGID . "\"><img src=\"./GetObject.php?NitroDefault=Images/checked.gif\" width=\"16\" height=\"16\" alt\"Active\" border=\"0\" style=\"cursor: pointer;\" title=\"Deactivate\" onclick=\"ModuleXMLRequest('ChangeUserRight', '&Action=Deactivate&UserID=" . $ID . "&SecurityID=" . $SGID . "'); return false;\" /></div>";
} else {
$IMG = "<div id=\"UserID" . $ID . "SecurityID" . $SGID . "\"><img src=\"./GetObject.php?NitroDefault=Images/unchecked.gif\" width=\"16\" height=\"16\" alt\"Not Active\" border=\"0\" style=\"cursor: pointer;\" title=\"Activate\" onclick=\"ModuleXMLRequest('ChangeUserRight', '&Action=Activate&UserID=" . $ID . "&SecurityID=" . $SGID . "'); return false;\" /></div>";
}
$ListRow->AddData($SGID, $IMG);
}
$List->AddListRow($ListRow);
unset($ListRow);
}
DebugCloseGroup(DEBUG_MOD_OK);
$List-> SetTemplate("file:" . NITRO_PATH . "Defaults/Templates/BackOffice/Listing.tpl");
return $List->Draw();
}
}
?>