[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonpickcourse.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 23 Nov 2004 18:03:04 -0000
This is a MIME encoded message
--raeburn1101232984
Content-Type: text/plain
raeburn Tue Nov 23 13:03:04 2004 EDT
Modified files:
/loncom/interface loncreateuser.pm lonpickcourse.pm
Log:
DC can now add user roles to courses without needing an role in the target course. Choice of sections can be made from existing sections, or new sections can be added. Still need to add contextual help, and javascript to alert/prohibit > 1 section for a student role.
--raeburn1101232984
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20041123130304.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.87 loncom/interface/loncreateuser.pm:1.88
--- loncom/interface/loncreateuser.pm:1.87 Thu Sep 23 18:51:24 2004
+++ loncom/interface/loncreateuser.pm Tue Nov 23 13:03:04 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.87 2004/09/23 22:51:24 albertel Exp $
+# $Id: loncreateuser.pm,v 1.88 2004/11/23 18:03:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -197,6 +197,79 @@
$ccuname=~s/\W//g;
$ccdomain=~s/\W//g;
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $dc_setcourse_code = '';
+ my $loaditem;
+ if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) {
+ my $dcdom = $1;
+ $loaditem = qq|OnLoad="document.cu.coursedesc.value=''"|;
+ $dc_setcourse_code = <<"ENDSCRIPT";
+ function setCourse() {
+ var course = document.cu.dccourse.value;
+ if (course != "") {
+ if (document.cu.dcdomain.value != document.cu.origdom.value) {
+ alert("You must select a course in the current domain");
+ return;
+ }
+ var userrole = document.cu.role.options[document.cu.role.selectedIndex].value
+ var section;
+ var numsections = 0;
+ if (document.cu.role.value != "cc") {
+ for (var i=0; i<document.cu.currsec.length; i++) {
+ if (document.cu.currsec.options[i].selected == true ) {
+ if (document.cu.currsec.options[i].value != "") {
+ if (numsections == 0) {
+ if (document.cu.currsec.options[i].value != "") {
+ section = document.cu.currsec.options[i].value
+ numsections = 1;
+ }
+ }
+ else {
+ section = section + "," + document.cu.currsec.options[i].value
+ numsections ++;
+ }
+ }
+ }
+ }
+ if (document.cu.newsec.value != "") {
+ if (numsections == 0) {
+ if (document.cu.newsec.value != "") {
+ section = document.cu.newsec.value
+ numsections = 1;
+ }
+ }
+ else {
+ section = section + "," + document.cu.newsec.value
+ numsections ++;
+ }
+ }
+ }
+ var numcourse = getIndex(document.cu.dccourse);
+ if (numcourse == "-1") {
+ alert("There was a problem with your course selection");
+ return
+ }
+ else {
+ var coursename = "_$dcdom"+"_"+course+"_"+userrole
+ document.cu.elements[numcourse].name = "act"+coursename
+ document.cu.elements[numcourse+4].name = "sec"+coursename
+ document.cu.elements[numcourse+4].value = section
+ document.cu.elements[numcourse+5].name = "start"+coursename
+ document.cu.elements[numcourse+6].name = "end"+coursename
+ }
+ }
+ document.cu.submit();
+ }
+
+ function getIndex(caller) {
+ for (var i=0;i<document.cu.elements.length;i++) {
+ if (document.cu.elements[i] == caller) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ENDSCRIPT
+ }
my $dochead =<<"ENDDOCHEAD";
<html>
<head>
@@ -210,6 +283,7 @@
}
$pjump_def
+ $dc_setcourse_code
function dateset() {
eval("document.cu."+document.cu.pres_marker.value+
@@ -221,7 +295,7 @@
</head>
ENDDOCHEAD
$r->print(&Apache::loncommon::bodytag(
- 'Create Users, Change User Privileges'));
+ 'Create Users, Change User Privileges',undef,$loaditem));
my $forminfo =<<"ENDFORMINFO";
<form action="/adm/createuser" method="post" name="cu">
<input type="hidden" name="phase" value="update_user_data">
@@ -682,8 +756,14 @@
#
# Course level
#
- $r->print(&course_level_table(%inccourses));
- $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
+
+ if ($ENV{'request.role'} =~ m-^dc\./(\w+)/$-) {
+ $r->print(&course_level_dc($1));
+ $r->print('<hr /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()">'."\n");
+ } else {
+ $r->print(&course_level_table(%inccourses));
+ $r->print("<hr /><input type=submit value=\"".&mt('Modify User')."\">\n");
+ }
$r->print("</form></body></html>");
}
@@ -989,24 +1069,25 @@
my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
my $url='/'.$one.'/'.$two;
my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
- $ENV{'form.sec_'.$full}=~s/\W//g;
- if ($ENV{'form.sec_'.$full}) {
- $url.='/'.$ENV{'form.sec_'.$full};
- }
- my $start = ( $ENV{'form.start_'.$full} ?
- $ENV{'form.start_'.$full} :
- $now );
- my $end = ( $ENV{'form.end_'.$full} ?
- $ENV{'form.end_'.$full} :
- 0 );
-
- $r->print(&mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', ending '.localtime($end):'').': <b>'.
- &Apache::lonnet::assigncustomrole(
- $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
- '</b><br>');
+ my $start = ( $ENV{'form.start_'.$full} ?
+ $ENV{'form.start_'.$full} :
+ $now );
+ my $end = ( $ENV{'form.end_'.$full} ?
+ $ENV{'form.end_'.$full} :
+ 0 );
+
+ # split multiple sections
+ my %sections = ();
+ my $num_sections = &build_roles($ENV{'form.sec_'.$full},\%sections);
+ if ($num_sections == 0) {
+ $r->print(&commit_customrole($url,$three,$four,$five,$start,$end));
+ } else {
+ foreach (sort {$a cmp $b} keys %sections) {
+ my $securl = $url.'/'.$_;
+ $r->print(&commit_customrole($securl,$three,$four,$five,$start,$end));
+ }
+ }
} elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
@@ -1018,33 +1099,27 @@
$ENV{'form.end_'.$one.'_'.$two.'_'.$three} :
0 );
my $url='/'.$one.'/'.$two;
- $ENV{'form.sec_'.$one.'_'.$two.'_'.$three}=~s/\W//g;
- if ($ENV{'form.sec_'.$one.'_'.$two.'_'.$three}) {
- $url.='/'.$ENV{'form.sec_'.$one.'_'.$two.'_'.$three};
- }
- # Assign the role and report it
- $r->print(&mt('Assigning').' '.$three.' in '.$url.
- ($start?', '.&mt('starting').' '.localtime($start):'').
- ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
- &Apache::lonnet::assignrole(
- $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
- $url,$three,$end,$start).
- '</b><br>');
- # Handle students differently
- if ($three eq 'st') {
- $url=~/^\/(\w+)\/(\w+)/;
- my $cid=$one.'_'.$two;
- $r->print(&mt('Add to classlist').': <b>'.
- &Apache::lonnet::critical(
- 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
- $ENV{'course.'.$cid.'.num'}.':classlist:'.
- &Apache::lonnet::escape(
- $ENV{'form.ccuname'}.':'.
- $ENV{'form.ccdomain'} ).'='.
- &Apache::lonnet::escape($end.':'.$start),
- $ENV{'course.'.$cid.'.home'})
- .'</b><br>');
- }
+ my $type = 'three';
+ # split multiple sections
+ my %sections = ();
+ my $num_sections = &build_roles($ENV{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections);
+ if ($num_sections == 0) {
+ $r->print(&commit_standardrole($url,$three,$start,$end,$one,$two));
+ } else {
+ my $emptysec = 0;
+ foreach my $sec (sort {$a cmp $b} keys %sections) {
+ $sec =~ s/\W//g;
+ if ($sec ne '') {
+ my $securl = $url.'/'.$sec;
+ $r->print(&commit_standardrole($securl,$three,$start,$end,$one,$two));
+ } else {
+ $emptysec = 1;
+ }
+ }
+ if ($emptysec) {
+ $r->print(&commit_standardrole($url,$three,$start,$end,$one,$two));
+ }
+ }
} elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with two id numbers
# set start, end times, and the url for the class
@@ -1055,6 +1130,25 @@
$ENV{'form.end_'.$1.'_'.$2} :
0 );
my $url='/'.$1.'/';
+ # split multiple sections
+ my %sections = ();
+ my $num_sections = &build_roles($ENV{'form.sec_'.$1.'_'.$2},\%sections);
+ if ($num_sections == 0) {
+ $r->print(&commit_standardrole($url,$2,$start,$end,$1));
+ } else {
+ my $emptysec = 0;
+ foreach my $sec (sort {$a cmp $b} keys %sections) {
+ if ($sec ne '') {
+ my $securl = $url.'/'.$sec;
+ $r->print(&commit_standardrole($securl,$2,$start,$end,$1));
+ } else {
+ $emptysec = 1;
+ }
+ }
+ if ($emptysec) {
+ $r->print(&commit_standardrole($url,$2,$start,$end,$1));
+ }
+ }
# Assign the role and report it.
$r->print(&mt('Assigning').' '.$2.' in '.$url.': '.
($start?', '.&mt('starting').' '.localtime($start):'').
@@ -1073,6 +1167,73 @@
$r->print('</body></html>');
}
+sub commit_customrole {
+ my ($url,$three,$four,$five,$end,$start) = @_;
+ my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.'@'.$three.' in '.$url.
+ ($start?', '.&mt('starting').' '.localtime($start):'').
+ ($end?', ending '.localtime($end):'').': <b>'.
+ &Apache::lonnet::assigncustomrole(
+ $ENV{'form.ccdomain'},$ENV{'form.ccuname'},$url,$three,$four,$five,$end,$start).
+ '</b><br>';
+ return $output;
+}
+
+sub commit_standardrole {
+ my ($url,$three,$start,$end,$one,$two) = @_;
+ my $output = (&mt('Assigning').' '.$three.' in '.$url.
+ ($start?', '.&mt('starting').' '.localtime($start):'').
+ ($end?', '.&mt('ending').' '.localtime($end):'').': <b>'.
+ &Apache::lonnet::assignrole(
+ $ENV{'form.ccdomain'},$ENV{'form.ccuname'},
+ $url,$three,$end,$start).
+ '</b><br>');
+
+# Handle students differently
+ if (($three eq 'st') && defined($one) && defined($two)) {
+ $url=~/^\/(\w+)\/(\w+)/;
+ my $cid=$one.'_'.$two;
+ $output .= (&mt('Add to classlist').': <b>'.
+ &Apache::lonnet::critical(
+ 'put:'.$ENV{'course.'.$cid.'.domain'}.':'.
+ $ENV{'course.'.$cid.'.num'}.':classlist:'.
+ &Apache::lonnet::escape(
+ $ENV{'form.ccuname'}.':'.
+ $ENV{'form.ccdomain'} ).'='.
+ &Apache::lonnet::escape($end.':'.$start),
+ $ENV{'course.'.$cid.'.home'})
+ .'</b><br>');
+ }
+ return $output;
+}
+
+
+sub build_roles {
+ my ($sectionstr,$sections) = @_;
+ my $num_sections = 0;
+ if ($sectionstr=~ /,/) {
+ my @secnums = split/,/,$sectionstr;
+ foreach my $sec (@secnums) {
+ $sec =~ ~s/\W//g;
+ unless ($sec eq "") {
+ if (exists($$sections{$sec})) {
+ $$sections{$sec} ++;
+ } else {
+ $$sections{$sec} = 1;
+ $num_sections ++;
+ }
+ }
+ }
+ } else {
+ $sectionstr=~s/\W//g;
+ unless ($sectionstr eq '') {
+ $$sections{$sectionstr} = 1;
+ $num_sections ++;
+ }
+ }
+
+ return $num_sections;
+}
+
# ========================================================== Custom Role Editor
sub custom_role_editor {
@@ -1376,6 +1537,64 @@
ENDTABLE
return $result;
}
+
+sub course_level_dc {
+ my ($dcdom) = @_;
+ my %customroles=&my_custom_roles();
+ my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
+ '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
+ '<input type="hidden" name="dccourse" value="" />';
+ my $courseform='<b>'.&Apache::loncommon::selectcourse_link
+ ('cu','dccourse','dcdomain','coursedesc').'</b>';
+
+ my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,$dcdom);
+ my %lt=&Apache::lonlocal::texthash(
+ 'crl' => "Course Level",
+ 'crt' => "Course Title",
+ 'rol' => "Role",
+ 'grs' => "Group/Section",
+ 'exs' => "Existing sections",
+ 'new' => "Define new section",
+ 'sta' => "Start",
+ 'end' => "End",
+ 'ssd' => "Set Start Date",
+ 'sed' => "Set End Date"
+ );
+ my $header = '<h4>'.$lt{'crl'}.'</h4>'.
+ '<table border="2"><tr><th>'.$courseform.'</th><th>'.$lt{'rol'}.'</th><th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th></tr>';
+ my $otheritems = '<tr><td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'".'cu'."'".','."'".'dccourse'."'".','."'".'dcdomain'."'".','."'".'coursedesc'."'".')" /></td>'.
+ '<td><select name="role">'."\n";
+ foreach ('st','ta','ep','ad','in','cc') {
+ my $plrole=&Apache::lonnet::plaintext($_);
+ $otheritems .= ' <option value="'.$_.'">'.$plrole;
+ }
+ if ( keys %customroles > 0) {
+ foreach (sort keys %customroles) {
+ my $custrole='cr_cr_'.$ENV{'user.domain'}.
+ '_'.$ENV{'user.name'}.'_'.$_;
+ $otheritems .= ' <option value="'.$custrole.'">'.$_;
+ }
+ }
+ $otheritems .= '</select></td><td>'.
+ '<table border="0" cellspacing="0" cellpadding="0">'.
+ '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
+ ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
+ '<td> </td>'.
+ '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
+ '<input type="text" name="newsec" value="" /></td>'.
+ '</tr></table></td>';
+ $otheritems .= <<ENDTIMEENTRY;
+<td><input type=hidden name="start" value=''>
+<a href=
+"javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
+<td><input type=hidden name="end" value=''>
+<a href=
+"javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
+ENDTIMEENTRY
+ $otheritems .= "</tr></table>\n";
+ return $cb_jscript.$header.$hiddenitems.$otheritems;
+}
+
#---------------------------------------------- end functions for &phase_two
#--------------------------------- functions for &phase_two and &phase_three
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.18 loncom/interface/lonpickcourse.pm:1.19
--- loncom/interface/lonpickcourse.pm:1.18 Fri Nov 12 18:29:56 2004
+++ loncom/interface/lonpickcourse.pm Tue Nov 23 13:03:04 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Pick a course
#
-# $Id: lonpickcourse.pm,v 1.18 2004/11/12 23:29:56 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.19 2004/11/23 18:03:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -52,7 +52,8 @@
&Apache::loncommon::get_unprocessed_cgi
($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
'sincefilter','form','cnumelement',
- 'cdomelement','cnameelement','roleelement']);
+ 'cdomelement','cnameelement','roleelement',
+ 'pickedcourse']);
# domain filter and selection
my $domainfilter=$ENV{'form.domainfilter'};
$domainfilter=~s/\W//g;
@@ -78,8 +79,22 @@
'select_form_order' =>
['-1','86400','604800','2592000','7776000',
'15552000','31104000']));
-
- $r->print(&Apache::loncommon::bodytag("Selecting a Course"));
+# if called from loncreateuser, report sections, then close
+ my ($loaditem,$seclist);
+ my $num_sections = 0;
+ my @sections = ();
+ if ($ENV{'form.form'} eq 'cu' && $ENV{'form.pickedcourse'}) {
+ $loaditem = 'onLoad="setSections()"';
+ my ($cdom,$cnum) = split/_/,$ENV{'form.pickedcourse'};
+ my %sections_count = ();
+ $num_sections = &Apache::loncommon::get_sections($cdom,$cnum,\%sections_count);
+ my @sections = ();
+ if ($num_sections > 0) {
+ @sections = (sort {$a <=> $b} keys %sections_count);
+ $seclist = join('","',@sections);
+ }
+ }
+ $r->print(&Apache::loncommon::bodytag("Selecting a Course",undef,$loaditem));
my %lt=&Apache::lonlocal::texthash(
'cac' => 'Course Activity',
'cde' => 'Course Description',
@@ -93,6 +108,11 @@
my $submitopener = '';
my $autosubmit = '';
my $roleelement = '';
+ my $lastaction = 'self.close()';
+ if ($ENV{'form.form'} eq 'cu') {
+ $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
+ 'document.courselist.submit();';
+ }
my $roledom = $ENV{'form.roleelement'};
if ($roledom) {
$roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
@@ -103,14 +123,43 @@
<script>
function gochoose(cname,cdom,cdesc) {
$name_code
- opener.document.$ENV{"form.form"}.$ENV{'form.cnumelement'}.value=cname;
- var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
- var i;
- for (i=0;i<slct.length;i++) {
- if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
+ var openerForm = "$ENV{'form.form'}";
+ opener.document.$ENV{'form.form'}.$ENV{'form.cnumelement'}.value=cname;
+ if (openerForm == 'cu' || openerForm == 'rolechoice') {
+ opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'}.value=cdom;
+ }
+ else {
+ var slct=opener.document.$ENV{'form.form'}.$ENV{'form.cdomelement'};
+ var i;
+ for (i=0;i<slct.length;i++) {
+ if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
+ }
}
$autosubmit
- self.close();
+ $lastaction
+}
+
+function setSections() {
+ var numSections = $num_sections
+ var sectionsArray = new Array("$seclist")
+ opener.document.$ENV{"form.form"}.currsec.length = 0
+ if (numSections == 0) {
+ opener.document.$ENV{"form.form"}.currsec.options[0] = new Option('No existing sections','-1',false,false)
+ }
+ else {
+ for (var i=0; i<numSections; i++) {
+ opener.document.$ENV{"form.form"}.currsec.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
+ }
+ opener.document.$ENV{"form.form"}.currsec.multiple=true
+ if (numSections < 3) {
+ opener.document.$ENV{"form.form"}.currsec.size=numSections;
+ }
+ else {
+ opener.document.$ENV{"form.form"}.currsec.size=3;
+ }
+ opener.document.$ENV{"form.form"}.currsec.options[0].selected = false
+ }
+ self.close()
}
</script>
$submitopener
@@ -139,7 +188,7 @@
my %courses=
&Apache::lonnet::courseiddump
($domainfilter,$descriptfilter,$timefilter);
- $r->print('<form>');
+ $r->print('<form name="courselist">');
my %by_descrip;
foreach my $course (keys %courses) {
my $descr;
@@ -162,7 +211,11 @@
")<br />\n");
}
if (!%courses) { $r->print(&mt('None found')); }
- $r->print('</form>');
+ $r->print('<input type="hidden" name="form" value="'.$ENV{'form.form'}.'" />'."\n".
+ '<input type="hidden" name="pickedcourse" value="" />'."\n".
+ '<input type="hidden" name="cnumelement" value="'.$ENV{'form.cnumelement'}.'" />'."\n".
+ '<input type="hidden" name="cdomelement" value="'.$ENV{'form.cdomelement'}.'" />'."\n".
+ '</form>');
}
$r->print('</body></html>');
return OK;
--raeburn1101232984--