[LON-CAPA-cvs] cvs: modules /studip studip.pm
www
www at source.lon-capa.org
Wed Jul 27 16:22:36 EDT 2011
www Wed Jul 27 20:22:36 2011 EDT
Modified files:
/modules/studip studip.pm
Log:
Continued work on Stud.IP connection. Check on user status within LON-CAPA.
Index: modules/studip/studip.pm
diff -u modules/studip/studip.pm:1.3 modules/studip/studip.pm:1.4
--- modules/studip/studip.pm:1.3 Wed Jul 27 08:46:47 2011
+++ modules/studip/studip.pm Wed Jul 27 20:22:36 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Landing point for incoming StudIP requests
#
-# $Id: studip.pm,v 1.3 2011/07/27 08:46:47 www Exp $
+# $Id: studip.pm,v 1.4 2011/07/27 20:22:36 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -79,58 +79,85 @@
$r->print('Course: '.$env{'form.course'}.'<br />');
$r->print('Stud.IP Course: '.$env{'form.studip_course'}.'<br />');
$r->print('Stud.IP Perm: '.$env{'form.studip_perm'}.'<br />');
+#
# Get session info
-
+# The command silently fails if there is no valid session, otherwise it gives back the username
+#
my ($commands,$error, at returned)=&send('get_session_username',$env{'form.sess_id'});
-
+
$r->print('<hr />Talking to: '.$url.'<br />');
$r->print('Error:'.$error.'<br />');
$r->print('Responses: '.join(',', at returned).'<br />');
$r->print('User:'.$returned[1].'<br />');
+# Data about the user
my $user=$returned[1];
+ my $domain=$env{'form.domain'};
my $adv=($env{'form.studip_perm'} eq 'dozent');
-# Is the user in the class?
+# Data about the LON-CAPA course
+ my ($cdom,$cnum)=split(/\//,$env{'form.course'});
+#
+# Now see if everything is correct, as we cannot trust any of the data that is passed in the query string
+#
if ($user) {
$r->print("Found user!<br />");
- my ($commands,$error, at returned)=&send('get_participants',$env{'form.studip_course'});
- $r->print('Error:'.$error.'<br />');
- $r->print('Responses: '.join(',', at returned).'<br />');
- my $found=0;
- for (my $i=1;$i<=$#returned;$i+=2) {
- if ($returned[$i] eq $user) {
- $found=1;
- last;
- }
- }
- if ($found) {
- $r->print("Found user in course.<br />");
+# Does the LON-CAPA course exist?
+ my $chome=&Apache::lonnet::homeserver($cnum,$cdom);
+ if ($chome ne 'no_host') {
+# Is the user in the Stud.IP class?
+ my ($commands,$error, at returned)=&send('get_participants',$env{'form.studip_course'});
+ $r->print('Error:'.$error.'<br />');
+ $r->print('Responses: '.join(',', at returned).'<br />');
+ my $found=0;
+ for (my $i=1;$i<=$#returned;$i+=2) {
+ if ($returned[$i] eq $user) {
+ $found=1;
+ last;
+ }
+ }
+ if ($found) {
+ $r->print("Found user in course.<br />");
# Check for advanced privileges
- if ($adv) {
- my ($commands,$error, at returned1)=&send('get_admins_for_seminar',$env{'form.studip_course'});
- my ($commands,$error, at returned2)=&send('get_lecturers_for_seminar',$env{'form.studip_course'});
- my @returned=(@returned1, at returned2);
- $r->print('Responses: '.join(',', at returned).'<br />');
- my $found=0;
- for (my $i=1;$i<=$#returned;$i+=2) {
- if ($returned[$i] eq $user) {
- $found=1;
- last;
+ if ($adv) {
+ my ($commands,$error, at returned1)=&send('get_admins_for_seminar',$env{'form.studip_course'});
+ my ($commands,$error, at returned2)=&send('get_lecturers_for_seminar',$env{'form.studip_course'});
+ my @returned=(@returned1, at returned2);
+ $r->print('Responses: '.join(',', at returned).'<br />');
+ my $found=0;
+ for (my $i=1;$i<=$#returned;$i+=2) {
+ if ($returned[$i] eq $user) {
+ $found=1;
+ last;
+ }
+ }
+ if ($found) {
+ $r->print("User is administrator/lecturer.<br />");
+ } else {
+ $r->print("User is not really administrator/lecturer.<br />");
+# Fall back to student mode
+ $adv=0;
}
}
- if ($found) {
- $r->print("User is administrator/lecturer.<br />");
+# Okay, now check the LON-CAPA end of things. Does the user already exist?
+ my $uhome=&Apache::lonnet::homeserver($user,$domain);
+ if ($uhome ne 'no_host') {
+ $r->print("User exists.<br />");
+# Does the user have roles in this course?
+ my %roles=&Apache::lonnet::get_my_roles($user,$domain,'userroles');
+ foreach my $key (keys %roles) {
+ $r->print($key.':'.$roles{$key}.'<br />');
+ }
} else {
- $r->print("User is not really administrator/lecturer.<br />");
- $adv=0;
+ $r->print("User does not yet exist.<br />");
+# User does not exist, make it and enroll in course
}
-#
-# User is in the class and session should be entered. If $adv is true, the user can enter an advanced role in the course
-#
+ } else {
+ $r->print("<h1>".&mt("Sorry ...")."</h1>");
+ $r->print("<p>".&mt("You are not currently enrolled in the Stud.IP course that corresponds to your LON-CAPA course")."</p>");
}
} else {
$r->print("<h1>".&mt("Sorry ...")."</h1>");
- $r->print("<p>".&mt("You are not currently enrolled in the Stud.IP course that corresponds to your LON-CAPA course")."</p>");
- }
+ $r->print("<p>".&mt("There is no corresponding LON-CAPA course.")."</p>");
+ }
} else {
$r->print("<h1>".&mt("Sorry ...")."</h1>");
$r->print("<p>".&mt("This is not a valid session. You might have to reload the 'Learning modules' page in Stud.IP and press 'Start' again.")."</p>");
More information about the LON-CAPA-cvs
mailing list