unit UUserCrossTable;
interface
type
// type for filesettings
TDirectory =
record
Name:
string;
FullAccess: Boolean;
Modify: Boolean;
Execute: Boolean;
List: Boolean;
Read: Boolean;
Write: Boolean;
end;
PDirectory = ^TDirectory;
TDirectories =
array of TDirectory;
// type for optional ad attributes
TOptAttr =
record
name:
string;
//string[50]
value:
string;
end;
POptAttr = ^TOptAttr;
TOptAttrs =
array of TOptAttr;
// type for group
TGroup =
record
name:
string;
ldappath:
string;
end;
PGroup = ^TGroup;
TGroups =
array of TGroup;
// type for quota
TQuota =
record
volume:
string;
limit: Integer;
Threshold: Integer;
end;
PQuota = ^TQuota;
TQuotas =
array of TQuota;
// THIS IS ONE USER
TUser =
class(TObject)
private
arrGroups: TGroups;
arrDirectories: TDirectories;
arrQuotas: TQuotas;
arrOptAttrs: TOptAttrs;
public
sAMAccountName:
string;
givenName:
string;
sn:
string;
password:
string;
containerPath:
string;
function Groups: TGroups;
function AddGroup(group: TGroup): Integer;
procedure removeGroup(
index: Integer);
function GroupCount: Integer;
procedure AssignGroups(Groups: TGroups);
procedure ClearGroups;
function Directories: TDirectories;
function AddDirectory(directory: TDirectory): Integer;
procedure removeDirectory(
index: Integer);
function DirectoryCount: Integer;
procedure AssignDirectories(Directories: TDirectories);
procedure ClearDirectories;
function Quotas: TQuotas;
function AddQuota(quota: TQuota): Integer;
procedure removeQuota(
index: Integer);
function QuotaCount: Integer;
procedure AssignQuotas(Quotas: TQuotas);
procedure ClearQuotas;
function OptionalAttributes: TOptAttrs;
function AddOptionalAttribute(attribute: TOptAttr): Integer;
procedure removeOptionalAttribute(
index: Integer);
function OptionalAttributeCount: Integer;
procedure AssignOptionalAttributes(Attributes: TOptAttrs);
procedure ClearOptionalAttributes;
end;
TUsers =
array of TUser;
// THIS IS THE TABLE CLASS WHO HANDLES THE ENTRIES
TUserCrossTable =
class(TObject)
private
arrUsers: TUsers;
public
function Users: TUsers;
function addUser(user: TUser): Integer;
procedure removeUser(
index: Integer);
function UserCount: Integer;
// procedure SaveToFile(name: string);
// procedure LoadFromFile(name: string);
end;
implementation
//------------------------------------------------------------------------------
// CLASS USER
//------------------------------------------------------------------------------
// GET ALL GROUPS
function TUser.Groups: TGroups;
begin
result := arrGroups;
end;
// ADD NEW GROUP
function TUser.AddGroup(group: TGroup): Integer;
begin
SetLength(arrGroups, Length(arrGroups)+1);
arrGroups[Length(arrGroups)-1] := group;
result := Length(arrGroups)-1;
end;
// REMOVE A GROUP
procedure TUser.removeGroup(
index: Integer);
begin
if index < 0
then exit;
if index > Length(arrGroups)
then exit;
if index = Length(arrGroups)
then
begin
SetLength(arrGroups, Length(arrGroups)-1);
Exit;
end;
System.Move(arrGroups[
index+1], arrGroups[
index], (Length(arrGroups) -
index - 1) * SizeOf(TGroup) + 1 );
// move
SetLength(arrGroups, Length(arrGroups)-1);
// set new length
Exit;
// exit
end;
// GET GROUP COUNT
function TUser.GroupCount;
begin
result := Length(arrGroups);
end;
// ASSIGN GROUPS
procedure TUser.AssignGroups(Groups: TGroups);
begin
arrGroups := Copy(Groups, 0, Length(Groups));
end;
// CLEAR GROUPS
procedure TUser.ClearGroups;
begin
SetLength(arrGroups, 0);
end;
// GET ALL DIRECTORIES
function TUser.Directories: TDirectories;
begin
result := arrDirectories;
end;
// ADD NEW DIRECTORY
function TUser.AddDirectory(directory: TDirectory): Integer;
begin
SetLength(arrDirectories, Length(arrDirectories)+1);
arrDirectories[Length(arrDirectories)-1] := directory;
result := Length(arrDirectories)-1;
end;
// REMOVE A DIRECTORY
procedure TUser.removeDirectory(
index: Integer);
begin
if index < 0
then exit;
if index > Length(arrDirectories)
then exit;
if index = Length(arrDirectories)
then
begin
SetLength(arrDirectories, Length(arrDirectories)-1);
Exit;
end;
System.Move(arrDirectories[
index+1], arrDirectories[
index], (Length(arrDirectories) -
index - 1) * SizeOf(TDirectory) + 1 );
// move
SetLength(arrDirectories, Length(arrDirectories)-1);
// set new length
Exit;
// exit
end;
// GET DIRECOTRY COUNT
function TUser.DirectoryCount;
begin
result := Length(arrDirectories);
end;
// ASSIGN DIRECTORIES
procedure TUser.AssignDirectories(Directories: TDirectories);
begin
arrDirectories := Copy(Directories, 0, Length(Directories));
end;
// CLEAR DIRECTORIES
procedure TUser.ClearDirectories;
begin
SetLength(arrDirectories, 0);
end;
// GET ALL QUOTAS
function TUser.Quotas: TQuotas;
begin
result := arrQuotas;
end;
// ADD NEW QUOTA
function TUser.AddQuota(quota: TQuota): Integer;
begin
SetLength(arrQuotas, Length(arrQuotas)+1);
arrQuotas[Length(arrQuotas)-1] := quota;
result := Length(arrQuotas)-1;
end;
// REMOVE A QUOTA
procedure TUser.removeQuota(
index: Integer);
begin
if index < 0
then exit;
if index > Length(arrQuotas)
then exit;
if index = Length(arrQuotas)
then
begin
SetLength(arrQuotas, Length(arrQuotas)-1);
Exit;
end;
System.Move(arrQuotas[
index+1], arrQuotas[
index], (Length(arrQuotas) -
index - 1) * SizeOf(TQuota) + 1 );
// move
SetLength(arrQuotas, Length(arrQuotas)-1);
// set new length
Exit;
// exit
end;
// GET QUOTA COUNT
function TUser.QuotaCount;
begin
result := Length(arrQuotas);
end;
// ASSIGN QUOTA
procedure TUser.AssignQuotas(Quotas: TQuotas);
begin
arrQuotas := Copy(Quotas, 0, Length(Quotas));
end;
// CLEAR QUOTAS
procedure TUser.ClearQuotas;
begin
SetLength(arrQuotas, 0);
end;
// GET ALL OPTIONAL ATTRIBUTES
function TUser.OptionalAttributes: TOptAttrs;
begin
result := arrOptAttrs;
end;
// ADD NEW OPTIONAL ATTRIBUTE
function TUser.AddOptionalAttribute(attribute: TOptAttr): Integer;
begin
SetLength(arrOptAttrs, Length(arrOptAttrs)+1);
arrOptAttrs[Length(arrOptAttrs)-1] := attribute;
result := Length(arrOptAttrs)-1;
end;
// REMOVE A OPTIONAL ATTRIBUTE
procedure TUser.removeOptionalAttribute(
index: Integer);
begin
if index < 0
then exit;
if index > Length(arrOptAttrs)
then exit;
if index = Length(arrOptAttrs)
then
begin
SetLength(arrOptAttrs, Length(arrOptAttrs)-1);
Exit;
end;
System.Move(arrOptAttrs[
index+1], arrOptAttrs[
index], (Length(arrOptAttrs) -
index - 1) * SizeOf(TOptAttr) + 1 );
// move
SetLength(arrOptAttrs, Length(arrOptAttrs)-1);
// set new length
Exit;
// exit
end;
// GET OPTIONAL ATTRIBUTE COUNT
function TUser.OptionalAttributeCount;
begin
result := Length(arrOptAttrs);
end;
// ASSIGN OPTIONAL ATTRIBUTES
procedure TUser.AssignOptionalAttributes(Attributes: TOptAttrs);
begin
arrOptAttrs := Copy(Attributes, 0, Length(Attributes));
end;
// CLEAR OPTIONAL ATTRIBUTES
procedure TUser.ClearOptionalAttributes;
begin
SetLength(arrOptAttrs, 0);
end;
//------------------------------------------------------------------------------
// CLASS USER CROSS TABLE
//------------------------------------------------------------------------------
// GET ALL USERS
function TUserCrossTable.Users: TUsers;
begin
result := arrUsers;
end;
// ADD AN USER
function TUserCrossTable.addUser(user: TUser): Integer;
begin
SetLength(arrUsers, Length(arrUsers)+1);
arrUsers[Length(arrUsers)-1] := user;
result := Length(arrUsers)-1;
end;
// REMOVE AN USER
procedure TUserCrossTable.removeUser(
index: Integer);
begin
if index < 0
then exit;
if index > Length(arrUsers)
then exit;
if index = Length(arrUsers)
then
begin
SetLength(arrUsers, Length(arrUsers)-1);
Exit;
end;
Finalize(arrUsers[
index]);
System.Move(arrUsers[
index+1], arrUsers[
index], (Length(arrUsers) -
index - 1) * SizeOf(TUser) + 1 );
// move
Pointer(arrUsers[Length(arrUsers)-1]) :=
nil;
// set nil
SetLength(arrUsers, Length(arrUsers)-1);
// set new length
Exit;
// exit
end;
// GET USER COUNT
function TUserCrossTable.UserCount;
begin
result := Length(arrUsers);
end;
end.