$read), array('id_mensaje' => $message_id)); } /** * Gets a private message * * This function abstracts the database backend so it can simply be replaced with another system * * @param int $message_id * * @return mixed False if it doesn't exist or a filled array otherwise */ function get_message ($message_id) { global $config; $sql = sprintf("SELECT id_usuario_origen, subject, mensaje, timestamp FROM tmensajes WHERE id_usuario_destino='%s' AND id_mensaje=%d" , $config["id_user"], $message_id); $row = get_db_row_sql ($sql); if (empty ($row)) { return false; } $return["sender"] = $row["id_usuario_origen"]; $return["subject"] = $row["subject"]; $return["message"] = $row["mensaje"]; $return["timestamp"] = $row["timestamp"]; return $return; } /** * Counts private messages * * @param string $user * @param bool $incl_read Whether or not to include read messages * * @return int The number of messages this user has */ function get_message_count ($user = false, $incl_read = false) { if (empty ($user)) { global $config; $user = $config["id_user"]; } if (empty ($incl_read)) { $filter = "AND estado = 0"; } else { $filter = ""; } $sql = sprintf("SELECT COUNT(*) FROM tmensajes WHERE id_usuario_destino='%s' %s", $user, $filter); return (int) get_db_sql ($sql); } /** * Get message overview in array * * @param string $order How to order them valid: * (status (default), subject, timestamp, sender) * @param string $order_dir Direction of order (ASC = Ascending, DESC = Descending) * * @return int The number of messages this user has */ function get_message_overview ($order = "status", $order_dir = "ASC") { global $config; switch ($order) { case "timestamp": case "sender": case "subject": break; case "status": default: $order = "estado"; } if ($order_dir != "ASC") { $order .= " DESC"; } $result = array (); $return = get_db_all_rows_field_filter ('tmensajes', 'id_usuario_destino', $config["id_user"], $order); if ($return === false) { return $result; } foreach ($return as $message) { $result[$message["id_mensaje"]]["sender"] = $message["id_usuario_origen"]; $result[$message["id_mensaje"]]["subject"] = $message["subject"]; $result[$message["id_mensaje"]]["timestamp"] = $message["timestamp"]; $result[$message["id_mensaje"]]["status"] = $message["estado"]; } return $result; } ?>