Project

General

Profile

« Previous | Next » 

Revision 2127

Added by darkviper almost 9 years ago

! framework/ ~WbDatabaseHelper ~WbDatabase some little correction to different methods

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
18 Jun -2015 Build 2127 Manuela v.d.Decken(DarkViper)
15
! framework/ ~WbDatabaseHelper  ~WbDatabase some little correction to different methods
14 16
18 Jun -2015 Build 2126 Manuela v.d.Decken(DarkViper)
15 17
! /framework/msgQueue
16 18
Methods  ::getError() and ::getSuccess() are deprecated and have
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.4');
54
if(!defined('REVISION')) define('REVISION', '2126');
54
if(!defined('REVISION')) define('REVISION', '2127');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/WbDatabaseHelper.php
38 38
 * Alias for isField()
39 39
 * @deprecated from WB-2.8.5 and higher
40 40
 */
41
	public function field_exists($table_name, $field_name)
42
	{
43
		return $this->isField($table_name, $field_name);
44
	}
41
    public function field_exists($table_name, $field_name)
42
    {
43
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
44
        return $this->isField($table_name, $field_name);
45
    }
45 46
/*
46 47
 * @param string full name of the table (incl. TABLE_PREFIX)
47 48
 * @param string name of the field to seek for
48 49
 * @return bool true if field exists
49 50
 */
50
	public function isField($table_name, $field_name)
51
	{
52
		$sql = 'DESCRIBE `'.$table_name.'` `'.$field_name.'` ';
53
		$query = $this->doQuery($sql);
54
		return ($query->numRows() != 0);
55
	}
51
    public function isField($table_name, $field_name)
52
    {
53
        $sql = 'DESCRIBE `'.$table_name.'` `'.$field_name.'` ';
54
        $query = $this->doQuery($sql);
55
        return ($query->numRows() != 0);
56
    }
56 57
/**
57 58
 * Alias for isIndex()
58 59
 * @deprecated from WB-2.8.5 and higher
59 60
 */
60
	public function index_exists($table_name, $index_name, $number_fields = 0)
61
	{
62
		return $this->isIndex($table_name, $index_name, $number_fields = 0);
63
	}
61
    public function index_exists($table_name, $index_name, $number_fields = 0)
62
    {
63
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
64
        return $this->isIndex($table_name, $index_name, $number_fields = 0);
65
    }
64 66
/*
65 67
 * isIndex
66 68
 * @param string full name of the table (incl. TABLE_PREFIX)
67 69
 * @param string name of the index to seek for
68 70
 * @return bool true if field exists
69 71
 */
70
	public function isIndex($table_name, $index_name, $number_fields = 0)
71
	{
72
		$number_fields = intval($number_fields);
73
		$keys = 0;
74
		$sql = 'SHOW INDEX FROM `'.$table_name.'`';
75
		if (($res_keys = $this->doQuery($sql))) {
76
			while (($rec_key = $res_keys->fetchRow(MYSQL_ASSOC))) {
77
				if ( $rec_key['Key_name'] == $index_name ) {
78
					$keys++;
79
				}
80
			}
72
    public function isIndex($table_name, $index_name, $number_fields = 0)
73
    {
74
        $number_fields = intval($number_fields);
75
        $keys = 0;
76
        $sql = 'SHOW INDEX FROM `'.$table_name.'`';
77
        if (($res_keys = $this->doQuery($sql))) {
78
            while (($rec_key = $res_keys->fetchRow(MYSQL_ASSOC))) {
79
                if ( $rec_key['Key_name'] == $index_name ) {
80
                    $keys++;
81
                }
82
            }
81 83

  
82
		}
83
		if ( $number_fields == 0 ) {
84
			return ($keys != $number_fields);
85
		} else {
86
			return ($keys == $number_fields);
87
		}
88
	}
84
        }
85
        if ( $number_fields == 0 ) {
86
            return ($keys != $number_fields);
87
        } else {
88
            return ($keys == $number_fields);
89
        }
90
    }
89 91
/**
90 92
 * Alias for addField()
91 93
 * @deprecated from WB-2.8.5 and higher
92 94
 */
93
	public function field_add($table_name, $field_name, $description)
94
	{
95
		return $this->addField($table_name, $field_name, $description);
96
	}
95
    public function field_add($table_name, $field_name, $description)
96
    {
97
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
98
        return $this->addField($table_name, $field_name, $description);
99
    }
97 100
/*
98 101
 * @param string full name of the table (incl. TABLE_PREFIX)
99 102
 * @param string name of the field to add
100 103
 * @param string describes the new field like ( INT NOT NULL DEFAULT '0')
101 104
 * @return bool true if successful, otherwise false and error will be set
102 105
 */
103
	public function addField($table_name, $field_name, $description)
104
	{
105
		if (!$this->isField($table_name, $field_name)) {
106
		// add new field into a table
107
			$sql = 'ALTER TABLE `'.$table_name.'` ADD '.$field_name.' '.$description.' ';
108
			$query = $this->doQuery($sql);
109
			$this->set_error(mysqli_error($this->oDbHandle));
110
			if (!$this->isError()) {
111
				return ( $this->isField($table_name, $field_name) ) ? true : false;
112
			}
113
		} else {
114
			$this->set_error('field \''.$field_name.'\' already exists');
115
		}
116
		return false;
117
	}
106
    public function addField($table_name, $field_name, $description)
107
    {
108
        if (!$this->isField($table_name, $field_name)) {
109
        // add new field into a table
110
            $sql = 'ALTER TABLE `'.$table_name.'` ADD '.$field_name.' '.$description.' ';
111
            $query = $this->doQuery($sql);
112
            $this->set_error(mysqli_error($this->oDbHandle));
113
            if (!$this->isError()) {
114
                return ( $this->isField($table_name, $field_name) ) ? true : false;
115
            }
116
        } else {
117
            $this->set_error('field \''.$field_name.'\' already exists');
118
        }
119
        return false;
120
    }
118 121
/**
119 122
 * Alias for modifyField()
120 123
 * @deprecated from WB-2.8.5 and higher
121 124
 */
