Skip to content

Patch for issue #49 #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/PageRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,32 @@ protected function getTemplateChoice() {
else
$this->drawTemplateChoice();

# If mode is modification, use a DefaultForObjectClass template if exaclty 1 matches. Propose the template choice otherwise.
} elseif (($this->getMode() == 'modification') && (! isset($_REQUEST['template']))) {
if (DEBUGTMP) printf('<font size=-2>%s:<u>%s</u></font><br />',__METHOD__,'DEFAULTFOROBJECTCLASS template if only 1 template matches.');

$dn = $this->getModeContainer();
$server = $this->getServer();
$dnojcs = $server->getDNAttrValue($dn,'objectClass');
$matchingtmplIDs = array();
$unmatchingtmplIDs = array();
$tpldefojc = array();
foreach ($templates->getTemplates($this->getMode(),$this->getModeContainer(),true) as $tpl) {
$tpldefojc = $tpl->getDefaultForObjectClass();
if (array_intersect($tpldefojc,$dnojcs)) {
array_push($matchingtmplIDs,$tpl->getID());
} else {
array_push($unmatchingtmplIDs,$tpl->getID());
}
}
if (count($matchingtmplIDs) == 0) # No matching DefaultForObjectClass found,
return 'none'; # so we use the default template.
elseif (count($matchingtmplIDs) == 1) # Exactly 1 matching DefaultForObjectClass found,
return $matchingtmplIDs[0]; # so we use it.
elseif (count($unmatchingtmplIDs) == 0) # No template found at all,
return 'none'; # so we use the default template.
else # Multiple templates found,
$this->drawTemplateChoice(); # so propose the template choice.
} else {
if (DEBUGTMP) printf('<font size=-2>%s:<u>%s</u></font><br />',__METHOD__,'SELECT a template to use.');

Expand Down
37 changes: 37 additions & 0 deletions lib/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Template extends xmlTemplate {
private $invalid_reason;
# The TEMPLATE structural objectclasses
protected $structural_oclass = array();
# The objectclasses for which this template is the default
protected $defaultfor_oclass = array();
protected $description = '';
# Is this a read-only template (only valid in modification templates)
private $readonly = false;
Expand Down Expand Up @@ -124,6 +126,31 @@ protected function storeTemplate($xmldata) {

break;

# Record our defaultFor object Classes from the Template.
case ('defaultforobjectclasses'):
if (DEBUG_ENABLED)
debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key);

if (isset($xmldata['template'][$xml_key]['defaultforobjectclass']))
if (is_array($xmldata['template'][$xml_key]['defaultforobjectclass'])) {
foreach ($xmldata['template'][$xml_key]['defaultforobjectclass'] as $index => $details) {

# If we havent recorded this objectclass already, do so now.
if (! in_array($details,$this->defaultfor_oclass))
array_push($this->defaultfor_oclass,$details);
}

} else {
# XML files with only 1 objectClass dont have a numeric index.
$soc = $xmldata['template'][$xml_key]['defaultforobjectclass'];

# If we havent recorded this objectclass already, do so now.
if (! in_array($soc,$this->defaultfor_oclass))
array_push($this->defaultfor_oclass,$soc);
}

break;

# Build our attribute list from the DN and Template.
case ('attributes'):
if (DEBUG_ENABLED)
Expand Down Expand Up @@ -179,6 +206,7 @@ protected function storeTemplate($xmldata) {

if ($xml_key == 'invalid' && $xml_value)
$this->setInvalid(_('Disabled by XML configuration'),true);

}
}

Expand Down Expand Up @@ -924,6 +952,15 @@ public function setInvisible() {
$this->visible = false;
}

/**
* Get the objectclasses for which this template is the default
*
* @return array The objectclasses
*/
public function getDefaultForObjectClass() {
return $this->defaultfor_oclass;
}

public function getRegExp() {
if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->regexp);
Expand Down