SF.net SVN: postfixadmin:[931] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2010-12-31 20:13:59
|
Revision: 931 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=931&view=rev Author: christian_boltz Date: 2010-12-31 20:13:53 +0000 (Fri, 31 Dec 2010) Log Message: ----------- changed db_update parameters for the most common usecase "WHERE col=value" - column and value are separate parameters now functions.inc.php: - changed function db_update() parameters - column name and value for the WHERE condition are now two separate parameters. This means we don't need to escape_string(), add quotes etc. for most UPDATE queries. Example call: db_update('alias', 'address', $this->username, $values_array) - the previous db_update() is now called db_update_q() model/UserHandler.php: - changed db_update call to the new parameters - removed now unused variables - renamed $username to $E_username - call pacrypt directly when setting the $set array, no need for $new_db_password model/AliasHandler.php - changed db_update call to the new parameters edit-mailbox.php - switched to db_update_q() Modified Paths: -------------- trunk/edit-mailbox.php trunk/functions.inc.php trunk/model/AliasHandler.php trunk/model/UserHandler.php Modified: trunk/edit-mailbox.php =================================================================== --- trunk/edit-mailbox.php 2010-12-31 19:23:31 UTC (rev 930) +++ trunk/edit-mailbox.php 2010-12-31 20:13:53 UTC (rev 931) @@ -154,7 +154,7 @@ if(preg_match('/^(.*)@/', $fUsername, $matches)) { $formvars['local_part'] = $matches[1]; } - $result = db_update('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified')); + $result = db_update_q('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified')); # TODO: check if we need the AND domain=... clause, if not, switch to db_update() $maildir = $user_details['maildir']; if ($result != 1 || !mailbox_postedit($fUsername,$fDomain,$maildir, $quota)) { $tMessage = $PALANG['pEdit_mailbox_result_error']; Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2010-12-31 19:23:31 UTC (rev 930) +++ trunk/functions.inc.php 2010-12-31 20:13:53 UTC (rev 931) @@ -1728,15 +1728,30 @@ /** * db_update * Action: Updates a specified table - * Call: db_update (string table, string where, array values [, array timestamp]) + * Call: db_update (string table, string where_col, string where_value, array values [, array timestamp]) * @param String - table name - * @param String - WHERE condition + * @param String - column of WHERE condition + * @param String - value of WHERE condition * @param array - key/value map of data to insert into the table. * @param array (optional) - array of fields to set to now() - default: array('modified') * @return int - number of updated rows */ -function db_update ($table, $where, $values, $timestamp = array('modified') ) -{ +function db_update ($table, $where_col, $where_value, $values, $timestamp = array('modified') ) { + $where = $where_col . " = '" . escape_string($where_value) . "'"; + return db_update_q ($table, $where, $values, $timestamp = array('modified') ); +} + +/** + * db_update_q + * Action: Updates a specified table + * Call: db_update_q (string table, string where, array values [, array timestamp]) + * @param String - table name + * @param String - WHERE condition (as SQL) + * @param array - key/value map of data to insert into the table. + * @param array (optional) - array of fields to set to now() - default: array('modified') + * @return int - number of updated rows + */ +function db_update_q ($table, $where, $values, $timestamp = array('modified') ) { $table = table_by_key ($table); foreach(array_keys($values) as $key) { Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2010-12-31 19:23:31 UTC (rev 930) +++ trunk/model/AliasHandler.php 2010-12-31 20:13:53 UTC (rev 931) @@ -167,7 +167,7 @@ $alias_data = array( 'goto' => $goto, ); - $result = db_update('alias', "address = '$E_username'", $alias_data); + $result = db_update('alias', 'address', $this->username, $alias_data); } if($result != 1) { return false; Modified: trunk/model/UserHandler.php =================================================================== --- trunk/model/UserHandler.php 2010-12-31 19:23:31 UTC (rev 930) +++ trunk/model/UserHandler.php 2010-12-31 20:13:53 UTC (rev 931) @@ -28,17 +28,14 @@ * as per the configuration in config.inc.php */ public function change_pw($new_password, $old_password, $match = true) { - $username = $this->username; list(/*NULL*/,$domain) = explode('@', $username); - $username = escape_string($username); + $E_username = escape_string($this->username); $table_mailbox = table_by_key('mailbox'); - $new_db_password = pacrypt($new_password); - if ($match == true) { $active = db_get_boolean(True); - $result = db_query("SELECT password FROM $table_mailbox WHERE username='$username' AND active='$active'"); + $result = db_query("SELECT password FROM $table_mailbox WHERE username='$E_username' AND active='$active'"); $result = db_assoc($result['result']); if (pacrypt($old_password, $result['password']) != $result['password']) { @@ -49,10 +46,10 @@ } $set = array( - 'password' => $new_db_password + 'password' => pacrypt($new_password) , ); - $result = db_update('mailbox', 'username=\''.$username.'\'', $set ); + $result = db_update('mailbox', 'username', $this->username, $set ); if ($result != 1) { db_log ('CONSOLE', $domain, 'edit_password', "FAILURE: " . $this->username); # TODO: replace hardcoded CONSOLE - class is used by XMLRPC and users/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |