diff --git a/htdocs/add_attr_form.php b/htdocs/add_attr_form.php index ba5ece0..80e19db 100644 --- a/htdocs/add_attr_form.php +++ b/htdocs/add_attr_form.php @@ -17,7 +17,9 @@ $request['dn'] = get_request('dn','GET'); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null)); $request['page']->setDN($request['dn']); @@ -38,10 +40,15 @@ if (get_request('meth','REQUEST') != 'ajax') { $attr['binary'] = array(); foreach ($request['template']->getAvailAttrs() as $attribute) + { if ($app['server']->isAttrBinary($attribute->getName())) - array_push($attr['binary'],$attribute); - else - array_push($attr['avail'],$attribute); + { + array_push($attr['binary'], $attribute); + } else + { + array_push($attr['avail'], $attribute); + } + } if (count($attr['avail']) > 0) { echo '
'; @@ -53,9 +60,13 @@ if (get_request('meth','REQUEST') != 'ajax') { echo '
'; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) + { echo ''; + } else + { echo ''; + } printf('',$app['server']->getIndex()); printf('',htmlspecialchars($request['dn'])); @@ -65,9 +76,13 @@ if (get_request('meth','REQUEST') != 'ajax') { foreach ($attr['avail'] as $attribute) { # Is there a user-friendly translation available for this attribute? if ($attribute->haveFriendlyName()) - $attr_display = sprintf('%s (%s)',$attribute->getFriendlyName(),$attribute->getName(false)); + { + $attr_display = sprintf('%s (%s)', $attribute->getFriendlyName(), $attribute->getName(FALSE)); + } else - $attr_display = $attribute->getName(false); + { + $attr_display = $attribute->getName(FALSE); + } printf('',htmlspecialchars($attribute->getName()),$attr_display); } @@ -95,9 +110,13 @@ if (get_request('meth','REQUEST') != 'ajax') { echo '
'; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) + { echo ''; + } else + { echo ''; + } printf('',$app['server']->getIndex()); printf('',$request['dn']); @@ -108,9 +127,13 @@ if (get_request('meth','REQUEST') != 'ajax') { foreach ($attr['binary'] as $attribute) { # Is there a user-friendly translation available for this attribute? if ($attribute->haveFriendlyName()) - $attr_display = sprintf('%s (%s)',$attribute->getFriendlyName(),$attribute->getName(false)); + { + $attr_display = sprintf('%s (%s)', $attribute->getFriendlyName(), $attribute->getName(FALSE)); + } else - $attr_display = $attribute->getName(false); + { + $attr_display = $attribute->getName(FALSE); + } printf('',htmlspecialchars($attribute->getName()),$attr_display); } @@ -121,11 +144,15 @@ if (get_request('meth','REQUEST') != 'ajax') { printf('',_('Add')); if (! ini_get('file_uploads')) + { printf('
%s
', _('Your PHP configuration has disabled file uploads. Please check php.ini before proceeding.')); + } else - printf('
%s: %s
',_('Maximum file size'),ini_get('upload_max_filesize')); + { + printf('
%s: %s
', _('Maximum file size'), ini_get('upload_max_filesize')); + } echo '
'; echo ''; @@ -145,7 +172,9 @@ if (get_request('meth','REQUEST') != 'ajax') { echo ''; foreach ($request['template']->getAvailAttrs() as $attribute) - $request['page']->draw('Template',$attribute); + { + $request['page']->draw('Template', $attribute); + } $request['page']->drawFormSubmitButton(); echo '
'; @@ -173,7 +202,9 @@ if (get_request('meth','REQUEST') != 'ajax') { printf('','',''); foreach ($request['template']->getAvailAttrs() as $attribute) - printf('',htmlspecialchars($attribute->getName()),$attribute->getFriendlyName()); + { + printf('', htmlspecialchars($attribute->getName()), $attribute->getFriendlyName()); + } echo ''; diff --git a/htdocs/add_oclass_form.php b/htdocs/add_oclass_form.php index d94a188..856abd8 100644 --- a/htdocs/add_oclass_form.php +++ b/htdocs/add_oclass_form.php @@ -21,7 +21,9 @@ $request['dn'] = get_request('dn','REQUEST',true); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null)); $request['page']->setDN($request['dn']); @@ -37,10 +39,14 @@ $ldap['attrs']['must'] = array(); foreach ($request['template']->getAttribute('objectclass')->getValues() as $oclass_name) { # Exclude "top" if its there. if (! strcasecmp('top',$oclass_name)) + { continue; + } if ($soc = $app['server']->getSchemaObjectClass($oclass_name)) - $ldap['attrs']['must'] = array_merge($ldap['attrs']['must'],$soc->getMustAttrNames(true)); + { + $ldap['attrs']['must'] = array_merge($ldap['attrs']['must'], $soc->getMustAttrNames(TRUE)); + } } $ldap['attrs']['must'] = array_unique($ldap['attrs']['must']); @@ -49,12 +55,18 @@ $ldap['attrs']['must'] = array_unique($ldap['attrs']['must']); * but that the object does not currently contain */ $ldap['attrs']['need'] = array(); foreach ($ldap['attrs']['must'] as $attr) +{ if (is_null($request['template']->getAttribute($attr))) - array_push($ldap['attrs']['need'],$attribute_factory->newAttribute($attr,array('values'=>array()),$app['server']->getIndex())); + { + array_push($ldap['attrs']['need'], $attribute_factory->newAttribute($attr, array('values' => array()), $app['server']->getIndex())); + } +} # Mark all the need attributes as shown foreach ($ldap['attrs']['need'] as $index => $values) +{ $ldap['attrs']['need'][$index]->show(); +} if (count($ldap['attrs']['need']) > 0) { $request['page']->drawTitle(sprintf('%s %s',_('Add new objectClass to'),get_rdn($request['dn']))); @@ -73,9 +85,12 @@ if (count($ldap['attrs']['need']) > 0) { echo '
'; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) - echo ''; + { + echo ''; } else + { echo ''; + } printf('',$app['server']->getIndex()); printf('',htmlspecialchars($request['dn'])); @@ -87,11 +102,15 @@ if (count($ldap['attrs']['need']) > 0) { $counter = 0; echo ''; foreach ($request['template']->getAttribute('objectclass')->getValues() as $value) - $request['page']->draw('HiddenValue',$request['template']->getAttribute('objectclass'),$counter++); + { + $request['page']->draw('HiddenValue', $request['template']->getAttribute('objectclass'), $counter++); + } echo ''; foreach ($ldap['attrs']['need'] as $count => $attr) - $request['page']->draw('Template',$attr); + { + $request['page']->draw('Template', $attr); + } echo ''; @@ -108,7 +127,9 @@ if (count($ldap['attrs']['need']) > 0) { $app['server']->getIndex(),rawurlencode($request['dn'])); if (get_request('meth','REQUEST') == 'ajax') + { $href .= '&meth=ajax'; + } header(sprintf('Location: %s',$href)); die(); diff --git a/htdocs/add_value_form.php b/htdocs/add_value_form.php index e01b3dc..042d542 100644 --- a/htdocs/add_value_form.php +++ b/htdocs/add_value_form.php @@ -19,7 +19,9 @@ $request['attr'] = get_request('attr','GET',true); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null)); $request['page']->setDN($request['dn']); @@ -46,9 +48,12 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' echo '
'; echo '
'; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) - echo ''; + { + echo ''; } else + { echo ''; + } } printf('',$app['server']->getIndex()); @@ -71,7 +76,9 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' echo ''; + } else + { echo ''; + } foreach (array('src','dst') as $side) { # If we are on the source side, show the attribute name. @@ -109,7 +119,9 @@ foreach ($attrs_all as $attr) { echo ''; if ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID()) + { echo ''; + } else { echo ''; + } else { echo ''; + } else + { echo ''; + } foreach (array('src','dst') as $side) { echo '', htmlspecialchars($attribute->getName()),htmlspecialchars($attribute->getName()),$input_disabled,$input_onclick); @@ -133,10 +144,14 @@ if (count($request['template']->getLDAPadd(true))) { echo _('You made no changes'); if (isAjaxEnabled()) + { printf(' %s.', - htmlspecialchars($href),htmlspecialchars($href),_('Retrieving DN'),_('Go back')); + htmlspecialchars($href), htmlspecialchars($href), _('Retrieving DN'), _('Go back')); + } else - printf(' %s.',htmlspecialchars($href),_('Go back')); + { + printf(' %s.', htmlspecialchars($href), _('Go back')); + } echo ''; } diff --git a/htdocs/delete.php b/htdocs/delete.php index 9a2d01e..1e2973c 100644 --- a/htdocs/delete.php +++ b/htdocs/delete.php @@ -16,7 +16,9 @@ $request = array(); $request['dn'] = get_request('dn','REQUEST',true); if (! $app['server']->dnExists($request['dn'])) - error(sprintf('%s (%s)',_('No such entry.'),''.pretty_print_dn($request['dn']).''),'error','index.php'); +{ + error(sprintf('%s (%s)', _('No such entry.'), '' . pretty_print_dn($request['dn']) . ''), 'error', 'index.php'); +} # Delete the entry. $result = $app['server']->delete($request['dn']); @@ -25,7 +27,9 @@ if ($result) { $redirect_url = ''; if (isAjaxEnabled()) - $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1',$app['server']->getIndex()); + { + $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1', $app['server']->getIndex()); + } system_message(array( 'title'=>_('Delete DN'), @@ -33,8 +37,10 @@ if ($result) { 'type'=>'info'), sprintf('index.php?server_id=%s%s',$app['server']->getIndex(),$redirect_url)); } else +{ system_message(array( - 'title'=>_('Could not delete the entry.').sprintf(' (%s)',pretty_print_dn($request['dn'])), - 'body'=>ldap_error_msg($app['server']->getErrorMessage(null),$app['server']->getErrorNum(null)), - 'type'=>'error')); + 'title' => _('Could not delete the entry.') . sprintf(' (%s)', pretty_print_dn($request['dn'])), + 'body' => ldap_error_msg($app['server']->getErrorMessage(NULL), $app['server']->getErrorNum(NULL)), + 'type' => 'error')); +} diff --git a/htdocs/delete_attr.php b/htdocs/delete_attr.php index ce12be8..d20f8e4 100644 --- a/htdocs/delete_attr.php +++ b/htdocs/delete_attr.php @@ -17,7 +17,9 @@ $request['attr'] = get_request('attr','REQUEST',true); $request['index'] = get_request('index','REQUEST',true); if ($app['server']->isAttrReadOnly($request['attr'])) - error(sprintf(_('The attribute "%s" is flagged as read-only in the phpLDAPadmin configuration.'),$request['attr']),'error','index.php'); +{ + error(sprintf(_('The attribute "%s" is flagged as read-only in the phpLDAPadmin configuration.'), $request['attr']), 'error', 'index.php'); +} $update_array = array(); $update_array[$request['attr']] = $app['server']->getDNAttrValue($request['dn'],$request['attr']); @@ -26,21 +28,27 @@ $redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $app['server']->getIndex(),rawurlencode($request['dn'])); if (! isset($update_array[$request['attr']][$request['index']])) +{ system_message(array( - 'title'=>_('Could not delete attribute value.'), - 'body'=>sprintf('%s. %s/%s',_('The attribute value does not exist'),$request['attr'],$request['index']), - 'type'=>'warn'),$redirect_url); + 'title' => _('Could not delete attribute value.'), + 'body' => sprintf('%s. %s/%s', _('The attribute value does not exist'), $request['attr'], $request['index']), + 'type' => 'warn'), $redirect_url); +} else { unset($update_array[$request['attr']][$request['index']]); foreach ($update_array as $key => $values) + { $update_array[$key] = array_values($values); + } $result = $app['server']->modify($request['dn'],$update_array); if ($result) { foreach ($update_array as $attr => $junk) - $redirect_url .= sprintf('&modified_attrs[]=%s',$attr); + { + $redirect_url .= sprintf('&modified_attrs[]=%s', $attr); + } header("Location: $redirect_url"); die(); diff --git a/htdocs/delete_form.php b/htdocs/delete_form.php index 2294ccc..9010b8e 100644 --- a/htdocs/delete_form.php +++ b/htdocs/delete_form.php @@ -22,10 +22,12 @@ $request['template'] = $request['page']->getTemplate(); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) +{ system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s)',_('The entry does not exist'),$request['dn']), - 'type'=>'error'),'index.php'); + 'title' => _('Entry does not exist'), + 'body' => sprintf('%s (%s)', _('The entry does not exist'), $request['dn']), + 'type' => 'error'), 'index.php'); +} # We search all children, not only the visible children in the tree $request['children'] = $app['server']->getContainerContents($request['dn'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER); @@ -106,7 +108,9 @@ if (count($request['children'])) { $i = 0; printf(''; echo "\n"; diff --git a/htdocs/download_binary_attr.php b/htdocs/download_binary_attr.php index d648077..2d9d573 100644 --- a/htdocs/download_binary_attr.php +++ b/htdocs/download_binary_attr.php @@ -21,14 +21,18 @@ $request['type'] = get_request('type','GET',false,'octet-stream'); $request['filename'] = get_request('filename','GET',false,sprintf('%s:%s.bin',get_rdn($request['dn'],true),$request['attr'])); if (! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $search = $app['server']->getDNAttrValues($request['dn'],null,LDAP_DEREF_NEVER,array($request['attr'])); # Dump the binary data to the browser $obStatus = ob_get_status(); -if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) +if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) +{ ob_end_clean(); +} if (! isset($search[$request['attr']][$request['index']])) { # We cant display an error, but we can set a system message, which will be display on the next page render. diff --git a/htdocs/draw_tree_node.php b/htdocs/draw_tree_node.php index cc1e47b..11df546 100644 --- a/htdocs/draw_tree_node.php +++ b/htdocs/draw_tree_node.php @@ -18,7 +18,9 @@ $request['noheader'] = get_request('noheader','REQUEST',false,0); $tree = Tree::getInstance($request['server_id']); if (! $tree) +{ die(); +} $treesave = false; @@ -50,12 +52,18 @@ if ($request['dn']) { } if ($treesave) - set_cached_item($app['server']->getIndex(),'tree','null',$tree); +{ + set_cached_item($app['server']->getIndex(), 'tree', 'null', $tree); +} if ($request['dn']) - echo $tree->draw_children($dnentry,$request['code']); +{ + echo $tree->draw_children($dnentry, $request['code']); +} else +{ $tree->draw($request['noheader']); +} die(); diff --git a/htdocs/entry_chooser.php b/htdocs/entry_chooser.php index 6a24934..1789541 100644 --- a/htdocs/entry_chooser.php +++ b/htdocs/entry_chooser.php @@ -46,7 +46,9 @@ if (isset($app['server']) && ! is_null($request['container'])) { foreach ($app['server']->getBaseDN() as $base) { if (DEBUG_ENABLED) - debug_log('Comparing BaseDN [%s] with container [%s]',64,0,__FILE__,__LINE__,__METHOD__,$base,$request['container']); + { + debug_log('Comparing BaseDN [%s] with container [%s]', 64, 0, __FILE__, __LINE__, __METHOD__, $base, $request['container']); + } if (! pla_compare_dns($request['container'],$base)) { $parent_container = false; @@ -67,33 +69,42 @@ if (isset($app['server']) && ! is_null($request['container'])) { echo ''; if (! count($request['children'])) - printf('',_('no entries')); + { + printf('', _('no entries')); + } else - foreach ($request['children'] as $dn) { - $href['return'] = sprintf("javascript:returnDN('%s%s')",($request['rdn'] ? sprintf('%s,',$request['rdn']) : ''),str_replace('\\','\\\\',$dn)); + { + foreach ($request['children'] as $dn) + { + $href['return'] = sprintf("javascript:returnDN('%s%s')", ($request['rdn'] ? sprintf('%s,', $request['rdn']) : ''), str_replace('\\', '\\\\', $dn)); $href['expand'] = sprintf('entry_chooser.php?server_id=%s&form=%s&element=%s&rdn=%s&container=%s', - $app['server']->getIndex(),$request['form'],$request['element'],$request['rdn'],rawurlencode($dn)); + $app['server']->getIndex(), $request['form'], $request['element'], $request['rdn'], rawurlencode($dn)); echo ''; echo ''; - printf('',$href['expand'],IMGDIR); + printf('', $href['expand'], IMGDIR); $entry = $tree->getEntry($dn); - if (is_null($entry)) { + if (is_null($entry)) + { $tree->addEntry($dn); $entry = $tree->getEntry($dn); } if ($entry) + { $item = draw_formatted_dn($app['server'], $entry); - else + } else + { $item = $dn; + } - printf('',$href['return'], $item ); + printf('', $href['return'], $item); echo ''; echo "\n\n"; } + } # Draw the root of the selection tree (ie, list all the servers) } else { diff --git a/htdocs/export.php b/htdocs/export.php index 5e4ab24..43f64ea 100644 --- a/htdocs/export.php +++ b/htdocs/export.php @@ -24,8 +24,10 @@ $types = $request['export']->getType(); # send the header if ($request['file']) { $obStatus = ob_get_status(); - if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) + if (isset($obStatus['type']) && $obStatus['type'] && $obStatus['status']) + { ob_end_clean(); + } header('Content-type: application/download'); header(sprintf('Content-Disposition: inline; filename="%s.%s"','export',$types['extension'].($request['export']->isCompressed() ? '.gz' : ''))); diff --git a/htdocs/export_form.php b/htdocs/export_form.php index 8099109..7d8adbd 100644 --- a/htdocs/export_form.php +++ b/htdocs/export_form.php @@ -69,9 +69,11 @@ printf('',_('Search Scope')) echo ''; @@ -123,9 +125,11 @@ echo '
'; printf('%s',_('Line ends')); foreach ($available_formats as $id => $desc) +{ printf('
', - htmlspecialchars($id),htmlspecialchars($id),($request['format']==$id) ? ' checked="checked"' : '', - htmlspecialchars($id),$desc); + htmlspecialchars($id), htmlspecialchars($id), ($request['format'] == $id) ? ' checked="checked"' : '', + htmlspecialchars($id), $desc); +} echo '
'; echo ''; @@ -149,13 +153,21 @@ echo ''; */ function get_line_end_format() { if (is_browser('win')) + { return 'win'; + } elseif (is_browser('unix')) + { return 'unix'; + } elseif (is_browser('mac')) + { return 'mac'; + } else + { return 'unix'; + } } /** @@ -166,9 +178,13 @@ function get_line_end_format() { */ function get_user_agent_string() { if (isset($_SERVER['HTTP_USER_AGENT'])) + { return strtolower($_SERVER['HTTP_USER_AGENT']); + } else + { return ''; + } } /** @@ -208,8 +224,12 @@ function is_browser($type) { ); if (isset($agents[$type])) - return in_array(get_user_agent_string(),$agents[$type]); + { + return in_array(get_user_agent_string(), $agents[$type]); + } else - return false; + { + return FALSE; + } } diff --git a/htdocs/images/default/index.php b/htdocs/images/default/index.php index 0d4445f..89682db 100644 --- a/htdocs/images/default/index.php +++ b/htdocs/images/default/index.php @@ -19,11 +19,17 @@ $dir = opendir( '.' ); while( ( $file = readdir( $dir ) ) !== false ) { if( $file == '.' || $file == '..' ) - continue; + { + continue; + } if( ! preg_match( '/\.png$/', $file ) ) - continue; + { + continue; + } if( $file == 'phpLDAPadmin_logo1.png' ) - continue; + { + continue; + } $files[ filesize( $file ) . '_' . $file ] = $file; } diff --git a/htdocs/images/tango/index.php b/htdocs/images/tango/index.php index 0d4445f..89682db 100644 --- a/htdocs/images/tango/index.php +++ b/htdocs/images/tango/index.php @@ -19,11 +19,17 @@ $dir = opendir( '.' ); while( ( $file = readdir( $dir ) ) !== false ) { if( $file == '.' || $file == '..' ) - continue; + { + continue; + } if( ! preg_match( '/\.png$/', $file ) ) - continue; + { + continue; + } if( $file == 'phpLDAPadmin_logo1.png' ) - continue; + { + continue; + } $files[ filesize( $file ) . '_' . $file ] = $file; } diff --git a/htdocs/import.php b/htdocs/import.php index 2eaade7..c6b36e5 100644 --- a/htdocs/import.php +++ b/htdocs/import.php @@ -60,7 +60,8 @@ while (! $request['import']->eof()) { printf('%s %s',$actionString[$changetype],$edit_href,$request['template']->getDN()); if ($request['import']->LDAPimport()) - printf(' %s
',_('Success')); + { + printf(' %s
',_('Success')); } else { printf(' %s

',_('Failed')); @@ -84,7 +85,9 @@ while (! $request['import']->eof()) { } if (! $request['continuous_mode']) + { break; + } } function display_pla_parse_error($request) { @@ -103,7 +106,9 @@ function display_pla_parse_error($request) { printf('',_('Data')); foreach ($request->error['data'] as $line) - printf('',$line); + { + printf('', $line); + } echo '
'; for ($i=0;$i<$request['count'];$i++) { if ($i > 0) + { echo '
'; + } $request['page']->draw('CurrentValue',$request['attribute'],$i); $request['page']->draw('HiddenValue',$request['attribute'],$i); } @@ -96,7 +103,9 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' $socs = $app['server']->SchemaObjectClasses(); foreach ($request['attribute']->getValues() as $oclass) + { unset($socs[strtolower($oclass)]); + } # Draw objectClass selection echo ''; @@ -105,7 +114,9 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' foreach ($socs as $name => $oclass) { # Exclude any structural ones, that are not in the heirachy, as they'll only generate an LDAP_OBJECT_CLASS_VIOLATION if (($oclass->getType() == 'structural') && ! $oclass->isRelated($request['attribute']->getValues())) - continue; + { + continue; + } printf('',$oclass->getName(false),$oclass->getName(false)); } @@ -121,8 +132,10 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' echo ''; if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints')) + { printf('', - IMGDIR,_('Note: You may be required to enter new attributes that these objectClass(es) require')); + IMGDIR, _('Note: You may be required to enter new attributes that these objectClass(es) require')); + } echo '

Hint%s
'; echo ''; @@ -136,14 +149,20 @@ if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST' $sattr = $app['server']->getSchemaAttribute($request['attr']); if ($sattr->getDescription()) - printf('%s: %s
',_('Description'),$sattr->getDescription()); + { + printf('%s: %s
', _('Description'), $sattr->getDescription()); + } if ($sattr->getType()) - printf('%s: %s
',_('Syntax'),$sattr->getType()); + { + printf('%s: %s
', _('Syntax'), $sattr->getType()); + } if ($sattr->getMaxLength()) + { printf('%s: %s %s
', - _('Maximum Length'),number_format($sattr->getMaxLength()),_('characters')); + _('Maximum Length'), number_format($sattr->getMaxLength()), _('characters')); + } echo '
'; printf('',_('Add New Value')); diff --git a/htdocs/cmd.php b/htdocs/cmd.php index 5f39368..6ee45ad 100644 --- a/htdocs/cmd.php +++ b/htdocs/cmd.php @@ -21,20 +21,30 @@ ob_start(); switch ($www['cmd']) { default: if (defined('HOOKSDIR') && file_exists(HOOKSDIR.$www['cmd'].'.php')) - $app['script_cmd'] = HOOKSDIR.$www['cmd'].'.php'; + { + $app['script_cmd'] = HOOKSDIR . $www['cmd'] . '.php'; + } elseif (defined('HTDOCDIR') && file_exists(HTDOCDIR.$www['cmd'].'.php')) - $app['script_cmd'] = HTDOCDIR.$www['cmd'].'.php'; + { + $app['script_cmd'] = HTDOCDIR . $www['cmd'] . '.php'; + } elseif (file_exists('welcome.php')) + { $app['script_cmd'] = 'welcome.php'; + } else - $app['script_cmd'] = null; + { + $app['script_cmd'] = NULL; + } } if (DEBUG_ENABLED) - debug_log('Ready to render page for command [%s,%s].',128,0,__FILE__,__LINE__,__METHOD__,$www['cmd'],$app['script_cmd']); +{ + debug_log('Ready to render page for command [%s,%s].', 128, 0, __FILE__, __LINE__, __METHOD__, $www['cmd'], $app['script_cmd']); +} # Create page. # Set the index so that we render the right server tree. @@ -44,7 +54,9 @@ $www['page'] = new page($app['server']->getIndex()); if (trim($www['cmd'])) { # If this is a READ-WRITE operation, the LDAP server must not be in READ-ONLY mode. if ($app['server']->isReadOnly() && ! in_array(get_request('cmd','REQUEST'),$app['readwrite_cmds'])) - error(_('You cannot perform updates while server is in read-only mode'),'error','index.php'); + { + error(_('You cannot perform updates while server is in read-only mode'), 'error', 'index.php'); + } # If this command has been disabled by the config. if (! $_SESSION[APPCONFIG]->isCommandAvailable('script',$www['cmd'])) { @@ -56,7 +68,9 @@ if (trim($www['cmd'])) { } if ($app['script_cmd']) +{ include $app['script_cmd']; +} # Refresh a frame - this is so that one frame can trigger another frame to be refreshed. if (isAjaxEnabled() && get_request('refresh','REQUEST') && get_request('refresh','REQUEST') != get_request('frame','REQUEST')) { @@ -73,7 +87,11 @@ $www['page']->block_add('body',$www['body']); ob_end_clean(); if ($www['meth'] == 'ajax') - $www['page']->show(get_request('frame','REQUEST',false,'BODY'),true,get_request('raw','REQUEST',false,false)); +{ + $www['page']->show(get_request('frame', 'REQUEST', FALSE, 'BODY'), TRUE, get_request('raw', 'REQUEST', FALSE, FALSE)); +} else +{ $www['page']->display(); +} diff --git a/htdocs/common.php b/htdocs/common.php index 22e9af4..4c14646 100644 --- a/htdocs/common.php +++ b/htdocs/common.php @@ -9,6 +9,8 @@ */ if (! defined('LIBDIR')) - define('LIBDIR',sprintf('%s/',realpath('../lib/'))); +{ + define('LIBDIR', sprintf('%s/', realpath('../lib/'))); +} require_once LIBDIR.'common.php'; diff --git a/htdocs/compare.php b/htdocs/compare.php index 84b8ea1..111ed85 100644 --- a/htdocs/compare.php +++ b/htdocs/compare.php @@ -21,10 +21,14 @@ $ldap['SRC'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_src')); $ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst')); if (! $ldap['SRC']->dnExists($request['dnSRC'])) - error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnSRC'])),'error','index.php'); +{ + error(sprintf('%s (%s)', _('No such entry.'), pretty_print_dn($request['dnSRC'])), 'error', 'index.php'); +} if (! $ldap['DST']->dnExists($request['dnDST'])) - error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnDST'])),'error','index.php'); +{ + error(sprintf('%s (%s)', _('No such entry.'), pretty_print_dn($request['dnDST'])), 'error', 'index.php'); +} $request['pageSRC'] = new PageRender($ldap['SRC']->getIndex(),get_request('template','REQUEST',false,'none')); $request['pageSRC']->setDN($request['dnSRC']); @@ -88,16 +92,22 @@ sort($attrs_all); foreach ($attrs_all as $attr) { # Has the config.php specified that this attribute is to be hidden or shown? if ($ldap['SRC']->isAttrHidden($attr) || $ldap['DST']->isAttrHidden($attr)) + { continue; + } $attributeSRC = $request['templateSRC']->getAttribute($attr); $attributeDST = $request['templateDST']->getAttribute($attr); # Get the values and see if they are the same. if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues())) + { echo '
 '; @@ -126,7 +138,9 @@ foreach ($attrs_all as $attr) { case 'dst': if ($attributeDST) { if ($attributeSRC && ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID())) + { echo ' '; @@ -151,9 +165,13 @@ foreach ($attrs_all as $attr) { # Get the values and see if they are the same. if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues())) + { echo '
'; @@ -163,17 +181,25 @@ foreach ($attrs_all as $attr) { case 'src': if ($attributeSRC && count($attributeSRC->getValues())) - $request['pageSRC']->draw('CurrentValues',$attributeSRC); + { + $request['pageSRC']->draw('CurrentValues', $attributeSRC); + } else + { echo ' '; + } break; case 'dst': if ($attributeDST && count($attributeDST->getValues())) - $request['pageDST']->draw('CurrentValues',$attributeDST); + { + $request['pageDST']->draw('CurrentValues', $attributeDST); + } else + { echo ' '; + } break; } diff --git a/htdocs/compare_form.php b/htdocs/compare_form.php index 8e9070b..4018a9c 100644 --- a/htdocs/compare_form.php +++ b/htdocs/compare_form.php @@ -18,7 +18,9 @@ $request['dn'] = get_request('dn','GET'); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); $request['page']->setDN($request['dn']); diff --git a/htdocs/copy.php b/htdocs/copy.php index 04071c5..57cd2b4 100644 --- a/htdocs/copy.php +++ b/htdocs/copy.php @@ -22,20 +22,30 @@ $ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst')); # Error checking if (! trim($request['dnDST'])) - error(_('You left the destination DN blank.'),'error','index.php'); +{ + error(_('You left the destination DN blank.'), 'error', 'index.php'); +} if ($ldap['DST']->isReadOnly()) - error(_('Destination server is currently READ-ONLY.'),'error','index.php'); +{ + error(_('Destination server is currently READ-ONLY.'), 'error', 'index.php'); +} if ($ldap['DST']->dnExists($request['dnDST'])) - error(sprintf(_('The destination entry (%s) already exists.'),pretty_print_dn($request['dnDST'])),'error','index.php'); +{ + error(sprintf(_('The destination entry (%s) already exists.'), pretty_print_dn($request['dnDST'])), 'error', 'index.php'); +} if (! $ldap['DST']->dnExists($ldap['DST']->getContainer($request['dnDST']))) +{ error(sprintf(_('The destination container (%s) does not exist.'), - pretty_print_dn($ldap['DST']->getContainer($request['dnDST']))),'error','index.php'); + pretty_print_dn($ldap['DST']->getContainer($request['dnDST']))), 'error', 'index.php'); +} if (pla_compare_dns($request['dnSRC'],$request['dnDST']) == 0 && $ldap['SRC']->getIndex() == $ldap['DST']->getIndex()) - error(_('The source and destination DN are the same.'),'error','index.php'); +{ + error(_('The source and destination DN are the same.'), 'error', 'index.php'); +} $request['recursive'] = (get_request('recursive') == 'on') ? true : false; $request['remove'] = (get_request('remove') == 'yes') ? true : false; @@ -79,10 +89,13 @@ if ($request['recursive']) { # Set all attributes with a values as shown, and remove the add value options foreach ($request['templateDST']->getAttributes(true) as $sattribute) - if ($sattribute->getValues() && ! $sattribute->isInternal()) { + { + if ($sattribute->getValues() && ! $sattribute->isInternal()) + { $sattribute->show(); $sattribute->setMaxValueCount(count($sattribute->getValues())); } + } $request['pageDST']->accept(); @@ -92,13 +105,17 @@ if ($request['recursive']) { $copy_result = copy_dn($ldap['SRC'],$ldap['DST'],$request['dnSRC'],$request['dnDST'],$request['remove']); if ($copy_result) + { $copy_message = sprintf('%s %s: %s %s', $request['remove'] ? _('Move successful') : _('Copy successful'), - _('DN'),$request['dnDST'],_('has been created.')); + _('DN'), $request['dnDST'], _('has been created.')); + } else + { $copy_message = sprintf('%s %s: %s %s', $request['remove'] ? _('Move NOT successful') : _('Copy NOT successful'), - _('DN'),$request['dnDST'],_('has NOT been created.')); + _('DN'), $request['dnDST'], _('has NOT been created.')); + } } } @@ -115,7 +132,9 @@ if ($copy_result) { function r_copy_dn($serverSRC,$serverDST,$snapshottree,$dnSRC,$dnDST,$remove) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $copy_message = array(); @@ -127,7 +146,9 @@ function r_copy_dn($serverSRC,$serverDST,$snapshottree,$dnSRC,$dnDST,$remove) { $copy_result = copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,false); if (! $copy_result) - return false; + { + return FALSE; + } array_push($copy_message,sprintf('%s %s: %s %s',_('Copy successful'),_('DN'),$dnDST,_('has been created.'))); @@ -138,27 +159,35 @@ function r_copy_dn($serverSRC,$serverDST,$snapshottree,$dnSRC,$dnDST,$remove) { $copy_message = array_merge($copy_message,array_values($copy_result)); if (! $copy_result) - $hadError = true; + { + $hadError = TRUE; + } } if (! $hadError && $remove) { $delete_result = $serverSRC->delete($dnSRC); if ($delete_result) - array_push($copy_message,sprintf('%s %s: %s %s',_('Delete successful'),_('DN'),$dnDST,_('has been deleted.'))); + { + array_push($copy_message, sprintf('%s %s: %s %s', _('Delete successful'), _('DN'), $dnDST, _('has been deleted.'))); + } } } else { $copy_result = copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,$remove); if ($copy_result) - array_push($copy_message,sprintf('%s %s: %s %s', + { + array_push($copy_message, sprintf('%s %s: %s %s', $remove ? _('Move successful') : _('Copy successful'), - _('DN'),$dnDST,_('has been created.'))); + _('DN'), $dnDST, _('has been created.'))); + } else - array_push($copy_message,sprintf('%s %s: %s %s', + { + array_push($copy_message, sprintf('%s %s: %s %s', $remove ? _('Move NOT successful') : _('Copy NOT successful'), - _('DN'),$dnDST,_('has NOT been created.'))); + _('DN'), $dnDST, _('has NOT been created.'))); + } } return $copy_message; @@ -166,7 +195,9 @@ function r_copy_dn($serverSRC,$serverDST,$snapshottree,$dnSRC,$dnDST,$remove) { function copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,$remove) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $request = array(); $request['pageSRC'] = new PageRender($serverSRC->getIndex(),get_request('template','REQUEST',false,'none')); @@ -183,14 +214,20 @@ function copy_dn($serverSRC,$serverDST,$dnSRC,$dnDST,$remove) { # Create of move the entry if ($remove) - return $serverDST->rename($request['templateSRC']->getDN(),$request['templateDST']->getRDN(),$serverDST->getContainer($dnDST),true); + { + return $serverDST->rename($request['templateSRC']->getDN(), $request['templateDST']->getRDN(), $serverDST->getContainer($dnDST), TRUE); + } else - return $serverDST->add($request['templateDST']->getDN(),$request['templateDST']->getLDAPadd()); + { + return $serverDST->add($request['templateDST']->getDN(), $request['templateDST']->getLDAPadd()); + } } function build_tree($server,$dn,$buildtree) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # We search all children, not only the visible children in the tree $children = $server->getContainerContents($dn,null,0); @@ -198,11 +235,15 @@ function build_tree($server,$dn,$buildtree) { if (count($children)) { $buildtree[$dn] = $children; foreach ($children as $child_dn) - $buildtree = build_tree($server,$child_dn,$buildtree); + { + $buildtree = build_tree($server, $child_dn, $buildtree); + } } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$buildtree); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $buildtree); + } return $buildtree; } diff --git a/htdocs/copy_form.php b/htdocs/copy_form.php index ebe6086..7516668 100644 --- a/htdocs/copy_form.php +++ b/htdocs/copy_form.php @@ -17,7 +17,9 @@ $request['dn'] = get_request('dn','GET'); # Check if the entry exists. if (! $request['dn'] || ! $app['server']->dnExists($request['dn'])) - error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php'); +{ + error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); +} $request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); $request['page']->setDN($request['dn']); @@ -93,11 +95,14 @@ echo '
'; echo ''; if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints')) - printf('
Light%s
', - IMGDIR,_('Hint: Copying between different servers only works if there are no schema violations')); +{ + printf('
Light%s
', + IMGDIR,_('Hint: Copying between different servers only works if there are no schema violations')); } # Draw the javascrpt to enable/disable the filter field if this may be a recursive copy if (count($request['children']) > 0) - printf('',JSDIR); +{ + printf('', JSDIR); +} diff --git a/htdocs/create.php b/htdocs/create.php index 075f933..9e81e17 100644 --- a/htdocs/create.php +++ b/htdocs/create.php @@ -26,7 +26,9 @@ $request['page']->accept(); $request['template'] = $request['page']->getTemplate(); if ((! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) && ! get_request('create_base')) - error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php'); +{ + error(sprintf(_('The container you specified (%s) does not exist. Please try again.'), $request['template']->getContainer()), 'error', 'index.php'); +} # Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... $tree = get_cached_item($app['server']->getIndex(),'tree'); @@ -39,17 +41,23 @@ if (! $request['container'] && ! get_request('create_base')) { # Check our RDN if (! count($request['template']->getRDNAttrs())) - error(_('The were no attributes marked as an RDN attribute.'),'error','index.php'); +{ + error(_('The were no attributes marked as an RDN attribute.'), 'error', 'index.php'); +} if (! $request['template']->getRDN()) - error(_('The RDN field is empty?'),'error','index.php'); +{ + error(_('The RDN field is empty?'), 'error', 'index.php'); +} # Some other attribute checking... foreach ($request['template']->getAttributes() as $attribute) { # Check that our Required Attributes have a value - we shouldnt really return a hit here, the template engine shouldnt have allowed this to slip through. # @todo this isIgnoredAttr() function is missing? if ($attribute->isRequired() && ! count($attribute->getValues()) && ! $app['server']->isIgnoredAttr($attr->getName())) + { error(sprintf(_('You left the value blank for required attribute (%s).'), - $attribute->getName(false)),'error','index.php'); + $attribute->getName(FALSE)), 'error', 'index.php'); + } } # Create the entry @@ -60,25 +68,34 @@ if ($add_result) { $href = sprintf('cmd=template_engine&server_id=%s',$app['server']->getIndex()); if ($request['redirect']) + { $redirect_url = $request['redirect']; + } else if ($action_number == 2) + { $redirect_url = sprintf('cmd.php?%s&template=%s&container=%s', - $href,'default',$request['template']->getContainerEncode()); + $href, 'default', $request['template']->getContainerEncode()); + } else + { $redirect_url = sprintf('cmd.php?%s&template=%s&dn=%s', - $href,'default',$request['template']->getDNEncode()); + $href, 'default', $request['template']->getDNEncode()); + } if ($action_number == 1 || $action_number == 2) - printf('',$redirect_url); + { + printf('',$redirect_url); } if ($action_number == 1 || $action_number == 2) { $create_message = sprintf('%s %s: %s %s', _('Creation successful!'),_('DN'),$request['template']->getDN(),_('has been created.')); if (isAjaxEnabled()) - $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1',$app['server']->getIndex()); + { + $redirect_url .= sprintf('&refresh=SID_%s_nodes&noheader=1', $app['server']->getIndex()); + } system_message(array( 'title'=>_('Create Entry'), diff --git a/htdocs/create_confirm.php b/htdocs/create_confirm.php index 02e87ff..96b88c7 100644 --- a/htdocs/create_confirm.php +++ b/htdocs/create_confirm.php @@ -20,7 +20,9 @@ $request['page']->accept(); $request['template'] = $request['page']->getTemplate(); if (! $request['template']->getContainer() || ! $app['server']->dnExists($request['template']->getContainer())) - error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),$request['template']->getContainer()),'error','index.php'); +{ + error(sprintf(_('The container you specified (%s) does not exist. Please try again.'), $request['template']->getContainer()), 'error', 'index.php'); +} # Check if the container is a leaf - we shouldnt really return a hit here, the template engine shouldnt have allowed a user to attempt to create an entry... $tree = get_cached_item($app['server']->getIndex(),'tree'); @@ -33,17 +35,23 @@ if (! $request['container']) { # Check our RDN if (! count($request['template']->getRDNAttrs())) - error(_('The were no attributes marked as an RDN attribute.'),'error','index.php'); +{ + error(_('The were no attributes marked as an RDN attribute.'), 'error', 'index.php'); +} if (! $request['template']->getRDN()) - error(_('The RDN field is empty?'),'error','index.php'); +{ + error(_('The RDN field is empty?'), 'error', 'index.php'); +} # Some other attribute checking... foreach ($request['template']->getAttributes() as $attribute) { # Check that our Required Attributes have a value - we shouldnt really return a hit here, the template engine shouldnt have allowed this to slip through. # @todo this isIgnoredAttr() function is missing? if ($attribute->isRequired() && ! count($attribute->getValues()) && ! $app['server']->isIgnoredAttr($attr->getName())) + { error(sprintf(_('You left the value blank for required attribute (%s).'), - $attribute->getName(false)),'error','index.php'); + $attribute->getName(FALSE)), 'error', 'index.php'); + } } # Check for unique attributes @@ -68,7 +76,8 @@ if (count($request['template']->getLDAPadd(true))) { printf('',$request['template']->getContainerEncode(false)); printf('',$request['template']->getID()); foreach ($request['template']->getRDNAttrs() as $rdn) - printf('',htmlspecialchars($rdn)); + { + printf('',htmlspecialchars($rdn)); } echo "\n"; $request['page']->drawHiddenAttributes(); @@ -100,7 +109,9 @@ if (count($request['template']->getLDAPadd(true))) { $input_onclick = ''; if ($attribute->isRequired()) + { $input_disabled = 'disabled="disabled"'; + } printf('
 (%s) (%s)
 PlusPlus%s%s
%s'; foreach ($available_scopes as $id => $desc) +{ printf('
', - htmlspecialchars($id),$id,($id == $request['scope']) ? 'checked="checked"' : '', - htmlspecialchars($id),$desc); + htmlspecialchars($id), $id, ($id == $request['scope']) ? 'checked="checked"' : '', + htmlspecialchars($id), $desc); +} echo '
%s:
 %s
 %s
'; echo ''; diff --git a/htdocs/import_form.php b/htdocs/import_form.php index 9c7ed35..07bc201 100644 --- a/htdocs/import_form.php +++ b/htdocs/import_form.php @@ -13,7 +13,9 @@ require './common.php'; if (! ini_get('file_uploads')) - error(_('Your PHP.INI does not have file_uploads = ON. Please enable file uploads in PHP.'),'error','index.php'); +{ + error(_('Your PHP.INI does not have file_uploads = ON. Please enable file uploads in PHP.'), 'error', 'index.php'); +} $request['page'] = new PageRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none')); $request['page']->drawTitle(sprintf('%s',_('Import'))); diff --git a/htdocs/index.php b/htdocs/index.php index c847e1a..634b208 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -33,72 +33,104 @@ error_reporting(-1); # General functions needed to proceed. ob_start(); if (! file_exists(LIBDIR.'functions.php')) { - if (ob_get_level()) ob_end_clean(); + if (ob_get_level()) + { + ob_end_clean(); + } die(sprintf("Fatal error: Required file '%sfunctions.php' does not exist.",LIBDIR)); } if (! is_readable(LIBDIR.'functions.php')) { - if (ob_get_level()) ob_end_clean(); + if (ob_get_level()) + { + ob_end_clean(); + } die(sprintf("Cannot read the file '%sfunctions.php' its permissions may be too strict.",LIBDIR)); } if (ob_get_level()) +{ ob_end_clean(); +} # Make sure this PHP install has pcre if (! extension_loaded('pcre')) +{ die('

Your install of PHP appears to be missing PCRE support.

Please install PCRE support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)

'); +} require LIBDIR.'functions.php'; spl_autoload_register("autoload"); # Define the path to our configuration file. if (defined('CONFDIR')) - $app['config_file'] = CONFDIR.'config.php'; +{ + $app['config_file'] = CONFDIR . 'config.php'; +} else +{ $app['config_file'] = 'config.php'; +} # Make sure this PHP install has session support if (! extension_loaded('session')) - error('

Your install of PHP appears to be missing php-session support.

Please install php-session support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)

','error',null,true); +{ + error('

Your install of PHP appears to be missing php-session support.

Please install php-session support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)

', 'error', NULL, TRUE); +} # Make sure this PHP install has gettext, we use it for language translation if (! extension_loaded('gettext')) +{ system_message(array( - 'title'=>_('Missing required extension'), - 'body'=>'Your install of PHP appears to be missing GETTEXT support.

GETTEXT is used for language translation.

Please install GETTEXT support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', - 'type'=>'error')); + 'title' => _('Missing required extension'), + 'body' => 'Your install of PHP appears to be missing GETTEXT support.

GETTEXT is used for language translation.

Please install GETTEXT support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', + 'type' => 'error')); +} # Make sure this PHP install has all our required extensions if (! extension_loaded('ldap')) +{ system_message(array( - 'title'=>_('Missing required extension'), - 'body'=>'Your install of PHP appears to be missing LDAP support.

Please install LDAP support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', - 'type'=>'error')); + 'title' => _('Missing required extension'), + 'body' => 'Your install of PHP appears to be missing LDAP support.

Please install LDAP support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', + 'type' => 'error')); +} # Make sure that we have php-xml loaded. if (! function_exists('xml_parser_create')) +{ system_message(array( - 'title'=>_('Missing required extension'), - 'body'=>'Your install of PHP appears to be missing XML support.

Please install XML support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', - 'type'=>'error')); + 'title' => _('Missing required extension'), + 'body' => 'Your install of PHP appears to be missing XML support.

Please install XML support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)', + 'type' => 'error')); +} /** * Helper functions. * Our required helper functions are defined in functions.php */ if (isset($app['function_files']) && is_array($app['function_files'])) - foreach ($app['function_files'] as $file_name ) { - if (! file_exists($file_name)) - error(sprintf('Fatal error: Required file "%s" does not exist.',$file_name),'error',null,true); +{ + foreach ($app['function_files'] as $file_name) + { + if ( ! file_exists($file_name)) + { + error(sprintf('Fatal error: Required file "%s" does not exist.', $file_name), 'error', NULL, TRUE); + } - if (! is_readable($file_name)) - error(sprintf('Fatal error: Cannot read the file "%s", its permissions may be too strict.',$file_name),'error',null,true); + if ( ! is_readable($file_name)) + { + error(sprintf('Fatal error: Cannot read the file "%s", its permissions may be too strict.', $file_name), 'error', NULL, TRUE); + } ob_start(); require $file_name; - if (ob_get_level()) ob_end_clean(); + if (ob_get_level()) + { + ob_end_clean(); + } } +} # Configuration File check if (! file_exists($app['config_file'])) { @@ -122,7 +154,9 @@ if (! $config = check_config($app['config_file'])) { } if ($uri = get_request('URI','GET')) - header(sprintf('Location: cmd.php?%s',base64_decode($uri))); +{ + header(sprintf('Location: cmd.php?%s', base64_decode($uri))); +} if (! preg_match('/^([0-9]+\.?)+/',app_version())) { system_message(array( @@ -131,17 +165,21 @@ if (! preg_match('/^([0-9]+\.?)+/',app_version())) { 'type'=>'info','special'=>true)); if (count($_SESSION[APPCONFIG]->untested())) + { system_message(array( - 'title'=>'Untested configuration paramaters', - 'body'=>sprintf('The following parameters have not been tested. If you have configured these parameters, and they are working as expected, please let the developers know, so that they can be removed from this message.
%s',implode(', ',$_SESSION[APPCONFIG]->untested())), - 'type'=>'info','special'=>true)); + 'title' => 'Untested configuration paramaters', + 'body' => sprintf('The following parameters have not been tested. If you have configured these parameters, and they are working as expected, please let the developers know, so that they can be removed from this message.
%s', implode(', ', $_SESSION[APPCONFIG]->untested())), + 'type' => 'info', 'special' => TRUE)); + } $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); if (count($server->untested())) + { system_message(array( - 'title'=>'Untested server configuration paramaters', - 'body'=>sprintf('The following parameters have not been tested. If you have configured these parameters, and they are working as expected, please let the developers know, so that they can be removed from this message.
%s',implode(', ',$server->untested())), - 'type'=>'info','special'=>true)); + 'title' => 'Untested server configuration paramaters', + 'body' => sprintf('The following parameters have not been tested. If you have configured these parameters, and they are working as expected, please let the developers know, so that they can be removed from this message.
%s', implode(', ', $server->untested())), + 'type' => 'info', 'special' => TRUE)); + } } include './cmd.php'; diff --git a/htdocs/login.php b/htdocs/login.php index 600feca..19b3866 100644 --- a/htdocs/login.php +++ b/htdocs/login.php @@ -16,22 +16,28 @@ $user['login'] = get_request('login'); $user['password'] = get_request('login_pass'); if ($user['login'] && ! strlen($user['password'])) +{ system_message(array( - 'title'=>_('Authenticate to server'), - 'body'=>_('You left the password blank.'), - 'type'=>'warn'), - sprintf('cmd.php?cmd=login_form&server_id=%s',get_request('server_id','REQUEST'))); + 'title' => _('Authenticate to server'), + 'body' => _('You left the password blank.'), + 'type' => 'warn'), + sprintf('cmd.php?cmd=login_form&server_id=%s', get_request('server_id', 'REQUEST'))); +} if ($app['server']->login($user['login'],$user['password'],'user')) +{ system_message(array( - 'title'=>_('Authenticate to server'), - 'body'=>_('Successfully logged into server.'), - 'type'=>'info'), - sprintf('cmd.php?server_id=%s',get_request('server_id','REQUEST'))); + 'title' => _('Authenticate to server'), + 'body' => _('Successfully logged into server.'), + 'type' => 'info'), + sprintf('cmd.php?server_id=%s', get_request('server_id', 'REQUEST'))); +} else +{ system_message(array( - 'title'=>_('Failed to Authenticate to server'), - 'body'=>_('Invalid Username or Password.'), - 'type'=>'error'), - sprintf('cmd.php?cmd=login_form&server_id=%s',get_request('server_id','REQUEST'))); + 'title' => _('Failed to Authenticate to server'), + 'body' => _('Invalid Username or Password.'), + 'type' => 'error'), + sprintf('cmd.php?cmd=login_form&server_id=%s', get_request('server_id', 'REQUEST'))); +} diff --git a/htdocs/login_form.php b/htdocs/login_form.php index 6cecf6a..cca6f4c 100644 --- a/htdocs/login_form.php +++ b/htdocs/login_form.php @@ -44,9 +44,13 @@ if ($app['server']->getAuthType() == 'http') { header(sprintf('WWW-Authenticate: Basic realm="%s"',$_SESSION[APPCONFIG]->getValue('session','http_realm'))); if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0') - header('HTTP/1.0 401 Unauthorized'); // http 1.0 method + { + header('HTTP/1.0 401 Unauthorized'); + } // http 1.0 method else - header('Status: 401 Unauthorized'); // http 1.1 method + { + header('Status: 401 Unauthorized'); + } // http 1.1 method return; @@ -59,7 +63,8 @@ if ($app['server']->getAuthType() == 'http') { echo ''; if (get_request('redirect','GET',false,false)) - printf('',rawurlencode(get_request('redirect','GET'))); + { + printf('',rawurlencode(get_request('redirect', 'GET'))); } echo '

'; @@ -79,8 +84,10 @@ if ($app['server']->getAuthType() == 'http') { # If Anon bind allowed, then disable the form if the user choose to bind anonymously. if ($app['server']->isAnonBindAllowed()) + { printf('%s ', _('Anonymous')); + } printf('', _('Authenticate')); @@ -93,6 +100,8 @@ if ($app['server']->getAuthType() == 'http') { echo ''; if ($app['server']->isAnonBindAllowed()) - printf('',JSDIR); + { + printf('', JSDIR); + } } diff --git a/htdocs/logout.php b/htdocs/logout.php index d6451fa..dde190b 100644 --- a/htdocs/logout.php +++ b/htdocs/logout.php @@ -21,9 +21,11 @@ if ($app['server']->logout()) { sprintf('index.php?server_id=%s',$app['server']->getIndex())); } else +{ system_message(array( - 'title'=>_('Failed to Logout of server'), - 'body'=>_('Please report this error to the admins.'), - 'type'=>'error'), - sprintf('index.php?server_id=%s',$app['server']->getIndex())); + 'title' => _('Failed to Logout of server'), + 'body' => _('Please report this error to the admins.'), + 'type' => 'error'), + sprintf('index.php?server_id=%s', $app['server']->getIndex())); +} diff --git a/htdocs/mass_delete.php b/htdocs/mass_delete.php index ff19076..dd7e8ac 100644 --- a/htdocs/mass_delete.php +++ b/htdocs/mass_delete.php @@ -16,23 +16,29 @@ $request = array(); $request['dn'] = get_request('dn','REQUEST'); if (! $request['dn']) +{ system_message(array( - 'title'=>_('No entry selected'), - 'body'=>_('No entry was selected to delete'), - 'type'=>'warn'),'index.php'); + 'title' => _('No entry selected'), + 'body' => _('No entry was selected to delete'), + 'type' => 'warn'), 'index.php'); +} if (! is_array($request['dn'])) +{ $request['dn'] = array($request['dn']); +} $request['children'] = array(); $request['parent'] = array(); foreach ($request['dn'] as $dn) { # Check if the entry exists. if (! $dn || ! $app['server']->dnExists($dn)) + { system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s/%s)',_('The entry does not exist and will be ignored'),$dn), - 'type'=>'error')); + 'title' => _('Entry does not exist'), + 'body' => sprintf('%s (%s/%s)', _('The entry does not exist and will be ignored'), $dn), + 'type' => 'error')); + } # We search all children, not only the visible children in the tree if (! in_array_ignore_case($dn,$request['children'])) { @@ -49,16 +55,21 @@ echo '
'; echo ''; if (count($request['parent']) == 1) - printf('',_('Are you sure you want to permanently delete this object?')); +{ + printf('',_('Are you sure you want to permanently delete this object?')); } else - printf('',_('Are you sure you want to permanently delete these objects?')); +{ + printf('', _('Are you sure you want to permanently delete these objects?')); +} echo ''; printf('',_('Server'),$app['server']->getName()); foreach ($request['parent'] as $dn) +{ printf('', - _('Distinguished Name'),_('DN'),$dn); + _('Distinguished Name'), _('DN'), $dn); +} echo ''; @@ -82,7 +93,9 @@ if (count($request['children'])) { } foreach ($request['search'] as $value) - array_push($request['delete'],$value['dn']); + { + array_push($request['delete'], $value['dn']); + } echo ''; echo ''; echo "\n"; @@ -123,7 +138,9 @@ echo ''; echo ''; printf('',$app['server']->getIndex()); foreach ($request['parent'] as $dn) - printf('',htmlspecialchars($dn)); +{ + printf('', htmlspecialchars($dn)); +} printf('',sprintf(_('Delete all %s objects'),count($request['delete']))); echo ''; echo ''; diff --git a/htdocs/mass_edit.php b/htdocs/mass_edit.php index a66c7f2..0f7953f 100644 --- a/htdocs/mass_edit.php +++ b/htdocs/mass_edit.php @@ -40,14 +40,18 @@ foreach ($request['dn'] as $dn) { # Mark our attributes to edit as shown. foreach ($template->getAttributes(true) as $attribute) { if ($attribute->isInternal()) + { continue; + } if (in_array_ignore_case($attribute->getName(),$request['attrs']) || in_array('*',$request['attrs'])) { $attribute->show(); # Get a list of our columns (we are not interested in these attribute values) if (! isset($attrcols[$attribute->getName()])) + { $attrcols[$attribute->getName()] = $attribute; + } } } @@ -57,7 +61,9 @@ foreach ($request['dn'] as $dn) { usort($attrcols,'sortAttrs'); if (! count($request['page'])) +{ header('Location: index.php'); +} # We'll render this forms Title with the first DN's object. $request['page'][0]->drawTitle(_('Bulk edit the following DNs')); @@ -69,7 +75,8 @@ echo ''; printf('',$app['server']->getIndex()); foreach ($request['page'] as $j => $page) - printf('',$j,$page->getTemplate()->getDN()); +{ + printf('',$j,$page->getTemplate()->getDN()); } echo ''; @@ -99,7 +106,9 @@ foreach ($request['page'] as $j => $page) { echo ''; diff --git a/htdocs/mass_update.php b/htdocs/mass_update.php index b75c398..fbdd59a 100644 --- a/htdocs/mass_update.php +++ b/htdocs/mass_update.php @@ -32,7 +32,9 @@ foreach ($request['dn'] as $index => $dn) { # Simulate the requirements for *Render->accept() if (! isset($request['mass_values'][$index])) + { continue; + } $_REQUEST['new_values'] = $request['mass_values'][$index]; @@ -41,7 +43,9 @@ foreach ($request['dn'] as $index => $dn) { $render->accept(true); if ($render->getTemplate()->getLDAPmodify(false,$index)) + { $request['update'][$index] = $render; + } } # We can use the $render to give us a title @@ -57,9 +61,13 @@ if (count($request['update'])) { $result = $app['server']->modify($template->getDN(),$template->getLDAPmodify(false,$index)); if ($result) - printf('%s: %s
',$template->getDN(),_('Modification successful!')); + { + printf('%s: %s
', $template->getDN(), _('Modification successful!')); + } else - printf('%s: %s
',$template->getDN(),_('Modification NOT successful!')); + { + printf('%s: %s
', $template->getDN(), _('Modification NOT successful!')); + } } } else { @@ -69,7 +77,9 @@ if (count($request['update'])) { echo ''; foreach ($request['update'] as $j => $page) - printf('',$j,$page->getTemplate()->getDN()); + { + printf('', $j, $page->getTemplate()->getDN()); + } echo '
%s
%s
%s
%s
 
%s:%s
%s%s
 
'; @@ -109,7 +122,9 @@ if (count($request['children'])) { echo '
'; printf(''; echo '
'; if ($attribute) { foreach ($attribute->getValues() as $i => $val) - $page->draw('MassFormReadWriteValue',$attribute,$i,$j); + { + $page->draw('MassFormReadWriteValue', $attribute, $i, $j); + } # The attribute doesnt exist. If it is available by the shema, we can draw an empty input box. } else { @@ -115,7 +124,9 @@ foreach ($request['page'] as $j => $page) { } if (! $match) + { printf('
%s
', _('Attribute not available')); + } } echo '
'; echo '', - $this->getDepth()+3-3,_('This base cannot be created with PLA.')); + $this->getDepth() + 3 - 3, _('This base cannot be created with PLA.')); + } else + { printf('', - $this->getDepth()+3-3,_('This base entry does not exist.'),$server->getIndex(),$javascript_id,_('Create it?')); + $this->getDepth() + 3 - 3, _('This base entry does not exist.'), $server->getIndex(), $javascript_id, _('Create it?')); + } } else { $this->draw_item($base->getDN(),-1); @@ -121,7 +139,9 @@ class HTMLTree extends Tree { echo '
'; @@ -117,13 +127,17 @@ if (count($request['update'])) { foreach ($attribute->getValues() as $key => $value) { # For multiple values, we'll highlight the changed ones if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues())) + { echo ''; + } $page->draw('CurrentValue',$attribute,$key); # For multiple values, close the highlighting if ((count($attribute->getValues()) > 5) && in_array($value,$attribute->getAddedValues())) + { echo ''; + } echo '
'; printf('',$index,$attribute->getName(),$key,$value); @@ -135,18 +149,24 @@ if (count($request['update'])) { echo '
'; if (! $attribute->getOldValues()) - printf('[%s]',_('attribute doesnt exist')); + { + printf('[%s]', _('attribute doesnt exist')); + } foreach ($attribute->getOldValues() as $key => $value) { # For multiple values, we'll highlight the changed ones if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues())) + { echo ''; + } $page->draw('OldValue',$attribute,$key); # For multiple values, close the highlighting if ((count($attribute->getOldValues()) > 5) && in_array($value,$attribute->getRemovedValues()) && count($attribute->getValues())) + { echo ''; + } echo '
'; } diff --git a/htdocs/modify_member_form.php b/htdocs/modify_member_form.php index 6a22f97..2e5bf73 100644 --- a/htdocs/modify_member_form.php +++ b/htdocs/modify_member_form.php @@ -22,9 +22,13 @@ $request['page']->accept(true); $request['template'] = $request['page']->getTemplate(); if (! is_null($request['dn'])) +{ $rdn = get_rdn($request['dn']); +} else - $rdn = null; +{ + $rdn = NULL; +} # Get all current group members $current_members = $app['server']->getDNAttrValue($request['dn'],$request['attr']); @@ -63,9 +67,13 @@ printf('%s %s %s %s:', $possible_members = array(); for ($i=0;$igetValue('modify_member','posixgroupattr'))) - $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','posixattr')][0]; + { + $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member', 'posixattr')][0]; + } else - $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','attr')]; + { + $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member', 'attr')]; + } } # Show only user that are not already in group. @@ -82,9 +90,12 @@ echo '
'; echo '
'; echo '
'; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) - echo ''; +{ + echo ''; } else +{ echo ''; +} echo '
'; echo ''; @@ -107,7 +118,9 @@ switch ($request['attr']) { $possible = sprintf('(,%s,)',$matches[1]); if (! in_array($possible,$current_members)) - printf('',$possible); + { + printf('', $possible); + } } break; @@ -115,7 +128,9 @@ switch ($request['attr']) { case ('memberuid' || 'member' || 'uniquemember'): foreach ($possible_members as $possible) { if (! in_array($possible,$current_members)) - printf('',$possible); + { + printf('', $possible); + } } break; @@ -129,7 +144,9 @@ echo ''; @@ -158,8 +175,10 @@ printf('',$request['attr']); /* Generate array of input text boxes from current members. * update_confirm.php will see this as old_values[member-attribute][item] */ for ($i=0; $i', - htmlspecialchars($request['attr']),$i,htmlspecialchars($current_members[$i])); + htmlspecialchars($request['attr']), $i, htmlspecialchars($current_members[$i])); +} /* Javascript generates array of input text boxes from new members. * update_confirm.php will see this as new_values[member-attribute][item] diff --git a/htdocs/monitor.php b/htdocs/monitor.php index aeb71e7..a669f8e 100644 --- a/htdocs/monitor.php +++ b/htdocs/monitor.php @@ -20,10 +20,12 @@ $query['attrs'] = array('+','*'); $results = $app['server']->query($query,null); if (! isset($attrs['monitorcontext']) || ! count($results)) +{ system_message(array( - 'title'=>_('Monitoring context does not exist'), - 'body'=>sprintf('%s: %s',_('Could not obtain the monitor context for this server'),$app['server']->getName()), - 'type'=>'warn'),'index.php'); + 'title' => _('Monitoring context does not exist'), + 'body' => sprintf('%s: %s', _('Could not obtain the monitor context for this server'), $app['server']->getName()), + 'type' => 'warn'), 'index.php'); +} printf('

%s%s

',_('Monitor info for: '),$app['server']->getName()); printf('

%s

',_('Server reports the following information about itself')); @@ -67,7 +69,9 @@ foreach (array( printf('
',_('Type'),'namingContext'); foreach ($attrs as $attr) - printf('',$attr); + { + printf('', $attr); + } echo ''; @@ -83,12 +87,17 @@ foreach (array( $seealso = is_array($results[$key]['seealso']) ? $results[$key]['seealso'] : array($results[$key]['seealso']); foreach ($seealso as $db) + { if (isset($results[$db]['namingcontexts'])) + { printf('%s
', - isset($results[$db]['labeleduri']) ? implode(' ',$results[$db]['labeleduri']) : _('Internal'), - implode(' ',$results[$db]['namingcontexts'])); - else - printf('%s ',implode(' ',$results[$db]['monitoredinfo'])); + isset($results[$db]['labeleduri']) ? implode(' ', $results[$db]['labeleduri']) : _('Internal'), + implode(' ', $results[$db]['namingcontexts'])); + } else + { + printf('%s ', implode(' ', $results[$db]['monitoredinfo'])); + } + } } else { echo ' '; @@ -99,20 +108,29 @@ foreach (array( echo ''; + } echo '
'; echo ''; echo '%s%s%s%s
'; if (isset($results[$key][$attr])) { if (! is_array($results[$key][$attr])) + { $sc = array($results[$key][$attr]); + } else + { $sc = $results[$key][$attr]; + } if (strcasecmp('supportedcontrol',$attr) == 0) - foreach ($sc as $control) { + { + foreach ($sc as $control) + { $oidtotext = support_oid_to_text($control); printf('%s
', - $control,$oidtotext['title']); + $control, $oidtotext['title']); } + } else - printf('%s ',implode('
',$sc)); + { + printf('%s ', implode('
', $sc)); + } } else { echo ' '; @@ -207,14 +225,20 @@ foreach (array( echo ''; if (isset($results[$dn]['monitoropinitiated'])) + { printf('', - 'monitorOpInitiated',$results[$dn]['monitoropinitiated'][0]); + 'monitorOpInitiated', $results[$dn]['monitoropinitiated'][0]); + } if (isset($results[$dn]['monitoropcompleted'])) + { printf('', - 'monitorOpCompleted',$results[$dn]['monitoropcompleted'][0]); + 'monitorOpCompleted', $results[$dn]['monitoropcompleted'][0]); + } if (isset($results[$dn]['monitoredinfo'])) + { printf('', - 'monitoredInfo',$results[$dn]['monitoredinfo'][0]); + 'monitoredInfo', $results[$dn]['monitoredinfo'][0]); + } # Look for some connecitons foreach ($results as $key => $value) { diff --git a/htdocs/password_checker.php b/htdocs/password_checker.php index e5f97fa..5203f03 100644 --- a/htdocs/password_checker.php +++ b/htdocs/password_checker.php @@ -56,9 +56,13 @@ if ($request['action'] == 'compare') { echo '    '; if (password_check($request['hash'],$request['password'],$request['attribute'])) - printf('%s',_('Passwords match!')); + { + printf('%s', _('Passwords match!')); + } else - printf('%s',_('Passwords do not match!')); + { + printf('%s', _('Passwords do not match!')); + } echo ''; } diff --git a/htdocs/purge_cache.php b/htdocs/purge_cache.php index 92bba75..4289209 100644 --- a/htdocs/purge_cache.php +++ b/htdocs/purge_cache.php @@ -15,15 +15,22 @@ $purge_session_keys = array('app_initialized','backtrace','cache',APPCONFIG); $size = 0; foreach ($purge_session_keys as $key) - if (isset($_SESSION[$key])) { +{ + if (isset($_SESSION[$key])) + { $size += strlen(serialize($_SESSION[$key])); unset($_SESSION[$key]); } +} if (! $size) +{ $body = _('No cache to purge.'); +} else - $body = sprintf(_('Purged %s bytes of cache.'),number_format($size)); +{ + $body = sprintf(_('Purged %s bytes of cache.'), number_format($size)); +} system_message(array( 'title'=>_('Purge cache'), diff --git a/htdocs/rdelete.php b/htdocs/rdelete.php index ae6624c..1368354 100644 --- a/htdocs/rdelete.php +++ b/htdocs/rdelete.php @@ -15,17 +15,24 @@ $request = array(); $request['dn'] = get_request('dn','REQUEST',true); if (! is_array($request['dn'])) +{ $request['dn'] = array($request['dn']); +} $request['parent'] = array(); foreach ($request['dn'] as $dn) - if (! $app['server']->dnExists($dn)) +{ + if ( ! $app['server']->dnExists($dn)) + { system_message(array( - 'title'=>_('Entry does not exist'), - 'body'=>sprintf('%s (%s)',_('Unable to delete entry, it does not exist'),$dn), - 'type'=>'error')); - else - array_push($request['parent'],$dn); + 'title' => _('Entry does not exist'), + 'body' => sprintf('%s (%s)', _('Unable to delete entry, it does not exist'), $dn), + 'type' => 'error')); + } else + { + array_push($request['parent'], $dn); + } +} printf('

%s

',_('Delete LDAP entries')); printf('

%s

',_('Recursive delete progress')); @@ -70,7 +77,9 @@ function pla_rdelete($server,$dn) { } else { foreach ($children as $child_dn) - pla_rdelete($server,$child_dn); + { + pla_rdelete($server, $child_dn); + } printf('%s %s...',_('Deleting'),$dn); diff --git a/htdocs/refresh.php b/htdocs/refresh.php index 072a62c..4db8150 100644 --- a/htdocs/refresh.php +++ b/htdocs/refresh.php @@ -17,9 +17,13 @@ if (get_request('purge','REQUEST')) { del_cached_item($app['server']->getIndex(),'tree'); if ($tree) + { $openDNs = $tree->listOpenItems(); + } else + { $openDNs = array(); + } $tree = Tree::getInstance($app['server']->getIndex()); @@ -37,10 +41,14 @@ if (get_request('purge','REQUEST')) { set_cached_item($app['server']->getIndex(),'tree','null',$tree); } -if (get_request('meth','REQUEST') == 'ajax') - header(sprintf('Location: cmd.php?cmd=draw_tree_node&noheader=%s&server_id=%s&meth=ajax&frame=TREE',get_request('noheader','REQUEST',false,0),$app['server']->getIndex())); +if (get_request('meth','REQUEST') == 'ajax') +{ + header(sprintf('Location: cmd.php?cmd=draw_tree_node&noheader=%s&server_id=%s&meth=ajax&frame=TREE', get_request('noheader', 'REQUEST', FALSE, 0), $app['server']->getIndex())); +} else - header(sprintf('Location: cmd.php?server_id=%s',$app['server']->getIndex())); +{ + header(sprintf('Location: cmd.php?server_id=%s', $app['server']->getIndex())); +} die(); diff --git a/htdocs/rename.php b/htdocs/rename.php index 6af59fb..eab4440 100644 --- a/htdocs/rename.php +++ b/htdocs/rename.php @@ -23,13 +23,17 @@ if (! $app['server']->isBranchRenameEnabled()) { $children = $app['server']->getContainerContents($request['dnSRC'],null,0,'(objectClass=*)',LDAP_DEREF_NEVER); if (count($children) > 0) - error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'),'error','index.php'); + { + error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'), 'error', 'index.php'); + } } $request['dnDST'] = sprintf('%s,%s',$request['rdnDST'],$request['container']); if ($request['dnDST'] == $request['dnSRC']) - error(_('You did not change the RDN'),'error','index.php'); +{ + error(_('You did not change the RDN'), 'error', 'index.php'); +} $rdnattr = array(); $rdnattr['SRC'] = explode('=',$request['dnSRC']); @@ -39,7 +43,9 @@ $new_dn_value = explode('=',$request['rdnDST'],2); $rdnattr['DST'] = $new_dn_value[0]; if (count($new_dn_value) != 2 || ! isset($new_dn_value[1])) - error(_('Invalid RDN value'),'error','index.php'); +{ + error(_('Invalid RDN value'), 'error', 'index.php'); +} $deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST']; $success = $app['server']->rename($request['dnSRC'],$request['rdnDST'],$request['container'],$deleteoldrdn); diff --git a/htdocs/schema.php b/htdocs/schema.php index a54f95c..0b50641 100644 --- a/htdocs/schema.php +++ b/htdocs/schema.php @@ -48,7 +48,9 @@ echo '
'; $counter = 0; foreach ($entry['schema_types'] as $item => $value) { if ($counter++) + { echo ' | '; + } $entry['href'][$item] = sprintf('cmd=schema&server_id=%s&view=%s',$app['server']->getIndex(),$item); @@ -57,10 +59,13 @@ foreach ($entry['schema_types'] as $item => $value) { } else { if (isAjaxEnabled()) - printf('%s', - htmlspecialchars($entry['href'][$item]),htmlspecialchars($entry['href'][$item]),$value,$value,$value); + { + printf('%s', + htmlspecialchars($entry['href'][$item]),htmlspecialchars($entry['href'][$item]),$value,$value,$value); } else - printf('%s',htmlspecialchars($entry['href'][$item]),_($value)); + { + printf('%s', htmlspecialchars($entry['href'][$item]), _($value)); + } } } @@ -78,7 +83,9 @@ switch($entry['view']) { $schema_syntaxes = $app['server']->SchemaSyntaxes(); if (! $schema_syntaxes) - error($schema_error_str,'error','index.php'); + { + error($schema_error_str, 'error', 'index.php'); + } foreach ($schema_syntaxes as $syntax) { $counter++; @@ -86,10 +93,14 @@ switch($entry['view']) { $desc = $syntax->getDescription(); if ($highlight_oid && $highlight_oid == $oid) + { echo '
'; + } else - printf('',$counter%2==0?'even':'odd'); + { + printf('', $counter % 2 == 0 ? 'even' : 'odd'); + } printf('',$oid,$desc); } @@ -119,7 +130,9 @@ switch($entry['view']) { $sattrs = $app['server']->SchemaAttributes(); if (! $sattrs || ! $app['server']->SchemaObjectClasses()) - error($schema_error_str,'error','index.php'); + { + error($schema_error_str, 'error', 'index.php'); + } printf('%s:',_('Jump to an attribute type')); echo ''; @@ -132,18 +145,26 @@ switch($entry['view']) { drawJSItems($sattrs); echo ''; + } echo ''; foreach ($sattrs as $name => $attr) + { printf('', - $name,$name == $entry['value'] ? 'selected="selected" ': '',$attr->getName(false)); + $name, $name == $entry['value'] ? 'selected="selected" ' : '', $attr->getName(FALSE)); + } echo ''; if (isAjaxEnabled()) - printf('',_('Go')); + { + printf('', _('Go')); + } else - printf('',_('Go')); + { + printf('', _('Go')); + } echo ''; echo ''; echo '
'; @@ -151,12 +172,18 @@ switch($entry['view']) { foreach ($sattrs as $attr) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$attr->getName())) { if ((! is_null($entry['value']) && $entry['value']==$attr->getName()) || ! trim($entry['value'])) - $entry['viewed'] = true; + { + $entry['viewed'] = TRUE; + } if (isAjaxEnabled() && $entry['value']) - printf('
',$attr->getName(),strcasecmp($entry['value'],$attr->getName()) ? 'none' : 'block'); + { + printf('
', $attr->getName(), strcasecmp($entry['value'], $attr->getName()) ? 'none' : 'block'); + } else - printf('
',$attr->getName()); + { + printf('
', $attr->getName()); + } echo '
%s%s
%s%s
%s%s
%s%s
'; printf('', @@ -190,15 +217,21 @@ switch($entry['view']) { echo ''; @@ -208,15 +241,21 @@ switch($entry['view']) { echo ''; @@ -241,10 +280,14 @@ switch($entry['view']) { } else { $href = htmlspecialchars(sprintf('%s&highlight_oid=%s',$entry['href']['syntaxes'],$attr->getSyntaxOID())); if (isAjaxEnabled()) + { printf('%s (%s)', - $href,$href,_('Syntaxes'),'',$attr->getType(),$attr->getSyntaxOID()); + $href, $href, _('Syntaxes'), '', $attr->getType(), $attr->getSyntaxOID()); + } else - printf('%s (%s)',$href,$attr->getType(),$attr->getSyntaxOID()); + { + printf('%s (%s)', $href, $attr->getType(), $attr->getSyntaxOID()); + } } echo ''; @@ -270,11 +313,15 @@ switch($entry['view']) { echo ''; break; @@ -283,17 +330,25 @@ switch($entry['view']) { echo ''; break; @@ -302,17 +357,25 @@ switch($entry['view']) { echo ''; break; @@ -335,7 +398,9 @@ switch($entry['view']) { case 'matching_rules': $schema_matching_rules = $app['server']->MatchingRules(); if (! $schema_matching_rules) - error($schema_error_str,'error','index.php'); + { + error($schema_error_str, 'error', 'index.php'); + } printf('%s
',_('Jump to a matching rule')); @@ -349,21 +414,29 @@ switch($entry['view']) { drawJSItems($schema_matching_rules); echo ''; + } echo ''; foreach ($schema_matching_rules as $rule) + { printf('', $rule->getName(), - ($rule->getName() == $entry['value'] ? 'selected="selected"': ''), - $rule->getName(false)); + ($rule->getName() == $entry['value'] ? 'selected="selected"' : ''), + $rule->getName(FALSE)); + } echo ''; if (isAjaxEnabled()) - printf('',_('Go')); + { + printf('', _('Go')); + } else - printf('',_('Go')); + { + printf('', _('Go')); + } echo ''; echo ''; echo '
'; @@ -381,19 +454,29 @@ switch($entry['view']) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$rule->getName())) { if ((! is_null($entry['value']) && $entry['value']==$rule->getName()) || ! trim($entry['value'])) - $entry['viewed'] = true; + { + $entry['viewed'] = TRUE; + } if (null != $rule->getDescription()) - $desc .= sprintf(' (%s)',$rule->getDescription()); + { + $desc .= sprintf(' (%s)', $rule->getDescription()); + } if ( $rule->getIsObsolete()) - $desc .= sprintf(' %s',_('Obsolete')); + { + $desc .= sprintf(' %s', _('Obsolete')); + } if (isAjaxEnabled() && $entry['value']) - printf('',$counter%2 ? 'odd' : 'even',$rule->getName(), - strcasecmp($entry['value'],$rule->getName()) ? 'none' : ''); + { + printf('', $counter % 2 ? 'odd' : 'even', $rule->getName(), + strcasecmp($entry['value'], $rule->getName()) ? 'none' : ''); + } else - printf('',$counter%2 ? 'odd' : 'even',$rule->getName()); + { + printf('', $counter % 2 ? 'odd' : 'even', $rule->getName()); + } printf('',$oid); printf('',$desc); @@ -412,14 +495,20 @@ switch($entry['view']) { printf('
'; if (isAjaxEnabled()) + { printf('', - _('Go'),$app['server']->getIndex(),_('Attributes'),$rule->getName()); + _('Go'), $app['server']->getIndex(), _('Attributes'), $rule->getName()); + } else - printf('',_('Go')); + { + printf('', _('Go')); + } echo ''; echo ''; echo '
%s
'; if (is_null($attr->getSupAttribute())) - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } else { $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['attributes'],strtolower($attr->getSupAttribute()))); if (isAjaxEnabled()) + { printf('%s', - $href,strtolower($attr->getSupAttribute()),$attr->getSupAttribute()); + $href, strtolower($attr->getSupAttribute()), $attr->getSupAttribute()); + } else - printf('%s',$href,$attr->getSupAttribute()); + { + printf('%s', $href, $attr->getSupAttribute()); + } } echo ''; if (is_null($attr->getEquality())) - printf('(%s)',_('not specified')); + { + printf('(%s)', _('not specified')); + } else { $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['matching_rules'],$attr->getEquality())); if (isAjaxEnabled()) + { printf('%s', - $href,$href,_('Matching Rules'),$attr->getEquality(),$attr->getEquality()); + $href, $href, _('Matching Rules'), $attr->getEquality(), $attr->getEquality()); + } else - printf('%s',$href,$attr->getEquality()); + { + printf('%s', $href, $attr->getEquality()); + } } echo ''; if ( is_null($attr->getMaxLength())) - echo '('._('not applicable').')'; + { + echo '(' . _('not applicable') . ')'; + } else - printf('%s %s',number_format($attr->getMaxLength()), - $attr->getMaxLength()>1 ? _('characters') : _('character')); + { + printf('%s %s', number_format($attr->getMaxLength()), + $attr->getMaxLength() > 1 ? _('characters') : _('character')); + } echo ''; if (count($attr->getAliases()) == 0) - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } else - foreach ($attr->getAliases() as $alias) { - $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['attributes'],strtolower($alias))); + { + foreach ($attr->getAliases() as $alias) + { + $href = htmlspecialchars(sprintf('%s&viewvalue=%s', $entry['href']['attributes'], strtolower($alias))); if (isAjaxEnabled()) + { printf('%s', - $href,strtolower($alias),$alias); - else - printf('%s',$href,$alias); + $href, strtolower($alias), $alias); + } else + { + printf('%s', $href, $alias); + } } + } echo ''; if (count($attr->getUsedInObjectClasses()) == 0) - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } else - foreach ($attr->getUsedInObjectClasses() as $objectclass) { - $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['objectclasses'],strtolower($objectclass))); + { + foreach ($attr->getUsedInObjectClasses() as $objectclass) + { + $href = htmlspecialchars(sprintf('%s&viewvalue=%s', $entry['href']['objectclasses'], strtolower($objectclass))); if (isAjaxEnabled()) + { printf('%s ', - $href,$href,_('ObjectClasses'),strtolower($objectclass),$objectclass); - else - printf('%s ',$href,$objectclass); + $href, $href, _('ObjectClasses'), strtolower($objectclass), $objectclass); + } else + { + printf('%s ', $href, $objectclass); + } } + } echo '
%s%s
'; @@ -435,7 +524,9 @@ switch($entry['view']) { case 'objectclasses': $socs = $app['server']->SchemaObjectClasses(); if (! $socs) - error($schema_error_str,'error','index.php'); + { + error($schema_error_str, 'error', 'index.php'); + } printf('%s:',_('Jump to an objectClass')); @@ -449,19 +540,27 @@ switch($entry['view']) { drawJSItems($socs); echo ''; + } echo ''; foreach ($socs as $name => $oclass) + { printf('', - $name,$name == $entry['value'] ? 'selected="selected" ': '',$oclass->getName(false)); + $name, $name == $entry['value'] ? 'selected="selected" ' : '', $oclass->getName(FALSE)); + } echo ''; if (isAjaxEnabled()) - printf('',_('Go')); + { + printf('', _('Go')); + } else - printf('',_('Go')); + { + printf('', _('Go')); + } echo ''; echo ''; echo '
'; @@ -469,68 +568,102 @@ switch($entry['view']) { foreach ($socs as $name => $oclass) { if (isAjaxEnabled() || (is_null($entry['value']) || ! trim($entry['value']) || $entry['value']==$oclass->getName())) { if ((! is_null($entry['value']) && $entry['value']==$oclass->getName()) || ! trim($entry['value'])) - $entry['viewed'] = true; + { + $entry['viewed'] = TRUE; + } if (isAjaxEnabled() && $entry['value']) - printf('
',$oclass->getName(),strcasecmp($entry['value'],$oclass->getName()) ? 'none' : ''); + { + printf('
', $oclass->getName(), strcasecmp($entry['value'], $oclass->getName()) ? 'none' : ''); + } else - printf('
',$oclass->getName()); + { + printf('
', $oclass->getName()); + } echo ''; printf('',$name,$oclass->getName(false)); printf('',_('OID'),$oclass->getOID()); if ($oclass->getDescription()) - printf('',_('Description'),$oclass->getDescription()); + { + printf('', _('Description'), $oclass->getDescription()); + } printf('',_('Type'),$oclass->getType()); if ($oclass->getIsObsolete()) - printf('',_('This objectClass is obsolete.')); + { + printf('', _('This objectClass is obsolete.')); + } printf(''; printf(''; printf('', @@ -546,20 +679,28 @@ switch($entry['view']) { echo '
  • '; $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['attributes'],$attr->getName())); if (isAjaxEnabled()) + { printf('%s', - $href,$href,_('Attributes'),$attr->getName(),$attr->getName(false)); + $href, $href, _('Attributes'), $attr->getName(), $attr->getName(FALSE)); + } else - printf('%s',$href,$attr->getName(false)); + { + printf('%s', $href, $attr->getName(FALSE)); + } if ($attr->getSource() != $oclass->getName(false)) { echo '
    '; $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['objectclasses'],strtolower($attr->getSource()))); printf('(%s ',_('Inherited from')); if (isAjaxEnabled()) + { printf('%s', - $href,_('Jump to this objectClass definition'),strtolower($attr->getSource()),$attr->getSource()); + $href, _('Jump to this objectClass definition'), strtolower($attr->getSource()), $attr->getSource()); + } else - printf('%s',$href,$attr->getSource()); + { + printf('%s', $href, $attr->getSource()); + } echo ')'; } echo '
  • '; @@ -567,7 +708,9 @@ switch($entry['view']) { echo ''; } else - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } echo ''; echo ''; echo ''; @@ -618,7 +771,9 @@ switch($entry['view']) { } if (! is_null($entry['value']) && ! $entry['viewed']) - error(sprintf(_('No such schema item: "%s"'),$entry['value']),'error','index.php'); +{ + error(sprintf(_('No such schema item: "%s"'), $entry['value']), 'error', 'index.php'); +} function drawJSItems($object) { echo '',JSDIR); @@ -226,17 +266,23 @@ class AJAXTree extends HTMLTree { */ private function create_before_child($entry,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (strlen($level) == 0) + { return ''; + } $server = $this->getServer(); $output = ''; if (! $server->isReadOnly() && ! $entry->isLeaf() && (count($entry->getChildren()) > 10) && $this->getServer()->isShowCreateEnabled() && $_SESSION[APPCONFIG]->getValue('appearance','show_top_create')) - $output = $this->draw_create_new_entry($entry,$level,IMGDIR.'/tree_split.png'); + { + $output = $this->draw_create_new_entry($entry, $level, IMGDIR . '/tree_split.png'); + } return $output; } @@ -249,16 +295,22 @@ class AJAXTree extends HTMLTree { */ private function create_after_child($entry,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (strlen($level) == 0) + { return ''; + } $server = $this->getServer(); $output = ''; if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled()) - $output = $this->draw_create_new_entry($entry,$level,IMGDIR.'/tree_corner.png'); + { + $output = $this->draw_create_new_entry($entry, $level, IMGDIR . '/tree_corner.png'); + } return $output; } @@ -272,7 +324,9 @@ class AJAXTree extends HTMLTree { */ private function draw_create_new_entry($entry,$level,$img) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $output = ''; @@ -286,11 +340,15 @@ class AJAXTree extends HTMLTree { $output .= ' '; if (isAjaxEnabled()) + { $output .= sprintf('', - htmlspecialchars($href),_('Create new entry here'), - htmlspecialchars($href),_('Loading')); + htmlspecialchars($href), _('Create new entry here'), + htmlspecialchars($href), _('Loading')); + } else - $output .= sprintf('',htmlspecialchars($href),_('Create new entry here')); + { + $output .= sprintf('', htmlspecialchars($href), _('Create new entry here')); + } $output .= _('Create new entry here'); $output .= ''; @@ -305,13 +363,19 @@ class AJAXTree extends HTMLTree { */ public function listOpenItems() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->entries as $dn => $value) + { if ($value->isOpened()) - array_push($result,$value->getDN()); + { + array_push($result, $value->getDN()); + } + } return $result; } diff --git a/lib/Attribute.php b/lib/Attribute.php index e419727..83ad05c 100644 --- a/lib/Attribute.php +++ b/lib/Attribute.php @@ -80,7 +80,9 @@ class Attribute { public function __construct($name,$values,$server_id,$source=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $_SESSION[APPCONFIG]->getServer($server_id); @@ -90,7 +92,9 @@ class Attribute { $this->setLDAPdetails($sattr); } else + { $this->name = $name; + } $this->source = $source; @@ -103,22 +107,30 @@ class Attribute { default: if (! isset($values['values'])) - debug_dump_backtrace('no index "values"',1); + { + debug_dump_backtrace('no index "values"', 1); + } $this->initValue($values['values']); } # Should this attribute be hidden if ($server->isAttrHidden($this->name)) - $this->forcehide = true; + { + $this->forcehide = TRUE; + } # Should this attribute value be read only if ($server->isAttrReadOnly($this->name)) - $this->readonly = true; + { + $this->readonly = TRUE; + } # Should this attribute value be unique if ($server->isAttrUnique($this->name)) - $this->unique = true; + { + $this->unique = TRUE; + } } /** @@ -130,38 +142,52 @@ class Attribute { */ public function getName($lower=true,$real=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->name); + } if ($real) + { return $lower ? strtolower($this->name) : $this->name; + } else + { return $lower ? strtolower($this->real_attr_name()) : $this->real_attr_name(); + } } public function getValues() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->values); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->values); + } return $this->values; } public function getOldValues() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->oldvalues); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->oldvalues); + } return $this->oldvalues; } public function getValueCount() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->values); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->values); + } return count($this->values); } public function getSource() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->source); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->source); + } return $this->source; } @@ -172,17 +198,23 @@ class Attribute { */ public function autoValue($new_val) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->values) + { return; + } $this->values = $new_val; } public function initValue($new_val) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->values || $this->oldvalues) { debug_dump(array('new_val'=>$new_val,'this'=>$this)); @@ -194,35 +226,47 @@ class Attribute { public function clearValue() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->values = array(); } public function setOldValue($val) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->oldvalues = $val; } public function setValue($new_val) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->values) { if ($this->values == $new_val) + { return; + } if ($this->oldvalues) { debug_dump($this); debug_dump_backtrace('old values are set',1); } else + { $this->oldvalues = $this->values; + } } if ($new_val == $this->values) + { return; + } $this->values = $new_val; $this->justModified(); @@ -230,27 +274,39 @@ class Attribute { public function addValue($new_val,$i=-1) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($i < 0) + { $i = $this->getValueCount(); + } $old_val = $this->getValue($i); if (is_null($old_val) || ($old_val != $new_val)) + { $this->justModified(); + } $this->values[$i] = $new_val; } public function delValue($i=-1) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($i < 0) + { $this->setValue(array()); + } if (! $this->hasBeenModified()) + { $this->oldvalues = $this->values; + } if (isset($this->values[$i])) { unset($this->values[$i]); @@ -261,86 +317,120 @@ class Attribute { public function getValue($i) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->values[$i])) + { return $this->values[$i]; + } else - return null; + { + return NULL; + } } public function getOldValue($i) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->oldvalues[$i])) + { return $this->oldvalues[$i]; + } else - return null; + { + return NULL; + } } public function getMinValueCount() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->min_value_count); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->min_value_count); + } return $this->min_value_count; } public function setMinValueCount($min) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->min_value_count = $min; } public function getMaxValueCount() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->max_value_count); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->max_value_count); + } return $this->max_value_count; } public function setMaxValueCount($max) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->max_value_count = $max; } public function haveMoreValues() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getMaxValueCount() < 0 || ($this->getValueCount() < $this->getMaxValueCount())) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } public function justModified() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->modified = true; } public function hasBeenModified() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->modified); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->modified); + } return $this->modified; } public function isForceDelete() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->forcedelete); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->forcedelete); + } return $this->forcedelete; } public function setForceDelete() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->forcedelete = true; $this->oldvalues = $this->values; @@ -350,73 +440,103 @@ class Attribute { public function isInternal() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->internal); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->internal); + } return $this->internal; } public function setInternal() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->internal = true; } public function isRequired() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getMinValueCount() > 0) - return true; + { + return TRUE; + } elseif ($this->ldaptype == 'must') - return true; + { + return TRUE; + } elseif ($this->isRDN()) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } public function isMay() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (($this->ldaptype == 'may') && ! $this->isRequired()) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } public function setType($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->type = strtolower($type); } public function getType() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->type); + } return $this->type; } public function setLDAPtype($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->ldaptype = strtolower($type); } public function getLDAPtype() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->ldaptype); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->ldaptype); + } return $this->ldaptype; } public function setProperties($properties) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($properties as $index => $value) { if ($index == 'maxvalnb') { @@ -441,7 +561,9 @@ class Attribute { } if (isset($this->$index)) + { $this->$index = $value; + } else { debug_dump($this); debug_dump_backtrace(sprintf('Unknown property (%s) with value (%s) for (%s)',$index,$value,$this->getName()),1); @@ -451,29 +573,39 @@ class Attribute { public function setRequired() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getMinValueCount() <= 0) + { $this->setMinValueCount(1); + } } public function setOptional() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->setMinValueCount(0); } public function isReadOnly() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->readonly); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->readonly); + } return $this->readonly; } public function setReadOnly() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->readonly = true; } @@ -484,163 +616,213 @@ class Attribute { public function isVisible() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->visible && (! $this->forcehide); } public function hide() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->visible = false; } public function show() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->visible = true; } public function haveFriendlyName() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $_SESSION[APPCONFIG]->haveFriendlyName($this); } public function getFriendlyName() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->display); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->display); + } if ($this->display) + { return $this->display; + } else + { return $_SESSION[APPCONFIG]->getFriendlyName($this); + } } public function setDescription($description) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->description = $description; } public function getDescription() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->description); + } return $this->description; } public function setIcon($icon) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->icon = $icon; } public function getIcon() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->icon); + } return $this->icon ? sprintf('%s/%s',IMGDIR,$this->icon) : ''; } public function getHint() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->hint); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->hint); + } return $this->hint; } public function setHint($hint) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->hint = $hint; } public function getMaxLength() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->maxlength); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->maxlength); + } return $this->maxlength; } public function setMaxLength($maxlength) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->maxlength = $maxlength; } public function getSize() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->size); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->size); + } return $this->size; } public function setSize($size) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->size = $size; } public function getSpacer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->spacer); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->spacer); + } return $this->spacer; } public function getPage() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->page); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->page); + } return $this->page; } public function setPage($page) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->page = $page; } public function getOnChange() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->onchange); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->onchange); + } return $this->onchange; } public function getHelper() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helper); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->helper); + } return $this->helper; } public function getHelperValue() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->helpervalue); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->helpervalue); + } return $this->helpervalue; } public function getVerify() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->verify); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->verify); + } return $this->verify; } public function setRDN($rdn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->rdn = $rdn; } @@ -652,7 +834,9 @@ class Attribute { */ public function isRDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->rdn); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->rdn); + } return $this->rdn; } @@ -664,18 +848,26 @@ class Attribute { */ private function setLDAPdetails($sattr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # By default, set this as a MAY attribute, later processing should make it a MUST attribute if it is. if (! $this->ldaptype) + { $this->ldaptype = 'may'; + } # Store our Aliases foreach ($sattr->getAliases() as $alias) - array_push($this->aliases,strtolower($alias)); + { + array_push($this->aliases, strtolower($alias)); + } if ($sattr->getIsSingleValue()) + { $this->setMaxValueCount(1); + } } /** @@ -684,62 +876,82 @@ class Attribute { */ public function getAliases() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->aliases); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->aliases); + } return $this->aliases; } public function getAutoValue() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->autovalue); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->autovalue); + } return $this->autovalue; } public function getPostValue() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->postvalue); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->postvalue); + } return $this->postvalue; } public function setPostValue($postvalue) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->postvalue = $postvalue; } public function setXML($values) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Mostly all the time, this should be an array if (is_array($values)) + { foreach ($values as $index => $value) - switch ($index) { + { + switch ($index) + { # Helpers should be accompanied with a attribute. case 'helper': - if (! isset($values['post']) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + if ( ! isset($values['post']) && ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Missing [post] setting in XML file'),$index), - 'body'=>_('[helper] needs an accompanying [post] action.'), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Missing [post] setting in XML file'), $index), + 'body' => _('[helper] needs an accompanying [post] action.'), + 'type' => 'warn')); + } - if (isset($value['value']) && ! is_array($value['value']) && preg_match('/^=php\.(\w+)\((.*)\)$/',$value['value'],$matches)) { + if (isset($value['value']) && ! is_array($value['value']) && preg_match('/^=php\.(\w+)\((.*)\)$/', $value['value'], $matches)) + { $this->helpervalue['function'] = $matches[1]; $this->helpervalue['args'] = $matches[2]; unset ($value['value']); } - foreach ($value as $i => $detail) { - if (! in_array($i,array('default','display','id','value'))) { - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + foreach ($value as $i => $detail) + { + if ( ! in_array($i, array('default', 'display', 'id', 'value'))) + { + if ( ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$i), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting for helper will be ignored.'),$detail), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown XML setting'), $i), + 'body' => sprintf('%s [%s]', _('Unknown XML type setting for helper will be ignored.'), $detail), + 'type' => 'warn')); + } unset($value[$i]); } @@ -749,70 +961,86 @@ class Attribute { break; - case 'hidden': $value ? $this->visible = false : $this->visible = true; + case 'hidden': + $value ? $this->visible = FALSE : $this->visible = TRUE; break; - case 'spacer': $value ? $this->$index = true : $this->$index = false; + case 'spacer': + $value ? $this->$index = TRUE : $this->$index = FALSE; break; # Essentially, we ignore type, it is used to select an Attribute type in the Factory. But we'll generated a warning if there is an unknown type. case 'type': - if (! in_array($value,array('password','multiselect','select','textarea')) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + if ( ! in_array($value, array('password', 'multiselect', 'select', 'textarea')) && ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting will be ignored.'),$value), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown XML setting'), $index), + 'body' => sprintf('%s [%s]', _('Unknown XML type setting will be ignored.'), $value), + 'type' => 'warn')); + } break; case 'post': - if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) { + if (preg_match('/^=php\.(\w+)\((.*)\)$/', $value, $matches)) + { $this->postvalue['function'] = $matches[1]; $this->postvalue['args'] = $matches[2]; } else - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + if ( ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown XML type setting will be ignored.'),$value), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown XML setting'), $index), + 'body' => sprintf('%s [%s]', _('Unknown XML type setting will be ignored.'), $value), + 'type' => 'warn')); + } case 'value': if (is_array($value)) - foreach ($value as $x => $y) { - if (! $this->haveMoreValues()) { + { + foreach ($value as $x => $y) + { + if ( ! $this->haveMoreValues()) + { system_message(array( - 'title'=>_('Automatically removed attribute values from template'), - 'body'=>sprintf('%s [%s]',_('Template defines more values than can be accepted by attribute.'),$this->getName(true)), - 'type'=>'warn')); + 'title' => _('Automatically removed attribute values from template'), + 'body' => sprintf('%s [%s]', _('Template defines more values than can be accepted by attribute.'), $this->getName(TRUE)), + 'type' => 'warn')); $this->clearValue(); break; } else - $this->addValue($x,$y); + { + $this->addValue($x, $y); + } } - - else + } else # Check to see if the value is auto generated. - if (preg_match('/^=php\.(\w+)\((.*)\)$/',$value,$matches)) { + if (preg_match('/^=php\.(\w+)\((.*)\)$/', $value, $matches)) + { $this->autovalue['function'] = $matches[1]; $this->autovalue['args'] = $matches[2]; # We'll add a hint too - if (! $this->hint) + if ( ! $this->hint) + { $this->hint = _('Automatically determined'); + } } else + { $this->addValue($value); + } break; # Queries case 'ordersort': - # Creation/Editing Templates + # Creation/Editing Templates case 'cols': case 'default': case 'display': @@ -826,23 +1054,32 @@ class Attribute { case 'rows': case 'size': case 'values': - case 'verify': $this->$index = $value; + case 'verify': + $this->$index = $value; break; case 'max': if ($this->getMaxValueCount() == -1) + { $this->setMaxValueCount($value); + } default: - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + if ( ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown XML setting'),$index), - 'body'=>sprintf('%s [%s]',_('Unknown attribute setting will be ignored.'),serialize($value)), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown XML setting'), $index), + 'body' => sprintf('%s [%s]', _('Unknown attribute setting will be ignored.'), serialize($value)), + 'type' => 'warn')); + } } + } + } elseif (is_string($values) && (strlen($values) > 0)) + { $this->values = array($values); + } } /** @@ -850,7 +1087,9 @@ class Attribute { */ public function getRemovedValues() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return array_diff($this->getOldValues(),$this->getValues()); } @@ -860,7 +1099,9 @@ class Attribute { */ public function getAddedValues() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return array_diff($this->getValues(),$this->getOldValues()); } @@ -875,7 +1116,9 @@ class Attribute { */ private function real_attr_name() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->name); + } return preg_replace('/;.*$/U','',$this->name); } @@ -887,12 +1130,18 @@ class Attribute { */ public function needJS($type=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (is_null($type)) { foreach (array('focus','blur','validate') as $type) + { if ($this->needJS($type)) - return true; + { + return TRUE; + } + } return false; @@ -902,18 +1151,28 @@ class Attribute { } elseif ($type == 'blur') { if ($this->onchange || $this->isRequired()) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } elseif ($type == 'validate') { if ($this->isRequired()) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } else - debug_dump_backtrace(sprintf('Unknown JS request %s',$type),1); + { + debug_dump_backtrace(sprintf('Unknown JS request %s', $type), 1); + } } } diff --git a/lib/AttributeFactory.php b/lib/AttributeFactory.php index ff2ecd8..a0d609c 100644 --- a/lib/AttributeFactory.php +++ b/lib/AttributeFactory.php @@ -26,10 +26,12 @@ class AttributeFactory { default: if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown template [post] function'),$matches[1]), - 'body'=>sprintf('%s [%s]',_('The template function is not known and will be ignored.'),$values['post']), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown template [post] function'), $matches[1]), + 'body' => sprintf('%s [%s]', _('The template function is not known and will be ignored.'), $values['post']), + 'type' => 'warn')); + } unset($values['post']); } @@ -38,16 +40,23 @@ class AttributeFactory { # Check our helper functions exists if (isset($values['helper']['value']) && ! is_array($values['helper']['value'])) - if (preg_match('/^=php\.(\w+)\((.*)\)$/',$values['helper']['value'],$matches)) - if (! in_array($matches[1],array('GetNextNumber','PasswordEncryptionTypes'))) { - if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + { + if (preg_match('/^=php\.(\w+)\((.*)\)$/', $values['helper']['value'], $matches)) + { + if ( ! in_array($matches[1], array('GetNextNumber', 'PasswordEncryptionTypes'))) + { + if ( ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown template helper function'),$matches[1]), - 'body'=>sprintf('%s [%s]',_('The template helper function is not known and will be ignored.'),$values['helper']['value']), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown template helper function'), $matches[1]), + 'body' => sprintf('%s [%s]', _('The template helper function is not known and will be ignored.'), $values['helper']['value']), + 'type' => 'warn')); + } unset($values['helper']['value']); } + } + } # Check to see if the value is auto generated, our attribute type is dependant on the function called. if (isset($values['value']) && ! is_array($values['value'])) { @@ -55,7 +64,9 @@ class AttributeFactory { switch ($matches[1]) { case 'MultiList': if (! isset($values['type'])) + { $values['type'] = 'multiselect'; + } case 'PickList': return $this->newSelectionAttribute($name,$values,$server_id,$source); @@ -70,10 +81,12 @@ class AttributeFactory { default: if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + { system_message(array( - 'title'=>sprintf('%s [%s]',_('Unknown template function'),$matches[1]), - 'body'=>sprintf('%s [%s]',_('The template function is not known and will be ignored.'),$values['value']), - 'type'=>'warn')); + 'title' => sprintf('%s [%s]', _('Unknown template function'), $matches[1]), + 'body' => sprintf('%s [%s]', _('The template function is not known and will be ignored.'), $values['value']), + 'type' => 'warn')); + } unset($values['value']); } @@ -81,20 +94,26 @@ class AttributeFactory { } if (isset($values['type'])) - switch ($values['type']) { + { + switch ($values['type']) + { case 'password': - if (! strcasecmp($name,'sambaLMPassword') || ! strcasecmp($name,'sambaNTPassword')) - return $this->newSambaPasswordAttribute($name,$values,$server_id,$source); - else - return $this->newPasswordAttribute($name,$values,$server_id,$source); + if ( ! strcasecmp($name, 'sambaLMPassword') || ! strcasecmp($name, 'sambaNTPassword')) + { + return $this->newSambaPasswordAttribute($name, $values, $server_id, $source); + } else + { + return $this->newPasswordAttribute($name, $values, $server_id, $source); + } case 'multiselect': case 'select': - return $this->newSelectionAttribute($name,$values,$server_id,$source); + return $this->newSelectionAttribute($name, $values, $server_id, $source); case 'textarea': - return $this->newMultiLineAttribute($name,$values,$server_id,$source); + return $this->newMultiLineAttribute($name, $values, $server_id, $source); } + } if (! strcasecmp($name,'objectClass')) { return $this->newObjectClassAttribute($name,$values,$server_id,$source); diff --git a/lib/BinaryAttribute.php b/lib/BinaryAttribute.php index 81e3df2..3ade393 100644 --- a/lib/BinaryAttribute.php +++ b/lib/BinaryAttribute.php @@ -28,8 +28,14 @@ class BinaryAttribute extends Attribute { } public function getFileName($i) { - if (isset($this->filenames[$i])) return $this->filenames[$i]; - else return null; + if (isset($this->filenames[$i])) + { + return $this->filenames[$i]; + } + else + { + return NULL; + } } public function addFileName($name, $i = -1) { @@ -45,8 +51,14 @@ class BinaryAttribute extends Attribute { } public function getFilePath($i) { - if (isset($this->filepaths[$i])) return $this->filepaths[$i]; - else return null; + if (isset($this->filepaths[$i])) + { + return $this->filepaths[$i]; + } + else + { + return NULL; + } } public function addFilePath($path, $i = -1) { diff --git a/lib/HTMLTree.php b/lib/HTMLTree.php index 35ede20..014697f 100644 --- a/lib/HTMLTree.php +++ b/lib/HTMLTree.php @@ -26,14 +26,18 @@ class HTMLTree extends Tree { */ public function draw($onlytree=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $js_drawn = false; $server = $this->getServer(); echo '
    %s
    %s: %s
    %s: %s
    %s: %s
    %s: %s
    %s
    %s
    %s: ',_('Inherits from')); if (count($oclass->getSupClasses()) == 0) - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } else - foreach ($oclass->getSupClasses() as $i => $object_class) { - $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['objectclasses'],strtolower($object_class))); + { + foreach ($oclass->getSupClasses() as $i => $object_class) + { + $href = htmlspecialchars(sprintf('%s&viewvalue=%s', $entry['href']['objectclasses'], strtolower($object_class))); if (isAjaxEnabled()) + { printf('%s', - $href,strtolower($object_class),$object_class); - else + $href, strtolower($object_class), $object_class); + } else + { printf('%s', - $href,$object_class,_('Jump to this objectClass definition'),$object_class); + $href, $object_class, _('Jump to this objectClass definition'), $object_class); + } if ($i < count($oclass->getSupClasses()) - 1) + { echo ', '; + } } + } echo '
    %s: ',_('Parent to')); if (strcasecmp($oclass->getName(),'top') == 0) { $href = htmlspecialchars($entry['href']['objectclasses']); if (isAjaxEnabled()) + { printf('all', $href); + } else - printf('(all)',$href); + { + printf('(all)', $href); + } } elseif (count($oclass->getChildObjectClasses()) == 0) - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } else - foreach ($oclass->getChildObjectClasses() as $i => $object_class) { - $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['objectclasses'],strtolower($object_class))); + { + foreach ($oclass->getChildObjectClasses() as $i => $object_class) + { + $href = htmlspecialchars(sprintf('%s&viewvalue=%s', $entry['href']['objectclasses'], strtolower($object_class))); if (isAjaxEnabled()) + { printf('%s', - $href,_('Jump to this objectClass definition'),strtolower($object_class),$object_class); - else - printf('%s',$href,_('Jump to this objectClass definition'),$object_class); + $href, _('Jump to this objectClass definition'), strtolower($object_class), $object_class); + } else + { + printf('%s', $href, _('Jump to this objectClass definition'), $object_class); + } - if ( $i < count($oclass->getChildObjectClasses()) - 1) + if ($i < count($oclass->getChildObjectClasses()) - 1) + { echo ', '; + } } + } echo '
     %s%s 
    '; @@ -579,20 +722,28 @@ switch($entry['view']) { echo '
  • '; $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['attributes'],$attr->getName())); if (isAjaxEnabled()) + { printf('%s', - $href,$href,_('Attributes'),$attr->getName(),$attr->getName(false)); + $href, $href, _('Attributes'), $attr->getName(), $attr->getName(FALSE)); + } else - printf('%s',$href,$attr->getName(false)); + { + printf('%s', $href, $attr->getName(FALSE)); + } if ($attr->getSource() != $oclass->getName(false)) { echo '
    '; $href = htmlspecialchars(sprintf('%s&viewvalue=%s',$entry['href']['objectclasses'],strtolower($attr->getSource()))); printf('(%s ',_('Inherited from')); if (isAjaxEnabled()) + { printf('%s', - $href,_('Jump to this objectClass definition'),strtolower($attr->getSource()),$attr->getSource()); + $href, _('Jump to this objectClass definition'), strtolower($attr->getSource()), $attr->getSource()); + } else - printf('%s',$href,$attr->getSource()); + { + printf('%s', $href, $attr->getSource()); + } echo ')'; } @@ -605,7 +756,9 @@ switch($entry['view']) { echo ''; } else - printf('(%s)',_('none')); + { + printf('(%s)', _('none')); + } echo '
  • '; if (! $onlytree) + { $this->draw_server_name(); + } $this->javascript = ''; $javascript_id = 0; @@ -46,14 +50,22 @@ class HTMLTree extends Tree { $this->draw_menu(); if ($server->getAuthType() != 'config') + { $this->draw_logged_in_user(); + } else - printf('',$this->getDepth()+3); + { + printf('', $this->getDepth() + 3); + } if ($server->isReadOnly()) - printf('',$this->getDepth()+3-1,_('read only')); + { + printf('', $this->getDepth() + 3 - 1, _('read only')); + } else - printf('',$this->getDepth()+3); + { + printf('', $this->getDepth() + 3); + } printf('
     
     
    (%s)
    (%s)
     
     
     
    ', $_SESSION[APPCONFIG]->getValue('appearance','tree_width') ? sprintf('width: %spx; ',$_SESSION[APPCONFIG]->getValue('appearance','tree_width')) : '', @@ -74,7 +86,9 @@ class HTMLTree extends Tree { echo '
    '; if (! $onlytree) + { echo '
    '; return; @@ -107,11 +121,15 @@ class HTMLTree extends Tree { $this->javascript .= sprintf(''); if (preg_match('/,/',$base->getDN())) + { printf('
    %s
    %s %s
    '; if (! $onlytree) + { echo '
    '; + } # We are not logged in, draw a login... link. } else { @@ -157,7 +177,9 @@ class HTMLTree extends Tree { */ protected function draw_server_name() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); @@ -179,15 +201,22 @@ class HTMLTree extends Tree { */ protected function draw_menu() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $links = ''; if (is_array($_SESSION[APPCONFIG]->getValue('menu','session'))) - foreach ($_SESSION[APPCONFIG]->getValue('menu','session') as $link => $title) { + { + foreach ($_SESSION[APPCONFIG]->getValue('menu', 'session') as $link => $title) + { if ($this->get_menu_item($link)) - $links .= sprintf('%s',$this->get_menu_item($link)); + { + $links .= sprintf('%s', $this->get_menu_item($link)); + } } + } # Finally add our logout link. $links .= sprintf('%s',$this->get_logout_menu_item()); @@ -207,7 +236,9 @@ class HTMLTree extends Tree { */ protected function get_menu_item($item) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $menu = array(); @@ -215,7 +246,9 @@ class HTMLTree extends Tree { switch($item) { case 'schema': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) + { return ''; + } $menu['cmd'] = 'schema'; $menu['ajax'] = _('Loading Schema'); @@ -228,7 +261,9 @@ class HTMLTree extends Tree { case 'search': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','query_engine')) + { return ''; + } $menu['cmd'] = 'query_engine'; $menu['ajax'] = _('Loading Search'); @@ -241,7 +276,9 @@ class HTMLTree extends Tree { case 'refresh': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','refresh')) + { return ''; + } $menu['cmd'] = 'refresh'; $menu['href'] = '&noheader=1&purge=1'; @@ -255,7 +292,9 @@ class HTMLTree extends Tree { case 'server_info': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','server_info')) + { return ''; + } $menu['cmd'] = 'server_info'; $menu['ajax'] = _('Loading Info'); @@ -268,11 +307,15 @@ class HTMLTree extends Tree { case 'monitor': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','monitor')) + { return ''; + } $attrs = $server->getRootDSE(); if (! $attrs || ! isset($attrs['monitorcontext'])) + { return ''; + } $menu['cmd'] = 'monitor'; $menu['ajax'] = _('Loading Monitor Info'); @@ -285,7 +328,9 @@ class HTMLTree extends Tree { case 'import': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','import_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','import') || $server->isReadOnly()) + { return ''; + } $menu['cmd'] = 'import_form'; $menu['ajax'] = _('Loading Import'); @@ -298,7 +343,9 @@ class HTMLTree extends Tree { case 'export': if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') || ! $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) + { return ''; + } $menu['cmd'] = 'export_form'; $menu['ajax'] = _('Loading Export'); @@ -316,25 +363,35 @@ class HTMLTree extends Tree { $href_parms = htmlspecialchars(sprintf('cmd=%s&server_id=%s%s',$menu['cmd'],$server->getIndex(),isset($menu['href']) ? $menu['href'] : '')); if (isAjaxEnabled()) + { return sprintf('%s
    %s
    ', - $href_parms,$menu['div'],$href_parms,$menu['ajax'],$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']); + $href_parms, $menu['div'], $href_parms, $menu['ajax'], $menu['title'], $server->getName(), IMGDIR, $menu['img'], $menu['name'], $menu['name']); + } else + { return sprintf('%s
    %s
    ', - $href_parms,$menu['title'],$server->getName(),IMGDIR,$menu['img'],$menu['name'],$menu['name']); + $href_parms, $menu['title'], $server->getName(), IMGDIR, $menu['img'], $menu['name'], $menu['name']); + } } protected function get_logout_menu_item() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $href = sprintf('cmd.php?cmd=logout&server_id=%s',$server->getIndex()); if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','logout') || in_array($server->getAuthType(),array('config','http','proxy','sasl'))) + { return ''; + } else + { return sprintf('%s
    %s
    ', - htmlspecialchars($href),_('Logout of this server'),IMGDIR,'logout-big.png',_('logout'),_('logout')); + htmlspecialchars($href), _('Logout of this server'), IMGDIR, 'logout-big.png', _('logout'), _('logout')); + } } /** @@ -342,7 +399,9 @@ class HTMLTree extends Tree { */ protected function draw_logged_in_user() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); @@ -362,28 +421,39 @@ class HTMLTree extends Tree { $bases = $server->getContainerTop($logged_in_dn); if (is_array($bases) && count($bases)) - array_push($logged_in_dn_array,$bases); + { + array_push($logged_in_dn_array, $bases); + } $rdn = $logged_in_dn; # Some sanity checking here, in case our DN doesnt look like a DN if (! is_array($logged_in_dn_array)) + { $logged_in_dn_array = array($logged_in_dn); + } if (trim($logged_in_dn)) { if ($server->dnExists($logged_in_dn)) - foreach ($logged_in_dn_array as $rdn_piece) { - $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),rawurlencode($rdn)); - printf('%s',htmlspecialchars($href),pretty_print_dn($rdn_piece)); + { + foreach ($logged_in_dn_array as $rdn_piece) + { + $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $server->getIndex(), rawurlencode($rdn)); + printf('%s', htmlspecialchars($href), pretty_print_dn($rdn_piece)); if ($rdn_piece != end($logged_in_dn_array)) + { echo ','; + } - $rdn = substr($rdn,(1 + strpos($rdn,','))); + $rdn = substr($rdn, (1 + strpos($rdn, ','))); } + } else + { echo $logged_in_dn; + } } else { echo 'Anonymous'; @@ -401,7 +471,9 @@ class HTMLTree extends Tree { */ protected function draw_item($item,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); @@ -416,7 +488,9 @@ class HTMLTree extends Tree { # If the entry doesnt exist in the server, then return here with an empty string. if (! $entry) + { return; + } # Get our children. $child_count = $this->readChildrenNumber($item); @@ -432,15 +506,24 @@ class HTMLTree extends Tree { # Is this node expanded? (deciding whether to draw "+" or "-") if ($entry->isOpened()) - if (! $child_count && ! $this->getServer()->isShowCreateEnabled()) - printf('-',IMGDIR); - else - printf('-',$href['collapse'],IMGDIR); + { + if ( ! $child_count && ! $this->getServer()->isShowCreateEnabled()) + { + printf('-', IMGDIR); + } else + { + printf('-', $href['collapse'], IMGDIR); + } + } else if (($child_count !== false) && (! $child_count) && (! $this->getServer()->isShowCreateEnabled())) - printf('-',IMGDIR); + { + printf('-', IMGDIR); + } else - printf('+',$href['expand'],IMGDIR); + { + printf('+', $href['expand'], IMGDIR); + } printf('img', $href['edit'],$server->getIndex(),preg_replace('/=/','_',base64_encode($item)),IMGDIR,$entry->getIcon()); @@ -449,7 +532,9 @@ class HTMLTree extends Tree { printf('%s',$href['edit'],$this->get_formatted_dn($entry,$level)); if ($child_count) - printf(' (%s)',$child_count); + { + printf(' (%s)', $child_count); + } echo ''; @@ -464,7 +549,9 @@ class HTMLTree extends Tree { } foreach ($entry->getChildren() as $dnChildEntry) - $this->draw_item($dnChildEntry,$level+1); + { + $this->draw_item($dnChildEntry, $level + 1); + } # Always draw the "create new" link at the bottom of the listing if (! $server->isReadOnly() && ! $entry->isLeaf() && $this->getServer()->isShowCreateEnabled()) { @@ -473,17 +560,25 @@ class HTMLTree extends Tree { } if (DEBUG_ENABLED) - debug_log('Leaving (%s,%s)',33,0,__FILE__,__LINE__,__METHOD__,$item,$level); + { + debug_log('Leaving (%s,%s)', 33, 0, __FILE__, __LINE__, __METHOD__, $item, $level); + } } protected function get_formatted_dn($entry,$level) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($level < 0) + { return pretty_print_dn($entry->getDN()); + } else - return draw_formatted_dn($this->getServer(),$entry); + { + return draw_formatted_dn($this->getServer(), $entry); + } } /** @@ -495,7 +590,9 @@ class HTMLTree extends Tree { */ protected function draw_create_link($rdn,$level,$encoded_dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # print the "Create New object" link. $href = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$encoded_dn)); @@ -513,7 +610,9 @@ class HTMLTree extends Tree { */ protected function draw_login_link() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $href_parm = htmlspecialchars(sprintf('cmd=%s&server_id=%s',get_custom_file($server->getIndex(),'login_form',''),$server->getIndex())); @@ -542,7 +641,9 @@ class HTMLTree extends Tree { */ protected function draw_javascript() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->javascript) { echo "\n"; @@ -557,13 +658,17 @@ class HTMLTree extends Tree { */ public function getDepth() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); # If we are not logged in if (! $server->isLoggedIn(null)) + { return 0; + } static $depths = array(); @@ -577,7 +682,9 @@ class HTMLTree extends Tree { $depth = count(pla_explode_dn($dn->getDN()))+1-$basedepth; if ($depth > $max) + { $max = $depth; + } } $depths[$server->getIndex()] = $max; diff --git a/lib/MassRender.php b/lib/MassRender.php index dbc3f9a..e030215 100644 --- a/lib/MassRender.php +++ b/lib/MassRender.php @@ -14,12 +14,15 @@ */ class MassRender extends TemplateRender { protected function drawMassFormReadWriteValueAttribute($attribute,$i,$j) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ',__METHOD__); } $val = $attribute->getValue($i); if ($attribute->getHelper()) - echo ''; @@ -176,27 +221,38 @@ class page { private function control_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } echo '
    '; + { + echo '', _('Update Object')); + } } /** STEP FORM METHODS * @@ -1459,8 +1879,14 @@ class TemplateRender extends PageRender { */ private function drawStepTitle($page) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [templateNAME:%s]
    ',__METHOD__,$this->template->getName()); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMP||DEBUGTMPSUB) + { + printf('* %s [templateNAME:%s]
    ', __METHOD__, $this->template->getName()); + } # The default template needs to ask the user for objectClasses. if ($this->template->isType('default')) { @@ -1471,20 +1897,29 @@ class TemplateRender extends PageRender { printf('%s: ',sprintf(_('Step %s of %s'),$page,$this->pagelast)); if ($page == 1) + { echo _('Container and ObjectClass(es)'); + } else + { echo _('Specify attributes and values'); + } echo ''; } elseif ($this->template->getDescription()) + { printf('

    %s (%s)

    ', _($this->template->getDescription()), - sprintf(_('Step %s of %s'),$page,$this->pagelast)); + sprintf(_('Step %s of %s'), $page, $this->pagelast)); + } } private function drawStepFormStart($page) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (($this->template->isType('default') && $this->template->getContext() == 'create' && $page == 1) || $page < $this->pagelast) { echo ''; @@ -1495,20 +1930,29 @@ class TemplateRender extends PageRender { echo '
    '; if ($_SESSION[APPCONFIG]->getValue('confirm','create') && ! get_request('create_base')) + { echo ''; + } else + { echo ''; + } } } protected function drawStepForm($page) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } printf('',$this->getServerID()); printf('',$this->template->getID()); printf('',$page+1); if (get_request('create_base')) + { echo ''; + } $this->drawHiddenAttributes(); @@ -1529,9 +1973,13 @@ class TemplateRender extends PageRender { $this->drawRDNChooser(); if ($this->template->isType('default') && $this->template->getContext() == 'create') + { $this->drawStepFormDefaultAttributes(); + } else + { $this->drawShownAttributes(); + } } $this->drawStepFormSubmitButton($page); @@ -1540,21 +1988,31 @@ class TemplateRender extends PageRender { } private function drawStepFormEnd() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->drawFormEnd(); } private function drawStepFormSubmitButton($page) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } echo '
    '; if ($page < $this->pagelast) - printf('',_('Proceed >>')); + { + printf('', _('Proceed >>')); + } else // @todo cant use AJAX here, it affects file uploads. + { printf('', _('Create Object')); + } echo ''; } @@ -1562,7 +2020,10 @@ class TemplateRender extends PageRender { * Given our known objectClass in the template, this will render the required MAY and optional MUST attributes */ private function drawStepFormDefaultAttributes() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Put required attributes first $attrs = array(); @@ -1571,30 +2032,48 @@ class TemplateRender extends PageRender { foreach ($this->template->getAttributes(true) as $attribute) { # Skip the objectclass attribute, we already know it in a default creation form. if ($attribute->getName() == 'objectclass') + { continue; + } if ($attribute->isRequired()) - array_push($attrs['required'],$attribute); + { + array_push($attrs['required'], $attribute); + } elseif (! $attribute->getValues()) - array_push($attrs['optional'],$attribute); + { + array_push($attrs['optional'], $attribute); + } } printf('',_('Required Attributes')); if (count($attrs['required'])) + { foreach ($attrs['required'] as $attribute) - $this->draw('Template',$attribute); + { + $this->draw('Template', $attribute); + } + } else - printf('',_('none')); + { + printf('', _('none')); + } printf('',_('Optional Attributes')); if (count($attrs['optional'])) + { foreach ($attrs['optional'] as $attribute) - $this->draw('Template',$attribute); + { + $this->draw('Template', $attribute); + } + } else - printf('',_('none')); + { + printf('', _('none')); + } echo "\n"; } @@ -1602,19 +2081,28 @@ class TemplateRender extends PageRender { /** DRAW ATTRIBUTES **/ private function drawShownAttributes() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } foreach ($this->template->getAttributesShown() as $attribute) - if (($attribute->getPage() == $this->page) && ($attribute->isRequired() || $attribute->isMay())) { - $this->draw('Template',$attribute); + { + if (($attribute->getPage() == $this->page) && ($attribute->isRequired() || $attribute->isMay())) + { + $this->draw('Template', $attribute); echo "\n"; } + } } /** DRAW PAGE JAVACRIPT */ protected function drawJavascript() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } echo "\n"; printf('',__METHOD__); @@ -1648,7 +2136,9 @@ function validateForm(silence) { # If we displayed the RDN chooser... if (! count($this->template->getRDNAttrs())) + { echo ' valid = (!document.getElementById(\'rdn_attribute\').value || !valid) ? false : true;'; + } echo ' return valid; @@ -1671,7 +2161,9 @@ function validateForm(silence) { echo "\n"; foreach ($this->template->getAttributesShown() as $attribute) - $this->draw('Javascript',$attribute); + { + $this->draw('Javascript', $attribute); + } // @todo We need to sleep here a little bit, because our JS may not have loaded yet. echo '',$attribute->getName(),$i,$config['format']); if (in_array_ignore_case($attribute->getName(),array_keys($config['time'])) && ($config['time'][$attribute->getName()])) - printf('',$attribute->getName(),$i,'true'); + { + printf('', $attribute->getName(), $i, 'true'); + } echo "\n"; } @@ -2391,7 +3075,10 @@ function deleteAttribute(attrName,friendlyName,i) */ protected function drawIconDnAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->draw('DnValueIcon',$attribute,$val); } @@ -2402,10 +3089,15 @@ function deleteAttribute(attrName,friendlyName,i) */ protected function drawIconObjectClassAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (! $_SESSION[APPCONFIG]->getValue('appearance','show_schema_link') || !$_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) + { return; + } if (strlen($val) > 0) { $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=objectclasses&viewvalue=%s', @@ -2424,9 +3116,13 @@ function deleteAttribute(attrName,friendlyName,i) # This JS may have been rendered by multiple Binary attributes if (isset($drawn[$attribute->getName()]) && $drawn[$attribute->getName()]) + { return; + } else - $drawn[$attribute->getName()] = true; + { + $drawn[$attribute->getName()] = TRUE; + } printf('',__METHOD__,$attribute->getName()); echo "\n"; @@ -2449,7 +3145,10 @@ function deleteAttribute(attrName,friendlyName,i) } protected function drawCheckLinkPasswordAttribute($attribute,$component_id) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } printf('%s...
    ', $component_id,$attribute->getName(),_('Check password')); @@ -2464,7 +3163,10 @@ function deleteAttribute(attrName,friendlyName,i) * @param $attribute */ protected function drawJavascriptRandomPasswordAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } printf("\n\n",__METHOD__); $this->drawJavascriptPasswordAttribute($attribute); @@ -2500,19 +3202,27 @@ function deleteAttribute(attrName,friendlyName,i) $id = 'enc'; if ($val = $attribute->getValue($i)) + { $default = get_enc_type($val); + } else - $default = $this->getServer()->getValue('appearance','password_hash'); + { + $default = $this->getServer()->getValue('appearance', 'password_hash'); + } if (! $attribute->getPostValue()) - printf('',$attribute->getName(),$i); + { + printf('', $attribute->getName(), $i); + } printf(''; } @@ -2521,7 +3231,9 @@ function deleteAttribute(attrName,friendlyName,i) $id = 'enc'; if (! $attribute->getPostValue()) - printf('',$attribute->getName(),$i); + { + printf('', $attribute->getName(), $i); + } switch ($attribute->getName()) { case 'sambalmpassword' : $enc = 'lm'; break; @@ -2542,24 +3254,38 @@ function deleteAttribute(attrName,friendlyName,i) */ protected function drawIconSelectionAttribute($attribute,$val) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (! $attribute->isMultiple() || $attribute->isReadOnly()) - $this->drawIconAttribute($attribute,$val); + { + $this->drawIconAttribute($attribute, $val); + } } protected function getMenuItemSelectionAttribute($attribute,$i) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } switch ($i) { case 'add': if (! $attribute->isMultiple()) - return $this->getMenuItemAttribute($attribute,$i); + { + return $this->getMenuItemAttribute($attribute, $i); + } else + { return ''; + } case 'modify': return ''; diff --git a/lib/Tree.php b/lib/Tree.php index 648688f..4aecd72 100644 --- a/lib/Tree.php +++ b/lib/Tree.php @@ -27,7 +27,9 @@ abstract class Tree { protected function __construct($server_id) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server_id; } @@ -39,9 +41,11 @@ abstract class Tree { * @param $server_id * @return object Tree */ - static public function getInstance($server_id) { + public static function getInstance($server_id) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $tree = get_cached_item($server_id,'tree'); @@ -49,14 +53,18 @@ abstract class Tree { $server = $_SESSION[APPCONFIG]->getServer($server_id); if (! $server) - return null; + { + return NULL; + } $treeclass = $_SESSION[APPCONFIG]->getValue('appearance','tree'); $tree = new $treeclass($server_id); # If we are not logged in, just return the empty tree. if (is_null($server->getLogin(null))) + { return $tree; + } foreach ($server->getBaseDN(null) as $base) { if ($base) { @@ -82,7 +90,9 @@ abstract class Tree { */ protected function getServerID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->server_id); + } return $this->server_id; } @@ -94,7 +104,9 @@ abstract class Tree { */ protected function getServer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $_SESSION[APPCONFIG]->getServer($this->server_id); } @@ -106,13 +118,19 @@ abstract class Tree { */ public function getBaseEntries() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $return = array(); foreach ($this->entries as $details) - if ($details->isBaseDN() AND ((! $this->getServer()->getValue('server','hide_noaccess_base')) OR $details->isInLdap())) - array_push($return,$details); + { + if ($details->isBaseDN() AND (( ! $this->getServer()->getValue('server', 'hide_noaccess_base')) OR $details->isInLdap())) + { + array_push($return, $details); + } + } return $return; } @@ -131,12 +149,16 @@ abstract class Tree { */ private function indexDN($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $index = strtolower(implode(',',pla_explode_dn($dn))); if (DEBUG_ENABLED) - debug_log('Result (%s)',1,0,__FILE__,__LINE__,__METHOD__,$index); + { + debug_log('Result (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $index); + } return $index; } @@ -149,14 +171,20 @@ abstract class Tree { */ public function getEntry($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $dnlower = $this->indexDN($dn); if (isset($this->entries[$dnlower])) + { return $this->entries[$dnlower]; + } else - return null; + { + return NULL; + } } /** @@ -167,7 +195,9 @@ abstract class Tree { */ public function addEntry($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $dnlower = $this->indexDN($dn); @@ -177,16 +207,22 @@ abstract class Tree { # return; if (isset($this->entries[$dnlower])) - debug_dump_backtrace('Calling add entry to an entry that ALREADY exists?',1); + { + debug_dump_backtrace('Calling add entry to an entry that ALREADY exists?', 1); + } if (DEBUG_ENABLED) - debug_log('New ENTRY (%s).',64,0,__FILE__,__LINE__,__METHOD__,$dn); + { + debug_log('New ENTRY (%s).', 64, 0, __FILE__, __LINE__, __METHOD__, $dn); + } $tree_factory = new TreeItem($server->getIndex(),$dn); $tree_factory->setObjectClasses($server->getDNAttrValue($dn,'objectClass')); if ((($isleaf = $server->getDNAttrValue($dn,'hassubordinates')) && ! strcasecmp($isleaf[0],'false'))) + { $tree_factory->setLeaf(); + } $this->entries[$dnlower] = $tree_factory; @@ -200,7 +236,9 @@ abstract class Tree { $parent_dn = $server->getContainer($dn); if (DEBUG_ENABLED) - debug_log('Parent DNs (%s)',64,0,__FILE__,__LINE__,__METHOD__,$parent_dn); + { + debug_log('Parent DNs (%s)', 64, 0, __FILE__, __LINE__, __METHOD__, $parent_dn); + } if ($parent_dn) { $parent_entry = $this->getEntry($parent_dn); @@ -224,20 +262,26 @@ abstract class Tree { */ public function delEntry($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $dnlower = $this->indexDN($dn); if (isset($this->entries[$dnlower])) + { unset($this->entries[$dnlower]); + } # Delete entry from parent's children as well. $parent_dn = $server->getContainer($dn); $parent_entry = $this->getEntry($parent_dn); if ($parent_entry) + { $parent_entry->delChild($dn); + } } /** @@ -248,7 +292,9 @@ abstract class Tree { */ public function renameEntry($dnOLD,$dnNEW) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $dnlowerOLD = $this->indexDN($dnOLD); @@ -256,7 +302,9 @@ abstract class Tree { $this->entries[$dnlowerNEW] = $this->entries[$dnlowerOLD]; if ($dnlowerOLD != $dnlowerNEW) + { unset($this->entries[$dnlowerOLD]); + } $this->entries[$dnlowerNEW]->rename($dnNEW); # Update the parent's children @@ -265,11 +313,15 @@ abstract class Tree { $parent_entry = $this->getEntry($parentNEW); if ($parent_entry) + { $parent_entry->addChild($dnNEW); + } $parent_entry = $this->getEntry($parentOLD); if ($parent_entry) + { $parent_entry->delChild($dnOLD); + } } /** @@ -280,13 +332,17 @@ abstract class Tree { */ public function readChildren($dn,$nolimit=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $dnlower = $this->indexDN($dn); if (! isset($this->entries[$dnlower])) - debug_dump_backtrace('Reading children on an entry that isnt set? '.$dnlower,true); + { + debug_dump_backtrace('Reading children on an entry that isnt set? ' . $dnlower, TRUE); + } $ldap['child_limit'] = $nolimit ? 0 : $_SESSION[APPCONFIG]->getValue('search','size_limit'); $ldap['filter'] = $_SESSION[APPCONFIG]->getValue('appearance','tree_filter'); @@ -302,28 +358,40 @@ abstract class Tree { } if (DEBUG_ENABLED) - debug_log('Children of (%s) are (%s)',64,0,__FILE__,__LINE__,__METHOD__,$dn,$ldap['children']); + { + debug_log('Children of (%s) are (%s)', 64, 0, __FILE__, __LINE__, __METHOD__, $dn, $ldap['children']); + } # Relax our execution time, it might take some time to load this if ($nolimit) - @set_time_limit($_SESSION[APPCONFIG]->getValue('search','time_limit')); + { + @set_time_limit($_SESSION[APPCONFIG]->getValue('search', 'time_limit')); + } $this->entries[$dnlower]->readingChildren(true); foreach ($ldap['children'] as $child) { if (DEBUG_ENABLED) - debug_log('Adding (%s)',64,0,__FILE__,__LINE__,__METHOD__,$child); + { + debug_log('Adding (%s)', 64, 0, __FILE__, __LINE__, __METHOD__, $child); + } if (! in_array($child,$this->entries[$dnlower]->getChildren())) + { $this->entries[$dnlower]->addChild($child); + } } $this->entries[$dnlower]->readingChildren(false); if (count($this->entries[$dnlower]->getChildren()) == $ldap['child_limit']) + { $this->entries[$dnlower]->setSizeLimited(); + } else + { $this->entries[$dnlower]->unsetSizeLimited(); + } } /** @@ -334,16 +402,22 @@ abstract class Tree { */ protected function readChildrenNumber($dn,$nolimit=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $dnlower = $this->indexDN($dn); if (! isset($this->entries[$dnlower])) - debug_dump_backtrace('Reading children on an entry that isnt set?',true); + { + debug_dump_backtrace('Reading children on an entry that isnt set?', TRUE); + } # Read the entry if we havent got it yet. if (! $this->entries[$dnlower]->isLeaf() && ! $this->entries[$dnlower]->getChildren()) - $this->readChildren($dn,$nolimit); + { + $this->readChildren($dn, $nolimit); + } return count($this->entries[$dnlower]->getChildren()); } diff --git a/lib/TreeItem.php b/lib/TreeItem.php index 12f44b3..0b8de68 100644 --- a/lib/TreeItem.php +++ b/lib/TreeItem.php @@ -40,7 +40,9 @@ class TreeItem { public function __construct($server_id,$dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server_id; $this->dn = $dn; @@ -53,7 +55,9 @@ class TreeItem { */ public function getDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->dn); + } return $this->dn; } @@ -69,7 +73,9 @@ class TreeItem { */ public function getRDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return get_rdn($this->getDN(),0,true); } @@ -79,7 +85,9 @@ class TreeItem { */ public function setBase() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->base_entry = true; } @@ -89,28 +97,36 @@ class TreeItem { */ public function isBaseDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->base_entry); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->base_entry); + } return $this->base_entry; } public function setObjectClasses($oc) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->objectclasses = $oc; } public function getObjectClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->objectclasses); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->objectclasses); + } return $this->objectclasses; } public function isInLDAP() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return count($this->objectclasses) ? true : false; } @@ -121,7 +137,9 @@ class TreeItem { */ public function getChildren() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->children); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->children); + } if ($this->childsort && ! $this->reading_children) { usort($this->children,'pla_compare_dns'); @@ -140,7 +158,9 @@ class TreeItem { */ public function isChildSorted() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->childsort); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->childsort); + } return $this->childsort; } @@ -150,7 +170,9 @@ class TreeItem { */ public function childSorted() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->childsort = false; } @@ -162,10 +184,14 @@ class TreeItem { */ public function addChild($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (in_array($dn,$this->children)) + { return; + } array_push($this->children,$dn); $this->childsort = true; @@ -178,14 +204,18 @@ class TreeItem { */ public function delChild($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->children) { # If the parent hasnt been opened in the tree, then there wont be any children. $index = array_search($dn,$this->children); if ($index !== false) + { unset($this->children[$index]); + } } } @@ -196,7 +226,9 @@ class TreeItem { */ public function rename($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->dn = $dn; } @@ -206,7 +238,9 @@ class TreeItem { */ public function isOpened() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->open); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->open); + } return $this->open; } @@ -216,7 +250,9 @@ class TreeItem { */ public function close() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->open = false; } @@ -226,7 +262,9 @@ class TreeItem { */ public function open() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->open = true; } @@ -236,7 +274,9 @@ class TreeItem { */ public function setLeaf() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->leaf = true; } @@ -246,7 +286,9 @@ class TreeItem { */ public function isLeaf() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->leaf); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->leaf); + } return $this->leaf; } @@ -257,10 +299,14 @@ class TreeItem { */ public function getIcon() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->icon); + } if (! $this->icon) - $this->icon = get_icon($this->server_id,$this->dn,$this->objectclasses); + { + $this->icon = get_icon($this->server_id, $this->dn, $this->objectclasses); + } return $this->icon; } @@ -270,7 +316,9 @@ class TreeItem { */ public function setSizeLimited() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->size_limited = true; } @@ -280,7 +328,9 @@ class TreeItem { */ public function unsetSizeLimited() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->size_limited = false; } @@ -290,21 +340,27 @@ class TreeItem { */ public function isSizeLimited() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->size_limited; } public function setTemplate($template) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->template = $template; } public function getTemplate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->template; } diff --git a/lib/Visitor.php b/lib/Visitor.php index 3e98dbf..68ddb9d 100644 --- a/lib/Visitor.php +++ b/lib/Visitor.php @@ -23,10 +23,14 @@ abstract class Visitor { public function __call($method,$args) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! in_array($method,array('get','visit','draw'))) - debug_dump_backtrace(sprintf('Incorrect use of method loading [%s]',$method),1); + { + debug_dump_backtrace(sprintf('Incorrect use of method loading [%s]', $method), 1); + } $methods = array(); @@ -41,7 +45,8 @@ abstract class Visitor { while ($class && ! method_exists($this,$call)) { if (defined('DEBUGTMP') && DEBUGTMP) - printf('Class (%s): Method doesnt exist (%s,%s)
    ',$class,get_class($this),$call); + { + printf('Class (%s): Method doesnt exist (%s,%s)
    ',$class,get_class($this),$call); } $class = get_parent_class($class); $call = "$method$fnct$class"; @@ -49,18 +54,22 @@ abstract class Visitor { } if (defined('DEBUGTMP') && DEBUGTMP) - printf('Calling Methods: %s
    ',implode('|',$methods)); + { + printf('Calling Methods: %s
    ', implode('|', $methods)); } if (defined('DEBUGTMP') && DEBUGTMP && method_exists($this,$call)) - printf('Method Exists: %s::%s (%s)
    ',get_class($this),$call,$args); + { + printf('Method Exists: %s::%s (%s)
    ', get_class($this), $call, $args); } if (method_exists($this,$call)) { $r = call_user_func_array(array($this,$call),$args); if (isset($r)) - return $r; + { + return $r; } else - return; + { + return; } } elseif (DEBUG_ENABLED) { debug_log('Doesnt exist param (%s,%s)',1,0,__FILE__,__LINE__,__METHOD__,$method,$fnct); @@ -76,12 +85,15 @@ abstract class Visitor { */ public function getServerID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id); + { + debug_log('Entered (%%)', 129, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->server_id); } if (isset($this->server_id)) - return $this->server_id; + { + return $this->server_id; } else - return null; + { + return NULL; } } /** @@ -91,7 +103,8 @@ abstract class Visitor { */ protected function getServer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); } return $_SESSION[APPCONFIG]->getServer($this->getServerID()); } diff --git a/lib/blowfish.php b/lib/blowfish.php index 2cdee47..16a7103 100644 --- a/lib/blowfish.php +++ b/lib/blowfish.php @@ -320,7 +320,7 @@ class Horde_Cipher_blowfish { $keyPos = 0; } } - $this->p[$i] = $this->p[$i] ^ $keyXor; + $this->p[$i] ^= $keyXor; } $encZero = array('L' => 0, 'R' => 0); @@ -438,9 +438,11 @@ class Horde_Cipher_blowfish { $unpack = unpack('N*', $block); if (! is_array($unpack)) + { error( sprintf('BLOWFISH: decryptBock()
    We expected unpack to produce an array, but instead it produced [%s]. This function was entered with (%s,%s). If you think that this is a bug, then please tell the PLA developers how you got here. You are using PLA [%s,%s]', - serialize($unpack),$block,$key,app_version(),phpversion()),'error','index.php'); + serialize($unpack), $block, $key, app_version(), phpversion()), 'error', 'index.php'); + } list($L, $R) = array_values($unpack); diff --git a/lib/config_default.php b/lib/config_default.php index ca837b0..056e358 100644 --- a/lib/config_default.php +++ b/lib/config_default.php @@ -585,14 +585,22 @@ class Config { static $CACHE = array(); if ($usecache && count($CACHE)) + { return $CACHE; + } foreach ($this->default as $key => $vals) + { $CACHE[$key] = $vals; + } foreach ($this->custom as $key => $vals) + { foreach ($vals as $index => $val) + { $CACHE[$key][$index]['value'] = $val; + } + } return $CACHE; } @@ -608,17 +616,27 @@ class Config { $config = $this->getConfigArray(); if (! isset($config[$key])) + { if ($fatal) + { error(sprintf('A call was made in [%s] to getValue requesting [%s] that isnt predefined.', - basename($_SERVER['PHP_SELF']),$key),'error',null,true); - else + basename($_SERVER['PHP_SELF']), $key), 'error', NULL, TRUE); + } else + { return ''; + } + } if (! isset($config[$key][$index])) + { if ($fatal) - error(sprintf('Requesting an index [%s] in key [%s] that isnt predefined.',$index,$key),'error',null,true); - else + { + error(sprintf('Requesting an index [%s] in key [%s] that isnt predefined.', $index, $key), 'error', NULL, TRUE); + } else + { return ''; + } + } return isset($config[$key][$index]['value']) ? $config[$key][$index]['value'] : $config[$key][$index]['default']; } @@ -630,9 +648,15 @@ class Config { $result = array(); foreach ($this->default as $option => $details) + { foreach ($details as $param => $values) + { if (isset($values['untested']) && $values['untested']) - array_push($result,sprintf('%s.%s',$option,$param)); + { + array_push($result, sprintf('%s.%s', $option, $param)); + } + } + } return $result; } @@ -642,7 +666,9 @@ class Config { */ public function CheckCustom() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->custom)) { foreach ($this->custom as $masterkey => $masterdetails) { @@ -650,19 +676,27 @@ class Config { if (isset($this->default->$masterkey)) { if (! is_array($masterdetails)) - error(sprintf('Error in configuration file, [%s] should be an ARRAY.',$masterdetails),'error',null,true); + { + error(sprintf('Error in configuration file, [%s] should be an ARRAY.', $masterdetails), 'error', NULL, TRUE); + } foreach ($masterdetails as $key => $value) { # Test that the key is correct. if (! in_array($key,array_keys($this->default->$masterkey))) - error(sprintf('Error in configuration file, [%s] has not been defined as a configurable variable.',$key),'error',null,true); + { + error(sprintf('Error in configuration file, [%s] has not been defined as a configurable variable.', $key), 'error', NULL, TRUE); + } # Test if its should be an array or not. if (is_array($this->default->{$masterkey}[$key]['default']) && ! is_array($value)) - error(sprintf('Error in configuration file, %s[\'%s\'] SHOULD be an array of values.',$masterkey,$key),'error',null,true); + { + error(sprintf('Error in configuration file, %s[\'%s\'] SHOULD be an array of values.', $masterkey, $key), 'error', NULL, TRUE); + } if (! is_array($this->default->{$masterkey}[$key]['default']) && is_array($value)) - error(sprintf('Error in configuration file, %s[\'%s\'] should NOT be an array of values.',$masterkey,$key),'error',null,true); + { + error(sprintf('Error in configuration file, %s[\'%s\'] should NOT be an array of values.', $masterkey, $key), 'error', NULL, TRUE); + } } } else { @@ -677,16 +711,22 @@ class Config { */ public function getCommandList() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $config = $this->getConfigArray(false); masort($config['command'],'summary'); if (isset($config['command']) && is_array($config['command'])) + { return $config['command']; + } else + { return array(); + } } /** @@ -696,7 +736,9 @@ class Config { */ public function isCommandAvailable($index='cmd') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $a = func_get_args(); array_shift($a); @@ -706,20 +748,30 @@ class Config { $cmd = $this->getValue('commands',$index); if (! is_string($a) || ! isset($cmd[$a])) - return false; + { + return FALSE; + } else + { return $cmd[$a]; + } } public function configDefinition($key,$index,$config) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($config) || ! array_key_exists('desc',$config) || ! array_key_exists('default',$config)) + { return; + } if (isset($this->default->$key)) + { $definition = $this->default->$key; + } $definition[$index] = $config; $this->default->$key = $definition; @@ -730,7 +782,9 @@ class Config { */ private function getFriendlyAttrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return array_change_key_case($this->getValue('appearance','friendly_attrs')); } @@ -744,23 +798,36 @@ class Config { */ public function getFriendlyName($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $friendly_attrs; if (! $friendly_attrs) + { $friendly_attrs = $this->getFriendlyAttrs(); + } if (! is_object($attr)) + { if (isset($friendly_attrs[$attr])) + { return $friendly_attrs[$attr]; - else + } else + { return $attr; + } + } if (isset($friendly_attrs[$attr->getName()])) + { return $friendly_attrs[$attr->getName()]; + } else - return $attr->getName(false); + { + return $attr->getName(FALSE); + } } /** @@ -772,7 +839,9 @@ class Config { */ public function haveFriendlyName($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $attr->getName(false) != $this->getFriendlyName($attr); } @@ -785,13 +854,19 @@ class Config { */ public function getFriendlyHTML($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->haveFriendlyName($attr)) + { return sprintf('%s', - _('Alias for'),$attr->getName(false),$this->getFriendlyName($attr)); + _('Alias for'), $attr->getName(FALSE), $this->getFriendlyName($attr)); + } else - return $attr->getName(false); + { + return $attr->getName(FALSE); + } } public function setServers($servers) { @@ -808,7 +883,9 @@ class Config { */ public function getServerList($visible=true) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',3,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 3, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->servers->getServerList($visible); } diff --git a/lib/createlm.php b/lib/createlm.php index e0b1872..1a8ad5c 100644 --- a/lib/createlm.php +++ b/lib/createlm.php @@ -138,8 +138,14 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 * @return int */ private function x($i) { - if ($i < 0) return 4294967296 - $i; - else return $i; + if ($i < 0) + { + return 4294967296 - $i; + } + else + { + return $i; + } } /** @@ -205,7 +211,10 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 $d = $this->lshift($this->sc[$i], $d); $cd = $c; - for ($k = 0; $k < sizeof($d); $k++) $cd[] = $d[$k]; + for ($k = 0; $k < sizeof($d); $k++) + { + $cd[] = $d[$k]; + } $ki[$i] = $this->permute($cd, $this->perm2, 48); } @@ -220,8 +229,14 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 for ($i = 0; $i < 16; $i++) { $er = $this->permute($r, $this->perm4, 48); - if ($forw) $erk = $this->mxor($er, $ki[$i]); - else $erk = $this->mxor($er, $ki[15 - $i]); + if ($forw) + { + $erk = $this->mxor($er, $ki[$i]); + } + else + { + $erk = $this->mxor($er, $ki[15 - $i]); + } for ($j = 0; $j < 8; $j++) { for ($k = 0; $k < 6; $k++) { @@ -246,11 +261,20 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 } $pcb = $this->permute($cb, $this->perm5, 32); $r2 = $this->mxor($l, $pcb); - for ($k = 0; $k < 32; $k++) $l[$k] = $r[$k]; - for ($k = 0; $k < 32; $k++) $r[$k] = $r2[$k]; + for ($k = 0; $k < 32; $k++) + { + $l[$k] = $r[$k]; + } + for ($k = 0; $k < 32; $k++) + { + $r[$k] = $r2[$k]; + } } $rl = $r; - for ($i = 0; $i < sizeof($l); $i++) $rl[] = $l[$i]; + for ($i = 0; $i < sizeof($l); $i++) + { + $rl[] = $l[$i]; + } return $this->permute($rl, $this->perm6, 64); } @@ -270,7 +294,7 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 $key[6] = (($str[5]&0x3F)<<1) | $this->unsigned_shift_r($str[6], 7); $key[7] = $str[6]&0x7F; for ($i = 0; $i < 8; $i++) { - $key[$i] = ($key[$i] << 1); + $key[$i] <<= 1; } return $key; } @@ -352,12 +376,19 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 */ public function nthash($password = "") { if (function_exists('mhash')) + { if (defined('MHASH_MD4')) - return strtoupper(bin2hex(mhash(MHASH_MD4,iconv('UTF-8','UTF-16LE',$password)))); - else - return strtoupper(hash('md4', iconv("UTF-8","UTF-16LE",$password))); + { + return strtoupper(bin2hex(mhash(MHASH_MD4, iconv('UTF-8', 'UTF-16LE', $password)))); + } else + { + return strtoupper(hash('md4', iconv("UTF-8", "UTF-16LE", $password))); + } + } else - error(_('Your PHP install does not have the mhash() function. Cannot do hashes.'),'error','index.php'); + { + error(_('Your PHP install does not have the mhash() function. Cannot do hashes.'), 'error', 'index.php'); + } } /** @@ -371,13 +402,13 @@ private $sbox = array(array(array(14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12 private function unsigned_shift_r($a, $b) { $z = 0x80000000; if ($z & $a) { - $a = ($a >> 1); + $a >>= 1; $a &= (~$z); $a |= 0x40000000; - $a = ($a >> ($b - 1)); + $a >>= ($b - 1); } else { - $a = ($a >> $b); + $a >>= $b; } return $a; } diff --git a/lib/ds.php b/lib/ds.php index c046ae8..10422cb 100644 --- a/lib/ds.php +++ b/lib/ds.php @@ -62,8 +62,12 @@ abstract class DS { */ public function setDefaults($defaults) { foreach ($defaults as $key => $details) + { foreach ($details as $setting => $value) + { $this->default->{$key}[$setting] = $value; + } + } } public function isDefaultKey($key) { @@ -83,19 +87,29 @@ abstract class DS { */ public function getValue($key,$setting,$fatal=true) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->custom->{$key}[$setting])) + { return $this->custom->{$key}[$setting]; + } elseif (isset($this->default->{$key}[$setting]) && array_key_exists('default',$this->default->{$key}[$setting])) + { return $this->default->{$key}[$setting]['default']; + } elseif ($fatal) - debug_dump_backtrace("Error trying to get a non-existant value ($key,$setting)",1); + { + debug_dump_backtrace("Error trying to get a non-existant value ($key,$setting)", 1); + } else - return null; + { + return NULL; + } } /** @@ -106,11 +120,13 @@ abstract class DS { */ public function setValue($key,$setting,$value) { if (isset($this->custom->{$key}[$setting])) + { system_message(array( - 'title'=>_('Configuration setting already defined.'), - 'body'=>sprintf('A call has been made to reset a configuration value (%s,%s,%s)', - $key,$setting,$value), - 'type'=>'info')); + 'title' => _('Configuration setting already defined.'), + 'body' => sprintf('A call has been made to reset a configuration value (%s,%s,%s)', + $key, $setting, $value), + 'type' => 'info')); + } $this->custom->{$key}[$setting] = $value; } @@ -122,9 +138,15 @@ abstract class DS { $result = array(); foreach ($this->default as $option => $details) + { foreach ($details as $param => $values) + { if (isset($values['untested']) && $values['untested']) - array_push($result,sprintf('%s.%s',$option,$param)); + { + array_push($result, sprintf('%s.%s', $option, $param)); + } + } + } return $result; } @@ -134,7 +156,9 @@ abstract class DS { */ public function getName() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('server','name'); } @@ -147,7 +171,9 @@ abstract class DS { */ public function getAuthType() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } switch ($this->getValue('login','auth_type')) { case 'cookie': @@ -173,45 +199,68 @@ abstract class DS { */ public function getLogin($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $method = $this->getMethod($method); # For anonymous binds if ($method == 'anon') + { if (isset($_SESSION['USER'][$this->index][$method]['name'])) + { return ''; - else - return null; + } else + { + return NULL; + } + } switch ($this->getAuthType()) { case 'cookie': if (! isset($_COOKIE[$method.'-USER'])) # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_id')) && $method == 'login') ? $this->getValue('login','bind_id') : null; + { + return ( ! is_null($this->getValue('login', 'bind_id')) && $method == 'login') ? $this->getValue('login', 'bind_id') : NULL; + } else - return blowfish_decrypt($_COOKIE[$method.'-USER']); + { + return blowfish_decrypt($_COOKIE[$method . '-USER']); + } case 'config': if (! isset($_SESSION['USER'][$this->index][$method]['name'])) - return $this->getValue('login','bind_id'); + { + return $this->getValue('login', 'bind_id'); + } else + { return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['name']); + } case 'proxy': if (! isset($_SESSION['USER'][$this->index][$method]['proxy'])) - return $this->getValue('login','bind_id'); + { + return $this->getValue('login', 'bind_id'); + } else + { return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['proxy']); + } case 'http': case 'session': case 'sasl': if (! isset($_SESSION['USER'][$this->index][$method]['name'])) # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_id')) && $method == 'login') ? $this->getValue('login','bind_id') : null; + { + return ( ! is_null($this->getValue('login', 'bind_id')) && $method == 'login') ? $this->getValue('login', 'bind_id') : NULL; + } else + { return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['name']); + } default: die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); @@ -227,7 +276,9 @@ abstract class DS { */ protected function setLogin($user,$pass,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $method = $this->getMethod($method); @@ -242,7 +293,9 @@ abstract class DS { case 'proxy': if (isset($_SESSION['USER'][$this->index][$method]['proxy'])) + { unset($_SESSION['USER'][$this->index][$method]['proxy']); + } case 'http': case 'session': @@ -264,40 +317,59 @@ abstract class DS { */ protected function getPassword($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $method = $this->getMethod($method); # For anonymous binds if ($method == 'anon') + { if (isset($_SESSION['USER'][$this->index][$method]['name'])) + { return ''; - else - return null; + } else + { + return NULL; + } + } switch ($this->getAuthType()) { case 'cookie': if (! isset($_COOKIE[$method.'-PASS'])) # If our bind_id is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_pass')) && $method == 'login') ? $this->getValue('login','bind_pass') : null; + { + return ( ! is_null($this->getValue('login', 'bind_pass')) && $method == 'login') ? $this->getValue('login', 'bind_pass') : NULL; + } else - return blowfish_decrypt($_COOKIE[$method.'-PASS']); + { + return blowfish_decrypt($_COOKIE[$method . '-PASS']); + } case 'config': case 'proxy': if (! isset($_SESSION['USER'][$this->index][$method]['pass'])) - return $this->getValue('login','bind_pass'); + { + return $this->getValue('login', 'bind_pass'); + } else + { return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['pass']); + } case 'http': case 'session': case 'sasl': if (! isset($_SESSION['USER'][$this->index][$method]['pass'])) # If our bind_pass is set, we'll pass that back for logins. - return (! is_null($this->getValue('login','bind_pass')) && $method == 'login') ? $this->getValue('login','bind_pass') : null; + { + return ( ! is_null($this->getValue('login', 'bind_pass')) && $method == 'login') ? $this->getValue('login', 'bind_pass') : NULL; + } else + { return blowfish_decrypt($_SESSION['USER'][$this->index][$method]['pass']); + } default: die(sprintf('Error: %s hasnt been configured for auth_type %s',__METHOD__,$this->getAuthType())); @@ -311,14 +383,18 @@ abstract class DS { */ public function isLoggedIn($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); $method = $this->getMethod($method); if (isset($CACHE[$this->index][$method]) && ! is_null($CACHE[$this->index][$method])) + { return $CACHE[$this->index][$method]; + } $CACHE[$this->index][$method] = null; @@ -326,10 +402,12 @@ abstract class DS { switch ($this->getAuthType()) { case 'config': if (! $CACHE[$this->index][$method] = $this->login($this->getLogin($method),$this->getPassword($method),$method)) + { system_message(array( - 'title'=>_('Unable to login.'), - 'body'=>_('Your configuration file has authentication set to CONFIG based authentication, however, the userid/password failed to login'), - 'type'=>'error')); + 'title' => _('Unable to login.'), + 'body' => _('Your configuration file has authentication set to CONFIG based authentication, however, the userid/password failed to login'), + 'type' => 'error')); + } break; @@ -345,9 +423,13 @@ abstract class DS { header(sprintf('WWW-Authenticate: Basic realm="%s %s"',app_name(),_('login'))); if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0') - header('HTTP/1.0 401 Unauthorized'); // http 1.0 method + { + header('HTTP/1.0 401 Unauthorized'); + } // http 1.0 method else - header('Status: 401 Unauthorized'); // http 1.1 method + { + header('Status: 401 Unauthorized'); + } // http 1.1 method # If we still dont have login details... if (! isset($_SERVER['PHP_AUTH_USER'])) { @@ -370,7 +452,9 @@ abstract class DS { $CACHE[$this->index][$method] = false; } else - $CACHE[$this->index][$method] = true; + { + $CACHE[$this->index][$method] = TRUE; + } } break; @@ -383,9 +467,13 @@ abstract class DS { case 'sasl': # Propogate any given Kerberos credential cache location if (isset($_ENV['REDIRECT_KRB5CCNAME'])) - putenv(sprintf('KRB5CCNAME=%s',$_ENV['REDIRECT_KRB5CCNAME'])); + { + putenv(sprintf('KRB5CCNAME=%s', $_ENV['REDIRECT_KRB5CCNAME'])); + } elseif (isset($_SERVER['KRB5CCNAME'])) - putenv(sprintf('KRB5CCNAME=%s',$_SERVER['KRB5CCNAME'])); + { + putenv(sprintf('KRB5CCNAME=%s', $_SERVER['KRB5CCNAME'])); + } # Map the SASL auth ID to a DN $regex = $this->getValue('login', 'sasl_dn_regex'); @@ -399,7 +487,9 @@ abstract class DS { # Otherwise, use the user name as is # For GSSAPI Authentication + mod_auth_kerb and Basic Authentication } else + { $CACHE[$this->index][$method] = $this->login(isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : '', '', $method); + } break; @@ -417,7 +507,9 @@ abstract class DS { */ public function logout($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $method = $this->getMethod($method); @@ -436,7 +528,9 @@ abstract class DS { case 'session': case 'sasl': if (isset($_SESSION['USER'][$this->index][$method])) + { unset($_SESSION['USER'][$this->index][$method]); + } return true; @@ -450,24 +544,34 @@ abstract class DS { */ public function isVisible() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('server','visible'); } public function isReadOnly() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! trim($this->getLogin(null)) && $_SESSION[APPCONFIG]->getValue('appearance','anonymous_bind_implies_read_only')) - return true; + { + return TRUE; + } else - return $this->getValue('server','read_only'); + { + return $this->getValue('server', 'read_only'); + } } public function getIndex() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->index); + { + debug_log('Entered (%%)', 17, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->index); + } return $this->index; } @@ -483,22 +587,30 @@ abstract class DS { */ protected function getMethod($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); # Immediately return if method is set. if (! is_null($method)) + { return $method; + } # If we have been here already, then return our result if (isset($CACHE[$this->index]) && ! is_null($CACHE)) + { return $CACHE[$this->index]; + } $CACHE[$this->index] = 'anon'; if ($this->isLoggedIn('user')) + { $CACHE[$this->index] = 'user'; + } return $CACHE[$this->index]; } @@ -508,7 +620,9 @@ abstract class DS { */ public function isSessionValid() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs,true); + { + debug_log('Entered (%%)', 17, 1, __FILE__, __LINE__, __METHOD__, $fargs, TRUE); + } return true; } @@ -519,12 +633,18 @@ abstract class DS { */ public function inactivityTime() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->isLoggedIn() && ! in_array($this->getAuthType(),array('config','http'))) - return time()+($this->getValue('login','timeout')*60); + { + return time() + ($this->getValue('login', 'timeout') * 60); + } else - return null; + { + return NULL; + } } } @@ -654,17 +774,25 @@ class Datastore { */ public function setValue($key,$setting,$value) { if (! $this->objects[$this->index]->isDefaultKey($key)) - error("ERROR: Setting a key [$key] that isnt predefined.",'error',true); + { + error("ERROR: Setting a key [$key] that isnt predefined.", 'error', TRUE); + } if (! $this->objects[$this->index]->isDefaultSetting($key,$setting)) - error("ERROR: Setting a index [$key,$setting] that isnt predefined.",'error',true); + { + error("ERROR: Setting a index [$key,$setting] that isnt predefined.", 'error', TRUE); + } # Test if its should be an array or not. if (is_array($this->objects[$this->index]->getValue($key,$setting)) && ! is_array($value)) - error("Error in configuration file, {$key}['$setting'] SHOULD be an array of values.",'error',true); + { + error("Error in configuration file, {$key}['$setting'] SHOULD be an array of values.", 'error', TRUE); + } if (! is_array($this->objects[$this->index]->getValue($key,$setting)) && is_array($value)) - error("Error in configuration file, {$key}['$setting'] should NOT be an array of values.",'error',true); + { + error("Error in configuration file, {$key}['$setting'] should NOT be an array of values.", 'error', TRUE); + } # Store the value in the object. $this->objects[$this->index]->setValue($key,$setting,$value); @@ -678,12 +806,16 @@ class Datastore { */ public function getServerList($isVisible=true) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE; if (isset($CACHE[$isVisible])) + { return $CACHE[$isVisible]; + } $CACHE[$isVisible] = array(); @@ -695,8 +827,12 @@ class Datastore { } foreach ($this->objects as $id => $server) - if (! $isVisible || ($isVisible && $server->getValue('server','visible'))) + { + if ( ! $isVisible || ($isVisible && $server->getValue('server', 'visible'))) + { $CACHE[$isVisible][$id] = $server; + } + } masort($CACHE[$isVisible],'name'); @@ -711,17 +847,25 @@ class Datastore { */ public function Instance($index=null) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If no index defined, then pick the lowest one. if (is_null($index) || ! trim($index) || ! is_numeric($index)) + { $index = min($this->getServerList())->getIndex(); + } if (! isset($this->objects[$index])) - debug_dump_backtrace(sprintf('Error: Datastore instance [%s] doesnt exist?',htmlspecialchars($index)),1); + { + debug_dump_backtrace(sprintf('Error: Datastore instance [%s] doesnt exist?', htmlspecialchars($index)), 1); + } if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) - debug_log('Returning instance of database (%s)',3,0,__FILE__,__LINE__,__METHOD__,$index); + { + debug_log('Returning instance of database (%s)', 3, 0, __FILE__, __LINE__, __METHOD__, $index); + } return $this->objects[$index]; } @@ -734,11 +878,17 @@ class Datastore { */ public function InstanceName($name=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->getServerList(false) as $index) + { if ($this->objects[$index]->getName() == $name) + { return $this->objects[$index]; + } + } # If we get here, then no object with the name exists. return null; @@ -752,11 +902,17 @@ class Datastore { */ public function InstanceId($id=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->getServerList(false) as $index) - if ($this->objects[$index->getIndex()]->getValue('server','id') == $id) + { + if ($this->objects[$index->getIndex()]->getValue('server', 'id') == $id) + { return $this->objects[$index->getIndex()]; + } + } # If we get here, then no object with the name exists. return null; diff --git a/lib/ds_ldap.php b/lib/ds_ldap.php index d1131d7..6951828 100644 --- a/lib/ds_ldap.php +++ b/lib/ds_ldap.php @@ -22,7 +22,9 @@ class ldap extends DS { public function __construct($index) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->index = $index; $this->type = 'ldap'; @@ -123,7 +125,9 @@ class ldap extends DS { */ protected function connect($method,$debug=false,$new=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); @@ -131,7 +135,9 @@ class ldap extends DS { $bind = array(); if (isset($CACHE[$this->index][$method]) && $CACHE[$this->index][$method]) + { return $CACHE[$this->index][$method]; + } # Check if we have logged in and therefore need to use those details as our bind. $bind['id'] = is_null($this->getLogin($method)) && $method != 'anon' ? $this->getLogin('user') : $this->getLogin($method); @@ -139,41 +145,59 @@ class ldap extends DS { # If our bind id is still null, we are not logged in. if (is_null($bind['id']) && ! in_array($method,array('anon','login'))) - return null; + { + return NULL; + } # If we bound to the LDAP server with these details for a different connection, return that resource if (isset($CACHE[$this->index]) && ! $new) - foreach ($CACHE[$this->index] as $cachedmethod => $resource) { - if (($this->getLogin($cachedmethod) == $bind['id']) && ($this->getPassword($cachedmethod) == $bind['pass'])) { + { + foreach ($CACHE[$this->index] as $cachedmethod => $resource) + { + if (($this->getLogin($cachedmethod) == $bind['id']) && ($this->getPassword($cachedmethod) == $bind['pass'])) + { $CACHE[$this->index][$method] = $resource; return $CACHE[$this->index][$method]; } } + } $CACHE[$this->index][$method] = null; # No identifiable connection exists, lets create a new one. if (DEBUG_ENABLED) - debug_log('Creating NEW connection [%s] for index [%s]',16,0,__FILE__,__LINE__,__METHOD__, - $method,$this->index); + { + debug_log('Creating NEW connection [%s] for index [%s]', 16, 0, __FILE__, __LINE__, __METHOD__, + $method, $this->index); + } if (function_exists('run_hook')) - run_hook('pre_connect',array('server_id'=>$this->index,'method'=>$method)); + { + run_hook('pre_connect', array('server_id' => $this->index, 'method' => $method)); + } if ($this->getValue('server','port')) - $resource = ldap_connect($this->getValue('server','host'),$this->getValue('server','port')); + { + $resource = ldap_connect($this->getValue('server', 'host'), $this->getValue('server', 'port')); + } else - $resource = ldap_connect($this->getValue('server','host')); + { + $resource = ldap_connect($this->getValue('server', 'host')); + } $CACHE[$this->index][$method] = $resource; if (DEBUG_ENABLED) - debug_log('LDAP Resource [%s], Host [%s], Port [%s]',16,0,__FILE__,__LINE__,__METHOD__, - $resource,$this->getValue('server','host'),$this->getValue('server','port')); + { + debug_log('LDAP Resource [%s], Host [%s], Port [%s]', 16, 0, __FILE__, __LINE__, __METHOD__, + $resource, $this->getValue('server', 'host'), $this->getValue('server', 'port')); + } if (! is_resource($resource)) - debug_dump_backtrace('UNHANDLED, $resource is not a resource',1); + { + debug_dump_backtrace('UNHANDLED, $resource is not a resource', 1); + } # Go with LDAP version 3 if possible (needed for renaming and Novell schema fetching) ldap_set_option($resource,LDAP_OPT_PROTOCOL_VERSION,3); @@ -185,25 +209,37 @@ class ldap extends DS { # Try to fire up TLS is specified in the config if ($this->isTLSEnabled()) + { $this->startTLS($resource); + } # If SASL has been configured for binding, then start it now. if ($this->isSASLEnabled()) - $bind['result'] = $this->startSASL($resource,$method); + { + $bind['result'] = $this->startSASL($resource, $method); + } # Normal bind... else - $bind['result'] = @ldap_bind($resource,$bind['id'],$bind['pass']); + { + $bind['result'] = @ldap_bind($resource, $bind['id'], $bind['pass']); + } if ($debug) - debug_dump(array('method'=>$method,'bind'=>$bind,'USER'=>$_SESSION['USER'])); + { + debug_dump(array('method' => $method, 'bind' => $bind, 'USER' => $_SESSION['USER'])); + } if (DEBUG_ENABLED) - debug_log('Resource [%s], Bind Result [%s]',16,0,__FILE__,__LINE__,__METHOD__,$resource,$bind); + { + debug_log('Resource [%s], Bind Result [%s]', 16, 0, __FILE__, __LINE__, __METHOD__, $resource, $bind); + } if (! $bind['result']) { if (DEBUG_ENABLED) - debug_log('Leaving with FALSE, bind FAILed',16,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Leaving with FALSE, bind FAILed', 16, 0, __FILE__, __LINE__, __METHOD__); + } $this->noconnect = true; @@ -219,17 +255,24 @@ class ldap extends DS { # If this is a proxy session, we need to switch to the proxy user if ($this->isProxyEnabled() && $bind['id'] && $method != 'anon') - if (! $this->startProxy($resource,$method)) { - $this->noconnect = true; - $CACHE[$this->index][$method] = null; + { + if ( ! $this->startProxy($resource, $method)) + { + $this->noconnect = TRUE; + $CACHE[$this->index][$method] = NULL; } + } } if (function_exists('run_hook')) - run_hook('post_connect',array('server_id'=>$this->index,'method'=>$method,'id'=>$bind['id'])); + { + run_hook('post_connect', array('server_id' => $this->index, 'method' => $method, 'id' => $bind['id'])); + } if ($debug) - debug_dump(array($method=>$CACHE[$this->index][$method])); + { + debug_dump(array($method => $CACHE[$this->index][$method])); + } return $CACHE[$this->index][$method]; } @@ -245,7 +288,9 @@ class ldap extends DS { */ public function login($user=null,$pass=null,$method=null,$new=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $userDN = null; @@ -253,15 +298,23 @@ class ldap extends DS { if (! is_null($user)) { # If login,attr is set to DN, then user should be a DN if (($this->getValue('login','attr') == 'dn') || $method != 'user') + { $userDN = $user; + } else - $userDN = $this->getLoginID($user,'login'); + { + $userDN = $this->getLoginID($user, 'login'); + } if (! $userDN && $this->getValue('login','fallback_dn')) + { $userDN = $user; + } if (! $userDN) - return false; + { + return FALSE; + } } else { if (in_array($method,array('user','anon'))) { @@ -276,7 +329,9 @@ class ldap extends DS { } if (! $this->isAnonBindAllowed() && ! trim($userDN)) - return false; + { + return FALSE; + } # Temporarily set our user details $this->setLogin($userDN,$pass,$method); @@ -290,7 +345,9 @@ class ldap extends DS { return false; } else - return true; + { + return TRUE; + } } /** @@ -309,16 +366,22 @@ class ldap extends DS { */ public function query($query,$method,$index=null,$debug=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attrs_only = 0; # Defaults if (! isset($query['attrs'])) + { $query['attrs'] = array(); + } else # Re-index the attrs, PHP throws an error if the keys are not sequential from 0. + { $query['attrs'] = array_values($query['attrs']); + } if (! isset($query['base'])) { $bases = $this->getBaseDN(); @@ -326,21 +389,33 @@ class ldap extends DS { } if (! isset($query['deref'])) - $query['deref'] = $_SESSION[APPCONFIG]->getValue('deref','search'); + { + $query['deref'] = $_SESSION[APPCONFIG]->getValue('deref', 'search'); + } if (! isset($query['filter'])) + { $query['filter'] = '(&(objectClass=*))'; + } if (! isset($query['scope'])) + { $query['scope'] = 'sub'; + } if (! isset($query['size_limit'])) + { $query['size_limit'] = 0; + } if (! isset($query['time_limit'])) + { $query['time_limit'] = 0; + } if ($query['scope'] == 'base' && ! isset($query['baseok'])) + { system_message(array( - 'title'=>sprintf('Dont call %s',__METHOD__), - 'body'=>sprintf('Use getDNAttrValues for base queries [%s]',$query['base']), - 'type'=>'info')); + 'title' => sprintf('Dont call %s', __METHOD__), + 'body' => sprintf('Use getDNAttrValues for base queries [%s]', $query['base']), + 'type' => 'info')); + } if (is_array($query['base'])) { system_message(array( @@ -352,10 +427,14 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('%s search PREPARE.',16,0,__FILE__,__LINE__,__METHOD__,$query['scope']); + { + debug_log('%s search PREPARE.', 16, 0, __FILE__, __LINE__, __METHOD__, $query['scope']); + } if ($debug) - debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method))); + { + debug_dump(array('query' => $query, 'server' => $this->getIndex(), 'con' => $this->connect($method))); + } $resource = $this->connect($method,$debug); @@ -375,14 +454,20 @@ class ldap extends DS { } if ($debug) - debug_dump(array('method'=>$method,'search'=>$search,'error'=>$this->getErrorMessage())); + { + debug_dump(array('method' => $method, 'search' => $search, 'error' => $this->getErrorMessage())); + } if (DEBUG_ENABLED) - debug_log('Search scope [%s] base [%s] filter [%s] attrs [%s] COMPLETE (%s).',16,0,__FILE__,__LINE__,__METHOD__, - $query['scope'],$query['base'],$query['filter'],$query['attrs'],is_null($search)); + { + debug_log('Search scope [%s] base [%s] filter [%s] attrs [%s] COMPLETE (%s).', 16, 0, __FILE__, __LINE__, __METHOD__, + $query['scope'], $query['base'], $query['filter'], $query['attrs'], is_null($search)); + } if (! $search) + { return array(); + } $return = array(); @@ -390,12 +475,16 @@ class ldap extends DS { if ($entries = ldap_get_entries($resource,$search)) { # Remove the count if (isset($entries['count'])) + { unset($entries['count']); + } # Iterate over the entries foreach ($entries as $a => $entry) { if (! isset($entry['dn'])) - debug_dump_backtrace('No DN?',1); + { + debug_dump_backtrace('No DN?', 1); + } # Remove the none entry references. if (! is_array($entry)) { @@ -416,7 +505,9 @@ class ldap extends DS { # Remove the count if (isset($entry[$b]['count'])) + { unset($entry[$b]['count']); + } } # Our queries always include the DN (the only value not an array). @@ -426,11 +517,15 @@ class ldap extends DS { # Sort our results foreach ($return as $key=> $values) + { ksort($return[$key]); + } } if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -442,7 +537,9 @@ class ldap extends DS { */ public function getErrorMessage($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return ldap_error($this->connect($method)); } @@ -454,7 +551,9 @@ class ldap extends DS { */ public function getErrorNum($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return ldap_errno($this->connect($method)); } @@ -471,7 +570,9 @@ class ldap extends DS { */ public function getLoginID($user,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $query['filter'] = sprintf('(&(%s=%s)%s)', $this->getValue('login','attr'),$user, @@ -484,18 +585,26 @@ class ldap extends DS { $result = $this->query($query,$method); if (count($result) == 1) + { break; + } } if (count($result) != 1) - return null; + { + return NULL; + } $detail = array_shift($result); if (! isset($detail['dn'])) + { die('ERROR: DN missing?'); + } else + { return $detail['dn']; + } } /** @@ -504,12 +613,18 @@ class ldap extends DS { */ private function getLoginBaseDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getValue('login','base')) - return $this->getValue('login','base'); + { + return $this->getValue('login', 'base'); + } else + { return $this->getBaseDN(); + } } /** @@ -517,7 +632,9 @@ class ldap extends DS { */ private function getLoginClass() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('login','class'); } @@ -527,7 +644,9 @@ class ldap extends DS { */ public function isAnonBindAllowed() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('login','anon_bind'); } @@ -544,14 +663,18 @@ class ldap extends DS { */ private function isTLSEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getValue('server','tls') && ! function_exists('ldap_start_tls')) { error(_('TLS has been enabled in your config, but your PHP install does not support TLS. TLS will be disabled.'),'warn'); return false; } else - return $this->getValue('server','tls'); + { + return $this->getValue('server', 'tls'); + } } /** @@ -561,7 +684,9 @@ class ldap extends DS { */ private function startTLS($resource) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! $this->getValue('server','tls') || (function_exists('ldap_start_tls') && ! @ldap_start_tls($resource))) { system_message(array( @@ -572,7 +697,9 @@ class ldap extends DS { return false; } else - return true; + { + return TRUE; + } } /** @@ -587,10 +714,14 @@ class ldap extends DS { */ private function isSASLEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getValue('login','auth_type') != 'sasl') - return false; + { + return FALSE; + } if (! function_exists('ldap_sasl_bind')) { error(_('SASL has been enabled in your config, but your PHP install does not support SASL. SASL will be disabled.'),'warn'); @@ -613,13 +744,17 @@ class ldap extends DS { */ private function startSASL($resource,$method) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); # We shouldnt be doing SASL binds for anonymous queries? if ($method == 'anon') - return false; + { + return FALSE; + } # At the moment, we have only implemented GSSAPI if (! in_array(strtolower($this->getValue('sasl','mech')),array('gssapi'))) { @@ -632,7 +767,9 @@ class ldap extends DS { } if (! isset($CACHE['login_dn'])) + { $CACHE['login_dn'] = is_null($this->getLogin($method)) ? $this->getLogin('user') : $this->getLogin($method); + } $CACHE['authz_id'] = ''; @@ -687,7 +824,9 @@ class ldap extends DS { */ private function isProxyEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('login','auth_type') == 'proxy' ? true : false; } @@ -700,7 +839,9 @@ class ldap extends DS { */ private function startProxy($resource,$method) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $rootdse = $this->getRootDSE(); @@ -733,12 +874,16 @@ class ldap extends DS { break; } else - $filter .= sprintf('(%s=%s)',$attr,$_SERVER[$var]); + { + $filter .= sprintf('(%s=%s)', $attr, $_SERVER[$var]); + } } } if ($missing) - return false; + { + return FALSE; + } $filter .= ')'; @@ -749,7 +894,9 @@ class ldap extends DS { $query['base'] = $base; if ($search = $this->query($query,$method)) + { break; + } } if (count($search) != 1) { @@ -793,7 +940,9 @@ class ldap extends DS { */ public function modify($dn,$attrs,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # We need to supress the error here - programming should detect and report it. return @ldap_mod_replace($this->connect($method),$dn,$attrs); @@ -816,7 +965,9 @@ class ldap extends DS { */ public function getBaseDN($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE; @@ -824,19 +975,25 @@ class ldap extends DS { $result = array(); if (isset($CACHE[$this->index][$method])) + { return $CACHE[$this->index][$method]; + } # If the base is set in the configuration file, then just return that. if (count($this->getValue('server','base'))) { if (DEBUG_ENABLED) - debug_log('Return BaseDN from Config [%s]',17,0,__FILE__,__LINE__,__METHOD__,implode('|',$this->getValue('server','base'))); + { + debug_log('Return BaseDN from Config [%s]', 17, 0, __FILE__, __LINE__, __METHOD__, implode('|', $this->getValue('server', 'base'))); + } $CACHE[$this->index][$method] = $this->getValue('server','base'); # We need to figure it out. } else { if (DEBUG_ENABLED) - debug_log('Connect to LDAP to find BaseDN',80,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Connect to LDAP to find BaseDN', 80, 0, __FILE__, __LINE__, __METHOD__); + } # Set this to empty, in case we loop back here looking for the baseDNs $CACHE[$this->index][$method] = array(); @@ -845,7 +1002,9 @@ class ldap extends DS { if (isset($results['namingcontexts'])) { if (DEBUG_ENABLED) - debug_log('LDAP Entries:%s',80,0,__FILE__,__LINE__,__METHOD__,implode('|',$results['namingcontexts'])); + { + debug_log('LDAP Entries:%s', 80, 0, __FILE__, __LINE__, __METHOD__, implode('|', $results['namingcontexts'])); + } $result = $results['namingcontexts']; } @@ -866,14 +1025,20 @@ class ldap extends DS { */ public function dnExists($dn,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $results = $this->getDNAttrValues($dn,$method); if ($results) + { return $results; + } else - return false; + { + return FALSE; + } } /** @@ -884,7 +1049,9 @@ class ldap extends DS { */ public function getContainerTop($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $return = $dn; @@ -896,7 +1063,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -910,7 +1079,9 @@ class ldap extends DS { */ public function getContainerPath($dn,$path='..') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $top = $this->getContainerTop($dn); @@ -927,16 +1098,24 @@ class ldap extends DS { foreach ($parenttree as $key => $value) { if ($value == '..') { if ($this->getContainer($dn)) + { $dn = $this->getContainer($dn); + } if ($dn == $top) + { break; + } } elseif($value) - $dn = sprintf('%s,%s',$value,$dn); + { + $dn = sprintf('%s,%s', $value, $dn); + } else + { break; + } } if (! $dn) { @@ -957,22 +1136,30 @@ class ldap extends DS { */ public function getContainer($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $parts = $this->explodeDN($dn); if (count($parts) <= 1) - $return = null; + { + $return = NULL; + } else { $return = $parts[1]; for ($i=2;$iescapeDN($dn),1); if (! $result[$with_attributes]) { if (DEBUG_ENABLED) - debug_log('Returning NULL - NO result.',1,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Returning NULL - NO result.', 1, 0, __FILE__, __LINE__, __METHOD__); + } return array(); } @@ -1099,7 +1296,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$result[$with_attributes]); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $result[$with_attributes]); + } return $result[$with_attributes]; } @@ -1111,19 +1310,27 @@ class ldap extends DS { */ protected function escapeDN($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! trim($dn)) + { return $dn; + } # Check if the RDN has a comma and escape it. while (preg_match('/([^\\\\]),(\s*[^=]*\s*),/',$dn)) - $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/','$1\\\\2C$2,',$dn); + { + $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/', '$1\\\\2C$2,', $dn); + } $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*)([^,])$/','$1\\\\2C$2$3',$dn); if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$dn); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $dn); + } return $dn; } @@ -1135,7 +1342,9 @@ class ldap extends DS { */ private function unescapeDN($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $unescape = function ($input) { return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function ($match) { @@ -1147,7 +1356,9 @@ class ldap extends DS { $a = array(); foreach ($dn as $key => $rdn) + { $a[$key] = $unescape($rdn); + } // $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn); return $a; @@ -1160,7 +1371,9 @@ class ldap extends DS { public function getRootDSE($method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $query = array(); $query['base'] = ''; @@ -1170,9 +1383,13 @@ class ldap extends DS { $results = $this->query($query,$method); if (is_array($results) && count($results) == 1) + { return array_change_key_case(array_pop($results)); + } else + { return array(); + } } /** Schema Methods **/ @@ -1188,45 +1405,63 @@ class ldap extends DS { */ private function getSchemaDN($method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If we already got the SchemaDN, then return it. if ($this->_schemaDN) + { return $this->_schemaDN; + } if (! $this->connect($method)) - return false; + { + return FALSE; + } $search = @ldap_read($this->connect($method),$dn,'objectclass=*',array('subschemaSubentry'),false,0,10,LDAP_DEREF_NEVER); if (DEBUG_ENABLED) - debug_log('Search returned (%s)',24,0,__FILE__,__LINE__,__METHOD__,is_resource($search)); + { + debug_log('Search returned (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, is_resource($search)); + } # Fix for broken ldap.conf configuration. if (! $search && ! $dn) { if (DEBUG_ENABLED) - debug_log('Trying to find the DN for "broken" ldap.conf',80,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Trying to find the DN for "broken" ldap.conf', 80, 0, __FILE__, __LINE__, __METHOD__); + } if (isset($this->_baseDN)) { foreach ($this->_baseDN as $base) { $search = @ldap_read($this->connect($method),$base,'objectclass=*',array('subschemaSubentry'),false,0,10,LDAP_DEREF_NEVER); if (DEBUG_ENABLED) - debug_log('Search returned (%s) for base (%s)',24,0,__FILE__,__LINE__,__METHOD__, - is_resource($search),$base); + { + debug_log('Search returned (%s) for base (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, + is_resource($search), $base); + } if ($search) + { break; + } } } } if (! $search) - return null; + { + return NULL; + } if (! @ldap_count_entries($this->connect($method),$search)) { if (DEBUG_ENABLED) - debug_log('Search returned 0 entries. Returning NULL',25,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Search returned 0 entries. Returning NULL', 25, 0, __FILE__, __LINE__, __METHOD__); + } return null; } @@ -1234,15 +1469,21 @@ class ldap extends DS { $entries = @ldap_get_entries($this->connect($method),$search); if (DEBUG_ENABLED) - debug_log('Search returned [%s]',24,0,__FILE__,__LINE__,__METHOD__,$entries); + { + debug_log('Search returned [%s]', 24, 0, __FILE__, __LINE__, __METHOD__, $entries); + } if (! $entries || ! is_array($entries)) - return null; + { + return NULL; + } $entry = isset($entries[0]) ? $entries[0] : false; if (! $entry) { if (DEBUG_ENABLED) - debug_log('Entry is false, Returning NULL',80,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Entry is false, Returning NULL', 80, 0, __FILE__, __LINE__, __METHOD__); + } return null; } @@ -1250,7 +1491,9 @@ class ldap extends DS { $sub_schema_sub_entry = isset($entry[0]) ? $entry[0] : false; if (! $sub_schema_sub_entry) { if (DEBUG_ENABLED) - debug_log('Sub Entry is false, Returning NULL',80,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Sub Entry is false, Returning NULL', 80, 0, __FILE__, __LINE__, __METHOD__); + } return null; } @@ -1258,7 +1501,9 @@ class ldap extends DS { $this->_schemaDN = isset($entry[$sub_schema_sub_entry][0]) ? $entry[$sub_schema_sub_entry][0] : false; if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$this->_schemaDN); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $this->_schemaDN); + } return $this->_schemaDN; } @@ -1283,12 +1528,16 @@ class ldap extends DS { */ private function getRawSchema($method,$schema_to_fetch,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $valid_schema_to_fetch = array('objectclasses','attributetypes','ldapsyntaxes','matchingrules','matchingruleuse'); if (! $this->connect($method) || $this->noconnect) - return false; + { + return FALSE; + } # error checking $schema_to_fetch = strtolower($schema_to_fetch); @@ -1297,54 +1546,72 @@ class ldap extends DS { $schema = $this->_schema_entries[$schema_to_fetch]; if (DEBUG_ENABLED) - debug_log('Returning CACHED (%s)',25,0,__FILE__,__LINE__,__METHOD__,$schema); + { + debug_log('Returning CACHED (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $schema); + } return $schema; } # This error message is not localized as only developers should ever see it if (! in_array($schema_to_fetch,$valid_schema_to_fetch)) + { error(sprintf('Bad parameter provided to function to %s::getRawSchema(). "%s" is not valid for the schema_to_fetch parameter.', - get_class($this),$schema_to_fetch),'error','index.php'); + get_class($this), $schema_to_fetch), 'error', 'index.php'); + } # Try to get the schema DN from the specified entry. $schema_dn = $this->getSchemaDN($method,$dn); # Do we need to try again with the Root DSE? if (! $schema_dn && trim($dn)) - $schema_dn = $this->getSchemaDN($method,''); + { + $schema_dn = $this->getSchemaDN($method, ''); + } # Store the eventual schema retrieval in $schema_search $schema_search = null; if ($schema_dn) { if (DEBUG_ENABLED) - debug_log('Using Schema DN (%s)',24,0,__FILE__,__LINE__,__METHOD__,$schema_dn); + { + debug_log('Using Schema DN (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_dn); + } foreach (array('(objectClass=*)','(objectClass=subschema)') as $schema_filter) { if (DEBUG_ENABLED) - debug_log('Looking for schema with Filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,$schema_filter); + { + debug_log('Looking for schema with Filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_filter); + } $schema_search = @ldap_read($this->connect($method),$schema_dn,$schema_filter,array($schema_to_fetch),false,0,10,LDAP_DEREF_NEVER); if (is_null($schema_search)) + { continue; + } $schema_entries = @ldap_get_entries($this->connect($method),$schema_search); if (DEBUG_ENABLED) - debug_log('Search returned [%s]',24,0,__FILE__,__LINE__,__METHOD__,$schema_entries); + { + debug_log('Search returned [%s]', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_entries); + } if (is_array($schema_entries) && isset($schema_entries['count']) && $schema_entries['count']) { if (DEBUG_ENABLED) - debug_log('Found schema with (DN:%s) (FILTER:%s) (ATTR:%s)',24,0,__FILE__,__LINE__,__METHOD__, - $schema_dn,$schema_filter,$schema_to_fetch); + { + debug_log('Found schema with (DN:%s) (FILTER:%s) (ATTR:%s)', 24, 0, __FILE__, __LINE__, __METHOD__, + $schema_dn, $schema_filter, $schema_to_fetch); + } break; } if (DEBUG_ENABLED) - debug_log('Didnt find schema with filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,$schema_filter); + { + debug_log('Didnt find schema with filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_filter); + } unset($schema_entries); $schema_search = null; @@ -1355,7 +1622,9 @@ class ldap extends DS { * is still null, use some common subSchemaSubentry DNs as a work-around. */ if (is_null($schema_search)) { if (DEBUG_ENABLED) - debug_log('Attempting work-arounds for "broken" LDAP servers...',24,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Attempting work-arounds for "broken" LDAP servers...', 24, 0, __FILE__, __LINE__, __METHOD__); + } foreach ($this->getBaseDN() as $base) { $ldap['W2K3 AD'][expand_dn_with_base($base,'cn=Aggregate,cn=Schema,cn=configuration,')] = '(objectClass=*)'; @@ -1369,33 +1638,45 @@ class ldap extends DS { foreach ($ldap as $ldap_server_name => $ldap_options) { foreach ($ldap_options as $ldap_dn => $ldap_filter) { if (DEBUG_ENABLED) - debug_log('Attempting [%s] (%s) (%s)
    ',24,0,__FILE__,__LINE__,__METHOD__, - $ldap_server_name,$ldap_dn,$ldap_filter); + { + debug_log('Attempting [%s] (%s) (%s)
    ', 24, 0, __FILE__, __LINE__, __METHOD__, + $ldap_server_name, $ldap_dn, $ldap_filter); + } $schema_search = @ldap_read($this->connect($method),$ldap_dn,$ldap_filter,array($schema_to_fetch),false,0,10,LDAP_DEREF_NEVER); if (is_null($schema_search)) + { continue; + } $schema_entries = @ldap_get_entries($this->connect($method),$schema_search); if (DEBUG_ENABLED) - debug_log('Search returned [%s]',24,0,__FILE__,__LINE__,__METHOD__,$schema_entries); + { + debug_log('Search returned [%s]', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_entries); + } if ($schema_entries && isset($schema_entries[0][$schema_to_fetch])) { if (DEBUG_ENABLED) - debug_log('Found schema with filter of (%s)',24,0,__FILE__,__LINE__,__METHOD__,$ldap_filter); + { + debug_log('Found schema with filter of (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $ldap_filter); + } break; } if (DEBUG_ENABLED) - debug_log('Didnt find schema with filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,$ldap_filter); + { + debug_log('Didnt find schema with filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $ldap_filter); + } unset($schema_entries); $schema_search = null; } if ($schema_search) + { break; + } } } @@ -1404,7 +1685,9 @@ class ldap extends DS { $olc_schema_found = false; if (is_null($schema_search)) { if (DEBUG_ENABLED) - debug_log('Attempting cn=config work-around...',24,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Attempting cn=config work-around...', 24, 0, __FILE__, __LINE__, __METHOD__); + } $ldap_dn = 'cn=schema,cn=config'; $ldap_filter = '(objectClass=*)'; @@ -1415,17 +1698,23 @@ class ldap extends DS { $schema_entries = @ldap_get_entries($this->connect($method),$schema_search); if (DEBUG_ENABLED) - debug_log('Search returned [%s]',24,0,__FILE__,__LINE__,__METHOD__,$schema_entries); + { + debug_log('Search returned [%s]', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_entries); + } if ($schema_entries) { if (DEBUG_ENABLED) - debug_log('Found schema with filter of (%s) and attribute filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,$ldap_filter,$olc_schema); + { + debug_log('Found schema with filter of (%s) and attribute filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $ldap_filter, $olc_schema); + } $olc_schema_found = true; } else { if (DEBUG_ENABLED) - debug_log('Didnt find schema with filter (%s) and attribute filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,$ldap_filter,$olc_schema); + { + debug_log('Didnt find schema with filter (%s) and attribute filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, $ldap_filter, $olc_schema); + } unset($schema_entries); $schema_search = null; @@ -1439,8 +1728,10 @@ class ldap extends DS { * Attempt to pull schema from Root DSE with scope "one" (work-around for Isode M-Vault X.500/LDAP) */ foreach (array('base','one') as $ldap_scope) { if (DEBUG_ENABLED) - debug_log('Attempting to find schema with scope (%s), filter (objectClass=*) and a blank base.',24,0,__FILE__,__LINE__,__METHOD__, + { + debug_log('Attempting to find schema with scope (%s), filter (objectClass=*) and a blank base.', 24, 0, __FILE__, __LINE__, __METHOD__, $ldap_scope); + } switch ($ldap_scope) { case 'base': @@ -1453,21 +1744,29 @@ class ldap extends DS { } if (is_null($schema_search)) + { continue; + } $schema_entries = @ldap_get_entries($this->connect($method),$schema_search); if (DEBUG_ENABLED) - debug_log('Search returned [%s]',24,0,__FILE__,__LINE__,__METHOD__,$schema_entries); + { + debug_log('Search returned [%s]', 24, 0, __FILE__, __LINE__, __METHOD__, $schema_entries); + } if ($schema_entries && isset($schema_entries[0][$schema_to_fetch])) { if (DEBUG_ENABLED) - debug_log('Found schema with filter of (%s)',24,0,__FILE__,__LINE__,__METHOD__,'(objectClass=*)'); + { + debug_log('Found schema with filter of (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, '(objectClass=*)'); + } break; } if (DEBUG_ENABLED) - debug_log('Didnt find schema with filter (%s)',24,0,__FILE__,__LINE__,__METHOD__,'(objectClass=*)'); + { + debug_log('Didnt find schema with filter (%s)', 24, 0, __FILE__, __LINE__, __METHOD__, '(objectClass=*)'); + } unset($schema_entries); $schema_search = null; @@ -1481,13 +1780,17 @@ class ldap extends DS { if (is_null($schema_search)) { # We need to have objectclasses and attribues, so display an error, asking the user to get us this information. if (in_array($schema_to_fetch,$schema_error_message_array)) + { system_message(array( - 'title'=>sprintf('%s (%s)',_('Our attempts to find your SCHEMA have failed'),$schema_to_fetch), - 'body'=>sprintf('%s: %s',_('Error'),$schema_error_message), - 'type'=>'error')); + 'title' => sprintf('%s (%s)', _('Our attempts to find your SCHEMA have failed'), $schema_to_fetch), + 'body' => sprintf('%s: %s', _('Error'), $schema_error_message), + 'type' => 'error')); + } else if (DEBUG_ENABLED) - debug_log('Returning because schema_search is NULL ()',25,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Returning because schema_search is NULL ()', 25, 0, __FILE__, __LINE__, __METHOD__); + } # We'll set this, so if we return here our cache will return the known false. $this->_schema_entries[$schema_to_fetch] = false; @@ -1497,7 +1800,9 @@ class ldap extends DS { if (! $schema_entries) { $return = false; if (DEBUG_ENABLED) - debug_log('Returning false since ldap_get_entries() returned false.',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning false since ldap_get_entries() returned false.', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1512,7 +1817,9 @@ class ldap extends DS { foreach ($entry[$olc_schema] as $schema_definition) /* Schema definitions in child nodes prefix the schema entries with "{n}" the preg_replace call strips out this prefix. */ - $schema[] = preg_replace('/^\{\d*\}\(/','(',$schema_definition); + { + $schema[] = preg_replace('/^\{\d*\}\(/', '(', $schema_definition); + } } } @@ -1520,12 +1827,16 @@ class ldap extends DS { $this->_schema_entries[$olc_schema] = $schema; if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$schema); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $schema); + } return $schema; } else - return null; + { + return NULL; + } } if (! isset($schema_entries[0][$schema_to_fetch])) { @@ -1537,7 +1848,9 @@ class ldap extends DS { $return = false; if (DEBUG_ENABLED) - debug_log('Returning because (%s) isnt in the schema array. (%s)',25,0,__FILE__,__LINE__,__METHOD__,$schema_to_fetch,$return); + { + debug_log('Returning because (%s) isnt in the schema array. (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $schema_to_fetch, $return); + } return $return; } @@ -1554,7 +1867,9 @@ class ldap extends DS { $this->_schema_entries[$schema_to_fetch] = $schema; if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$schema); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $schema); + } return $schema; } @@ -1574,7 +1889,9 @@ class ldap extends DS { */ public function getSchemaObjectClass($oclass_name,$method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $oclass_name = strtolower($oclass_name); $socs = $this->SchemaObjectClasses($method,$dn); @@ -1583,10 +1900,14 @@ class ldap extends DS { $return = false; if (isset($socs[$oclass_name])) + { $return = $socs[$oclass_name]; + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1606,7 +1927,9 @@ class ldap extends DS { */ public function getSchemaAttribute($attr_name,$method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attr_name = strtolower($attr_name); $sattrs = $this->SchemaAttributes($method,$dn); @@ -1615,10 +1938,14 @@ class ldap extends DS { $return = false; if (isset($sattrs[$attr_name])) + { $return = $sattrs[$attr_name]; + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1639,14 +1966,18 @@ class ldap extends DS { */ public function SchemaObjectClasses($method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = null; if ($return = get_cached_item($this->index,'schema','objectclasses')) { if (DEBUG_ENABLED) - debug_log('Returning CACHED [%s] (%s)',25,0,__FILE__,__LINE__,__METHOD__,$this->index,'objectclasses'); + { + debug_log('Returning CACHED [%s] (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'objectclasses'); + } return $return; } @@ -1659,7 +1990,9 @@ class ldap extends DS { foreach ($raw as $line) { if (is_null($line) || ! strlen($line)) + { continue; + } $object_class = new ObjectClass($line,$this); $return[$object_class->getName()] = $object_class; @@ -1667,9 +2000,15 @@ class ldap extends DS { # Now go through and reference the parent/child relationships foreach ($return as $oclass) + { foreach ($oclass->getSupClasses() as $parent_name) + { if (isset($return[strtolower($parent_name)])) - $return[strtolower($parent_name)]->addChildObjectClass($oclass->getName(false)); + { + $return[strtolower($parent_name)]->addChildObjectClass($oclass->getName(FALSE)); + } + } + } ksort($return); @@ -1678,7 +2017,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1696,14 +2037,18 @@ class ldap extends DS { */ public function SchemaAttributes($method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = null; if ($return = get_cached_item($this->index,'schema','attributes')) { if (DEBUG_ENABLED) - debug_log('(): Returning CACHED [%s] (%s)',25,0,__FILE__,__LINE__,__METHOD__,$this->index,'attributes'); + { + debug_log('(): Returning CACHED [%s] (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'attributes'); + } return $return; } @@ -1724,7 +2069,9 @@ class ldap extends DS { $attrs_oid = array(); foreach ($raw as $line) { if (is_null($line) || ! strlen($line)) + { continue; + } $attr = new AttributeType($line); if (isset($syntaxes[$attr->getSyntaxOID()])) { @@ -1814,7 +2161,9 @@ class ldap extends DS { /* only overwrite the SINGLE-VALUE property if the child explicitly sets it * (note: All LDAP attributes default to multi-value if not explicitly set SINGLE-VALUE) */ if ($tmp_single_val) - $attr->setIsSingleValue(true); + { + $attr->setIsSingleValue(TRUE); + } /* replace this attribute in the attrs array now that we have populated new values therein */ @@ -1834,7 +2183,9 @@ class ldap extends DS { # Add the used in and required_by values. $socs = $this->SchemaObjectClasses($method); if (! is_array($socs)) + { return array(); + } foreach ($socs as $object_class) { $must_attrs = $object_class->getMustAttrNames(); @@ -1843,18 +2194,30 @@ class ldap extends DS { # Add Used In. foreach ($oclass_attrs as $attr_name) + { if (isset($attrs[strtolower($attr_name)])) - $attrs[strtolower($attr_name)]->addUsedInObjectClass($object_class->getName(false)); + { + $attrs[strtolower($attr_name)]->addUsedInObjectClass($object_class->getName(FALSE)); + } + } # Add Required By. foreach ($must_attrs as $attr_name) + { if (isset($attrs[strtolower($attr_name)])) - $attrs[strtolower($attr_name)]->addRequiredByObjectClass($object_class->getName(false)); + { + $attrs[strtolower($attr_name)]->addRequiredByObjectClass($object_class->getName(FALSE)); + } + } # Force May foreach ($object_class->getForceMayAttrs() as $attr_name) + { if (isset($attrs[strtolower($attr_name->name)])) + { $attrs[strtolower($attr_name->name)]->setForceMay(); + } + } } $return = $attrs; @@ -1864,7 +2227,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1878,14 +2243,18 @@ class ldap extends DS { */ public function MatchingRules($method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = null; if ($return = get_cached_item($this->index,'schema','matchingrules')) { if (DEBUG_ENABLED) - debug_log('Returning CACHED [%s] (%s).',25,0,__FILE__,__LINE__,__METHOD__,$this->index,'matchingrules'); + { + debug_log('Returning CACHED [%s] (%s).', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'matchingrules'); + } return $return; } @@ -1898,7 +2267,9 @@ class ldap extends DS { foreach ($raw as $line) { if (is_null($line) || ! strlen($line)) + { continue; + } $rule = new MatchingRule($line); $key = $rule->getName(); @@ -1914,13 +2285,17 @@ class ldap extends DS { if ($raw != false) { foreach ($raw as $line) { if (is_null($line) || ! strlen($line)) + { continue; + } $rule_use = new MatchingRuleUse($line); $key = $rule_use->getName(); if (isset($rules[$key])) + { $rules[$key]->setUsedByAttrs($rule_use->getUsedByAttrs()); + } } } else { @@ -1928,12 +2303,17 @@ class ldap extends DS { * the reverse-map for the "$rule->getUsedByAttrs()" data.*/ $sattrs = $this->SchemaAttributes($method,$dn); if (is_array($sattrs)) - foreach ($sattrs as $attr) { + { + foreach ($sattrs as $attr) + { $rule_key = strtolower($attr->getEquality()); if (isset($rules[$rule_key])) - $rules[$rule_key]->addUsedByAttr($attr->getName(false)); + { + $rules[$rule_key]->addUsedByAttr($attr->getName(FALSE)); + } } + } } $return = $rules; @@ -1943,7 +2323,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1957,14 +2339,18 @@ class ldap extends DS { */ public function SchemaSyntaxes($method=null,$dn='') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',25,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 25, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = null; if ($return = get_cached_item($this->index,'schema','syntaxes')) { if (DEBUG_ENABLED) - debug_log('Returning CACHED [%s] (%s).',25,0,__FILE__,__LINE__,__METHOD__,$this->index,'syntaxes'); + { + debug_log('Returning CACHED [%s] (%s).', 25, 0, __FILE__, __LINE__, __METHOD__, $this->index, 'syntaxes'); + } return $return; } @@ -1977,13 +2363,17 @@ class ldap extends DS { foreach ($raw as $line) { if (is_null($line) || ! strlen($line)) + { continue; + } $syntax = new Syntax($line); $key = strtolower(trim($syntax->getOID())); if (! $key) + { continue; + } $return[$key] = $syntax; } @@ -1995,7 +2385,9 @@ class ldap extends DS { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',25,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 25, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -2009,7 +2401,9 @@ class ldap extends DS { */ public function isForceMay($attr_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return in_array($attr_name,unserialize(strtolower(serialize($this->getValue('server','force_may'))))); } @@ -2041,7 +2435,9 @@ class ldap extends DS { */ public function getDNAttrValue($dn,$attr,$method=null,$deref=LDAP_DEREF_NEVER) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Ensure our attr is in lowercase $attr = strtolower($attr); @@ -2049,9 +2445,13 @@ class ldap extends DS { $values = $this->getDNAttrValues($dn,$method,$deref); if (isset($values[$attr])) + { return $values[$attr]; + } else + { return array(); + } } /** @@ -2094,7 +2494,9 @@ class ldap extends DS { */ public function getDNAttrValues($dn,$method=null,$deref=LDAP_DEREF_NEVER,$attrs=array('*','+'),$nocache=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE; @@ -2102,17 +2504,25 @@ class ldap extends DS { $method = $this->getMethod($method); if (in_array('*',$attrs) && in_array('+',$attrs)) + { $cacheindex = '&'; + } elseif (in_array('+',$attrs)) + { $cacheindex = '+'; + } elseif (in_array('*',$attrs)) + { $cacheindex = '*'; + } if (! $nocache && ! is_null($cacheindex) && isset($CACHE[$this->index][$method][$dn][$cacheindex])) { $results = $CACHE[$this->index][$method][$dn][$cacheindex]; if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$results); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $results); + } } else { $query = array(); @@ -2124,20 +2534,28 @@ class ldap extends DS { $results = $this->query($query,$method); if (count($results)) + { $results = array_pop($results); + } $results = array_change_key_case($results); # Covert all our result key values to an array foreach ($results as $key => $values) - if (! is_array($results[$key])) + { + if ( ! is_array($results[$key])) + { $results[$key] = array($results[$key]); + } + } # Finally sort the results ksort($results); if (! is_null($cacheindex) && count($results)) + { $CACHE[$this->index][$method][$dn][$cacheindex] = $results; + } } return $results; @@ -2153,32 +2571,48 @@ class ldap extends DS { */ public function isDNAttr($attr_name, $method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Simple test first $dn_attrs = array('aliasedObjectName'); foreach ($dn_attrs as $dn_attr) - if (strcasecmp($attr_name,$dn_attr) == 0) - return true; + { + if (strcasecmp($attr_name, $dn_attr) == 0) + { + return TRUE; + } + } # Now look at the schema OID $sattr = $this->getSchemaAttribute($attr_name); if (! $sattr) - return false; + { + return FALSE; + } $syntax_oid = $sattr->getSyntaxOID(); if ('1.3.6.1.4.1.1466.115.121.1.12' == $syntax_oid) - return true; + { + return TRUE; + } if ('1.3.6.1.4.1.1466.115.121.1.34' == $syntax_oid) - return true; + { + return TRUE; + } $syntaxes = $this->SchemaSyntaxes($method); if (! isset($syntaxes[$syntax_oid])) - return false; + { + return FALSE; + } $syntax_desc = $syntaxes[ $syntax_oid ]->getDescription(); if (strpos(strtolower($syntax_desc),'distinguished name')) - return true; + { + return TRUE; + } return false; } @@ -2194,22 +2628,30 @@ class ldap extends DS { */ public function isJpegPhoto($attr_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # easy quick check if (! strcasecmp($attr_name,'jpegPhoto') || ! strcasecmp($attr_name,'photo')) - return true; + { + return TRUE; + } # go to the schema and get the Syntax OID $sattr = $this->getSchemaAttribute($attr_name); if (! $sattr) - return false; + { + return FALSE; + } $oid = $sattr->getSyntaxOID(); $type = $sattr->getType(); if (! strcasecmp($type,'JPEG') || ($oid == '1.3.6.1.4.1.1466.115.121.1.28')) - return true; + { + return TRUE; + } return false; } @@ -2225,17 +2667,23 @@ class ldap extends DS { */ public function isAttrBoolean($attr_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $type = ($sattr = $this->getSchemaAttribute($attr_name)) ? $sattr->getType() : null; if (! strcasecmp('boolean',$type) || ! strcasecmp('isCriticalSystemObject',$attr_name) || ! strcasecmp('showInAdvancedViewOnly',$attr_name)) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -2251,7 +2699,9 @@ class ldap extends DS { */ public function isAttrBinary($attr_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } /** * Determining if an attribute is binary can be an expensive operation. @@ -2273,7 +2723,9 @@ class ldap extends DS { $attr_name = strtolower($attr_name); if (isset($attr_cache[$this->index][$attr_name])) + { return $attr_cache[$this->index][$attr_name]; + } if ($attr_name == 'userpassword') { $attr_cache[$this->index][$attr_name] = false; @@ -2337,28 +2789,38 @@ class ldap extends DS { */ public function userIsMember($user, $group) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $user = strtolower($user); $group = $this->getDNAttrValues($group); # If you are using groupOfNames objectClass if (array_key_exists('member',$group) && ! is_array($group['member'])) + { $group['member'] = array($group['member']); + } if (array_key_exists('member',$group) && in_array($user,arrayLower($group['member']))) - return true; + { + return TRUE; + } # If you are using groupOfUniqueNames objectClass if (array_key_exists('uniquemember',$group) && ! is_array($group['uniquemember'])) + { $group['uniquemember'] = array($group['uniquemember']); + } if (array_key_exists('uniquemember',$group) && in_array($user,arrayLower($group['uniquemember']))) - return true; + { + return TRUE; + } return false; } @@ -2370,16 +2832,22 @@ class ldap extends DS { */ protected function userIsAllowedLogin($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $dn = trim(strtolower($dn)); if (! $this->getValue('login','allowed_dns')) - return true; + { + return TRUE; + } foreach ($this->getValue('login','allowed_dns') as $login_allowed_dn) { if (DEBUG_ENABLED) - debug_log('Working through (%s)',80,0,__FILE__,__LINE__,__METHOD__,$login_allowed_dn); + { + debug_log('Working through (%s)', 80, 0, __FILE__, __LINE__, __METHOD__, $login_allowed_dn); + } /* Check if $login_allowed_dn is an ldap search filter * Is first occurence of 'filter=' (case ensitive) at position 0 ? */ @@ -2394,41 +2862,58 @@ class ldap extends DS { $results = $this->query($query,null); if (DEBUG_ENABLED) - debug_log('Search, Filter [%s], BaseDN [%s] Results [%s]',16,0,__FILE__,__LINE__,__METHOD__, - $query['filter'],$query['base'],$results); + { + debug_log('Search, Filter [%s], BaseDN [%s] Results [%s]', 16, 0, __FILE__, __LINE__, __METHOD__, + $query['filter'], $query['base'], $results); + } if ($results) { $dn_array = array(); foreach ($results as $result) - array_push($dn_array,$result['dn']); + { + array_push($dn_array, $result['dn']); + } $dn_array = array_unique($dn_array); if (count($dn_array)) - foreach ($dn_array as $result_dn) { - if (DEBUG_ENABLED) - debug_log('Comparing with [%s]',80,0,__FILE__,__LINE__,__METHOD__,$result_dn); + { + foreach ($dn_array as $result_dn) + { + if (DEBUG_ENABLED) + { + debug_log('Comparing with [%s]', 80, 0, __FILE__, __LINE__, __METHOD__, $result_dn); + } - # Check if $result_dn is a user DN - if (strcasecmp($dn,trim(strtolower($result_dn))) == 0) - return true; + # Check if $result_dn is a user DN + if (strcasecmp($dn, trim(strtolower($result_dn))) == 0) + { + return TRUE; + } - # Check if $result_dn is a group DN - if ($this->userIsMember($dn,$result_dn)) - return true; - } + # Check if $result_dn is a group DN + if ($this->userIsMember($dn, $result_dn)) + { + return TRUE; + } + } + } } } } # Check if $login_allowed_dn is a user DN if (strcasecmp($dn,trim(strtolower($login_allowed_dn))) == 0) - return true; + { + return TRUE; + } # Check if $login_allowed_dn is a group DN if ($this->userIsMember($dn,$login_allowed_dn)) - return true; + { + return TRUE; + } } return false; diff --git a/lib/ds_ldap_pla.php b/lib/ds_ldap_pla.php index 41e68b1..9b621b3 100644 --- a/lib/ds_ldap_pla.php +++ b/lib/ds_ldap_pla.php @@ -163,12 +163,18 @@ class ldap_pla extends ldap { */ public function isShowCreateEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! $_SESSION[APPCONFIG]->isCommandAvailable('script','create')) - return false; + { + return FALSE; + } else - return $this->getValue('appearance','show_create'); + { + return $this->getValue('appearance', 'show_create'); + } } /** @@ -182,16 +188,24 @@ class ldap_pla extends ldap { */ public function isAnonBindAllowed() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If only_login_allowed_dns is set, then we cant have anonymous. if (count($this->getValue('login','allowed_dns')) > 0) - $return = false; + { + $return = FALSE; + } else - $return = $this->getValue('login','anon_bind'); + { + $return = $this->getValue('login', 'anon_bind'); + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -208,7 +222,9 @@ class ldap_pla extends ldap { */ public function isBranchRenameEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->getValue('server','branch_rename'); } @@ -232,22 +248,31 @@ class ldap_pla extends ldap { */ public function isMultiLineAttr($attr_name, $val=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = false; # First, check the optional val param for a \n or a \r if (! is_null($val) && (strpos($val,"\n") || strpos($val,"\r"))) - $return = true; + { + $return = TRUE; + } # Next, compare strictly by name first else - foreach ($_SESSION[APPCONFIG]->getValue('appearance','multi_line_attributes') as $multi_line_attr_name) - if (strcasecmp($multi_line_attr_name,$attr_name) == 0) { - $return = true; + { + foreach ($_SESSION[APPCONFIG]->getValue('appearance', 'multi_line_attributes') as $multi_line_attr_name) + { + if (strcasecmp($multi_line_attr_name, $attr_name) == 0) + { + $return = TRUE; break; } + } + } # If unfound, compare by syntax OID if (! $return) { @@ -257,16 +282,23 @@ class ldap_pla extends ldap { $syntax_oid = $sattr->getSyntaxOID(); if ($syntax_oid) - foreach ($_SESSION[APPCONFIG]->getValue('appearance','multi_line_syntax_oids') as $multi_line_syntax_oid) - if ($multi_line_syntax_oid == $syntax_oid) { - $return = true; + { + foreach ($_SESSION[APPCONFIG]->getValue('appearance', 'multi_line_syntax_oids') as $multi_line_syntax_oid) + { + if ($multi_line_syntax_oid == $syntax_oid) + { + $return = TRUE; break; } + } + } } } if (DEBUG_ENABLED) - debug_log('Returning (%s)',17,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 17, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -283,15 +315,23 @@ class ldap_pla extends ldap { private function isAttrTest($attr,$attrs,$except_dn) { $attr = trim($attr); if (! trim($attr) || ! count($attrs)) - return false; + { + return FALSE; + } # Is the user excluded? if ($except_dn && $this->userIsMember($this->getLogin(),$except_dn)) - return false; + { + return FALSE; + } foreach ($attrs as $attr_name) - if (strcasecmp($attr,trim($attr_name)) == 0) - return true; + { + if (strcasecmp($attr, trim($attr_name)) == 0) + { + return TRUE; + } + } return false; } @@ -309,7 +349,9 @@ class ldap_pla extends ldap { */ public function isAttrReadOnly($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attrs = $_SESSION[APPCONFIG]->getValue('appearance','readonly_attrs'); $except_dn = $_SESSION[APPCONFIG]->getValue('appearance','readonly_attrs_exempt'); @@ -330,7 +372,9 @@ class ldap_pla extends ldap { */ public function isAttrHidden($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attrs = $_SESSION[APPCONFIG]->getValue('appearance','hide_attrs'); $except_dn = $_SESSION[APPCONFIG]->getValue('appearance','hide_attrs_exempt'); @@ -347,16 +391,22 @@ class ldap_pla extends ldap { */ public function add($dn,$entry_array,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($entry_array as $attr => $val) + { $entry_array[$attr] = dn_unescape($val); + } $result = false; # Check our unique attributes. if (! $this->checkUniqueAttrs($dn,$entry_array)) - return false; + { + return FALSE; + } if (run_hook('pre_entry_create',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$entry_array))) { $result = @ldap_add($this->connect($method),dn_escape($dn),$entry_array); @@ -367,7 +417,9 @@ class ldap_pla extends ldap { # If we created the base, delete it, then add it back if (get_request('create_base')) + { $tree->delEntry($dn); + } $tree->addEntry($dn); @@ -394,7 +446,9 @@ class ldap_pla extends ldap { */ public function delete($dn,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = false; @@ -426,7 +480,9 @@ class ldap_pla extends ldap { */ public function rename($dn,$new_rdn,$container,$deleteoldrdn,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = false; @@ -457,11 +513,15 @@ class ldap_pla extends ldap { */ public function modify($dn,$attrs,$method=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Check our unique attributes. if (! $this->checkUniqueAttrs($dn,$attrs)) - return false; + { + return FALSE; + } $result = false; $summary = array(); @@ -481,7 +541,9 @@ class ldap_pla extends ldap { 'type'=>'warn')); } else + { $summary['add'][$attr]['new'] = $values; + } # For modify attributes } elseif (count($values)) { @@ -511,12 +573,16 @@ class ldap_pla extends ldap { 'type'=>'warn')); } else + { $summary['delete'][$attr]['old'] = $current_attrs[$attr]; + } } } if (! count($attrs)) - return false; + { + return FALSE; + } if (run_hook('pre_entry_modify',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$attrs))) { $result = @ldap_modify($this->connect($method),$dn,$attrs); @@ -525,27 +591,34 @@ class ldap_pla extends ldap { run_hook('post_entry_modify',array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attrs'=>$attrs)); foreach (array('add','modify','delete') as $mode) + { if (isset($summary[$mode])) + { foreach ($summary[$mode] as $attr => $values) - switch ($mode) { + { + switch ($mode) + { case 'add': - run_hook(sprintf('post_attr_%s',$mode), - array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'newvalue'=>$values['new'])); + run_hook(sprintf('post_attr_%s', $mode), + array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'newvalue' => $values['new'])); break; case 'modify': - run_hook(sprintf('post_attr_%s',$mode), - array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$values['old'],'newvalue'=>$values['new'])); + run_hook(sprintf('post_attr_%s', $mode), + array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $values['old'], 'newvalue' => $values['new'])); break; case 'delete': - run_hook(sprintf('post_attr_%s',$mode), - array('server_id'=>$this->index,'method'=>$method,'dn'=>$dn,'attr'=>$attr,'oldvalue'=>$values['old'])); + run_hook(sprintf('post_attr_%s', $mode), + array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $values['old'])); break; default: - debug_dump_backtrace(sprintf('Unkown mode %s',$mode),1); + debug_dump_backtrace(sprintf('Unkown mode %s', $mode), 1); } + } + } + } } else { system_message(array( 'title'=>_('Could not perform ldap_modify operation.'), @@ -570,13 +643,19 @@ class ldap_pla extends ldap { */ public function isAttrUnique($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Should this attribute value be unique if (in_array_ignore_case($attr,$this->getValue('unique','attrs'))) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -591,11 +670,15 @@ class ldap_pla extends ldap { */ public function checkUniqueAttrs($dn,$attrs) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If none of the attributes are defined unique, we'll return immediately; if (! $checkattrs = array_intersect(arrayLower($this->getValue('unique','attrs')),array_keys(array_change_key_case($attrs)))) - return true; + { + return TRUE; + } # Check see and use our alternate uid_dn and password if we have it. if (! $this->login($this->getValue('unique','dn'),$this->getValue('unique','pass'),'unique')) { @@ -613,9 +696,15 @@ class ldap_pla extends ldap { # Build our search filter to double check each attribute. $query['filter'] = '(|'; foreach ($checkattrs as $attr) + { foreach ($attrs[$attr] as $val) + { if ($val) - $query['filter'] .= sprintf('(%s=%s)',$attr,$val); + { + $query['filter'] .= sprintf('(%s=%s)', $attr, $val); + } + } + } $query['filter'] .= ')'; $query['attrs'] = $checkattrs; @@ -629,21 +718,26 @@ class ldap_pla extends ldap { # If we have a match. if (count($results)) + { foreach ($results as $values) # If one of the attributes is owned to somebody else, then we may as well die here. - if ($values['dn'] != $dn) { - $href = sprintf('cmd.php?cmd=query_engine&server_id=%s&filter=%s&scope=sub&query=none&format=list&search=true',$this->index,$query['filter']); + { + if ($values['dn'] != $dn) + { + $href = sprintf('cmd.php?cmd=query_engine&server_id=%s&filter=%s&scope=sub&query=none&format=list&search=true', $this->index, $query['filter']); system_message(array( - 'title'=>_('Attribute value would not be unique'), - 'body'=>sprintf('%s (%s)', + 'title' => _('Attribute value would not be unique'), + 'body' => sprintf('%s (%s)', _('This update has been or will be cancelled, it would result in an attribute value not being unique. You might like to search the LDAP server for the offending entry.'), htmlspecialchars($href), _('Search')), 'type'=>'warn')); - return false; + return FALSE; } + } + } } # If we get here, then it must be OK? @@ -655,11 +749,15 @@ class ldap_pla extends ldap { */ public function isSessionValid() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',17,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If inactiveTime() returns a value, we need to check that it has not expired. if (is_null($this->inactivityTime()) || ! $this->isLoggedIn()) - return true; + { + return TRUE; + } # If session has expired if ((isset($_SESSION['ACTIVITY'][$this->getIndex()])) && ($_SESSION['ACTIVITY'][$this->getIndex()] < time())) { diff --git a/lib/export_functions.php b/lib/export_functions.php index 9eac6ad..0906e76 100644 --- a/lib/export_functions.php +++ b/lib/export_functions.php @@ -133,20 +133,30 @@ abstract class Export { $attrs = preg_replace('/\s+/','',$attrs); if ($attrs) - $query['attrs'] = explode(',',$attrs); + { + $query['attrs'] = explode(',', $attrs); + } else + { $query['attrs'] = array('*'); + } if (get_request('sys_attr')) { if (! in_array('*',$query['attrs'])) - array_push($query['attrs'],'*'); + { + array_push($query['attrs'], '*'); + } array_push($query['attrs'],'+'); } if (! $base) + { $bases = $server->getBaseDN(); + } else + { $bases = array($base); + } foreach ($bases as $base) { $query['base'] = $base; @@ -160,10 +170,12 @@ abstract class Export { # If no result, there is a something wrong if (! $this->results[$base] && $server->getErrorNum(null)) + { system_message(array( - 'title'=>_('Encountered an error while performing search.'), - 'body'=>ldap_error_msg($server->getErrorMessage(null),$server->getErrorNum(null)), - 'type'=>'error')); + 'title' => _('Encountered an error while performing search.'), + 'body' => ldap_error_msg($server->getErrorMessage(NULL), $server->getErrorNum(NULL)), + 'type' => 'error')); + } $this->items += count($this->results[$base]); } @@ -188,7 +200,9 @@ abstract class Export { } if (get_request('compress','REQUEST') == 'on') - $this->compress = true; + { + $this->compress = TRUE; + } } public function isCompressed() { @@ -223,8 +237,12 @@ abstract class Export { */ protected function isSafeAscii($str) { for ($i=0;$i 127) - return false; + { + return FALSE; + } + } return true; } @@ -242,7 +260,7 @@ class ExportCSV extends Export { private $multivalue_separator = ' | '; private $escapeCode = '"'; - static public function getType() { + public static function getType() { return array('type'=>'CSV','description' => 'CSV (Spreadsheet)','extension'=>'csv'); } @@ -259,8 +277,12 @@ class ExportCSV extends Export { unset($dndetails['dn']); foreach (array_keys($dndetails) as $key) - if (! in_array($key,$headers)) - array_push($headers,$key); + { + if ( ! in_array($key, $headers)) + { + array_push($headers, $key); + } + } } } @@ -273,7 +295,9 @@ class ExportCSV extends Export { $output .= sprintf('%s%s%s',$this->qualifier,$headers[$i],$this->qualifier); if ($i < $num_headers-1) + { $output .= $this->separator; + } } # Drop out our DN header. @@ -297,36 +321,52 @@ class ExportCSV extends Export { $binary_attribute = $server->isAttrBinary($attr) ? 1 : 0; if (! is_array($entry[$attr])) + { $attr_values = array($entry[$attr]); + } else + { $attr_values = $entry[$attr]; + } $num_attr_values = count($attr_values); for ($i=0; $i<$num_attr_values; $i++) { if ($binary_attribute) + { $output .= base64_encode($attr_values[$i]); + } else + { $output .= $this->LdapEscape($attr_values[$i]); + } if ($i < $num_attr_values-1) + { $output .= $this->multivalue_separator; + } } } $output .= $this->qualifier; if ($j < $num_headers-1) + { $output .= $this->separator; + } } $output .= $this->br; } if ($this->compress) + { return gzencode($output); + } else + { return $output; + } } /** @@ -347,7 +387,7 @@ class ExportCSV extends Export { * @subpackage Export */ class ExportDSML extends Export { - static public function getType() { + public static function getType() { return array('type'=>'DSML','description' => _('DSML V.1 Export'),'extension'=>'xml'); } @@ -394,12 +434,16 @@ class ExportDSML extends Export { # Display the objectClass attributes first if (isset($dndetails['objectClass'])) { if (! is_array($dndetails['objectClass'])) + { $dndetails['objectClass'] = array($dndetails['objectClass']); + } $output .= sprintf('%s%s',$indent['att'],$this->br); foreach ($dndetails['objectClass'] as $ocValue) - $output .= sprintf('%s%s%s',$indent['val'],$ocValue,$this->br); + { + $output .= sprintf('%s%s%s', $indent['val'], $ocValue, $this->br); + } $output .= sprintf('%s%s',$indent['att'],$this->br); unset($dndetails['objectClass']); @@ -408,7 +452,9 @@ class ExportDSML extends Export { # Display the attributes foreach ($dndetails as $key => $attr) { if (! is_array($attr)) + { $attr = array($attr); + } $output .= sprintf('%s%s',$indent['att'],$key,$this->br); @@ -416,8 +462,10 @@ class ExportDSML extends Export { $binary_mode = $server->isAttrBinary($key) ? 1 : 0; foreach ($attr as $value) + { $output .= sprintf('%s%s%s', - $indent['val'],($binary_mode ? base64_encode($value) : htmlspecialchars($value)),$this->br); + $indent['val'], ($binary_mode ? base64_encode($value) : htmlspecialchars($value)), $this->br); + } $output .= sprintf('%s%s',$indent['att'],$this->br); } @@ -430,9 +478,13 @@ class ExportDSML extends Export { $output .= sprintf('%s',$this->br); if ($this->compress) + { return gzencode($output); + } else + { return $output; + } } } @@ -446,7 +498,7 @@ class ExportLDIF extends Export { # The maximum length of the ldif line private $line_length = 76; - static public function getType() { + public static function getType() { return array('type'=>'LDIF','description' => _('LDIF Export'),'extension'=>'ldif'); } @@ -481,26 +533,39 @@ class ExportLDIF extends Export { $title_string = sprintf('# %s %s: %s%s',_('Entry'),$counter,$dn,$this->br); if (strlen($title_string) > $this->line_length-3) - $title_string = substr($title_string,0,$this->line_length-3).'...'.$this->br; + { + $title_string = substr($title_string, 0, $this->line_length - 3) . '...' . $this->br; + } $output .= $title_string; # Display dn if ($this->isSafeAscii($dn)) - $output .= $this->multiLineDisplay(sprintf('dn: %s',$dn)); + { + $output .= $this->multiLineDisplay(sprintf('dn: %s', $dn)); + } else - $output .= $this->multiLineDisplay(sprintf('dn:: %s',base64_encode($dn))); + { + $output .= $this->multiLineDisplay(sprintf('dn:: %s', base64_encode($dn))); + } # display the attributes foreach ($dndetails as $key => $attr) { if (! is_array($attr)) + { $attr = array($attr); + } foreach ($attr as $value) - if (! $this->isSafeAscii($value) || $server->isAttrBinary($key)) - $output .= $this->multiLineDisplay(sprintf('%s:: %s',$key,base64_encode($value))); - else - $output .= $this->multiLineDisplay(sprintf('%s: %s',$key,$value)); + { + if ( ! $this->isSafeAscii($value) || $server->isAttrBinary($key)) + { + $output .= $this->multiLineDisplay(sprintf('%s:: %s', $key, base64_encode($value))); + } else + { + $output .= $this->multiLineDisplay(sprintf('%s: %s', $key, $value)); + } + } } $output .= $this->br; @@ -508,9 +573,13 @@ class ExportLDIF extends Export { } if ($this->compress) + { return gzencode($output); + } else + { return $output; + } } /** @@ -547,7 +616,7 @@ class ExportLDIF extends Export { * @subpackage Export */ class ExportVCARD extends Export { - static public function getType() { + public static function getType() { return array('type'=>'VCARD','description' => _('VCARD 2.1 Export'),'extension'=>'vcf'); } @@ -603,7 +672,9 @@ class ExportVCARD extends Export { # Loop for the attributes foreach ($dndetails as $key => $attr) { if (! is_array($attr)) + { $attr = array($attr); + } # If an attribute of the ldap entry exist in the mapping array for vcard if (isset($this->mapping[$key])) { @@ -613,8 +684,12 @@ class ExportVCARD extends Export { $output .= sprintf('%s:%s',$this->mapping[$key],$attr[0]); if (isset($entry['ou'])) + { foreach ($entry['ou'] as $ou_value) - $output .= sprintf(';%s',$ou_value); + { + $output .= sprintf(';%s', $ou_value); + } + } # The attribute is binary. (to do : need to fold the line) } elseif (in_array($key,array('audio','jpegphoto'))) { @@ -637,9 +712,13 @@ class ExportVCARD extends Export { } if ($this->compress) + { return gzencode($output); + } else + { return $output; + } } } diff --git a/lib/functions.php b/lib/functions.php index 6b99c08..bca6e7f 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -46,7 +46,9 @@ $app['function_files'] = array( ); if (file_exists(LIBDIR.'functions.custom.php')) - array_push($app['function_files'],LIBDIR.'functions.custom.php'); +{ + array_push($app['function_files'], LIBDIR . 'functions.custom.php'); +} /** * Loads class definition @@ -54,17 +56,25 @@ if (file_exists(LIBDIR.'functions.custom.php')) */ function autoload($className) { if (file_exists(HOOKSDIR."classes/$className.php")) - require_once(HOOKSDIR."classes/$className.php"); + { + require_once(HOOKSDIR . "classes/$className.php"); + } elseif (file_exists(LIBDIR."$className.php")) - require_once(LIBDIR."$className.php"); + { + require_once(LIBDIR . "$className.php"); + } elseif (file_exists(LIBDIR."ds_$className.php")) - require_once(LIBDIR."ds_$className.php"); + { + require_once(LIBDIR . "ds_$className.php"); + } else + { system_message(array( - 'title'=>_('Generic Error'), - 'body'=>sprintf('%s: %s [%s]', - __METHOD__,_('Called to load a class that cant be found'),$className), - 'type'=>'error')); + 'title' => _('Generic Error'), + 'body' => sprintf('%s: %s [%s]', + __METHOD__, _('Called to load a class that cant be found'), $className), + 'type' => 'error')); + } } /** @@ -74,14 +84,23 @@ function autoload($className) { */ function array_stripslashes(&$array) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (is_array($array)) + { while (list($key) = each($array)) + { if (is_array($array[$key]) && $key != $array) + { array_stripslashes($array[$key]); - else + } else + { $array[$key] = stripslashes($array[$key]); + } + } + } } /** @@ -122,7 +141,9 @@ if (! function_exists('_')) { */ function app_error_handler($errno,$errstr,$file,$lineno) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } /** * error_reporting will be 0 if the error context occurred @@ -131,7 +152,9 @@ function app_error_handler($errno,$errstr,$file,$lineno) { * disabled them with '@' */ if (ini_get('error_reporting') == 0 || error_reporting() == 0) + { return; + } $file = basename($file); $caller = basename($_SERVER['PHP_SELF']); @@ -203,11 +226,15 @@ function app_version() { static $CACHE = null; if ($CACHE) + { return $CACHE; + } $version_file = realpath(LIBDIR.'../VERSION'); if (! file_exists($version_file)) + { $CACHE = 'UNKNOWN'; + } else { $version = rtrim(file_get_contents($version_file)); @@ -216,14 +243,18 @@ function app_version() { # Check if we are a CVS copy. if (preg_match('/^(DEVEL)?$/',$CACHE)) + { $CACHE = 'DEVEL'; + } # Check if we are special DEVEL version elseif (preg_match('/^DEVEL-([0-9\.]+)+$/',$CACHE)) {} # If return is still the same as version, then the tag is not one we expect. elseif ($CACHE == $version) + { $CACHE = 'UNKNOWN'; + } } return $CACHE; @@ -255,16 +286,20 @@ function check_config($config_file) { # Make sure their PHP version is current enough if (strcmp(phpversion(),REQUIRED_PHP_VERSION) < 0) + { system_message(array( - 'title'=>_('Incorrect version of PHP'), - 'body'=>sprintf('phpLDAPadmin requires PHP version %s or greater.
    (You are using %s)', - REQUIRED_PHP_VERSION,phpversion()), - 'type'=>'error')); + 'title' => _('Incorrect version of PHP'), + 'body' => sprintf('phpLDAPadmin requires PHP version %s or greater.
    (You are using %s)', + REQUIRED_PHP_VERSION, phpversion()), + 'type' => 'error')); + } $config = new Config; if (file_exists(LIBDIR.'config_custom.php') && is_readable(LIBDIR.'config_custom.php')) - include LIBDIR.'config_custom.php'; + { + include LIBDIR . 'config_custom.php'; + } ob_start(); require $config_file; @@ -298,15 +333,21 @@ function check_config($config_file) { for ($i = $line_num-9; $i<$line_num+5; $i++) { if ($i+1 == $line_num) + { $body .= '
    '; + } if ($i < 0) + { continue; + } $body .= sprintf('%s: %s
    ',$i+1,$file[$i]); if ($i+1 == $line_num) + { $body .= '
    '; + } } $body .= ''; @@ -326,7 +367,9 @@ function check_config($config_file) { # Check for server definitions. if (! isset($servers) || count($servers->GetServerList()) == 0) - error(_('Your config.php is missing Server Definitions. Please see the sample file config/config.php.example.'),'error','index.php',true); + { + error(_('Your config.php is missing Server Definitions. Please see the sample file config/config.php.example.'), 'error', 'index.php', TRUE); + } $config->setServers($servers); @@ -334,11 +377,13 @@ function check_config($config_file) { $ini_limit = ini_get('memory_limit'); $ini_limit = str_replace('G', 1024 * 1024 * 1024 * (int)$ini_limit, $ini_limit); if ((ini_get('memory_limit') > -1) && $ini_limit < $config->getValue('session','memorylimit')) + { system_message(array( - 'title'=>_('Memory Limit low.'), - 'body'=>sprintf('Your php memory limit is low - currently %s, you should increase it to at least %s. This is normally controlled in /etc/php.ini.', - ini_get('memory_limit'),$config->getValue('session','memorylimit')), - 'type'=>'error')); + 'title' => _('Memory Limit low.'), + 'body' => sprintf('Your php memory limit is low - currently %s, you should increase it to at least %s. This is normally controlled in /etc/php.ini.', + ini_get('memory_limit'), $config->getValue('session', 'memorylimit')), + 'type' => 'error')); + } return $config; } @@ -351,7 +396,9 @@ function check_config($config_file) { */ function cmd_control_pane($type) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } switch ($type) { case 'main' : @@ -428,7 +475,9 @@ function debug_dump($variable,$die=false,$onlydebugaddr=false) { isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('debug','addr') && $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SESSION[APPCONFIG]->getValue('debug','addr') && $_SERVER['REMOTE_ADDR'] != $_SESSION[APPCONFIG]->getValue('debug','addr')) + { return; + } $backtrace = debug_backtrace(); $caller['class'] = isset($backtrace[0]['class']) ? $backtrace[0]['class'] : 'N/A'; @@ -442,7 +491,9 @@ function debug_dump($variable,$die=false,$onlydebugaddr=false) { print ''; if ($die) + { die(); + } } /** @@ -501,25 +552,39 @@ function debug_log($msg,$level,$indent) { # In case we are called before we are fully initialised or if debugging is not set. if (! isset($_SESSION[APPCONFIG]) || ! ($_SESSION[APPCONFIG]->getValue('debug','file') || $_SESSION[APPCONFIG]->getValue('debug','syslog'))) + { return; + } $debug_level = $_SESSION[APPCONFIG]->getValue('debug','level'); if (! $debug_level || (! ($level & $debug_level))) + { return; + } if ($_SESSION[APPCONFIG]->getValue('debug','addr')) - if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] == $_SESSION[APPCONFIG]->getValue('debug','addr')) - $debugaddr = true; - elseif ($_SERVER['REMOTE_ADDR'] == $_SESSION[APPCONFIG]->getValue('debug','addr')) - $debugaddr = true; - else - $debugaddr = false; + { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] == $_SESSION[APPCONFIG]->getValue('debug', 'addr')) + { + $debugaddr = TRUE; + } elseif ($_SERVER['REMOTE_ADDR'] == $_SESSION[APPCONFIG]->getValue('debug', 'addr')) + { + $debugaddr = TRUE; + } else + { + $debugaddr = FALSE; + } + } else - $debugaddr = true; + { + $debugaddr = TRUE; + } if (! $debugaddr) + { return; + } # If we are limiting debug to a browser, then check that $caller = basename($_SERVER['PHP_SELF']); @@ -544,40 +609,60 @@ function debug_log($msg,$level,$indent) { # TEMP: New debuglog format if (preg_match('/%%/',$msg) && $args[0] != 'NOARGS') + { $args = array_shift($args); + } $fargs = array(); foreach ($args as $key) { if (is_array($key)) - array_push($fargs,serialize($key)); + { + array_push($fargs, serialize($key)); + } elseif (is_object($key)) - array_push($fargs,sprintf('OBJECT:%s',get_class($key))); + { + array_push($fargs, sprintf('OBJECT:%s', get_class($key))); + } else - array_push($fargs,$key); + { + array_push($fargs, $key); + } } if (preg_match('/%%/',$msg)) - $msg = preg_replace('/%%/',join('|',$fargs),$msg); + { + $msg = preg_replace('/%%/', join('|', $fargs), $msg); + } else - $msg = vsprintf($msg,array_values($fargs)); + { + $msg = vsprintf($msg, array_values($fargs)); + } if (function_exists('stopwatch')) + { $timer = stopwatch(); + } else - $timer = null; + { + $timer = NULL; + } $debug_message = sprintf('[%2.3f] %15s(%04s-%03s): %s%s: %s',$timer,basename($file),$line,$level,str_repeat('.',$indent),$method,substr($msg,0,200)); if ($debug_file || $_SESSION[APPCONFIG]->getValue('debug','file')) { if (! $debug_file) - $debug_file = fopen($_SESSION[APPCONFIG]->getValue('debug','file'), - $_SESSION[APPCONFIG]->getValue('debug','append') ? 'a' : 'w'); + { + $debug_file = fopen($_SESSION[APPCONFIG]->getValue('debug', 'file'), + $_SESSION[APPCONFIG]->getValue('debug', 'append') ? 'a' : 'w'); + } fwrite($debug_file,$debug_message."\n"); } if ($_SESSION[APPCONFIG]->getValue('debug','syslog') && function_exists('syslog_notice')) + { syslog_notice($debug_message); + } } /** @@ -594,16 +679,24 @@ function error($msg,$type='note',$redirect=null,$fatal=false,$backtrace=false) { # Just a check to see that we are called right. if (! isset($www['page']) && ! $fatal) + { die("Function error called incorrectly [$msg]"); + } # If the error is fatal, we'll need to stop here. if (! isset($www['page'])) + { $www['page'] = new page(); + } if ($fatal) - $www['page']->setsysmsg(array('title'=>_('Error'),'body'=>$msg,'type'=>$type)); + { + $www['page']->setsysmsg(array('title' => _('Error'), 'body' => $msg, 'type' => $type)); + } else - system_message(array('title'=>_('Error'),'body'=>$msg,'type'=>$type),$redirect); + { + system_message(array('title' => _('Error'), 'body' => $msg, 'type' => $type), $redirect); + } # Spin loop detection if ($counter++ > 20) { @@ -633,16 +726,22 @@ function error($msg,$type='note',$redirect=null,$fatal=false,$backtrace=false) { $display = print_r($line['args'], TRUE);/* strlen(serialize($line['args'])) < 50 ? htmlspecialchars(serialize($line['args'])) : htmlspecialchars(substr(serialize($line['args']),0,50)).'...'; */ $_SESSION['backtrace'][$error]['args'] = $line['args']; if (file_exists(LIBDIR.'../tools/unserialize.php')) + { $body .= sprintf(' (%s)', - '../tools/unserialize.php',$error,$display); + '../tools/unserialize.php', $error, $display); + } else - $body .= sprintf(' (%s)',$display); + { + $body .= sprintf(' (%s)', $display); + } } $body .= ''; $body .= "\n"; if (isset($line['file'])) + { $last['file'] = $line['file']; + } } $body .= '
    '; } printf('', $j,htmlspecialchars($attribute->getName()),$i, diff --git a/lib/PageRender.php b/lib/PageRender.php index ac7381c..eb90681 100644 --- a/lib/PageRender.php +++ b/lib/PageRender.php @@ -22,7 +22,9 @@ class PageRender extends Visitor { public function __construct($server_id,$template_id) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server_id; $this->template_id = $template_id; @@ -38,21 +40,27 @@ class PageRender extends Visitor { */ protected function getTemplates() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return new Templates($this->server_id); } public function getTemplate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->template; } public function getTemplateID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->template->getID(); } @@ -62,45 +70,69 @@ class PageRender extends Visitor { */ public function accept() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s:%s
    ',time(),__METHOD__); + if (DEBUGTMP) + { + printf('%s:%s
    ', time(), __METHOD__); + } if ($this->template_id) { $templates = $this->getTemplates(); $this->template = $templates->getTemplate($this->template_id); if ($this->dn) + { $this->template->setDN($this->dn); + } elseif ($this->container) + { $this->template->setContainer($this->container); + } $this->template->accept(); # Process our actions if (get_request('post_value','REQUEST')) - foreach (get_request('post_value','REQUEST') as $attr => $values) { + { + foreach (get_request('post_value', 'REQUEST') as $attr => $values) + { $attribute = $this->template->getAttribute($attr); - if (! $attribute) - debug_dump_backtrace(sprintf('There was a post_value for an attribute [%s], but it doesnt exist?',$attr),1); + if ( ! $attribute) + { + debug_dump_backtrace(sprintf('There was a post_value for an attribute [%s], but it doesnt exist?', $attr), 1); + } foreach ($values as $index) + { if ($attribute->getPostValue()) - $this->get('Post',$attribute,$index); - else - $this->get('AutoPost',$attribute,$index); + { + $this->get('Post', $attribute, $index); + } else + { + $this->get('AutoPost', $attribute, $index); + } + } } + } foreach ($this->template->getAttributes(true) as $attribute) { - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Accept:%s]
    ',__METHOD__,get_class($attribute)); + if (DEBUGTMP||DEBUGTMPSUB) + { + printf('* %s [Accept:%s]
    ', __METHOD__, get_class($attribute)); + } $this->visit('',$attribute); } // Sort our attribute values for display, if we are the custom template. if ($this->template->getID() == 'none') + { $this->template->sort(); + } } } @@ -110,34 +142,44 @@ class PageRender extends Visitor { public function drawSubTitle($subtitle=null) { if (is_null($subtitle)) + { $subtitle = sprintf('%s: %s   %s: %s', - _('Server'),$this->getServer()->getName(),_('Distinguished Name'),$this->dn); + _('Server'), $this->getServer()->getName(), _('Distinguished Name'), $this->dn); + } printf('

    %s

    ',$subtitle); } public function setDN($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->container) + { system_message(array( - 'title'=>__METHOD__, - 'body'=>'CONTAINER set while setting DN', - 'type'=>'info')); + 'title' => __METHOD__, + 'body' => 'CONTAINER set while setting DN', + 'type' => 'info')); + } $this->dn = $dn; } public function setContainer($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->dn) + { system_message(array( - 'title'=>__METHOD__, - 'body'=>'DN set while setting CONTAINER', - 'type'=>'info')); + 'title' => __METHOD__, + 'body' => 'DN set while setting CONTAINER', + 'type' => 'info')); + } $this->container = $dn; } @@ -155,7 +197,9 @@ class PageRender extends Visitor { */ protected function getPostAttribute($attribute,$i) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $autovalue = $attribute->getPostValue(); $args = explode(';',$autovalue['args']); @@ -188,7 +232,9 @@ class PageRender extends Visitor { array_push($values,$pv[$attribute->getName()][$i]); if (! $pv[$attribute->getName()][$i]) + { $blank++; + } } else { array_push($values,''); @@ -209,18 +255,27 @@ class PageRender extends Visitor { 'type'=>'warn')); } else - array_push($values,$attribute2->getValue(0)); + { + array_push($values, $attribute2->getValue(0)); + } } # If all our value expansion results in blanks, we'll return no value if (count($matchattrs) == $blank) + { if (count($vals) > 1) - $vals[$i] = null; - else - $vals = null; + { + $vals[$i] = NULL; + } else + { + $vals = NULL; + } + } else - $vals[$i] = implode($char,$values); + { + $vals[$i] = implode($char, $values); + } break; @@ -241,37 +296,49 @@ class PageRender extends Visitor { } if (! $attribute->hasBeenModified()) + { return; + } # Get the attribute. if (preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',strtolower($args[1]),$matchall)) { if (count($matchall[1]) != 1) + { system_message(array( - 'title'=>_('Invalid value count for PasswordEncrypt'), - 'body'=>sprintf('%s (%s)',_('Unable to get the attribute value for PasswordEncrypt()'),count($matchall[1])), - 'type'=>'warn')); + 'title' => _('Invalid value count for PasswordEncrypt'), + 'body' => sprintf('%s (%s)', _('Unable to get the attribute value for PasswordEncrypt()'), count($matchall[1])), + 'type' => 'warn')); + } $passwordattr = $matchall[1][0]; $passwordvalue = $_REQUEST['new_values'][$passwordattr][$i]; } else + { $passwordvalue = $args[1]; + } if (! trim($passwordvalue) || in_array($passwordvalue,$attribute->getOldValues())) + { return; + } # Get the encoding if ($passwordattr && preg_match_all('/%(\w+)(\|.+)?(\/[lU])?%/U',strtolower($args[0]),$matchall)) { if (count($matchall[1]) != 1) + { system_message(array( - 'title'=>_('Invalid value count for PasswordEncrypt'), - 'body'=>sprintf('%s (%s)',_('Unable to get the attribute value for PasswordEncrypt()'),count($matchall[1])), - 'type'=>'warn')); + 'title' => _('Invalid value count for PasswordEncrypt'), + 'body' => sprintf('%s (%s)', _('Unable to get the attribute value for PasswordEncrypt()'), count($matchall[1])), + 'type' => 'warn')); + } $enc = $_REQUEST[$matchall[1][0]][$passwordattr][$i]; } else + { $enc = $args[0]; + } $enc = strtolower($enc); @@ -301,14 +368,20 @@ class PageRender extends Visitor { } if (! $vals || $vals == $attribute->getValues()) + { return; + } $attribute->clearValue(); if (! is_array($vals)) + { $attribute->setValue(array($vals)); + } else + { $attribute->setValue($vals); + } } /** @@ -318,9 +391,14 @@ class PageRender extends Visitor { */ protected function getTemplateChoice() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # First work out our template $templates = $this->getTemplates(); @@ -328,13 +406,19 @@ class PageRender extends Visitor { # If the template we asked for is available if ($this->template_id === $template->getID()) { - if (DEBUGTMP) printf('%s:%s
    ',__METHOD__,'Choosing the SELECTED template'); + if (DEBUGTMP) + { + printf('%s:%s
    ', __METHOD__, 'Choosing the SELECTED template'); + } return $this->template_id; # If there are no defined templates } elseif (count($templates->getTemplates($this->getMode(),$this->getModeContainer(),false)) <= 0) { - if (DEBUGTMP) printf('%s:%s
    ',__METHOD__,'Choosing the DEFAULT template, no other template applicable'); + if (DEBUGTMP) + { + printf('%s:%s
    ', __METHOD__, 'Choosing the DEFAULT template, no other template applicable'); + } # Since getTemplate() returns a default template if the one we want doesnt exist, we can return $templates->getID(), it should be the default. if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template') AND $this->getMode() == 'creation') { @@ -347,23 +431,35 @@ class PageRender extends Visitor { return 'invalid'; } else + { return $template->getID(); + } # If there is only 1 defined template, and no default available, then that is our template. } elseif ((count($templates->getTemplates($this->getMode(),$this->getModeContainer(),true)) == 1) && ! $this->haveDefaultTemplate()) { - if (DEBUGTMP) printf('%s:%s
    ',__METHOD__,'AUTOMATIC choosing a template, only 1 template applicable'); + if (DEBUGTMP) + { + printf('%s:%s
    ', __METHOD__, 'AUTOMATIC choosing a template, only 1 template applicable'); + } $template = $templates->getTemplates($this->getMode(),$this->getModeContainer(),true); $template = array_shift($template); # Dont render the only available template if it is invalid. if (! $template->isInvalid()) + { return $template->getID(); + } else + { $this->drawTemplateChoice(); + } } else { - if (DEBUGTMP) printf('%s:%s
    ',__METHOD__,'SELECT a template to use.'); + if (DEBUGTMP) + { + printf('%s:%s
    ', __METHOD__, 'SELECT a template to use.'); + } # Propose the template choice $this->drawTemplateChoice(); @@ -378,22 +474,34 @@ class PageRender extends Visitor { */ final protected function drawNameAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd.php?cmd=schema&server_id=%s&view=attributes&viewvalue=%s', $this->getServerID(),$attribute->getName()); if (! $_SESSION[APPCONFIG]->getValue('appearance','show_schema_link') || !$_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) - printf('%s',_($attribute->getFriendlyName())); + { + printf('%s', _($attribute->getFriendlyName())); + } elseif ($attribute->getLDAPtype()) + { printf('%s', htmlspecialchars($href), - _('Click to view the schema definition for attribute type'),$attribute->getName(false),_($attribute->getFriendlyName())); + _('Click to view the schema definition for attribute type'), $attribute->getName(FALSE), _($attribute->getFriendlyName())); + } else - printf('%s',_('This attribute is not defined in the LDAP schema'),_($attribute->getFriendlyName())); + { + printf('%s', _('This attribute is not defined in the LDAP schema'), _($attribute->getFriendlyName())); + } - if (DEBUGTMPSUB) printf(' [%s]',get_class($attribute)); + if (DEBUGTMPSUB) + { + printf(' [%s]', get_class($attribute)); + } } /** ATTRIBUTE NOTES @@ -401,7 +509,10 @@ class PageRender extends Visitor { */ protected function drawNotesAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $attr_note = ''; @@ -410,38 +521,56 @@ class PageRender extends Visitor { if ($alias_note) { if (trim($attr_note)) + { $attr_note .= ', '; + } $attr_note .= $alias_note; } } if ($attr_note) - printf('%s',$attr_note); + { + printf('%s', $attr_note); + } } protected function getNoteAliasAttribute($attribute) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Is there a user-friendly translation available for this attribute? $friendly_name = $attribute->getFriendlyName(); if (strtolower($friendly_name) != $attribute->getName()) + { return sprintf('%s', - _('Note'),$friendly_name,_('is an alias for'),$attribute->getName(false),_('alias')); + _('Note'), $friendly_name, _('is an alias for'), $attribute->getName(FALSE), _('alias')); + } else + { return ''; + } } #@todo this function shouldnt re-calculate requiredness, it should be known in the template already - need to set the ldaptype when initiating the attribute. protected function getNoteRequiredAttribute($attribute) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $required_by = ''; $sattr_required = ''; @@ -449,73 +578,114 @@ class PageRender extends Visitor { # Is this attribute required by an objectClass ? $sattr = $this->getServer()->getSchemaAttribute($attribute->getName()); if ($sattr) + { $sattr_required = $sattr->getRequiredByObjectClasses(); + } if ($sattr_required) { $oc = $this->template->getAttribute('objectclass'); if ($oc) - foreach ($oc->getValues() as $objectclass) { + { + foreach ($oc->getValues() as $objectclass) + { # If this objectclass is in our required list - if (in_array_ignore_case($objectclass,$sattr_required)) { - $required_by .= sprintf('%s ',$objectclass); + if (in_array_ignore_case($objectclass, $sattr_required)) + { + $required_by .= sprintf('%s ', $objectclass); continue; } # If not, see if it is in our parent. $sattr = $this->getServer()->getSchemaObjectClass($objectclass); - if (array_intersect($sattr->getParents(),$sattr_required)) - $required_by .= sprintf('%s ',$objectclass); + if (array_intersect($sattr->getParents(), $sattr_required)) + { + $required_by .= sprintf('%s ', $objectclass); + } } + } else - debug_dump_backtrace('How can there be no objectclasses?',1); + { + debug_dump_backtrace('How can there be no objectclasses?', 1); + } } if ($required_by) - return sprintf('%s',_('Required attribute for objectClass(es)'),$required_by,_('required')); + { + return sprintf('%s', _('Required attribute for objectClass(es)'), $required_by, _('required')); + } else + { return ''; + } } protected function getNoteRDNAttribute($attribute) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Is this attribute required because its the RDN if ($attribute->isRDN()) - return sprintf('rdn',_('This attribute is required for the RDN.')); + { + return sprintf('rdn', _('This attribute is required for the RDN.')); + } else + { return ''; + } } protected function getNoteHintAttribute($attribute) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Is there a hint for this attribute if ($attribute->getHint()) - return sprintf('%s',_($attribute->getHint()),_('hint')); + { + return sprintf('%s', _($attribute->getHint()), _('hint')); + } else + { return ''; + } } protected function getNoteROAttribute($attribute) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Is this attribute is readonly if ($attribute->isReadOnly()) - return sprintf('ro',_('This attribute has been marked as Read Only.')); + { + return sprintf('ro', _('This attribute has been marked as Read Only.')); + } else + { return ''; + } } /** DRAW HIDDEN VALUES **/ @@ -524,18 +694,27 @@ class PageRender extends Visitor { */ final public function drawHiddenAttributes() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->template->getAttributes(true) as $attribute) - if ($attribute->hasbeenModified()) { + { + if ($attribute->hasbeenModified()) + { if ($attribute->getValues()) + { foreach ($attribute->getValues() as $index => $details) - $this->draw('HiddenValue',$attribute,$index); - - # We are deleting this attribute, so we need to display an empty value + { + $this->draw('HiddenValue', $attribute, $index); + } + } # We are deleting this attribute, so we need to display an empty value else - $this->draw('HiddenValue',$attribute,0); + { + $this->draw('HiddenValue', $attribute, 0); + } } + } } /** @@ -544,7 +723,10 @@ class PageRender extends Visitor { * @param $i */ final protected function drawHiddenValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -557,14 +739,22 @@ class PageRender extends Visitor { * @param $attribute */ protected function drawOldValuesAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } foreach ($attribute->getValues() as $index => $details) - $this->draw('OldValue',$attribute,$index); + { + $this->draw('OldValue', $attribute, $index); + } } final protected function drawOldValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } echo $attribute->getOldValue($i); } @@ -574,11 +764,16 @@ class PageRender extends Visitor { */ protected function drawCurrentValuesAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } for ($i=0;$i<$attribute->getValueCount();$i++) { if ($i > 0) + { echo '
    '; + } $this->draw('CurrentValue',$attribute,$i); } @@ -590,8 +785,14 @@ class PageRender extends Visitor { * @param $i */ final protected function drawCurrentValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } echo htmlspecialchars($attribute->getValue($i)); } @@ -602,26 +803,43 @@ class PageRender extends Visitor { * @param $i */ protected function drawFormValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } if ($this->getServer()->isReadOnly() || $attribute->isReadOnly() || ($attribute->isRDN() && $this->template->getType() != 'creation' && $i < count($attribute->getValues()))) - $this->draw('FormReadOnlyValue',$attribute,$i); + { + $this->draw('FormReadOnlyValue', $attribute, $i); + } else - $this->draw('FormReadWriteValue',$attribute,$i); + { + $this->draw('FormReadWriteValue', $attribute, $i); + } # Show the ADDVALUE DIV if the attribute can have more values, and we have rendered the last value if ($attribute->haveMoreValues() && $attribute->getValueCount() == $i+1) - printf('
    ',$attribute->getName()); + { + printf('
    ', $attribute->getName()); + } if ($attribute->getPostValue()) - printf('',$attribute->getName(),$i); + { + printf('', $attribute->getName(), $i); + } } protected function drawFormReadOnlyValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -630,12 +848,17 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); if ($attribute->getHelper() || $attribute->getVerify()) + { echo ''; } elseif ($attribute->getVerify()) + { echo ''; + } if ($attribute->getVerify()) { printf('
    '; + } printf('', htmlspecialchars($attribute->getName()),$i, @@ -652,7 +875,9 @@ class PageRender extends Visitor { echo '
    ', @@ -667,7 +892,9 @@ class PageRender extends Visitor { } if ($attribute->getHelper() || $attribute->getVerify()) + { echo '
    '; + } } /** @@ -676,7 +903,10 @@ class PageRender extends Visitor { * @param $i */ final protected function drawHiddenValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -687,7 +917,9 @@ class PageRender extends Visitor { final protected function drawOldValueBinaryAttribute($attribute,$i) { # If we dont have a value, we'll just return; if (! $attribute->getOldValue($i)) + { return; + } printf('[%s]',_('Binary Value')); } @@ -696,11 +928,16 @@ class PageRender extends Visitor { printf('[%s]',_('Binary Value')); if (in_array($attribute->getName(),array('objectsid'))) + { printf(' (%s)', binSIDtoText($attribute->getValue(0))); + } } protected function drawFormReadOnlyValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->draw('CurrentValue',$attribute,$i); echo '

    '; @@ -715,14 +952,19 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueBinaryAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if ($attribute->getValue($i)) { $this->draw('FormReadOnlyValue',$attribute,$i); if (! $attribute->isReadOnly() && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr')) + { printf('Trash %s', - $attribute->getName(),$attribute->getFriendlyName(),$i,IMGDIR,_('delete attribute')); + $attribute->getName(), $attribute->getFriendlyName(), $i, IMGDIR, _('delete attribute')); + } } else { printf('
    ', @@ -736,7 +978,10 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueDateAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -754,12 +999,17 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueDnAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); if ($attribute->getHelper()) + { echo ''; if (isAjaxEnabled()) - return sprintf($layout,IMGDIR,'add.png',_('Add'), - htmlspecialchars($href),_('Add new attribute to this object'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Add new attribute')),_('Add new attribute')); + { + return sprintf($layout, IMGDIR, 'add.png', _('Add'), + htmlspecialchars($href), _('Add new attribute to this object'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Add new attribute')), _('Add new attribute')); + } else - return sprintf($this->layout['action'],IMGDIR,'add.png',_('Add'), - htmlspecialchars($href),_('Add new attribute to this object'),_('Add new attribute')); + { + return sprintf($this->layout['action'], IMGDIR, 'add.png', _('Add'), + htmlspecialchars($href), _('Add new attribute to this object'), _('Add new attribute')); + } } protected function getMenuItemShowChildren($children_count) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=one&query=none&size_limit=0&search=true', $this->getServerID(),rawurlencode('objectClass=*'),$this->template->getDNEncode()); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'children.png',_('Children'), - htmlspecialchars($href),_('View the children of this object'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')), - ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'),$children_count)); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'children.png', _('Children'), + htmlspecialchars($href), _('View the children of this object'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), + ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'), $children_count)); + } else - return sprintf($this->layout['action'],IMGDIR,'children.png',_('Children'), - htmlspecialchars($href),_('View the children of this object'), - ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'),$children_count)); + { + return sprintf($this->layout['action'], IMGDIR, 'children.png', _('Children'), + htmlspecialchars($href), _('View the children of this object'), + ($children_count == 1) ? _('View 1 child') : sprintf(_('View %s children'), $children_count)); + } } protected function getMenuItemExportSub() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=export_form&%s&scope=%s',$this->url_base,'sub'); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'export.png',_('Save'), - htmlspecialchars($href),_('Save a dump of this object and all of its children'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Export subtree')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'export.png', _('Save'), + htmlspecialchars($href), _('Save a dump of this object and all of its children'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Export subtree')); + } else - return sprintf($this->layout['action'],IMGDIR,'export.png',_('Save'), - htmlspecialchars($href),_('Save a dump of this object and all of its children'),_('Export subtree')); + { + return sprintf($this->layout['action'], IMGDIR, 'export.png', _('Save'), + htmlspecialchars($href), _('Save a dump of this object and all of its children'), _('Export subtree')); + } } /** CHOOSERS **/ @@ -1267,7 +1638,10 @@ class TemplateRender extends PageRender { * RDN Chooser */ protected function drawRDNChooser() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (! count($this->template->getRDNAttrs())) { printf('','RDN'); @@ -1276,9 +1650,13 @@ class TemplateRender extends PageRender { printf('',_('select the rdn attribute')); if ($_SESSION[APPCONFIG]->getValue('appearance','rdn_all_attrs')) - $allattrs = true; + { + $allattrs = TRUE; + } else - $allattrs = false; + { + $allattrs = FALSE; + } foreach ($this->template->getAttributes($allattrs) as $attr) { $n = $attr->getName(false); @@ -1295,10 +1673,14 @@ class TemplateRender extends PageRender { } else { echo ''; } @@ -1309,13 +1691,18 @@ class TemplateRender extends PageRender { * @param $default_container */ protected function drawContainerChooser($default_container) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } echo ''; printf('',_('Container')); echo ''; printf('',_('ObjectClasses')); @@ -1340,7 +1732,9 @@ class TemplateRender extends PageRender { foreach ($socs as $name => $oclass) { if (! strcasecmp('top',$name)) + { continue; + } printf('', ($oclass->getType() == 'structural') ? 'style="font-weight: bold" ' : '', @@ -1362,16 +1756,25 @@ class TemplateRender extends PageRender { protected function drawInternalAttributes() { if ($this->template->getAttributesInternal()) + { foreach ($this->template->getAttributesInternal() as $attribute) - $this->draw('Internal',$attribute); + { + $this->draw('Internal', $attribute); + } + } else - printf('',_('No internal attributes')); + { + printf('', _('No internal attributes')); + } echo "\n"; } protected function drawInternalAttribute($attribute) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->draw('Template',$attribute); } @@ -1383,14 +1786,21 @@ class TemplateRender extends PageRender { echo '
    '; if ($_SESSION[APPCONFIG]->getValue('confirm','update')) + { echo ''; + } else + { echo ''; + } echo '
    '; } protected function drawForm($nosubmit=false) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } echo '
    '; printf('',$this->getServerID()); @@ -1402,7 +1812,9 @@ class TemplateRender extends PageRender { $this->drawShownAttributes(); if (! $nosubmit) + { $this->drawFormSubmitButton(); + } echo '
    '; + } $input_name = sprintf('new_values[%s][%s]',htmlspecialchars($attribute->getName()),$i); $id = sprintf('new_values_%s_%s',htmlspecialchars($attribute->getName()),$i); @@ -785,7 +1035,10 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueGidAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->drawFormReadWriteValueAttribute($attribute,$i); @@ -821,10 +1074,16 @@ class PageRender extends Visitor { $description = isset($group['description']) ? $group['description'] : null; if (is_array($description)) + { foreach ($description as $item) - printf(' (%s)',$item); + { + printf(' (%s)', $item); + } + } else - printf(' (%s)',$description); + { + printf(' (%s)', $description); + } echo ''; @@ -840,12 +1099,20 @@ class PageRender extends Visitor { * @param $i */ final protected function drawOldValueJpegAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } # If we dont have a value, we'll just return; if (! $attribute->getOldValue($i)) + { return; + } draw_jpeg_photo($this->getServer(),$this->template->getDN(),$attribute->getName(),$i,false,false); } @@ -856,19 +1123,29 @@ class PageRender extends Visitor { * @param $i */ final protected function drawCurrentValueJpegAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } # If we dont have a value, we'll just return; if (! $attribute->getValue($i)) + { return; + } # If the attribute is modified, the new value needs to be stored in a session variable for the draw_jpeg_photo callback. if ($attribute->hasBeenModified()) { $_SESSION['tmp'][$attribute->getName()][$i] = $attribute->getValue($i); draw_jpeg_photo(null,$this->template->getDN(),$attribute->getName(),$i,false,false); } else - draw_jpeg_photo($this->getServer(),$this->template->getDN(),$attribute->getName(),$i,false,false); + { + draw_jpeg_photo($this->getServer(), $this->template->getDN(), $attribute->getName(), $i, FALSE, FALSE); + } } protected function drawFormReadOnlyValueJpegAttribute($attribute,$i) { @@ -879,7 +1156,10 @@ class PageRender extends Visitor { } protected function drawFormReadOnlyValueMultiLineAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -892,7 +1172,10 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueMultiLineAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -907,7 +1190,10 @@ class PageRender extends Visitor { } protected function drawFormValueObjectClassAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $val = $attribute->getValue($i); @@ -934,52 +1220,83 @@ class PageRender extends Visitor { _('structural')); } else - $this->draw('FormReadWriteValue',$attribute,$i); + { + $this->draw('FormReadWriteValue', $attribute, $i); + } } protected function getAutoPostPasswordAttribute($attribute,$i) { # If the password is already encoded, then we'll return if (preg_match('/^\{.+\}.+/',$attribute->getValue($i))) + { return; + } $attribute->setPostValue(array('function'=>'PasswordEncrypt','args'=>sprintf('%%enc%%;%%%s%%',$attribute->getName()))); $this->get('Post',$attribute,$i); } protected function drawOldValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } $val = $attribute->getOldValue($i); if (obfuscate_password_display(get_enc_type($val))) - echo str_repeat('*',16); + { + echo str_repeat('*', 16); + } else + { echo nl2br(htmlspecialchars($attribute->getOldValue($i))); + } } final protected function drawCurrentValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); - if (DEBUGTMPSUB) printf(' [%s]',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } + if (DEBUGTMPSUB) + { + printf(' [%s]', __METHOD__); + } $val = $attribute->getValue($i); if (obfuscate_password_display(get_enc_type($val))) - echo str_repeat('*',16); + { + echo str_repeat('*', 16); + } else + { echo nl2br(htmlspecialchars($attribute->getValue($i))); + } } protected function drawFormReadOnlyValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $server = $this->getServer(); $val = $attribute->getValue($i); if (trim($val)) + { $enc_type = get_enc_type($val); + } else - $enc_type = $server->getValue('appearance','password_hash'); + { + $enc_type = $server->getValue('appearance', 'password_hash'); + } $obfuscate_password = obfuscate_password_display($enc_type); @@ -989,11 +1306,16 @@ class PageRender extends Visitor { $i,htmlspecialchars($val),($attribute->getSize() > 0) ? 'size="'.$attribute->getSize().'"' : ''); if (trim($val)) - $this->draw('CheckLink',$attribute,'new_values_'.htmlspecialchars($attribute->getName()).'_'.$i); + { + $this->draw('CheckLink', $attribute, 'new_values_' . htmlspecialchars($attribute->getName()) . '_' . $i); + } } protected function drawFormReadWriteValuePasswordAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $server = $this->getServer(); $val = $attribute->getValue($i); @@ -1002,9 +1324,13 @@ class PageRender extends Visitor { # Set the default hashing type if the password is blank (must be newly created) if (trim($val)) + { $enc_type = get_enc_type($val); + } else - $enc_type = $server->getValue('appearance','password_hash'); + { + $enc_type = $server->getValue('appearance', 'password_hash'); + } echo '', htmlspecialchars($attribute->getName()),$j++, @@ -1111,13 +1454,17 @@ class PageRender extends Visitor { } foreach ($vals as $val) - if (! isset($selected[$val])) + { + if ( ! isset($selected[$val])) + { printf('', - htmlspecialchars($attribute->getName()),$j++, - htmlspecialchars($attribute->getName()),$val, - $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ',$attribute->getName()) : '', - $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ',$attribute->getName()) : '', + htmlspecialchars($attribute->getName()), $j++, + htmlspecialchars($attribute->getName()), $val, + $attribute->needJS('focus') ? sprintf('onfocus="focus_%s(this);" ', $attribute->getName()) : '', + $attribute->needJS('blur') ? sprintf('onblur="blur_%s(this);" ', $attribute->getName()) : '', $val); + } + } echo '
    '; @@ -1023,9 +1349,13 @@ class PageRender extends Visitor { echo ''; if ($attribute->getHelper()) - $this->draw('Helper',$attribute,$i); + { + $this->draw('Helper', $attribute, $i); + } else - $this->draw('DefaultHelper',$attribute,$i); + { + $this->draw('DefaultHelper', $attribute, $i); + } echo '
    '; @@ -1046,19 +1376,26 @@ class PageRender extends Visitor { } protected function drawFormReadWriteValueSelectionAttribute($attribute,$i) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if ($attribute->isMultiple()) { # For multiple selection, we draw the component only one time if ($i > 0) + { return; + } $selected = array(); $vals = $attribute->getValues(); $j = 0; if (! $vals && ! is_null($attribute->getDefault()) && ! is_array($vals = $attribute->getDefault())) + { $vals = array($attribute->getDefault()); + } if (($attribute->getSize() > 0) && ($attribute->getSize() < $attribute->getOptionCount())) { @@ -1067,7 +1404,9 @@ class PageRender extends Visitor { foreach ($attribute->getSelection() as $value => $description) { if (in_array($value,$vals)) - $selected[$value] = true; + { + $selected[$value] = TRUE; + } printf('', htmlspecialchars($attribute->getName()),$j++, @@ -1079,10 +1418,12 @@ class PageRender extends Visitor { foreach ($vals as $val) { if (! isset($selected[$val])) + { printf('', - htmlspecialchars($attribute->getName()),$j++, - $val,htmlspecialchars($attribute->getName()), - htmlspecialchars($attribute->getName()),$val); + htmlspecialchars($attribute->getName()), $j++, + $val, htmlspecialchars($attribute->getName()), + htmlspecialchars($attribute->getName()), $val); + } echo "\n"; } @@ -1099,7 +1440,9 @@ class PageRender extends Visitor { foreach ($attribute->getSelection() as $value => $description) { if (in_array($value,$vals)) - $selected[$value] = true; + { + $selected[$value] = TRUE; + } printf('
     %s
     %s
    '; } @@ -1127,17 +1474,21 @@ class PageRender extends Visitor { $val = $attribute->getValue($i) ? $attribute->getValue($i) : $attribute->getDefault(); if ($attribute->getHelper()) + { echo ''; echo ''; @@ -212,7 +240,9 @@ class QueryRender extends PageRender { private function visitStart() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->drawTitle(_('Search Results')); $this->drawSubTitle(); @@ -221,7 +251,9 @@ class QueryRender extends PageRender { private function visitEnd() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $afattrs = $this->getAFattrs(); @@ -243,7 +275,9 @@ class QueryRender extends PageRender { $counter++; if (! $show = get_request('show','REQUEST')) - $show = ($counter === 1 ? $this->getAjaxRef($base) : null); + { + $show = ($counter === 1 ? $this->getAjaxRef($base) : NULL); + } printf('
    ', $this->getAjaxRef($base), ($show == $this->getAjaxRef($base) ? 'block' : 'none')); @@ -284,18 +318,26 @@ class QueryRender extends PageRender { # Ignore DN, we've already displayed it. if ($attr == 'dn') + { continue 2; + } if (! isset($dndetails[$attr])) + { continue 2; + } # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) + { $afattrs[$attr]->initValue($dndetails[$attr]); + } else + { $afattrs[$attr]->initValue(array($dndetails[$attr])); + } echo '
    '; echo ''; @@ -329,7 +371,9 @@ class QueryRender extends PageRender { printf('',$server->getIndex()); foreach ($this->template->resultsdata[$base]['attrs'] as $attr) - printf('',$attr); + { + printf('', $attr); + } echo ''; @@ -362,7 +406,9 @@ class QueryRender extends PageRender { # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass','enabled')) - printf('',$j,$dndetails['dn']); + { + printf('', $j, $dndetails['dn']); + } $href = sprintf('cmd=template_engine&server_id=%s&dn=%s',$server->getIndex(),$this->template->getDNEncode()); printf('', @@ -390,9 +436,13 @@ class QueryRender extends PageRender { # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) + { $afattrs[$attr]->initValue($dndetails[$attr]); + } else + { $afattrs[$attr]->initValue(array($dndetails[$attr])); + } echo ''; echo ''; @@ -433,7 +485,9 @@ class QueryRender extends PageRender { } if (get_request('format','REQUEST',false,'table') == 'table') - printf('',JSDIR); + { + printf('', JSDIR); + } } public function drawSubTitle($subtitle=null) { @@ -446,7 +500,9 @@ class QueryRender extends PageRender { $subtitle .= '
    '; $subtitle .= sprintf('%s: %s',('Query'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); + { + $subtitle .= sprintf(' (%s)', $this->template->getName(FALSE)); + } } } @@ -455,20 +511,26 @@ class QueryRender extends PageRender { private function getAFattrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attribute_factory = new AttributeFactory(); $results = array(); foreach (explode(',',$this->template->getAttrDisplayOrder()) as $attr) - $results[strtolower($attr)] = $attribute_factory->newAttribute($attr,array('values'=>array()),$this->getServerID()); + { + $results[strtolower($attr)] = $attribute_factory->newAttribute($attr, array('values' => array()), $this->getServerID()); + } return $results; } private function getAjaxRef($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return preg_replace('/=/','.',base64_encode($dn)); } @@ -480,7 +542,9 @@ class QueryRender extends PageRender { echo 'var $items = new Array();'; $counter = 0; foreach ($this->template->results as $base => $results) - printf("items[%s] = '%s';",$counter++,$this->getAjaxRef($base)); + { + printf("items[%s] = '%s';", $counter++, $this->getAjaxRef($base)); + } echo 'return items;'; echo '}'; echo "\n\n"; @@ -490,7 +554,9 @@ class QueryRender extends PageRender { $counter = 0; foreach ($this->template->results as $base => $results) { if (! $show = get_request('show','REQUEST')) - $show = ($counter++ === 0 ? $this->getAjaxRef($base) : null); + { + $show = ($counter++ === 0 ? $this->getAjaxRef($base) : NULL); + } printf('', $this->getAjaxRef($base), @@ -534,10 +600,14 @@ class QueryRender extends PageRender { $query_string = htmlspecialchars(sprintf('%s&format=%s&show=%s&focusbase=%s',array_to_query_string($_GET,array('format','meth')),$f,$this->getAjaxRef($base),$base)); if (isAjaxEnabled()) + { printf('%s', - $query_string,$query_string,_('Loading Search'),_($f)); + $query_string, $query_string, _('Loading Search'), _($f)); + } else - printf('%s',$query_string,_($f)); + { + printf('%s', $query_string, _($f)); + } } } diff --git a/lib/SelectionAttribute.php b/lib/SelectionAttribute.php index d3df9b8..278b2c3 100644 --- a/lib/SelectionAttribute.php +++ b/lib/SelectionAttribute.php @@ -28,9 +28,13 @@ class SelectionAttribute extends Attribute { } if (isset($values['type']) && $values['type'] == 'multiselect') - $this->multiple = true; + { + $this->multiple = TRUE; + } else - $this->multiple = false; + { + $this->multiple = FALSE; + } } public function addOption($value,$description) { @@ -39,7 +43,9 @@ class SelectionAttribute extends Attribute { public function addValue($new_val,$i=-1) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->addOption($new_val,$i); } diff --git a/lib/Template.php b/lib/Template.php index 625383e..b376768 100644 --- a/lib/Template.php +++ b/lib/Template.php @@ -61,16 +61,22 @@ class Template extends xmlTemplate { # If this is the default template, we might disable leafs by default. if (is_null($filename)) - $this->noleaf = $_SESSION[APPCONFIG]->getValue('appearance','disable_default_leaf'); + { + $this->noleaf = $_SESSION[APPCONFIG]->getValue('appearance', 'disable_default_leaf'); + } } public function __clone() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # We need to clone our attributes, when passing back a template with getTemplate foreach ($this->attributes as $key => $value) + { $this->attributes[$key] = clone $value; + } } /** @@ -80,67 +86,93 @@ class Template extends xmlTemplate { */ protected function storeTemplate($xmldata) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); $objectclasses = array(); foreach ($xmldata['template'] as $xml_key => $xml_value) { if (DEBUG_ENABLED) - debug_log('Foreach loop Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key,is_array($xml_value)); + { + debug_log('Foreach loop Key [%s] Value [%s]', 4, 0, __FILE__, __LINE__, __METHOD__, $xml_key, is_array($xml_value)); + } switch ($xml_key) { # Build our object Classes from the DN and Template. case ('objectclasses'): if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); + { + debug_log('Case [%s]', 4, 0, __FILE__, __LINE__, __METHOD__, $xml_key); + } if (isset($xmldata['template'][$xml_key]['objectclass'])) - if (is_array($xmldata['template'][$xml_key]['objectclass'])) { - foreach ($xmldata['template'][$xml_key]['objectclass'] as $index => $details) { + { + if (is_array($xmldata['template'][$xml_key]['objectclass'])) + { + foreach ($xmldata['template'][$xml_key]['objectclass'] as $index => $details) + { # XML files with only 1 objectClass dont have a numeric index. $soc = $server->getSchemaObjectClass(strtolower($details)); # If we havent recorded this objectclass already, do so now. - if (is_object($soc) && ! in_array($soc->getName(),$objectclasses)) - array_push($objectclasses,$soc->getName(false)); - - elseif (! is_object($soc) && ! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning')) + if (is_object($soc) && ! in_array($soc->getName(), $objectclasses)) + { + array_push($objectclasses, $soc->getName(FALSE)); + } elseif ( ! is_object($soc) && ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning')) + { system_message(array( - 'title'=>_('Automatically removed objectClass from template'), - 'body'=>sprintf('%s: %s %s',$this->getTitle(),$details,_('removed from template as it is not defined in the schema')), - 'type'=>'warn')); + 'title' => _('Automatically removed objectClass from template'), + 'body' => sprintf('%s: %s %s', $this->getTitle(), $details, _('removed from template as it is not defined in the schema')), + 'type' => 'warn')); + } } - } else { + } else + { # XML files with only 1 objectClass dont have a numeric index. $soc = $server->getSchemaObjectClass(strtolower($xmldata['template'][$xml_key]['objectclass'])); # If we havent recorded this objectclass already, do so now. - if (is_object($soc) && ! in_array($soc->getName(),$objectclasses)) - array_push($objectclasses,$soc->getName(false)); + if (is_object($soc) && ! in_array($soc->getName(), $objectclasses)) + { + array_push($objectclasses, $soc->getName(FALSE)); + } } + } break; # Build our attribute list from the DN and Template. case ('attributes'): if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); + { + debug_log('Case [%s]', 4, 0, __FILE__, __LINE__, __METHOD__, $xml_key); + } if (is_array($xmldata['template'][$xml_key])) { foreach ($xmldata['template'][$xml_key] as $tattrs) - foreach ($tattrs as $index => $details) { + { + foreach ($tattrs as $index => $details) + { if (DEBUG_ENABLED) - debug_log('Foreach tattrs Key [%s] Value [%s]',4,0,__FILE__,__LINE__,__METHOD__, - $index,$details); + { + debug_log('Foreach tattrs Key [%s] Value [%s]', 4, 0, __FILE__, __LINE__, __METHOD__, + $index, $details); + } # If there is no schema definition for the attribute, it will be ignored. if ($sattr = $server->getSchemaAttribute($index)) + { if (is_null($this->getAttribute($sattr->getName()))) - $this->addAttribute($sattr->getName(),$details,'XML'); + { + $this->addAttribute($sattr->getName(), $details, 'XML'); + } + } } + } masort($this->attributes,'order'); } @@ -149,7 +181,9 @@ class Template extends xmlTemplate { default: if (DEBUG_ENABLED) - debug_log('Case [%s]',4,0,__FILE__,__LINE__,__METHOD__,$xml_key); + { + debug_log('Case [%s]', 4, 0, __FILE__, __LINE__, __METHOD__, $xml_key); + } # Some key definitions need to be an array, some must not be: $allowed_arrays = array('rdn'); @@ -158,15 +192,24 @@ class Template extends xmlTemplate { # Items that must be stored lowercase if (in_array($xml_key,$storelower)) + { if (is_array($xml_value)) + { foreach ($xml_value as $index => $value) + { $xml_value[$index] = strtolower($value); - else + } + } else + { $xml_value = strtolower($xml_value); + } + } # Items that must be stored as arrays if (in_array($xml_key,$storearray) && ! is_array($xml_value)) + { $xml_value = array($xml_value); + } # Items that should not be an array if (! in_array($xml_key,$allowed_arrays) && is_array($xml_value)) { @@ -178,7 +221,9 @@ class Template extends xmlTemplate { $this->$xml_key = $xml_value; if ($xml_key == 'invalid' && $xml_value) - $this->setInvalid(_('Disabled by XML configuration'),true); + { + $this->setInvalid(_('Disabled by XML configuration'), TRUE); + } } } @@ -214,9 +259,13 @@ class Template extends xmlTemplate { } if (! is_null($attribute)) + { $attribute->setRDN($counter++); + } elseif ($this->isType('creation')) - $this->setInvalid(sprintf(_('Missing RDN attribute %s in the XML file.'),$key)); + { + $this->setInvalid(sprintf(_('Missing RDN attribute %s in the XML file.'), $key)); + } } } @@ -228,12 +277,18 @@ class Template extends xmlTemplate { */ protected function hasDefaultTemplate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template')) - return false; + { + return FALSE; + } else - return true; + { + return TRUE; + } } /** @@ -244,7 +299,9 @@ class Template extends xmlTemplate { */ protected function readTemplates($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $template_xml = new Templates($this->server_id); return $template_xml->getTemplates($type); @@ -262,17 +319,21 @@ class Template extends xmlTemplate { */ public function accept($makeVisible=false,$nocache=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $this->getServer(); # If a DN is set, then query the LDAP server for the details. if ($this->dn) { if (! $server->dnExists($this->dn)) + { system_message(array( - 'title'=>__METHOD__, - 'body'=>sprintf('DN (%s) didnt exist in LDAP?',$this->dn), - 'type'=>'info')); + 'title' => __METHOD__, + 'body' => sprintf('DN (%s) didnt exist in LDAP?', $this->dn), + 'type' => 'info')); + } $rdnarray = rdn_explode(strtolower(get_rdn(dn_escape($this->dn)))); @@ -280,31 +341,47 @@ class Template extends xmlTemplate { foreach ($server->getDNAttrValues($this->dn,null,LDAP_DEREF_NEVER,array_merge(array('*'),$server->getValue('server','custom_attrs')),$nocache) as $attr => $values) { # We ignore DNs. if ($attr == 'dn') + { continue; + } $attribute = $this->getAttribute($attr); if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$values)); + { + $attribute = $this->addAttribute($attr, array('values' => $values)); + } else if ($attribute->getValues()) { # Override values to those that are defined in the XML file. if ($attribute->getSource() != 'XML') + { $attribute->setValue(array_values($values)); + } else + { $attribute->setOldValue(array_values($values)); + } } else + { $attribute->initValue(array_values($values)); + } # Work out the RDN attributes foreach ($attribute->getValues() as $index => $value) + { if (in_array(sprintf('%s=%s', - $attribute->getName(),strtolower($attribute->getValue($index))),$rdnarray)) + $attribute->getName(), strtolower($attribute->getValue($index))), $rdnarray)) + { $attribute->setRDN($counter++); + } + } if ($makeVisible) + { $attribute->show(); + } } # Get the Internal Attributes @@ -312,15 +389,23 @@ class Template extends xmlTemplate { $attribute = $this->getAttribute($attr); if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$values)); + { + $attribute = $this->addAttribute($attr, array('values' => $values)); + } else if ($attribute->getValues()) + { $attribute->setValue(array_values($values)); + } else + { $attribute->initValue(array_values($values)); + } if (! in_array_ignore_case($attribute->getName(),$server->getValue('server','custom_attrs'))) + { $attribute->setInternal(); + } } # If this is the default template, and our $_REQUEST has defined our objectclass, then query the schema to get the attributes @@ -346,53 +431,83 @@ class Template extends xmlTemplate { # Read in our new values. foreach (array('new_values') as $key) { if (isset($_REQUEST[$key])) - foreach ($_REQUEST[$key] as $attr => $values) { + { + foreach ($_REQUEST[$key] as $attr => $values) + { # If it isnt an array, silently ignore it. - if (! is_array($values)) + if ( ! is_array($values)) + { continue; + } # If _REQUEST['skip_array'] with this attr set, we'll ignore this new_value if (isset($_REQUEST['skip_array'][$attr]) && $_REQUEST['skip_array'][$attr] == 'on') + { continue; + } # Prune out entries with a blank value. foreach ($values as $index => $value) - if (! strlen(trim($value))) + { + if ( ! strlen(trim($value))) + { unset($values[$index]); + } + } $attribute = $this->getAttribute($attr); # If the attribute is null, then no attribute exists, silently ignore it (unless this is the default template) - if (is_null($attribute) && (! $this->isType('default') && ! $this->isType(null))) + if (is_null($attribute) && ( ! $this->isType('default') && ! $this->isType(NULL))) + { continue; + } # If it is a binary attribute, the post should have base64 encoded the value, we'll need to reverse that if ($server->isAttrBinary($attr)) + { foreach ($values as $index => $value) + { $values[$index] = base64_decode($value); + } + } - if (is_null($attribute)) { - $attribute = $this->addAttribute($attr,array('values'=>$values)); + if (is_null($attribute)) + { + $attribute = $this->addAttribute($attr, array('values' => $values)); if (count($values)) + { $attribute->justModified(); + } } else + { $attribute->setValue(array_values($values)); + } } + } # Read in our new binary values if (isset($_FILES[$key]['name'])) - foreach ($_FILES[$key]['name'] as $attr => $values) { + { + foreach ($_FILES[$key]['name'] as $attr => $values) + { $new_values = array(); - foreach ($values as $index => $details) { + foreach ($values as $index => $details) + { # Ignore empty files - if (! $_FILES[$key]['size'][$attr][$index]) + if ( ! $_FILES[$key]['size'][$attr][$index]) + { continue; + } - if (! is_uploaded_file($_FILES[$key]['tmp_name'][$attr][$index])) { + if ( ! is_uploaded_file($_FILES[$key]['tmp_name'][$attr][$index])) + { if (isset($_FILES[$key]['error'][$attr][$index])) - switch($_FILES[$key]['error'][$attr][$index]) { + { + switch ($_FILES[$key]['error'][$attr][$index]) + { # No error; possible file attack! case 0: @@ -424,45 +539,58 @@ class Template extends xmlTemplate { $msg = _('Security error: The file being uploaded may be malicious.'); break; } - - else + } else + { $msg = _('Security error: The file being uploaded may be malicious.'); + } system_message(array( - 'title'=>_('Upload Binary Attribute Error'),'body'=>$msg,'type'=>'warn')); + 'title' => _('Upload Binary Attribute Error'), 'body' => $msg, 'type' => 'warn')); - } else { + } else + { $binaryfile = array(); $binaryfile['name'] = $_FILES[$key]['tmp_name'][$attr][$index]; - $binaryfile['handle'] = fopen($binaryfile['name'],'r'); - $binaryfile['data'] = fread($binaryfile['handle'],filesize($binaryfile['name'])); + $binaryfile['handle'] = fopen($binaryfile['name'], 'r'); + $binaryfile['data'] = fread($binaryfile['handle'], filesize($binaryfile['name'])); fclose($binaryfile['handle']); $new_values[$index] = $binaryfile['data']; } } - if (count($new_values)) { + if (count($new_values)) + { $attribute = $this->getAttribute($attr); if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>$new_values)); - else + { + $attribute = $this->addAttribute($attr, array('values' => $new_values)); + } else + { foreach ($new_values as $value) + { $attribute->addValue($value); + } + } $attribute->justModified(); } } + } } # If there are any single item additions (from the add_attr form for example) if (isset($_REQUEST['single_item_attr'])) { if (isset($_REQUEST['single_item_value'])) { if (! is_array($_REQUEST['single_item_value'])) + { $values = array($_REQUEST['single_item_value']); + } else + { $values = $_REQUEST['single_item_value']; + } } elseif (isset($_REQUEST['binary'])) { /* Special case for binary attributes (like jpegPhoto and userCertificate): @@ -471,15 +599,19 @@ class Template extends xmlTemplate { * of the attribute. */ if ($_FILES['single_item_value']['size'] === 0) + { system_message(array( - 'title'=>_('Upload Binary Attribute Error'), - 'body'=>sprintf('%s %s',_('The file you chose is either empty or does not exist.'),_('Please go back and try again.')), - 'type'=>'warn')); + 'title' => _('Upload Binary Attribute Error'), + 'body' => sprintf('%s %s', _('The file you chose is either empty or does not exist.'), _('Please go back and try again.')), + 'type' => 'warn')); + } else { if (! is_uploaded_file($_FILES['single_item_value']['tmp_name'])) { if (isset($_FILES['single_item_value']['error'])) - switch($_FILES['single_item_value']['error']) { + { + switch ($_FILES['single_item_value']['error']) + { # No error; possible file attack! case 0: @@ -511,9 +643,12 @@ class Template extends xmlTemplate { $msg = _('Security error: The file being uploaded may be malicious.'); break; } + } else + { $msg = _('Security error: The file being uploaded may be malicious.'); + } system_message(array( 'title'=>_('Upload Binary Attribute Error'),'body'=>$msg,'type'=>'warn'),'index.php'); @@ -533,9 +668,13 @@ class Template extends xmlTemplate { $attribute = $this->getAttribute($_REQUEST['single_item_attr']); if (is_null($attribute)) - $attribute = $this->addAttribute($_REQUEST['single_item_attr'],array('values'=>$values)); + { + $attribute = $this->addAttribute($_REQUEST['single_item_attr'], array('values' => $values)); + } else + { $attribute->setValue(array_values($values)); + } $attribute->justModified(); } @@ -545,7 +684,9 @@ class Template extends xmlTemplate { if ($this->isType('default') && $this->getContext() == 'create') { # Load our schema, based on the objectclasses that may have already been defined. if (! get_request('create_base')) + { $this->rebuildTemplateAttrs(); + } # Set the RDN attribute $counter = 1; @@ -553,7 +694,9 @@ class Template extends xmlTemplate { $attribute = $this->getAttribute($value); if (! is_null($attribute)) + { $attribute->setRDN($counter++); + } else { system_message(array( @@ -574,13 +717,17 @@ class Template extends xmlTemplate { */ public function setDN($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->container)) + { system_message(array( - 'title'=>__METHOD__, - 'body'=>'CONTAINER set while setting DN', - 'type'=>'info')); + 'title' => __METHOD__, + 'body' => 'CONTAINER set while setting DN', + 'type' => 'info')); + } $this->dn = $dn; } @@ -595,21 +742,27 @@ class Template extends xmlTemplate { */ public function setRDNAttributes($rdn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Setup to work out our RDN. $rdnarray = rdn_explode($rdn); $counter = 1; foreach ($this->getAttributes(true) as $attribute) - foreach ($rdnarray as $index => $rdnattr) { - list($attr,$value) = explode('=',$rdnattr); + { + foreach ($rdnarray as $index => $rdnattr) + { + list($attr, $value) = explode('=', $rdnattr); - if (strtolower($attr) == $attribute->getName()) { + if (strtolower($attr) == $attribute->getName()) + { $attribute->setRDN($counter++); unset($rdnarray[$index]); } } + } return $rdnarray; } @@ -622,26 +775,38 @@ class Template extends xmlTemplate { */ public function getDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->dn); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->dn); + } if ($this->dn) + { return $this->dn; + } # If DN is not set, our DN will be made from our RDN and Container. elseif ($this->getRDN() && $this->getContainer()) - return sprintf('%s,%s',$this->getRDN(),$this->getContainer()); + { + return sprintf('%s,%s', $this->getRDN(), $this->getContainer()); + } # If container is not set, we're probably creating the base elseif ($this->getRDN() && get_request('create_base')) + { return $this->getRDN(); + } } public function getDNEncode($url=true) { // @todo Be nice to do all this in 1 location if ($url) - return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN())); + { + return urlencode(preg_replace('/%([0-9a-fA-F]+)/', "%25\\1", $this->getDN())); + } else - return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->getDN()); + { + return preg_replace('/%([0-9a-fA-F]+)/', "%25\\1", $this->getDN()); + } } /** @@ -652,13 +817,17 @@ class Template extends xmlTemplate { */ public function setContainer($container) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->dn)) + { system_message(array( - 'title'=>__METHOD__, - 'body'=>'DN set while setting CONTAINER', - 'type'=>'info')); + 'title' => __METHOD__, + 'body' => 'DN set while setting CONTAINER', + 'type' => 'info')); + } $this->container = $container; } @@ -670,7 +839,9 @@ class Template extends xmlTemplate { */ public function getContainer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->container); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->container); + } return $this->container; } @@ -678,9 +849,13 @@ class Template extends xmlTemplate { public function getContainerEncode($url=true) { // @todo Be nice to do all this in 1 location if ($url) - return urlencode(preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->container)); + { + return urlencode(preg_replace('/%([0-9a-fA-F]+)/', "%25\\1", $this->container)); + } else - return preg_replace('/%([0-9a-fA-F]+)/',"%25\\1",$this->container); + { + return preg_replace('/%([0-9a-fA-F]+)/', "%25\\1", $this->container); + } } /** @@ -691,7 +866,9 @@ class Template extends xmlTemplate { */ public function copy($template,$rdn,$asnew=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $rdnarray = rdn_explode($rdn); @@ -707,7 +884,9 @@ class Template extends xmlTemplate { # Mark our internal attributes. if ($sattribute->isInternal()) + { $attribute->setInternal(); + } $modified = false; foreach ($rdnarray as $index => $rdnattr) { @@ -732,7 +911,9 @@ class Template extends xmlTemplate { // @todo If this is a Jpeg Attribute, we need to mark it read only, since it cant be deleted like text attributes can if (strcasecmp(get_class($attribute),'jpegAttribute') == 0) + { $attribute->setReadOnly(); + } } # If we have any RDN values left over, there werent in the original entry and need to be added. @@ -742,15 +923,23 @@ class Template extends xmlTemplate { $attribute = $this->addAttribute($attr,array('values'=>array($value))); if (is_null($attribute)) + { debug_dump_backtrace('Attribute is null, it probably doesnt exist in the destination server?'); + } else + { $attribute->setRDN($counter++); + } } # If we are copying into a new entry, we need to discard all the "old values" if ($asnew) - foreach ($this->getAttributes(true) as $sattribute) + { + foreach ($this->getAttributes(TRUE) as $sattribute) + { $sattribute->setOldValue(array()); + } + } } /** @@ -762,13 +951,17 @@ class Template extends xmlTemplate { */ public function getAttrbyLdapType($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->attributes as $index => $attribute) { if ($attribute->getLDAPtype() == strtolower($type)) - array_push($result,$attribute->getName()); + { + array_push($result, $attribute->getName()); + } } return $result; @@ -782,12 +975,18 @@ class Template extends xmlTemplate { */ public function isAttrType($attr, $type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (in_array(strtolower($attr),$this->getAttrbyLdapType($type))) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -797,13 +996,19 @@ class Template extends xmlTemplate { */ private function getRDNObjects() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $return = array(); foreach ($this->attributes as $attribute) + { if ($attribute->isRDN()) - array_push($return,$attribute); + { + array_push($return, $attribute); + } + } masort($return,'rdn'); return $return; @@ -816,20 +1021,24 @@ class Template extends xmlTemplate { */ public function getRDNAttrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $return = array(); foreach ($this->getRDNObjects() as $attribute) { # We'll test if two RDN's have the same number (we cant test anywhere else) if (isset($return[$attribute->isRDN()]) && $this->getType() == 'creation') + { system_message(array( - 'title'=>_('RDN attribute sequence already defined'), - 'body'=>sprintf('%s %s', - sprintf(_('There is a problem in template [%s].'),$this->getName()), + 'title' => _('RDN attribute sequence already defined'), + 'body' => sprintf('%s %s', + sprintf(_('There is a problem in template [%s].'), $this->getName()), sprintf(_('RDN attribute sequence [%s] is already used by attribute [%s] and cant be used by attribute [%s] also.'), - $attribute->isRDN(),$return[$attribute->isRDN()],$attribute->getName())), - 'type'=>'error'),'index.php'); + $attribute->isRDN(), $return[$attribute->isRDN()], $attribute->getName())), + 'type' => 'error'), 'index.php'); + } $return[$attribute->isRDN()] = $attribute->getName(); } @@ -845,11 +1054,15 @@ class Template extends xmlTemplate { */ public function getRDN() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If the DN is set, then the RDN will be calculated from it. if ($this->dn) + { return get_rdn($this->dn); + } $rdn = ''; @@ -858,10 +1071,14 @@ class Template extends xmlTemplate { # If an RDN attribute has no values, return with an empty string. The calling script should handle this. if (! count($vals)) + { return ''; + } foreach ($vals as $val) - $rdn .= sprintf('%s=%s+',$attribute->getName(false),$val); + { + $rdn .= sprintf('%s=%s+', $attribute->getName(FALSE), $val); + } } # Chop the last plus sign off when returning @@ -873,7 +1090,9 @@ class Template extends xmlTemplate { */ public function getRDNAttributeName() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attr = array(); @@ -898,16 +1117,26 @@ class Template extends xmlTemplate { */ public function getContext() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->getContainer() && get_request('cmd','REQUEST') == 'copy') + { return 'copyasnew'; + } elseif ($this->getContainer() || get_request('create_base')) + { return 'create'; + } elseif ($this->getDN()) + { return 'edit'; + } else + { return 'unknown'; + } } /** @@ -917,7 +1146,9 @@ class Template extends xmlTemplate { */ public function isVisible() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->visible); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->visible); + } return $this->visible; } @@ -932,7 +1163,9 @@ class Template extends xmlTemplate { public function getRegExp() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->regexp); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->regexp); + } return $this->regexp; } @@ -942,12 +1175,18 @@ class Template extends xmlTemplate { */ public function isReadOnly() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ((($this->getContext() == 'edit') && $this->readonly) || $this->getServer()->isReadOnly()) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -958,15 +1197,21 @@ class Template extends xmlTemplate { */ public function getAttributes($optional=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($optional) + { return $this->attributes; + } $result = array(); foreach ($this->attributes as $attribute) { if (! $attribute->isRequired()) + { continue; + } array_push($result,$attribute); } @@ -979,13 +1224,19 @@ class Template extends xmlTemplate { */ public function getAttributesShown() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->attributes as $attribute) + { if ($attribute->isVisible()) - array_push($result,$attribute); + { + array_push($result, $attribute); + } + } return $result; } @@ -995,13 +1246,19 @@ class Template extends xmlTemplate { */ public function getAttributesInternal() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->attributes as $attribute) + { if ($attribute->isInternal()) - array_push($result,$attribute); + { + array_push($result, $attribute); + } + } return $result; } @@ -1013,13 +1270,19 @@ class Template extends xmlTemplate { */ public function getObjectClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attribute = $this->getAttribute('objectclass'); if ($attribute) + { return $attribute->getValues(); + } else + { return array(); + } } /** @@ -1027,7 +1290,9 @@ class Template extends xmlTemplate { */ public function getIcon() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->icon); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->icon); + } return isset($this->icon) ? sprintf('%s/%s',IMGDIR,$this->icon) : ''; } @@ -1039,7 +1304,9 @@ class Template extends xmlTemplate { */ public function getDescription() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->description); + } return $this->description; } @@ -1052,7 +1319,9 @@ class Template extends xmlTemplate { */ public function setInvalid($msg,$admin=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->invalid = true; $this->invalid_reason = $msg; @@ -1066,17 +1335,25 @@ class Template extends xmlTemplate { */ public function isInValid() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->invalid) + { return $this->invalid_reason; + } else - return false; + { + return FALSE; + } } public function isAdminDisabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->invalid_admin); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->invalid_admin); + } return $this->invalid_admin; } @@ -1089,12 +1366,16 @@ class Template extends xmlTemplate { */ private function setMinValueCount($attr,$value) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attribute = $this->getAttribute($attr); if (! is_null($attribute)) + { $attribute->setMinValueCount($value); + } } /** @@ -1105,12 +1386,16 @@ class Template extends xmlTemplate { */ private function setAttrLDAPtype($attr,$value) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attribute = $this->getAttribute($attr); if (is_null($attribute)) - $attribute = $this->addAttribute($attr,array('values'=>array())); + { + $attribute = $this->addAttribute($attr, array('values' => array())); + } $attribute->setLDAPtype($value); } @@ -1122,7 +1407,9 @@ class Template extends xmlTemplate { */ public function OnChangeAdd($origin,$value) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attribute = $this->getAttribute($origin); @@ -1130,7 +1417,9 @@ class Template extends xmlTemplate { $command = $matches[1]; $arg = $matches[2]; } else + { return; + } switch ($command) { /* @@ -1171,7 +1460,9 @@ class Template extends xmlTemplate { //print"
    ";print_r($matchall); //0 = highlevel match, 1 = attr, 2 = subst, 3 = mod
     
     				if (! isset($attribute->js['autoFill']))
    +				{
     					$attribute->js['autoFill'] = '';
    +				}
     
     				$formula = $string;
     				$formula = preg_replace('/^([^%])/','\'$1',$formula);
    @@ -1183,7 +1474,9 @@ class Template extends xmlTemplate {
     
     					# If the attribute is the same as in the XML file, then dont need to do anything.
     					if (! $sattr || ! strcasecmp($sattr->getName(),$checkattr))
    +					{
     						continue;
    +					}
     
     					$formula = preg_replace("/$checkattr/",$sattr->getName(),$formula);
     					$matchall[1][$index] = $sattr->getName();
    @@ -1199,9 +1492,13 @@ class Template extends xmlTemplate {
     					$substrarray = array();
     
     					if (! isset($varcount[$match_attr]))
    +					{
     						$varcount[$match_attr] = 0;
    +					}
     					else
    +					{
     						$varcount[$match_attr]++;
    +					}
     
     					$js_match_attr = $match_attr;
     					$match_attr = $js_match_attr.'xx'.$varcount[$match_attr];
    @@ -1288,7 +1585,9 @@ class Template extends xmlTemplate {
     	 */
     	private function rebuildTemplateAttrs() {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
     		$server = $this->getServer();
     
    @@ -1306,59 +1605,81 @@ class Template extends xmlTemplate {
     				$soc = $server->getSchemaObjectClass($oclass);
     
     				if ($soc->getType() == 'structural' && (! $inherited))
    -					array_push($this->structural_oclass,$oclass);
    +				{
    +					array_push($this->structural_oclass, $oclass);
    +				}
     
     				# Make sure our MUST attributes are marked as such for this template.
     				if ($soc->getMustAttrs())
    -					foreach ($soc->getMustAttrs() as $index => $details) {
    +				{
    +					foreach ($soc->getMustAttrs() as $index => $details)
    +					{
     						$objectclassattr = $details->getName();
     
     						# We add the 'objectClass' attribute, only if it's explicitly in the template attribute list
    -						if ((strcasecmp('objectClass',$objectclassattr) != 0) ||
    -								((strcasecmp('objectClass',$objectclassattr) == 0) && (! is_null($this->getAttribute($objectclassattr))))) {
    +						if ((strcasecmp('objectClass', $objectclassattr) != 0) ||
    +							((strcasecmp('objectClass', $objectclassattr) == 0) && ( ! is_null($this->getAttribute($objectclassattr)))))
    +						{
     
     							# Go through the aliases, and ignore any that are already defined.
    -							$ignore = false;
    +							$ignore = FALSE;
     							$sattr = $server->getSchemaAttribute($objectclassattr);
    -							foreach ($sattr->getAliases() as $alias) {
    -								if ($this->isAttrType($alias,'must')) {
    -									$ignore = true;
    +							foreach ($sattr->getAliases() as $alias)
    +							{
    +								if ($this->isAttrType($alias, 'must'))
    +								{
    +									$ignore = TRUE;
     									break;
     								}
     							}
     
     							if ($ignore)
    +							{
     								continue;
    +							}
     
    -							$this->setAttrLDAPtype($sattr->getName(),'must');
    -							$this->setMinValueCount($sattr->getName(),1);
    +							$this->setAttrLDAPtype($sattr->getName(), 'must');
    +							$this->setMinValueCount($sattr->getName(), 1);
     
     							# We need to mark the attributes as show, except for the objectclass attribute.
    -							if (strcasecmp('objectClass',$objectclassattr) != 0) {
    +							if (strcasecmp('objectClass', $objectclassattr) != 0)
    +							{
     								$attribute = $this->getAttribute($sattr->getName());
     								$attribute->show();
     							}
     						}
     
    -						if (! in_array($objectclassattr,$allattrs))
    -							array_push($allattrs,$objectclassattr);
    +						if ( ! in_array($objectclassattr, $allattrs))
    +						{
    +							array_push($allattrs, $objectclassattr);
    +						}
     					}
    +				}
     
     				if ($soc->getMayAttrs())
    -					foreach ($soc->getMayAttrs() as $index => $details) {
    +				{
    +					foreach ($soc->getMayAttrs() as $index => $details)
    +					{
     						$objectclassattr = $details->getName();
     						$sattr = $server->getSchemaAttribute($objectclassattr);
     
     						# If it is a MUST attribute, skip to the next one.
    -						if ($this->isAttrType($objectclassattr,'must'))
    +						if ($this->isAttrType($objectclassattr, 'must'))
    +						{
     							continue;
    +						}
     
    -						if (! $this->isAttrType($objectclassattr,'may'))
    -							$this->setAttrLDAPtype($sattr->getName(false),'may');
    +						if ( ! $this->isAttrType($objectclassattr, 'may'))
    +						{
    +							$this->setAttrLDAPtype($sattr->getName(FALSE), 'may');
    +						}
     
    -						if (! in_array($objectclassattr,$allattrs))
    -							array_push($allattrs,$objectclassattr);
    +						if ( ! in_array($objectclassattr, $allattrs))
    +						{
    +							array_push($allattrs, $objectclassattr);
    +						}
     					}
    +				}
     
     				# Keep a list to objectclasses we have processed, so we dont get into a loop.
     				array_push($oclass_processed,$oclass);
    @@ -1367,14 +1688,20 @@ class Template extends xmlTemplate {
     				if (count($supoclasses) || count($superclasslist)) {
     					foreach ($supoclasses as $supoclass) {
     						if (! in_array($supoclass,$oclass_processed))
    +						{
     							$superclasslist[] = $supoclass;
    +						}
     					}
     
     					$oclass = array_shift($superclasslist);
     					if ($oclass)
    -						$inherited = true;
    +					{
    +						$inherited = TRUE;
    +					}
     					else
    -						$supclass = false;
    +					{
    +						$supclass = FALSE;
    +					}
     
     				} else {
     					$supclass = false;
    @@ -1384,17 +1711,22 @@ class Template extends xmlTemplate {
     
     		# Check that attributes are defined by an ObjectClass
     		foreach ($this->getAttributes(true) as $index => $attribute)
    -			if (! in_array($attribute->getName(),$allattrs) && (! array_intersect($attribute->getAliases(),$allattrs))
    -				&& (! in_array_ignore_case('extensibleobject',$this->getObjectClasses()))
    -				&& (! in_array_ignore_case($attribute->getName(),$server->getValue('server','custom_attrs')))) {
    +		{
    +			if ( ! in_array($attribute->getName(), $allattrs) && ( ! array_intersect($attribute->getAliases(), $allattrs))
    +				&& ( ! in_array_ignore_case('extensibleobject', $this->getObjectClasses()))
    +				&& ( ! in_array_ignore_case($attribute->getName(), $server->getValue('server', 'custom_attrs'))))
    +			{
     				unset($this->attributes[$index]);
     
    -				if (! $_SESSION[APPCONFIG]->getValue('appearance','hide_template_warning'))
    +				if ( ! $_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_warning'))
    +				{
     					system_message(array(
    -						'title'=>_('Automatically removed attribute from template'),
    -						'body'=>sprintf('%s: %s %s',$this->getTitle(),$attribute->getName(false),_('removed from template as it is not defined by an ObjectClass')),
    -						'type'=>'warn'));
    +						'title' => _('Automatically removed attribute from template'),
    +						'body' => sprintf('%s: %s %s', $this->getTitle(), $attribute->getName(FALSE), _('removed from template as it is not defined by an ObjectClass')),
    +						'type' => 'warn'));
    +				}
     			}
    +		}
     	}
     
     	/**
    @@ -1405,26 +1737,37 @@ class Template extends xmlTemplate {
     	 */
     	public function getLDAPadd($attrsOnly=false) {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
     		$return = array();
     		$returnattrs = array();
     
     		if ($attrsOnly && count($returnattrs))
    +		{
     			return $returnattrs;
    +		}
     
     		foreach ($this->getAttributes(true) as $attribute)
    -			if (! $attribute->isInternal() && count($attribute->getValues())) {
    +		{
    +			if ( ! $attribute->isInternal() && count($attribute->getValues()))
    +			{
     				$return[$attribute->getName()] = $attribute->getValues();
     				$returnattrs[$attribute->getName()] = $attribute;
     			}
    +		}
     
     		# Ensure that our objectclasses has "top".
     		if (isset($return['objectclass']) && ! in_array('top',$return['objectclass']))
    -			array_push($return['objectclass'],'top');
    +		{
    +			array_push($return['objectclass'], 'top');
    +		}
     
     		if ($attrsOnly)
    +		{
     			return $returnattrs;
    +		}
     
     		return $return;
     	}
    @@ -1442,13 +1785,17 @@ class Template extends xmlTemplate {
     	 */
     	public function getLDAPmodify($attrsOnly=false,$index=0) {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
     		static $return = array();
     		static $returnattrs = array();
     
     		if ($attrsOnly && isset($returnattrs[$index]) && count($returnattrs[$index]))
    +		{
     			return $returnattrs[$index];
    +		}
     
     		$returnattrs[$index] = array();
     		$return[$index] = array();
    @@ -1465,21 +1812,33 @@ class Template extends xmlTemplate {
     
     				if ($soc) {
     					if ($soc->isStructural())
    -						$haveStructural = true;
    +					{
    +						$haveStructural = TRUE;
    +					}
     
     					# While we are looping, workout which attributes these objectclasses define.
     					foreach ($soc->getMustAttrs(true) as $value)
    -						if (! in_array($value->getName(),$attr_to_keep))
    -							array_push($attr_to_keep,$value->getName());
    +					{
    +						if ( ! in_array($value->getName(), $attr_to_keep))
    +						{
    +							array_push($attr_to_keep, $value->getName());
    +						}
    +					}
     
     					foreach ($soc->getMayAttrs(true) as $value)
    -						if (! in_array($value->getName(),$attr_to_keep))
    -							array_push($attr_to_keep,$value->getName());
    +					{
    +						if ( ! in_array($value->getName(), $attr_to_keep))
    +						{
    +							array_push($attr_to_keep, $value->getName());
    +						}
    +					}
     				}
     			}
     
     			if (! $haveStructural)
    -				error(_('An entry should have one structural objectClass.'),'error','index.php');
    +			{
    +				error(_('An entry should have one structural objectClass.'), 'error', 'index.php');
    +			}
     
     			# Work out the attributes to delete.
     			foreach ($this->getAttribute('objectclass')->getRemovedValues() as $value) {
    @@ -1490,29 +1849,41 @@ class Template extends xmlTemplate {
     
     					if ($attribute && (! in_array($value->getName(),$attr_to_keep)) && ($value->getName() != 'objectclass'))
     						#array_push($attr_to_delete,$value->getName(false));
    +					{
     						$attribute->setForceDelete();
    +					}
     				}
     
     				foreach ($soc->getMayAttrs() as $value) {
     					$attribute = $this->getAttribute($value->getName());
     
     					if ($attribute && (! in_array($value->getName(),$attr_to_keep)) && ($value->getName() != 'objectclass'))
    +					{
     						$attribute->setForceDelete();
    +					}
     				}
     			}
     		}
     
     		foreach ($this->getAttributes(true) as $attribute)
    +		{
     			if ($attribute->hasBeenModified()
    -				&& (count(array_diff($attribute->getValues(),$attribute->getOldValues())) || ! count($attribute->getValues())
    +				&& (count(array_diff($attribute->getValues(), $attribute->getOldValues())) || ! count($attribute->getValues())
     					|| $attribute->isForceDelete() || (count($attribute->getValues()) != count($attribute->getOldValues()))))
    +			{
     				$returnattrs[$index][$attribute->getName()] = $attribute;
    +			}
    +		}
     
     		if ($attrsOnly)
    +		{
     			return $returnattrs[$index];
    +		}
     
     		foreach ($returnattrs[$index] as $attribute)
    +		{
     			$return[$index][$attribute->getName()] = $attribute->getValues();
    +		}
     
     		return $return[$index];
     	}
    @@ -1523,16 +1894,24 @@ class Template extends xmlTemplate {
     	 */
     	public function getForceDeleteAttrs() {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
     		static $result = array();
     
     		if (count($result))
    +		{
     			return $result;
    +		}
     
     		foreach ($this->attributes as $attribute)
    +		{
     			if ($attribute->isForceDelete())
    -				array_push($result,$attribute);
    +			{
    +				array_push($result, $attribute);
    +			}
    +		}
     
     		return $result;
     	}
    @@ -1542,7 +1921,9 @@ class Template extends xmlTemplate {
     	 */
     	public function getAvailAttrs() {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
     		$attributes = array();
     		$server = $this->getServer();
    @@ -1566,10 +1947,13 @@ class Template extends xmlTemplate {
     			}
     
     			foreach ($attrs as $attr)
    -				if (is_null($this->getAttribute($attr))) {
    -					$attribute = $attribute_factory->newAttribute($attr,array('values'=>array()),$server->getIndex(),null);
    -					array_push($attributes,$attribute);
    +			{
    +				if (is_null($this->getAttribute($attr)))
    +				{
    +					$attribute = $attribute_factory->newAttribute($attr, array('values' => array()), $server->getIndex(), NULL);
    +					array_push($attributes, $attribute);
     				}
    +			}
     		}
     
     		masort($attributes,'name');
    diff --git a/lib/TemplateRender.php b/lib/TemplateRender.php
    index 90883e3..8332266 100644
    --- a/lib/TemplateRender.php
    +++ b/lib/TemplateRender.php
    @@ -24,34 +24,52 @@ class TemplateRender extends PageRender {
     	 */
     	public function accept($norender=false) {
     		if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS'))
    -			debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs);
    +		{
    +			debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    +		}
     
    -		if (DEBUGTMP) printf('%s:%s
    ',time(),__METHOD__); - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Visit-Start:%s]
    ',__METHOD__,get_class($this)); + if (DEBUGTMP) + { + printf('%s:%s
    ', time(), __METHOD__); + } + if (DEBUGTMP||DEBUGTMPSUB) + { + printf('* %s [Visit-Start:%s]
    ', __METHOD__, get_class($this)); + } $tree = get_cached_item($this->server_id,'tree'); if (! $tree) + { $tree = Tree::getInstance($this->server_id); + } $treeitem = $tree->getEntry($this->dn); # If we have a DN, and no template_id, see if the tree has one from last time if ($this->dn && is_null($this->template_id) && $treeitem && $treeitem->getTemplate()) + { $this->template_id = $treeitem->getTemplate(); + } # Check that we have a valid template, or present a selection # @todo change this so that the modification templates rendered are the ones for the objectclass of the dn. if (! $this->template_id) + { $this->template_id = $this->getTemplateChoice(); + } if ($treeitem) + { $treeitem->setTemplate($this->template_id); + } $this->page = get_request('page','REQUEST',false,1); if ($this->template_id AND $this->template_id != 'invalid') { if (! $this->template) + { parent::accept(); + } $this->url_base = sprintf('server_id=%s&dn=%s', $this->getServerID(),$this->template->getDNEncode()); @@ -62,25 +80,34 @@ class TemplateRender extends PageRender { # If we dont want to render this template automatically, we'll return here. if ($norender) + { return; + } $this->visitStart(); foreach ($this->template->getAttributes(true) as $attribute) { # Evaluate our defaults if ($attribute->getAutoValue()) - $this->get('Default',$attribute, + { + $this->get('Default', $attribute, $this->template->getContainer() ? $this->template->getContainer() : $this->getServer()->getContainerPath($this->template->getDN()), 'autovalue'); + } # If this is the default template, we should mark all our attributes to show(). if (($this->template->getID() == 'none') && (! $attribute->isInternal()) && (($this->template->getContext() == 'edit' && $this->template->getID() == 'none') || ($this->template->getContext() == 'create' && $attribute->getName() != 'objectclass'))) + { $attribute->show(); + } } - if (DEBUGTMP||DEBUGTMPSUB) printf('* %s [Visit-End:%s]
    ',__METHOD__,get_class($this)); + if (DEBUGTMP||DEBUGTMPSUB) + { + printf('* %s [Visit-End:%s]
    ', __METHOD__, get_class($this)); + } $this->visitEnd(); } @@ -88,7 +115,9 @@ class TemplateRender extends PageRender { protected function getDefaultAttribute($attribute,$container,$type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } switch ($type) { case 'autovalue': @@ -143,13 +172,17 @@ class TemplateRender extends PageRender { $function_args = explode(',',$args[0]); if (function_exists($function)) - $vals = call_user_func_array($function,$function_args); + { + $vals = call_user_func_array($function, $function_args); + } else + { system_message(array( - 'title'=>_('Function doesnt exist'), - 'body'=>sprintf('%s (%s)',_('An attempt was made to call a function that doesnt exist'),$function), - 'type'=>'warn')); + 'title' => _('Function doesnt exist'), + 'body' => sprintf('%s (%s)', _('An attempt was made to call a function that doesnt exist'), $function), + 'type' => 'warn')); + } break; @@ -183,10 +216,14 @@ class TemplateRender extends PageRender { case 'GetNextNumber': # If the attribute already has values, we'll return if ($type == 'autovalue' && $attribute->getValues()) + { return; + } if ($args[0] == '$') - $args[0] = $server->getValue($this->server_id,'auto_number','search_base'); + { + $args[0] = $server->getValue($this->server_id, 'auto_number', 'search_base'); + } $container = $server->getContainerPath($container,$args[0]); @@ -206,19 +243,19 @@ class TemplateRender extends PageRender { switch ($operand) { case '*': - $next_number = $next_number * $operator; + $next_number *= $operator; break; case '+': - $next_number = $next_number + $operator; + $next_number += $operator; break; case '-': - $next_number = $next_number - $operator; + $next_number -= $operator; break; case '/': - $next_number = $next_number / $operator; + $next_number /= $operator; break; } } @@ -270,9 +307,13 @@ class TemplateRender extends PageRender { case 'PickList': # arg5 overrides our container if (empty($args[5])) - $container = $server->getContainerPath($container,$args[0]); + { + $container = $server->getContainerPath($container, $args[0]); + } else + { $container = $args[5]; + } # Process filter (arg 1), eventually replace %attr% by it's value set in a previous page. preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[1],$filtermatchall); @@ -288,7 +329,9 @@ class TemplateRender extends PageRender { } if (empty($args[3])) + { $args[3] = "%{$args[2]}%"; + } preg_match_all('/%(\w+)(\|.+)?(\/[lUC])?%/U',$args[3],$matchall); //print_r($matchall); // -1 = highlevel match, 1 = attr, 2 = subst, 3 = mod @@ -309,7 +352,9 @@ class TemplateRender extends PageRender { foreach ($fixedvalues as $fixedvalue) { if (empty($fixedvalue)) + { continue; + } $fixedvalue = preg_split('/=\>/',$fixedvalue); $displayvalue = explode('=',$fixedvalue[1]); @@ -327,45 +372,63 @@ class TemplateRender extends PageRender { foreach ($matchall[1] as $key => $arg) { if (isset($values[$arg])) + { $disp_val = $values[$arg]; + } else + { $disp_val = ''; + } if (is_array($disp_val)) + { $disp_val = $disp_val[0]; + } if ($matchall[3][$key]) - switch ($matchall[3][$key]) { + { + switch ($matchall[3][$key]) + { case '/l': - # lowercase + # lowercase if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_LOWER,'utf-8'); - else + { + $disp_val = mb_convert_case($disp_val, MB_CASE_LOWER, 'utf-8'); + } else + { $disp_val = strtolower($disp_val); + } break; case '/U': - # uppercase + # uppercase if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_UPPER,'utf-8'); - else + { + $disp_val = mb_convert_case($disp_val, MB_CASE_UPPER, 'utf-8'); + } else + { $disp_val = strtoupper($disp_val); + } - break; + break; case '/C': - # capitalize + # capitalize if (function_exists('mb_convert_case')) - $disp_val = mb_convert_case($disp_val,MB_CASE_TITLE,'utf-8'); - else + { + $disp_val = mb_convert_case($disp_val, MB_CASE_TITLE, 'utf-8'); + } else + { $disp_val = ucfirst($disp_val); + } break; default: break; } + } # make value a substring of preg_match_all('/^\|([0-9]*)-([0-9]*)$/',trim($matchall[2][$key]),$substrarray); @@ -375,9 +438,13 @@ class TemplateRender extends PageRender { $end = $substrarray[2][0] ? $substrarray[2][0] : strlen($disp_val); if (function_exists('mb_substr')) - $disp_val = mb_substr($disp_val,$begin,$end,'utf-8'); + { + $disp_val = mb_substr($disp_val, $begin, $end, 'utf-8'); + } else - $disp_val = substr($disp_val,$begin,$end); + { + $disp_val = substr($disp_val, $begin, $end); + } } $display = preg_replace("/%($arg)(\|.+)?(\/[lUC])?%/U",$disp_val,$display); @@ -417,9 +484,13 @@ class TemplateRender extends PageRender { switch ($type) { case 'autovalue': if (! is_array($vals)) + { $attribute->autoValue(array($vals)); + } else + { $attribute->autoValue($vals); + } break; @@ -434,16 +505,26 @@ class TemplateRender extends PageRender { */ protected function getMode() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->dn) + { return 'modification'; + } elseif ($this->container) + { return 'creation'; + } elseif (get_request('create_base')) + { return 'creation'; + } else - debug_dump_backtrace(sprintf('Unknown mode for %s',__METHOD__),1); + { + debug_dump_backtrace(sprintf('Unknown mode for %s', __METHOD__), 1); + } } /** @@ -451,7 +532,9 @@ class TemplateRender extends PageRender { */ protected function getModeContainer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } switch ($this->getMode()) { case 'creation': @@ -472,19 +555,28 @@ class TemplateRender extends PageRender { */ protected function haveDefaultTemplate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($_SESSION[APPCONFIG]->getValue('appearance','disable_default_template')) - return false; + { + return FALSE; + } else - return true; + { + return TRUE; + } } /** * Present a list of available templates for creating and editing LDAP entries */ protected function drawTemplateChoice() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $this->drawTitle(); $this->drawSubTitle(); @@ -511,7 +603,9 @@ class TemplateRender extends PageRender { if (count($_POST)) { echo '
    '; foreach ($_POST as $p => $v) - printf('',$p,$v); + { + printf('', $p, $v); + } echo '
    '; echo "\n\n"; } @@ -526,7 +620,9 @@ class TemplateRender extends PageRender { $nb_templates = count($templates); if ($this->haveDefaultTemplate()) + { $nb_templates++; + } foreach ($templates as $name => $details) { $i++; @@ -543,15 +639,21 @@ class TemplateRender extends PageRender { echo '
    '; if ($isInValid) - printf('',IMGDIR); + { + printf('', IMGDIR); + } else { if (isAjaxEnabled()) + { printf('', - htmlspecialchars($details->getID()),htmlspecialchars($details->getID()),htmlspecialchars($href_parms),$details->getID(),str_replace('\'','\\\'',_('Retrieving DN'))); + htmlspecialchars($details->getID()), htmlspecialchars($details->getID()), htmlspecialchars($href_parms), $details->getID(), str_replace('\'', '\\\'', _('Retrieving DN'))); + } else + { printf('', - htmlspecialchars($details->getID()),htmlspecialchars($details->getID())); + htmlspecialchars($details->getID()), htmlspecialchars($details->getID())); + } } printf('', @@ -560,12 +662,16 @@ class TemplateRender extends PageRender { htmlspecialchars($details->getID())); if ($isInValid) - printf('',htmlspecialchars($details->getID()),_($isInValid)); + { + printf('', htmlspecialchars($details->getID()), _($isInValid)); + } echo _($details->getTitle()); if ($isInValid) + { echo ''; + } echo ''; echo ''; @@ -584,10 +690,14 @@ class TemplateRender extends PageRender { echo ''; if (isAjaxEnabled()) + { printf('', - htmlspecialchars($href_parms),'none',str_replace('\'','\\\'',_('Retrieving DN'))); + htmlspecialchars($href_parms), 'none', str_replace('\'', '\\\'', _('Retrieving DN'))); + } else + { echo ''; + } printf('',IMGDIR); printf('',_('Default')); @@ -609,20 +719,31 @@ class TemplateRender extends PageRender { */ private function visitStart() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # If we have a DN, then we are an editing template if ($this->dn) + { $this->template->setDN($this->dn); + } # Else if we have a container, we are a creating template elseif ($this->container || get_request('create_base')) + { $this->template->setContainer($this->container); + } else - debug_dump_backtrace('Dont know what type of template we are - no DN or CONTAINER?',1); + { + debug_dump_backtrace('Dont know what type of template we are - no DN or CONTAINER?', 1); + } # Header $this->drawHeader(); @@ -630,13 +751,22 @@ class TemplateRender extends PageRender { private function visitEnd() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } foreach ($this->template->getAttributesShown() as $attribute) + { if ($attribute->getPage() > $this->pagelast) + { $this->pagelast = $attribute->getPage(); + } + } echo "\n\n"; if ($this->template->getContext() == 'create') { @@ -676,14 +806,21 @@ class TemplateRender extends PageRender { /** PAGE DRAWING METHODS **/ private function drawHeader() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Title $this->drawTitle(); if (get_request('create_base')) - $this->drawSubTitle(sprintf('%s: %s',_('Creating Base DN'),$this->template->getDN())); + { + $this->drawSubTitle(sprintf('%s: %s', _('Creating Base DN'), $this->template->getDN())); + } else + { $this->drawSubTitle(); + } echo "\n"; # Menu @@ -691,10 +828,15 @@ class TemplateRender extends PageRender { } public function drawTitle($title=null) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (is_null($title)) - switch ($this->getMode()) { + { + switch ($this->getMode()) + { case 'creation': $title = _('Create Object'); break; @@ -706,15 +848,21 @@ class TemplateRender extends PageRender { default: $title = 'Title'; } + } parent::drawTitle($title); } public function drawSubTitle($subtitle=null) { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if ($subtitle) + { return parent::drawSubTitle($subtitle); + } switch ($this->getMode()) { case 'creation': @@ -726,7 +874,9 @@ class TemplateRender extends PageRender { $subtitle .= '
    '; $subtitle .= sprintf('%s: %s',_('Template'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); + { + $subtitle .= sprintf(' (%s)', $this->template->getName(FALSE)); + } } break; @@ -740,7 +890,9 @@ class TemplateRender extends PageRender { $subtitle .= '
    '; $subtitle .= sprintf('%s: %s',_('Template'),$this->template->getID() != 'none' ? $this->template->getTitle() : _('Default')); if ($this->template->getName()) - $subtitle .= sprintf(' (%s)',$this->template->getName(false)); + { + $subtitle .= sprintf(' (%s)', $this->template->getName(FALSE)); + } } break; @@ -752,7 +904,10 @@ class TemplateRender extends PageRender { /** PAGE ENTRY MENU **/ private function drawMenu() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # We only have a menu for editing entries. if ($this->template->getContext() == 'edit') { @@ -774,7 +929,9 @@ class TemplateRender extends PageRender { $it = $item[0]; if (count($item) > 1) + { $ms = $item[1]; + } } else { $it = $item; @@ -793,9 +950,13 @@ class TemplateRender extends PageRender { } if ($endofrow) + { print $ms; + } else + { echo "$ms"; + } echo ''; $endofrow = true; @@ -818,9 +979,13 @@ class TemplateRender extends PageRender { } if ($endofrow || $start) + { print $ms; + } else + { echo "$ms"; + } echo ''; $endofrow = true; @@ -832,9 +997,13 @@ class TemplateRender extends PageRender { } if (($menuitem_number % 2) == 1) + { echo ''; + } else + { echo ''; + } echo ''; echo '
    '; + } $found = false; $empty_value = false; # 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(false)), - 'type'=>'warn')); + '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(FALSE)), + 'type' => 'warn')); + } printf('
    '; echo ''; echo '
     icon'; $this->draw('CurrentValues',$afattrs[$attr]); @@ -409,7 +459,9 @@ class QueryRender extends PageRender { printf('',2+count(explode(',',$ado))); foreach ($mass_actions as $display => $action) - printf('  ',$action,$display); + { + printf('  ', $action, $display); + } echo '
    %s
    DisabledDisabled
          
    '; @@ -848,46 +1017,75 @@ class TemplateRender extends PageRender { private function getMenuItem($i) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s (%s)
    ',__METHOD__,$i); + if (DEBUGTMP) + { + printf('%s (%s)
    ', __METHOD__, $i); + } switch ($i) { case 'entryrefresh': if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_refresh')) + { return $this->getMenuItemRefresh(); + } else + { return ''; + } case 'switchtemplate': if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','switch_template')) + { return $this->getMenuItemSwitchTemplate(); + } else + { return ''; + } case 'entryexport': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) + { return $this->getMenuItemExportBase(); + } else + { return ''; + } case 'entrycopy': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','copy_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','copy') && ! $this->template->isReadOnly()) + { return $this->getMenuItemMove(); + } else + { return ''; + } case 'showinternal': if ($_SESSION[APPCONFIG]->isCommandAvailable('cmd','entry_internal_attributes_show')) + { return $this->getMenuItemInternalAttributes(); + } else + { return ''; + } case 'entrydelete': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) + { return $this->getMenuItemDelete(); + } else + { return ''; + } case 'entryrename': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','rename_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','rename') && ! $this->template->isReadOnly()) { @@ -904,7 +1102,9 @@ class TemplateRender extends PageRender { } if (! $rdnro) + { return $this->getMenuItemRename(); + } } return ''; @@ -912,27 +1112,43 @@ class TemplateRender extends PageRender { case 'msgdel': if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','delete') && ! $this->template->isReadOnly()) - return array('',$this->getDeleteAttributeMessage()); + { + return array('', $this->getDeleteAttributeMessage()); + } else + { return ''; + } case 'entrycompare': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','compare_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','compare') && ! $this->template->isReadOnly()) + { return $this->getMenuItemCompare(); + } else + { return ''; + } case 'childcreate': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','create') && ! $this->template->isReadOnly() && ! $this->template->isNoLeaf()) + { return $this->getMenuItemCreate(); + } else + { return ''; + } case 'addattr': if ($_SESSION[APPCONFIG]->isCommandAvailable('script','add_attr_form') && ! $this->template->isReadOnly()) + { return $this->getMenuItemAddAttribute(); + } else + { return ''; + } case 'childview': case 'childexport': @@ -964,44 +1180,72 @@ class TemplateRender extends PageRender { if ($children_count > 0 || $more_children) { if ($children_count <= 0) + { $children_count = ''; + } if ($more_children) + { $children_count .= '+'; + } if ($i == 'childview') + { return $this->getMenuItemShowChildren($children_count); + } elseif ($i == 'childexport' && $_SESSION[APPCONFIG]->isCommandAvailable('script','export_form') && $_SESSION[APPCONFIG]->isCommandAvailable('script','export')) + { return $this->getMenuItemExportSub(); + } else + { return ''; + } } else + { return ''; + } case 'msgschema': if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints') && $_SESSION[APPCONFIG]->isCommandAvailable('script','schema')) - return array('',$this->getViewSchemaMessage()); + { + return array('', $this->getViewSchemaMessage()); + } else + { return array(); + } case 'msgro': if ($this->template->isReadOnly()) - return array('',$this->getReadOnlyMessage()); + { + return array('', $this->getReadOnlyMessage()); + } else + { return array(); + } case 'msgmodattr': $modified_attrs = array(); $modified = get_request('modified_attrs','REQUEST',false,array()); foreach ($this->template->getAttributes(true) as $attribute) - if (in_array($attribute->getName(),$modified)) - array_push($modified_attrs,$attribute->getFriendlyName()); + { + if (in_array($attribute->getName(), $modified)) + { + array_push($modified_attrs, $attribute->getFriendlyName()); + } + } if (count($modified_attrs)) - return array('',$this->getModifiedAttributesMessage($modified_attrs)); + { + return array('', $this->getModifiedAttributesMessage($modified_attrs)); + } else + { return array(); + } default: return false; @@ -1010,21 +1254,35 @@ class TemplateRender extends PageRender { protected function getDeleteAttributeMessage() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if ($_SESSION[APPCONFIG]->isCommandAvailable('script','delete_attr') && ! $this->template->isReadOnly()) - return sprintf($this->layout['hint'],_('Hint: To delete an attribute, empty the text field and click save.')); + { + return sprintf($this->layout['hint'], _('Hint: To delete an attribute, empty the text field and click save.')); + } else + { return ''; + } } protected function getModifiedAttributesMessage(&$modified_attributes) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } return sprintf($this->layout['hint'], (count($modified_attributes) == 1) ? @@ -1034,18 +1292,28 @@ class TemplateRender extends PageRender { protected function getReadOnlyMessage() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } return sprintf($this->layout['hint'],_('Viewing entry in read-only mode.')); } protected function getViewSchemaMessage() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } return sprintf($this->layout['hint'],_('Hint: To view the schema for an attribute, click the attribute name.')); } @@ -1054,73 +1322,111 @@ class TemplateRender extends PageRender { private function getMenuItemRefresh() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=template_engine&%s&junk=%s',$this->url_base,random_junk()); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'refresh.png',_('Refresh'), - htmlspecialchars($href),_('Refresh this entry'),htmlspecialchars($href),str_replace('\'','\\\'',_('Reloading')),_('Refresh')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'refresh.png', _('Refresh'), + htmlspecialchars($href), _('Refresh this entry'), htmlspecialchars($href), str_replace('\'', '\\\'', _('Reloading')), _('Refresh')); + } else - return sprintf($this->layout['action'],IMGDIR,'refresh.png',_('Refresh'), - htmlspecialchars($href),_('Refresh this entry'),_('Refresh')); + { + return sprintf($this->layout['action'], IMGDIR, 'refresh.png', _('Refresh'), + htmlspecialchars($href), _('Refresh this entry'), _('Refresh')); + } } protected function getMenuItemSwitchTemplate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $href = sprintf('cmd=template_engine&%s&template=',$this->url_base); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'switch.png',_('Switch Template'), - htmlspecialchars($href),_('Change to another template'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Switch Template')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'switch.png', _('Switch Template'), + htmlspecialchars($href), _('Change to another template'), htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Switch Template')); + } else - return sprintf($this->layout['action'],IMGDIR,'switch.png',_('Switch Template'), - htmlspecialchars($href),_('Change to another template'),_('Switch Template')); + { + return sprintf($this->layout['action'], IMGDIR, 'switch.png', _('Switch Template'), + htmlspecialchars($href), _('Change to another template'), _('Switch Template')); + } } protected function getMenuItemExportBase() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=export_form&%s&scope=base',$this->url_base); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'export.png',_('Export'), - htmlspecialchars($href),_('Save a dump of this object'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Export')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'export.png', _('Export'), + htmlspecialchars($href), _('Save a dump of this object'), htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Export')); + } else - return sprintf($this->layout['action'],IMGDIR,'export.png',_('Export'), - htmlspecialchars($href),_('Save a dump of this object'),_('Export')); + { + return sprintf($this->layout['action'], IMGDIR, 'export.png', _('Export'), + htmlspecialchars($href), _('Save a dump of this object'), _('Export')); + } } private function getMenuItemMove() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=copy_form&%s',$this->url_base); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'cut.png',_('Cut'), - htmlspecialchars($href),_('Copy this object to another location, a new DN, or another server'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Copy or move this entry')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'cut.png', _('Cut'), + htmlspecialchars($href), _('Copy this object to another location, a new DN, or another server'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Copy or move this entry')); + } else - return sprintf($this->layout['action'],IMGDIR,'cut.png',_('Cut'), - htmlspecialchars($href),_('Copy this object to another location, a new DN, or another server'), + { + return sprintf($this->layout['action'], 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 getMenuItemInternalAttributes() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (get_request('show_internal_attrs','REQUEST')) { $href = sprintf('cmd=template_engine&%s&junk=',$this->url_base,random_junk()); @@ -1138,127 +1444,192 @@ class TemplateRender extends PageRender { private function getMenuItemDelete() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=delete_form&%s',$this->url_base); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'trash.png',_('Trash'), - htmlspecialchars($href),_('You will be prompted to confirm this decision'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Delete this entry')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'trash.png', _('Trash'), + htmlspecialchars($href), _('You will be prompted to confirm this decision'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Delete this entry')); + } else - return sprintf($this->layout['action'],IMGDIR,'trash.png',_('Trash'), - htmlspecialchars($href),_('You will be prompted to confirm this decision'),_('Delete this entry')); + { + return sprintf($this->layout['action'], IMGDIR, 'trash.png', _('Trash'), + htmlspecialchars($href), _('You will be prompted to confirm this decision'), _('Delete this entry')); + } } protected function getMenuItemRename() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=rename_form&%s&template=%s',$this->url_base,$this->template->getID()); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'rename.png',_('Rename'), - htmlspecialchars($href),_('Rename this entry'),htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Rename')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'rename.png', _('Rename'), + htmlspecialchars($href), _('Rename this entry'), htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Rename')); + } else - return sprintf($this->layout['action'],IMGDIR,'rename.png',_('Rename'), - htmlspecialchars($href),_('Rename this entry'),_('Rename')); + { + return sprintf($this->layout['action'], IMGDIR, 'rename.png', _('Rename'), + htmlspecialchars($href), _('Rename this entry'), _('Rename')); + } } protected function getMenuItemCompare() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=compare_form&%s',$this->url_base); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'compare.png',_('Compare'), - htmlspecialchars($href),_('Compare this entry with another'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Compare with another entry')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'compare.png', _('Compare'), + htmlspecialchars($href), _('Compare this entry with another'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Compare with another entry')); + } else - return sprintf($this->layout['action'],IMGDIR,'compare.png',_('Compare'), - htmlspecialchars($href),_('Compare this entry with another'),_('Compare with another entry')); + { + return sprintf($this->layout['action'], IMGDIR, 'compare.png', _('Compare'), + htmlspecialchars($href), _('Compare this entry with another'), _('Compare with another entry')); + } } protected function getMenuItemCreate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $href = sprintf('cmd=template_engine&server_id=%s&container=%s',$this->getServerID(),$this->template->getDNEncode()); if (isAjaxEnabled()) - return sprintf($this->layout['actionajax'],IMGDIR,'create.png',_('Create'), - htmlspecialchars($href),_('Create a child entry'), - htmlspecialchars($href),str_replace('\'','\\\'',_('Loading')),_('Create a child entry')); + { + return sprintf($this->layout['actionajax'], IMGDIR, 'create.png', _('Create'), + htmlspecialchars($href), _('Create a child entry'), + htmlspecialchars($href), str_replace('\'', '\\\'', _('Loading')), _('Create a child entry')); + } else - return sprintf($this->layout['action'],IMGDIR,'create.png',_('Create'), - htmlspecialchars($href),_('Create a child entry'),_('Create a child entry')); + { + return sprintf($this->layout['action'], IMGDIR, 'create.png', _('Create'), + htmlspecialchars($href), _('Create a child entry'), _('Create a child entry')); + } } protected function getMenuItemAddAttribute() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (! $this->template->getAvailAttrs()) + { return ''; + } $href = sprintf('cmd=add_attr_form&%s',$this->url_base); $layout = '
    %s%s
    %s
    '; foreach ($this->template->getRDNAttrs() as $rdn) - printf('',htmlspecialchars($rdn)); + { + printf('', htmlspecialchars($rdn)); + } if (get_request('create_base')) + { echo ''; + } echo '
    %s'; if (get_request('create_base')) - printf('%s',$default_container,htmlspecialchars($default_container)); + { + printf('%s', $default_container, htmlspecialchars($default_container)); + } else { printf('',htmlspecialchars($default_container)); draw_chooser_link('entry_form','container'); @@ -1328,11 +1715,16 @@ class TemplateRender extends PageRender { * Object Class Chooser */ protected function drawObjectClassChooser() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } $socs = $this->getServer()->SchemaObjectClasses(); if (! $socs) + { $socs = array(); + } echo '
    %s
    (%s)
    (%s)
    '; @@ -1412,7 +1824,10 @@ class TemplateRender extends PageRender { } public function drawFormEnd() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } # Include the RDN details to support creating the base if (get_request('create_base')) { @@ -1446,12 +1861,17 @@ class TemplateRender extends PageRender { } public function drawFormSubmitButton() { - if (DEBUGTMP) printf('%s
    ',__METHOD__); + if (DEBUGTMP) + { + printf('%s
    ', __METHOD__); + } if (! $this->template->isReadOnly()) // @todo cant use AJAX here, it affects file uploads. + { printf('
      
    %s
    (%s)
    (%s)
    %s
    (%s)
    (%s)
    '; @@ -688,12 +787,14 @@ function get_request($attr,$type='POST',$die=false,$default=null) { } if ($die && is_null($value)) + { system_message(array( - 'title'=>_('Generic Error'), - 'body'=>sprintf('%s: Called "%s" without "%s" using "%s"', - basename($_SERVER['PHP_SELF']),get_request('cmd','REQUEST'),$attr,$type), - 'type'=>'error'), + 'title' => _('Generic Error'), + 'body' => sprintf('%s: Called "%s" without "%s" using "%s"', + basename($_SERVER['PHP_SELF']), get_request('cmd', 'REQUEST'), $attr, $type), + 'type' => 'error'), 'index.php'); + } return $value; } @@ -707,16 +808,24 @@ function get_request($attr,$type='POST',$die=false,$default=null) { */ function system_message($msg,$redirect=null) { if (! is_array($msg)) - return null; + { + return NULL; + } if (! isset($msg['title']) && ! isset($msg['body'])) - return null; + { + return NULL; + } if (! isset($msg['type'])) + { $msg['type'] = 'info'; + } if (! isset($_SESSION['sysmsg']) || ! is_array($_SESSION['sysmsg'])) + { $_SESSION['sysmsg'] = array(); + } # Try and detect if we are in a redirect loop if (get_request('redirect','GET') && $msg['type'] != 'debug') { @@ -732,14 +841,20 @@ function system_message($msg,$redirect=null) { if ($redirect) { if (preg_match('/\?/',$redirect)) + { $redirect .= '&'; + } else + { $redirect .= '?'; + } $redirect .= 'redirect=true'; # Check if we were an ajax request, and only render the ajax message if (get_request('meth','REQUEST') == 'ajax') + { $redirect .= '&meth=ajax'; + } header("Location: $redirect"); die(); @@ -760,15 +875,21 @@ function system_message($msg,$redirect=null) { */ function blowfish_encrypt($data,$secret=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If our secret is null or blank, get the default. if ($secret === null || ! trim($secret)) - $secret = $_SESSION[APPCONFIG]->getValue('session','blowfish') ? $_SESSION[APPCONFIG]->getValue('session','blowfish') : session_id(); + { + $secret = $_SESSION[APPCONFIG]->getValue('session', 'blowfish') ? $_SESSION[APPCONFIG]->getValue('session', 'blowfish') : session_id(); + } # If the secret isnt set, then just return the data. if (! trim($secret)) + { return $data; + } if (function_exists('mcrypt_module_open') && ! empty($data)) { $td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,''); @@ -781,9 +902,13 @@ function blowfish_encrypt($data,$secret=null) { } if (file_exists(LIBDIR.'blowfish.php')) - require_once LIBDIR.'blowfish.php'; + { + require_once LIBDIR . 'blowfish.php'; + } else + { return $data; + } $pma_cipher = new Horde_Cipher_blowfish; $encrypt = ''; @@ -792,7 +917,9 @@ function blowfish_encrypt($data,$secret=null) { $block = substr($data, $i, 8); if (strlen($block) < 8) - $block = full_str_pad($block,8,"\0", 1); + { + $block = full_str_pad($block, 8, "\0", 1); + } $encrypt .= $pma_cipher->encryptBlock($block, $secret); } @@ -810,21 +937,29 @@ function blowfish_encrypt($data,$secret=null) { */ function blowfish_decrypt($encdata,$secret=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # This cache gives major speed up for stupid callers :) static $CACHE = array(); if (isset($CACHE[$encdata])) + { return $CACHE[$encdata]; + } # If our secret is null or blank, get the default. if ($secret === null || ! trim($secret)) - $secret = $_SESSION[APPCONFIG]->getValue('session','blowfish') ? $_SESSION[APPCONFIG]->getValue('session','blowfish') : session_id(); + { + $secret = $_SESSION[APPCONFIG]->getValue('session', 'blowfish') ? $_SESSION[APPCONFIG]->getValue('session', 'blowfish') : session_id(); + } # If the secret isnt set, then just return the data. if (! trim($secret)) + { return $encdata; + } if (function_exists('mcrypt_module_open') && ! empty($encdata)) { $td = mcrypt_module_open(MCRYPT_BLOWFISH,'',MCRYPT_MODE_ECB,''); @@ -837,16 +972,22 @@ function blowfish_decrypt($encdata,$secret=null) { } if (file_exists(LIBDIR.'blowfish.php')) - require_once LIBDIR.'blowfish.php'; + { + require_once LIBDIR . 'blowfish.php'; + } else + { return $encdata; + } $pma_cipher = new Horde_Cipher_blowfish; $decrypt = ''; $data = base64_decode($encdata); for ($i=0; $idecryptBlock(substr($data, $i, 8), $secret); + } // Strip off our \0's that were added. $return = preg_replace("/\\0*$/",'',$decrypt); @@ -865,7 +1006,9 @@ function blowfish_decrypt($encdata,$secret=null) { */ function full_str_pad($input,$pad_length,$pad_string='',$pad_type=0) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $str = ''; $length = $pad_length - strlen($input); @@ -903,17 +1046,23 @@ function full_str_pad($input,$pad_length,$pad_string='',$pad_type=0) { */ function get_cached_item($index,$item,$subitem='null') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = null; # Check config to make sure session-based caching is enabled. if ($_SESSION[APPCONFIG]->getValue('cache',$item) && isset($_SESSION['cache'][$index][$item][$subitem])) + { $return = $_SESSION['cache'][$index][$item][$subitem]; + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -930,7 +1079,9 @@ function get_cached_item($index,$item,$subitem='null') { */ function set_cached_item($index,$item,$subitem='null',$data) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Check config to make sure session-based caching is enabled. if ($_SESSION[APPCONFIG]->getValue('cache',$item)) { @@ -942,7 +1093,9 @@ function set_cached_item($index,$item,$subitem='null',$data) { return true; } else - return false; + { + return FALSE; + } } /** @@ -953,16 +1106,22 @@ function set_cached_item($index,$item,$subitem='null',$data) { */ function del_cached_item($index,$item,$subitem='null') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } global $CACHE; # Check config to make sure session-based caching is enabled. if (isset($_SESSION['cache'][$index][$item][$subitem])) + { unset($_SESSION['cache'][$index][$item][$subitem]); + } if (isset($CACHE[$index][$item][$subitem])) + { unset($CACHE[$index][$item][$subitem]); + } } /** @@ -978,7 +1137,9 @@ function del_cached_item($index,$item,$subitem='null') { */ function set_cookie($name,$val,$expire=null,$dir=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = false; @@ -989,7 +1150,9 @@ function set_cookie($name,$val,$expire=null,$dir=null) { } if ($dir == null) + { $dir = dirname($_SERVER['PHP_SELF']); + } if (@setcookie($name,$val,$expire,$dir)) { $_COOKIE[$name] = $val; @@ -997,7 +1160,9 @@ function set_cookie($name,$val,$expire=null,$dir=null) { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1013,7 +1178,9 @@ function set_cookie($name,$val,$expire=null,$dir=null) { */ function get_custom_file($index,$filename,$path) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Set default return $return = $path.$filename; @@ -1021,10 +1188,14 @@ function get_custom_file($index,$filename,$path) { $custom = $server->getValue('custom','pages_prefix'); if (! is_null($custom) && is_file(realpath($path.$custom.$filename))) - $return = $path.$custom.$filename; + { + $return = $path . $custom . $filename; + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1039,11 +1210,15 @@ function get_custom_file($index,$filename,$path) { */ function masort(&$data,$sortby,$rev=0) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # if the array to sort is null or empty, or if we have some nasty chars if (! preg_match('/^[a-zA-Z0-9_]+(\([a-zA-Z0-9_,]*\))?$/',$sortby) || ! $data) + { return; + } static $CACHE = array(); @@ -1149,8 +1324,14 @@ function masort(&$data,$sortby,$rev=0) { $key = strtolower($key); - if ((! isset($a[$key])) && isset($b[$key])) return 1; - if (isset($a[$key]) && (! isset($b[$key]))) return -1; + if ((! isset($a[$key])) && isset($b[$key])) + { + return 1; + } + if (isset($a[$key]) && (! isset($b[$key]))) + { + return -1; + } if ((isset($a[$key])) && (isset($b[$key]))) { if (is_array($a[$key])) { @@ -1175,8 +1356,14 @@ function masort(&$data,$sortby,$rev=0) { return ($aa > $bb) ? 1 : -1; } else { - if (($c = strcasecmp($bb, $aa)) != 0) return $c; - if (($c = strcasecmp($aa, $bb)) != 0) return $c; + if (($c = strcasecmp($bb, $aa)) != 0) + { + return $c; + } + if (($c = strcasecmp($aa, $bb)) != 0) + { + return $c; + } } } } @@ -1223,19 +1410,29 @@ function isCompress() { */ function obfuscate_password_display($enc=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($_SESSION[APPCONFIG]->getValue('appearance','obfuscate_password_display')) - $return = true; + { + $return = TRUE; + } elseif (! $_SESSION[APPCONFIG]->getValue('appearance','show_clear_password') && (is_null($enc) || $enc == 'clear')) - $return = true; + { + $return = TRUE; + } else - $return = false; + { + $return = FALSE; + } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -1252,13 +1449,17 @@ function obfuscate_password_display($enc=null) { */ function pretty_print_dn($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $dn_save = $dn; $dn = pla_explode_dn($dn); if (! $dn) + { return $dn_save; + } foreach ($dn as $i => $element) { $element = htmlspecialchars($element); @@ -1285,29 +1486,39 @@ function pretty_print_dn($dn) { */ function is_dn_string($str) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } /* Try to break the string into its component parts if it can be done ie, "uid=Manager" "dc=example" and "dc=com" */ $parts = pla_explode_dn($str); if (! is_array($parts) || ! count($parts)) - return false; + { + return FALSE; + } /* Foreach of the "parts", look for an "=" character, and make sure neither the left nor the right is empty */ foreach ($parts as $part) { if (! strpos($part,"=")) - return false; + { + return FALSE; + } $sub_parts = explode('=',$part,2); $left = $sub_parts[0]; $right = $sub_parts[1]; if ( ! strlen(trim($left)) || ! strlen(trim($right))) - return false; + { + return FALSE; + } if (strpos($left,'#') !== false) - return false; + { + return FALSE; + } } # We survived the above rigor. This is a bonified DN string. @@ -1322,14 +1533,20 @@ function is_dn_string($str) { */ function is_mail_string($str) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $mail_regex = "/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/"; if (preg_match($mail_regex,$str)) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -1340,14 +1557,20 @@ function is_mail_string($str) { */ function is_url_string($str) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $url_regex = '/^(ftp|https?):\/\/+[\w\.\-\/\?\=\&]*\w+/'; if (preg_match($url_regex,$str)) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -1383,23 +1606,37 @@ function is_url_string($str) { */ function pla_compare_dns($dn1,$dn2) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If pla_compare_dns is passed via a tree, then we'll just get the DN part. if (is_array($dn1)) + { if (isset($dn1['dn'])) + { $dn1 = $dn1['dn']; - else - $dn1 = implode('+',$dn1); + } else + { + $dn1 = implode('+', $dn1); + } + } if (is_array($dn2)) + { if (isset($dn2['dn'])) + { $dn2 = $dn2['dn']; - else - $dn2 = implode('+',$dn2); + } else + { + $dn2 = implode('+', $dn2); + } + } # If they are obviously the same, return immediately if (! strcasecmp($dn1,$dn2)) + { return 0; + } $dn1_parts = pla_explode_dn(pla_reverse_dn($dn1)); $dn2_parts = pla_explode_dn(pla_reverse_dn($dn2)); @@ -1423,12 +1660,16 @@ function pla_compare_dns($dn1,$dn2) { $dn2_sub_part_attr = trim($dn2_sub_parts[0]); if (0 != ($cmp = strcasecmp($dn1_sub_part_attr,$dn2_sub_part_attr))) + { return $cmp; + } $dn1_sub_part_val = trim($dn1_sub_parts[1]); $dn2_sub_part_val = trim($dn2_sub_parts[1]); if (0 != ($cmp = strcasecmp($dn1_sub_part_val,$dn2_sub_part_val))) + { return $cmp; + } } /* If we iterated through all entries in the smaller of the two DNs @@ -1483,7 +1724,9 @@ function pla_compare_dns($dn1,$dn2) { */ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); $attr = strtolower($attr); @@ -1523,7 +1766,9 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu } } else + { $query['base'] = $base; + } if (! $server->dnExists($query['base'])) { system_message(array( @@ -1557,7 +1802,9 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu foreach ($search as $dn => $values) { $values = array_change_key_case($values); foreach ($values[$attr] as $value) - array_push($autonum,$value); + { + array_push($autonum, $value); + } } $autonum = array_unique($autonum); @@ -1571,7 +1818,9 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu $min = array_change_key_case($server->getValue('auto_number','min')); if (isset($min[$attr])) + { $minNumber = $min[$attr] > $minNumber ? $min[$attr] : $minNumber; + } } for ($i=0;$i $num+1) - return $autonum[$i] >= $num ? $num+1 : $num; + { + return $autonum[$i] >= $num ? $num + 1 : $num; + } } # If we didnt find a suitable gap and are all above the minNumber, we'll just return the $minNumber @@ -1603,7 +1854,9 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu # If we are called with a filter, we'll use the one from the configuration. if (! empty($filter)) + { $query['filter'] = $filter; + } $search = $server->query($query,'auto_number'); @@ -1677,16 +1930,22 @@ function get_next_number($base,$attr,$increment=false,$filter=false,$startmin=nu */ function get_icon($server_id,$dn,$object_classes=array()) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $_SESSION[APPCONFIG]->getServer($server_id); # Fetch and lowercase all the objectClasses in an array if (! count($object_classes)) - $object_classes = $server->getDNAttrValue($dn,'objectClass'); + { + $object_classes = $server->getDNAttrValue($dn, 'objectClass'); + } foreach ($object_classes as $index => $value) + { $object_classes[$index] = strtolower($value); + } $rdn = get_rdn($dn); $rdn_parts = explode('=',$rdn,2); @@ -1697,10 +1956,14 @@ function get_icon($server_id,$dn,$object_classes=array()) { # Return icon filename based upon objectClass value if (in_array('sambaaccount',$object_classes) && '$' == $rdn{ strlen($rdn) - 1 }) + { return 'nt_machine.png'; + } if (in_array('sambaaccount',$object_classes)) + { return 'nt_user.png'; + } elseif (in_array('person',$object_classes) || in_array('organizationalperson',$object_classes) || @@ -1708,38 +1971,58 @@ function get_icon($server_id,$dn,$object_classes=array()) { in_array('account',$object_classes) || in_array('posixaccount',$object_classes)) + { return 'ldap-user.png'; + } elseif (in_array('organization',$object_classes)) + { return 'ldap-o.png'; + } elseif (in_array('organizationalunit',$object_classes)) + { return 'ldap-ou.png'; + } elseif (in_array('organizationalrole',$object_classes)) + { return 'ldap-uid.png'; + } elseif (in_array('dcobject',$object_classes) || in_array('domainrelatedobject',$object_classes) || in_array('domain',$object_classes) || in_array('builtindomain',$object_classes)) + { return 'ldap-dc.png'; + } elseif (in_array('alias',$object_classes)) + { return 'ldap-alias.png'; + } elseif (in_array('room',$object_classes)) + { return 'door.png'; + } elseif (in_array('iphost',$object_classes)) + { return 'host.png'; + } elseif (in_array('device',$object_classes)) + { return 'device.png'; + } elseif (in_array('document',$object_classes)) + { return 'document.png'; + } elseif (in_array('country',$object_classes)) { $tmp = pla_explode_dn($dn); @@ -1748,105 +2031,165 @@ function get_icon($server_id,$dn,$object_classes=array()) { if ($cval && false === strpos($cval,'..') && file_exists(realpath(sprintf('%s/../countries/%s.png',IMGDIR,strtolower($cval))))) - return sprintf('../countries/%s.png',strtolower($cval)); + { + return sprintf('../countries/%s.png', strtolower($cval)); + } else + { return 'country.png'; + } } elseif (in_array('jammvirtualdomain',$object_classes)) + { return 'mail.png'; + } elseif (in_array('locality',$object_classes)) + { return 'locality.png'; + } elseif (in_array('posixgroup',$object_classes) || in_array('groupofnames',$object_classes) || in_array('group',$object_classes)) + { return 'ldap-ou.png'; + } elseif (in_array('applicationprocess',$object_classes)) + { return 'process.png'; + } elseif (in_array('groupofuniquenames',$object_classes)) + { return 'ldap-uniquegroup.png'; + } elseif (in_array('nlsproductcontainer',$object_classes)) + { return 'n.png'; + } elseif (in_array('ndspkikeymaterial',$object_classes)) + { return 'lock.png'; + } elseif (in_array('server',$object_classes)) + { return 'server-small.png'; + } elseif (in_array('volume',$object_classes)) + { return 'hard-drive.png'; + } elseif (in_array('ndscatcatalog',$object_classes)) + { return 'catalog.png'; + } elseif (in_array('resource',$object_classes)) + { return 'n.png'; + } elseif (in_array('ldapgroup',$object_classes)) + { return 'ldap-server.png'; + } elseif (in_array('ldapserver',$object_classes)) + { return 'ldap-server.png'; + } elseif (in_array('nisserver',$object_classes)) + { return 'ldap-server.png'; + } elseif (in_array('rbscollection',$object_classes)) + { return 'ldap-ou.png'; + } elseif (in_array('dfsconfiguration',$object_classes)) + { return 'nt_machine.png'; + } elseif (in_array('applicationsettings',$object_classes)) + { return 'server-settings.png'; + } elseif (in_array('aspenalias',$object_classes)) + { return 'mail.png'; + } elseif (in_array('container',$object_classes)) + { return 'folder.png'; + } elseif (in_array('ipnetwork',$object_classes)) + { return 'network.png'; + } elseif (in_array('samserver',$object_classes)) + { return 'server-small.png'; + } elseif (in_array('lostandfound',$object_classes)) + { return 'find.png'; + } elseif (in_array('infrastructureupdate',$object_classes)) + { return 'server-small.png'; + } elseif (in_array('filelinktracking',$object_classes)) + { return 'files.png'; + } elseif (in_array('automountmap',$object_classes) || in_array('automount',$object_classes)) + { return 'hard-drive.png'; + } elseif (strpos($rdn_value,'ipsec') === 0 || strcasecmp($rdn_value,'IP Security') == 0|| strcasecmp($rdn_value,'MSRADIUSPRIVKEY Secret') == 0 || strpos($rdn_value,'BCKUPKEY_') === 0) + { return 'lock.png'; + } elseif (strcasecmp($rdn_value,'MicrosoftDNS') == 0) + { return 'ldap-dc.png'; + } # Oh well, I don't know what it is. Use a generic icon. else + { return 'ldap-default.png'; + } } /** @@ -1858,19 +2201,27 @@ function get_icon($server_id,$dn,$object_classes=array()) { */ function expand_dn_with_base($base,$sub_dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $empty_str = (is_null($sub_dn) || (($len=strlen(trim($sub_dn))) == 0)); if ($empty_str) + { return $base; + } # If we have a string which doesn't need a base elseif ($sub_dn[$len-1] != ',') + { return $sub_dn; + } else - return sprintf('%s%s',$sub_dn,$base); + { + return sprintf('%s%s', $sub_dn, $base); + } } /** @@ -1884,7 +2235,9 @@ function expand_dn_with_base($base,$sub_dn) { */ function random_salt($length) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $possible = '0123456789'. 'abcdefghijklmnopqrstuvwxyz'. @@ -1894,7 +2247,9 @@ function random_salt($length) { mt_srand((double)microtime() * 1000000); while (strlen($str) < $length) - $str .= substr($possible,(rand()%strlen($possible)),1); + { + $str .= substr($possible, (rand() % strlen($possible)), 1); + } return $str; } @@ -1911,19 +2266,29 @@ function random_salt($length) { */ function get_rdn($dn,$include_attrs=0,$decode=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (is_null($dn)) - return null; + { + return NULL; + } $rdn = pla_explode_dn($dn,$include_attrs); if (! count($rdn) || ! isset($rdn[0])) + { return $dn; + } if ($decode) + { $rdn = dn_unescape($rdn[0]); + } else + { $rdn = $rdn[0]; + } return $rdn; } @@ -1935,7 +2300,9 @@ function get_rdn($dn,$include_attrs=0,$decode=false) { */ function rdn_explode($rdn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Setup to work out our RDN. $rdnarray = explode('\+',$rdn); @@ -1943,7 +2310,9 @@ function rdn_explode($rdn) { # Capture items that have +, but are not an attribute foreach ($rdnarray as $index => $val) { if (preg_match('/=/',$val)) + { $validindex = $index; + } if (! preg_match('/=/',$val)) { $rdnarray[$validindex] .= '+'.$val; @@ -1971,7 +2340,9 @@ function rdn_explode($rdn) { */ function pla_verbose_error($key) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); @@ -1979,7 +2350,9 @@ function pla_verbose_error($key) { $source_file = LIBDIR.'ldap_error_codes.txt'; if (! file_exists($source_file) || ! is_readable($source_file) || ! ($f = fopen($source_file,'r'))) - return false; + { + return FALSE; + } $contents = fread($f,filesize($source_file)); fclose($f); @@ -2000,9 +2373,13 @@ function pla_verbose_error($key) { } if (isset($CACHE[$key])) + { return $CACHE[$key]; + } else - return array('title' => null,'desc' => null); + { + return array('title' => NULL, 'desc' => NULL); + } } /** @@ -2023,7 +2400,9 @@ function pla_verbose_error($key) { */ function support_oid_to_text($key) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } static $CACHE = array(); @@ -2035,7 +2414,9 @@ function support_oid_to_text($key) { $source_file = LIBDIR.'ldap_supported_oids.txt'; if (! file_exists($source_file) || ! is_readable($source_file) || ! ($f = fopen($source_file,'r'))) - return false; + { + return FALSE; + } $contents = fread($f,filesize($source_file)); fclose($f); @@ -2057,12 +2438,16 @@ function support_oid_to_text($key) { } if (isset($CACHE[$key])) + { return $CACHE[$key]; + } else + { return array( - 'title'=>$key, - 'ref'=>null, - 'desc'=>sprintf('%s',$unknown['desc'],$unknown['title'])); + 'title' => $key, + 'ref' => NULL, + 'desc' => sprintf('%s', $unknown['desc'], $unknown['title'])); + } } /** @@ -2073,7 +2458,9 @@ function support_oid_to_text($key) { */ function ldap_error_msg($msg,$errnum) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $body = ''; @@ -2118,16 +2505,22 @@ function ldap_error_msg($msg,$errnum) { */ function draw_jpeg_photo($server,$dn,$attr_name='jpegphoto',$index,$draw_delete_buttons=false,$options=array()) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $fixed = array(); $fixed['width'] = isset($options['fixed_width']) ? $options['fixed_width'] : false; $fixed['height'] = isset($options['fixed_height']) ? $options['fixed_height'] : false; if (is_null($server)) + { $jpeg_data = $_SESSION['tmp']; + } else - $jpeg_data = $server->getDNAttrValues($dn,null,LDAP_DEREF_NEVER,array($attr_name)); + { + $jpeg_data = $server->getDNAttrValues($dn, NULL, LDAP_DEREF_NEVER, array($attr_name)); + } if (! isset($jpeg_data[$attr_name][$index]) || ! $jpeg_data[$attr_name][$index]) { system_message(array( @@ -2148,10 +2541,12 @@ function draw_jpeg_photo($server,$dn,$attr_name='jpegphoto',$index,$draw_delete_ if (function_exists('getimagesize')) { $jpeg_temp_dir = realpath($_SESSION[APPCONFIG]->getValue('jpeg','tmpdir').'/'); if (! is_writable($jpeg_temp_dir)) + { system_message(array( - 'title'=>_('Unable to write to jpeg tmp directory'), - 'body'=>_('Please set jpeg,tmpdir to a writable directory in the phpLDAPadmin config.php'), - 'type'=>'warn')); + 'title' => _('Unable to write to jpeg tmp directory'), + 'body' => _('Please set jpeg,tmpdir to a writable directory in the phpLDAPadmin config.php'), + 'type' => 'warn')); + } else { # We have an image to display @@ -2205,8 +2600,10 @@ function draw_jpeg_photo($server,$dn,$attr_name='jpegphoto',$index,$draw_delete_ if ($draw_delete_buttons) # + { printf('
    %s', - $attr_name,_('Delete photo')); + $attr_name, _('Delete photo')); + } } /** @@ -2216,7 +2613,9 @@ function draw_jpeg_photo($server,$dn,$attr_name='jpegphoto',$index,$draw_delete_ */ function password_types() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return array( ''=>'clear', @@ -2243,14 +2642,18 @@ function password_types() { */ function hash_password($password_clear,$enc_type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $enc_type = strtolower($enc_type); switch($enc_type) { case 'blowfish': if (! defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) - error(_('Your system crypt library does not support blowfish encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support blowfish encryption.'), 'error', 'index.php'); + } # Hardcoded to second blowfish version and set number of rounds $new_value = sprintf('{CRYPT}%s',crypt($password_clear,'$2a$12$'.random_salt(13))); @@ -2259,16 +2662,22 @@ function hash_password($password_clear,$enc_type) { case 'crypt': if ($_SESSION[APPCONFIG]->getValue('password', 'no_random_crypt_salt')) - $new_value = sprintf('{CRYPT}%s',crypt($password_clear,substr($password_clear,0,2))); + { + $new_value = sprintf('{CRYPT}%s', crypt($password_clear, substr($password_clear, 0, 2))); + } else - $new_value = sprintf('{CRYPT}%s',crypt($password_clear,random_salt(2))); + { + $new_value = sprintf('{CRYPT}%s', crypt($password_clear, random_salt(2))); + } break; case 'ext_des': # Extended des crypt. see OpenBSD crypt man page. if (! defined('CRYPT_EXT_DES') || CRYPT_EXT_DES == 0) - error(_('Your system crypt library does not support extended DES encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support extended DES encryption.'), 'error', 'index.php'); + } $new_value = sprintf('{CRYPT}%s',crypt($password_clear,'_'.random_salt(8))); @@ -2290,7 +2699,9 @@ function hash_password($password_clear,$enc_type) { case 'md5crypt': if (! defined('CRYPT_MD5') || CRYPT_MD5 == 0) - error(_('Your system crypt library does not support md5crypt encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support md5crypt encryption.'), 'error', 'index.php'); + } $new_value = sprintf('{CRYPT}%s',crypt($password_clear,'$1$'.random_salt(9))); @@ -2299,11 +2710,17 @@ function hash_password($password_clear,$enc_type) { case 'sha': # Use php 4.3.0+ sha1 function, if it is available. if (function_exists('sha1')) - $new_value = sprintf('{SHA}%s',base64_encode(pack('H*',sha1($password_clear)))); + { + $new_value = sprintf('{SHA}%s', base64_encode(pack('H*', sha1($password_clear)))); + } elseif (function_exists('mhash')) - $new_value = sprintf('{SHA}%s',base64_encode(mhash(MHASH_SHA1,$password_clear))); + { + $new_value = sprintf('{SHA}%s', base64_encode(mhash(MHASH_SHA1, $password_clear))); + } else - error(_('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'),'error','index.php'); + { + error(_('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'), 'error', 'index.php'); + } break; @@ -2360,7 +2777,9 @@ function hash_password($password_clear,$enc_type) { */ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (in_array($attribute,array('sambalmpassword','sambantpassword'))) { $smb = new smbHash; @@ -2368,15 +2787,23 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword switch($attribute) { case 'sambalmpassword': if (strcmp($smb->lmhash($plainpassword),strtoupper($cryptedpassword)) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } case 'sambantpassword': if (strcmp($smb->nthash($plainpassword),strtoupper($cryptedpassword)) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } return false; @@ -2402,9 +2829,13 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword $new_hash = base64_encode(mhash(MHASH_SHA1,$plainpassword.$salt).$salt); if (strcmp($cryptedpassword,$new_hash) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } else { error(_('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'),'error','index.php'); @@ -2421,9 +2852,13 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword $new_hash = base64_encode(mhash(MHASH_MD5,$plainpassword.$salt).$salt); if (strcmp($cryptedpassword,$new_hash) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } else { error(_('Your PHP install does not have the mhash() function. Cannot do SHA hashes.'),'error','index.php'); @@ -2434,18 +2869,26 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword # SHA crypted passwords case 'sha': if (strcasecmp(hash_password($plainpassword,'sha'),'{SHA}'.$cryptedpassword) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } break; # MD5 crypted passwords case 'md5': if( strcasecmp(hash_password($plainpassword,'md5'),'{MD5}'.$cryptedpassword) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } break; @@ -2456,14 +2899,20 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword # Make sure that web server supports blowfish crypt if (! defined('CRYPT_BLOWFISH') || CRYPT_BLOWFISH == 0) - error(_('Your system crypt library does not support blowfish encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support blowfish encryption.'), 'error', 'index.php'); + } list($version,$rounds,$salt_hash) = explode('$',$cryptedpassword); if (crypt($plainpassword,'$'.$version.'$'.$rounds.'$'.$salt_hash) == $cryptedpassword) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } # Check if it's an crypted md5 @@ -2471,14 +2920,20 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword # Make sure that web server supports md5 crypt if (! defined('CRYPT_MD5') || CRYPT_MD5 == 0) - error(_('Your system crypt library does not support md5crypt encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support md5crypt encryption.'), 'error', 'index.php'); + } list($dummy,$type,$salt,$hash) = explode('$',$cryptedpassword); if (crypt($plainpassword,'$1$'.$salt) == $cryptedpassword) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } # Check if it's extended des crypt @@ -2486,21 +2941,31 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword # Make sure that web server supports ext_des if (! defined('CRYPT_EXT_DES') || CRYPT_EXT_DES == 0) - error(_('Your system crypt library does not support extended DES encryption.'),'error','index.php'); + { + error(_('Your system crypt library does not support extended DES encryption.'), 'error', 'index.php'); + } if (crypt($plainpassword,$cryptedpassword) == $cryptedpassword) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } # Password is plain crypt else { if (crypt($plainpassword,$cryptedpassword) == $cryptedpassword) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } break; @@ -2508,18 +2973,26 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword # SHA512 crypted passwords case 'sha512': if (strcasecmp(hash_password($plainpassword,'sha512'),'{SHA512}'.$cryptedpassword) == 0) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } break; # No crypt is given assume plaintext passwords are used default: if ($plainpassword == $cryptedpassword) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } } @@ -2535,28 +3008,40 @@ function password_check($cryptedpassword,$plainpassword,$attribute='userpassword */ function get_enc_type($user_password) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Capture the stuff in the { } to determine if this is crypt, md5, etc. $enc_type = null; if (preg_match('/{([^}]+)}/',$user_password,$enc_type)) + { $enc_type = strtolower($enc_type[1]); + } else - return null; + { + return NULL; + } # Handle crypt types if (strcasecmp($enc_type,'crypt') == 0) { # No need to check for standard crypt, because enc_type is already equal to 'crypt'. if (preg_match('/{[^}]+}\\$1\\$+/',$user_password)) + { $enc_type = 'md5crypt'; + } elseif (preg_match('/{[^}]+}\\$2+/',$user_password)) + { $enc_type = 'blowfish'; + } elseif (preg_match('/{[^}]+}_+/',$user_password)) + { $enc_type = 'ext_des'; + } } return $enc_type; @@ -2571,7 +3056,9 @@ function get_enc_type($user_password) { */ function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none') { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $href = sprintf("javascript:dnChooserPopup('%s','%s','%s');",$form,$element,$rdn == 'none' ? '' : rawurlencode($rdn)); $title = _('Click to popup a dialog to select an entry (DN) graphically'); @@ -2579,7 +3066,9 @@ function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none') printf('Find',$href,$title,IMGDIR); if ($include_choose_text) - printf('%s',$href,$title,_('browse')); + { + printf('%s', $href, $title, _('browse')); + } } /** @@ -2602,14 +3091,18 @@ function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none') */ function pla_explode_dn($dn,$with_attributes=0) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } global $CACHE; if (isset($CACHE['explode'][$dn][$with_attributes])) { if (DEBUG_ENABLED) - debug_log('Return CACHED result (%s) for (%s)',1,0,__FILE__,__LINE__,__METHOD__, - $CACHE['explode'][$dn][$with_attributes],$dn); + { + debug_log('Return CACHED result (%s) for (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, + $CACHE['explode'][$dn][$with_attributes], $dn); + } return $CACHE['explode'][$dn][$with_attributes]; } @@ -2621,7 +3114,9 @@ function pla_explode_dn($dn,$with_attributes=0) { $result[1] = ldap_explode_dn(dn_escape($dn),1); if (! $result[$with_attributes]) { if (DEBUG_ENABLED) - debug_log('Returning NULL - NO result.',1,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Returning NULL - NO result.', 1, 0, __FILE__, __LINE__, __METHOD__); + } return array(); } @@ -2640,7 +3135,9 @@ function pla_explode_dn($dn,$with_attributes=0) { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$result[$with_attributes]); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $result[$with_attributes]); + } return $result[$with_attributes]; } @@ -2652,18 +3149,24 @@ function pla_explode_dn($dn,$with_attributes=0) { */ function dn_escape($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $olddn = $dn; # Check if the RDN has a comma and escape it. while (preg_match('/([^\\\\]),(\s*[^=]*\s*),/',$dn)) - $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/','$1\\\\2C$2,',$dn); + { + $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*),/', '$1\\\\2C$2,', $dn); + } $dn = preg_replace('/([^\\\\]),(\s*[^=]*\s*)([^,])$/','$1\\\\2C$2$3',$dn); if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$dn); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $dn); + } return $dn; } @@ -2675,7 +3178,9 @@ function dn_escape($dn) { */ function dn_unescape($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $unescape = function ($input) { return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function ($match) { @@ -2687,7 +3192,9 @@ function dn_unescape($dn) { $a = array(); foreach ($dn as $key => $rdn) + { $a[$key] = $unescape($rdn); + } // $a[$key] = preg_replace('/\\\([0-9A-Fa-f]{2})/e',"''.chr(hexdec('\\1')).''",$rdn); return $a; @@ -2729,9 +3236,13 @@ function get_href($type,$extra_info='') { return sprintf('%s/mailarchive/forum.php?forum_name=%s',$sf,$forum_id); case 'logo': if (! isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on') + { $proto = 'http'; + } else + { $proto = 'https'; + } return isset($_SESSION) && ! $_SESSION[APPCONFIG]->getValue('appearance','remoteurls') ? '' : sprintf('%s://sflogo.sourceforge.net/sflogo.php?group_id=%s&type=10',$proto,$group_id); case 'sf': @@ -2776,29 +3287,43 @@ function utime() { */ function array_to_query_string($array,$exclude_vars=array()) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($array) || ! count($array)) + { return ''; + } $str = ''; $i = 0; foreach ($array as $name => $val) - if (! in_array($name,$exclude_vars)) + { + if ( ! in_array($name, $exclude_vars)) + { if (is_array($val)) - foreach ($val as $v) { + { + foreach ($val as $v) + { if ($i++ > 0) + { $str .= '&'; + } - $str .= sprintf('%s[]=%s',rawurlencode($name),rawurlencode($v)); + $str .= sprintf('%s[]=%s', rawurlencode($name), rawurlencode($v)); + } + } else + { + if ($i++ > 0) + { + $str .= '&'; } - else { - if ($i++ > 0) - $str .= '&'; - - $str .= sprintf('%s=%s',rawurlencode($name),rawurlencode($val)); + $str .= sprintf('%s=%s', rawurlencode($name), rawurlencode($val)); } + } + } return $str; } @@ -2823,7 +3348,9 @@ function array_to_query_string($array,$exclude_vars=array()) { */ function pla_reverse_dn($dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return (implode(',',array_reverse(pla_explode_dn($dn)))); } @@ -2836,10 +3363,14 @@ function pla_reverse_dn($dn) { */ function sortAttrs($a,$b) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($a == $b) + { return 0; + } $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); $attrs_display_order = arrayLower($_SESSION[APPCONFIG]->getValue('appearance','attr_display_order')); @@ -2849,17 +3380,27 @@ function sortAttrs($a,$b) { $b_key = array_search($b->getName(),$attrs_display_order); if ((! $a_key) && ($a_key !== 0)) - if ((! $a_key = array_search(strtolower($a->getFriendlyName()),$attrs_display_order)) && ($a_key !== 0)) - $a_key = count($attrs_display_order)+1; + { + if (( ! $a_key = array_search(strtolower($a->getFriendlyName()), $attrs_display_order)) && ($a_key !== 0)) + { + $a_key = count($attrs_display_order) + 1; + } + } if ((! $b_key) && ($b_key !== 0)) - if ((! $b_key = array_search(strtolower($b->getFriendlyName()),$attrs_display_order)) && ($b_key !== 0)) - $b_key = count($attrs_display_order)+1; + { + if (( ! $b_key = array_search(strtolower($b->getFriendlyName()), $attrs_display_order)) && ($b_key !== 0)) + { + $b_key = count($attrs_display_order) + 1; + } + } # Case where neither $a, nor $b are in $attrs_display_order, $a_key = $b_key = one greater than num elements. # So we sort them alphabetically if ($a_key === $b_key) - return strcasecmp($a->getFriendlyName(),$b->getFriendlyName()); + { + return strcasecmp($a->getFriendlyName(), $b->getFriendlyName()); + } # Case where at least one attribute or its friendly name is in $attrs_display_order # return -1 if $a before $b in $attrs_display_order @@ -2874,14 +3415,20 @@ function sortAttrs($a,$b) { */ function arrayLower($array) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($array)) + { return $array; + } $newarray = array(); foreach ($array as $key => $value) + { $newarray[$key] = strtolower($value); + } return $newarray; } @@ -2895,13 +3442,19 @@ function arrayLower($array) { */ function in_array_ignore_case($needle,$haystack) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($haystack)) - return false; + { + return FALSE; + } if (! is_string($needle)) - return false; + { + return FALSE; + } $return = false; @@ -2913,7 +3466,9 @@ function in_array_ignore_case($needle,$haystack) { } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -2926,7 +3481,9 @@ function in_array_ignore_case($needle,$haystack) { */ function draw_formatted_dn($server,$entry) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $dn = $entry->getDn(); @@ -2938,14 +3495,20 @@ function draw_formatted_dn($server,$entry) { $tokens = $tokens[0]; if (DEBUG_ENABLED) - debug_log('The tokens are (%s)',1,0,__FILE__,__LINE__,__METHOD__,$tokens); + { + debug_log('The tokens are (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $tokens); + } foreach ($tokens as $token) { if (strcasecmp($token,'%dn') == 0) - $format = str_replace($token,pretty_print_dn($dn),$format); + { + $format = str_replace($token, pretty_print_dn($dn), $format); + } elseif (strcasecmp($token,'%rdn') == 0) - $format = str_replace($token,pretty_print_dn($entry->getRDN()),$format); + { + $format = str_replace($token, pretty_print_dn($entry->getRDN()), $format); + } elseif (strcasecmp($token,'%rdnvalue') == 0) { $rdn = get_rdn($dn,0,true); @@ -2962,10 +3525,14 @@ function draw_formatted_dn($server,$entry) { $has_none = true; } elseif (is_array($attr_values)) - $display = implode(', ',$attr_values); + { + $display = implode(', ', $attr_values); + } else + { $display = $attr_values; + } $format = str_replace($token,$display,$format); } @@ -2973,7 +3540,9 @@ function draw_formatted_dn($server,$entry) { # If this format has all values available, use it. Otherwise, try the next one if (!$has_none) + { return $format; + } } return $format; @@ -2990,7 +3559,9 @@ function draw_formatted_dn($server,$entry) { */ function server_select_list($selected=null,$logged_on=false,$name='index',$isVisible=true,$js=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $count = 0; $server_menu_html = sprintf(''; if ($count > 1) + { return $server_menu_html; + } elseif ($count) + { return sprintf('%s ', - $selected_server->getName(),$name,$selected_server->getIndex()); + $selected_server->getName(), $name, $selected_server->getIndex()); + } else + { return ''; + } } /** @@ -3030,19 +3609,25 @@ function server_select_list($selected=null,$logged_on=false,$name='index',$isVis */ function littleEndian($hex) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = ''; - for ($x=strlen($hex)-2;$x>= 0;$x=$x-2) - $result .= substr($hex,$x,2); + for ($x=strlen($hex)-2; $x>= 0; $x -= 2) + { + $result .= substr($hex, $x, 2); + } return $result; } function binSIDtoText($binsid) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $hex_sid = bin2hex($binsid); $rev = hexdec(substr($hex_sid,0,2)); // Get revision-part of SID @@ -3073,7 +3658,9 @@ function binSIDtoText($binsid) { */ function return_ldap_hash($base,$filter,$key,$attrs,$sort=true) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $server = $_SESSION[APPCONFIG]->getServer(get_request('server_id','REQUEST')); $key = strtolower($key); @@ -3087,31 +3674,50 @@ function return_ldap_hash($base,$filter,$key,$attrs,$sort=true) { $results = array(); foreach ($search as $dn => $values) + { if (isset($values[$key])) + { if (is_array($values[$key])) + { foreach ($values[$key] as $i => $k) - foreach ($attrs as $attr) { + { + foreach ($attrs as $attr) + { $lattr = strtolower($attr); - if (isset($values[$lattr])) { + if (isset($values[$lattr])) + { $v = ''; if (is_array($values[$lattr]) && isset($values[$lattr][$i])) + { $v = $values[$lattr][$i]; + } if (is_string($v) && (strlen($v) > 0)) + { $results[$k][$attr] = $v; + } } } - - else - foreach ($attrs as $attr) { + } + } else + { + foreach ($attrs as $attr) + { $lattr = strtolower($attr); if (isset($values[$lattr])) + { $results[$values[$key]][$attr] = $values[$lattr]; + } } + } + } + } if ($sort) - masort($results,is_array($sort) ? implode(',',$sort) : 'dn'); + { + masort($results, is_array($sort) ? implode(',', $sort) : 'dn'); + } return $results; } @@ -3122,7 +3728,9 @@ function return_ldap_hash($base,$filter,$key,$attrs,$sort=true) { */ function password_generate() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $no_use_similiar = ! $_SESSION[APPCONFIG]->getValue('password','use_similar'); $lowercase = $_SESSION[APPCONFIG]->getValue('password','lowercase'); @@ -3154,32 +3762,50 @@ function password_generate() { shuffle($punc); if ($lowercase > 0) - $outarray = array_merge($outarray,a_array_rand($llower,$lowercase)); + { + $outarray = array_merge($outarray, a_array_rand($llower, $lowercase)); + } if ($uppercase > 0) - $outarray = array_merge($outarray,a_array_rand($lupper,$uppercase)); + { + $outarray = array_merge($outarray, a_array_rand($lupper, $uppercase)); + } if ($digits > 0) - $outarray = array_merge($outarray,a_array_rand($numbers,$digits)); + { + $outarray = array_merge($outarray, a_array_rand($numbers, $digits)); + } if ($punctuation > 0) - $outarray = array_merge($outarray,a_array_rand($punc,$punctuation)); + { + $outarray = array_merge($outarray, a_array_rand($punc, $punctuation)); + } $num_spec = $lowercase + $uppercase + $digits + $punctuation; if ($num_spec < $length) { $leftover = array(); if ($lowercase > 0) - $leftover = array_merge($leftover,$llower); + { + $leftover = array_merge($leftover, $llower); + } if ($uppercase > 0) - $leftover = array_merge($leftover,$lupper); + { + $leftover = array_merge($leftover, $lupper); + } if ($digits > 0) - $leftover = array_merge($leftover,$numbers); + { + $leftover = array_merge($leftover, $numbers); + } if ($punctuation > 0) - $leftover = array_merge($leftover,$punc); + { + $leftover = array_merge($leftover, $punc); + } if (count($leftover) == 0) - $leftover = array_merge($leftover,$llower,$lupper,$numbers,$punc); + { + $leftover = array_merge($leftover, $llower, $lupper, $numbers, $punc); + } shuffle($leftover); $outarray = array_merge($outarray,a_array_rand($leftover,$length-$num_spec)); @@ -3189,7 +3815,9 @@ function password_generate() { $return = implode('',$outarray); if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -3204,13 +3832,19 @@ function password_generate() { */ function a_array_rand($input,$num_req) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (count($input) == 0) + { return array(); + } if ($num_req < 1) + { return array(); + } $return = array(); if ($num_req > count($input)) { @@ -3222,14 +3856,20 @@ function a_array_rand($input,$num_req) { } else { $idxlist = array_rand($input,$num_req); if ($num_req == 1) + { $idxlist = array($idxlist); + } for($i = 0; $i < count($idxlist); $i++) + { $return[] = $input[$idxlist[$i]]; + } } if (DEBUG_ENABLED) - debug_log('Returning (%s)',1,0,__FILE__,__LINE__,__METHOD__,$return); + { + debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $return); + } return $return; } @@ -3260,11 +3900,17 @@ function htmlid($sid,$dn) { */ function isAjaxEnabled() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',1,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($_SESSION[APPCONFIG])) - return ($_SESSION[APPCONFIG]->getValue('appearance','tree') == 'AJAXTree'); + { + return ($_SESSION[APPCONFIG]->getValue('appearance', 'tree') == 'AJAXTree'); + } else - return false; + { + return FALSE; + } } diff --git a/lib/import_functions.php b/lib/import_functions.php index 8252285..f0c7b56 100644 --- a/lib/import_functions.php +++ b/lib/import_functions.php @@ -106,9 +106,13 @@ abstract class Import { public function getSource($attr) { if (isset($this->source[$attr])) + { return $this->source[$attr]; + } else - return null; + { + return NULL; + } } # @todo integrate hooks @@ -150,7 +154,7 @@ class ImportLDIF extends Import { private $template; public $error = array(); - static public function getType() { + public static function getType() { return array('type'=>'LDIF','description' => _('LDIF Import'),'extension'=>'ldif'); } @@ -172,7 +176,9 @@ class ImportLDIF extends Import { list($text,$version) = $this->getAttrValue(array_shift($lines)); if ($version != 1) - return $this->error(sprintf('%s %s',_('LDIF import only suppports version 1'),$version),$lines); + { + return $this->error(sprintf('%s %s', _('LDIF import only suppports version 1'), $version), $lines); + } $haveVersion = true; $lines = $this->nextLines(); @@ -191,7 +197,9 @@ class ImportLDIF extends Import { array_shift($lines); } else + { $changetype = 'add'; + } $this->template = new Template($this->server_id,null,null,$changetype); @@ -212,7 +220,9 @@ class ImportLDIF extends Import { case 'modify': if (! $server->dnExists($dn)) - return $this->error(sprintf('%s %s',_('DN does not exist'),$dn),$lines); + { + return $this->error(sprintf('%s %s', _('DN does not exist'), $dn), $lines); + } $this->template->setDN($dn); $this->template->accept(false,true); @@ -224,7 +234,9 @@ class ImportLDIF extends Import { case 'moddn': case 'modrdn': if (! $server->dnExists($dn)) - return $this->error(sprintf('%s %s',_('DN does not exist'),$dn),$lines); + { + return $this->error(sprintf('%s %s', _('DN does not exist'), $dn), $lines); + } $this->template->setDN($dn); $this->template->accept(); @@ -235,14 +247,20 @@ class ImportLDIF extends Import { default: if (! $server->dnExists($dn)) - return $this->error(_('Unkown change type'),$lines); + { + return $this->error(_('Unkown change type'), $lines); + } } } else - return $this->error(_('A valid dn line is required'),$lines); + { + return $this->error(_('A valid dn line is required'), $lines); + } } else - return false; + { + return FALSE; + } } /** @@ -255,9 +273,13 @@ class ImportLDIF extends Import { # Get the DN if (substr($value,0,1) == ':') - $value = base64_decode(trim(substr($value,1))); + { + $value = base64_decode(trim(substr($value, 1))); + } else + { $value = trim($value); + } return array($attr,$value); } @@ -284,20 +306,28 @@ class ImportLDIF extends Import { /* If the next line begin with a space, we append it to the current row * else we push it into the array (unwrap)*/ if ($this->isWrappedLine()) + { $current[$count] .= trim($this->_currentLine); + } elseif ($this->isCommentLine()) {} # Do nothing elseif (! $this->isBlankLine()) + { $current[++$count] = trim($this->_currentLine); + } else - $endEntryFound = true; + { + $endEntryFound = TRUE; + } } # Return the LDIF entry array return $current; } else + { return array(); + } } /** @@ -394,19 +424,27 @@ class ImportLDIF extends Import { if ($fh = @fopen($filename,'rb')) { if (! $return = @fread($fh,filesize($filename))) - return $this->error(_('Unable to read file for'),$value); + { + return $this->error(_('Unable to read file for'), $value); + } @fclose($fh); } else - return $this->error(_('Unable to open file for'),$value); + { + return $this->error(_('Unable to open file for'), $value); + } } else - return $this->error(_('The url attribute value should begin with file:// for'),$value); + { + return $this->error(_('The url attribute value should begin with file:// for'), $value); + } # It's a string } else + { $return = $value; + } return trim($return); } @@ -425,9 +463,13 @@ class ImportLDIF extends Import { } else if ($attribute->hasBeenModified()) + { $attribute->addValue($value); + } else + { $attribute->setValue(array($value)); + } } } @@ -438,7 +480,9 @@ class ImportLDIF extends Import { */ private function getModifyDetails($lines) { if (! count($lines)) - return $this->error(_('Missing attributes for'),$lines); + { + return $this->error(_('Missing attributes for'), $lines); + } # While the array is not empty while (count($lines)) { @@ -452,7 +496,9 @@ class ImportLDIF extends Import { $action_attribute_value = $attrvalue[1]; if (! in_array($action_attribute,array('add','delete','replace'))) - return $this->error(_('Missing modify command add, delete or replace'),array_merge(array($currentLine),$lines)); + { + return $this->error(_('Missing modify command add, delete or replace'), array_merge(array($currentLine), $lines)); + } $processline = true; switch ($action_attribute) { @@ -464,8 +510,10 @@ class ImportLDIF extends Import { $attribute = $this->template->getAttribute($action_attribute_value); if (is_null($attribute)) - return $this->error(sprintf('%s %s',_('Attempting to delete a non existant attribute'),$action_attribute_value), - array_merge(array($currentLine),$lines)); + { + return $this->error(sprintf('%s %s', _('Attempting to delete a non existant attribute'), $action_attribute_value), + array_merge(array($currentLine), $lines)); + } $deleteattr = true; @@ -475,8 +523,10 @@ class ImportLDIF extends Import { $attribute = $this->template->getAttribute($action_attribute_value); if (is_null($attribute)) - return $this->error(sprintf('%s %s',_('Attempting to replace a non existant attribute'),$action_attribute_value), - array_merge(array($currentLine),$lines)); + { + return $this->error(sprintf('%s %s', _('Attempting to replace a non existant attribute'), $action_attribute_value), + array_merge(array($currentLine), $lines)); + } break; @@ -507,9 +557,13 @@ class ImportLDIF extends Import { switch ($action_attribute) { case 'add': if (is_null($attribute)) - $attribute = $this->template->addAttribute($attr,array('values'=>array($attribute_value_part))); + { + $attribute = $this->template->addAttribute($attr, array('values' => array($attribute_value_part))); + } else - $attribute->addValue($attribute_value_part,-1); + { + $attribute->addValue($attribute_value_part, -1); + } $attribute->justModified(); @@ -519,19 +573,27 @@ class ImportLDIF extends Import { $deleteattr = false; if (($key = array_search($attribute_value_part,$attribute->getValues())) !== false) + { $attribute->delValue($key); + } else - return $this->error(sprintf('%s %s',_('Delete value doesnt exist in DN'),$attribute_value_part), - array_merge(array($currentLine),$lines)); + { + return $this->error(sprintf('%s %s', _('Delete value doesnt exist in DN'), $attribute_value_part), + array_merge(array($currentLine), $lines)); + } break; case 'replace': if ($attribute->hasBeenModified()) - $attribute->addValue($attribute_value_part,-1); + { + $attribute->addValue($attribute_value_part, -1); + } else + { $attribute->setValue(array($attribute_value_part)); + } break; @@ -540,20 +602,28 @@ class ImportLDIF extends Import { } } else - return $this->error(sprintf('%s %s',_('The attribute to modify doesnt match the one specified by'),$action_attribute), - array_merge(array($currentLine),$lines)); + { + return $this->error(sprintf('%s %s', _('The attribute to modify doesnt match the one specified by'), $action_attribute), + array_merge(array($currentLine), $lines)); + } } else - return $this->error(sprintf('%s %s',_('Attribute not valid'),$currentLine), - array_merge(array($currentLine),$lines)); + { + return $this->error(sprintf('%s %s', _('Attribute not valid'), $currentLine), + array_merge(array($currentLine), $lines)); + } $currentLine = array_shift($lines); if (trim($currentLine)) - $processline = true; + { + $processline = TRUE; + } } if ($action_attribute == 'delete' && $deleteattr) + { $attribute->setValue(array()); + } } @@ -571,7 +641,9 @@ class ImportLDIF extends Import { # MODRDN MODDN should only be 2 or 3 lines. if (count($lines) != 2 && count($lines) !=3) - return $this->error(_('Invalid entry'),$lines); + { + return $this->error(_('Invalid entry'), $lines); + } else { $currentLine = array_shift($lines); @@ -598,16 +670,24 @@ class ImportLDIF extends Import { $attrs['newsuperior'] = $attrvalue[1]; } else - return $this->error(_('A valid newsuperior attribute should be specified'),$lines); + { + return $this->error(_('A valid newsuperior attribute should be specified'), $lines); + } } else + { $attrs['newsuperior'] = $server->getContainer($this->template->getDN()); + } } else - return $this->error(_('A valid deleteoldrdn attribute should be specified'),$lines); + { + return $this->error(_('A valid deleteoldrdn attribute should be specified'), $lines); + } } else - return $this->error(_('A valid newrdn attribute should be specified'),$lines); + { + return $this->error(_('A valid newrdn attribute should be specified'), $lines); + } } # Well do something out of the ordinary here, since our template doesnt handle mod[r]dn yet. diff --git a/lib/page.php b/lib/page.php index 0c5a84a..acff18a 100644 --- a/lib/page.php +++ b/lib/page.php @@ -27,13 +27,19 @@ class page { public function __construct($index=null) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If we done have a configuration, then our IMGDIR and CSS are not defined if (! defined('IMGDIR')) - define('IMGDIR','images/default'); + { + define('IMGDIR', 'images/default'); + } if (! defined('CSSDIR')) - define('CSSDIR','css/default'); + { + define('CSSDIR', 'css/default'); + } $this->index = $index; @@ -42,9 +48,13 @@ class page { $this->_app['logo'] = IMGDIR.'/logo-small.png'; if (! is_null($index)) - $this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,$_SESSION[APPCONFIG]->getValue('appearance','stylesheet')); + { + $this->_app['urlcss'] = sprintf('%s/%s', CSSDIR, $_SESSION[APPCONFIG]->getValue('appearance', 'stylesheet')); + } else - $this->_app['urlcss'] = sprintf('%s/%s',CSSDIR,'style.css'); + { + $this->_app['urlcss'] = sprintf('%s/%s', CSSDIR, 'style.css'); + } # Default Values for configurable items. $this->_default['sysmsg']['error'] = IMGDIR.'/error-big.png'; @@ -67,13 +77,17 @@ class page { header('Content-Encoding: gzip'); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) - debug_log('Sent COMPRESSED header to browser and discarded (%s)',129,0,__FILE__,__LINE__,__METHOD__,$preOutput); + { + debug_log('Sent COMPRESSED header to browser and discarded (%s)', 129, 0, __FILE__, __LINE__, __METHOD__, $preOutput); + } } if (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','compress') && ini_get('zlib.output_compression')) - $this->setsysmsg(array('title'=>_('Warning'),'body'=>_('WARNING: You cannot have PHP compression and application compression enabled at the same time. Please unset zlib.output_compression or set $config->custom->appearance[\'compress\']=false'),'type'=>'warn')); + { + $this->setsysmsg(array('title' => _('Warning'), 'body' => _('WARNING: You cannot have PHP compression and application compression enabled at the same time. Please unset zlib.output_compression or set $config->custom->appearance[\'compress\']=false'), 'type' => 'warn')); + } # Turn back on output buffering. ob_start(); @@ -86,7 +100,9 @@ class page { /* Add to the HTML Header */ public function head_add($html) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->_head[] .= $html; } @@ -94,11 +110,15 @@ class page { /* Print out the HTML header */ private function pageheader_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # HTML prepage requirements. foreach ($this->_pageheader as $line) - echo $line."\n"; + { + echo $line . "\n"; + } # Page Title echo ''; @@ -106,16 +126,22 @@ class page { $DNs = get_request('dn','REQUEST'); if (is_array($DNs)) + { $DNs = ''; + } if (isset($_SESSION[APPCONFIG])) + { printf('%s (%s) - %s%s', $this->_app['title'], app_version(), - $DNs ? htmlspecialchars($DNs).' ' : '', - $_SESSION[APPCONFIG]->getValue('appearance','page_title')); + $DNs ? htmlspecialchars($DNs) . ' ' : '', + $_SESSION[APPCONFIG]->getValue('appearance', 'page_title')); + } else - printf('%s - %s',$this->_app['title'],app_version()); + { + printf('%s - %s', $this->_app['title'], app_version()); + } echo ''; # Style sheet. @@ -131,8 +157,12 @@ class page { # HTML head requirements. if (is_array($this->_head) && count($this->_head)) + { foreach ($this->_head as $line) - echo $line."\n"; + { + echo $line . "\n"; + } + } echo ''; echo "\n"; @@ -140,12 +170,18 @@ class page { private function head_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($_SESSION[APPCONFIG])) - $pagetitle = $_SESSION[APPCONFIG]->getValue('appearance','page_title') ? ' - '.$_SESSION[APPCONFIG]->getValue('appearance','page_title') : ''; + { + $pagetitle = $_SESSION[APPCONFIG]->getValue('appearance', 'page_title') ? ' - ' . $_SESSION[APPCONFIG]->getValue('appearance', 'page_title') : ''; + } else + { $pagetitle = ''; + } echo ''; @@ -155,18 +191,27 @@ class page { echo ''; echo '
    '; $empty = true; if (function_exists('cmd_control_pane')) + { foreach (cmd_control_pane('top') as $cmddetails) - if ((isset($cmddetails['enable']) && $cmddetails['enable']) || ! isset($cmddetails['enable'])) { - if (! $empty) + { + if ((isset($cmddetails['enable']) && $cmddetails['enable']) || ! isset($cmddetails['enable'])) + { + if ( ! $empty) + { echo ' '; + } - printf('%s',$cmddetails['link'],$cmddetails['image']); + printf('%s', $cmddetails['link'], $cmddetails['image']); - $empty = false; + $empty = FALSE; } + } + } if ($empty) + { echo ' '; + } echo '
    '; echo ''; if ($empty) + { echo ''; + } echo ''; echo '
    '; $empty = true; if (function_exists('cmd_control_pane')) + { foreach (cmd_control_pane('main') as $cmddetails) - if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) { - if (! $empty) + { + if ((isset($cmddetails['enable']) && trim($cmddetails['enable'])) || ! isset($cmddetails['enable'])) + { + if ( ! $empty) + { echo ' | '; + } - printf('%s',$cmddetails['link'], - (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance','control_icons')) ? $cmddetails['image'] : $cmddetails['title']); + printf('%s', $cmddetails['link'], + (isset($_SESSION[APPCONFIG]) && $_SESSION[APPCONFIG]->getValue('appearance', 'control_icons')) ? $cmddetails['image'] : $cmddetails['title']); - $empty = false; + $empty = FALSE; } + } + } echo ' 
    '; @@ -204,13 +260,19 @@ class page { protected function tree() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! isset($_SESSION[APPCONFIG])) + { return; + } if (is_null($this->index)) + { $this->index = min(array_keys($_SESSION[APPCONFIG]->getServerList())); + } if (count($_SESSION[APPCONFIG]->getServerList()) > 1) { echo ''; @@ -233,30 +295,42 @@ class page { public function block_add($side,$object) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_object($object)) - error(sprintf('block_add called with [%s], but it is not an object',serialize($object))); + { + error(sprintf('block_add called with [%s], but it is not an object', serialize($object))); + } $this->_block[$side][] = $object; } private function block_print($side) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! isset($this->_block[$side])) + { return; + } printf('',$side); foreach ($this->_block[$side] as $object) + { echo $object->draw($side); + } echo ''; } private function sysmsg() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (isset($this->sysmsg)) { foreach ($this->sysmsg as $index => $details) { @@ -276,30 +350,43 @@ class page { } if (isset($details['title'])) + { printf('%s%s', - $icon,$details['type'],$details['title']); + $icon, $details['type'], $details['title']); + } if (isset($details['body'])) - if (is_array($details['body'])) { + { + if (is_array($details['body'])) + { echo ''; foreach ($details['body'] as $line) - printf('%s
    ',$line); + { + printf('%s
    ', $line); + } echo ''; } else - printf('%s',$details['body']); + { + printf('%s', $details['body']); + } + } } } } private function body($raw=false) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Add the Session System Messages if (isset($_SESSION['sysmsg']) && is_array($_SESSION['sysmsg'])) { foreach ($_SESSION['sysmsg'] as $msg) + { $this->setsysmsg($msg); + } unset($_SESSION['sysmsg']); } @@ -312,13 +399,19 @@ class page { } if (isset($this->_block['body'])) + { foreach ($this->_block['body'] as $object) - echo $object->draw('body',$raw); + { + echo $object->draw('body', $raw); + } + } } private function footer_print() { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } printf('%s
    %s
    %s', isCompress() ? '[C]' : ' ', @@ -334,7 +427,9 @@ class page { */ public function show($frame,$compress=false,$raw=false) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If the body is called via AJAX, and compression is enable, we need to compress the output if ($compress && ob_get_level() && isCompress()) { @@ -360,8 +455,10 @@ class page { ob_end_clean(); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) - debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__, - strlen($output),$output); + { + debug_log('Sending COMPRESSED output to browser[(%s),%s]', 129, 0, __FILE__, __LINE__, __METHOD__, + strlen($output), $output); + } print gzencode($output); } @@ -369,7 +466,9 @@ class page { public function display($filter=array()) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # Control what is displayed. $display = array( @@ -400,7 +499,9 @@ class page { echo ''; if ($display['HEAD']) + { $this->head_print(); + } # Control Line if ($display['CONTROL']) { @@ -434,7 +535,9 @@ class page { # Page Footer if ($display['FOOT']) + { $this->footer_print(); + } # Finish HTML echo '
    '; @@ -447,8 +550,10 @@ class page { ob_end_clean(); if (defined('DEBUG_ENABLED') && DEBUG_ENABLED) - debug_log('Sending COMPRESSED output to browser[(%s),%s]',129,0,__FILE__,__LINE__,__METHOD__, - strlen($output),$output); + { + debug_log('Sending COMPRESSED output to browser[(%s),%s]', 129, 0, __FILE__, __LINE__, __METHOD__, + strlen($output), $output); + } print gzencode($output); } @@ -456,19 +561,31 @@ class page { public function setsysmsg($data) { if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',129,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($data)) + { return; + } if (isset($this->sysmsg)) + { $msgnum = count($this->sysmsg) + 1; + } else + { $msgnum = 1; + } foreach (array('title','body','type') as $index) + { if (isset($data[$index])) + { $this->sysmsg[$msgnum][$index] = $data[$index]; + } + } } } @@ -499,19 +616,27 @@ class block { $output = ''; if ($raw) + { $output .= $this->body; + } else { $output .= sprintf('',$side); if (isset($this->title)) - $output .= sprintf('',$this->title); + { + $output .= sprintf('', $this->title); + } if (isset($this->body)) - $output .= sprintf('',$this->body); + { + $output .= sprintf('', $this->body); + } if (isset($this->footer)) - $output .= sprintf('',$this->foot); + { + $output .= sprintf('', $this->foot); + } $output .= '
    %s
    %s
    %s
    %s
    %s
    %s
    '; } diff --git a/lib/schema_functions.php b/lib/schema_functions.php index 56e58b3..4d858bd 100644 --- a/lib/schema_functions.php +++ b/lib/schema_functions.php @@ -28,28 +28,36 @@ abstract class SchemaItem { public function setOID($oid) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->oid = $oid; } public function setDescription($desc) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->description = $desc; } public function getOID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->oid); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->oid); + } return $this->oid; } public function getDescription() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->description); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->description); + } return $this->description; } @@ -59,7 +67,9 @@ abstract class SchemaItem { */ public function getIsObsolete() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->is_obsolete); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->is_obsolete); + } return $this->is_obsolete; } @@ -73,7 +83,9 @@ abstract class SchemaItem { */ public function getName($lower=true) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->name); + } return $lower ? strtolower($this->name) : $this->name; } @@ -110,7 +122,9 @@ class ObjectClass extends SchemaItem { */ public function __construct($class,$server) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server->getIndex(); $this->type = $server->getValue('server','schema_oclass_default'); @@ -129,9 +143,13 @@ class ObjectClass extends SchemaItem { do { $i++; if (strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match('/\'$/s',$strings[$i])); @@ -140,9 +158,13 @@ class ObjectClass extends SchemaItem { do { $i++; if (strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match('/\'$/s',$strings[$i])); @@ -155,28 +177,38 @@ class ObjectClass extends SchemaItem { $this->name = preg_replace('/\'$/','',$this->name); if (DEBUG_ENABLED) - debug_log('Case NAME returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->name); + { + debug_log('Case NAME returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->name); + } break; case 'DESC': do { $i++; if (strlen($this->description) == 0) - $this->description=$this->description.$strings[$i]; + { + $this->description .= $strings[$i]; + } else - $this->description=$this->description.' '.$strings[$i]; + { + $this->description = $this->description . ' ' . $strings[$i]; + } } while (! preg_match('/\'$/s',$strings[$i])); if (DEBUG_ENABLED) - debug_log('Case DESC returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->description); + { + debug_log('Case DESC returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->description); + } break; case 'OBSOLETE': $this->is_obsolete = TRUE; if (DEBUG_ENABLED) - debug_log('Case OBSOLETE returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->is_obsolete); + { + debug_log('Case OBSOLETE returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->is_obsolete); + } break; case 'SUP': @@ -189,34 +221,44 @@ class ObjectClass extends SchemaItem { do { $i++; if ($strings[$i] != '$') - array_push($this->sup_classes,preg_replace("/'/",'',$strings[$i])); + { + array_push($this->sup_classes, preg_replace("/'/", '', $strings[$i])); + } } while (! preg_match('/\)+\)?/',$strings[$i+1])); } if (DEBUG_ENABLED) - debug_log('Case SUP returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->sup_classes); + { + debug_log('Case SUP returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->sup_classes); + } break; case 'ABSTRACT': $this->type = 'abstract'; if (DEBUG_ENABLED) - debug_log('Case ABSTRACT returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->type); + { + debug_log('Case ABSTRACT returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->type); + } break; case 'STRUCTURAL': $this->type = 'structural'; if (DEBUG_ENABLED) - debug_log('Case STRUCTURAL returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->type); + { + debug_log('Case STRUCTURAL returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->type); + } break; case 'AUXILIARY': $this->type = 'auxiliary'; if (DEBUG_ENABLED) - debug_log('Case AUXILIARY returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->type); + { + debug_log('Case AUXILIARY returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->type); + } break; case 'MUST': @@ -225,7 +267,9 @@ class ObjectClass extends SchemaItem { $i = $this->parseList(++$i,$strings,$attrs); if (DEBUG_ENABLED) - debug_log('parseList returned %d (%s)',8,0,__FILE__,__LINE__,__METHOD__,$i,$attrs); + { + debug_log('parseList returned %d (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $i, $attrs); + } foreach ($attrs as $string) { $attr = new ObjectClass_ObjectClassAttribute($string,$this->name); @@ -235,11 +279,15 @@ class ObjectClass extends SchemaItem { array_push($this->may_attrs,$attr); } else - array_push($this->must_attrs,$attr); + { + array_push($this->must_attrs, $attr); + } } if (DEBUG_ENABLED) - debug_log('Case MUST returned (%s) (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->must_attrs,$this->force_may); + { + debug_log('Case MUST returned (%s) (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->must_attrs, $this->force_may); + } break; case 'MAY': @@ -248,7 +296,9 @@ class ObjectClass extends SchemaItem { $i = $this->parseList(++$i,$strings,$attrs); if (DEBUG_ENABLED) - debug_log('parseList returned %d (%s)',8,0,__FILE__,__LINE__,__METHOD__,$i,$attrs); + { + debug_log('parseList returned %d (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $i, $attrs); + } foreach ($attrs as $string) { $attr = new ObjectClass_ObjectClassAttribute($string,$this->name); @@ -256,7 +306,9 @@ class ObjectClass extends SchemaItem { } if (DEBUG_ENABLED) - debug_log('Case MAY returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->may_attrs); + { + debug_log('Case MAY returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->may_attrs); + } break; default: @@ -264,7 +316,9 @@ class ObjectClass extends SchemaItem { $this->setOID($strings[$i]); if (DEBUG_ENABLED) - debug_log('Case default returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->getOID()); + { + debug_log('Case default returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->getOID()); + } } break; } @@ -274,8 +328,10 @@ class ObjectClass extends SchemaItem { $this->description = preg_replace("/\'$/",'',$this->description); if (DEBUG_ENABLED) - debug_log('Returning () - NAME (%s), DESCRIPTION (%s), MUST (%s), MAY (%s), FORCE MAY (%s)',9,0,__FILE__,__LINE__,__METHOD__, - $this->name,$this->description,$this->must_attrs,$this->may_attrs,$this->force_may); + { + debug_log('Returning () - NAME (%s), DESCRIPTION (%s), MUST (%s), MAY (%s), FORCE MAY (%s)', 9, 0, __FILE__, __LINE__, __METHOD__, + $this->name, $this->description, $this->must_attrs, $this->may_attrs, $this->force_may); + } } /** @@ -287,7 +343,9 @@ class ObjectClass extends SchemaItem { */ private function parseList($i,$strings,&$attrs) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } /* * A list starts with a ( followed by a list of attributes separated by $ terminated by ) @@ -300,7 +358,9 @@ class ObjectClass extends SchemaItem { if (! preg_match('/^\(/',$string)) { # A bareword only - can be terminated by a ) if the last item if (preg_match('/\)+$/',$string)) - $string = preg_replace('/\)+$/','',$string); + { + $string = preg_replace('/\)+$/', '', $string); + } array_push($attrs,$string); @@ -330,9 +390,13 @@ class ObjectClass extends SchemaItem { } if (preg_match('/\)$/',$string)) - $string = preg_replace('/\)+$/','',$string); + { + $string = preg_replace('/\)+$/', '', $string); + } else + { $i++; + } array_push($attrs,$string); } @@ -341,7 +405,9 @@ class ObjectClass extends SchemaItem { sort($attrs); if (DEBUG_ENABLED) - debug_log('Returning (%d,[%s],[%s])',9,0,__FILE__,__LINE__,__METHOD__,$i,$strings,$attrs); + { + debug_log('Returning (%d,[%s],[%s])', 9, 0, __FILE__, __LINE__, __METHOD__, $i, $strings, $attrs); + } return $i; } @@ -351,10 +417,14 @@ class ObjectClass extends SchemaItem { */ public function getParents() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ((count($this->sup_classes) == 1) && ($this->sup_classes[0] == 'top')) + { return array(); + } $server = $_SESSION[APPCONFIG]->getServer($this->server_id); $return = array(); @@ -365,7 +435,9 @@ class ObjectClass extends SchemaItem { $oc = $server->getSchemaObjectClass($object_class); if ($oc) - $return = array_merge($return,$oc->getParents()); + { + $return = array_merge($return, $oc->getParents()); + } } return $return; @@ -387,10 +459,14 @@ class ObjectClass extends SchemaItem { */ public function getMustAttrs($parents=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! $parents) + { return $this->must_attrs; + } $server = $_SESSION[APPCONFIG]->getServer($this->server_id); $attrs = $this->must_attrs; @@ -404,10 +480,15 @@ class ObjectClass extends SchemaItem { # Remove any duplicates foreach ($attrs as $index => $attr) + { if (isset($allattr[$attr->getName()])) + { unset($attrs[$index]); - else + } else + { $allattr[$attr->getName()] = 1; + } + } return $attrs; } @@ -429,10 +510,14 @@ class ObjectClass extends SchemaItem { */ public function getMayAttrs($parents=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! $parents) + { return $this->may_attrs; + } $server = $_SESSION[APPCONFIG]->getServer($this->server_id); $attrs = $this->may_attrs; @@ -446,17 +531,24 @@ class ObjectClass extends SchemaItem { # Remove any duplicates foreach ($attrs as $index => $attr) + { if (isset($allattr[$attr->name])) + { unset($attrs[$index]); - else + } else + { $allattr[$attr->name] = 1; + } + } return $attrs; } public function getForceMayAttrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->force_may; } @@ -478,12 +570,16 @@ class ObjectClass extends SchemaItem { */ public function getMustAttrNames($parents=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attr_names = array(); foreach ($this->getMustAttrs($parents) as $attr) - array_push($attr_names,$attr->getName()); + { + array_push($attr_names, $attr->getName()); + } return $attr_names; } @@ -505,12 +601,16 @@ class ObjectClass extends SchemaItem { */ public function getMayAttrNames($parents=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $attr_names = array(); foreach ($this->getMayAttrs($parents) as $attr) - array_push($attr_names,$attr->getName()); + { + array_push($attr_names, $attr->getName()); + } return $attr_names; } @@ -524,13 +624,19 @@ class ObjectClass extends SchemaItem { */ public function addChildObjectClass($name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $name = trim($name); foreach ($this->children_objectclasses as $existing_objectclass) - if (strcasecmp($name,$existing_objectclass) == 0) - return false; + { + if (strcasecmp($name, $existing_objectclass) == 0) + { + return FALSE; + } + } array_push($this->children_objectclasses,$name); } @@ -542,7 +648,9 @@ class ObjectClass extends SchemaItem { */ public function getChildObjectClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->children_objectclasses; } @@ -554,7 +662,9 @@ class ObjectClass extends SchemaItem { */ public function getSupClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } return $this->sup_classes; } @@ -566,11 +676,15 @@ class ObjectClass extends SchemaItem { */ public function isRelated($oclass) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } # If I am in the array, we'll just return false if (in_array_ignore_case($this->name,$oclass)) - return false; + { + return FALSE; + } $server = $_SESSION[APPCONFIG]->getServer($this->server_id); @@ -578,7 +692,9 @@ class ObjectClass extends SchemaItem { $oc = $server->getSchemaObjectClass($object_class); if ($oc->isStructural() && in_array_ignore_case($this->getName(),$oc->getParents())) - return true; + { + return TRUE; + } } return false; @@ -589,7 +705,9 @@ class ObjectClass extends SchemaItem { */ public function getType() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->type); + } return $this->type; } @@ -603,10 +721,14 @@ class ObjectClass extends SchemaItem { */ private function addMustAttrs($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($attr) || ! count($attr)) + { return; + } $this->must_attrs = array_values(array_unique(array_merge($this->must_attrs,$attr))); } @@ -619,10 +741,14 @@ class ObjectClass extends SchemaItem { */ private function addMayAttrs($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($attr) || ! count($attr)) + { return; + } $this->may_attrs = array_values(array_unique(array_merge($this->may_attrs,$attr))); } @@ -634,23 +760,35 @@ class ObjectClass extends SchemaItem { */ public function isForceMay($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->force_may as $forcemay) + { if ($forcemay->getName() == $attr) - return true; + { + return TRUE; + } + } return false; } public function isStructural() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if ($this->type == 'structural') - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } } @@ -681,7 +819,9 @@ class ObjectClass_ObjectClassAttribute { */ public function __construct($name,$source) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->name = $name; $this->source = $source; @@ -690,7 +830,9 @@ class ObjectClass_ObjectClassAttribute { # Gets this attribute's name public function getName($lower=true) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->name); + } return $lower ? strtolower($this->name) : $this->name; } @@ -698,7 +840,9 @@ class ObjectClass_ObjectClassAttribute { # Gets the name of the ObjectClass which originally specified this attribute. public function getSource() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->source); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->source); + } return $this->source; } @@ -749,7 +893,9 @@ class AttributeType extends SchemaItem { */ public function __construct($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $strings = preg_split('/[\s,]+/',$attr,-1,PREG_SPLIT_DELIM_CAPTURE); @@ -765,9 +911,13 @@ class AttributeType extends SchemaItem { do { $i++; if (strlen($this->name)==0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); @@ -779,14 +929,22 @@ class AttributeType extends SchemaItem { do { # In case we came here becaues of a (' if (preg_match('/^\(/',$strings[$i])) - $strings[$i] = preg_replace('/^\(/','',$strings[$i]); + { + $strings[$i] = preg_replace('/^\(/', '', $strings[$i]); + } else + { $i++; + } if (strlen($this->name) == 0) - $this->name = $strings[$i]; + { + $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); @@ -800,27 +958,37 @@ class AttributeType extends SchemaItem { } if (DEBUG_ENABLED) - debug_log('Case NAME returned (%s) (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->name,$this->aliases); + { + debug_log('Case NAME returned (%s) (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->name, $this->aliases); + } break; case 'DESC': do { $i++; if (strlen($this->description)==0) - $this->description=$this->description.$strings[$i]; + { + $this->description .= $strings[$i]; + } else - $this->description=$this->description.' '.$strings[$i]; + { + $this->description = $this->description . ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); if (DEBUG_ENABLED) - debug_log('Case DESC returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->description); + { + debug_log('Case DESC returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->description); + } break; case 'OBSOLETE': $this->is_obsolete = TRUE; if (DEBUG_ENABLED) - debug_log('Case OBSOLETE returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->is_obsolete); + { + debug_log('Case OBSOLETE returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->is_obsolete); + } break; case 'SUP': @@ -828,7 +996,9 @@ class AttributeType extends SchemaItem { $this->sup_attribute = $strings[$i]; if (DEBUG_ENABLED) - debug_log('Case SUP returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->sup_attribute); + { + debug_log('Case SUP returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->sup_attribute); + } break; case 'EQUALITY': @@ -836,7 +1006,9 @@ class AttributeType extends SchemaItem { $this->equality = $strings[$i]; if (DEBUG_ENABLED) - debug_log('Case EQUALITY returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->equality); + { + debug_log('Case EQUALITY returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->equality); + } break; case 'ORDERING': @@ -844,7 +1016,9 @@ class AttributeType extends SchemaItem { $this->ordering = $strings[$i]; if (DEBUG_ENABLED) - debug_log('Case ORDERING returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->ordering); + { + debug_log('Case ORDERING returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->ordering); + } break; case 'SUBSTR': @@ -852,7 +1026,9 @@ class AttributeType extends SchemaItem { $this->sub_str = $strings[$i]; if (DEBUG_ENABLED) - debug_log('Case SUBSTR returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->sub_str); + { + debug_log('Case SUBSTR returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->sub_str); + } break; case 'SYNTAX': @@ -862,9 +1038,13 @@ class AttributeType extends SchemaItem { # Does this SYNTAX string specify a max length (ie, 1.2.3.4{16}) if (preg_match('/{(\d+)}$/',$this->syntax,$this->max_length)) + { $this->max_length = $this->max_length[1]; + } else - $this->max_length = null; + { + $this->max_length = NULL; + } if ($i < count($strings) - 1 && $strings[$i+1] == '{') { do { @@ -874,28 +1054,36 @@ class AttributeType extends SchemaItem { } if (DEBUG_ENABLED) - debug_log('Case SYNTAX returned (%s) (%s) (%s)',8,0,__FILE__,__LINE__,__METHOD__, - $this->syntax,$this->syntax_oid,$this->max_length); + { + debug_log('Case SYNTAX returned (%s) (%s) (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, + $this->syntax, $this->syntax_oid, $this->max_length); + } break; case 'SINGLE-VALUE': $this->is_single_value = TRUE; if (DEBUG_ENABLED) - debug_log('Case SINGLE-VALUE returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->is_single_value); + { + debug_log('Case SINGLE-VALUE returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->is_single_value); + } break; case 'COLLECTIVE': $this->is_collective = TRUE; if (DEBUG_ENABLED) - debug_log('Case COLLECTIVE returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->is_collective); + { + debug_log('Case COLLECTIVE returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->is_collective); + } break; case 'NO-USER-MODIFICATION': $this->is_no_user_modification = TRUE; if (DEBUG_ENABLED) - debug_log('Case NO-USER-MODIFICATION returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->is_no_user_modification); + { + debug_log('Case NO-USER-MODIFICATION returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->is_no_user_modification); + } break; case 'USAGE': @@ -903,7 +1091,9 @@ class AttributeType extends SchemaItem { $this->usage = $strings[$i]; if (DEBUG_ENABLED) - debug_log('Case USAGE returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->usage); + { + debug_log('Case USAGE returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->usage); + } break; default: @@ -911,7 +1101,9 @@ class AttributeType extends SchemaItem { $this->setOID($strings[$i]); if (DEBUG_ENABLED) - debug_log('Case default returned (%s)',8,0,__FILE__,__LINE__,__METHOD__,$this->getOID()); + { + debug_log('Case default returned (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $this->getOID()); + } } } } @@ -928,7 +1120,9 @@ class AttributeType extends SchemaItem { $this->sup_attribute = preg_replace("/\'$/",'',$this->sup_attribute); if (DEBUG_ENABLED) - debug_log('Returning ()',9,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Returning ()', 9, 0, __FILE__, __LINE__, __METHOD__); + } } /** @@ -938,7 +1132,9 @@ class AttributeType extends SchemaItem { */ public function getUsage() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->usage); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->usage); + } return $this->usage; } @@ -951,7 +1147,9 @@ class AttributeType extends SchemaItem { */ public function getSupAttribute() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->sup_attribute); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->sup_attribute); + } return $this->sup_attribute; } @@ -963,7 +1161,9 @@ class AttributeType extends SchemaItem { */ public function getEquality() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->equality); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->equality); + } return $this->equality; } @@ -975,7 +1175,9 @@ class AttributeType extends SchemaItem { */ public function getOrdering() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->ordering); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->ordering); + } return $this->ordering; } @@ -987,7 +1189,9 @@ class AttributeType extends SchemaItem { */ public function getSubstr() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->sub_str); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->sub_str); + } return $this->sub_str; } @@ -1000,7 +1204,9 @@ class AttributeType extends SchemaItem { */ public function getAliases() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->aliases); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->aliases); + } return $this->aliases; } @@ -1013,11 +1219,17 @@ class AttributeType extends SchemaItem { */ public function isAliasFor($attr_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->aliases as $alias_attr_name) - if (strcasecmp($alias_attr_name,$attr_name) == 0) - return true; + { + if (strcasecmp($alias_attr_name, $attr_name) == 0) + { + return TRUE; + } + } return false; } @@ -1029,7 +1241,9 @@ class AttributeType extends SchemaItem { */ public function getSyntaxString() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->syntax); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->syntax); + } return $this->syntax; } @@ -1044,7 +1258,9 @@ class AttributeType extends SchemaItem { */ public function getSyntaxOID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->syntax_oid); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->syntax_oid); + } return $this->syntax_oid; } @@ -1056,7 +1272,9 @@ class AttributeType extends SchemaItem { */ public function getMaxLength() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->max_length); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->max_length); + } return $this->max_length; } @@ -1069,7 +1287,9 @@ class AttributeType extends SchemaItem { */ public function getIsSingleValue() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->is_single_value); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->is_single_value); + } return $this->is_single_value; } @@ -1081,7 +1301,9 @@ class AttributeType extends SchemaItem { */ public function setIsSingleValue($is) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->is_single_value = $is; } @@ -1093,7 +1315,9 @@ class AttributeType extends SchemaItem { */ public function getIsCollective() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->is_collective); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->is_collective); + } return $this->is_collective; } @@ -1105,7 +1329,9 @@ class AttributeType extends SchemaItem { */ public function getIsNoUserModification() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->is_no_user_modification); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->is_no_user_modification); + } return $this->is_no_user_modification; } @@ -1117,7 +1343,9 @@ class AttributeType extends SchemaItem { */ public function getType() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->type); + } return $this->type; } @@ -1131,7 +1359,9 @@ class AttributeType extends SchemaItem { */ public function removeAlias($remove_alias_name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->aliases as $i => $alias_name) { @@ -1152,7 +1382,9 @@ class AttributeType extends SchemaItem { */ public function addAlias($alias) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } array_push($this->aliases,$alias); } @@ -1164,7 +1396,9 @@ class AttributeType extends SchemaItem { */ public function setName($name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->name = $name; } @@ -1176,7 +1410,9 @@ class AttributeType extends SchemaItem { */ public function setSupAttribute($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->sup_attribute = $attr; } @@ -1188,7 +1424,9 @@ class AttributeType extends SchemaItem { */ public function setAliases($aliases) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->aliases = $aliases; } @@ -1200,7 +1438,9 @@ class AttributeType extends SchemaItem { */ public function setType($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->type = $type; } @@ -1213,14 +1453,20 @@ class AttributeType extends SchemaItem { */ public function addUsedInObjectClass($name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->used_in_object_classes as $used_in_object_class) { if (DEBUG_ENABLED) - debug_log('Checking (%s) with (%s)',8,0,__FILE__,__LINE__,__METHOD__,$used_in_object_class,$name); + { + debug_log('Checking (%s) with (%s)', 8, 0, __FILE__, __LINE__, __METHOD__, $used_in_object_class, $name); + } if (strcasecmp($used_in_object_class,$name) == 0) - return false; + { + return FALSE; + } } array_push($this->used_in_object_classes,$name); @@ -1234,7 +1480,9 @@ class AttributeType extends SchemaItem { */ public function getUsedInObjectClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->used_in_object_classes); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->used_in_object_classes); + } return $this->used_in_object_classes; } @@ -1247,11 +1495,17 @@ class AttributeType extends SchemaItem { */ public function addRequiredByObjectClass($name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->required_by_object_classes as $required_by_object_class) - if (strcasecmp($required_by_object_class,$name) == 0) - return false; + { + if (strcasecmp($required_by_object_class, $name) == 0) + { + return FALSE; + } + } array_push($this->required_by_object_classes,$name); } @@ -1264,7 +1518,9 @@ class AttributeType extends SchemaItem { */ public function getRequiredByObjectClasses() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->required_by_object_classes); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->required_by_object_classes); + } return $this->required_by_object_classes; } @@ -1274,14 +1530,18 @@ class AttributeType extends SchemaItem { */ public function setForceMay() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->forced_as_may = true; } public function isForceMay() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->forced_as_may); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->forced_as_may); + } return $this->forced_as_may; } @@ -1300,7 +1560,9 @@ class Syntax extends SchemaItem { */ public function __construct($class) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $strings = preg_split('/[\s,]+/',$class,-1,PREG_SPLIT_DELIM_CAPTURE); @@ -1313,15 +1575,21 @@ class Syntax extends SchemaItem { do { $i++; if (strlen($this->description) == 0) - $this->description=$this->description.$strings[$i]; + { + $this->description .= $strings[$i]; + } else - $this->description=$this->description.' '.$strings[$i]; + { + $this->description = $this->description . ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); break; default: if (preg_match('/[\d\.]+/i',$strings[$i]) && $i == 1) + { $this->setOID($strings[$i]); + } } } @@ -1348,7 +1616,9 @@ class MatchingRule extends SchemaItem { */ public function __construct($strings) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $strings = preg_split('/[\s,]+/',$strings,-1,PREG_SPLIT_DELIM_CAPTURE); @@ -1362,9 +1632,13 @@ class MatchingRule extends SchemaItem { do { $i++; if (strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); } else { @@ -1372,9 +1646,13 @@ class MatchingRule extends SchemaItem { do { $i++; if (strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); do { @@ -1390,9 +1668,13 @@ class MatchingRule extends SchemaItem { do { $i++; if (strlen($this->description)==0) - $this->description=$this->description.$strings[$i]; + { + $this->description .= $strings[$i]; + } else - $this->description=$this->description.' '.$strings[$i]; + { + $this->description = $this->description . ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); break; @@ -1406,7 +1688,9 @@ class MatchingRule extends SchemaItem { default: if (preg_match('/[\d\.]+/i',$strings[$i]) && $i == 1) + { $this->setOID($strings[$i]); + } } } $this->description = preg_replace("/^\'/",'',$this->description); @@ -1420,7 +1704,9 @@ class MatchingRule extends SchemaItem { */ public function setUsedByAttrs($attrs) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->used_by_attrs = $attrs; } @@ -1433,11 +1719,17 @@ class MatchingRule extends SchemaItem { */ public function addUsedByAttr($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->used_by_attrs as $attr_name) - if (strcasecmp($attr_name,$attr) == 0) - return false; + { + if (strcasecmp($attr_name, $attr) == 0) + { + return FALSE; + } + } array_push($this->used_by_attrs,$attr); @@ -1451,7 +1743,9 @@ class MatchingRule extends SchemaItem { */ public function getUsedByAttrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->used_by_attrs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->used_by_attrs); + } return $this->used_by_attrs; } @@ -1469,7 +1763,9 @@ class MatchingRuleUse extends SchemaItem { public function __construct($strings) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 9, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $strings = preg_split('/[\s,]+/',$strings,-1,PREG_SPLIT_DELIM_CAPTURE); @@ -1483,9 +1779,13 @@ class MatchingRuleUse extends SchemaItem { do { $i++; if (! isset($this->name) || strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); @@ -1494,9 +1794,13 @@ class MatchingRuleUse extends SchemaItem { do { $i++; if (strlen($this->name) == 0) + { $this->name = $strings[$i]; + } else - $this->name .= ' '.$strings[$i]; + { + $this->name .= ' ' . $strings[$i]; + } } while (! preg_match("/\'$/s",$strings[$i])); do { @@ -1530,7 +1834,9 @@ class MatchingRuleUse extends SchemaItem { default: if (preg_match('/[\d\.]+/i',$strings[$i]) && $i == 1) + { $this->setOID($strings[$i]); + } } } @@ -1544,7 +1850,9 @@ class MatchingRuleUse extends SchemaItem { */ public function getUsedByAttrs() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',9,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->used_by_attrs); + { + debug_log('Entered (%%)', 9, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->used_by_attrs); + } return $this->used_by_attrs; } diff --git a/lib/session_functions.php b/lib/session_functions.php index 9b75e2e..d63abb4 100644 --- a/lib/session_functions.php +++ b/lib/session_functions.php @@ -29,9 +29,13 @@ function app_session_get_id() { $id_hex = hexdec($id_md5[0]) + 1; $ip_hex = hexdec($ip_md5[0]); if ($ip_hex <= app_session_id_ip_min) + { $ip_len = app_session_id_ip_min; + } else + { $ip_len = $ip_hex - 1; + } $new_id = substr($id_md5, 0, $id_hex) . substr($ip_md5, $ip_hex, $ip_len) . @@ -51,9 +55,13 @@ function app_session_verify_id() { $id_hex = hexdec($check_id[0]) + 1; $ip_hex = hexdec($ip_md5[0]); if ($ip_hex <= app_session_id_ip_min) + { $ip_len = app_session_id_ip_min; + } else + { $ip_len = $ip_hex - 1; + } $ip_ses = substr($check_id, $id_hex, $ip_len); $ip_ver = substr($ip_md5, $ip_hex, $ip_len); @@ -79,7 +87,9 @@ function app_session_start() { # If we have a sysmsg before our session has started, then preserve it. if (isset($_SESSION['sysmsg'])) + { $sysmsg = $_SESSION['sysmsg']; + } /* If session.auto_start is on in the server's PHP configuration (php.ini), then * we will have problems loading our schema cache since the session will have started @@ -87,11 +97,15 @@ function app_session_start() { * session to prevent this problem. */ if (ini_get('session.auto_start') && ! array_key_exists(app_session_id_init,$_SESSION)) + { @session_destroy(); + } # Do we already have a session? if (@session_id()) + { return; + } @session_name(APP_SESSION_ID); @session_start(); @@ -116,11 +130,16 @@ function app_session_start() { @header('Cache-control: private'); // IE 6 Fix if (app_session_id_paranoid && ! app_session_verify_id()) - error('Session inconsistent or session timeout','error','index.php'); + { + error('Session inconsistent or session timeout', 'error', 'index.php'); + } # Check we have the correct version of the SESSION cache if (isset($_SESSION['cache']) || isset($_SESSION[app_session_id_init])) { - if (! is_array($_SESSION[app_session_id_init])) $_SESSION[app_session_id_init] = array(); + if (! is_array($_SESSION[app_session_id_init])) + { + $_SESSION[app_session_id_init] = array(); + } if (! isset($_SESSION[app_session_id_init]['version']) || ! isset($_SESSION[app_session_id_init]['config']) || ! isset($_SESSION[app_session_id_init]['name']) || $_SESSION[app_session_id_init]['name'] !== app_name() @@ -143,25 +162,37 @@ function app_session_start() { $config_file = CONFDIR.'config.php'; $config = check_config($config_file); if (! $config) - debug_dump_backtrace('config is empty?',1); + { + debug_dump_backtrace('config is empty?', 1); + } } else { # Sanity check, specially when upgrading from a previous release. if (isset($_SESSION['cache'])) + { foreach (array_keys($_SESSION['cache']) as $id) + { if (isset($_SESSION['cache'][$id]['tree']['null']) && ! is_object($_SESSION['cache'][$id]['tree']['null'])) + { unset($_SESSION['cache'][$id]); + } + } + } } } # If we came via index.php, then set our $config. if (! isset($_SESSION[APPCONFIG]) && isset($config)) + { $_SESSION[APPCONFIG] = $config; + } # Restore our sysmsg's if there were any. if ($sysmsg) { if (! isset($_SESSION['sysmsg']) || ! is_array($_SESSION['sysmsg'])) + { $_SESSION['sysmsg'] = array(); + } $_SESSION['sysmsg'] = array_merge($_SESSION['sysmsg'],$sysmsg); } diff --git a/lib/xml2array.php b/lib/xml2array.php index 377a16c..c3225ee 100644 --- a/lib/xml2array.php +++ b/lib/xml2array.php @@ -43,16 +43,20 @@ class xml2array { $this->strXmlData = xml_parse($this->resParser,$strInputXML); if (! $this->strXmlData) + { die(sprintf('XML error: %s at line %d in file %s', xml_error_string(xml_get_error_code($this->resParser)), xml_get_current_line_number($this->resParser), $filename)); + } xml_parser_free($this->resParser); $output = array(); foreach ($this->arrOutput as $key => $values) + { $output[$key] = $this->cleanXML($values); + } #return $this->arrOutput; return $output; @@ -71,7 +75,9 @@ class xml2array { $cnt = count($this->stack_ref[$name]); $this->stack_ref[$name][$cnt] = array(); if (isset($attrs)) + { $this->stack_ref[$name][$cnt] = $attrs; + } $this->push_pos($this->stack_ref[$name][$cnt]); @@ -79,7 +85,9 @@ class xml2array { $this->stack_ref[$name]=array(); if (isset($attrs)) - $this->stack_ref[$name]=$attrs; + { + $this->stack_ref[$name] = $attrs; + } $this->push_pos($this->stack_ref[$name]); } @@ -89,9 +97,13 @@ class xml2array { if (trim($tagData) != '') { if (isset($this->stack_ref['#text'])) + { $this->stack_ref['#text'] .= $tagData; + } else + { $this->stack_ref['#text'] = $tagData; + } } } @@ -108,10 +120,14 @@ class xml2array { private function cleanXML($details) { # Quick processing for the final branch of the XML array. if (is_array($details) && isset($details['#text'])) + { return $details['#text']; + } elseif (is_array($details) && isset($details['ID']) && count($details) == 1) + { return $details['ID']; + } $cleanXML = array(); @@ -125,21 +141,32 @@ class xml2array { # More detailed processing... if (is_array($details)) + { foreach ($details as $key => $values) - if (is_numeric($key) && isset($values['ID']) && count($values) > 1) { + { + if (is_numeric($key) && isset($values['ID']) && count($values) > 1) + { $key = $values['ID']; unset($values['ID']); $cleanXML[$key] = $this->cleanXML($values); } elseif (isset($values['#text'])) + { $cleanXML[$key] = $this->cleanXML($values); - - elseif (is_array($values)) + } elseif (is_array($values)) + { $cleanXML[$key] = $this->cleanXML($values); + } + } + } if (! $cleanXML) + { return $details; + } else + { return $cleanXML; + } } } diff --git a/lib/xmlTemplates.php b/lib/xmlTemplates.php index de4abb8..48ce7d5 100644 --- a/lib/xmlTemplates.php +++ b/lib/xmlTemplates.php @@ -20,7 +20,9 @@ abstract class xmlTemplates { public function __construct($server_id) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server_id; $server = $_SESSION[APPCONFIG]->getServer($this->server_id); @@ -31,7 +33,9 @@ abstract class xmlTemplates { # Try to get the templates from our CACHE. if ($this->templates = get_cached_item($server_id,$class['item'])) { if (DEBUG_ENABLED) - debug_log('Using CACHED templates',4,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Using CACHED templates', 4, 0, __FILE__, __LINE__, __METHOD__); + } # See if the template_time has expired to see if we should reload the templates. foreach ($this->templates as $index => $template) { @@ -62,7 +66,9 @@ abstract class xmlTemplates { } if (DEBUG_ENABLED) - debug_log('Templates refreshed',4,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Templates refreshed', 4, 0, __FILE__, __LINE__, __METHOD__); + } # See if there are any new template files $index = max(array_keys($this->templates))+1; @@ -70,17 +76,23 @@ abstract class xmlTemplates { $dir = $class['dir'].$type; $dh = opendir($dir); if (! $type) + { $type = 'template'; + } while ($file = readdir($dh)) { # Ignore any files that are not XML files. if (! preg_match('/.xml$/',$file)) + { continue; + } # Ignore any files that are not the predefined custom files. if ($_SESSION[APPCONFIG]->getValue('appearance','custom_templates_only') && ! preg_match("/^${custom_prefix}/",$file)) + { continue; + } $filename = sprintf('%s/%s',$dir,$file); @@ -102,7 +114,9 @@ abstract class xmlTemplates { } else { if (DEBUG_ENABLED) - debug_log('Parsing templates',4,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Parsing templates', 4, 0, __FILE__, __LINE__, __METHOD__); + } # Need to reset this, as get_cached_item() returns null if nothing cached. $this->templates = array(); @@ -113,17 +127,23 @@ abstract class xmlTemplates { $dir = $class['dir'].$type; $dh = opendir($class['dir'].$type); if (! $type) + { $type = 'template'; + } while ($file = readdir($dh)) { # Ignore any files that are not XML files. if (! preg_match('/.xml$/',$file)) + { continue; + } # Ignore any files that are not the predefined custom files. if ($_SESSION[APPCONFIG]->getValue('appearance','custom_templates_only') && ! preg_match("/^${custom_prefix}/",$file)) + { continue; + } $filename = sprintf('%s/%s',$dir,$file); @@ -136,7 +156,9 @@ abstract class xmlTemplates { } if (DEBUG_ENABLED) - debug_log('Templates loaded',4,0,__FILE__,__LINE__,__METHOD__); + { + debug_log('Templates loaded', 4, 0, __FILE__, __LINE__, __METHOD__); + } if ($changed) { masort($this->templates,'title'); @@ -149,7 +171,9 @@ abstract class xmlTemplates { */ private function getClassVars() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $class = array(); @@ -190,26 +214,38 @@ abstract class xmlTemplates { */ public function getTemplates($type=null,$container=null,$disabled=false) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); if (is_array($this->templates)) - foreach ($this->templates as $details) { + { + foreach ($this->templates as $details) + { # Clone this, as we'll disable some templates, as a result of the container being requested. $template = clone $details; - if (! is_null($container) && ($regexp = $template->getRegExp()) && (! @preg_match('/'.$regexp.'/i',$container))) { - $template->setInvalid(_('This template is not valid in this container'),true); + if ( ! is_null($container) && ($regexp = $template->getRegExp()) && ( ! @preg_match('/' . $regexp . '/i', $container))) + { + $template->setInvalid(_('This template is not valid in this container'), TRUE); - if ($_SESSION[APPCONFIG]->getValue('appearance','hide_template_regexp')) + if ($_SESSION[APPCONFIG]->getValue('appearance', 'hide_template_regexp')) + { $template->setInvisible(); + } } - if ($template->isVisible() && (! $disabled || ! $template->isAdminDisabled())) - if (is_null($type) || (! is_null($type) && $template->isType($type))) - array_push($result,$template); + if ($template->isVisible() && ( ! $disabled || ! $template->isAdminDisabled())) + { + if (is_null($type) || ( ! is_null($type) && $template->isType($type))) + { + array_push($result, $template); + } + } } + } return $result; } @@ -222,13 +258,19 @@ abstract class xmlTemplates { */ public function getTemplate($templateid) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $class = $this->getClassVars(); foreach ($this->templates as $template) + { if ($template->getID() === $templateid) + { return clone $template; + } + } # If we get here, the template ID didnt exist, so return a blank template, which be interpreted as the default template $object = new $class['name']($this->server_id,null,null,'default'); @@ -240,12 +282,16 @@ abstract class xmlTemplates { */ private function getTemplateFiles() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->templates as $template) - array_push($result,$template->getFileName()); + { + array_push($result, $template->getFileName()); + } return $result; } @@ -275,7 +321,9 @@ abstract class xmlTemplate { public function __construct($server_id,$name=null,$filename=null,$type=null,$id=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $this->server_id = $server_id; $this->name = $name; @@ -286,7 +334,9 @@ abstract class xmlTemplate { # If there is no filename, then this template is a default template. if (is_null($filename)) + { return; + } # If we have a filename, parse the template file and build the object. $objXML = new xml2array(); @@ -302,11 +352,17 @@ abstract class xmlTemplate { */ protected function getAttrID($attr) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->attributes as $index => $attribute) - if (strtolower($attr) == $attribute->getName() || in_array(strtolower($attr),$attribute->getAliases())) + { + if (strtolower($attr) == $attribute->getName() || in_array(strtolower($attr), $attribute->getAliases())) + { return $index; + } + } return null; } @@ -316,7 +372,9 @@ abstract class xmlTemplate { */ public function getFileName() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->filename); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->filename); + } return $this->filename; } @@ -326,12 +384,18 @@ abstract class xmlTemplate { */ public function getID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->id); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->id); + } if ($this->name) - return sprintf('%s:%s',$this->getName(false),$this->id); + { + return sprintf('%s:%s', $this->getName(FALSE), $this->id); + } else + { return 'none'; + } } /** @@ -341,12 +405,18 @@ abstract class xmlTemplate { */ public function getName($lower=true) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->name); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->name); + } if ($lower) + { return strtolower($this->name); + } else + { return $this->name; + } } /** @@ -354,7 +424,9 @@ abstract class xmlTemplate { */ public function getReadTime() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->readtime); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->readtime); + } return $this->readtime; } @@ -366,7 +438,9 @@ abstract class xmlTemplate { */ protected function getServer() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs); + } return $_SESSION[APPCONFIG]->getServer($this->getServerID()); } @@ -378,7 +452,9 @@ abstract class xmlTemplate { */ protected function getServerID() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->server_id); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->server_id); + } return $this->server_id; } @@ -391,12 +467,18 @@ abstract class xmlTemplate { */ public function isType($type) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs, $this->type); + } if ($this->type == $type) - return true; + { + return TRUE; + } else - return false; + { + return FALSE; + } } /** @@ -404,7 +486,9 @@ abstract class xmlTemplate { */ public function getType() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->type); + { + debug_log('Entered (%%)', 5, 1, __FILE__, __LINE__, __METHOD__, $fargs, $this->type); + } return $this->type; } @@ -414,10 +498,14 @@ abstract class xmlTemplate { */ public function getTitle() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! isset($this->title) && ! isset($this->description)) + { return ''; + } return isset($this->title) ? $this->title : $this->description; } @@ -432,10 +520,14 @@ abstract class xmlTemplate { */ public function addAttribute($name,$value,$source=null) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } if (! is_array($value)) - debug_dump_backtrace('Value should be an array()',1); + { + debug_dump_backtrace('Value should be an array()', 1); + } $server = $this->getServer(); @@ -443,10 +535,12 @@ abstract class xmlTemplate { $attribute_factory = new AttributeFactory(); if (preg_match('/;/',$name)) + { system_message(array( - 'title'=>'phpLDAPadmin doesnt support RFC3866.', - 'body'=>sprintf('%s {%s} (%s)','PLA might not do what you expect...',$name,(is_array($value) ? serialize($value) : $value)), - 'type'=>'warn')); + 'title' => 'phpLDAPadmin doesnt support RFC3866.', + 'body' => sprintf('%s {%s} (%s)', 'PLA might not do what you expect...', $name, (is_array($value) ? serialize($value) : $value)), + 'type' => 'warn')); + } # If there isnt a schema item for this attribute $attribute = $attribute_factory->newAttribute($name,$value,$server->getIndex(),$source); @@ -454,7 +548,9 @@ abstract class xmlTemplate { $attrid = $this->getAttrID($attribute->getName()); if (is_null($attrid)) - array_push($this->attributes,$attribute); + { + array_push($this->attributes, $attribute); + } return $attribute; } @@ -466,12 +562,16 @@ abstract class xmlTemplate { */ public function getAttributeNames() { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } $result = array(); foreach ($this->attributes as $attribute) - array_push($result,$attribute->getName()); + { + array_push($result, $attribute->getName()); + } return $result; } @@ -484,11 +584,17 @@ abstract class xmlTemplate { */ public function getAttribute($name) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) - debug_log('Entered (%%)',5,0,__FILE__,__LINE__,__METHOD__,$fargs); + { + debug_log('Entered (%%)', 5, 0, __FILE__, __LINE__, __METHOD__, $fargs); + } foreach ($this->attributes as $attribute) - if (($attribute->getName() == strtolower($name)) || in_array(strtolower($name),$attribute->getAliases())) + { + if (($attribute->getName() == strtolower($name)) || in_array(strtolower($name), $attribute->getAliases())) + { return $attribute; + } + } return null; }