phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] [18621] fix some of the broken bits


From: Dave Hall
Subject: [Phpgroupware-cvs] [18621] fix some of the broken bits
Date: Tue, 24 Jun 2008 14:09:05 +0000

Revision: 18621
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18621
Author:   skwashd
Date:     2008-06-24 14:09:05 +0000 (Tue, 24 Jun 2008)

Log Message:
-----------
fix some of the broken bits

Modified Paths:
--------------
    trunk/phpgwapi/inc/auth/class.auth_.inc.php
    trunk/phpgwapi/inc/auth/class.auth_ads.inc.php
    trunk/phpgwapi/inc/auth/class.auth_exchange.inc.php
    trunk/phpgwapi/inc/auth/class.auth_http.inc.php
    trunk/phpgwapi/inc/auth/class.auth_ldap.inc.php
    trunk/phpgwapi/inc/auth/class.auth_mail.inc.php
    trunk/phpgwapi/inc/auth/class.auth_nis.inc.php
    trunk/phpgwapi/inc/auth/class.auth_ntlm.inc.php
    trunk/phpgwapi/inc/auth/class.auth_remoteuser.inc.php
    trunk/phpgwapi/inc/auth/class.auth_sql.inc.php
    trunk/phpgwapi/inc/auth/class.auth_sqlssl.inc.php
    trunk/phpgwapi/inc/class.session_handler_db.inc.php
    trunk/phpgwapi/inc/class.sessions.inc.php
    trunk/phpgwapi/inc/class.sql.inc.php
    trunk/phpgwapi/inc/common_functions.inc.php
    trunk/phpgwapi/setup/tables_update.inc.php

Modified: trunk/phpgwapi/inc/auth/class.auth_.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_.inc.php 2008-06-24 00:11:21 UTC (rev 
18620)
+++ trunk/phpgwapi/inc/auth/class.auth_.inc.php 2008-06-24 14:09:05 UTC (rev 
18621)
@@ -4,67 +4,159 @@
        * @author Dan Kuykendall <address@hidden>
        * @author Joseph Engo <address@hidden>
        * @author Philipp Kamps <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on SQL table
        *
        * @package phpgwapi
        * @subpackage accounts
        */
-       class auth_
+       abstract class phpgwapi_auth_
        {
-               var $previous_login = -1;
-               var $xmlrpc_methods = array();
-
-               function auth()
-               {
-                       $this->xmlrpc_methods[] = array(
+               public $xmlrpc_methods = array
+               (
+                       array
+                       (
                                'name'       => 'change_password',
                                'decription' => 'Change the current users 
password'
-                       );
-               }
+                       )
+               );
 
-               function authenticate($username, $passwd, $passwd_type)
+               /**
+               * Constructor
+               */
+               public function __construct()
+               {}
+
+               /**
+               * Authenticate a user
+               *
+               * @param string $username the login to authenticate
+               * @param string $passwd the password supplied by the user
+               * @return bool did the user authenticate?
+               * @return bool did the user sucessfully authenticate
+               */
+               abstract public function authenticate($username, $passwd);
+
+               /**
+               * Set the user's password to a new value
+               *
+               * @param string $old_passwd the user's old password
+               * @param string $new_passwd the user's new password
+               * @param int $account_id the account to change the password for 
- defaults to current user
+               */
+               abstract public function change_password($old_passwd, 
$new_passwd, $account_id = 0);
+
+               /**
+               * Generate random salt
+               *
+               * @param int $chars number of characters of salt required
+               * @return string the salt
+               */
+               private function _shake_salt($chars)
                {
+                       if ( $chars > 32 )
+                       {
+                               $chars = 32;
+                       }
+
+                       $salt = substr(md5(uniqid(rand(), true)), 0, $chars);
+                       return $salt;
                }
 
-               function change_password($old_passwd, $new_passwd, $account_id 
= '')
+               /**
+               * Generate a password hash
+               *
+               * @param string $passwd the password to turn into a hash
+               * @return string the hashed password - ready for use
+               */
+               public function create_hash($passwd)
                {
-                       // Don't allow passwords changes for other accounts 
when using XML-RPC
-                       if (! $account_id || 
$GLOBALS['phpgw_info']['flags']['currentapp'] == 'login')
+                       switch 
($GLOBALS['phpgw_info']['server']['encryption_type'])
                        {
-                               $account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
-                               $pwd_check  = " and account_pwd='" . 
md5($old_passwd) . "'";
-                       }
+                               case 'CRYPT':
+                                       return '{CRYPT}' . crypt($passwd, 
$this->_shake_salt(CRYPT_SALT_LENGTH));
 
-                       $encrypted_passwd = md5($new_passwd);
+                               case 'MD5':
+                                       return "{MD5}" . 
base64_encode(phpgwapi_common::hex2bin(md5($passwd)));
 
-                       $GLOBALS['phpgw']->db->query("update phpgw_accounts set 
account_pwd='" . md5($new_passwd) . "',"
-                               . "account_lastpwd_change='" . time() . "' 
where account_id='" . $account_id . "'" . $pwd_check,__LINE__,__FILE__);
+                               case 'SHA':
+                                       return "{SHA}" . 
base64_encode(phpgwapi_common::hex2bin(sha1($passwd)));
 
-                       if ($GLOBALS['phpgw']->db->affected_rows())
-                       {
-                               
$GLOBALS['phpgw']->session->appsession('password','phpgwapi',base64_encode($new_passwd));
-                               return $encrypted_passwd;
+                               case 'SMD5':
+                                       $salt = $this->_shake_salt(4);
+                                       return "{SMD5}" . 
base64_encode(phpgwapi_common::hex2bin(md5($passwd . $salt) . $salt));
+
+                               case 'SSHA':
+                               default:
+                                       $salt = $this->_shake_salt(4);
+                                       return '{SSHA}' . 
base64_encode(phpgwapi_common::hex2bin(sha1($passwd . $salt) . $salt));
                        }
-                       else
+               }
+
+               /**
+               * Verify that a hash matches a password
+               * 
+               * @param string $passwd the password contained in the hash
+               * @param string $hash the hashed version of the password
+               * @return bool does the password match the hash?
+               */
+               public function verify_hash($passwd, $hash)
+               {
+                       if ( !preg_match('/^{(.*)}(.*)$/', $hash, $m) || 
count($m) != 3  ) //full string, algorhythm, hash
                        {
+                               // invalid hash
                                return false;
                        }
-               }
+                       $algo = $m[1];
+                       $hash = $m[2];
+                       unset($m);
 
-               function update_lastlogin($account_id, $ip)
-               {
-                       $GLOBALS['phpgw']->db->query("update phpgw_accounts set 
account_lastloginfrom='"
-                               . "$ip', account_lastlogin='" . time()
-                               . "' where 
account_id='$account_id'",__LINE__,__FILE__);
+                       switch ( strtoupper($algo) )
+                       {
+                               case 'CRYPT':
+                                       //TODO implement this
+                                       return false;
+                               case 'MD5':
+                                       $hash = bin2hex(base64_decode($hash));
+                                       return $hash === md5($passwd);
+
+                               case 'SHA':
+                                       $hash = bin2hex(base64_decode($hash));
+                                       return $hash === sha1($passwd);
+
+                               case 'SMD5':
+                                       $hash = bin2hex(base64_decode($hash));
+                                       $salt = substr($hash, 32);
+                                       $hash = substr($hash, 0, 32);
+                                       return $hash === md5($passwd . $salt);
+
+                               case 'SSHA':
+                                       $hash = bin2hex(base64_decode($hash));
+                                       $salt = substr($hash, 40);
+                                       $hash = substr($hash, 0, 40);
+                                       return $hash === sha1($passwd . $salt);
+                       }
                }
-
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_ads.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_ads.inc.php      2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_ads.inc.php      2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -2,63 +2,68 @@
        /**
        * Authentication based on MS Active Directory Service
        * @author Philipp Kamps <address@hidden>
-       * @copyright Portions Copyright (C) 2000-2004 Free Software Foundation, 
Inc. http://www.fsf.org/
+       * @copyright Portions Copyright (C) 2000-2008 Free Software Foundation, 
Inc. http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
-       /**
-       * Include M$ Exchange authentification
-       */
-       include_once(PHPGW_API_INC . '/auth/class.auth_exchange.inc.php');
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
 
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on MS Active Directory Service
        *
        * @package phpgwapi
        * @subpackage accounts
        */
-       class auth_ads extends auth_exchange
+       class phpgwapi_auth_ads extends phpgwapi_auth_exchange
        {
-               
                /**
-               *
-               * your ADS base DN
+               * @var string $base_dn the base DN for the LDAP server
                */
-               var $ldap_base = ''; //'DC=pbgroup,DC=lan';
+               private $base_dn = ''; //'DC=pbgroup,DC=lan';
 
                /**
-               *
-               * your ads host
+               * @var string $ads_host the Active Directory host to connect to
                */
-               var $host = ''; // example: '192.168.100.1';
+               private $ads_host = ''; // example: '192.168.100.1';
 
-               function auth_ads()
+               /**
+               * @var string $ads_pass The password to use when binding to 
Active Directory
+               */
+               private $bind_password = '';
+
+               public function __construct()
                {
-                       parent::auth_exchange();
+                       parent::__construct();
                }
                
                function transform_username($username)
                {
                        // see this code as an example
-                       ldap_bind($this->ldap,
-                                         'CN=admin,CN=Users,DC=pbgroup,DC=lan',
-                                         'password'
-                                        );
-                       $sr = ldap_search($this->ldap,
-                                                         
'CN=Users,DC=pbgroup,DC=lan',
-                                                         
'mailNickname='.$username,
-                                                         array('cn')
-                                                        );
-                       $entries = ldap_get_entries($this->ldap, $sr);
+                       ldap_bind($this->ads_host, $this->get_base_dn(), 
$this->bind_password);
+                       $sr = ldap_search($this->ads_host, 
$this->get_base_dn(), "mailNickname={$username}", array('cn'));
+                       $entries = ldap_get_entries($this->ads_host, $sr);
                        return $entries[0]['cn'][0];
                }
                
                function get_base_dn()
                {
-                       return 'CN=Users,'.$this->ldap_base;
+                       return 'CN=Users,'.$this->base_dn;
                }
        }
 ?>

Modified: trunk/phpgwapi/inc/auth/class.auth_exchange.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_exchange.inc.php 2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_exchange.inc.php 2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -2,42 +2,54 @@
        /**
        * Authentication based on Exchange 5.5
        * @author Philipp Kamps <address@hidden>
-       * @copyright Portions Copyright (C) 2000-2004 Free Software Foundation, 
Inc. http://www.fsf.org/
+       * @copyright Portions Copyright (C) 2000-2008 Free Software Foundation, 
Inc. http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on LDAP
        *
        * @package phpgwapi
        * @subpackage accounts
        */
-       class auth_exchange extends auth_
+       class phpgwapi_auth_exchange extends phpgwapi_auth_
        {
                /**
-               *
-               * ldap connection
+               * @var resource $ldap ldap connection
                */
                var $ldap;
                
                /**
-               *
-               * your windows domain
+               * @var string $domain your windows domain
                */
                var $domain = '';
 
                /**
-               *
-               * your exchange host
+               * @var string $host your exchange host
                */
                var $host = '';
 
-               function auth_exchange()
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                        if(!$this->ldap = ldap_connect($this->host))
                        {
                                die('not connected');
@@ -45,17 +57,17 @@
                        }
                }
                
-               function get_base_dn()
+               protected function get_base_dn()
                {
                        return 'DC='.$this->domain;
                }
                
-               function transform_username($username)
+               protected function transform_username($username)
                {
                        return $username;
                }
                
-               function authenticate($username, $passwd, $pwType)
+               public function authenticate($username, $passwd)
                {
                        if($pwType == 'none')
                        {
@@ -71,20 +83,13 @@
                        $passwd = stripslashes($passwd);
 
                        /* Try to bind to the repository */
-                       if(@ldap_bind($this->ldap,
-                                                 
'cn='.$this->transform_username($username).','.$this->get_base_dn(),
-                                                 $passwd
-                                                ))
-                       {
-                               return true;
-                       }
-
-                       return false;
+                       return  @ldap_bind($this->ldap,
+                                               
'cn='.$this->transform_username($username).','.$this->get_base_dn(),
+                                               $passwd);
                }
 
-               function change_password($old_passwd, $new_passwd, 
$_account_id='') 
+               public function change_password($old_passwd, $new_passwd, 
$_account_id='') 
                {
                        return false;
                }
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_http.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_http.inc.php     2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_http.inc.php     2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -3,13 +3,28 @@
        * Authentication based on HTTP auth
        * @author Dan Kuykendall <address@hidden>
        * @author Joseph Engo <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on HTTP auth
        *
@@ -17,24 +32,17 @@
        * @subpackage accounts
        * @ignore
        */
-       class auth_http extends auth_
+       class phpgwapi_auth_http extends phpgwapi_auth_
        {
 
-               function auth_http()
+               function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
 
                function authenticate($username, $passwd)
                {
-                       if (isset($GLOBALS['PHP_AUTH_USER']))
-                       {
-                               return True;
-                       }
-                       else
-                       {
-                               return False;
-                       }
+                       return isset($_SERVER['PHP_AUTH_USER']) && 
!!strlen($_SERVER['PHP_AUTH_USER']);
                }
 
                function change_password($old_passwd, $new_passwd)
@@ -43,4 +51,3 @@
                }
 
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_ldap.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_ldap.inc.php     2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_ldap.inc.php     2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -1,129 +1,191 @@
 <?php
        /**
-       * Authentication based on LDAP Server
-       * @author Lars Kneschke <address@hidden>
-       * @author Joseph Engo <address@hidden>
-  * @copyright Copyright (C) 2000,2001 Lars Kneschke, Joseph Engo
-       * @copyright Portions Copyright (C) 2000-2004 Free Software Foundation, 
Inc. http://www.fsf.org/
-       * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
-       * @package phpgwapi
-       * @subpackage accounts
-       * @version $Id$
-       */
+        * Authentication based on LDAP Server
+        * @author Lars Kneschke <address@hidden>
+        * @author Joseph Engo <address@hidden>
+        * @author Benoit Hamet <address@hidden>
+        * @author Dave Hall <address@hidden>
+        * @copyright Copyright (C) 2000,2001 Lars Kneschke, Joseph Engo
+        * @copyright Portions Copyright (C) 2000-2008 Free Software 
Foundation, Inc. http://www.fsf.org/
+        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
+        * @package phpgwapi
+        * @subpackage accounts
+        * @version $Id$
+        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on LDAP Server
        *
        * @package phpgwapi
        * @subpackage accounts
-       * @ignore
        */
-       class auth_ldap extends auth_
+       class phpgwapi_auth_ldap extends phpgwapi_auth_
        {
-               
-               function auth_ldap()
+               /**
+               * @var string $user_search_dn DN pattern used to search for a 
user
+               */
+               protected $username_search_dn = "uid=%u";
+
+               /**
+               * @var string $user_search_dn DN pattern used to search for a 
user
+               */
+               protected $userid_search_dn = "uidNumber=%i";
+
+               /**
+               * Constructor
+               */
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
-               
-               function authenticate($username, $passwd)
+
+               /**
+               * Substitute user specific values for DN search
+               *
+               * @param string $dn the pattern to substitute
+               * @param string $username the login for the user
+               * @param int $accountid the id of the user's account
+               */
+               protected function _generate_dn($dn, $username = '', $accountid 
= 0)
                {
-                       /*
-                               this avoids warings with ldap_bind when user / 
password are not correct
-                               it is reset before this method is completed
-                       */
-                       $error_level = error_reporting();
-                       error_reporting(0); 
+                       if ( !$username )
+                       {
+                               $username = 
$GLOBALS['phpgw']->accounts->id2lid($accountid);
+                       }
 
+                       if ( !$accountid )
+                       {
+                               $accountid = 
$GLOBALS['phpgw']->accounts->name2id($username);
+                       }
+
+                       $search_pairs = array
+                       (
+                               '/%u/'  => $username,
+                               '/%i/'  => $accountid
+                               //'/%d/'        => //phpgw domain here - once 
we know how to grab it
+                               // others could go here at some point
+                       );
+
+                       return preg_replace(array_keys($search_pairs), 
$search_pairs, $dn);
+               }
+
+               public function authenticate($username, $passwd)
+               {
+                       // We use a common return here to make sure all LDAP 
connections are closed properly
+                       $ok = false;
+
                        //Connect as Admin with v3 or v2 in LDAP server
                        if ( !$ldap = $GLOBALS['phpgw']->common->ldapConnect() )
                        {
                                $GLOBALS['phpgw']->log->message('F-Abort, 
Failed connecting to LDAP server for authenication, execution stopped');
                                $GLOBALS['phpgw']->log->commit();
-                               return false;
+                               return $ok;
                        }
+
+                       // Generate the search DN
+                       $search = 
$this->_generate_dn($this->username_search_dn, $username);
+
                        //Search for the dn
-                       $attributes = array( 'uid', 'dn', 'phpgwaccountstatus' 
);
-                       $sri = ldap_search($ldap, 
$GLOBALS['phpgw_info']['server']['ldap_context'], "uid=$username", $attributes);
+                       $attributes = array( 'uid', 'dn', 'shadowexpire' );
+                       $sri = ldap_search($ldap, 
$GLOBALS['phpgw_info']['server']['ldap_context'], $search, $attributes);
                        $allValues = ldap_get_entries($ldap, $sri);
-                       if ($allValues['count'] > 0)
+
+                       if ($allValues['count'] > 0 
+                               && (!isset($allValues[0]['shadowexpire'][0])
+                                       || $allValues[0]['shadowexpire'][0] >= 
(date('U') / phpgwapi_datetime::SECONDS_IN_DAY ) ) )
                        {
-                               // let's check if its an inactive account
-                               if($allValues[0]['phpgwaccountstatus'][0] != 
'I')
+                               /* we only care about the first dn */
+                               $userDN = $allValues[0]['dn'];
+                               /*
+                               generate a bogus password to pass if the user 
doesn't give us one 
+                               this gets around systems that are anonymous 
search enabled
+                               */
+                               if (empty($passwd))
                                {
-                                       /* we only care about the first dn */
-                                       $userDN = $allValues[0]['dn'];
-                                       /*
-                                       generate a bogus password to pass if 
the user doesn't give us one 
-                                       this gets around systems that are 
anonymous search enabled
-                                       */
-                                       if (empty($passwd))
-                                       {
-                                               $passwd = crypt(microtime());
-                                       }
-                                       /* try to bind as the user with user 
suplied password */
-                                       if (ldap_bind($ldap, $userDN, $passwd))
-                                       {
-                                               ldap_unbind($ldap); // we don't 
need this connection anymore, so avoid a leak.
-                                               error_reporting($error_level);
-                                               return true;
-                                       }
+                                       $passwd = crypt(microtime());
                                }
+
+                               /* try to bind as the user with user suplied 
password */
+                               $user_bind = @ldap_bind($ldap, $userDN, 
$passwd);
+                               $ok = is_resource($user_bind);
+                               @ldap_unbind($user_bind); // we don't need this 
connection anymore, so avoid a leak.
                        }
                        @ldap_unbind($ldap);
-                       /* Turn error reporting back to normal */
-                       error_reporting($error_level);
 
-                       /* dn not found or password wrong */
-                       return False;
+                       return $ok;
                }
 
-               function change_password($old_passwd, $new_passwd, 
$_account_id='') 
+               public function change_password($old_passwd, $new_passwd, 
$_account_id = 0) 
                {
-                       if ('' == $_account_id)
+                       if ( !$_account_id )
                        {
                                $_account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        }
+
+                       // Generate the search DN
+                       $search = $this->_generate_dn($this->userid_search_dn, 
'', $account_id);
        
                        $ds = $GLOBALS['phpgw']->common->ldapConnect();
-                       $sri = ldap_search($ds, 
$GLOBALS['phpgw_info']['server']['ldap_context'], 'uidnumber='.$_account_id);
+                       $sri = ldap_search($ds, 
$GLOBALS['phpgw_info']['server']['ldap_context'], $search, array('dn') );
                        $allValues = ldap_get_entries($ds, $sri);
+                       if ( $allValues['count'] == 0 )
+                       {
+                               ldap_unbind($ds);
+                               return '';
+                       }
+
                        $dn = $allValues[0]['dn'];
                        
-                       $entry['userpassword'] = 
$GLOBALS['phpgw']->common->encrypt_password($new_passwd);
-                       if (is_array($allValues[0]['objectclass']) &&
-                                 ( in_array('phpgwAccount', 
$allValues[0]['objectclass']) ||
-                                       in_array('phpgwaccount', 
$allValues[0]['objectclass'])
-                                 )
-                          )
+                       $entry['userpassword'] = 
$this->generate_hash($new_password); 
+                       if ( isset($allValues[0]['shadowlastchange']) )
                        {
-                               $entry['phpgwlastpasswordchange'] = time();
+                               $entry['shadowLastChange'] = date('U') / 
phpgwapi_datetime::SECONDS_IN_DAY;
                        }
 
+                       $pass = '';
                        if (@ldap_modify($ds, $dn, $entry)) 
                        {
                                
$GLOBALS['phpgw']->session->appsession('password','phpgwapi',$new_passwd);
-                               return $entry['userpassword'];
+                               $pass = $entry['userpassword'];
                        }
-                       else
-                       {
-                               return false;
-                       }
+
+                       ldap_unbind($ds);
+                       return $pass;
                }
 
-               function update_lastlogin($account_id, $ip)
+               public function update_lastlogin($account_id, $ip)
                {
                        $entry['phpgwlastlogin']     = time();
                        $entry['phpgwlastloginfrom'] = $ip;
+                       
+                       // Generate the search DN
+                       $search = $this->_generate_dn($this->userid_search_dn, 
'', $account_id);
+       
                        $ds = $GLOBALS['phpgw']->common->ldapConnect();
-                       $sri = ldap_search($ds, 
$GLOBALS['phpgw_info']['server']['ldap_context'], '(&(uidnumber=' . 
$account_id.')(objectclass=phpgwaccount))');
+                       $sri = ldap_search($ds, 
$GLOBALS['phpgw_info']['server']['ldap_context'], $search, array('dn') );
                        $allValues = ldap_get_entries($ds, $sri);
-                       
-                       if ($dn = $allValues[0]['dn'])
+
+                       if ( $allValues['count']
+                               && isset($allValues[0]['phpgwlastlogin']) )
                        {
-                               $this->previous_login = 
$allValues[0]['phpgwlastlogin'][0];
+                               $dn = $allValues[0]['dn'];
                                ldap_modify($ds, $dn, $entry);
                        }
+                       ldap_unbind($ds);
                }
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_mail.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_mail.inc.php     2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_mail.inc.php     2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -2,96 +2,87 @@
        /**
        * Authentication based on Mail server
        * @author Dan Kuykendall <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on Mail server
        *
        * @package phpgwapi
        * @subpackage accounts
-       * @ignore
        */
-       class auth_mail extends auth_
+       class phpgwapi_auth_mail extends phpgwapi_auth_
        {
+               /**
+               * @var string $ssl_args arguments used for SSL connection - 
disables SSL validation by default
+               * @internal see http://php.net/imap_open for more info
+               */
+               private $ssl_agrs = '/novalidate-cert';
                
-               function auth_mail()
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
                
                function authenticate($username, $passwd)
                {
-                       error_reporting(error_reporting() - 2);
+                       $server = 
$GLOBALS['phpgw_info']['server']['mail_server'];
 
-                       if ($GLOBALS['phpgw_info']['server']['mail_login_type'] 
== 'vmailmgr')
+                       switch ( 
$GLOBALS['phpgw_info']['server']['mail_login_type'] )
                        {
-                               $username = $username . '@' . 
$GLOBALS['phpgw_info']['server']['mail_suffix'];
+                               case 'vmailmgr':
+                                       $username = 
"address@hidden'phpgw_info']['server']['mail_suffix']}";
+                                       break;
+                               case 'ispman':
+                                       $username = "{$username}_" . 
preg_replace('/\./', '_', $GLOBALS['phpgw_info']['server']['mail_suffix']);
+                                       break;
                        }
-                       if ($GLOBALS['phpgw_info']['server']['mail_login_type'] 
== 'ispman')
-                       {
-                               $username = $username . '_' . str_replace('.', 
'_', $GLOBALS['phpgw_info']['server']['mail_suffix']);
-                       }
-                       if 
($GLOBALS['phpgw_info']['server']['mail_server_type']=='imap')
-                       {
-                               $GLOBALS['phpgw_info']['server']['mail_port'] = 
'143';
-                       }
-                       elseif 
($GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3')
-                       {
-                               $GLOBALS['phpgw_info']['server']['mail_port'] = 
'110';
-                       }
-                       elseif 
($GLOBALS['phpgw_info']['server']['mail_server_type']=='imaps')
-                       {
-                               $GLOBALS['phpgw_info']['server']['mail_port'] = 
'993';
-                       }
-                       elseif 
($GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3s')
-                       {
-                               $GLOBALS['phpgw_info']['server']['mail_port'] = 
'995';
-                       }
 
-                       if( 
$GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3')
+                       $extra = '';
+                       switch ( 
$GLOBALS['phpgw_info']['server']['mail_server_type'] )
                        {
-                               $mailauth = 
imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server'].'/pop3'
-                                       
.':'.$GLOBALS['phpgw_info']['server']['mail_port'].'}INBOX', $username , 
$passwd);
+                               case 'pop3s':
+                                       $port = 995;
+                                       $extra = "/ssl{$this->ssl_args}";
+                               case 'pop3':
+                                       $extra = "/pop3{$extra}";
+                                       $port = 110;
+                                       break;
+                               case 'imaps':
+                                       $port = 993;
+                                       $extra = "/ssl{$this->ssl_args}";
+                                       $mailauth = 
imap_open("\{{$GLOBALS['phpgw_info']['server']['mail_server']}:{$port}\}INBOX", 
$username , $passwd);
+                                       break;
+                               case 'imap':
+                               default:
+                                       $port = 143;
+                                       
$GLOBALS['phpgw_info']['server']['mail_port'] = '143';
                        }
-                       elseif ( 
$GLOBALS['phpgw_info']['server']['mail_server_type']=='imaps' )
-                       {
-                               // IMAPS support:
-                               $mailauth = 
imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server']."/ssl/novalidate-cert"
-                                                                               
 .':993}INBOX', $username , $passwd);
-                       }
-                       elseif ( 
$GLOBALS['phpgw_info']['server']['mail_server_type']=='pop3s' )
-                       {
-                               // POP3S support:
-                               $mailauth = 
imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server']."/ssl/novalidate-cert"
-                                                                               
 .':995}INBOX', $username , $passwd);
-                       }
-                       else
-                       {
-                               /* assume imap */
-                               $mailauth = 
imap_open('{'.$GLOBALS['phpgw_info']['server']['mail_server']
-                                       
.':'.$GLOBALS['phpgw_info']['server']['mail_port'].'}INBOX', $username , 
$passwd);
-                       }
 
-                       error_reporting(error_reporting() + 2);
-                       if ($mailauth == False)
-                       {
-                               return False;
-                       }
-                       else
-                       {
-                               imap_close($mailauth);
-                               return True;
-                       }
+                       return !! 
@imap_open("\{{$server}{$extra}:{$port}\}INBOX", $username , $passwd);
                }
 
                function change_password($old_passwd, $new_passwd)
                {
-                       return False;
+                       return '';
                }
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_nis.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_nis.inc.php      2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_nis.inc.php      2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -3,13 +3,28 @@
        * Authentication based on NIS maps
        * @author Dylan Adams <address@hidden>
        * @copyright Copyright (C) 2001 Dylan Adams
-       * @copyright Portions Copyright (C) 2004 Free Software Foundation, Inc 
http://www.fsf.org/
+       * @copyright Portions Copyright (C) 2004 - 2008 Free Software 
Foundation, Inc http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on NIS maps
        *
@@ -17,12 +32,12 @@
        * @subpackage accounts
        * @ignore
        */
-       class auth_nis extends auth_
+       class phpgwapi_auth_nis extends phpgwapi_auth_
        {
                
-               function auth_nis()
+               function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
                
                function authenticate($username, $passwd)
@@ -55,8 +70,6 @@
                function change_password($old_passwd, $new_passwd, $account_id 
= '')
                {
                        // can't change passwords unless server runs as root 
(bad idea)
-                       return( False );
+                       return '';
                }
-
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_ntlm.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_ntlm.inc.php     2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_ntlm.inc.php     2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -2,13 +2,28 @@
        /**
        * Authentication based on ntlm auth
        * @author Philipp Kamps <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on ntlm auth
        *
@@ -16,31 +31,18 @@
        * @subpackage accounts
        * @ignore
        */
-       class auth_ntlm extends auth_
+       class phpgwapi_auth_ntlm extends phpgwapi_auth_remote_user
        {
 
-               function auth_ntlm()
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
 
-               function authenticate($username, $passwd)
-               {
-                       if (strlen($_SERVER['REMOTE_USER']))
-                       {
-                               return true;
-                       }
-                       else
-                       {
-                               return false;
-                       }
-               }
-
                function change_password($old_passwd, $new_passwd)
                {
                        // not yet supported - this script would change the 
windows domain password
-                       return false;
+                       return '';
                }
 
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_remoteuser.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_remoteuser.inc.php       2008-06-24 
00:11:21 UTC (rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_remoteuser.inc.php       2008-06-24 
14:09:05 UTC (rev 18621)
@@ -2,13 +2,28 @@
        /**
        * Authentication based on Apache
        * @author DANG Quang Vu <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage auth
        * @version $Id$
        */
        
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * By using an Apache authentication method, phpGroupware does not 
authenticate users internally 
        * in its accounts directory (LDAP, MySQL,...). Instead of that, it 
depends on the Apache session's 
@@ -17,33 +32,26 @@
        * Using with Single Sign-On(Shibboleth, CAS, ...)
        */
        
-       class auth_remoteuser extends auth_
+       class phpgwapi_auth_remoteuser extends phpgwapi_auth_
        {
                
-               function auth_remoteuser()
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
                
-               function authenticate($username, $passwd, $passwd_type)
+               public function authenticate($username, $passwd)
                {
-                       if(isset($_SERVER['REMOTE_USER']) && 
strlen($_SERVER['REMOTE_USER']) > 0)
-                       {
-                               return true;
-                       }
-                       else
-                       {
-                               return false;
-                       }
+                       return isset($_SERVER['REMOTE_USER']) && 
!!strlen($_SERVER['REMOTE_USER']);
                }
                
-               function change_password($old_passwd, $new_passwd, $account_id 
= '')
+               public function change_password($old_passwd, $new_passwd, 
$account_id = '')
                {
                        return false;
                }
 
-               function update_lastlogin($account_id, $ip)
+               public function update_lastlogin($account_id, $ip)
                {
+                       return '';
                }
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_sql.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_sql.inc.php      2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_sql.inc.php      2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -3,54 +3,127 @@
        * Authentication based on SQL table
        * @author Dan Kuykendall <address@hidden>
        * @author Joseph Engo <address@hidden>
-       * @copyright Copyright (C) 2000-2004 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Copyright (C) 2000-2008 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on SQL table
        *
        * @package phpgwapi
        * @subpackage accounts
        */
-       class auth_sql extends auth_
+       class phpgwapi_auth_sql extends phpgwapi_auth_
        {
 
-               function auth_sql()
+               /**
+               * Constructor
+               */
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
 
-               function authenticate($username, $passwd, $passwd_type)
+               /**
+               * Authenticate a user
+               *
+               * @param string $username the login to authenticate
+               * @param string $passwd the password supplied by the user
+               * @return bool did the user sucessfully authenticate
+               */
+               public function authenticate($username, $passwd)
                {
-                       $db =& $GLOBALS['phpgw']->db;
+                       $username = 
$GLOBALS['phpgw']->db->db_addslashes($username);
 
-                       if ($passwd_type == 'text')
+                       $sql = 'SELECT account_pwd FROM phpgw_accounts'
+                               . " WHERE account_lid = '{$username}'"
+                                       . " AND account_status = 'A'";
+
+                       $GLOBALS['phpgw']->db->query($sql, __LINE__, __FILE__);
+                       if ( !$GLOBALS['phpgw']->db->next_record() )
                        {
-                               $_passwd = md5($passwd);
+                               return false;
                        }
 
-                       if ($passwd_type == 'md5')
+                       $hash = $GLOBALS['phpgw']->db->f('account_pwd', true);
+                       return $this->verify_hash($passwd, $hash);
+               }
+
+               /**
+               * Set the user's password to a new value
+               *
+               * @param string $old_passwd the user's old password
+               * @param string $new_passwd the user's new password
+               * @param int $account_id the account to change the password for 
- defaults to current user
+               * @return string the new encrypted hash, or an empty string on 
failure
+               */
+               public function change_password($old_passwd, $new_passwd, 
$account_id = 0)
+               {
+                       $account_id = (int) $account_id;
+                       // Don't allow passwords changes for other accounts 
when using XML-RPC
+                       if ( !$account_id )
                        {
-                               $_passwd = $passwd;
+                               $account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        }
+                       
+                       if ( $GLOBALS['phpgw_info']['flags']['currentapp'] == 
'login')
+                       {
+                               if ( 
!$this->authenticate($GLOBALS['phpgw']->accounts->id2lid($account_id), 
$old_passwd) )
+                               {
+                                       return '';
+                               }
+                       }
 
-                       $db->query("SELECT * FROM phpgw_accounts WHERE 
account_lid = '$username' AND "
-                               . "account_pwd='" . $_passwd . "' AND 
account_status ='A'",__LINE__,__FILE__);
-                       $db->next_record();
+                       $hash = $this->generate_hash($new_password);
+                       $hash_safe = 
$GLOBALS['phpgw']->db->db_addslashes($hash); // just to be safe :)
+                       $now = time();
 
-                       if ($db->f('account_lid'))
+                       $sql = 'UPDATE phpgw_accounts'
+                               . " SET account_pwd = '{$hash_safe}', 
account_lastpwd_change = {$now}"
+                               . " WHERE account_id = {$account_id}";
+
+                       if ( !!$GLOBALS['phpgw']->db->query($sql, __LINE__, 
__FILE__) )
                        {
-                               $this->previous_login = 
$db->f('account_lastlogin');
-                               return true;
+                               return $hash;
                        }
-                       else
-                       {
-                               return false;
-                       }
+                       return '';
                }
+               
+               /**
+               * Update when the user last logged in
+               *
+               * @param int $account_id the user's account id
+               * @param string $ip the source IP adddress for the request
+               */
+               public function update_lastlogin($account_id, $ip)
+               {
+                       $ip = $GLOBALS['phpgw']->db->db_addslashes($ip);
+                       $account_id = (int) $account_id;
+                       $now = time();
+
+                       $sql = 'UPDATE phpgw_accounts'
+                               . " SET account_lastloginfrom = '{$ip}',"
+                                       . " account_lastlogin = {$now}"
+                               . " WHERE account_id = {$account_id}";
+
+                       $GLOBALS['phpgw']->db->query($sql, __LINE__, __FILE__);
+               }
        }
-?>

Modified: trunk/phpgwapi/inc/auth/class.auth_sqlssl.inc.php
===================================================================
--- trunk/phpgwapi/inc/auth/class.auth_sqlssl.inc.php   2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/auth/class.auth_sqlssl.inc.php   2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -3,66 +3,65 @@
        * Authentication based on SQL, with optional SSL authentication
        * @author Andreas 'Count' Kotes <address@hidden>
        * @copyright Copyright (C) 200x Andreas 'Count' Kotes <address@hidden>
-       * @copyright Portions Copyright (C) 2004 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @copyright Portions Copyright (C) 2004-2008 Free Software Foundation, 
Inc. http://www.fsf.org/
        * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General 
Public License
        * @package phpgwapi
        * @subpackage accounts
        * @version $Id$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU Lesser General Public License as 
published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU Lesser General Public 
License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Authentication based on SQL, with optional SSL authentication
        *
        * @package phpgwapi
        * @subpackage accounts
-       * @ignore
        */
-       class auth_sqlssl extends auth_
+       class phpgwapi_auth_sqlssl extends phpgwapi_auth_sql
        {
 
-               function auth_sqlssl()
+               /**
+               * Constructor
+               */
+               public function __construct()
                {
-                       parent::auth();
+                       parent::__construct();
                }
 
-               function authenticate($username, $passwd)
+               /**
+               * Authenticate a user
+               *
+               * @param string $username the login to authenticate
+               * @param string $passwd the password supplied by the user
+               * @return bool did the user authenticate?
+               * @return bool did the user sucessfully authenticate
+               */
+               public function authenticate($username, $passwd)
                {
-                       $db =& $GLOBALS['phpgw']->db;
-
-                       $local_debug = False;
-
-                       if($local_debug)
+                       if ( isset($_SERVER['SSL_CLIENT_S_DN']) )
                        {
-                               echo "<b>Debug SQL: uid - $username passwd - 
$passwd</b>";
-                       }
+                               $username = 
$GLOBALS['phpgw']->db->db_addslashes($username);
 
-                       // Apache + mod_ssl provide the data in the environment
-                       // Certificate (chain) verification occurs inside 
mod_ssl
-                       // see 
http://www.modssl.org/docs/2.8/ssl_howto.html#ToC6
-                       if(!isset($_SERVER['SSL_CLIENT_S_DN']))
-                       {
-                               // if we're not doing SSL authentication, 
behave like auth_sql
-                               $db->query("SELECT * FROM phpgw_accounts WHERE 
account_lid = '$username' AND "
-                                       . "account_pwd='" . md5($passwd) . "' 
AND account_status ='A'",__LINE__,__FILE__);
-                               $db->next_record();
+                               $sql = 'SELECT account_lid FROM phpgw_accounts'
+                                       . " WHERE account_lid = '{$username}'"
+                                               . " AND account_status = 'A'";
+                               $GLOBALS['phpgw']->db->query($sql, __LINE__, 
__FILE__);
+                               return $GLOBALS['phpgw']->db->next_record();
                        }
-                       else
-                       {
-                               // use username only for authentication, ignore 
X.509 subject in $passwd for now
-                               $db->query('SELECT * FROM phpgw_accounts'
-                                       . " WHERE account_lid = '" . 
$db->db_addslashes($username) . "'"
-                                       . "AND account_status 
='A'",__LINE__,__FILE__);
-                               $db->next_record();
-                       }
-
-                       if($db->f('account_lid'))
-                       {
-                               return True;
-                       }
-                       else
-                       {
-                               return False;
-                       }
+                       return parent::authenticate($username, $passwd);
                }
        }
-?>

Modified: trunk/phpgwapi/inc/class.session_handler_db.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.session_handler_db.inc.php 2008-06-24 00:11:21 UTC 
(rev 18620)
+++ trunk/phpgwapi/inc/class.session_handler_db.inc.php 2008-06-24 14:09:05 UTC 
(rev 18621)
@@ -74,6 +74,47 @@
                }
 
                /**
+                * Get a list of currently logged in sessions
+                *
+                * @return array list of sessions
+                */
+               public static function get_list()
+               {
+                       // clean out the dead sessions
+                       self::gc(ini_get('session.gc_maxlifetime'));
+                       
+                       $values = array();
+
+                       $sql = 'SELECT session_id, ip, data FROM 
phpgw_sessions';
+
+                       $GLOBALS['phpgw']->db->query($sql, __LINE__, __FILE__);
+                       while ($GLOBALS['phpgw']->db->next_record())
+                       {
+                               $data = 
$GLOBALS['phpgw']->crypto->decrypt($GLOBALS['phpgw']->db->f('data', true));
+
+                               // skip invalid or anonymous sessions
+                               if ( !isset($data['phpgw_session'])
+                                       || 
!isset($data['phpgw_session']['session_flags'])
+                                       || 
$data['phpgw_session']['session_flags'] == 'A' )
+                               {
+                                       continue;
+                               }
+
+                               $values[$GLOBALS['phpgw']->db->f('session_id', 
true)] = array
+                               (
+                                       'id'            => 
$GLOBALS['phpgw']->db->f('id', true),
+                                       'lid'           => 
$data['phpgw_session']['session_lid'],
+                                       'ip'            => 
$GLOBALS['phpgw']->db->f('ip', true),
+                                       'action'        => 
$data['phpgw_session']['session_action'],
+                                       'dla'           => 
$data['phpgw_session']['session_dla'],
+                                       'logints'       => 
$data['phpgw_session']['session_logintime']
+                               );
+                       }
+                       return $values;
+               }
+
+
+               /**
                 * Open connection to session handler backend
                 *
                 * @internal does nothing for us
@@ -122,7 +163,6 @@
                        $data = 
$GLOBALS['phpgw']->db->db_addslashes($GLOBALS['phpgw']->crypto->encrypt($data));
                        $ts = time();
 
-                       // need to do it this way - REPLACE INTO would make a 
more elegant solution 
                        $GLOBALS['phpgw']->db->query("SELECT session_id FROM 
phpgw_sessions WHERE session_id = '{$id}'", __LINE__, __FILE__);
                        if ( $GLOBALS['phpgw']->db->next_record() )
                        {

Modified: trunk/phpgwapi/inc/class.sessions.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.sessions.inc.php   2008-06-24 00:11:21 UTC (rev 
18620)
+++ trunk/phpgwapi/inc/class.sessions.inc.php   2008-06-24 14:09:05 UTC (rev 
18621)
@@ -523,10 +523,12 @@
                */
                public function link($url, $extravars = array(), 
$redirect=false)
                {
-                       $term = '&amp;'; //W3C Compliant in markup
+                       //W3C Compliant in markup       
+                       $term = '&amp;'; 
                        if ( $redirect )
                        {
-                               $term = '&'; // RFC Compliant for 
Header('Location: ...
+                               // RFC Compliant for Header('Location: ...
+                               $term = '&'; 
                        }
 
                        /* first we process the $url to build the full 
scriptname */
@@ -650,96 +652,49 @@
                 */
                public function list_sessions($start, $order, $sort, 
$all_no_sort = false)
                {
-                       // FIXME this now only works with php sessions :(
-                       return array();
+                       // We cache the data for 5mins system wide as this is 
an expensive operation
+                       $last_updated = phpgwapi_cache::system_get('phpgwapi', 
'session_list_saved');
 
-                       /*
-
-                       $session_cache = 
$this->appsession('php4_session_cache','phpgwapi');
-
-                       $values = array();
-                       $maxmatchs = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-                       $dir = @opendir($path = ini_get('session.save_path'));
-                       while ($dir && $file = readdir($dir))
+                       if ( is_null($last_updated) 
+                               || $last_updated < 60 * 5 )
                        {
-                               if (substr($file,0,5) != 'sess_')
+                               $data = array();
+                               switch ( 
$GLOBALS['phpgw_info']['server']['sessions_type'] )
                                {
-                                       continue;
-                               }
-                               if (isset($session_cache[$file]))       // use 
copy from cache
-                               {
-                                       $session = $session_cache[$file];
+                                       case 'db':
+                                               $data = 
phpgwapi_session_handler_db::get_list();
+                                               break;
 
-                                       if ($session['session_flags'] == 'A' || 
!$session['session_id'] ||
-                                               $session['session_install_id'] 
!= $GLOBALS['phpgw_info']['server']['install_id'])
-                                       {
-                                               continue;       // no anonymous 
sessions or other domains or installations
-                                       }
-                                       if (!$all_no_sort)      // we need the 
up-to-date data --> unset and reread it
-                                       {
-                                               unset($session_cache[$file]);
-                                       }
+                                       case 'php':
+                                       default:
+                                               $data = self::_get_list();
                                }
-                               if ( !isset($session_cache[$file]) && 
is_readable($file) )      // not in cache, read and cache it
-                               {
-                                       $fd = fopen ($path . '/' . $file,'r');
-                                       $fs = filesize ($path . '/' . $file);
-
-                                       // handle filesize 0 because php 
recently warns if fread is used on 0byte files
-                                       if ($fs > 0)
-                                       {
-                                               $session = fread ($fd, filesize 
($path . '/' . $file));
-                                       }
-                                       else
-                                       {
-                                               $session = '';
-                                       }
-                                       fclose ($fd);
-
-                                       if (substr($session,0,14) != 
'phpgw_session|')
-                                       {
-                                               continue;
-                                       }
-                                       $session = 
unserialize(substr($session,14));
-                                       unset($session['phpgw_app_sessions']);  
// not needed, saves memory
-                                       $session_cache[$file] = $session;
-                               }
-
-                               if ($session['session_flags'] == 'A' || 
!$session['session_id'] ||
-                                       $session['session_install_id'] != 
$GLOBALS['phpgw_info']['server']['install_id'])
-                               {
-                                       continue;       // no anonymous 
sessions or other domains or installations
-                               }
-                               //echo "file='$file'=<pre>"; print_r($session); 
echo "</pre>";
-
-                               $session['php_session_file'] = $path . '/' . 
$file;
-                               $values[$session['session_id']] = $session;
+                               phpgwapi_cache::system_set('phpgwapi', 
'session_list', $data);
+                               phpgwapi_cache::system_set('phpgwapi', 
'session_list_saved', time());
                        }
-                       @closedir($dir);
+                       else
+                       {
+                               $data = phpgwapi_cache::system_get('phpgwapi', 
'session_list');
+                       }
 
-                       if (!$all_no_sort)
+                       if ( $all_no_sort )
                        {
-                               $GLOBALS['phpgw']->session->sort_by = $sort;
-                               $GLOBALS['phpgw']->session->sort_order = $order;
+                               return $data;
+                       }
 
-                               uasort($values, array('self', 'session_sort'));
+                       $GLOBALS['phpgw']->session->sort_by = $sort;
+                       $GLOBALS['phpgw']->session->sort_order = $order;
 
-                               $i = 0;
-                               $start = intval($start);
-                               foreach($values as $id => $data)
-                               {
-                                       if ($i < $start || $i > 
$start+$maxmatchs)
-                                       {
-                                               unset($values[$id]);
-                                       }
-                                       ++$i;
-                               }
-                               reset($values);
+                       uasort($data, array('self', 'session_sort'));
+
+                       $maxmatches = 25;
+                       if ( 
isset($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'])
+                               && (int) 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] )
+                       {
+                               $maxmatches = (int) 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
                        }
-                       $this->appsession('php4_session_cache', 'phpgwapi', 
$session_cache);
 
-                       return $values;
-                       */
+                       return array_slice($data, $start, $maxmatches);
                }
 
                /**
@@ -836,7 +791,7 @@
                public function phpgw_setcookie($cookiename, $cookievalue='', 
$cookietime=0)
                {
                        $secure = phpgw::get_var('HTTPS', 'bool', 'SERVER');
-                       setcookie($cookiename, $cookievalue, $cookietime, '/',
+                       setcookie($cookiename, $cookievalue, $cookietime, 
$GLOBALS['phpgw_info']['server']['webserver_url'],
                                        $this->_cookie_domain, $secure, true);
                }
 
@@ -891,7 +846,9 @@
                        {
                                session_id($sessionid);
                        }
+
                        session_start();
+
                        if ( isset($_SESSION['phpgw_session']) && 
is_array($_SESSION['phpgw_session']) )
                        {
                                return $_SESSION['phpgw_session'];
@@ -1061,8 +1018,6 @@
                public function update_dla()
                {
                        session_id($this->_sessionid);
-                       //FIXME remove the @ and wrap this in an if block
-                       @session_start();
 
                        if ( isset($GLOBALS['phpgw_info']['menuaction']) )
                        {
@@ -1288,7 +1243,6 @@
                                        $GLOBALS['phpgw']->crypto->cleanup();
                                        unset($GLOBALS['phpgw']->crypto);
                                }
-                               //echo 'DEBUG: Sessions: account_id is 
empty!<br>'."\n";
                                return false;
                        }
                        return true;
@@ -1305,140 +1259,72 @@
                {
                        // this is currently broken and unused
                        return false;
-                       /*
+               }
 
-                       $GLOBALS['phpgw']->interserver = 
createObject('phpgwapi.interserver');
-                       $this->_sessionid = $sessionid;
+               /**
+                * Get a list of currently logged in sessions
+                *
+                * @return array list of sessions
+                */
+               protected function _get_list()
+               {
+                       $values = array();
 
-                       $session = $this->read_session($this->_sessionid);
-                       $this->_session_flags = $session['session_flags'];
+                       /*
+                          Yes recursive - from the manual
+                          There is an optional N argument to this 
[session.save_path] that determines 
+                          the number of directory levels your session files 
will be spread around in.
+                        */
+                       $path = session_save_path();
 
-                       list($this->_account_lid, $this->_account_domain) = 
explode('@', $session['session_lid']);
-
-                       if ($this->_account_domain == '')
+                       // debian/ubuntu set the perms to /var/lib/php5 and so 
the sessions can't be read
+                       if ( !is_readable($path) )
                        {
-                               $this->_account_domain = 
$GLOBALS['phpgw_info']['server']['default_domain'];
+                               // FIXME we really should throw an exception 
here
+                               $values[] = array
+                               (
+                                       'id'            => 'Unable to read 
sessions',
+                                       'lid'           => 'invalid',
+                                       'ip'            => '0.0.0.0',
+                                       'action'        => 'Access denied by 
underlying filesystem',
+                                       'dla'           => 0,
+                                       'logints'       => 0
+                               );
+                               return $values;
                        }
 
-                       $phpgw_info_flags = $GLOBALS['phpgw_info']['flags'];
-
-                       $GLOBALS['phpgw_info']['flags'] = $phpgw_info_flags;
-
-                       $this->update_dla();
-                       $this->_account_id = 
$GLOBALS['phpgw']->interserver->name2id($this->_account_lid);
-
-                       if (!$this->_account_id)
+                       $dir = new RecursiveDirectoryIterator();
+                       foreach ( $dir as $filename )
                        {
-                               return false;
-                       }
-
-                       $GLOBALS['phpgw_info']['user']['account_id'] = 
$this->_account_id;
-
-                       $use_cache = false;
-                       if ( 
isset($GLOBALS['phpgw_info']['server']['cache_phpgw_info']) )
-                       {
-                               $use_cache = 
!!$GLOBALS['phpgw_info']['server']['cache_phpgw_info'];
-                       }
-
-                       $this->read_repositories($use_cache);
-
-                       // init the crypto object before appsession call below
-                       $this->_key = md5($this->_sessionid . 
$GLOBALS['phpgw_info']['server']['encryptkey']);
-                       $this->_iv  = 
$GLOBALS['phpgw_info']['server']['mcrypt_iv'];
-                       $GLOBALS['phpgw']->crypto->init(array($this->_key, 
$this->_iv));
-
-                       $GLOBALS['phpgw_info']['user']  = $this->_data;
-                       $GLOBALS['phpgw_info']['hooks'] = $this->hooks;
-
-                       $GLOBALS['phpgw_info']['user']['session_ip'] = 
$session['session_ip'];
-                       $GLOBALS['phpgw_info']['user']['passwd'] = 
base64_decode($this->appsession('password', 'phpgwapi'));
-
-                       if ($userid_array[1] != 
$GLOBALS['phpgw_info']['user']['domain'])
-                       {
-                               if(is_object($GLOBALS['phpgw']->log))
+                               // only try php session files
+                               if ( !preg_match('/^sess_([a-f0-9]+)$/', 
$filename) )
                                {
-                                       $GLOBALS['phpgw']->log->message(array(
-                                               'text' => 'W-VerifySession, the 
domains %1 and %2 don\t match',
-                                               'p1'   => $userid_array[1],
-                                               'p2'   => 
$GLOBALS['phpgw_info']['user']['domain'],
-                                               'line' => __LINE__,
-                                               'file' => __FILE__
-                                       ));
-                                       $GLOBALS['phpgw']->log->commit();
+                                       continue;
                                }
 
-                               if(is_object($GLOBALS['phpgw']->crypto))
-                               {
-                                       $GLOBALS['phpgw']->crypto->cleanup();
-                                       unset($GLOBALS['phpgw']->crypto);
-                               }
-                               return false;
-                       }
+                               $data = 
unserialize(file_get_contents($filename));
 
-                       $verify_ip = false;
-                       if ( 
isset($GLOBALS['phpgw_info']['server']['sessions_checkip']) )
-                       {
-                               $verify_ip = 
!!$GLOBALS['phpgw_info']['server']['sessions_checkip'];
-                       }
-
-                       if ( $verify_ip )
-                       {
-                               if ( PHP_OS != 'Windows'
-                                       && ( 
!$GLOBALS['phpgw_info']['user']['session_ip']
-                                               || 
$GLOBALS['phpgw_info']['user']['session_ip'] != $this->_get_user_ip()) )
+                               // skip invalid or anonymous sessions
+                               if ( !isset($data['phpgw_session'])
+                                       || 
$data['phpgw_session']['session_install_id'] != $this->_install_id
+                                       || 
!isset($data['phpgw_session']['session_flags'])
+                                       || 
$data['phpgw_session']['session_flags'] == 'A' )
                                {
-                                       if(is_object($GLOBALS['phpgw']->log))
-                                       {
-                                               // This needs some better 
wording
-                                               
$GLOBALS['phpgw']->log->message(array(
-                                                       'text' => 
'W-VerifySession, IP %1 doesn\'t match IP %2 in session table',
-                                                       'p1'   => 
$this->_get_user_ip(),
-                                                       'p2'   => 
$GLOBALS['phpgw_info']['user']['session_ip'],
-                                                       'line' => __LINE__,
-                                                       'file' => __FILE__
-                                               ));
-                                               
$GLOBALS['phpgw']->log->commit();
-                                       }
-
-                                       if(is_object($GLOBALS['phpgw']->crypto))
-                                       {
-                                               
$GLOBALS['phpgw']->crypto->cleanup();
-                                               
unset($GLOBALS['phpgw']->crypto);
-                                       }
-                                       return false;
+                                       continue;
                                }
-                       }
 
-                       $GLOBALS['phpgw']->acl->acl($this->_account_id);
-                       
$GLOBALS['phpgw']->accounts->set_account($this->_account_id);
-                       
$GLOBALS['phpgw']->preferences->set_account_id($this->_account_id);
-                       
$GLOBALS['phpgw']->applications->applications($this->_account_id);
-
-                       if (! $this->_account_lid)
-                       {
-                               if(is_object($GLOBALS['phpgw']->log))
-                               {
-                                       // This needs some better wording
-                                       $GLOBALS['phpgw']->log->message(array(
-                                               'text' => 'W-VerifySession, 
account_id is empty',
-                                               'line' => __LINE__,
-                                               'file' => __FILE__
-                                       ));
-                                       $GLOBALS['phpgw']->log->commit();
-                               }
-
-                               if(is_object($GLOBALS['phpgw']->crypto))
-                               {
-                                       $GLOBALS['phpgw']->crypto->cleanup();
-                                       unset($GLOBALS['phpgw']->crypto);
-                               }
-                               return false;
+                               $values[$data['phpgw_session']['session_id']] = 
array
+                               (
+                                       'id'            => 
$data['phpgw_session']['session_id'],
+                                       'lid'           => 
$data['phpgw_session']['session_lid'],
+                                       'ip'            => 
$data['phpgw_session']['session_ip'],
+                                       'action'        => 
$data['phpgw_session']['session_action'],
+                                       'dla'           => 
$data['phpgw_session']['session_dla'],
+                                       'logints'       => 
$data['phpgw_session']['session_logintime']
+                               );
                        }
-                       else
-                       {
-                               return true;
-                       }
-                       */
+                       return $values;
+
                }
 
                /**
@@ -1557,7 +1443,7 @@
                        }
 
                        $secure = phpgw::get_var('HTTPS', 'bool', 'SERVER');
-                       session_set_cookie_params(0, '/', 
$this->_cookie_domain, $secure, true);
+                       session_set_cookie_params(0, 
$GLOBALS['phpgw_info']['server']['webserver_url'], $this->_cookie_domain, 
$secure, true);
                        return $this->_cookie_domain;
                }
 
@@ -1584,8 +1470,6 @@
                        $this->_data['userid']      = $this->_account_lid;
                        $this->_data['passwd']      = $this->_passwd;
 
-                       //echo '<pre>' . print_r($this->_data, true) . '</pre>';
-
                        if ( $write_cache )
                        {
                                phpgwapi_cache::session_set('phpgwapi', 
'phpgw_info', $this->_data);

Modified: trunk/phpgwapi/inc/class.sql.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.sql.inc.php        2008-06-24 00:11:21 UTC (rev 
18620)
+++ trunk/phpgwapi/inc/class.sql.inc.php        2008-06-24 14:09:05 UTC (rev 
18621)
@@ -98,11 +98,13 @@
        * @package phpgwapi
        * @subpackage database
        */
-       abstract class sql_
+       abstract class phpgwapi_sql_
        {
-               function sql_()
+               /*
+               public function __construct()
                {
                }
+               */
 
                /*************************************************************\
                * Usefull low level functions to create queries logically   *
@@ -113,9 +115,10 @@
                *
                * @param string $left The left operand of the staement
                * @param string $right The right operand of the statement
+               *
                * @return string with an equal criteria formated.
                */
-               function equal($field, $value)
+               public static function equal($field, $value)
                {
                        return $field.' = '.$value;
                }
@@ -125,9 +128,10 @@
                *
                * @param string $left Left operand.
                * @param string $right Right operand.
+               *
                * @return string with criteria.
                */
-               function not_equal($field, $value)
+               public static function not_equal($field, $value)
                {
                        return $field.' <> '.$value;
                }
@@ -137,9 +141,10 @@
                *
                * @param string $left The left operand of the staement
                * @param string $right The right operand of the statement
+               *
                * @return string with an greater than criteria formated.
                */
-               function greater($field, $value)
+               public static function greater($field, $value)
                {
                        return $field.' > '.$value;
                }
@@ -149,9 +154,10 @@
                *
                * @param string $left The left operand of the staement
                * @param string $right The right operand of the statement
+               *
                * @return string with an less than criteria formated.
                */
-               function less($field, $value)
+               public static function less($field, $value)
                {
                        return $field.' < '.$value;
                }
@@ -161,9 +167,10 @@
                *
                * @param string $left The left operand of the staement
                * @param string $right The right operand of the statement
+               *
                * @return string with an greater-equal than criteria formated.
                */
-               function greater_equal($field, $value)
+               public static function greater_equal($field, $value)
                {
                        return $field.' >= '.$value;
                }
@@ -173,9 +180,10 @@
                *
                * @param string $left The left operand of the staement
                * @param string $right The right operand of the statement
+               *
                * @return string with an less-equal than criteria formated.
                */
-               function less_equal($field, $value)
+               public static function less_equal($field, $value)
                {
                        return $field.' <= '.$value;
                }
@@ -185,11 +193,12 @@
                *
                * @param string $field For search in.
                * @param string $value That will search.
+               *
                * @return string that use LIKE to search in field.
                */
-               function has($field, $value)
+               public static function has($field, $value)
                {
-                       return sql_criteria::upper($field).' LIKE 
'."'%$value%'";
+                       return phpgwapi_sql_criteria::upper($field).' LIKE 
'."'%$value%'";
                }
 
                /**
@@ -197,11 +206,12 @@
                *
                * @param string $field For search in.
                * @param string $value That will search.
+               *
                * @return string that use LIKE to search in field.
                */
-               function begin_with($field, $value)
+               public static function begin_with($field, $value)
                {
-                       return sql_criteria::upper($field).' LIKE '."'$value%'";
+                       return phpgwapi_sql_criteria::upper($field).' LIKE 
'."'$value%'";
                }
 
                /**
@@ -209,22 +219,25 @@
                *
                * @param string $field For search in.
                * @param string $value That will search.
+               *
                * @return string that use LIKE to search in field.
                */
-               function end_with($field, $value)
+               public static function end_with($field, $value)
                {
-                       return sql_criteria::upper($field).' LIKE '."'%$value'";
+                       return phpgwapi_sql_criteria::upper($field).' LIKE 
'."'%$value'";
                }
 
                /**
                * Generate an AND conjuction for sql criterias.
                *
                * Always return with brackets. I have more confidence in DBMS 
speed than the code that I will need to analize it in php.
+               *
                * @param string $left Left operand.
                * @param string $right Right operand.
+               *
                * @return string with (right) and (left)
                */
-               function and_($left, $right)
+               public static function and_($left, $right)
                {
                        return '('.$left.' AND '.$right.')';
                }
@@ -234,9 +247,10 @@
                *
                * @param string $left Left operand.
                * @param string $right Right operand.
+               *
                * @return string with (right) or (left)
                */
-               function or_($left, $right)
+               public static function or_($left, $right)
                {
                        return ' ('.$left.' OR '.$right.') ';
                }
@@ -245,9 +259,10 @@
                * Generate a is null critieria for sql.
                *
                * @param string $data A field.
+               *
                * @return string with criteria.
                */
-               function is_null($data)
+               public static function is_null($data)
                {
                        return $data.' IS NULL';
                }
@@ -256,19 +271,20 @@
                * Generate a is not null critieria for sql.
                *
                * @param string $data A field.
+               *
                * @return string with criteria.
                */              
-               function not_null($data)
+               public static function not_null($data)
                {
                        return $data.' IS NOT NULL';
                }
 
-               function upper($value)
+               public static function upper($value)
                {
                        return 'UPPER('.$value.')';
                }
 
-               function lower($value)
+               public static function lower($value)
                {
                        return 'LOWER('.$value.')';
                }
@@ -278,9 +294,10 @@
                *
                * @param string $field String with the field which you can 
filter.
                * @param string $values Array with posible values
+               *
                * @return string with criteria.
                */
-               function in($field, $values, $type='integer')
+               public static function in($field, $values, $type='integer')
                {
                        // This must be changed by anything
                        if ( is_array($values) && count($values) > 1)
@@ -300,11 +317,11 @@
                                if (is_array($values))
                                {
                                        //this never gets executed!
-                                       return sql::equal($field, 
sql::$type(current($values)));
+                                       return phpgwapi_sql::equal($field, 
phpgwapi_sql::$type(current($values)));
                                }
                                else
                                {
-                                       return sql::equal($field, 
sql::$type($values));
+                                       return phpgwapi_sql::equal($field, 
phpgwapi_sql::$type($values));
                                }       
                        }
                }
@@ -316,7 +333,7 @@
                * @param string $and Array with the list of operators for and.
                * @return string with many and conjuntions at same level.
                */
-               function append_and($clause)
+               public static function append_and($clause)
                {
                        if(is_array($clause))
                        {
@@ -337,7 +354,7 @@
                * @return string with many or conjuntions at same level.
                * @see append_and
                */
-               function append_or($clause)
+               public static function append_or($clause)
                {
                        if(is_array($clause))
                        {
@@ -356,24 +373,25 @@
 
                /**
                * @param str string the value that will be casted for sql type
+               *
                * @return string ready for using for a value with CHARACTER sql 
type
                */
-               function string($str)
+               public static function string($str)
                {
                        $str = $GLOBALS['phpgw']->db->db_addslashes($str);
                        return "'$str'";
                }
 
-               function character($str)
+               public static function character($str)
                {
-                       return sql::string($str);
+                       return phpgwapi_sql::string($str);
                }
 
                /**
                * @param integer string the value that will be casted for sql 
type
                * @return string ready for using for a value with INTEGER sql 
type              
                */
-               function integer($integer)
+               public static function integer($integer)
                {
                        return (int) $integer;
                }
@@ -381,28 +399,29 @@
                /**
                * Generate a string with date
                */
-               function date_($date, $format=False)
+               public static function date_($date, $format=False)
                {
                        switch(gettype($date))
                        {
-                       case 'integer':
-                               return sql::int_date2str($date, $format);
-                       default:
-                               return sql::str_date2int($date, $format);
+                               case 'integer':
+                                       return 
phpgwapi_sql::int_date2str($date, $format);
+
+                               default:
+                                       return 
phpgwapi_sql::str_date2int($date, $format);
                        }
                }
 
                /**
                * return a string with time
                */
-               function time_($time, $format=False)
+               public static function time_($time, $format=False)
                {
                        switch(gettype($time))
                        {
                        case 'integer':
-                               return sql::int_time2str($time, $format);
+                               return phpgwapi_sql::int_time2str($time, 
$format);
                        default:
-                               return sql::str_time2int($time, $format);
+                               return phpgwapi_sql::str_time2int($time, 
$format);
                        }
                }
 
@@ -410,27 +429,27 @@
                * Data types conversion                                      *
                \*************************************************************/
 
-               function int_date2str($int, $format=False)
+               public static function int_date2str($int, $format=False)
                {
                        $format = $format ? $format : 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
                        return date($format, intval($int));
                }
 
-               function int_time2str($int, $format=False)
+               public static function int_time2str($int, $format=False)
                {
                        $format = $format ? $format : 
$GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'];
                        return date($format, intval($int));
                }
                //note this is not 100% reliable, but close enough
-               function str_date2int($date, $format=False)
+               public static function str_date2int($date, $format=False)
                {
                        $format = $format ? $format : 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
                        return date($format, intval(strtotime($date)));
                }
 
-               function str_time2int($time)
+               public static function str_time2int($time)
                {
-                       return intval(sql::str_date2int($time));
+                       return (int) phpgwapi_sql::str_date2int($time);
                }
 
                /*************************************************************\
@@ -440,7 +459,7 @@
                /**
                * Return a NULL value
                */
-               function null()
+               public static function null()
                {
                        return ' NULL ';
                }
@@ -453,7 +472,7 @@
                * @param array $elements array with the elemnts that want to 
concatenate
                * @return string with $elements concatenated
                */
-               function concat($elements)
+               public static function concat($elements)
                {
                }
 
@@ -464,7 +483,7 @@
                * @param array $elements array with the elemnts that want to 
concatenate
                * @return string with $elements concatenated
                */
-               function concat_null($elements)
+               public static function concat_null($elements)
                {
                }
 
@@ -475,7 +494,7 @@
                * string. use it in SELECT development.
                * @param string $value Field or expresion to make safe.
                */
-               function safe_null($value)
+               public static function safe_null($value)
                {
                        if(empty($value) || !is_array($value))
                        {

Modified: trunk/phpgwapi/inc/common_functions.inc.php
===================================================================
--- trunk/phpgwapi/inc/common_functions.inc.php 2008-06-24 00:11:21 UTC (rev 
18620)
+++ trunk/phpgwapi/inc/common_functions.inc.php 2008-06-24 14:09:05 UTC (rev 
18621)
@@ -239,7 +239,7 @@
                }
 
                // because $of_classname::CreateObject() is not allowed, we use 
call_user_func
-               return call_user_func("{$of_classname}::createObject", $class, 
$p1, $p2, $p3, $p4, $p5,
+               return call_user_func(array($of_classname, 'createObject'), 
$class, $p1, $p2, $p3, $p4, $p5,
                                                                $p6, $p7, $p8, 
$p9, $p10, $p11, $p12, $p13, $p14, $p15, $p16);
        }
 

Modified: trunk/phpgwapi/setup/tables_update.inc.php
===================================================================
--- trunk/phpgwapi/setup/tables_update.inc.php  2008-06-24 00:11:21 UTC (rev 
18620)
+++ trunk/phpgwapi/setup/tables_update.inc.php  2008-06-24 14:09:05 UTC (rev 
18621)
@@ -1987,11 +1987,6 @@
                        'uc' => array()
                ));
 
-// TODO:
-//# phpgw_cust_attribute
-//# phpgw_cust_choice
-//# phpgw_cust_function 
-
                // Sessions changes
                
$GLOBALS['phpgw_setup']->oProc->DropTable('phpgw_app_sessions'); // no longer 
needed
                $GLOBALS['phpgw_setup']->oProc->DropTable('phpgw_sessions');






reply via email to

[Prev in Thread] Current Thread [Next in Thread]