122
	public function field_modify($table_name, $field_name, $description)
123
	{
124
		return $this->modifyField($table_name, $field_name, $description);
125
	}
125
    public function field_modify($table_name, $field_name, $description)
126
    {
127
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
128
        return $this->modifyField($table_name, $field_name, $description);
129
    }
126 130
/*
127 131
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
128 132
 * @param string $field_name: name of the field to add
129 133
 * @param string $description: describes the new field like ( INT NOT NULL DEFAULT '0')
130 134
 * @return bool: true if successful, otherwise false and error will be set
131 135
 */
132
	public function modifyField($table_name, $field_name, $description)
133
	{
134
		$retval = false;
135
		if ($this->isField($table_name, $field_name)) {
136
		// modify a existing field in a table
137
			$sql  = 'ALTER TABLE `'.$table_name.'` MODIFY `'.$field_name.'` '.$description;
138
			$retval = ( $this->doQuery($sql) ? true : false);
139
			$this->setError(mysqli_error($this->oDbHandle));
140
		}
141
		return $retval;
142
	}
136
    public function modifyField($table_name, $field_name, $description)
137
    {
138
        $retval = false;
139
        if ($this->isField($table_name, $field_name)) {
140
        // modify a existing field in a table
141
            $sql  = 'ALTER TABLE `'.$table_name.'` MODIFY `'.$field_name.'` '.$description;
142
            $retval = ( $this->doQuery($sql) ? true : false);
143
            $this->setError(mysqli_error($this->oDbHandle));
144
        }
145
        return $retval;
146
    }
143 147
/**
144 148
 * Alias for removeField()
145 149
 * @deprecated from WB-2.8.5 and higher
146 150
 */
147
	public function field_remove($table_name, $field_name)
148
	{
149
		return $this->removeField($table_name, $field_name);
150
	}
151
    public function field_remove($table_name, $field_name)
152
    {
153
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
154
        return $this->removeField($table_name, $field_name);
155
    }
151 156
/*
152 157
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
153 158
 * @param string $field_name: name of the field to remove
154 159
 * @return bool: true if successful, otherwise false and error will be set
155 160
 */
156
	public function removeField($table_name, $field_name)
157
	{
158
		$retval = false;
159
		if ($this->isField($table_name, $field_name)) {
160
		// modify a existing field in a table
161
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP `'.$field_name.'`';
162
			$retval = ( $this->doQuery($sql, $this->oDbHandle) ? true : false );
163
		}
164
		return $retval;
165
	}
161
    public function removeField($table_name, $field_name)
162
    {
163
        $retval = false;
164
        if ($this->isField($table_name, $field_name)) {
165
        // modify a existing field in a table
166
            $sql  = 'ALTER TABLE `'.$table_name.'` DROP `'.$field_name.'`';
167
            $retval = ( $this->doQuery($sql, $this->oDbHandle) ? true : false );
168
        }
169
        return $retval;
170
    }
166 171
/**
167 172
 * Alias for addIndex()
168 173
 * @deprecated from WB-2.8.5 and higher
169 174
 */
170 175
    public function index_add($table_name, $index_name, $field_list, $index_type = 'KEY')
171
	{
172
		return $this->addIndex($table_name, $index_name, $field_list, $index_type);
173
	}
176
    {
177
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
178
        return $this->addIndex($table_name, $index_name, $field_list, $index_type);
179
    }
174 180
/*
175 181
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
176 182
 * @param string $index_name: name of the new index (empty string for PRIMARY)
......
178 184
 * @param string $index_type: kind of index (PRIMARY, UNIQUE, KEY, FULLTEXT)
179 185
 * @return bool: true if successful, otherwise false and error will be set
180 186
 */
181
     public function addIndex($table_name, $index_name, $field_list, $index_type = 'KEY')
182
     {
183
        $retval = false;
184
        $field_list = explode(',', (str_replace(' ', '', $field_list)));
185
        $number_fields = sizeof($field_list);
186
        $field_list = '`'.implode('`,`', $field_list).'`';
187
        $index_name = $index_type == 'PRIMARY' ? $index_type : $index_name;
188
        if ( $this->isIndex($table_name, $index_name, $number_fields) ||
189
             $this->isIndex($table_name, $index_name))
190
        {
191
            $sql  = 'ALTER TABLE `'.$table_name.'` ';
192
            $sql .= 'DROP INDEX `'.$index_name.'`';
193
            if (!$this->doQuery($sql)) { return false; }
194
        }
195
        $sql  = 'ALTER TABLE `'.$table_name.'` ';
196
        $sql .= 'ADD '.$index_type.' ';
197
        $sql .= $index_type == 'PRIMARY' ? 'KEY ' : '`'.$index_name.'` ';
198
        $sql .= '( '.$field_list.' ); ';
199
        if ($this->doQuery($sql)) { $retval = true; }
200
        return $retval;
201
    }
187
    public function addIndex($table_name, $index_name, $field_list, $index_type = 'KEY')
188
    {
189
       $retval = false;
190
       $field_list = explode(',', (str_replace(' ', '', $field_list)));
191
       $number_fields = sizeof($field_list);
192
       $field_list = '`'.implode('`,`', $field_list).'`';
193
       $index_name = $index_type == 'PRIMARY' ? $index_type : $index_name;
194
       if ( $this->isIndex($table_name, $index_name, $number_fields) ||
195
            $this->isIndex($table_name, $index_name))
196
       {
197
           $sql  = 'ALTER TABLE `'.$table_name.'` ';
198
           $sql .= 'DROP INDEX `'.$index_name.'`';
199
           if (!$this->doQuery($sql)) { return false; }
200
       }
201
       $sql  = 'ALTER TABLE `'.$table_name.'` ';
202
       $sql .= 'ADD '.$index_type.' ';
203
       $sql .= $index_type == 'PRIMARY' ? 'KEY ' : '`'.$index_name.'` ';
204
       $sql .= '( '.$field_list.' ); ';
205
       if ($this->doQuery($sql)) { $retval = true; }
206
       return $retval;
207
   }
202 208
/**
203 209
 * Alias for removeIndex()
204 210
 * @deprecated from WB-2.8.5 and higher
205 211
 */
206
	public function index_remove($table_name, $index_name)
207
	{
208
		return $this->removeIndex($table_name, $index_name);
209
	}
212
    public function index_remove($table_name, $index_name)
213
    {
214
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
215
        return $this->removeIndex($table_name, $index_name);
216
    }
210 217
/*
211 218
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
212 219
 * @param string $field_name: name of the field to remove
213 220
 * @return bool: true if successful, otherwise false and error will be set
214 221
 */
215
	public function removeIndex($table_name, $index_name)
216
	{
217
		$retval = false;
218
		if ($this->isIndex($table_name, $index_name)) {
219
		// modify a existing field in a table
220
			$sql  = 'ALTER TABLE `'.$table_name.'` DROP INDEX `'.$index_name.'`';
221
			$retval = ( $this->doQuery($sql) ? true : false );
222
		}
223
		return $retval;
224
	}
222
    public function removeIndex($table_name, $index_name)
223
    {
224
        $retval = false;
225
        if ($this->isIndex($table_name, $index_name)) {
226
        // modify a existing field in a table
227
            $sql  = 'ALTER TABLE `'.$table_name.'` DROP INDEX `'.$index_name.'`';
228
            $retval = ( $this->doQuery($sql) ? true : false );
229
        }
230
        return $retval;
231
    }
225 232
/**
226 233
 * Alias for importSql()
227 234
 * @deprecated from WB-2.8.5 and higher
228 235
 */
229
	public function SqlImport($sSqlDump,
230
	                          $sTablePrefix = '',
231
	                          $sAction      = 'install',
232
	                          $sEngine      = 'MyISAM',
233
	                          $sCollation   = 'utf8_unicode_ci')
234
	{
235
		return $this->importSql($sSqlDump, $sTablePrefix, $sAction, $sEngine, $sCollation);
236
	}
236
    public function SqlImport($sSqlDump,
237
                              $sTablePrefix = '',
238
                              $sAction      = 'install',
239
                              $sEngine      = 'MyISAM',
240
                              $sCollation   = 'utf8_unicode_ci')
241
    {
242
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
243
        $oImport = new SqlImport($this, $sSqlDump);
244
        return $oImport->doImport($sAction);
245
    }
237 246

  
238 247
/**
239 248
 * retuns the type of the engine used for requested table
240 249
 * @param string $table name of the table, including prefix
241 250
 * @return boolean/string false on error, or name of the engine (myIsam/InnoDb)
242 251
 */
243
	public function getTableEngine($table)
244
	{
245
		$retVal = false;
246
		$mysqlVersion = mysqli_get_server_info($this->oDbHandle);
247
		$engineValue = (version_compare($mysqlVersion, '5.0') < 0) ? 'Type' : 'Engine';
248
		$sql = 'SHOW TABLE STATUS FROM `' . $this->sDbName . '` LIKE \'' . $table . '\'';
249
		if (($result = $this->doQuery($sql))) {
250
			if (($row = $result->fetchRow(MYSQL_ASSOC))) {
251
				$retVal = $row[$engineValue];
252
			}
253
		}
254
		return $retVal;
255
	}
256

  
252
    public function getTableEngine($table)
253
    {
254
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
255
        $retVal = false;
256
        $mysqlVersion = mysqli_get_server_info($this->oDbHandle);
257
        $engineValue = (version_compare($mysqlVersion, '5.0') < 0) ? 'Type' : 'Engine';
258
        $sql = 'SHOW TABLE STATUS FROM `' . $this->sDbName . '` LIKE \'' . $table . '\'';
259
        if (($result = $this->doQuery($sql))) {
260
            if (($row = $result->fetchRow(MYSQL_ASSOC))) {
261
                $retVal = $row[$engineValue];
262
            }
263
        }
264
        return $retVal;
265
    }
257 266
}
258 267

  
259 268
// end of class WbDatabaseHelper
269
// //////////////////////////////////////////////////////////////////////////////////// //
270
/* this functions are placed inside this file temporarely until a better place is found */
271
/* function to update a var/value-pair(s) in table ****************************
272
 * nonexisting keys are inserted
273
 * @param string $table: name of table to use (without prefix)
274
 * @param mixed $key:    a array of key->value pairs to update
275
 *                       or a string with name of the key to update
276
 * @param string $value: a sting with needed value, if $key is a string too
277
 * @return bool:  true if any keys are updated, otherwise false
278
 */
279
    function updateDbKeyValue($table, $key, $value = '')
280
    {
281
        $oDb = WbDatabase::getInstance();
282
        $table = preg_replace('/^'.preg_quote($oDb->TablePrefix, '/').'/s', '', $table);
283
        if (!is_array($key)) {
284
            if (trim($key) != '') {
285
                $key = array( trim($key) => trim($value) );
286
            } else {
287
                $key = array();
288
            }
289
        }
290
        $retval = true;
291
        $sNameValPairs = '';
292
        foreach ($key as $index => $val) {
293
            $sNameValPairs .= ', (\''.$index.'\', \''.$val.'\')';
294
        }
295
        $sValues = ltrim($sNameValPairs, ', ');
296
        if ($sValues != '') {
297
            $sql = 'REPLACE INTO `'.$oDb->TablePrefix.$table.'` (`name`, `value`) '
298
                 . 'VALUES '.$sValues;
299
            if (!$oDb->doQuery($sql)) {
300
                $retval = false;
301
            }
302
        }
303
        return $retval;
304
    }
305
/**
306
 * Alias for updateDbKeyValue()
307
 * @param string $table: name of table to use (without prefix)
308
 * @param mixed $key:    a array of key->value pairs to update
309
 *                        or a string with name of the key to update
310
 * @param string $value: a sting with needed value, if $key is a string too
311
 * @return bool:  true if any keys are updated, otherwise false
312
 * @deprecated from 2.8.4
313
 */
314
    function db_update_key_value($table, $key, $value = '')
315
    {
316
        trigger_error('Deprecated function call: '.basename(__FILE__).'::'.__FUNCTION__, E_USER_DEPRECATED);
317
        return updateDbKeyValue($table, $key, $value);
318
    }
branches/2.8.x/wb/framework/WbDatabase.php
21 21
 * @category     Core
22 22
 * @package      Core_database
23 23
 * @author       Manuela v.d.Decken <manuela@isteam.de>
24
 * @author       Dietmar W. <dietmar.woellbrink@websitebaker.org>
25 24
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
26 25
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
27
 * @version      0.0.9
26
 * @version      0.1.1
28 27
 * @revision     $Revision$
29 28
 * @lastmodified $Date$
30
 * @deprecated   from WB version number 2.9
31
 * @description  Mysql database wrapper for use with websitebaker up to version 2.8.4
29
 * @description  Mysqli database wrapper for use with websitebaker version 2.8.4
32 30
 */
33 31

  
34 32
/* -------------------------------------------------------- */
35 33
@define('DATABASE_CLASS_LOADED', true);
36
	/* define the old mysql consts for Backward compatibility */
37
	if (!defined('MYSQL_ASSOC'))
38
	{
39
		define('MYSQL_SEEK_LAST',            -1);
40
		define('MYSQL_SEEK_FIRST',            0);
41
		define('MYSQL_ASSOC',                 1);
42
		define('MYSQL_NUM',                   2);
43
		define('MYSQL_BOTH',                  3);
44
		define('MYSQL_CLIENT_COMPRESS',      32);
45
		define('MYSQL_CLIENT_IGNORE_SPACE', 256);
46
		define('MYSQL_CLIENT_INTERACTIVE', 1024);
47
		define('MYSQL_CLIENT_SSL',         2048);
48
	}
49 34

  
35
    define('MYSQLI_SEEK_LAST',            -1);
36
    define('MYSQLI_SEEK_FIRST',            0);
37
/* define the old mysql consts for Backward compatibility */
38
    if (!defined('MYSQL_ASSOC'))
39
    {
40
        define('MYSQL_SEEK_LAST',            -1);
41
        define('MYSQL_SEEK_FIRST',            0);
42
        define('MYSQL_ASSOC',                 1);
43
        define('MYSQL_NUM',                   2);
44
        define('MYSQL_BOTH',                  3);
45
        define('MYSQL_CLIENT_COMPRESS',      32);
46
        define('MYSQL_CLIENT_IGNORE_SPACE', 256);
47
        define('MYSQL_CLIENT_INTERACTIVE', 1024);
48
        define('MYSQL_CLIENT_SSL',         2048);
49
    }
