$PAGE->set_pagelayout('standard');
// Print the page header ---------------------------------------------------------
echo $OUTPUT->header();
// Print the main part of the page -----------------------------------------------
echo $OUTPUT->spacer(array('height' => 20));
echo $OUTPUT->heading('Actualizacion de los agrupamientos');
echo $OUTPUT->spacer(array('height' => 30));
//Recogida de los parametros 'teamname', 'teamid' y 'teammember'
$team_id = array();
$teamname = array();
$memberid = array();
// key idteam
$teams = blended_get_teams_from_form($numteams, $nummembers, $itemid);
/*Llamada a la funci�n que me actualiza el agrupamiento	
	recogiendo en el array 'contador' las veces que se repite cada miembro*/
$outputmessages = blended_actualizar_agrupamiento($teams, $item, $blended);
// Log ---------------------------------------------------------------------------
// Añade una entrada a la tabla de logs (registros). Estas son
// acciones m�s concretas que las noticias del servidor web, y
// proporcionan una forma sencilla de reconstruir qu� ha estado
// haciendo un usuario en particular.
// 	add_to_log ( $course->id, "blended", "update_groupings", "update_groupings.php?a=$blended->id", "$blended->id" );
$info = '';
$url = "update_groupings.php?id={$id}";
if ($CFG->version >= 2014051200) {
    require_once '../classes/event/teams_updated.php';
    \mod_blended\event\teams_updated::create_from_parts($course->id, $USER->id, $blended->id, $itemid, $url, $info)->trigger();
} else {
    add_to_log($course->id, "blended", "updateTeams", $url, "Blended: {$blended->id}, Assignment: {$itemid}");
}
//Form UPDATEGROUPING
    print_error('errornostudents', 'blended');
}
// show headings and menus of page
$url = new moodle_url('/mod/blended/teams/saveteamsgrades.php', array('id' => $id, 'itemid' => $itemid));
//HEADER----
$PAGE->set_url($url);
$PAGE->set_title(format_string($blended->name));
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('standard');
$item = blended_get_item($itemid);
$groupingid = blended_get_groupingid($item);
// Print the page header ---------------------------------------------------------
$teams = blended_get_teams_from_form($item);
$teams = blended_get_grades_from_form($teams);
//Actualizaci�n del agrupamiento
$outputmessages = blended_actualizar_agrupamiento($teams, $item, $blended, $delete_empty);
if (!empty($array_return)) {
    $strinserted = blended_get_error_alert($array_return, "insert");
}
//Para cada equipo:
foreach ($teams as $team) {
    //Si se ha introducido calificaci�n:
    if (!empty($team->grade)) {
        $current_team = blended_get_team($team->id);
        if (!$current_team) {
            continue;
        }
        $rawgrade = $team->grade->grade == -1 ? null : $team->grade->grade;
        $newfinalgrade = !isset($team->grade->grade) || $team->grade->grade == -1 ? null : $item->adjust_raw_grade($team->grade->grade, $item->grademin, $item->grademax);
        //        $outputmessages.="<p>New finalgrade $newfinalgrade for team $current_team->name</p>";
        blended_grade_team($item, $current_team, $newfinalgrade);