Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fusiondirectory
fusiondirectory
Commits
dda5297c
Commit
dda5297c
authored
Dec 03, 2013
by
Benoit Mortier
Browse files
update simple-plugin from simple-plugin master
parent
82b3ffd9
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/simpleplugin/class_attribute.inc
View file @
dda5297c
...
...
@@ -542,6 +542,11 @@ class Attribute
$this
->
setValue
(
$newvalue
);
}
}
function
foreignKeyCheck
(
$value
,
$source
)
{
return
(
$this
->
getValue
()
==
$value
);
}
}
/*! \brief This class allow to handle easily a Boolean LDAP attribute
...
...
@@ -1815,6 +1820,11 @@ class ArrayAttribute extends Attribute
}
unset
(
$value
);
}
function
foreignKeyCheck
(
$value
,
$source
)
{
return
in_array
(
$value
,
$this
->
value
);
}
}
/*! \brief This class allow to handle easily a multi-valuated attribute with no duplicate values
...
...
include/simpleplugin/class_dialogAttributes.inc
View file @
dda5297c
...
...
@@ -237,6 +237,94 @@ class DialogAttribute extends SetAttribute
}
}
class
DialogOrderedArrayAttribute
extends
OrderedArrayAttribute
{
protected
$dialogClass
;
function
__construct
(
$label
,
$description
,
$ldapName
,
$required
=
FALSE
,
$defaultValue
=
array
(),
$acl
=
""
)
{
Attribute
::
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$defaultValue
,
$acl
);
$this
->
edit_enabled
=
TRUE
;
}
function
getAcl
()
{
return
Attribute
::
getAcl
();
}
function
setAcl
(
$acl
)
{
return
Attribute
::
setAcl
(
$acl
);
}
function
check
()
{
return
Attribute
::
check
();
}
function
renderAttributeInput
(
$template
=
FALSE
)
{
}
function
renderAttribute
(
&
$attributes
,
$readOnly
)
{
Attribute
::
renderAttribute
(
$attributes
,
$readOnly
);
}
function
setParent
(
&
$plugin
)
{
Attribute
::
setParent
(
$plugin
);
}
function
loadPostValue
()
{
if
(
$this
->
isVisible
())
{
parent
::
loadPostValue
();
parent
::
applyPostValue
();
if
(
isset
(
$_POST
[
'add'
.
$this
->
getHtmlId
()]))
{
$this
->
plugin
->
openDialog
(
new
$this
->
dialogClass
(
$this
->
plugin
,
$this
));
}
}
}
protected
function
handleAddAndEditValue
()
{
}
protected
function
handleEdit
(
$key
)
{
$this
->
editingValue
=
$this
->
value
[
$key
];
$this
->
delPostValue
(
$key
);
$this
->
plugin
->
openDialog
(
new
$this
->
dialogClass
(
$this
->
plugin
,
$this
,
$this
->
editingValue
));
}
function
applyPostValue
()
{
}
function
addValue
(
$value
)
{
$this
->
value
[]
=
$value
;
$this
->
reIndexValues
();
}
protected
function
getAttributeArrayValue
(
$value
)
{
/* Convert text value to displayable array value */
die
(
'Pure virtual method'
);
}
function
readValue
(
$value
)
{
die
(
'Pure virtual method'
);
}
function
writeValue
(
$key
,
$value
)
{
die
(
'Pure virtual method'
);
}
}
class
GenericDialogAttribute
extends
DialogAttribute
{
protected
$displays
=
array
();
...
...
@@ -338,36 +426,31 @@ class UsersAttribute extends GenericDialogAttribute
*
* It looks like a SetAttribute, but clicking "Add" will open a dialog that allow to select one or more users or groups.
* It stores their dn as values, but displays the cn.
*"
*/
class
UsersGroupsAttribute
extends
DialogAttribute
class
UsersGroupsAttribute
extends
Generic
DialogAttribute
{
protected
$dialogClass
=
'UserGroupSelectDialog'
;
function
addValue
(
$dn
,
$entry
)
protected
function
ldapAttributesToGet
(
)
{
if
(
in_array
(
"posixGroup"
,
$entry
[
'objectClass'
]))
{
$name
=
trim
(
"%"
.
$entry
[
'cn'
][
0
]);
}
elseif
(
isset
(
$entry
[
'uid'
][
0
]))
{
$name
=
trim
(
$entry
[
'uid'
][
0
]);
}
if
(
!
in_array
(
$name
,
$this
->
value
)
&&
!
in_array
(
"!"
.
$name
,
$this
->
value
))
{
$this
->
value
[]
=
$name
;
}
return
array
(
'cn'
,
'uid'
,
'objectClass'
);
}
function
getFilterBlackList
(
)
protected
function
fillDisplayValueFrom
(
$i
,
$attrs
)
{
$used
=
array
();
foreach
(
$this
->
value
as
$name
)
{
$str
=
preg_replace
(
"/^!/"
,
""
,
$name
);
if
(
preg_match
(
"/^%/"
,
$str
))
{
$used
[
'cn'
][]
=
preg_replace
(
"/^%/"
,
""
,
$str
);
if
(
!
isset
(
$attrs
[
$this
->
display_attr
]))
{
unset
(
$this
->
value
[
$i
]);
}
else
{
if
(
$this
->
display_attr
==
'dn'
)
{
$this
->
displays
[
$i
]
=
$attrs
[
'dn'
];
}
elseif
(
in_array
(
"posixGroup"
,
$attrs
[
'objectClass'
]))
{
$this
->
displays
[
$i
]
=
sprintf
(
_
(
"Group %s"
),
trim
(
$attrs
[
'cn'
][
0
]));
}
elseif
(
isset
(
$attrs
[
'uid'
][
0
]))
{
$this
->
displays
[
$i
]
=
trim
(
$attrs
[
'uid'
][
0
]);
}
else
{
$
used
[
'uid'
][]
=
$str
;
$
this
->
displays
[
$i
]
=
$attrs
[
$this
->
display_attr
][
0
]
;
}
}
return
$used
;
}
}
...
...
include/simpleplugin/class_simplePlugin.inc
View file @
dda5297c
...
...
@@ -860,84 +860,163 @@ class simplePlugin extends plugin
if
((
$olddn
!==
NULL
)
&&
(
$olddn
==
$newdn
))
{
return
;
}
$this
->
browseForeignKeys
(
'handle'
,
$olddn
,
$newdn
);
}
function
browseForeignKeys
(
$mode
,
$param1
=
NULL
,
$param2
=
NULL
)
{
if
(
$mode
==
'handle'
)
{
$olddn
=
$param1
;
$newdn
=
$param2
;
$classes
=
array
(
get_class
(
$this
));
}
elseif
(
$mode
==
'references'
)
{
$classes
=
array_keys
(
$this
->
parent
->
by_object
);
}
// We group by objetType concerned
$infos
=
pluglist
::
pluginInfos
(
get_class
(
$this
));
$foreignRefs
=
array
();
foreach
(
$infos
[
'plForeignRefs'
]
as
$field
=>
$refs
)
{
if
(
$newdn
!==
NULL
)
{
if
(
$field
!=
'dn'
)
{
continue
;
}
}
else
{
if
(
$field
!=
'dn'
)
{
if
(
!
$this
->
attributesAccess
[
$field
]
->
hasChanged
())
{
continue
;
foreach
(
$classes
as
$tabclass
)
{
$infos
=
pluglist
::
pluginInfos
(
$tabclass
);
foreach
(
$infos
[
'plForeignRefs'
]
as
$field
=>
$refs
)
{
if
(
$mode
==
'handle'
)
{
if
(
$newdn
!==
NULL
)
{
if
(
$field
!=
'dn'
)
{
continue
;
}
}
else
{
if
(
$field
!=
'dn'
)
{
if
(
!
$this
->
attributesAccess
[
$field
]
->
hasChanged
())
{
continue
;
}
}
}
}
}
foreach
(
$refs
as
$ref
)
{
$class
=
$ref
[
0
];
$ofield
=
$ref
[
1
];
$cinfos
=
pluglist
::
pluginInfos
(
$class
);
foreach
(
$cinfos
[
'plObjectType'
]
as
$key
=>
$objectType
)
{
if
(
!
is_numeric
(
$key
))
{
$objectType
=
$key
;
foreach
(
$refs
as
$ref
)
{
$class
=
$ref
[
0
];
$ofield
=
$ref
[
1
];
$filter
=
$ref
[
2
];
$cinfos
=
pluglist
::
pluginInfos
(
$class
);
foreach
(
$cinfos
[
'plObjectType'
]
as
$key
=>
$objectType
)
{
if
(
!
is_numeric
(
$key
))
{
$objectType
=
$key
;
}
if
(
$mode
==
'handle'
)
{
if
(
$field
==
'dn'
)
{
$oldvalue
=
$olddn
;
$newvalue
=
$newdn
;
}
elseif
((
$olddn
!==
NULL
)
&&
(
$newdn
===
NULL
))
{
$oldvalue
=
$this
->
attributesAccess
[
$field
]
->
getInitialValue
();
$newvalue
=
NULL
;
}
else
{
$oldvalue
=
$this
->
attributesAccess
[
$field
]
->
getInitialValue
();
$newvalue
=
$this
->
attributesAccess
[
$field
]
->
getValue
();
}
$foreignRefs
[
$objectType
][
'refs'
][
$class
][
$ofield
]
=
array
(
'field'
=>
$field
,
'oldvalue'
=>
$oldvalue
,
'newvalue'
=>
$newvalue
,
);
$filter
=
plugin
::
tpl_parse_string
(
$filter
,
array
(
'oldvalue'
=>
$oldvalue
,
'newvalue'
=>
$newvalue
));
}
elseif
(
$mode
==
'references'
)
{
$foreignRefs
[
$objectType
][
'refs'
][
$class
][
'name'
]
=
$cinfos
[
'plShortName'
];
$foreignRefs
[
$objectType
][
'refs'
][
$class
][
'fields'
][
$ofield
]
=
array
(
'tab'
=>
$this
->
parent
->
by_name
[
$tabclass
],
'field'
=>
$field
);
$filter
=
plugin
::
tpl_parse_string
(
$filter
,
array
(
'oldvalue'
=>
$this
->
parent
->
by_object
[
$tabclass
]
->
$field
));
}
if
(
!
preg_match
(
'/^\(.*\)$/'
,
$filter
))
{
$filter
=
'('
.
$filter
.
')'
;
}
$foreignRefs
[
$objectType
][
'filters'
][
$filter
]
=
$filter
;
}
$foreignRefs
[
$objectType
][
$class
][
$ofield
]
=
$field
;
}
}
}
$refs
=
array
();
// For each concerned objectType
foreach
(
$foreignRefs
as
$objectType
=>
$tabRefs
)
{
// Compute filter
$filters
=
array_values
(
$tabRefs
[
'filters'
]);
$filter
=
'(&'
.
join
(
$filters
)
.
')'
;
// Search objects
$objects
=
objects
::
ls
(
$objectType
,
array
(
'dn'
=>
'raw'
));
$objects
=
objects
::
ls
(
$objectType
,
array
(
'dn'
=>
'raw'
)
,
NULL
,
$filter
);
// For each object of this type
foreach
(
array_keys
(
$objects
)
as
$dn
)
{
// Build the object
$tabobject
=
objects
::
open
(
$dn
,
$objectType
);
// For each tab concerned
f
oreach
(
$
tab
Refs
as
$tab
=>
$fieldRefs
)
{
// If the tab is activated on this object
if
(
isset
(
$tabobject
->
by_object
[
$tab
]))
{
// For each field
f
oreach
(
$
field
Refs
as
$ofield
=>
$field
)
{
// call plugin::foreignKeyUpdate(ldapname, oldvalue, newvalue) on the object
if
(
$field
==
'dn'
)
{
if
(
$mode
==
'handle'
)
{
// Build the object
$tabobject
=
objects
::
open
(
$dn
,
$objectType
);
// F
or
each tab
concerned
foreach
(
$tabRefs
[
'refs'
]
as
$tab
=>
$fieldRefs
)
{
// If the tab is activated on this object
if
(
isset
(
$tabobject
->
by_object
[
$tab
]))
{
// F
or
each field
foreach
(
$fieldRefs
as
$ofield
=>
$field
)
{
// call plugin::foreignKeyUpdate(ldapname, oldvalue, newvalue) on the object
$tabobject
->
by_object
[
$tab
]
->
foreignKeyUpdate
(
$ofield
,
$
olddn
,
$
newdn
,
$field
$
field
[
'oldvalue'
]
,
$
field
[
'newvalue'
]
,
$field
[
'field'
]
);
}
elseif
((
$olddn
!==
NULL
)
&&
(
$newdn
===
NULL
))
{
$tabobject
->
by_object
[
$tab
]
->
foreignKeyUpdate
(
$ofield
,
$this
->
attributesAccess
[
$field
]
->
getInitialValue
(),
NULL
,
$field
}
$tabobject
->
by_object
[
$tab
]
->
save_object
();
$tabobject
->
by_object
[
$tab
]
->
save
();
}
}
}
elseif
(
$mode
==
'references'
)
{
// For each tab concerned
foreach
(
$tabRefs
[
'refs'
]
as
$tab
=>
$tab_infos
)
{
// For each field
foreach
(
$tab_infos
[
'fields'
]
as
$ofield
=>
$field
)
{
if
(
!
isset
(
$refs
[
$dn
]))
{
$refs
[
$dn
]
=
array
(
'link'
=>
''
,
'tabs'
=>
array
(),
);
}
else
{
$tabobject
->
by_object
[
$tab
]
->
foreignKeyUpdate
(
$ofield
,
$this
->
attributesAccess
[
$field
]
->
getInitialValue
(),
$this
->
attributesAccess
[
$field
]
->
getValue
(),
$field
try
{
$refs
[
$dn
][
'link'
]
=
objects
::
link
(
$dn
,
$objectType
);
}
catch
(
Exception
$e
)
{
$refs
[
$dn
][
'link'
]
=
$dn
;
}
}
if
(
!
isset
(
$refs
[
$dn
][
'tabs'
][
$tab
]))
{
$refs
[
$dn
][
'tabs'
][
$tab
]
=
array
(
'link'
=>
''
,
'fields'
=>
array
(),
);
try
{
$refs
[
$dn
][
'tabs'
][
$tab
][
'link'
]
=
objects
::
link
(
$dn
,
$objectType
,
"tab_
$tab
"
,
sprintf
(
_
(
'Tab "%s"'
),
$tab_infos
[
'name'
]));
}
catch
(
Exception
$e
)
{
$refs
[
$dn
][
'tabs'
][
$tab
][
'link'
]
=
$tab
;
}
}
$refs
[
$dn
][
'tabs'
][
$tab
][
'fields'
][
$ofield
]
=
$field
;
}
$tabobject
->
by_object
[
$tab
]
->
save_object
();
$tabobject
->
by_object
[
$tab
]
->
save
();
}
}
}
}
if
(
$mode
==
'references'
)
{
return
$refs
;
}
}
function
foreignKeyUpdate
(
$field
,
$oldvalue
,
$newvalue
,
$source
)
{
$this
->
attributesAccess
[
$field
]
->
foreignKeyUpdate
(
$oldvalue
,
$newvalue
,
$source
);
}
function
foreignKeyCheck
(
$field
,
$value
,
$source
)
{
return
$this
->
attributesAccess
[
$field
]
->
foreignKeyCheck
(
$value
,
$source
);
}
}
?>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment