draw('Title', $entry); $this->draw('Subtitle', $entry); echo "\n"; # Menu $this->draw('Menu', $entry); } protected function drawEntryTitle($entry) {} protected function drawEntrySubtitle($entry) {} protected function drawEntryMenu($entry) {} protected function drawEntryJavascript($entry) { printf("\n\n",__METHOD__); if (isset($_SESSION[APPCONFIG])) { echo "\n"; echo ''."\n"; echo ''."\n"; echo "\n"; } echo ''."\n"; echo ''."\n"; echo ''."\n"; echo "\n"; echo ''."\n"; echo ''."\n"; for ($i = 0; $i < count($this->shown_attributes); $i++) { $this->draw('Javascript', $this->shown_attributes[$i]); } echo ''."\n"; printf("\n\n",__METHOD__); } /********************************/ /* Paint a DefaultCreatingEntry */ /********************************/ public function visitDefaultCreatingEntryStart($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); # Init $this->visit('Entry::Start', $entry); # Check $container = $entry->getContainer(); $container_ok = true; $objectclasses_ok = true; if ($this->step != 1) { if (!$container || !$this->getLDAPServer()->dnExists($container)) { $container_ok = false; $this->step = 1; } if (!$entry->getAttributes()) { $objectclasses_ok = false; $this->step = 1; } } # Header $this->draw('Header', $entry); # Errors if (!$container_ok) { error(sprintf(_('The container you specified (%s) does not exist.'),htmlspecialchars($container)),'error'); echo '
'; } if (!$objectclasses_ok) { error(_('You did not select any objectClasses for this object.'),'error'); echo '
'; } } public function visitDefaultCreatingEntryEnd($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); $this->draw('StepTitle', $entry, $this->step); $this->draw('StepFormStart', $entry, $this->step); $this->draw('StepForm', $entry, $this->step); $this->draw('StepFormEnd', $entry, $this->step); } protected function initDefaultCreatingEntryVisit($entry) { parent::initDefaultCreatingEntryVisit($entry); $this->step = 1; $step = get_request('step','REQUEST'); if ($step) $this->step = $step; } protected function drawDefaultCreatingEntryTitle($entry) { printf('

%s

',_('Create Object')); } protected function drawDefaultCreatingEntrySubtitle($entry) { printf('

%s%s %s

', _('Server'),_(':'),$this->getLDAPServer()->name); } protected function drawDefaultCreatingEntryStepTitle($entry, $step) { if ($step == 1) { echo '

'; printf(_('Step %s of %s'), '1', '2'); echo _(':'); echo ' '; echo _('Container and ObjectClass(es)'); echo '

'; } else { echo '

'; printf(_('Step %s of %s'), '2', '2'); echo _(':'); echo ' '; echo _('Specify attributes and values'); echo '

'; } } public function drawDefaultCreatingEntryStepFormStart($entry, $step) { if ($step == 1) { echo '
'; } else { echo ''; } } public function drawDefaultCreatingEntryStepForm($entry, $step) { $container = $entry->getContainer(); if ($step == 1) { printf('', $this->index); printf('', $step + 1); echo ''; $this->draw('ContainerChooser', $entry, $container); $this->draw('ObjectClassChooser', $entry); $this->draw('StepFormSubmitButton', $entry, $step); echo '
'; } else { printf('', htmlspecialchars($container)); printf('', $this->index); printf('', $step + 1); echo ''; $this->draw('RdnChooser', $entry); $this->draw('ShownAttributes', $entry); $this->draw('StepFormSubmitButton', $entry, $step); echo '
'; $this->draw('HiddenAttributes', $entry); } } public function drawDefaultCreatingEntryStepFormSubmitButton($entry, $step) { if ($step == 1) { echo ' '; printf('', _('Proceed >>')); echo ''; } else { echo '
'; printf('', _('Create Object')); echo '
'; } } public function drawDefaultCreatingEntryStepFormEnd($entry, $step) { echo '
'; # Javascript $this->draw('Javascript', $entry); } protected function drawDefaultCreatingEntryContainerChooser($entry, $default_container) { echo ''; printf('%s', _('Container')); printf('', htmlspecialchars($default_container)); draw_chooser_link('entry_form.container'); echo ''; echo ''; } protected function drawDefaultCreatingEntryObjectClassChooser($entry) { $oclasses = $this->getLDAPServer()->SchemaObjectClasses(); if (!$oclasses) $oclasses = array(); elseif (!is_array($oclasses)) $oclasses = array($oclasses); echo ''; printf('%s', _('ObjectClasses')); echo ''; echo ''; echo ''; if ($_SESSION[APPCONFIG]->GetValue('appearance', 'show_hints')) { printf(' Hint',IMGDIR); echo _('Hint: You must choose exactly one structural objectClass (shown in bold above)'); echo '
'; } } protected function drawDefaultCreatingEntryRdnChooser($entry) { $attrs = $entry->getAttributes(); $rdn_attr = $entry->getRdnAttribute(); printf('%s', 'RDN'); echo ''; } protected function drawDefaultCreatingEntryShownAttributes($entry) { $attrs = array(); # Put required attributes first foreach ($this->shown_attributes as $sa) if ($sa->isRequired()) $attrs[] = $sa; foreach ($this->shown_attributes as $sa) if (!$sa->isRequired()) $attrs[] = $sa; $has_required_attrs = false; $has_optional_attrs = false; foreach ($attrs as $attr) { if ($attr->isRequired()) { if (!$has_required_attrs) { printf('%s', _('Required Attributes')); $has_required_attrs = true; } } else { if (!$has_optional_attrs) { if (!$has_required_attrs) { printf('%s', _('Required Attributes')); printf('
(%s)
', _('none')); } printf('%s', _('Optional Attributes')); $has_optional_attrs = true; } } $this->draw('',$attr,$entry); echo "\n"; } if (!$has_optional_attrs) { printf('%s', _('Optional Attributes')); printf('
(%s)
', _('none')); } } protected function drawDefaultCreatingEntryHiddenAttributes($entry) { foreach ($this->hidden_attributes as $attr) { $this->draw('',$attr,$entry); echo "\n"; } } protected function drawDefaultCreatingEntryJavascript($entry) { $this->draw('Entry::Javascript', $entry); } /*******************************/ /* Paint a DefaultEditingEntry */ /*******************************/ public function visitDefaultEditingEntryStart($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); # Init $this->visit('Entry::Start', $entry); # Header $this->draw('Header', $entry); # Form start if (! $entry->isReadOnly()) { echo '
'; printf('',$this->index); printf('',htmlspecialchars($entry->getDn())); } echo '
'."\n\n"; echo ''; } public function visitDefaultEditingEntryEnd($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); # Draw internal attributes if (get_request('show_internal_attrs','REQUEST')) { $this->draw('InternalAttributes', $entry); echo "\n\n"; } # Draw visible attributes $this->draw('ShownAttributes', $entry); # Form end if (! $entry->isReadOnly()) { $this->draw('FormSubmitButton', $entry); echo '
'; # Draw hidden attributes $this->draw('HiddenAttributes', $entry); printf('
'); } else { printf(''); } # Javascript $this->draw('Javascript', $entry); } protected function initDefaultEditingEntryVisit($entry) { parent::initDefaultEditingEntryVisit($entry); $this->url_base = sprintf('cmd.php?server_id=%s&dn=%s', $this->index, rawurlencode($entry->getDn())); $this->hint_layout = sprintf('%s%%s',IMGDIR,_('Hint')); $this->action_layout = '%s%s'; } protected function drawDefaultEditingEntryTitle($entry) { $dn = $entry->getDn(); $rdn = get_rdn($dn); printf('

%s

',htmlspecialchars($rdn)); } protected function drawDefaultEditingEntrySubtitle($entry) { echo '

'; echo _('Server'); echo _(':'); echo ' '; echo $this->getLDAPServer()->name; echo '     '; echo _('Distinguished Name'); echo _(':'); echo ' '; echo htmlspecialchars($entry->getDn()); echo ''; echo '
'; echo _('Template'); echo _(':'); echo ' '; echo htmlspecialchars($entry->getTemplateTitle()); echo ''; if ($entry->getTemplateName()) { echo ' ('; echo htmlspecialchars($entry->getTemplateName()); echo ')'; } echo '

'; } protected function drawDefaultEditingEntryMenu($entry) { $i = 0; $item = ''; echo ''; echo ''; $menuitem_number = 0; while (($item = $this->get('MenuItem', $entry, $i)) !== false) { if ($item) { $endofrow = 0; $it = ''; // menu item $ms = ''; // item message if (is_array($item)) { if (count($item) > 0) { $it = $item[0]; if (count($item) > 1) $ms = $item[1]; } } else { $it = $item; } if ($it) { $menuitem_number++; echo $it; if ($ms) { if (($menuitem_number % 2) == 1) { $menuitem_number++; echo ''; $endofrow = 0; } if ($endofrow) print $ms; else echo "$ms"; echo ""; $endofrow = 1; } else { if ($menuitem_number > 1 && ($menuitem_number % 2) == 0) { echo ''; $endofrow = 1; } } } elseif ($ms) { if (($menuitem_number % 2) == 1) { $menuitem_number++; echo ''; $endofrow = 0; } if ($endofrow) print $ms; else echo "$ms"; echo ""; $endofrow = 1; } } $i++; } if (($menuitem_number % 2) == 1) echo ''; else echo ''; echo ''; echo ''; } protected function getDefaultEditingEntryMenuItem($entry, $i) { $config = $_SESSION[APPCONFIG]; switch ($i) { case IdEntryRefreshMenuItem : if ($config->isCommandAvailable('entry_refresh')) return $this->get('RefreshMenuItem', $entry); else return ''; case IdEntryExportBaseMenuItem : if ($config->isCommandAvailable('export')) return $this->get('ExportBaseMenuItem', $entry); else return ''; case IdEntryMoveMenuItem : if (!$entry->isReadOnly() && $config->isCommandAvailable('entry_move')) return $this->get('MoveMenuItem', $entry); else return ''; case IdEntryInternalAttributesMenuItem : if ($config->isCommandAvailable('entry_internal_attributes_show')) return $this->get('InternalAttributesMenuItem', $entry); else return ''; case IdEntryDeleteMenuItem : if (!$entry->isReadOnly() && $config->isCommandAvailable('entry_delete', 'simple_delete')) return $this->get('DeleteMenuItem', $entry); else return ''; case IdEntryRenameMenuItem : if (!$entry->isReadOnly() && $config->isCommandAvailable('entry_rename')) { foreach ($entry->getRdnAttributeName() as $rdnAttr) { $rdnAttr = $entry->getAttribute($rdnAttr); if ($rdnAttr && $rdnAttr->isVisible() && !$rdnAttr->isReadOnly()) return $this->get('RenameMenuItem', $entry); } } return ''; case IdEntryDeleteAttributeMessage : if ($config->GetValue('appearance', 'show_hints') && $config->isCommandAvailable('attribute_delete')) return array('', $this->get('DeleteAttributeMessage', $entry)); else return ''; case IdEntryCompareMenuItem : if (!$entry->isReadOnly() && $config->isCommandAvailable('entry_compare')) return $this->get('CompareMenuItem', $entry); else return ''; case IdEntryCreateMenuItem : if (!$entry->isReadOnly() && !$entry->isLeaf() && $config->isCommandAvailable('entry_create')) return $this->get('CreateMenuItem', $entry); else return ''; case IdEntryAddAttributeMenuItem : if (!$entry->isReadOnly() && $config->isCommandAvailable('attribute_add')) return $this->get('AddAttributeMenuItem', $entry); else return ''; case IdEntryShowChildrenMenuItem : case IdEntryExportSubMenuItem : static $children_count = false; static $more_children = false; if ($children_count === false) { # Visible children in the tree $children_count = $entry->getChildrenNumber(); # Is there filtered children ? $more_children = $entry->isSizeLimited(); if (!$more_children) { # All children in ldap $all_children = $this->getLDAPServer()->getContainerContents( $entry->getDn(), $children_count + 1, '(objectClass=*)', $config->GetValue('deref','view')); $more_children = (count($all_children) > $children_count); } } if ($children_count > 0 || $more_children) { if ($children_count <= 0) $children_count = ''; if ($more_children) $children_count .= '+'; if ($i == IdEntryShowChildrenMenuItem) { return $this->get('ShowChildrenMenuItem', $entry, $children_count); } elseif ($i == IdEntryExportSubMenuItem && $config->isCommandAvailable('export')) { return $this->get('ExportSubMenuItem', $entry); } else { return ''; } } else { return ''; } case IdEntryViewSchemaMessage : if ($config->GetValue('appearance', 'show_hints') && $config->isCommandAvailable('schema')) return array('', $this->get('ViewSchemaMessage', $entry)); else return ''; case IdEntryReadOnlyMessage : if ($entry->isReadOnly()) return array('', $this->get('ReadOnlyMessage', $entry)); else return ''; case IdEntryModifiedAttributesMessage : $modified_attrs = array(); foreach ($entry->getAttributes() as $attr) { if ($attr->hasBeenModified()) $modified_attrs[] = $attr->getFriendlyName(); } if ($modified_attrs) { return array('', $this->get('ModifiedAttributesMessage', $entry, $modified_attrs)); } else return ''; default : return false; } } protected function getDefaultEditingEntryRefreshMenuItem($entry) { $href = $this->url_base.'&cmd=template_engine&junk='.random_junk(); return sprintf($this->action_layout,IMGDIR,'refresh.png',_('Refresh'), htmlspecialchars($href),_('Refresh this entry'),_('Refresh')); } protected function getDefaultEditingEntryExportBaseMenuItem($entry) { $href = $this->url_base.'&cmd=export_form&scope=base'; return sprintf($this->action_layout,IMGDIR,'save.png',_('Save'), htmlspecialchars($href),_('Save a dump of this object'),_('Export')); } protected function getDefaultEditingEntryMoveMenuItem($entry) { $href = $this->url_base.'&cmd=copy_form'; return sprintf($this->action_layout,IMGDIR,'cut.png',_('Cut'),htmlspecialchars($href), _('Copy this object to another location,a new DN, or another server'), _('Copy or move this entry')); } protected function getDefaultEditingEntryInternalAttributesMenuItem($entry) { if (get_request('show_internal_attrs','REQUEST')) { $href = $this->url_base.'&cmd=template_engine&junk='.random_junk(); return sprintf($this->action_layout,IMGDIR,'tools-no.png',_('Hide'), htmlspecialchars($href),'',_('Hide internal attributes')); } else { $href = $this->url_base.'&cmd=template_engine&show_internal_attrs=true'; return sprintf($this->action_layout,IMGDIR,'tools.png',_('Show'), htmlspecialchars($href),'',_('Show internal attributes')); } } protected function getDefaultEditingEntryDeleteMenuItem($entry) { $href = $this->url_base.'&cmd=delete_form'; return sprintf($this->action_layout,IMGDIR,'trash.png',_('Trash'),htmlspecialchars($href), _('You will be prompted to confirm this decision'),_('Delete this entry')); } protected function getDefaultEditingEntryRenameMenuItem($entry) { $href = $this->url_base.'&cmd=rename_form'; return sprintf($this->action_layout,IMGDIR,'rename.png',_('Rename'),htmlspecialchars($href),'',_('Rename')); } protected function getDefaultEditingEntryCompareMenuItem($entry) { $href = $this->url_base.'&cmd=compare_form'; return sprintf($this->action_layout,IMGDIR,'compare.png',_('Compare'), htmlspecialchars($href),'',_('Compare with another entry')); } protected function getDefaultEditingEntryCreateMenuItem($entry) { $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s', $this->index,rawurlencode($entry->getDn())); return sprintf($this->action_layout,IMGDIR,'star.png',_('Create'),htmlspecialchars($href),'',_('Create a child entry')); } protected function getDefaultEditingEntryAddAttributeMenuItem($entry) { $href = $this->url_base.'&cmd=add_attr_form'; return sprintf($this->action_layout,IMGDIR,'add.png',_('Add'),htmlspecialchars($href),'',_('Add new attribute')); } protected function getDefaultEditingEntryShowChildrenMenuItem($entry,$children_count) { $href = sprintf('cmd.php?cmd=search&server_id=%s&search=true&filter=%s&base_dn=%s&form=advanced&scope=one', $this->index,rawurlencode('objectClass=*'),rawurlencode($entry->getDn())); return sprintf($this->action_layout,IMGDIR,'children.png',_('Children'),htmlspecialchars($href),'', ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'),$children_count)); } protected function getDefaultEditingEntryExportSubMenuItem($entry) { $href = sprintf('%s&cmd=export_form&scope=%s',$this->url_base,'sub'); return sprintf($this->action_layout,IMGDIR,'save.png',_('Save'),htmlspecialchars($href), _('Save a dump of this object and all of its children'),_('Export subtree')); } protected function getDefaultEditingEntryDeleteAttributeMessage($entry) { if ($_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete_value') && ! $entry->isReadOnly()) return sprintf($this->hint_layout,_('Hint: To delete an attribute, empty the text field and click save.')); else return ''; } protected function getDefaultEditingEntryViewSchemaMessage($entry) { return sprintf($this->hint_layout,_('Hint: To view the schema for an attribute, click the attribute name.')); } protected function getDefaultEditingEntryReadOnlyMessage($entry) { return sprintf($this->hint_layout,_('Viewing entry in read-only mode.')); } protected function getDefaultEditingEntryModifiedAttributesMessage($entry,&$modified_attributes) { return sprintf($this->hint_layout, (count($modified_attributes) == 1) ? sprintf(_('An attribute (%s) was modified and is highlighted below.'),implode('',$modified_attributes)) : sprintf(_('Some attributes (%s) were modified and are highlighted below.'),implode(', ',$modified_attributes))); } protected function drawDefaultEditingEntryInternalAttributes($entry) { $counter = 0; foreach ($this->internal_attributes as $attr) { $this->draw('',$attr,$entry); $counter++; echo "\n"; } if ($counter == 0) { echo '('; echo _('No internal attributes'); echo ')'; } } protected function drawDefaultEditingEntryShownAttributes($entry) { foreach ($this->shown_attributes as $attr) { $this->draw('',$attr,$entry); echo "\n"; } } protected function drawDefaultEditingEntryHiddenAttributes($entry) { foreach ($this->hidden_attributes as $attr) { $this->draw('',$attr,$entry); echo "\n"; } } protected function drawDefaultEditingEntryFormSubmitButton($entry) { echo '
'; } protected function drawDefaultEditingEntryJavascript($entry) { $this->draw('Entry::Javascript', $entry); } /*********************************/ /* Paint a TemplateCreatingEntry */ /*********************************/ public function visitTemplateCreatingEntryStart($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); $template = get_request('template','REQUEST'); $step = get_request('step','REQUEST'); if ($template) { if ($template == 'none') { $this->visit('DefaultCreatingEntry::Start', $entry); return; } else { $entry->setSelectedTemplateName($template); } } elseif ($step && $step > 0) { $this->visit('DefaultCreatingEntry::Start', $entry); return; } if ($entry->getSelectedTemplateName()) { # if we already choose an creation template, use it to display the entry $this->visit('DefaultCreatingEntry::Start', $entry); } elseif ($entry->getTemplatesCount() <= 0) { # if no template is available for this entry, draws it # to the parent manner $this->visit('DefaultCreatingEntry::Start', $entry); } elseif (($entry->getTemplatesCount() == 1) && !$entry->hasDefaultTemplate()) { $templates = &$entry->getTemplates(); $template_names = array_keys($templates); $entry->setSelectedTemplateName($template_names[0]); $this->visit('DefaultCreatingEntry::Start', $entry); } else { $this->visit_attributes = false; # propose the template choice $this->draw('TemplateChoice', $entry); } } public function visitTemplateCreatingEntryEnd($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); if ($this->visit_attributes) { foreach ($this->shown_attributes as $attr) { $page = 1; if ($attr->hasProperty('page')) { $page = $attr->getProperty('page'); } else { $attr->setProperty('page', 1); } if ($page && $page > $this->laststep) { $this->laststep = $page; } } $this->visit('DefaultCreatingEntry::End', $entry); $entry->setSelectedTemplateName(''); } } protected function initTemplateCreatingEntryVisit($entry) { $this->init('DefaultCreatingEntry::Visit', $entry); $this->laststep = 1; } protected function drawTemplateCreatingEntryRdnChooser($entry) { $rdn_attr = $entry->getRdnAttribute(); if (!$rdn_attr) { $this->draw('DefaultCreatingEntry::RdnChooser', $entry); } else { printf('', htmlspecialchars($rdn_attr->getName())); } } protected function drawTemplateCreatingEntryStepTitle($entry, $step) { if (!$entry->getSelectedTemplateName()) { $this->draw('DefaultCreatingEntry::StepTitle', $entry, $step); } else if ($entry->hasProperty('description')) { echo '

'; echo $entry->getProperty('description'); echo ' '; echo _('('); printf(_('step %s of %s'), $step, $this->laststep); echo _(')'); echo '

'; } } public function drawTemplateCreatingEntryStepFormStart($entry, $step) { if ($entry->getSelectedTemplateName()) { if ($step < $this->laststep) { echo '
'; } else { echo ''; printf('', $entry->hasProperty('action') ? rawurlencode($entry->getProperty('action')) : 'create'); } } else { $this->draw('DefaultCreatingEntry::StepFormStart', $entry, $step); } } public function drawTemplateCreatingEntryStepForm($entry, $step) { if (!$entry->getSelectedTemplateName()) { $this->draw('DefaultCreatingEntry::StepForm', $entry, $step); return; } $container = $entry->getContainer(); printf('', htmlspecialchars($container)); printf('', $this->index); printf('', $entry->getSelectedTemplateName()); printf('', $step + 1); echo ''; $this->draw('RdnChooser', $entry); # Draw attributes $this->draw('ShownAttributes', $entry); $this->draw('StepFormSubmitButton', $entry, $step); echo '
'; $this->draw('HiddenAttributes', $entry); } protected function drawTemplateCreatingEntryStepFormSubmitButton($entry, $step) { if ($step < $this->laststep) $this->draw('DefaultCreatingEntry::StepFormSubmitButton', $entry, 1); else $this->draw('DefaultCreatingEntry::StepFormSubmitButton', $entry, 2); } protected function drawTemplateCreatingEntryTemplateChoice($entry) { $this->draw('Title', $entry); $this->draw('Subtitle', $entry); echo "\n"; printf('

%s

',_('Select a template for the creation process')); $href = sprintf('cmd.php?%s', array_to_query_string($_GET,array('meth'),false)); echo ''; foreach ($_POST as $p => $v) { echo ""; } echo ''; $server_menu_html = server_select_list($this->index, true); printf('', _('Server'), _(':'), $server_menu_html); echo ''; printf('', _('Templates'), _(':')); echo ''; echo '
%s%s%s
%s%s'; echo ''; $i = -1; $templates = &$entry->getTemplates(); $nb_templates = count($templates); if ($entry->hasDefaultTemplate()) $nb_templates++; foreach ($templates as $template_name => $template_attrs) { $i++; # If the template doesnt have a title, we'll use the desc field. $template_attrs['desc'] = isset($template_attrs['title']) ? $template_attrs['title'] : $template_attrs['desc']; # Balance the columns properly if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { echo '
'; } echo ''; if (isset($template_attrs['invalid']) && $template_attrs['invalid']) { printf('',IMGDIR); } else { printf('', htmlspecialchars($template_name), htmlspecialchars($template_name)); } printf('', htmlspecialchars($template_name), $template_attrs['icon']); printf(''; } # Default template if ($entry->hasDefaultTemplate()) { $i++; if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { echo '
Error
'; } echo ''; echo ''; printf('',IMGDIR); printf('',_('Default')); } echo '
'; echo '
'; echo '
'; } protected function drawTemplateCreatingEntryShownAttributes($entry) { if (!$entry->getSelectedTemplateName()) { $this->draw('DefaultCreatingEntry::ShownAttributes', $entry); return; } foreach ($this->shown_attributes as $attr) { $page = $attr->getProperty('page'); if ($page == $this->step) { $this->draw('',$attr,$entry); echo "\n"; } else { # The displayed attributes are the visible attributes in shown_attributes list $attr->hide(); $this->hidden_attributes[] = $attr; } } } protected function drawTemplateCreatingEntryHiddenAttributes($entry) { if (!$entry->getSelectedTemplateName()) { $this->draw('DefaultCreatingEntry::HiddenAttributes', $entry); return; } foreach ($this->hidden_attributes as $attr) { $this->draw('',$attr,$entry); echo "\n"; } } protected function drawTemplateCreatingEntryJavascript($entry) { printf("\n\n",__METHOD__); $this->draw('DefaultCreatingEntry::Javascript', $entry); $templates = new Templates($this->index); foreach ($entry->getAttributes() as $attribute) { if ($attribute->hasProperty('onchange')) { $onchange = $attribute->getProperty('onchange'); if (is_array($onchange)) { foreach ($onchange as $value) $templates->OnChangeAdd($this->getLDAPServer(),$attribute->getName(),$value); } else { $templates->OnChangeAdd($this->getLDAPServer(),$attribute->getName(),$onchange); } } } $hash = $templates->getJsHash(); echo ''; printf("\n\n",__METHOD__); } /********************************/ /* Paint a TemplateEditingEntry */ /********************************/ public function visitTemplateEditingEntryStart($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); $template = get_request('template','REQUEST'); if ($template) { if ($template == 'none') { $this->visit('DefaultEditingEntry::Start', $entry); return; } else { $entry->setSelectedTemplateName($template); } } if ($entry->getSelectedTemplateName()) { # if we already choose an editing template, use it to display the entry $this->visit('DefaultEditingEntry::Start', $entry); } elseif ($entry->getTemplatesCount() <= 0) { # if no template is available for this entry, draws it # to the parent manner $this->visit('DefaultEditingEntry::Start', $entry); } elseif (($entry->getTemplatesCount() == 1) && !$entry->hasDefaultTemplate()) { $templates = &$entry->getTemplates(); $template_names = array_keys($templates); $entry->setSelectedTemplateName($template_names[0]); $this->visit('DefaultEditingEntry::Start', $entry); } else { $this->visit_attributes = false; # propose the template choice $this->draw('TemplateChoice', $entry); } } public function visitTemplateEditingEntryEnd($entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s)',1,__FILE__,__LINE__,__METHOD__,$entry->getDn()); if ($this->visit_attributes) { $this->visit('DefaultEditingEntry::End', $entry); $entry->setSelectedTemplateName(''); } } protected function drawTemplateEditingEntryTemplateChoice($entry) { $this->draw('Title', $entry); $this->draw('Subtitle', $entry); echo "\n"; printf('

%s

',_('Select a template to edit the entry')); $href = sprintf('cmd.php?%s', array_to_query_string($_GET,array('meth'),false)); echo '
'; foreach ($_POST as $p => $v) { echo ""; } echo ''; echo ''; printf('',_('Templates'), _(':')); echo ''; echo '
%s%s'; echo ''; $i = -1; $templates = &$entry->getTemplates(); $nb_templates = count($templates); if ($entry->hasDefaultTemplate()) $nb_templates++; foreach ($templates as $template_name => $template_attrs) { $i++; # If the template doesnt have a title, we'll use the desc field. $template_attrs['desc'] = isset($template_attrs['title']) ? $template_attrs['title'] : $template_attrs['desc']; # Balance the columns properly if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { echo '
'; } echo ''; printf('', htmlspecialchars($template_name), htmlspecialchars($template_name)); printf('', htmlspecialchars($template_name), $template_attrs['icon']); printf(''; } # Default template if ($entry->hasDefaultTemplate()) { $i++; if (($nb_templates % 2 == 0 && $i == intval($nb_templates / 2)) || ($nb_templates % 2 == 1 && $i == intval($nb_templates / 2) + 1)) { echo '
'; } echo ''; echo ''; printf('',IMGDIR); printf('',_('Default')); } echo '
'; echo '
'; echo '
'; } protected function drawTemplateEditingEntryShownAttributes($entry) { foreach ($this->shown_attributes as $attr) { // @todo if this->page == attr->page $this->draw('',$attr,$entry); echo "\n"; } } protected function drawTemplateEditingEntryHiddenAttributes($entry) { printf('', $entry->getSelectedTemplateName()); $this->draw('DefaultEditingEntry::HiddenAttributes', $entry); } protected function drawTemplateEditingEntryJavascript($entry) { printf("\n\n",__METHOD__); $this->draw('DefaultEditingEntry::Javascript', $entry); $templates = new Templates($this->index); foreach ($entry->getAttributes() as $attribute) { if ($attribute->hasProperty('onchange')) { $onchange = $attribute->getProperty('onchange'); if (is_array($onchange)) { foreach ($onchange as $value) $templates->OnChangeAdd($this->getLDAPServer(),$attribute->getName(),$value); } else { $templates->OnChangeAdd($this->getLDAPServer(),$attribute->getName(),$onchange); } } } $hash = $templates->getJsHash(); echo ''; printf("\n\n",__METHOD__); } /**************************/ /* Paint an Attribute */ /**************************/ protected function drawAttribute($attribute,$entry) { if ($attribute->isVisible()) $this->draw('Informations', $attribute); $this->draw('Values',$attribute,$entry); } protected function drawAttributeJavascript($attribute) { echo ''."\n"; } protected function drawAttributeFocusJavascript($attribute, $component) { $entry = $attribute->getEntry(); if ($entry) echo $this->get('AttributeFocusJavascript', $entry, $attribute, $component); } protected function drawAttributeBlurJavascript($attribute, $component) { $entry = $attribute->getEntry(); if ($entry) echo $this->get('AttributeBlurJavascript', $entry, $attribute, $component); } protected function drawAttributeValidateJavascript($attribute, $component, $silence, $var_valid) { if ($attribute->isRequired()) { echo 'var vals = getAttributeValues("new", "'.$attribute->getName().'"); if (vals.length <= 0) { '.$var_valid.' = false; alertError("'._('This attribute is required')._(':').' '.$attribute->getFriendlyName().'", '.$silence.'); }'; echo 'var comp = getAttributeComponents("new", "'.$attribute->getName().'"); for (var i = 0; i < comp.length; i++) { comp[i].style.backgroundColor = '.$var_valid.' ? "white" : \'#FFFFA0\'; comp[i].style.color = '.$var_valid.' ? "black" : \'#00005F\'; }'; } } protected function getEntryAttributeFocusJavascript($entry, $attribute, $component) { return ''; } protected function getEntryAttributeBlurJavascript($entry, $attribute, $component) { return ''; } protected function getDefaultCreatingEntryAttributeBlurJavascript($entry, $attribute, $component) { return "\n\t\t\t\t\t\t".'validate_'.$attribute->getName().'('.$component.', false);'."\n"; } protected function getTemplateCreatingEntryAttributeBlurJavascript($entry, $attribute, $component) { $j = 'fill('.$component.'.id, pla_getComponentValue('.$component.'));'; return $j; } protected function getDefaultEditingEntryAttributeBlurJavascript($entry, $attribute, $component) { return "\n\t\t\t\t\t\t".'validate_'.$attribute->getName().'('.$component.', false);'."\n"; } protected function getTemplateEditingEntryAttributeBlurJavascript($entry, $attribute, $component) { $j = 'fill('.$component.'.id, pla_getComponentValue('.$component.'));'; return $j; } protected function drawAttributeFillJavascript($attribute, $component_id, $component_value) { echo "\n\t\t\t\t\t\t".'validate_'.$attribute->getName().'(pla_getComponentById('.$component_id.'), false);'."\n"; } protected function drawAttributeInformations($attribute) { if (($this->context == ENTRY_WRITER_EDITING_CONTEXT) && $attribute->hasBeenModified()) echo ''; else echo ''; echo ''; $this->draw('Name', $attribute); echo ''; echo ''; # Setup the $attr_note, which will be displayed to the right of the attr name (if any) if ($_SESSION[APPCONFIG]->GetValue('appearance', 'show_attribute_notes')) { $this->draw('Notes', $attribute); } echo ''; echo ''; } protected function drawAttributeNotes($attribute) { $attr_note = ''; $alias_note = $this->get('AliasNote', $attribute); if ($alias_note) { if (trim($attr_note)) $attr_note .= ', '; $attr_note .= $alias_note; } $required_note = $this->get('RequiredNote', $attribute); if ($required_note) { if (trim($attr_note)) $attr_note .= ', '; $attr_note .= $required_note; } $rdn_note = $this->get('RdnNote', $attribute); if ($rdn_note) { if (trim($attr_note)) $attr_note .= ', '; $attr_note .= $rdn_note; } $hint_note = $this->get('HintNote',$attribute); if ($hint_note) { if (trim($attr_note)) $attr_note .= ', '; $attr_note .= $hint_note; } if ($attr_note) printf('%s', $attr_note); if ($attribute->isReadOnly() && $this->getLDAPServer()->isAttrReadOnly($attribute->getName())) { printf('(%s)', _('This attribute has been flagged as read only by the phpLDAPadmin administrator'), _('read only')); } } protected function drawAttributeValues($attribute,$entry) { if ($attribute->isVisible()) $this->draw('StartValueLine', $attribute); # draws values $value_count = $attribute->getValueCount(); $i = 0; for (; $i < $value_count; $i++) { $this->draw('Value',$attribute,$i,$entry); } if ($this->context == ENTRY_WRITER_CREATION_CONTEXT) { $blankvalue_count = $attribute->getMaxValueCount(); if ($blankvalue_count < 0) $blankvalue_count = 1; else $blankvalue_count -= $value_count; for ($j = 0; $j < $blankvalue_count; $j++) { $this->draw('BlankValue',$attribute,$i+$j,$entry); } } if ($attribute->isVisible()) { $this->draw('Menu', $attribute); $this->draw('EndValueLine', $attribute); } } protected function drawAttributeMenu($attribute) { $i = 0; $item = ''; while (($item = $this->get('MenuItem', $attribute, $i)) !== false) { if ($item) { echo '
'.$item.'
'; } $i++; } } protected function getAttributeMenuItem($attribute, $i) { if ($this->context != ENTRY_WRITER_EDITING_CONTEXT) return false; switch ($i) { case IdAttributeAddValueMenuItem : if ($attribute->isVisible() && !$attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value')) { if ($attribute->getMaxValueCount() < 0 || $attribute->getValueCount() < $attribute->getMaxValueCount()) { return $this->get('AddValueMenuItem', $attribute); } } return ''; case IdAttributeModifyMemberMenuItem : if (in_array($attribute->getName(), $_SESSION[APPCONFIG]->GetValue('modify_member','groupattr'))) { if ($attribute->isVisible() && !$attribute->isReadOnly() && !$attribute->isRdn() && ($_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value') || $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete_value'))) { return $this->get('ModifyMemberMenuItem', $attribute); } } return ''; case IdAttributeRenameMenuItem : if ($attribute->isVisible() && $attribute->isRdn() && !$attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('entry_rename')) { return $this->get('RenameMenuItem', $attribute); } return ''; default : return false; } } protected function drawAttributeStartValueLine($attribute) { if (($this->context == ENTRY_WRITER_EDITING_CONTEXT) && $attribute->hasBeenModified()) { echo ''; } else { echo ''; } echo ''; } protected function drawAttributeEndValueLine($attribute) { echo ''; echo ''; if (($this->context == ENTRY_WRITER_EDITING_CONTEXT) && $attribute->hasBeenModified()) { echo ''; } } protected function drawAttributeValue($attribute,$i,$entry) { if (DEBUG_ENABLED) debug_log('Entered with (%s, %d)',1,__FILE__,__LINE__,__METHOD__,$attribute->getName(),$i); $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($attribute->isVisible()) { echo '
'; $this->draw('Icon', $attribute, $val); echo ''; } $this->draw('OldValue', $attribute, $i); $this->draw('NewValue',$attribute,$i,$entry); if ($attribute->isVisible()) { echo ''; if (($i == 0) && $attribute->isRequired() && $attribute->getEntry() && !$attribute->getEntry()->isReadOnly()) { echo ' '; $this->draw('RequiredSymbol', $attribute); } echo '
'; } } /** * Save the current value to detect changes */ protected function drawAttributeOldValue($attribute, $i) { if ($this->context == ENTRY_WRITER_EDITING_CONTEXT) $val = $attribute->getValue($i); else $val = ''; if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); } /** * Display the current value */ protected function drawAttributeNewValue($attribute,$i,$entry) { if (!$attribute->isVisible()) { $this->draw('HiddenValue', $attribute, $i); $this->draw('Javascript',$attribute); } elseif ($attribute->isReadOnly() || ($attribute->getEntry() && $attribute->getEntry()->getDn() && $attribute->isRdn())) { /* If this is the RDN, we need to see if it has multiple values. If it does, and the multivalues are not * not in the RDN, then we need to make them editable. */ if ($attribute->isRdn()) { $rdn = split('\+',get_rdn($entry->getDN())); if (in_array(sprintf('%s=%s',$attribute->getName(),$attribute->getValue($i)),$rdn)) $this->draw('ReadOnlyValue', $attribute, $i); else $this->draw('ReadWriteValue', $attribute, $i); } else $this->draw('ReadOnlyValue', $attribute, $i); } else { $this->draw('ReadWriteValue', $attribute, $i); } } protected function drawAttributeBlankValue($attribute,$i,$entry) { $this->draw('Value',$attribute,$i,$entry); } protected function drawAttributeHiddenValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); } protected function drawAttributeReadOnlyValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('
', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : ''); } protected function drawAttributeReadWriteValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; if ($attribute->hasProperty('helper')) { echo '
'; } /* We smack an id="..." tag in here that doesn't have [][] in it to allow the * draw_chooser_link() to identify it after the user clicks. */ $id = sprintf('new_values_%s_%s', htmlspecialchars($attribute->getName()), $i); printf('', htmlspecialchars($attribute->getName()), $i, $id, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); if ($attribute->hasProperty('helper')) { echo ''; $this->draw('Helper', $attribute, $i); echo '
'; } } protected function drawAttributeHelper($attribute, $i) { $params = $attribute->getProperty('helper'); if (!$params) $params = array(); elseif (!is_array($params)) $params = array($params); $id = isset($params['id']) ? $params['id'] : ''; if (is_array($id)) $id = (count($id) > 0 ? $id[0] : ''); $display = isset($params['display']) ? $params['display'] : ''; if (is_array($display)) $display = (count($display) > 0 ? $display[0] : ''); $vals = isset($params['value']) ? $params['value'] : array(); if (!is_array($vals)) $vals = array($vals); $opts = isset($params['option']) ? $params['option'] : array(); if (!is_array($opts)) $opts = array($opts); $dn = ''; if ($attribute->getEntry()) { if ($this->context == ENTRY_WRITER_CREATION_CONTEXT) { $dn = $attribute->getEntry()->getContainer(); } else { $dn = $attribute->getEntry()->getDn(); } } $ldapserver = $this->getLDAPServer(); $arr1 = array(); foreach ($vals as $id_parval => $parval) { $arr2 = Templates::EvaluateDefault($ldapserver, $parval, $dn, null, null); if (is_array($arr2)) $arr1 = array_merge($arr1,$arr2); else $arr1[$id_parval] = $arr2; } $vals = $arr1; $arr1 = array(); foreach ($opts as $id_parval => $parval) { $arr2 = Templates::EvaluateDefault($ldapserver, $parval, $dn, null, null); if (is_array($arr2)) $arr1 = array_merge($arr1,$arr2); else $arr1[$id_parval] = $arr2; } $opts = $arr1; $default = (count($vals) > 0 ? $vals[0] : ''); if (!is_scalar($default)) $default = ''; if (!is_null($attribute->getValue($i)) && (strlen($default) <= 0)) { $default = $this->get('DefaultValueHelper', $attribute, $i); } if (count($opts) > 0) { $found = false; printf(''; } else { printf('', $id, htmlspecialchars($attribute->getName()), $i, $id, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($default)); } if ($display) { echo '
'; echo ''.$display.''; echo '
'; } } protected function getAttributeDefaultValueHelper($attribute, $i) { $params = $attribute->getProperty('helper'); # Should only return 1 default entry. if (isset($params['value']) && ! is_array($params['value'])) return $params['value']; # If there are multiple values, return the first one. else if (isset($params['value']) && is_array($params['value'])) return array_shift($params['value']); # No default values, return a blank. else return ''; } protected function getAttributeRenameMenuItem($attribute) { $encoded_dn = ''; if ($attribute->getEntry()) $encoded_dn = rawurlencode($attribute->getEntry()->getDn()); if (!$encoded_dn) return; // creating entry $url_base = sprintf('cmd.php?server_id=%s&dn=%s', $this->index, $encoded_dn); $href = sprintf('%s&cmd=rename_form', $url_base); return sprintf('(%s)', htmlspecialchars($href), _('rename')); } protected function getAttributeAddValueMenuItem($attribute) { /* Draw the "add value" link under the list of values for this attributes */ $encoded_dn = ''; $template = ''; if ($attribute->getEntry()) { $encoded_dn = rawurlencode($attribute->getEntry()->getDn()); if (method_exists($attribute->getEntry(), 'getSelectedTemplateName')) $template = $attribute->getEntry()->getSelectedTemplateName(); } if (!$encoded_dn) return; // creating entry $href = sprintf('cmd.php?cmd=add_value_form&server_id=%s&dn=%s%s&attr=%s', $this->index, $encoded_dn, $template ? "&template=$template" : '', rawurlencode($attribute->getName())); return sprintf('(%s)', htmlspecialchars($href), sprintf(_('Add an additional value to attribute \'%s\''), $attribute->getName()), _('add value')); } protected function getAttributeModifyMemberMenuItem($attribute) { $dn = ($attribute->getEntry()) ? $attribute->getEntry()->getDn() : ''; $encoded_dn = ($dn) ? rawurlencode($dn) : ''; if (!$encoded_dn) return; // creating entry $href = sprintf('cmd.php?cmd=modify_member_form&server_id=%s&dn=%s&attr=%s', $this->index, $encoded_dn, rawurlencode($attribute->getName())); return sprintf('(%s)', htmlspecialchars($href), sprintf(_('Modify members for \'%s\''), $dn), _('modify group members')); } protected function drawAttributeIcon($attribute, $val) { if (is_dn_string($val) || $this->getLDAPServer()->isDNAttr($attribute->getName())) { $this->draw('DnValueIcon', $attribute, $val); } elseif (is_mail_string($val)) { $this->draw('MailValueIcon', $attribute, $val); } elseif (is_url_string($val)) { $this->draw('UrlValueIcon', $attribute, $val); } else { $icon = $attribute->getIcon(); if ($icon) printf('Icon ', $icon); } } protected function drawAttributeDnValueIcon($attribute, $val) { if (strlen($val) <= 0) { printf('Go ',IMGDIR); } elseif ($this->getLDAPServer()->dnExists($val)) { printf('Go ', _('Go to'),htmlspecialchars($val),$this->index,rawurlencode($val),IMGDIR); } else { printf('Go ',_('DN not available'),htmlspecialchars($val),IMGDIR); } } protected function drawAttributeMailValueIcon($attribute, $val) { $img = sprintf('%s',IMGDIR,_('Mail')); if (strlen($val) <= 0) echo $img; else printf(''.$img.'', htmlspecialchars($val)); echo ' '; } protected function drawAttributeUrlValueIcon($attribute, $val) { $img = sprintf('%s',IMGDIR,_('URL')); $url = split(' +',$val,2); if (strlen($val) <= 0) echo $img; else printf('%s',htmlspecialchars($url[0]),$img); echo ' '; } protected function drawAttributeName($attribute) { $config = $_SESSION[APPCONFIG]; $attr_display = $attribute->getFriendlyName(); if ($attribute->getEntry() && $attribute->getEntry()->getDn() // if not creating attribute && $config->isCommandAvailable('schema') ) { $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=attributes&viewvalue=%s', $this->index, real_attr_name($attribute->getName())); printf('%s', $attribute->getName(), htmlspecialchars($href), $attr_display); } else { printf('%s', $attr_display); } } protected function getAttributeAliasNote($attribute) { # Is there a user-friendly translation available for this attribute? $friendly_name = $attribute->getFriendlyName(); if ($friendly_name != $attribute->getName()) return sprintf('%s', _('Note'),$friendly_name,_('is an alias for'),$attribute->getName(),_('alias')); else return ''; } protected function getAttributeRequiredNote($attribute) { # is this attribute required by an objectClass ? $required_by = ''; if ($attribute->getEntry()) { $schema_attr = $this->getLDAPServer()->getSchemaAttribute($attribute->getName(),$attribute->getEntry()->getDn()); if ($schema_attr) { $entry_attributes = $attribute->getEntry()->getAttributes(); $objectclass_attribute = null; foreach ($entry_attributes as $entry_attribute) { # It seems that some LDAP servers (Domino) returns attributes in lower case? if ($entry_attribute->getName() == 'objectClass' || $entry_attribute->getName() == 'objectclass') { $objectclass_attribute = $entry_attribute; break; } } if ($objectclass_attribute) { $classes = arrayLower($objectclass_attribute->getValues()); foreach ($schema_attr->getRequiredByObjectClasses() as $required) { if (in_array(strtolower($required), $classes)) { $required_by .= $required . ' '; } } } } } if ($required_by) { return "" . _('required') . ""; } else { return ''; } } protected function getAttributeRdnNote($attribute) { # is this attribute required because its the RDN if ($attribute->isRdn()) { return "" . 'rdn' . " "; } else { return ''; } } protected function getAttributeHintNote($attribute) { # Is there a hint for this attribute if ($attribute->getHint()) { return sprintf('%s ',htmlspecialchars($attribute->getHint()),_('hint')); } else { return ''; } } protected function drawAttributeRequiredSymbol($attribute) { echo '*'; } /***************************/ /* Paint a BinaryAttribute */ /***************************/ protected function drawBinaryAttributeValues($attribute) { $valcount = $attribute->getValueCount(); if ($attribute->isVisible()) { $this->draw('StartValueLine', $attribute); echo ''; echo _('Binary value'); if ($valcount > 0) { if (strcasecmp($attribute->getName(), 'objectSid') == 0) { printf(' (%s)', binSIDtoText($attribute->getValue(0))); } } echo '
'; if ($valcount > 0) { if ($attribute->getEntry() && $attribute->getEntry()->getDn()) { $href = sprintf('download_binary_attr.php?server_id=%s&dn=%s&attr=%s', $this->index, rawurlencode($attribute->getEntry()->getDn()), $attribute->getName()); if ($valcount > 1) { for ($i=1; $i<=$valcount; $i++) { printf('Save %s(%s)
', htmlspecialchars($href), $i,IMGDIR,_('download value'), $i); } } else { printf('Save %s
', htmlspecialchars($href),IMGDIR,_('download value')); } } if (! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete')) { printf(''. 'Trash %s', $attribute->getName(), $attribute->getFriendlyName(),IMGDIR,_('delete attribute')); } } elseif ($attribute->isReadOnly() || ! $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value')) { printf('
', _("[no value]")); } else { $i = 0; $val = ''; $id = sprintf('new_values_%s_%s', htmlspecialchars($attribute->getName()), $i); printf('
', htmlspecialchars($attribute->getName()), $i, $id, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); } echo '
'; $this->draw('EndValueLine', $attribute); } else { for ($i=0; $i<$valcount; $i++) { $n = $attribute->getFileName($i); $p = $attribute->getFilePath($i); if ($n && $p) { printf('', htmlspecialchars($attribute->getName()), $i, md5("$n|$p")); printf('', htmlspecialchars($attribute->getName()), $i, md5("$n|$p")); } } } } protected function drawBinaryAttributeJavascript($attribute) { printf("\n\n",__METHOD__); $this->draw('Attribute::Javascript', $attribute); $dn = ''; if ($attribute->getEntry()) $dn = $attribute->getEntry()->getDn(); if (!$dn) return; static $already_draw = false; if ($already_draw) return; else $already_draw = true; echo '
'; echo ' '; printf("\n\n",__METHOD__); } protected function drawBinaryAttributeBlurJavascript($attribute, $component) { } /***************************/ /* Paint a DateAttribute */ /***************************/ protected function drawDateAttributeReadWriteValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; printf(' ', $attribute->getName(), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); draw_date_selector_link($attribute->getName().'_'.$i); echo ''."\n"; } protected function drawDateAttributeJavascript($attribute) { printf("\n\n",__METHOD__); $this->draw('Attribute::Javascript', $attribute); $entry['date'] = $_SESSION[APPCONFIG]->GetValue('appearance','date_attrs'); $entry['time'] = $_SESSION[APPCONFIG]->GetValue('appearance','date_attrs_showtime'); $entry['format'] = $_SESSION[APPCONFIG]->GetValue('appearance', 'date'); if (isset($entry['date'][$attribute->getName()])) $entry['format'] = $entry['date'][$attribute->getName()]; printf('',JSDIR); printf('',JSDIR); printf('',JSDIR); for ($i = 0; $i <= $attribute->getValueCount(); $i++) { printf('',$attribute->getName(),$i,$entry['format']); if (in_array_ignore_case($attribute->getName(),array_keys($entry['time'])) && ($entry['time'][$attribute->getName()])) printf('',$attribute->getName(),$i,'true'); } printf("\n\n",__METHOD__); } /***************************/ /* Paint a DnAttribute */ /***************************/ protected function drawDnAttributeReadWriteValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; if ($attribute->hasProperty('helper')) { echo '
'; } $input_name = sprintf('new_values[%s][%s]', htmlspecialchars($attribute->getName()), $i); $input_id = sprintf('new_values_%s_%s', htmlspecialchars($attribute->getName()), $i); printf(' ', $input_name, $input_id, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); /* draw a link for popping up the entry browser if this is the type of attribute * that houses DNs. */ draw_chooser_link("entry_form.$input_id", false); echo ''; if ($attribute->hasProperty('helper')) { echo ''; $this->draw('Helper', $attribute, $i); echo '
'; } echo "\n"; } protected function drawDnAttributeIcon($attribute, $val) { $this->draw('DnValueIcon', $attribute, $val); } /***************************/ /* Paint a GidAttribute */ /***************************/ protected function drawGidAttributeReadWriteValue($attribute, $i) { $this->draw('Attribute::ReadWriteValue', $attribute, $i); $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; $dn = ''; if ($attribute->getEntry()) $dn = $attribute->getEntry()->getDn(); # If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience if (! in_array_ignore_case('posixGroup', $this->getLDAPServer()->getDNAttr($dn, 'objectClass'))) { $gid_number = $val; $search_group_filter = "(&(objectClass=posixGroup)(gidNumber=$val))"; $group = $this->getLDAPServer()->search(null, null, $search_group_filter,array('dn','description')); if (count($group) > 0) { echo '
'; $group = array_pop($group); $group_dn = $group['dn']; $group_name = explode('=',get_rdn($group_dn)); $group_name = $group_name[1]; $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $this->index, rawurlencode($group_dn)); echo ''; printf('%s', htmlspecialchars($href), htmlspecialchars($group_name)); $description = isset($group['description']) ? $group['description'] : null; if (is_array($description)) { foreach ($description as $item) printf(' (%s)',htmlspecialchars($item)); } else { printf(' (%s)',htmlspecialchars($description)); } echo ''; } } } /***************************/ /* Paint a JpegAttribute */ /***************************/ protected function drawJpegAttributeValues($attribute) { if ($attribute->isVisible()) { $this->draw('StartValueLine', $attribute); $value_count = $attribute->getValueCount(); if ($value_count > 0) { /* Don't draw the delete buttons if there is more than one jpegPhoto * (phpLDAPadmin can't handle this case yet) */ if ($attribute->getEntry() && $attribute->getEntry()->getDn()) { draw_jpeg_photos($this->getLDAPServer(), $attribute->getEntry()->getDn(), $attribute->getName(), ! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('attribute_delete')); } } elseif ($attribute->isReadOnly() || ! $_SESSION[APPCONFIG]->isCommandAvailable('attribute_add_value')) { printf('
',_('[no value]')); } else { $i = 0; $val = ''; $id = sprintf('new_values_%s_%s', htmlspecialchars($attribute->getName()), $i); printf('
', htmlspecialchars($attribute->getName()), $i, $id, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); } $this->draw('EndValueLine', $attribute); } else { $this->draw('BinaryAttribute::Values', $attribute); } } /******************************/ /* Paint a MultiLineAttribute */ /******************************/ protected function drawMultiLineAttributeReadOnlyValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('
', ($attribute->getRows() > 0) ? 'rows="'.$attribute->getRows().'"' : '', ($attribute->getCols() > 0) ? 'cols="'.$attribute->getCols().'"' : '', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); } protected function drawMultiLineAttributeReadWriteValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('', ($attribute->getRows() > 0) ? 'rows="'.$attribute->getRows().'"' : '', ($attribute->getCols() > 0) ? 'cols="'.$attribute->getCols().'"' : '', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, $attribute->getName(), $attribute->getName(), htmlspecialchars($val)); } /********************************/ /* Paint a ObjectClassAttribute */ /********************************/ protected function drawObjectClassAttributeNewValue($attribute,$i,$entry) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; $schema_object = ($val) ? $this->getLDAPServer()->getSchemaObjectClass($val) : false; $structural = (is_object($schema_object) && $schema_object->getType() == 'structural'); if (!$attribute->isVisible()) { $this->draw('HiddenValue', $attribute, $i); } elseif ($structural) { # Is this value is a structural objectClass, make it read-only printf('', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); printf(' (%s)
', _('This is a structural ObjectClass and cannot be removed.'), _('structural')); } else { $this->draw('Attribute::NewValue',$attribute,$i,$entry); } } protected function drawObjectClassAttributeIcon($attribute, $val) { if (strlen($val) > 0) { $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=objectClasses&viewvalue=%s', $this->index, $val); printf('Info ', _('View the schema description for this objectClass'), htmlspecialchars($href),IMGDIR); } } /*****************************/ /* Paint a PasswordAttribute */ /*****************************/ protected function drawPasswordAttributeOldValue($attribute, $i) { $this->draw('Attribute::OldValue', $attribute, $i); } protected function drawPasswordAttributeHiddenValue($attribute, $i) { if ($this->context == ENTRY_WRITER_CREATION_CONTEXT) $this->draw('Attribute::HiddenValue', $attribute, $i); } protected function drawPasswordAttributeReadOnlyValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; $enc_type = get_enc_type($val); if ($val == '') $enc_type = get_default_hash($this->index); $obfuscate_password = obfuscate_password_display($enc_type); printf('
', ($obfuscate_password ? 'password' : 'text'), htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : ''); if ($val != '') $this->draw('CheckLink', $attribute, 'new_values_'.htmlspecialchars($attribute->getName()).'_'.$i); } protected function drawPasswordAttributeReadWriteValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; $enc_type = get_enc_type($val); # Set the default hashing type if the password is blank (must be newly created) if ($val == '') $enc_type = get_default_hash($this->index); echo '
'; $obfuscate_password = obfuscate_password_display($enc_type); $id = sprintf('new_values_%s_%s', htmlspecialchars($attribute->getName()), $i); printf('', ($obfuscate_password ? 'password' : 'text'), htmlspecialchars($attribute->getName()), $i, $id, htmlspecialchars($val), $attribute->getName(), $attribute->getName(), ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); echo ''; if ($attribute->hasProperty('helper')) $this->draw('Helper', $attribute, $i); else echo enc_type_select_list($enc_type,'enc',$attribute->getName(),$i); echo '
'; if ($attribute->hasProperty('verify') && $attribute->getProperty('verify') && $obfuscate_password) { $id_v = sprintf('new_values_verify_%s_%s', htmlspecialchars($attribute->getName()), $i); printf('', htmlspecialchars($attribute->getName()), $i, $id_v, ($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : '', ($attribute->getMaxLength() > 0) ? 'maxlength="'.$attribute->getMaxLength().'"' : ''); echo ''; printf('(%s)', _('confirm')); echo '
'; } $this->draw('CheckLink', $attribute, $id); echo '
'; } protected function getPasswordAttributeDefaultValueHelper($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; $enc_type = get_enc_type($val); # Set the default hashing type if the password is blank (must be newly created) if ($val == '') { $enc_type = get_default_hash($this->index); } return $enc_type; } protected function drawPasswordAttributeCheckLink($attribute, $component_id) { printf('%s
', $component_id/*base64_encode($val)*/, _('Check password...')); } protected function drawPasswordAttributeJavascript($attribute) { printf("\n\n",__METHOD__); $this->draw('Attribute::Javascript', $attribute); static $already_draw = false; if ($already_draw) return; else $already_draw = true; # add the javascript so we can call check password later. printf("\n\n",__METHOD__); echo ' '; printf("\n\n",__METHOD__); } /***********************************/ /* Paint a RandomPasswordAttribute */ /***********************************/ protected function drawRandomPasswordAttributeJavascript($attribute) { printf("\n\n",__METHOD__); $this->draw('PasswordAttribute::Javascript', $attribute); $pwd = password_generate(); $pwd = str_replace("\\", "\\\\", $pwd); $pwd = str_replace("'", "\\'", $pwd); printf("\n\n",__METHOD__); echo ''; printf("\n\n",__METHOD__); } /******************************/ /* Paint a SelectionAttribute */ /******************************/ protected function drawSelectionAttributeValues($attribute,$entry) { if (!$attribute->isVisible() || !$attribute->isMultiple() || ($attribute->getValueCount() > 0)) { $this->draw('Attribute::Values',$attribute,$entry); } else { $this->draw('StartValueLine', $attribute); $this->draw('Value', $attribute, 0); $this->draw('Menu', $attribute); $this->draw('EndValueLine', $attribute); } } protected function drawSelectionAttributeReadOnlyValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); $select = $attribute->getSelection(); if (isset($select[$val])) $val = $select[$val]; echo htmlspecialchars($val).'
'; } protected function drawSelectionAttributeReadWriteValue($attribute, $i) { if ($attribute->isMultiple()) { # For multiple selection, we draw the component only one time if ($i > 0) return; if (($attribute->getSize() > 0) && ($attribute->getSize() < $attribute->getOptionCount())) { $selected = array(); printf(''; } else { $selected = array(); $vals = $attribute->getValues(); $j = 0; echo ''; foreach ($attribute->getSelection() as $value => $description) { if (in_array($value, $vals)) $selected[$value] = true; $id = 'new_values_'.htmlspecialchars($attribute->getName()).'_'.($j++); printf('', $id, htmlspecialchars($attribute->getName()), $value, $attribute->getName(), $attribute->getName(), isset($selected[$value]) ? 'checked' : '', " $description"); } foreach ($vals as $val) { if (!isset($selected[$val])) { $id = 'new_values_'.htmlspecialchars($attribute->getName()).'_'.($j++); printf('', $id, htmlspecialchars($attribute->getName()), $val, $attribute->getName(), $attribute->getName(), " $val"); } } echo '
%s
%s
'; } } else { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; if ($attribute->hasProperty('helper')) echo '
'; $found = false; $empty_value = false; $id = 'new_values_'.htmlspecialchars($attribute->getName()).'_'.$i; # If we are a required attribute, and the selection is blank, then the user cannot submit this form. if ($attribute->isRequired() && ! count($attribute->getSelection())) system_message(array( 'title'=>_('Template Value Error'), 'body'=>sprintf('This template uses a selection list for attribute [%s], however the selection list is empty.
You may need to create some dependancy entries in your LDAP server so that this attribute renders with values. Alternatively, you may be able to define the appropriate selection values in the template file.',$attribute->getName()), 'type'=>'warn')); printf(''; if ($attribute->hasProperty('helper')) { echo '
'; $this->draw('Helper', $attribute, $i); echo '
'; } } } protected function getSelectionAttributeMenuItem($attribute, $i) { switch ($i) { case IdAttributeAddValueMenuItem : if (!$attribute->isMultiple()) { return $this->get('Attribute::MenuItem', $attribute, $i); } return ''; case IdAttributeModifyMemberMenuItem : return ''; default : return $this->get('Attribute::MenuItem', $attribute, $i); } } protected function drawSelectionAttributeIcon($attribute, $val) { if (!$attribute->isMultiple() || $attribute->isReadOnly()) $this->draw('Attribute::Icon', $attribute, $val); } /***************************/ /* Paint a ShadowAttribute */ /***************************/ protected function drawShadowAttributeReadOnlyValue($attribute, $i) { $val = $attribute->getValue($i); if (!is_string($val)) $val = ''; if ($i < 0) $i = 0; printf('', htmlspecialchars($attribute->getName()), $i, htmlspecialchars($attribute->getName()), $i, htmlspecialchars($val)); $today = date('U'); $shadow_date = $today; if ($attribute->getEntry()) { $shadow_date = shadow_date($attribute->getEntry()->getAttributes(),$attribute->getName()); } echo htmlspecialchars($val).' '; echo ''; $this->draw('ShadowDate', $attribute, $shadow_date); echo '
'; } protected function drawShadowAttributeReadWriteValue($attribute, $i) { $this->draw('Attribute::ReadWriteValue', $attribute, $i); $val = $attribute->getValue($i); if (!is_string($val) || (strlen($val) <= 0)) return; $today = date('U'); $shadow_date = $today; if ($attribute->getEntry()) { $shadow_date = shadow_date($attribute->getEntry()->getAttributes(),$attribute->getName()); } # Show the dates for all the shadow attributes. if ($shadow_date !== false) { echo ''; $this->draw('ShadowDate', $attribute, $shadow_date); echo ''; echo '
'; } } protected function drawShadowAttributeShadowDate($attribute, $shadow_date) { $config = $_SESSION[APPCONFIG]; $shadow_before_today_attrs = arrayLower($attribute->shadow_before_today_attrs); $shadow_after_today_attrs = arrayLower($attribute->shadow_after_today_attrs); $today = date('U'); if (($today < $shadow_date) && in_array(strtolower($attribute->getName()),$shadow_before_today_attrs)) { echo '('; echo htmlspecialchars(strftime($config->GetValue('appearance', 'date'), $shadow_date)); echo ')'; } elseif (($today > $shadow_date) && in_array(strtolower($attribute->getName()),$shadow_after_today_attrs)) { echo '('; echo htmlspecialchars(strftime($config->GetValue('appearance', 'date'), $shadow_date)); echo ')'; } else { echo '('; echo htmlspecialchars(strftime($config->GetValue('appearance', 'date'), $shadow_date)); echo ')'; } } } ?>