/** * Edits a user by replacing his data and preferences by the new array * * @param array $usr_id usr_id of the user to be edited * @param array $data username, email, and other new data of the user * @global array $kga kimai-global-array * @return boolean true on success, false on failure * @author ob/th */ function usr_edit($usr_id, $data) { global $kga, $conn; $data = clean_data($data); $strings = array('usr_name', 'usr_mail', 'usr_alias', 'pw'); foreach ($strings as $key) { if (isset($data[$key])) { $values[$key] = MySQL::SQLValue($data[$key]); } } $numbers = array('usr_grp', 'usr_sts', 'usr_trash', 'usr_active', 'lastProject', 'lastEvent', 'lastRecord'); foreach ($numbers as $key) { if (isset($data[$key])) { $values[$key] = MySQL::SQLValue($data[$key], MySQL::SQLVALUE_NUMBER); } } $filter['usr_ID'] = MySQL::SQLValue($usr_id, MySQL::SQLVALUE_NUMBER); $table = $kga['server_prefix'] . "usr"; if (!$conn->TransactionBegin()) { $conn->Kill(); } $query = MySQL::BuildSQLUpdate($table, $values, $filter); if ($conn->Query($query)) { if (isset($data['usr_rate'])) { if (is_numeric($data['usr_rate'])) { save_rate($usr_id, NULL, NULL, $data['usr_rate']); } else { remove_rate($usr_id, NULL, NULL); } } if (!$conn->TransactionEnd()) { $conn->Kill(); } return true; } else { if (!$conn->TransactionRollback()) { $conn->Kill(); } return false; } }
$preferences['rowlimit'] = $_REQUEST['rowlimit']; $preferences['lang'] = $_REQUEST['lang']; $preferences['flip_pct_display'] = isset($_REQUEST['flip_pct_display']) ? 1 : 0; $preferences['pct_comment_flag'] = isset($_REQUEST['pct_comment_flag']) ? 1 : 0; $preferences['showIDs'] = isset($_REQUEST['showIDs']) ? 1 : 0; $preferences['noFading'] = isset($_REQUEST['noFading']) ? 1 : 0; $preferences['user_list_hidden'] = isset($_REQUEST['user_list_hidden']) ? 1 : 0; $preferences['hideClearedEntries'] = isset($_REQUEST['hideClearedEntries']) ? 1 : 0; $preferences['sublistAnnotations'] = $_REQUEST['sublistAnnotations']; usr_set_preferences($preferences, 'ui.'); usr_set_preferences(array('timezone' => $_REQUEST['timezone'])); $rate = str_replace($kga['conf']['decimalSeparator'], '.', $_REQUEST['rate']); if (is_numeric($rate)) { save_rate($kga['usr']['usr_ID'], null, NULL, $rate); } else { remove_rate($kga['usr']['usr_ID'], null, NULL); } // If the password field is empty don't overwrite the old password. if ($_REQUEST['pw'] != "") { $usr_data['pw'] = md5($kga['password_salt'] . $_REQUEST['pw'] . $kga['password_salt']); usr_edit($kga['usr']['usr_ID'], $usr_data); } break; /** * When the user changes the timespace it is stored in the database so * it can be restored, when the user reloads the page. */ /** * When the user changes the timespace it is stored in the database so * it can be restored, when the user reloads the page. */
/** * Edits a user by replacing his data and preferences by the new array * * @param array $usr_id usr_id of the user to be edited * @param array $data username, email, and other new data of the user * @global array $kga kimai-global-array * @return boolean true on success, false on failure * @author ob */ function usr_edit($usr_id, $data) { global $kga, $pdo_conn; $p = $kga['server_prefix']; $data = clean_data($data); $pdo_conn->beginTransaction(); $keys = array('usr_name', 'usr_grp', 'usr_sts', 'usr_trash', 'usr_active', 'usr_mail', 'usr_alias', 'pw', 'lastRecord', 'lastProject', 'lastEvent'); $query = 'UPDATE ' . $kga['server_prefix'] . 'usr SET '; $query .= buildSQLUpdateSet($keys, $data); $query .= ' WHERE usr_id = :userId;'; $statement = $pdo_conn->prepare($query); bindValues($statement, $keys, $data); $statement->bindValue(":userId", $usr_id); if (!$statement->execute()) { return false; } if (isset($data['usr_rate'])) { if (is_numeric($data['usr_rate'])) { save_rate($usr_id, NULL, NULL, $data['usr_rate']); } else { remove_rate($usr_id, NULL, NULL); } } if ($pdo_conn->commit() == true) { return true; } else { return false; } }