thomascube
2008-12-16 b9f9f185e76d725026e96068b6568d819b97c3ca
Simplify code

1 files modified
47 ■■■■■ changed files
program/include/rcube_ldap.php 47 ●●●●● patch | view | raw | blame | history
program/include/rcube_ldap.php
@@ -68,6 +68,8 @@
   */
  function connect()
  {
    global $RCMAIL;
    if (!function_exists('ldap_connect'))
      raise_error(array('type' => 'ldap', 'message' => "No ldap support in this installation of PHP"), true);
@@ -99,43 +101,24 @@
    {
      $this->ready = true;
      // User specific access, generate the proper values to use.
      if ($this->prop["user_specific"]) {
        // User specific access, generate the proper values to use.
        global $CONFIG, $RCMAIL;
        // No password set, use the session password
        if (empty($this->prop['bind_pass'])) {
          // No password set, use the users.
          $this->prop['bind_pass'] = $RCMAIL->decrypt_passwd($_SESSION["password"]);
        } // end if
        }
        // Get the pieces needed for variable replacement.
        // See if the logged in username has an "@" in it.
        if (is_bool(strstr($_SESSION["username"], "@"))) {
          // It does not, use the global default.
          $fu = $_SESSION["username"]."@".$CONFIG["username_domain"];
          $u = $_SESSION["username"];
          $d = $CONFIG["username_domain"];
        } // end if
        else {
          // It does.
          $fu = $_SESSION["username"];
          // Get the pieces needed for username and domain.
          list($u, $d) = explode("@", $_SESSION["username"]);
        } # end else
        // Replace the bind_dn variables.
        $bind_dn = str_replace(array("%fu", "%u", "%d"),
                               array($fu, $u, $d),
                               $this->prop['bind_dn']);
        $this->prop['bind_dn'] = $bind_dn;
        // Replace the base_dn variables.
        $base_dn = str_replace(array("%fu", "%u", "%d"),
                               array($fu, $u, $d),
                               $this->prop['base_dn']);
        $this->prop['base_dn'] = $base_dn;
        $this->ready = $this->bind($this->prop['bind_dn'], $this->prop['bind_pass']);
      } // end if
      elseif (!empty($this->prop['bind_dn']) && !empty($this->prop['bind_pass']))
        $fu = $RCMAIL->user->get_username();
        list($u, $d) = explode('@', $fu);
        // Replace the bind_dn and base_dn variables.
        $replaces = array('%fu' => $fu, '%u' => $u, '%d' => $d);
        $this->prop['bind_dn'] = strtr($this->prop['bind_dn'], $replaces);
        $this->prop['base_dn'] = strtr($this->prop['base_dn'], $replaces);
      }
      if (!empty($this->prop['bind_dn']) && !empty($this->prop['bind_pass']))
        $this->ready = $this->bind($this->prop['bind_dn'], $this->prop['bind_pass']);
    }
    else