mahara_iena_link.php 3.09 KB
Newer Older
Thomas Fradet's avatar
Thomas Fradet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?php

require_once('../../config.php');
require_once ('entity/block_mahara_iena_connexion.php');

global $COURSE, $USER, $CFG;

$courseid = required_param('courseid', PARAM_INT);
$url = new moodle_url('/blocks/mahara_iena/mahara_iena_link.php',array('courseid' => $courseid));

$PAGE->set_pagelayout('course');
$PAGE->set_url($url);

require_login($courseid, false, NULL);

$content = "";

if ( $_GET['connect_mahara'] == true ) {
	// connect the user to mahara to create his account with moodle/mahara existing link
	$mnetauth = get_auth_plugin('mnet');
	$target_url = "/";
	$url = $mnetauth->start_jump_session($CFG->iena_mahara, $target_url);
	if (empty($url)) {
		$content .= '<div class="alert alert-danger">La connexion a échouée.</div>';
	} else {
		redirect($url);
	}
} else {
	// check the group and proceed to mahara group creation and enroll if necessary
	$connexion = new block_mahara_iena_connexion($CFG->wstoken,$CFG->base_mahara);

	//ensure user is member of it's mahara group : true if already or succeed
	// $all_right = $connexion->ensure_user_is_mahara_group_member($USER, $_GET['mahara_group']);
Thomas Fradet's avatar
Thomas Fradet committed
34 35 36 37 38
	if ( $_GET['connect_direct'] == true ) {
		$all_right = true;
	} else {
		$all_right = $connexion->ensure_user_is_mahara_group_member_new($USER, $_GET['mahara_group'], $_GET['moodle_group']);
	}
Thomas Fradet's avatar
Thomas Fradet committed
39

Thomas Fradet's avatar
Thomas Fradet committed
40
	if ( $all_right === false  ) {
Thomas Fradet's avatar
Thomas Fradet committed
41 42 43 44
		$content .= '<div class="alert alert-danger">Erreur d\'ajout au groupe sur <a href="'.$CFG->base_mahara.'" target="_blank">'.$CFG->base_mahara.'</a>. </div>';
	} else {	
		/* connect to mahara and redirect to the mahara group */
		$mnetauth = get_auth_plugin('mnet');
Thomas Fradet's avatar
Thomas Fradet committed
45 46 47 48 49 50 51 52 53
		$ma_group = $_GET['mahara_group'];
		if ( $ma_group == "" || $ma_group == NULL ) {
			if ( gettype($all_right) == "integer" ) {
				$ma_group = $all_right;
			} else {
				$content .= '<div class="alert alert-warning">La redirection vers le groupe a échouée, veuillez réessayer. </div>';
			}
		}
		$group_url = "/group/view.php?id=".$ma_group;
Thomas Fradet's avatar
Thomas Fradet committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		$url      = $mnetauth->start_jump_session($CFG->iena_mahara, $group_url);
		if (empty($url)) {
			$content .= '<div class="alert alert-danger">La connexion a échouée.</div>';
		} else {
			redirect($url);
		}
	}

}

// if ($_GET['mahara_group']){

// } elseif ($_GET['connect_mahara']) {

// } else {
// 	// if no mahara group specified in get url, display error
// 	$content .= '<div class="alert alert-warning">Erreur : paramètre manquant. Utilisez le bloc '
// 	.get_string('title_plugin', 'block_mahara_iena', $CFG->mahara_alias)
// 	.' pour accéder aux groupes '
// 	.$CFG->mahara_alias.'.</div>';
// }

$PAGE->set_title(get_string('title_plugin', 'block_mahara_iena', $CFG->mahara_alias));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
echo $OUTPUT->header();
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";

$content .= "<a href=\"".$CFG->wwwroot."/course/view.php?id=".$COURSE->id." \" class=\"btn btn-primary\" role=\"button\">".get_string('back_course', 'block_mahara_iena')."</a>";

echo $content;

echo $OUTPUT->footer();