From c7a0ae00fbae6cada2d0ac8ca6968e37ae271bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Mon, 7 May 2018 16:29:03 +0200 Subject: [PATCH] :ambulance: fix(core) Lots of sonar fixes issue #5831 --- html/main.php | 55 ++++++------ include/class_IconTheme.inc | 6 +- include/class_config.inc | 43 +++++---- include/class_filter.inc | 37 ++++---- include/class_ldap.inc | 60 ++++++------- include/class_listing.inc | 87 +++++++++---------- include/class_listingSortIterator.inc | 10 +-- include/class_objects.inc | 7 +- include/class_pluglist.inc | 9 +- include/class_session.inc | 21 +---- include/class_template.inc | 16 ++-- include/class_tests.inc | 22 ++--- include/class_userinfo.inc | 59 +++++-------- include/functions.inc | 7 +- include/functions_debug.inc | 18 ++-- include/management/class_management.inc | 7 +- include/management/columns/class_Column.inc | 26 +++--- .../columns/class_PropertiesColumn.inc | 4 +- .../class_password-methods-smd5.inc | 3 +- .../class_password-methods-ssha.inc | 1 - .../class_password-methods.inc | 12 +-- include/php_setup.inc | 8 +- .../attributes/class_CompositeAttribute.inc | 3 +- .../attributes/class_FileAttribute.inc | 10 +-- .../attributes/class_SetAttribute.inc | 12 ++- include/simpleplugin/class_simpleTabs.inc | 19 ++-- .../addons/dashboard/class_dashBoardUsers.inc | 6 +- .../admin/departments/class_department.inc | 6 +- plugins/admin/users/class_userManagement.inc | 6 +- plugins/personal/generic/class_user.inc | 10 +-- setup/class_setup.inc | 3 +- setup/class_setupStepConfig.inc | 3 +- 32 files changed, 257 insertions(+), 339 deletions(-) diff --git a/html/main.php b/html/main.php index 1fe54dd68..280d327f6 100644 --- a/html/main.php +++ b/html/main.php @@ -42,10 +42,10 @@ session::set('errorsAlreadyPosted', array()); session::global_set('runtime_cache', array()); session::set('limit_exceeded', FALSE); -if ($_SERVER["REQUEST_METHOD"] == "POST") { - @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST"); +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, '_POST'); } -@DEBUG (DEBUG_SESSION, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION"); +@DEBUG (DEBUG_SESSION, __LINE__, __FUNCTION__, __FILE__, $_SESSION, '_SESSION'); /* Logged in? Simple security check */ if (!session::global_is_set('connected')) { @@ -201,11 +201,10 @@ if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )) { msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG); } -/* Redirect on back event */ -if ($_SERVER["REQUEST_METHOD"] == "POST") { - - /* Look for button events that match /^back[0-9]+$/, - extract the number and step the correct plugin. */ +if ($_SERVER['REQUEST_METHOD'] == 'POST') { + /* Redirect on back event + Look for button events that match /^back[0-9]+$/, + extract the number and step the correct plugin. */ foreach ($_POST as $key => $value) { if (preg_match("/^back[0-9]+$/", $key)) { $back = substr($key, 4); @@ -213,12 +212,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { exit; } } -} - -/* Redirect on password back event */ -if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])) { - header ("Location: main.php"); - exit; + /* Redirect on password back event */ + if (isset($_POST['password_back'])) { + header ("Location: main.php"); + exit; + } } /* Load department list when plugin has changed. That is some kind of @@ -250,24 +248,23 @@ $smarty->assign ("plug", "$plug"); $smarty->assign("usePrototype", "false"); /* React on clicks */ -if ($_SERVER["REQUEST_METHOD"] == "POST") { - if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])) { +if (($_SERVER['REQUEST_METHOD"'] == 'POST') + && (isset($_POST['delete_lock']) || isset($_POST['open_readonly']))) { - /* Set old Post data */ - if (session::global_is_set('LOCK_VARS_USED_GET')) { - foreach (session::global_get('LOCK_VARS_USED_GET') as $name => $value) { - $_GET[$name] = $value; - } + /* Set old Post data */ + if (session::global_is_set('LOCK_VARS_USED_GET')) { + foreach (session::global_get('LOCK_VARS_USED_GET') as $name => $value) { + $_GET[$name] = $value; } - if (session::global_is_set('LOCK_VARS_USED_POST')) { - foreach (session::global_get('LOCK_VARS_USED_POST') as $name => $value) { - $_POST[$name] = $value; - } + } + if (session::global_is_set('LOCK_VARS_USED_POST')) { + foreach (session::global_get('LOCK_VARS_USED_POST') as $name => $value) { + $_POST[$name] = $value; } - if (session::global_is_set('LOCK_VARS_USED_REQUEST')) { - foreach (session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value) { - $_REQUEST[$name] = $value; - } + } + if (session::global_is_set('LOCK_VARS_USED_REQUEST')) { + foreach (session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value) { + $_REQUEST[$name] = $value; } } } diff --git a/include/class_IconTheme.inc b/include/class_IconTheme.inc index f0482a04e..5fdb279f7 100644 --- a/include/class_IconTheme.inc +++ b/include/class_IconTheme.inc @@ -202,6 +202,7 @@ class IconTheme /* We store themes in the session. To do otherwise, override these methods. */ static public $session_var = 'IconThemes'; + static public function loadThemes($path) { $themes = array(); @@ -222,6 +223,7 @@ class IconTheme } $_SESSION[static::$session_var] = $themes; } + static public function findThemeIcon($theme, $context, $icon, $size) { if (!isset($_SESSION[static::$session_var])) { @@ -232,11 +234,11 @@ class IconTheme } return $_SESSION[static::$session_var][static::$default_theme]->FindIcon($context, $icon, $size); } + public function findTheme($theme) { if (isset($_SESSION[static::$session_var][$theme])) { - $ret = &$_SESSION[static::$session_var][$theme]; - return $ret; + return $_SESSION[static::$session_var][$theme]; } return NULL; } diff --git a/include/class_config.inc b/include/class_config.inc index 579e3f612..6847484d6 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -45,8 +45,8 @@ class config var $current = array(); /* Link to LDAP-server */ - var $ldap = NULL; - var $referrals = array(); + protected $ldapLink = NULL; + var $referrals = array(); /* * \brief Configuration data @@ -96,10 +96,9 @@ class config /* Check if class_location.inc has changed, this is the case if we have installed or removed plugins. */ $tmp = stat(CACHE_DIR.'/'.CLASS_CACHE); - if (session::global_is_set('class_location.inc:timestamp')) { - if ($tmp['mtime'] != session::global_get('class_location.inc:timestamp')) { - session::global_un_set('plist'); - } + if (session::global_is_set('class_location.inc:timestamp') + && ($tmp['mtime'] != session::global_get('class_location.inc:timestamp'))) { + session::global_un_set('plist'); } session::global_set('class_location.inc:timestamp', $tmp['mtime']); @@ -313,23 +312,23 @@ class config */ function get_ldap_link($sizelimit = FALSE) { - if ($this->ldap === NULL || !is_resource($this->ldap->cid)) { + if ($this->ldapLink === NULL || !is_resource($this->ldapLink->cid)) { /* Build new connection */ - $this->ldap = ldap_init ($this->current['SERVER'], $this->current['BASE'], + $this->ldapLink = ldap_init ($this->current['SERVER'], $this->current['BASE'], $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD'])); /* Check for connection */ - if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)) { + if (is_null($this->ldapLink) || (is_int($this->ldapLink) && $this->ldapLink == 0)) { msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG); exit(); } /* Move referrals */ if (!isset($this->current['REFERRAL'])) { - $this->ldap->referrals = array(); + $this->ldapLink->referrals = array(); } else { - $this->ldap->referrals = $this->current['REFERRAL']; + $this->ldapLink->referrals = $this->current['REFERRAL']; } if (!session::global_is_set('size_limit')) { @@ -338,7 +337,7 @@ class config } } - $obj = new ldapMultiplexer($this->ldap); + $obj = new ldapMultiplexer($this->ldapLink); if ($sizelimit) { $obj->set_size_limit(session::global_get('size_limit')); } else { @@ -454,13 +453,12 @@ class config } /* If no samba servers are found, look for configured sid/ridbase */ - if (count($this->data['SERVERS']['SAMBA']) == 0) { - if (isset($this->current['SAMBASID']) && isset($this->current['SAMBARIDBASE'])) { - $this->data['SERVERS']['SAMBA']['DEFAULT'] = array( - 'SID' => $this->get_cfg_value('SAMBASID'), - 'RIDBASE' => $this->get_cfg_value('SAMBARIDBASE') - ); - } + if ((count($this->data['SERVERS']['SAMBA']) == 0) + && isset($this->current['SAMBASID']) && isset($this->current['SAMBARIDBASE'])) { + $this->data['SERVERS']['SAMBA']['DEFAULT'] = array( + 'SID' => $this->get_cfg_value('SAMBASID'), + 'RIDBASE' => $this->get_cfg_value('SAMBARIDBASE') + ); } } @@ -475,10 +473,9 @@ class config if (!$forceReload) { $ldap = $this->get_ldap_link(); $ldap->cat($dn, array('fusionConfigMd5')); - if ($attrs = $ldap->fetch()) { - if (isset($attrs['fusionConfigMd5'][0]) && ($attrs['fusionConfigMd5'][0] == md5_file(CACHE_DIR.'/'.CLASS_CACHE))) { - return; - } + if (($attrs = $ldap->fetch()) && isset($attrs['fusionConfigMd5'][0]) + && ($attrs['fusionConfigMd5'][0] == md5_file(CACHE_DIR.'/'.CLASS_CACHE))) { + return; } } diff --git a/include/class_filter.inc b/include/class_filter.inc index b578e7930..95d52598c 100644 --- a/include/class_filter.inc +++ b/include/class_filter.inc @@ -301,33 +301,33 @@ class filter return $this->alphabet; } - $characters = _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); - $alphabet = ""; - $c = 0; + $characters = _('*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); + $this->alphabet = ''; + $c = 0; /* Fill cells with charaters */ for ($i = 0, $l = mb_strlen($characters, 'UTF8'); $i < $l; $i++) { if ($c == 0) { - $alphabet .= "<tr>"; + $this->alphabet .= "<tr>"; } - $ch = mb_substr($characters, $i, 1, "UTF8"); - $alphabet .= "<td><a class=\"alphaselect\" href=\"main.php?plug=". + $ch = mb_substr($characters, $i, 1, "UTF8"); + $this->alphabet .= "<td><a class=\"alphaselect\" href=\"main.php?plug=". validate($_GET['plug'])."&filter=".$ch."\"> ".$ch." </a></td>"; if ($c++ == $columns) { - $alphabet .= "</tr>"; - $c = 0; + $this->alphabet .= "</tr>"; + $c = 0; } } /* Fill remaining cells */ while ($c++ <= $columns) { - $alphabet .= "<td> </td>"; + $this->alphabet .= "<td> </td>"; } /* Save alphabet */ - $this->alphabet = "<table width='100%'>$alphabet</table>"; + $this->alphabet = '<table width="100%">'.$this->alphabet.'</table>'; return $this->alphabet; } @@ -473,24 +473,24 @@ class filter } } - $objectStorage = $this->objectStorage; + $branches = $this->objectStorage; if (isset($this->elements['FILTERTEMPLATE']) && $this->elementValues['FILTERTEMPLATE']) { - $objectStorage = array_merge( - $objectStorage, + $branches = array_merge( + $branches, array_map( function ($oc) { return 'ou=templates,'.$oc; }, - $objectStorage + $branches ) ); } // Now call filter method and merge resulting entries. $result = array_merge($result, call_user_func(array($backend, 'query'), - $this, $this->base, $this->scope, $filter, $attributes, $this->category, $objectStorage)); + $this, $this->base, $this->scope, $filter, $attributes, $this->category, $branches)); } return $result; @@ -504,10 +504,9 @@ class filter function isValid() { foreach ($this->elements as $tag => $element) { - if (isset($element->regex)) { - if (!preg_match('/'.(string)$element->regex.'/', $this->elementValues[$tag])) { - return FALSE; - } + if (isset($element->regex) + && !preg_match('/'.(string)$element->regex.'/', $this->elementValues[$tag])) { + return FALSE; } } return TRUE; diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 1b367ca74..95c2d1807 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -252,7 +252,7 @@ class LDAP $this->connect(); } - $start = microtime(TRUE); + $startTime = microtime(TRUE); $this->clearResult($srp); switch (strtolower($scope)) { case 'base': @@ -271,14 +271,12 @@ class LDAP $this->hasres[$srp] = TRUE; /* Check if query took longer as specified in max_ldap_query_time */ - if ($this->max_ldap_query_time) { - $diff = microtime(TRUE) - $start; - if ($diff > $this->max_ldap_query_time) { - msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG); - } + $diff = microtime(TRUE) - $startTime; + if ($this->max_ldap_query_time && ($diff > $this->max_ldap_query_time)) { + msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG); } - $this->log("LDAP operation: time=".(microtime(TRUE) - $start)." operation=search('".$this->basedn."', '$filter')"); + $this->log("LDAP operation: time=".$diff." operation=search('".$this->basedn."', '$filter')"); return $this->sr[$srp]; } else { $this->error = "Could not connect to LDAP server"; @@ -653,15 +651,14 @@ class LDAP } $str = ""; - if (preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error(), $m)) { - if (isset($attrs['objectClass'])) { - $ocs = $attrs['objectClass']; - if (!is_array($ocs)) { - $ocs = array($ocs); - } - if (isset($ocs[$m[1]])) { - $str .= " - <b>objectClass: ".$ocs[$m[1]]."</b>"; - } + if (isset($attrs['objectClass']) + && preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error(), $m)) { + $ocs = $attrs['objectClass']; + if (!is_array($ocs)) { + $ocs = array($ocs); + } + if (isset($ocs[$m[1]])) { + $str .= " - <b>objectClass: ".$ocs[$m[1]]."</b>"; } } if ($error == "Undefined attribute type") { @@ -886,12 +883,17 @@ class LDAP return $this->error; } else { $adderror = $this->get_additional_error(); - if ($adderror != "") { - $error = $this->error." (".$this->get_additional_error().", ".sprintf(_("while operating on '%s' using LDAP server '%s'"), $this->basedn, $this->hostname).")"; + if ($adderror != '') { + return sprintf( + _('%s (%s, while operating on "%s" using LDAP server "%s")'), + $this->error, $adderror, $this->basedn, $this->hostname + ); } else { - $error = $this->error." (".sprintf(_("while operating on LDAP server %s"), $this->hostname).")"; + return sprintf( + _('%s (while operating on LDAP server "%s")'), + $this->error, $this->hostname + ); } - return $error; } } @@ -1191,17 +1193,17 @@ class LDAP } // Get base to look for schema - $sr = @ldap_read($this->cid, '', 'objectClass=*', array('subschemaSubentry')); - $attr = @ldap_get_entries($this->cid, $sr); - if (!isset($attr[0]['subschemasubentry'][0])) { + $res = @ldap_read($this->cid, '', 'objectClass=*', array('subschemaSubentry')); + $attrs = @ldap_get_entries($this->cid, $res); + if (!isset($attrs[0]['subschemasubentry'][0])) { return array(); } /* Get list of objectclasses and fill array */ - $nb = $attr[0]['subschemasubentry'][0]; + $nb = $attrs[0]['subschemasubentry'][0]; $objectclasses = array(); - $sr = ldap_read ($this->cid, $nb, 'objectClass=*', array('objectclasses')); - $attrs = ldap_get_entries($this->cid, $sr); + $res = ldap_read ($this->cid, $nb, 'objectClass=*', array('objectclasses')); + $attrs = ldap_get_entries($this->cid, $res); if (!isset($attrs[0])) { return array(); } @@ -1332,10 +1334,10 @@ class LDAP ldap_bind ($ds, $admin, $password); /* Get base to look for naming contexts */ - $sr = @ldap_read ($ds, '', 'objectClass=*', array('namingContexts')); - $attr = @ldap_get_entries($ds, $sr); + $res = @ldap_read ($ds, '', 'objectClass=*', array('namingContexts')); + $attrs = @ldap_get_entries($ds, $res); - return $attr[0]['namingcontexts']; + return $attrs[0]['namingcontexts']; } } ?> diff --git a/include/class_listing.inc b/include/class_listing.inc index e5bbeaf87..168eceb93 100644 --- a/include/class_listing.inc +++ b/include/class_listing.inc @@ -57,7 +57,7 @@ class listing protected $objectDnMapping = array(); protected $copyPasteHandler = NULL; protected $snapshotHandler = NULL; - var $exporter = array(); + var $exporters = array(); var $exportColumns = array(); var $scrollPosition = 0; var $baseSelector; @@ -112,7 +112,7 @@ class listing if (preg_match('/Exporter$/', $class)) { $info = call_user_func(array($class, "getInfo")); if ($info != NULL) { - $this->exporter = array_merge($this->exporter, $info); + $this->exporters = array_merge($this->exporters, $info); } } } @@ -166,7 +166,7 @@ class listing $this->filter = $filter; $filter->headpage = $this; if ($this->departmentBrowser) { - $this->departments = $this->getDepartments(); + $this->refreshDepartmentsCache(); } $this->filter->setBase($this->base); } @@ -537,29 +537,26 @@ class listing } // Override the base if we got a message from the browser navigation - if ($this->departmentBrowser && isset($_GET['act'])) { - if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)) { - if (isset($this->departments[$match[1]])) { - $this->setBase($this->departments[$match[1]]['dn']); - } - } + if ($this->departmentBrowser && isset($_GET['act']) + && preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match) + && isset($this->departments[$match[1]])) { + $this->setBase($this->departments[$match[1]]['dn']); } // Filter POST with "act" attributes -> posted from action menu - if (isset($_POST['exec_act']) && $_POST['act'] != '') { - if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) { - $exporter = $this->exporter[$_POST['act']]; - $userinfo = ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S'); - $entryIterator = new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType); - $sortedEntries = array(); - foreach ($entryIterator as $entry) { - $sortedEntries[] = $entry; - } - $instance = new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns); - $type = call_user_func(array($exporter['class'], "getInfo")); - $type = $type[$_POST['act']]; - send_binary_content($instance->query(), $type['filename'], $type = $type['mime']); + if (isset($_POST['exec_act']) && ($_POST['act'] != '') + && preg_match('/^export.*$/', $_POST['act']) && isset($this->exporters[$_POST['act']])) { + $exporter = $this->exporters[$_POST['act']]; + $userinfo = ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S'); + $entryIterator = new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType); + $sortedEntries = array(); + foreach ($entryIterator as $entry) { + $sortedEntries[] = $entry; } + $instance = new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns); + $type = call_user_func(array($exporter['class'], "getInfo")); + $type = $type[$_POST['act']]; + send_binary_content($instance->query(), $type['filename'], $type = $type['mime']); } // Filter GET with "act" attributes @@ -594,8 +591,7 @@ class listing $deps = $ui->get_module_departments($this->categories); $this->setBase($deps[0]); } elseif ($action == 'BACK') { - $base = preg_replace('/^[^,]+,/', '', $this->base); - $this->tryAndSetBase($base); + $this->tryAndSetBase(preg_replace('/^[^,]+,/', '', $this->base)); } elseif ($action == 'HOME') { $this->tryAndSetBase(get_base_from_people($ui->dn)); } @@ -604,7 +600,7 @@ class listing // Reload departments if ($this->departmentBrowser) { - $this->departments = $this->getDepartments(); + $this->refreshDepartmentsCache(); } // Update filter and refresh entries @@ -765,11 +761,10 @@ class listing foreach ($matches as $match) { $cl = ''; $method = ''; - if (!preg_match('/^(.*)::(.*)$/', $match[1][0], $m)) { - if (!isset($this->filters[$match[1][0]]) || !preg_match('/^(.*)::(.*)$/', $this->filters[$match[1][0]], $m)) { - trigger_error('Unknown filter '.$match[1][0]); - continue; - } + if (!preg_match('/^(.*)::(.*)$/', $match[1][0], $m) + && (!isset($this->filters[$match[1][0]]) || !preg_match('/^(.*)::(.*)$/', $this->filters[$match[1][0]], $m))) { + trigger_error('Unknown filter '.$match[1][0]); + continue; } $cl = $m[1]; $method = $m[2]; @@ -1094,7 +1089,6 @@ class listing */ function filterLink($row, $dn, $mask, ...$vals) { - $pid = $this->pid; $params = array($mask); // Collect sprintf params @@ -1119,7 +1113,7 @@ class listing if (count($params) > 1) { $trans = sprintf(...$params); if ($trans != '') { - return '<a href="?plug='.$_GET['plug'].'&PID='.$pid.'&act=listing_edit_'.$row.'" title="'.$dn.'">'.$trans.'</a>'; + return '<a href="?plug='.$_GET['plug'].'&PID='.$this->pid.'&act=listing_edit_'.$row.'" title="'.$dn.'">'.$trans.'</a>'; } } @@ -1217,10 +1211,9 @@ class listing /* Detect the longer base valid for this dn */ $longerBase = ''; foreach (array_keys($this->bases) as $base) { - if (preg_match('/'.preg_quote($base, '/').'$/i', $dn)) { - if (strlen($base) > strlen($longerBase)) { - $longerBase = $base; - } + if (preg_match('/'.preg_quote($base, '/').'$/i', $dn) + && (strlen($base) > strlen($longerBase))) { + $longerBase = $base; } } $this->setBase($longerBase); @@ -1286,10 +1279,9 @@ class listing } // Filter POST with "act" attributes -> posted from action menu - if (isset($_POST['act']) && $_POST['act'] != '') { - if (!preg_match('/^export.*$/', $_POST['act'])) { - $result['action'] = validate($_POST['act']); - } + if (isset($_POST['act']) && ($_POST['act'] != '') + && !preg_match('/^export.*$/', $_POST['act'])) { + $result['action'] = validate($_POST['act']); } // Drop targets if empty @@ -1554,19 +1546,20 @@ class listing } } - /*! \brief Get the departments */ - function getDepartments() + /*! \brief Cache the departments */ + function refreshDepartmentsCache() { - $departments = array(); $ui = get_userinfo(); + $this->departments = array(); + // Get list of supported department types $types = departmentManagement::getDepartmentTypes(); // Load departments allowed by ACL $validDepartments = $ui->get_module_departments($this->categories); - /* Fetch departments andtheir informations */ + /* Fetch departments and their informations */ foreach ($types as $type) { $i = objects::infos($type); $deps = objects::ls( @@ -1602,11 +1595,9 @@ class listing $department['sort-attribute'] = $i['mainAttr']; // Move to the result list - $departments[] = $department; + $this->departments[] = $department; } } - - return $departments; } @@ -1731,7 +1722,7 @@ class listing $result .= "<li$separator id='actionmenu_exportList'><a href='#'><img class='center' src='geticon.php?context=actions&icon=document-export&size=16' alt='export'> "._("Export list")." <img src='images/forward-arrow.png' alt='arrow'></a><ul class='level3'>"; // Render export actions - foreach ($this->exporter as $action => $exporter) { + foreach ($this->exporters as $action => $exporter) { $result .= $this->renderActionMenuActionLink('', $action, $exporter['label'], $exporter['image']); } diff --git a/include/class_listingSortIterator.inc b/include/class_listingSortIterator.inc index ab37ff1ab..f4b666d65 100644 --- a/include/class_listingSortIterator.inc +++ b/include/class_listingSortIterator.inc @@ -76,11 +76,6 @@ class listingSortIterator implements Iterator { // Take a look at the several types switch ($type) { - // Sort for string by default - default: - case 'string': - return strcoll($a, $b); - case 'department': return strnatcmp($a, $b); @@ -109,6 +104,11 @@ class listingSortIterator implements Iterator { } } return 0; + + // Sort for string by default + case 'string': + default: + return strcoll($a, $b); } } ); diff --git a/include/class_objects.inc b/include/class_objects.inc index 6c1459599..7fc6b55fd 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -408,10 +408,9 @@ class objects if ($ldap->count() != 0) { while ($attrs = $ldap->fetch()) { $dn = $attrs['dn']; - if ($requiredPermissions != '') { - if (!preg_match('/'.$requiredPermissions.'/', $ui->get_permissions($dn, $infos['aclCategory'].'/'.'template'))) { - continue; - } + if (($requiredPermissions != '') + && !preg_match('/'.$requiredPermissions.'/', $ui->get_permissions($dn, $infos['aclCategory'].'/'.'template'))) { + continue; } $templates[$dn] = $attrs['cn'][0].' - '.$key; } diff --git a/include/class_pluglist.inc b/include/class_pluglist.inc index a3a45571a..8b83ec7ce 100644 --- a/include/class_pluglist.inc +++ b/include/class_pluglist.inc @@ -408,10 +408,9 @@ class pluglist { /* Parse headlines */ foreach ($config->data['SECTIONS'] as $section => $section_infos) { - $entries = ''; - $menu = ''; - $menu = '<div class="iconmenu-section"><h1 class="menuheader">'; - $menu .= $section_infos['NAME']."</h1>\n"; + $entries = ''; + $sectionMenu = '<div class="iconmenu-section"><h1 class="menuheader">'; + $sectionMenu .= $section_infos['NAME']."</h1>\n"; foreach ($config->data['MENU'][$section] as $info) { if (!$this->check_access($info)) { @@ -445,7 +444,7 @@ class pluglist { /* Append to menu */ if ($entries != "") { - $this->iconmenu .= $menu.$entries."</div>\n"; + $this->iconmenu .= $sectionMenu.$entries."</div>\n"; } } } diff --git a/include/class_session.inc b/include/class_session.inc index e54a922a2..28f052c12 100644 --- a/include/class_session.inc +++ b/include/class_session.inc @@ -117,9 +117,8 @@ class session { } /* Global fallback if not set */ - if ($channel == "") { - $ret = &$_SESSION[$name]; - return $ret; + if ($channel == '') { + return $_SESSION[$name]; } /* Sanity check */ @@ -128,9 +127,7 @@ class session { exit; } - $channel = "gch_".$channel; - $ret = &$_SESSION[$channel][$name]; - return $ret; + return $_SESSION['gch_'.$channel][$name]; } /*! @@ -154,8 +151,7 @@ class session { */ public static function &global_get_ref($name) { - $ret = &$_SESSION[$name]; - return $ret; + return $_SESSION[$name]; } /*! @@ -260,14 +256,5 @@ class session { { @session_destroy(); } - - /*! - * \brief Get all sessions - */ - public static function &get_all() - { - $ret = &$_SESSION; - return $ret; - } } ?> diff --git a/include/class_template.inc b/include/class_template.inc index f5897d3d7..58517ba1c 100644 --- a/include/class_template.inc +++ b/include/class_template.inc @@ -140,19 +140,19 @@ class template function serialize() { - $attributes = array(); + $ret = array(); foreach ($this->tabObject->by_object as $class => $plugin) { if (!isset($this->attributes[$class])) { continue; } - $attributes[$class] = array('name' => $this->tabObject->by_name[$class], 'attrs' => array()); + $ret[$class] = array('name' => $this->tabObject->by_name[$class], 'attrs' => array()); foreach ($this->attributes[$class] as $attr) { - $plugin->attributesAccess[$attr]->serializeAttribute($attributes[$class]['attrs'], FALSE); + $plugin->attributesAccess[$attr]->serializeAttribute($ret[$class]['attrs'], FALSE); } - $attributes[$class]['attrs_order'] = array_keys($attributes[$class]['attrs']); + $ret[$class]['attrs_order'] = array_keys($ret[$class]['attrs']); } - return $attributes; + return $ret; } function deserialize($values) @@ -197,19 +197,19 @@ class template return $dialogResult; } } - $attributes = array(); + $attributesRendered = array(); foreach ($this->attributes[$class] as $attr) { if ($plugin->attributesAccess[$attr]->getAclInfo() !== FALSE) { // We assign ACLs so that attributes can use them in their template code $smarty->assign($plugin->attributesAccess[$attr]->getAcl().'ACL', $plugin->aclGetPermissions($plugin->attributesAccess[$attr]->getAcl())); } - $plugin->attributesAccess[$attr]->renderAttribute($attributes, FALSE); + $plugin->attributesAccess[$attr]->renderAttribute($attributesRendered, FALSE); } $smarty->assign('section', $class); $smarty->assign('sectionId', $class); $smarty->assign('sectionClasses', ' fullwidth'); - $smarty->assign('attributes', $attributes); + $smarty->assign('attributes', $attributesRendered); $posted[] = $class.'_posted'; $sections[] = $smarty->fetch(get_template_path('simpleplugin_section.tpl')); diff --git a/include/class_tests.inc b/include/class_tests.inc index 5cbfc410b..2dc73fdf8 100644 --- a/include/class_tests.inc +++ b/include/class_tests.inc @@ -268,16 +268,10 @@ class tests */ public static function is_email($address) { - if ($address == "") { - return TRUE; - } - if (filter_var($address, FILTER_VALIDATE_EMAIL) !== FALSE) { - return TRUE; - } elseif (filter_var($address.'.com', FILTER_VALIDATE_EMAIL) !== FALSE) { - /* this is to allow addresses like example@localhost, which are refused by some PHP version */ - return TRUE; - } - return FALSE; + /* last test is to allow addresses like example@localhost, which are refused by some PHP version */ + return (($address == '') + || (filter_var($address, FILTER_VALIDATE_EMAIL) !== FALSE) + || (filter_var($address.'.com', FILTER_VALIDATE_EMAIL) !== FALSE)); } @@ -293,12 +287,8 @@ class tests global $config; $reservedNames = array(); foreach ($config->data['OBJECTS'] as $infos) { - if (isset($infos['ou'])) { - if ($infos['ou'] != '') { - if (preg_match('/ou=([^,]+),$/', $infos['ou'], $m)) { - $reservedNames[] = $m[1]; - } - } + if (isset($infos['ou']) && preg_match('/ou=([^,]+),$/', $infos['ou'], $m)) { + $reservedNames[] = $m[1]; } } diff --git a/include/class_userinfo.inc b/include/class_userinfo.inc index 53cc3d771..7663f3441 100644 --- a/include/class_userinfo.inc +++ b/include/class_userinfo.inc @@ -900,27 +900,20 @@ class userinfo // Check if the account has reached its kick off limitations. // ---------------------------------------------------------- // Once the accout reaches the kick off limit it has expired. - if ($sambaKickoffTime !== NULL) { - if (time() >= $sambaKickoffTime) { - return POSIX_ACCOUNT_EXPIRED; - } + if (($sambaKickoffTime !== NULL) && (time() >= $sambaKickoffTime)) { + return POSIX_ACCOUNT_EXPIRED; } // Check if the account has expired. // --------------------------------- - // An account is locked/expired once its expiration date has reached (shadowExpire). + // An account is locked/expired once its expiration date was reached (shadowExpire). // If the optional attribute (shadowInactive) is set, we've to postpone // the account expiration by the amount of days specified in (shadowInactive). - if (($shadowExpire != NULL) && ($shadowExpire <= $current)) { - - // The account seems to be expired, but we've to check 'shadowInactive' additionally. - // ShadowInactive specifies an amount of days we've to reprieve the user. - // It some kind of x days' grace. - if (($shadowInactive == NULL) || $current > $shadowExpire + $shadowInactive) { - - // Finally we've detect that the account is deactivated. - return POSIX_ACCOUNT_EXPIRED; - } + // ShadowInactive specifies an amount of days we've to reprieve the user. + // It some kind of x days' grace. + if (($shadowExpire != NULL) && ($shadowExpire <= $current) + && (($shadowInactive == NULL) || ($current > $shadowExpire + $shadowInactive))) { + return POSIX_ACCOUNT_EXPIRED; } // The users password is going to expire. @@ -930,18 +923,12 @@ class userinfo // The user has to be warned, if the days left till expiration, match the // configured warning period (shadowWarning) // --> shadowWarning: Warn x days before account expiration. - if (($shadowExpire != NULL) && ($shadowWarning != NULL)) { - - // Check if the account is still active and not already expired. - if ($shadowExpire >= $current) { - - // Check if we've to warn the user by comparing the remaining - // number of days till expiration with the configured amount - // of days in shadowWarning. - if (($shadowExpire - $current) <= $shadowWarning) { - return POSIX_WARN_ABOUT_EXPIRATION; - } - } + // Check if the account is still active and not already expired. + // Check if we've to warn the user by comparing the remaining + // number of days till expiration with the configured amount of days in shadowWarning. + if (($shadowExpire != NULL) && ($shadowWarning != NULL) + && ($shadowExpire >= $current) && ($shadowExpire <= $current + $shadowWarning)) { + return POSIX_WARN_ABOUT_EXPIRATION; } // -- I guess this is the correct detection, isn't it? @@ -959,11 +946,10 @@ class userinfo // The age of the current password (shadowLastChange) plus the maximum // amount amount of days (shadowMax) has to be smaller than the // current timestamp. - if (($shadowLastChange != NULL) && ($shadowMax != NULL)) { - // Check if we've an outdated password. - if ($current >= ($shadowLastChange + $shadowMax)) { - return POSIX_FORCE_PASSWORD_CHANGE; - } + // Check if we've an outdated password. + if (($shadowLastChange != NULL) && ($shadowMax != NULL) + && ($current >= $shadowLastChange + $shadowMax)) { + return POSIX_FORCE_PASSWORD_CHANGE; } // Check if we've to freeze the users password. @@ -971,11 +957,10 @@ class userinfo // Once a user has changed his password, he cannot change it again // for a given amount of days (shadowMin). // We should not allow to change the password within FusionDirectory too. - if (($shadowLastChange != NULL) && ($shadowMin != NULL)) { - // Check if we've an outdated password. - if (($shadowLastChange + $shadowMin) >= $current) { - return POSIX_DISALLOW_PASSWORD_CHANGE; - } + // Check if we've an outdated password. + if (($shadowLastChange != NULL) && ($shadowMin != NULL) + && ($shadowLastChange + $shadowMin >= $current)) { + return POSIX_DISALLOW_PASSWORD_CHANGE; } return 0; diff --git a/include/functions.inc b/include/functions.inc index 9cee2767f..d95f36666 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -1029,8 +1029,7 @@ function get_ou($name) if ($config->get_cfg_value($name, '_not_set_') != '_not_set_') { $ou = $config->get_cfg_value($name); } elseif (isset($map[$name])) { - $ou = $map[$name]; - return $ou; + return $map[$name]; } else { return NULL; } @@ -2365,9 +2364,7 @@ function isIpInNet($ip, $net, $mask) function expandIPv6 ($ip) { $hex = unpack('H*hex', inet_pton($ip)); - $ip = substr(preg_replace('/([A-f0-9]{4})/', "$1:", $hex['hex']), 0, -1); - - return $ip; + return substr(preg_replace('/([A-f0-9]{4})/', "$1:", $hex['hex']), 0, -1); } /* Mark the occurance of a string with a span */ diff --git a/include/functions_debug.inc b/include/functions_debug.inc index d7447e3c2..76d2803dc 100644 --- a/include/functions_debug.inc +++ b/include/functions_debug.inc @@ -151,10 +151,6 @@ class printAClass { case 'array': break; - case 'object': - $key_style = 'color:#FF9B2F;'; - break; - case 'integer': $value_style = 'color:green;'; break; @@ -182,6 +178,11 @@ class printAClass { $value = nl2br(htmlspecialchars($value)); } break; + + case 'object': + default: + $key_style = 'color:#FF9B2F;'; + break; } $this->output .= '<tr>'; @@ -260,11 +261,10 @@ function _script_globals() $varcount = 0; foreach ($GLOBALS as $GLOBALS_current_key => $GLOBALS_current_value) { - if (++$varcount > $GLOBALS_initial_count) { - /* die wollen wir nicht! */ - if ($GLOBALS_current_key != 'HTTP_SESSION_VARS' && $GLOBALS_current_key != '_SESSION') { - $script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value; - } + if ((++$varcount > $GLOBALS_initial_count) + && ($GLOBALS_current_key != 'HTTP_SESSION_VARS') + && ($GLOBALS_current_key != '_SESSION')) { + $script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value; } } diff --git a/include/management/class_management.inc b/include/management/class_management.inc index b79416f5f..43fa5ef8b 100644 --- a/include/management/class_management.inc +++ b/include/management/class_management.inc @@ -731,10 +731,9 @@ class management // Open object $this->openTabObject(objects::open($this->dn, $entry->getTemplatedType()), $this->dn); @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Edit entry initiated'); - if (isset($action['subaction'])) { - if ($this->handleSubAction($action) === FALSE) { - trigger_error('Was not able to handle subaction: '.$action['subaction']); - } + if (isset($action['subaction']) + && ($this->handleSubAction($action) === FALSE)) { + trigger_error('Was not able to handle subaction: '.$action['subaction']); } } diff --git a/include/management/columns/class_Column.inc b/include/management/columns/class_Column.inc index 66b0e9de3..5833b0a49 100644 --- a/include/management/columns/class_Column.inc +++ b/include/management/columns/class_Column.inc @@ -106,12 +106,12 @@ class Column function renderCell(ListingEntry $entry) { - $attribute = $this->attribute; + $attr = $this->attribute; if (isset($this->templateAttribute) && $entry->isTemplate()) { - $attribute = $this->templateAttribute; + $attr = $this->templateAttribute; } - if (isset($attribute) && isset($entry[$attribute])) { - return htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8'); + if (isset($attr) && isset($entry[$attr])) { + return htmlentities($entry[$attr], ENT_COMPAT, 'UTF-8'); } else { return ' '; } @@ -119,12 +119,12 @@ class Column function getRawExportValue(ListingEntry $entry) { - $attribute = $this->attribute; + $attr = $this->attribute; if (isset($this->templateAttribute) && $entry->isTemplate()) { - $attribute = $this->templateAttribute; + $attr = $this->templateAttribute; } - if (isset($attribute) && isset($entry[$attribute])) { - return $entry[$attribute]; + if (isset($attr) && isset($entry[$attr])) { + return $entry[$attr]; } else { return ''; } @@ -158,11 +158,6 @@ class Column // Take a look at the several types switch ($this->type) { - // Sort for string by default - default: - case 'string': - return strcoll($a, $b); - case 'department': return strnatcmp($a, $b); @@ -191,6 +186,11 @@ class Column } } return 0; + + // Sort for string by default + case 'string': + default: + return strcoll($a, $b); } } } diff --git a/include/management/columns/class_PropertiesColumn.inc b/include/management/columns/class_PropertiesColumn.inc index 502b701e5..a3ff9aae7 100644 --- a/include/management/columns/class_PropertiesColumn.inc +++ b/include/management/columns/class_PropertiesColumn.inc @@ -54,8 +54,8 @@ class PropertiesColumn extends Column function fillNeededAttributes(array &$attrs) { - foreach ($this->tabs as $type => $tabs) { - foreach ($tabs as $class) { + foreach ($this->tabs as $classes) { + foreach ($classes as $class) { $class::fillAccountAttrsNeeded($attrs); } } diff --git a/include/password-methods/class_password-methods-smd5.inc b/include/password-methods/class_password-methods-smd5.inc index 96d56b3b6..de2ed413a 100644 --- a/include/password-methods/class_password-methods-smd5.inc +++ b/include/password-methods/class_password-methods-smd5.inc @@ -58,8 +58,7 @@ class passwordMethodsmd5 extends passwordMethod mt_srand(microtime() * 10000000); $salt0 = substr(pack('h*', md5(mt_rand())), 0, 8); $salt = substr(pack('H*', md5($salt0 . $pwd)), 0, 4); - $hash = '{SMD5}'.base64_encode(pack('H*', md5($pwd . $salt)) . $salt); - return $hash; + return '{SMD5}'.base64_encode(pack('H*', md5($pwd . $salt)) . $salt); } function checkPassword($pwd, $hash) diff --git a/include/password-methods/class_password-methods-ssha.inc b/include/password-methods/class_password-methods-ssha.inc index fa386d7aa..0f2bd5cb4 100644 --- a/include/password-methods/class_password-methods-ssha.inc +++ b/include/password-methods/class_password-methods-ssha.inc @@ -59,7 +59,6 @@ class passwordMethodssha extends passwordMethod $salt = substr(pack('h*', md5(mt_rand())), 0, 8); $salt = substr(pack('H*', sha1($salt.$pwd)), 0, 4); $pwd = '{SSHA}'.base64_encode(pack('H*', sha1($pwd.$salt)).$salt); - return $pwd; } elseif (function_exists('mhash')) { $salt = mhash_keygen_s2k(MHASH_SHA1, $pwd, substr(pack('h*', md5(mt_rand())), 0, 8), 4); $pwd = '{SSHA}'.base64_encode(mhash(MHASH_SHA1, $pwd.$salt).$salt); diff --git a/include/password-methods/class_password-methods.inc b/include/password-methods/class_password-methods.inc index efbf1a119..8bb4a12ce 100644 --- a/include/password-methods/class_password-methods.inc +++ b/include/password-methods/class_password-methods.inc @@ -29,7 +29,6 @@ */ class passwordMethod { - var $attrs = array(); var $display = FALSE; var $hash = ''; @@ -95,8 +94,6 @@ class passwordMethod if (isset($attrs['userPassword'][0])) { $pwd = $attrs['userPassword'][0]; } - } elseif (isset($this->attrs['userPassword'][0])) { - $pwd = $this->attrs['userPassword'][0]; } return preg_match("/^[^\}]*+\}!/", $pwd); } @@ -138,17 +135,16 @@ class passwordMethod } /* Get current password hash */ - $attrs = $this->attrs; $pwd = ''; $ldap = $config->get_ldap_link(); $ldap->cd($config->current['BASE']); if (!empty($dn)) { $ldap->cat($dn); $attrs = $ldap->fetch(); - } - if (isset($attrs['userPassword'][0])) { - $pwd = $attrs['userPassword'][0]; - $dn = $attrs['dn']; + if (isset($attrs['userPassword'][0])) { + $pwd = $attrs['userPassword'][0]; + $dn = $attrs['dn']; + } } /* We can only lock/unlock non-empty passwords */ diff --git a/include/php_setup.inc b/include/php_setup.inc index 2cc4a09bc..3bb7ba0b9 100644 --- a/include/php_setup.inc +++ b/include/php_setup.inc @@ -179,11 +179,9 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline) } /* Hide ldap size limit messages */ - if (preg_match('/ldap_error/', $errstr)) { - if (preg_match('/sizelimit/', $errstr)) { - set_error_handler('gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT); - return; - } + if (preg_match('/ldap_error/', $errstr) && preg_match('/sizelimit/', $errstr)) { + set_error_handler('gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT); + return; } /* Error messages are hidden in FusionDirectory, so we only send them to the logging class and abort here */ diff --git a/include/simpleplugin/attributes/class_CompositeAttribute.inc b/include/simpleplugin/attributes/class_CompositeAttribute.inc index 22f06fadb..03bae4ca5 100644 --- a/include/simpleplugin/attributes/class_CompositeAttribute.inc +++ b/include/simpleplugin/attributes/class_CompositeAttribute.inc @@ -188,14 +188,13 @@ class CompositeAttribute extends Attribute function getArrayValue () { - $values = array_map( + return array_map( function ($a) { return $a->displayValue($a->getValue()); }, $this->attributes ); - return $values; } function check () diff --git a/include/simpleplugin/attributes/class_FileAttribute.inc b/include/simpleplugin/attributes/class_FileAttribute.inc index 181f2dfa7..e3b11b58a 100644 --- a/include/simpleplugin/attributes/class_FileAttribute.inc +++ b/include/simpleplugin/attributes/class_FileAttribute.inc @@ -182,7 +182,7 @@ class FileDownloadAttribute extends FileAttribute function renderAttribute(array &$attributes, $readOnly) { - if ($this->upload == FALSE) { + if ($this->upload === FALSE) { parent::renderAttribute($attributes, FALSE); } else { parent::renderAttribute($attributes, $readOnly); @@ -289,11 +289,9 @@ class ImageAttribute extends FileAttribute $id = $this->getHtmlId(); if (!$this->disabled && $this->isVisible()) { foreach (array_keys($_POST) as $name) { - if (!$this->isRequired()) { - if (preg_match('/^'.$id.'_remove_/', $name)) { - $this->setPostValue(''); - break; - } + if (!$this->isRequired() && preg_match('/^'.$id.'_remove_/', $name)) { + $this->setPostValue(''); + break; } if (preg_match('/^'.$id.'_upload_/', $name)) { parent::loadPostValue(); diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc index f0210f383..330239bfd 100644 --- a/include/simpleplugin/attributes/class_SetAttribute.inc +++ b/include/simpleplugin/attributes/class_SetAttribute.inc @@ -583,13 +583,11 @@ class OrderedArrayAttribute extends SetAttribute return TRUE; } } - if ($this->edit_enabled) { - if (preg_match('/^'.$id.'_edit_/', $postValue)) { - $key = preg_replace('/^'.$id.'_edit_/', '', $postValue); - $key = preg_replace('/_[xy]$/', '', $key); - $this->handleEdit($key); - return TRUE; - } + if ($this->edit_enabled && preg_match('/^'.$id.'_edit_/', $postValue)) { + $key = preg_replace('/^'.$id.'_edit_/', '', $postValue); + $key = preg_replace('/_[xy]$/', '', $key); + $this->handleEdit($key); + return TRUE; } if (preg_match('/^'.$id.'_del_/', $postValue)) { $key = preg_replace('/^'.$id.'_del_/', '', $postValue); diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc index 13247b422..7ac980eaf 100644 --- a/include/simpleplugin/class_simpleTabs.inc +++ b/include/simpleplugin/class_simpleTabs.inc @@ -203,16 +203,15 @@ class simpleTabs } unset($obj); + /* Build tab line */ + $display = $this->gen_tabs($this->dialogOpened()); + /* Show object */ - $display = '<div class="tab-content">'."\n"; + $display .= '<div class="tab-content">'."\n"; $display .= $this->by_object[$this->current]->execute(); - /* Build tab line */ - $tabs = $this->gen_tabs($this->dialogOpened()); - - /* Footer for tabbed dialog */ - $display = $tabs.$display.'</div>'; + $display .= '</div>'; return $display; } @@ -254,11 +253,9 @@ class simpleTabs $style = array('tab-left', 'tab-active', 'tab-right'); foreach ($this->by_name as $class => $name) { - /* Activate right tabs with style "tab-right" */ - if ($index == 1) { - $index++; - } elseif ($class == $this->current) { - /* Activate current tab with style "tab-active " */ + /* Activate right tabs with style "tab-right" + * Activate current tab with style "tab-active " */ + if (($index == 1) || ($class == $this->current)) { $index++; } diff --git a/plugins/addons/dashboard/class_dashBoardUsers.inc b/plugins/addons/dashboard/class_dashBoardUsers.inc index 3a3f72c95..9bff36861 100644 --- a/plugins/addons/dashboard/class_dashBoardUsers.inc +++ b/plugins/addons/dashboard/class_dashBoardUsers.inc @@ -122,9 +122,9 @@ class dashboardUsers extends simplePlugin sprintf(_('Group statistics could not be computed because of the following LDAP error: %s'), $e->getMessage()), ERROR_DIALOG ); - $nb_groups = 0; - $nb_mail_groups = 0; - $nb_samba_accounts = 0; + $nb_groups = 0; + $nb_mail_groups = 0; + $nb_samba_groups = 0; } return array( diff --git a/plugins/admin/departments/class_department.inc b/plugins/admin/departments/class_department.inc index 319f1fc74..ddf29b177 100644 --- a/plugins/admin/departments/class_department.inc +++ b/plugins/admin/departments/class_department.inc @@ -168,10 +168,8 @@ class department extends simplePlugin $namingAttr = static::$namingAttr; - if ($namingAttr == 'ou') { - if (tests::is_department_name_reserved($this->$namingAttr)) { - $message[] = msgPool::reserved(_('Name')); - } + if (($namingAttr == 'ou') && tests::is_department_name_reserved($this->$namingAttr)) { + $message[] = msgPool::reserved(_('Name')); } return $message; diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index ca7d2351a..8632dcff0 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -36,11 +36,7 @@ class LockAction extends Action function isLocked(ListingEntry $entry) { if (isset($entry['userPassword']) && preg_match('/^\{[^\}]/', $entry['userPassword'])) { - if (preg_match('/^[^\}]*+\}!/', $entry['userPassword'])) { - return TRUE; - } else { - return FALSE; - } + return preg_match('/^[^\}]*+\}!/', $entry['userPassword']); } return NULL; } diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 30d80ddc1..575196e5e 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -532,9 +532,9 @@ class user extends simplePlugin function compute_dn() { global $config; + if ($this->is_template) { - $dn = 'cn='.ldap_escape_dn($this->_template_cn).',ou=templates,'.get_ou('userRDN').$this->base; - return $dn; + return 'cn='.ldap_escape_dn($this->_template_cn).',ou=templates,'.get_ou('userRDN').$this->base; } $this->update_cn(); @@ -683,10 +683,8 @@ class user extends simplePlugin return sprintf(_('You must wait %d seconds before changing your password again'), $policy['pwdMinAge'][0] - ($now->getTimeStamp() - $date->getTimeStamp())); } } - if (isset($policy['pwdSafeModify'][0]) && ($policy['pwdSafeModify'][0] == 'FALSE')) { - if (empty($current_password)) { - $current_password = NULL; - } + if (isset($policy['pwdSafeModify'][0]) && ($policy['pwdSafeModify'][0] == 'FALSE') && empty($current_password)) { + $current_password = NULL; } if (isset($attrs['pwdHistory'][0])) { unset($attrs['pwdHistory']['count']); diff --git a/setup/class_setup.inc b/setup/class_setup.inc index 10f15707a..e153c9a98 100644 --- a/setup/class_setup.inc +++ b/setup/class_setup.inc @@ -90,8 +90,7 @@ class setup $smarty->assign('usePrototype', 'true'); $this->o_steps[$this->i_previous]->set_active(FALSE); $this->o_steps[$this->i_current]->set_active(); - $content = $this->o_steps[$this->i_current]->execute(); - return $content; + return $this->o_steps[$this->i_current]->execute(); } diff --git a/setup/class_setupStepConfig.inc b/setup/class_setupStepConfig.inc index 55a472f16..6f823dea2 100644 --- a/setup/class_setupStepConfig.inc +++ b/setup/class_setupStepConfig.inc @@ -72,8 +72,7 @@ class setupStepConfig extends configInLdap function get_title() { - $infos = parent::plInfo(); - return $infos['plDescription']; + return $this->get_description(); } function get_description() -- GitLab