50

  
50 51
class WbDatabase extends WbDatabaseHelper {
51 52

  
52
	private static $_oInstances = array();
53
    private static $_oInstances = array();
53 54

  
54
	protected $oDbHandle    = null; // readonly from outside
55
	protected $sDbName      = '';
56
	protected $sInstanceIdentifier = '';
57
	protected $sTablePrefix = '';
58
	protected $sCharset     = '';
59
	protected $connected    = false;
60
	protected $error        = '';
61
	protected $error_type   = '';
62
	protected $iQueryCount  = 0;
55
    protected $oDbHandle    = null; // readonly from outside
56
    protected $sDbName      = '';
57
    protected $sInstanceIdentifier = '';
58
    protected $sTablePrefix = '';
59
    protected $sCharset     = '';
60
    protected $connected    = false;
61
    protected $error        = '';
62
    protected $error_type   = '';
63
    protected $iQueryCount  = 0;
63 64

  
64 65
/**
65 66
 * __constructor
66 67
 *  prevent from public instancing
67 68
 */
68
	final private function  __construct() {}
69
    final private function  __construct() {}
69 70
/**
70 71
 * prevent from cloning
71 72
 */
72
	final private function __clone() {}
73
    final private function __clone() {}
73 74
/**
74 75
 * get a valid instance of this class
75 76
 * @param string $sIdentifier selector for several different instances
76 77
 * @return WbDatabase object
77 78
 */
78
	final public static function getInstance($sIdentifier = 'core')
79
	{
80
		if( !isset(self::$_oInstances[$sIdentifier])) {
79
    final public static function getInstance($sIdentifier = 'core')
80
    {
81
        if( !isset(self::$_oInstances[$sIdentifier])) {
81 82
            $c = __CLASS__;
82
			$oInstance = new $c;
83
			$oInstance->sInstanceIdentifier = $sIdentifier;
83
            $oInstance = new $c;
84
            $oInstance->sInstanceIdentifier = $sIdentifier;
84 85
            self::$_oInstances[$sIdentifier] = $oInstance;
85
		}
86
		return self::$_oInstances[$sIdentifier];
87
	}
86
        }
87
        return self::$_oInstances[$sIdentifier];
88
    }
88 89
/**
89 90
 * disconnect and kills an existing instance
90 91
 * @param string $sIdentifier selector for instance to kill
91 92
 */
92
	final public static function killInstance($sIdentifier)
93
	{
94
		if($sIdentifier != 'core') {
95
			if( isset(self::$_oInstances[$sIdentifier])) {
96
				self::$_oInstances[$sIdentifier]->disconnect();
97
				unset(self::$_oInstances[$sIdentifier]);
98
			}
99
		}
100
	}
93
    final public static function killInstance($sIdentifier)
94
    {
95
        if($sIdentifier != 'core') {
96
            if( isset(self::$_oInstances[$sIdentifier])) {
97
                self::$_oInstances[$sIdentifier]->disconnect();
98
                unset(self::$_oInstances[$sIdentifier]);
99
            }
100
        }
101
    }
101 102
/**
102 103
 * Establish connection
103 104
 * @param string $url
......
106 107
 * @description opens a connection using connect URL<br />
107 108
 *              Example for SQL-Url:  'mysql://user:password@example.com[:3306]/database?charset=utf8&tableprefix=xx_'
108 109
 */
109
	public function doConnect($url = '')
110
	{
111
		if ($this->connected) { return $this->connected; } // prevent from reconnecting
112
		$this->connected = false;
113
		if ($url != '') {
114
		// parse URL and extract connection data
115
			$aIni = parse_url($url);
116
			$scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysqli';
117
			$hostname = isset($aIni['host']) ? $aIni['host'] : '';
118
			$username = isset($aIni['user']) ? $aIni['user'] : '';
119
			$password = isset($aIni['pass']) ? $aIni['pass'] : '';
120
			$hostport = isset($aIni['port']) ? $aIni['port'] : '3306';
121
			$hostport = $hostport == '3306' ? null : $hostport;
122
			$db_name  = ltrim(isset($aIni['path']) ? $aIni['path'] : '', '/\\');
123
			$sTmp = isset($aIni['query']) ? $aIni['query'] : '';
124
			$aQuery = explode('&', $sTmp);
125
			foreach ($aQuery as $sArgument) {
126
				$aArg = explode('=', $sArgument);
127
				switch (strtolower($aArg[0])) {
128
					case 'charset':
129
						$this->sCharset = strtolower(preg_replace('/[^a-z0-9]/i', '', $aArg[1]));
130
						break;
131
					case 'tableprefix':
132
						$this->sTablePrefix = $aArg[1];
133
						break;
134
					default:
135
						break;
136
				}
137
			}
138
			$this->sDbName = $db_name;
139
		} else {
140
			throw new WbDatabaseException('Missing parameter: unable to connect database');
141
		}
142
		$this->oDbHandle = @mysqli_connect($hostname, $username, $password, $db_name, $hostport);
143
		if (!$this->oDbHandle) {
144
			throw new WbDatabaseException('unable to connect \''.$scheme.'://'.$hostname.':'.$hostport.'\'');
145
		} else {
110
    public function doConnect($url = '')
111
    {
112
        if ($this->connected) { return $this->connected; } // prevent from reconnecting
113
        $this->connected = false;
114
        if ($url != '') {
115
        // parse URL and extract connection data
116
            $aIni = parse_url($url);
117
            $scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysqli';
118
            $hostname = isset($aIni['host']) ? $aIni['host'] : '';
119
            $username = isset($aIni['user']) ? $aIni['user'] : '';
120
            $password = isset($aIni['pass']) ? $aIni['pass'] : '';
121
            $hostport = isset($aIni['port']) ? $aIni['port'] : '3306';
122
            $hostport = $hostport == '3306' ? null : $hostport;
123
            $db_name  = ltrim(isset($aIni['path']) ? $aIni['path'] : '', '/\\');
124
            $sTmp = isset($aIni['query']) ? $aIni['query'] : '';
125
            $aQuery = explode('&', $sTmp);
126
            foreach ($aQuery as $sArgument) {
127
                $aArg = explode('=', $sArgument);
128
                switch (strtolower($aArg[0])) {
129
                    case 'charset':
130
                        $this->sCharset = strtolower(preg_replace('/[^a-z0-9]/i', '', $aArg[1]));
131
                        break;
132
                    case 'tableprefix':
133
                        $this->sTablePrefix = $aArg[1];
134
                        break;
135
                    default:
136
                        break;
137
                }
138
            }
139
            $this->sDbName = $db_name;
140
        } else {
141
            throw new WbDatabaseException('Missing parameter: unable to connect database');
142
        }
143
        $this->oDbHandle = @mysqli_connect($hostname, $username, $password, $db_name, $hostport);
144
        if (!$this->oDbHandle) {
145
            throw new WbDatabaseException('unable to connect \''.$scheme.'://'.$hostname.':'.$hostport.'\'');
146
        } else {
146 147
            if ($this->sCharset) {
147 148
                @mysqli_query($this->oDbHandle, 'SET NAMES '.$this->sCharset);
148 149
                mysqli_set_charset($this->oDbHandle, $this->sCharset);
149 150
            }
150 151
            $this->connected = true;
151
		}
152
		return $this->connected;
153
	}
152
        }
153
        return $this->connected;
154
    }
154 155
/**
155 156
 * disconnect database
156 157
 * @return bool
157 158
 * @description Disconnect current object from the database<br />
158 159
 *              the 'core' connection can NOT be disconnected!
159 160
 */
160
	public function disconnect()
161
	{
162
		if ($this->connected == true && $oInstance->sInstanceIdentifier != 'core') {
163
			mysqli_close($this->oDbHandle);
164
			$this->connected = false;
165
			return true;
166
		}
167
		return false;
168
	}
161
    public function disconnect()
162
    {
163
        if ($this->connected == true && $oInstance->sInstanceIdentifier != 'core') {
164
            mysqli_close($this->oDbHandle);
165
            $this->connected = false;
166
            return true;
167
        }
168
        return false;
169
    }
169 170
/**
170 171
 * Alias for doQuery()
171
 * @deprecated from WB-2.8.5 and higher
172
 * @deprecated from WB-2.8.4 and higher
172 173
 */
173
	public function query($statement)
174
	{
175
		return $this->doQuery($statement);
176
	}
174
    public function query($statement)
175
    {
176
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
177
        return $this->doQuery($statement);
178
    }
177 179
/**
178 180
 * execute query
179 181
 * @param string $statement the SQL-statement to execute
180 182
 * @return null|\mysql
181 183
 */
182
	public function doQuery($statement) {
183
		$this->iQueryCount++;
184
		$mysql = new mysql($this->oDbHandle);
185
		$mysql->query($statement);
186
		$this->set_error($mysql->error($this->oDbHandle));
187
		if ($mysql->error()) {
188
			return null;
189
		} else {
190
			return $mysql;
191
		}
192
	}
184
    public function doQuery($statement) {
185
        $oRetval = null;
186
        $this->iQueryCount++;
187
        $mysql = new mysql($this->oDbHandle, $statement);
188
        $this->set_error($mysql->error($this->oDbHandle));
189
        if (!$mysql->error()) {
190
            $oRetval = $mysql;
191
        }
192
        $this->set_error($mysql->error($this->oDbHandle));
193
        return $oRetval;
194
    }
193 195
/**
194 196
 * Alias for getOne()
195
 * @deprecated from WB-2.8.5 and higher
197
 * @deprecated from WB-2.8.4 and higher
196 198
 */
197
	public function get_one( $statement )
198
	{
199
		return $this->getOne($statement);
200
	}
201
	// Gets the first column of the first row
199
    public function get_one( $statement )
200
    {
201
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
202
        return $this->getOne($statement);
203
    }
204
    // Gets the first column of the first row
202 205
/**
203 206
 * Gets the first column of the first row
204 207
 * @param string $statement  SQL-statement
205 208
 * @return null|mixed
206 209
 */
207
	public function getOne( $statement )
208
	{
209
		$this->iQueryCount++;
210
		$fetch_row = mysqli_fetch_array(mysqli_query($this->oDbHandle, $statement));
211
		$result = $fetch_row[0];
212
		$this->set_error(null);
213
		if (mysqli_error($this->oDbHandle)) {
214
    		$this->set_error(mysqli_error($this->oDbHandle));
215
			return null;
216
		} else {
217
			return $result;
218
		}
219
	}
210
    public function getOne( $sStatement )
211
    {
212
        $sRetval = null;
213
        if (($oRecSet = $this->doQuery($sStatement))) {
214
            if (($aRecord = $oRecSet->fetchArray(MYSQL_NUM))) {
215
                $sRetval = $aRecord[0];
216
            }
217
        }
218
        return ($this->isError() ? null : $sRetval);
219
    }
220 220
/**
221 221
 * Alias for setError()
222
 * @deprecated from WB-2.8.5 and higher
222
 * @deprecated from WB-2.8.4 and higher
223 223
 */
224
	public function set_error($message = null)
225
	{
226
		$this->setError($message = null);
227
	}
228
	// Set the DB error
224
    public function set_error($message = null)
225
    {
226
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
227
        $this->setError($message = null);
228
    }
229
    // Set the DB error
229 230
/**
230 231
 * setError
231 232
 * @param string $message
232 233
 */
233
	public function setError($message = null)
234
	{
235
		$this->error = $message;
236
	}
234
    public function setError($message = null)
235
    {
236
        $this->error = $message;
237
    }
237 238
/**
238 239
 * Alias for isError
239
 * @deprecated from WB-2.8.5 and higher
240
 * @deprecated from WB-2.8.4 and higher
240 241
 */
241
	public function is_error()
242
	{
243
		return $this->isError();
244
	}
242
    public function is_error()
243
    {
244
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
245
        return $this->isError();
246
    }
245 247
/**
246 248
 * isError
247 249
 * @return bool
248 250
 */
249
	public function isError()
250
	{
251
		return (!empty($this->error)) ? true : false;
252
	}
251
    public function isError()
252
    {
253
        return (!empty($this->error)) ? true : false;
254
    }
253 255
/**
254 256
 * Alias for getError
255
 * @deprecated from WB-2.8.5 and higher
257
 * @deprecated from WB-2.8.4 and higher
256 258
 */
257
	public function get_error()
258
	{
259
		return $this->getError();
260
	}
259
    public function get_error()
260
    {
261
        trigger_error('Deprecated function call: '.__CLASS__.'::'.__METHOD__, E_USER_DEPRECATED);
262
        return $this->getError();
263
    }
261 264
/**
262 265
 * get last Error
263 266
 * @return string
264 267
 */
265
	public function getError()
266
	{
267
		return $this->error;
268
	}
268
    public function getError()
269
    {
270
        return $this->error;
271
    }
269 272
/**
270 273
 * Protect class from property injections
271 274
 * @param string name of property
272 275
 * @param mixed value
273 276
 * @throws WbDatabaseException
274
 */	
275
	public function __set($name, $value)
276
	{
277
		throw new WbDatabaseException('tried to set a readonly or nonexisting property ['.$name.']!! ');
278
	}
277
 */
278
    public function __set($name, $value)
279
    {
280
        throw new WbDatabaseException('tried to set a readonly or nonexisting property ['.$name.']!! ');
281
    }
279 282
/**
280 283
 * default Getter for some properties
281 284
 * @param string name of the Property
282 285
 * @return NULL on error | valid property
283 286
 */
284
	public function __get($sPropertyName)
285
	{
286
		switch ($sPropertyName) {
287
			case 'DbHandle':
288
			case 'getDbHandle': // << set deprecated
289
			case 'db_handle': // << set deprecated
290
				$retval = $this->oDbHandle;
291
				break;
292
			case 'LastInsertId':
293
			case 'getLastInsertId': // << set deprecated
294
				$retval = $this->getLastInsertId();
295
				break;
296
			case 'DbName':
297
			case 'getDbName': // << set deprecated
298
			case 'db_name': // << set deprecated
299
				$retval = $this->sDbName;
300
				break;
301
			case 'TablePrefix':
302
			case 'getTablePrefix': // << set deprecated
303
				$retval = $this->sTablePrefix;			
304
				break;
305
			case 'QueryCount':
306
			case 'getQueryCount': // << set deprecated
307
				$retval = $this->iQueryCount;
308
				break;
309
			default:
310
				$retval = null;
311
				break;
312
		}
313
		return $retval;
314
	} // __get()
287
    public function __get($sPropertyName)
288
    {
289
        switch ($sPropertyName) {
290
            case 'getDbHandle': // << set deprecated
291
            case 'db_handle': // << set deprecated
292
                trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getDbHandle|db_handle)', E_USER_DEPRECATED);
293
            case 'DbHandle':
294
                $retval = $this->oDbHandle;
295
                break;
296
            case 'getLastInsertId': // << set deprecated
297
                trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getLastInsertId)', E_USER_DEPRECATED);
298
            case 'LastInsertId':
299
                $retval = $this->getLastInsertId();
300
                break;
301
            case 'getDbName': // << set deprecated
302
            case 'db_name': // << set deprecated
303
                trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getDbName|db_name)', E_USER_DEPRECATED);
304
            case 'DbName':
305
                $retval = $this->sDbName;
306
                break;
307
            case 'getTablePrefix': // << set deprecated
308
                trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getTablePrefix)', E_USER_DEPRECATED);
309
            case 'TablePrefix':
310
                $retval = $this->sTablePrefix;
311
                break;
312
            case 'getQueryCount': // << set deprecated
313
                trigger_error('Deprecated property call: '.__CLASS__.'::'.__METHOD__.'(getQueryCount)', E_USER_DEPRECATED);
314
            case 'QueryCount':
315
                $retval = $this->iQueryCount;
316
                break;
317
            default:
318
                $retval = null;
319
                break;
320
        }
321
        return $retval;
322
    } // __get()
315 323
/**
316 324
 * Escapes special characters in a string for use in an SQL statement
317 325
 * @param string $unescaped_string
318 326
 * @return string
319 327
 */
320
	public function escapeString($unescaped_string)
321
	{
322
		return mysqli_real_escape_string($this->oDbHandle, $unescaped_string);
323
	}
328
    public function escapeString($sUnescapedString)
329
    {
330
        return mysqli_real_escape_string($this->oDbHandle, $sUnescapedString);
331
    }
324 332
/**
333
 * Escapes wildchar characters in a string for use in an SQL-LIKE statement
334
 * @param string $unescaped_string
335
 * @return string
336
 */
