array (userinfo) * We can't simplify this because some auth schemes (like LDAP) automatically (or it's at least cheaper to) return all the information * Functions like get_user_info allow selection of specifics (in functions_db) * * @param string Field to order by (id_user, fullname or registered) * * @return array An array of user information */ function get_users ($order = "fullname") { switch ($order) { case "id_user": case "registered": case "last_connect": case "fullname": break; default: $order = "fullname"; } $output = array(); $result = get_db_all_rows_in_table ("tusuario", $order); if ($result !== false) { foreach ($result as $row) { $output[$row["id_user"]] = $row; } } return $output; } /** * Sets the last login for a user * * @param string User id */ function process_user_contact ($id_user) { return process_sql_update ("tusuario", array ("last_connect" => get_system_time ()), array ("id_user" => $id_user)); } /** * Create a new user * * @return bool false */ function create_user ($id_user, $password, $user_info) { $values = array (); $values["id_user"] = $id_user; $values["password"] = md5 ($password); $values["last_connect"] = 0; $values["registered"] = get_system_time (); foreach ($user_info as $key => $value) { switch ($key) { case "fullname": case "firstname": case "lastname": case "middlename": case "comments": case "email": case "phone": $values[$key] = $value; break; default: continue; //ignore } } return process_sql_insert ("tusuario", $values); } /** * Deletes the user * * @param string User id */ function delete_user ($id_user) { $sql = "DELETE FROM tusuario_perfil WHERE id_usuario = '".$id_user."'"; $result = process_sql ($sql); if ($result === false) { return false; } $sql = "DELETE FROM tusuario WHERE id_user = '".$id_user."'"; $result = process_sql ($sql); if ($result === false) { return false; } return true; } function process_user_password ( $user, $password_old, $password_new ) { $user = process_user_login ($user, $password_old); if ($user === false) { global $mysql_cache; $mysql_cache["auth_error"] = "Invalid login/password combination"; return false; } return process_sql_update ("tusuario", array ("password" => md5 ($password_new)), array ("id_user" => $user)); } function process_user_info ($id_user, $user_info) { $values = array (); foreach ($user_info as $key => $value) { switch ($key) { case "fullname": case "firstname": case "lastname": case "middlename": case "comments": case "email": case "phone": $values[$key] = $value; break; default: continue; //ignore break; } } return process_sql_update ("tusuario", $values, array ("id_user" => $id_user)); } /** * Sets the user admin status (LDAP doesn't do this) * * @param string User id */ function process_user_isadmin ($id_user, $is_admin) { if ($is_admin == true) { $is_admin = 1; } else { $is_admin = 0; } return process_sql_update ("tusuario", array ("is_admin" => $is_admin), array ("id_user" => $id_user)); } //Reference the global use authorization error to last auth error. $config["auth_error"] = &$mysql_cache["auth_error"]; ?>