337
    public function escapeLike($sUnescapedString)
338
    {
339
        return addcslashes($sUnescapedString, '_%');
340
    }
341
/**
325 342
 * Last inserted Id
326 343
 * @return bool|int false on error, 0 if no record inserted
327
 */	
328
	public function getLastInsertId()
329
	{
330
		return mysqli_insert_id($this->oDbHandle);
331
	}
344
 */
345
    public function getLastInsertId()
346
    {
347
        return mysqli_insert_id($this->oDbHandle);
348
    }
332 349

  
333 350
} /// end of class database
334 351
// //////////////////////////////////////////////////////////////////////////////////// //
......
347 364
 */
348 365
class WbDatabaseException extends AppException {}
349 366

  
350
/* extend global constants of mysql */
351
if(!defined('MYSQL_SEEK_FIRST')) { define('MYSQL_SEEK_FIRST', 0); }
352
if(!defined('MYSQL_SEEK_LAST')) { define('MYSQL_SEEK_LAST', -1); }
353

  
354 367
/**
355 368
 * mysql
356 369
 *
......
367 380
 */
368 381
class mysql {
369 382

  
370
	private $result    = null;
371
	private $oDbHandle = null;
383
    private $result    = null;
384
    private $oDbHandle = null;
372 385
    private $error     = '';
373 386

  
374
    public function __construct($oHandle)
387
    public function __construct($oHandle, $sStatement)
375 388
    {
376 389
        $this->oDbHandle = $oHandle;
390
        $this->query($sStatement);
377 391
    }
378 392
/**
379 393
 * query sql statement
......
381 395
 * @return object
382 396
 * @throws WbDatabaseException
383 397
 */
384
	public function query($sStatement)
385
	{
386
		$this->result = @mysqli_query($this->oDbHandle, $sStatement);
387
		if ($this->result === false) {
388
			if (DEBUG) {
389
				throw new WbDatabaseException(mysqli_error($this->oDbHandle));
390
			} else {
391
				throw new WbDatabaseException('Error in SQL-Statement');
392
			}
393
		}
394
		$this->error = mysqli_error($this->oDbHandle);
395
		return $this->result;
396
	}
398
    public function query($sStatement)
399
    {
400
        $this->result = @mysqli_query($this->oDbHandle, $sStatement);
401
        if ($this->result === false) {
402
            if (DEBUG) {
403
                throw new WbDatabaseException(mysqli_error($this->oDbHandle));
404
            } else {
405
                throw new WbDatabaseException('Error in SQL-Statement');
406
            }
407
        }
408
        $this->error = mysqli_error($this->oDbHandle);
409
        return $this->result;
410
    }
397 411
/**
398 412
 * numRows
399 413
 * @return integer
400 414
 * @description number of returned records
401 415
 */
402
	public function numRows()
403
	{
404
		return mysqli_num_rows($this->result);
405
	}
416
    public function numRows()
417
    {
418
        return mysqli_num_rows($this->result);
419
    }
406 420
/**
407 421
 * fetchRow
408
 * @param  int $typ MYSQL_BOTH(default) | MYSQL_ASSOC | MYSQL_NUM
409
 * @return array
422
 * @param  int $typ MYSQL_BOTH(default) | MYSQL_ASSOC | MYSQL_NUM // DEPRECATED
423
 * @return array with numeric indexes
410 424
 * @description get current record and increment pointer
411 425
 */
412
	public function fetchRow($typ = MYSQLI_BOTH)
413
	{
414
		return mysqli_fetch_array($this->result, $typ);
415
	}
426
    public function fetchRow($typ = MYSQLI_BOTH)
427
    {
428
        if ($typ != MYSQLI_NUM) {
429
            trigger_error('Deprecated call: '.__CLASS__.'::'.__METHOD__.' for MYSQLI_ASSOC|MYSQL_BOTH', E_USER_DEPRECATED);
430
            return mysqli_fetch_array($this->result, $typ);
431
        } else {
432
            return mysqli_fetch_row($this->result);
433
        }
434
    }
416 435
/**
436
 * fetchAssoc
437
 * @return array with assotiative indexes
438
 * @description get current record and increment pointer
439
 */
440
    public function fetchAssoc()
441
    {
442
        if ($typ != MYSQLI_NUM) {
443
            trigger_error('Deprecated call: '.__CLASS__.'::'.__METHOD__.' for MYSQLI_ASSOC|MYSQL_BOTH', E_USER_DEPRECATED);
444
            return mysqli_fetch_array($this->result, $typ);
445
        } else {
446
            return mysqli_fetch_row($this->result);
447
        }
448
    }
449
/**
417 450
 * fetchObject
418 451
 * @param  string $sClassname Name of the class to use. Is no given use stdClass
419 452
 * @param  string $aParams    optional array of arguments for the constructor
420 453
 * @return object
421 454
 * @description get current record as an object and increment pointer
422 455
 */
423
	public function fetchObject($sClassName = null, array $aParams = null)
424
	{
425
		if ($sClassName === null || class_exists($sClassName)) {
426
			return mysqli_fetch_object($this->result, $sClassName, $aParams);
427
		} else {
428
			throw new WbDatabaseException('Class <'.$sClassName.'> not available on request of mysql_fetch_object()');
429
		}
430
	}
456
    public function fetchObject($sClassName = null, array $aParams = null)
457
    {
458
        if ($sClassName === null || class_exists($sClassName)) {
459
            return mysqli_fetch_object($this->result, $sClassName, $aParams);
460
        } else {
461
            throw new WbDatabaseException('Class <'.$sClassName.'> not available on request of mysqli_fetch_object()');
462
        }
463
    }
431 464
/**
432 465
 * fetchArray
433 466
 * @param  int $iType MYSQL_ASSOC(default) | MYSQL_BOTH | MYSQL_NUM
434 467
 * @return array of current record
435 468
 * @description get current record and increment pointer
436 469
 */
437
	public function fetchArray($iType = MYSQLI_ASSOC)
438
	{
470
    public function fetchArray($iType = MYSQLI_ASSOC)
471
    {
439 472
        if ($iType < MYSQLI_ASSOC || $iType > MYSQLI_BOTH) {
440 473
            $iType = MYSQLI_ASSOC;
441 474
        }
442
		return mysqli_fetch_array($this->result, $iType);
443
	}
475
        return mysqli_fetch_array($this->result, $iType);
476
    }
444 477
/**
445 478
 * fetchAll
446 479
 * @param  int $iType MYSQL_ASSOC(default) | MYSQL_NUM
447 480
 * @return array of rows
448 481
 * @description get all records of the result set
449 482
 */
450
    public function fetchAll($iType = MYSQL_ASSOC)
483
    public function fetchAll($iType = MYSQLI_ASSOC)
451 484
    {
452
        $iType = $iType != MYSQL_NUM ? MYSQL_ASSOC : MYSQL_NUM;
485
        $iType = $iType != MYSQLI_NUM ? MYSQL_ASSOC : MYSQLI_NUM;
453 486
        return mysqli_fetch_all($this->result, $iType);
454 487
    }
455 488
/**
......
457 490
 * @return bool
458 491
 * @description set the recordpointer to the first record || false on error
459 492
 */
460
	public function rewind()
461
	{
462
		return $this->seekRow(MYSQL_SEEK_FIRST);
463
	}
493
    public function rewind()
494
    {
495
        return $this->seekRow(MYSQLI_SEEK_FIRST);
496
    }
464 497
/**
465 498
 * seekRow
466
 * @param int $position
499
 * @param int $position also can be MYSQLI_SEEK_FIRST||MYSQLI_SEEK_LAST
467 500
 * @return bool
468 501
 * @description set the pointer to the given record || false on error
469 502
 */
470
	public function seekRow( $position = MYSQL_SEEK_FIRST )
471
	{
472
		$pmax = $this->numRows() - 1;
473
		$p = (($position < 0 || $position > $pmax) ? $pmax : $position);
474
		return mysqli_data_seek($this->result, $p);
475
	}
503
    public function seekRow( $position = MYSQLI_SEEK_FIRST )
504
    {
505
        $pmax = $this->numRows() - 1;
506
        $p = (($position < 0 || $position > $pmax) ? $pmax : $position);
507
        return mysqli_data_seek($this->result, $p);
508
    }
476 509
/**
477 510
 * freeResult
478 511
 * @return bool
479 512
 * @description remove retult object from memeory
480 513
 */
481
	public function freeResult()
482
	{
483
		return mysqli_free_result($this->result);
484
	}
485
/** 
514
    public function freeResult()
515
    {
516
        return mysqli_free_result($this->result);
517
    }
518
/**
486 519
 * Get error
487 520
 * @return string || null if no error
488 521
 */
489
	public function error()
490
	{
491
		if (isset($this->error)) {
492
			return $this->error;
493
		} else {
494
			return null;
495
		}
496
	}
522
    public function error()
523
    {
524
        if (isset($this->error)) {
525
            return $this->error;
526
        } else {
527
            return null;
528
        }
529
    }
497 530

  
498 531
}
499
// //////////////////////////////////////////////////////////////////////////////////// //
500
/* this function is placed inside this file temporarely until a better place is found */
501
/*  function to update a var/value-pair(s) in table ****************************
502
 *  nonexisting keys are inserted
503
 *  @param string $table: name of table to use (without prefix)
504
 *  @param mixed $key:    a array of key->value pairs to update
505
 *                        or a string with name of the key to update
506
 *  @param string $value: a sting with needed value, if $key is a string too
507
 *  @return bool:  true if any keys are updated, otherwise false
508
 */
509
	function db_update_key_value($table, $key, $value = '')
510
	{
511
		$oDb = WbDatabase::getInstance();
512
        $table = preg_replace('/^'.preg_quote($oDb->TablePrefix, '/').'/s', '', $table);
513
		if (!is_array($key)) {
514
			if (trim($key) != '') {
515
				$key = array( trim($key) => trim($value) );
516
			} else {
517
				$key = array();
518
			}
519
		}
520
		$retval = true;
521
        $sNameValPairs = '';
522
		foreach ($key as $index => $val) {
523
            $sNameValPairs .= ', (\''.$index.'\', \''.$val.'\')';
524
        }
525
        $sValues = ltrim($sNameValPairs, ', ');
526
        if ($sValues != '') {
527
            $sql = 'REPLACE INTO `'.$oDb->TablePrefix.$table.'` (`name`, `value`) '
528
                 . 'VALUES '.$sValues;
529
			if (!$oDb->doQuery($sql)) {
530
				$retval = false;
531
			}
532
        }
533
		return $retval;
534
	}

Also available in: Unified diff