[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 15:22:05 -0000
This is a MIME encoded message
--raeburn1198250525
Content-Type: text/plain
raeburn Fri Dec 21 10:22:05 2007 EDT
Modified files:
/loncom/interface loncreateuser.pm lonuserutils.pm
Log:
lonuserutils.pm
- Javascript code used to verify section selections when DC picks a course to assign roles to moved to lonuserutils::dc_setcourse_js().
- Localization of alert messages generated by setCourse() javascript
(lonuserutils::sectioncheck_alerts() contains the text strings).
loncreateuser.pm
- groupslist used to check for section name/group name collision retrieved from lonuserutils::get_groupslist()
- Eliminate some unused code built to customize text for course vs. non-standard course context in course selector for DC to pick course to which to add roles.
- &validation_javascript() added to aggregate the javascript functions used in validating section choices for role addition.
--raeburn1198250525
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221102205.txt"
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.215 loncom/interface/loncreateuser.pm:1.216
--- loncom/interface/loncreateuser.pm:1.215 Fri Dec 21 09:35:42 2007
+++ loncom/interface/loncreateuser.pm Fri Dec 21 10:22:01 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.215 2007/12/21 14:35:42 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.216 2007/12/21 15:22:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -597,162 +597,33 @@
my $nondc_setsection_code = '';
my %loaditem;
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
- $groupslist = '"'.$groupslist.'"';
- }
-
- if ($env{'request.role'} =~ m-^dc\./($match_domain)/$-) {
- my $dcdom = $1;
- $loaditem{'onload'} = "document.cu.coursedesc.value='';";
- my @rolevals = ('st','ta','ep','in','cc');
- my (@crsroles,@grproles);
- for (my $i=0; $i<@rolevals; $i++) {
- $crsroles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Course');
- $grproles[$i]=&Apache::lonnet::plaintext($rolevals[$i],'Group');
- }
- my $rolevalslist = join('","',@rolevals);
- my $crsrolenameslist = join('","',@crsroles);
- my $grprolenameslist = join('","',@grproles);
- my $pickcrsfirst = '<--'.&mt('Pick course first');
- my $pickgrpfirst = '<--'.&mt('Pick group first');
- $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;
- var newsecs = new Array();
- 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 != "" && document.cu.currsec.options[i].value != null) {
- if (numsections == 0) {
- section = document.cu.currsec.options[i].value
- numsections = 1;
- }
- else {
- section = section + "," + document.cu.currsec.options[i].value
- numsections ++;
- }
- }
- }
- }
- if (document.cu.newsec.value != "" && document.cu.newsec.value != null) {
- if (numsections == 0) {
- section = document.cu.newsec.value
- }
- else {
- section = section + "," + document.cu.newsec.value
- }
- newsecs = document.cu.newsec.value.split(/,/g);
- numsections = numsections + newsecs.length;
- }
- if ((userrole == 'st') && (numsections > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsections+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- for (var j=0; j<newsecs.length; j++) {
- if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
- alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
- return;
- }
- if (document.cu.groups.value != '') {
- var groups = document.cu.groups.value.split(/,/g);
- for (var k=0; k<groups.length; k++) {
- if (newsecs[j] == groups[k]) {
- alert("'"+newsecs[j]+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
- return;
- }
- }
- }
- }
- if ((userrole == 'cc') && (numsections > 0)) {
- alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
- section = "";
- }
- var coursename = "_$dcdom"+"_"+course+"_"+userrole
- var numcourse = getIndex(document.cu.dccourse);
- if (numcourse == "-1") {
- alert("There was a problem with your course selection");
- return
- }
- else {
- document.cu.elements[numcourse].name = "act"+coursename;
- var numnewsec = getIndex(document.cu.newsec);
- if (numnewsec != "-1") {
- document.cu.elements[numnewsec].name = "sec"+coursename;
- document.cu.elements[numnewsec].value = section;
- }
- var numstart = getIndex(document.cu.start);
- if (numstart != "-1") {
- document.cu.elements[numstart].name = "start"+coursename;
- }
- var numend = getIndex(document.cu.end);
- if (numend != "-1") {
- document.cu.elements[numend].name = "end"+coursename
- }
- }
- }
- document.cu.submit();
- }
+ my $groupslist = &Apache::lonuserutils::get_groupslist();
- function getIndex(caller) {
- for (var i=0;i<document.cu.elements.length;i++) {
- if (document.cu.elements[i] == caller) {
- return i;
- }
- }
- return -1;
- }
-ENDSCRIPT
- } else {
- $nondc_setsection_code =
- &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
- }
- my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
- $nondc_setsection_code,$groupslist);
-
- my ($jsback,$elements) = &crumb_utilities();
- my $javascript_validations;
- if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($uhome eq 'no_host')) {
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($ccdomain);
- $javascript_validations =
- &Apache::lonuserutils::javascript_validations('auth',$krbdefdom,undef,
- undef,$ccdomain);
- }
- $js .= "\n".
- '<script type="text/javascript">'."\n".$jsback."\n".
- $javascript_validations.'</script>';
+ my $js = &validation_javascript($context,$ccdomain,$pjump_def,
+ $groupslist,$newuser,$formname,\%loaditem);
my $start_page =
&Apache::loncommon::start_page('User Management',
$js,{'add_entries' => \%loaditem,});
+ my %breadcrumb_text = &singleuser_breadcrumb();
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu)",
- text=>"Create/modify user",
+ ({href=>"javascript:backPage($form)",
+ text=>$breadcrumb_text{'search'},
faq=>282,bug=>'Instructor Interface',});
if ($env{'form.phase'} eq 'userpicked') {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
- text=>"Select a user",
+ ({href=>"javascript:backPage($form,'get_user_info','select')",
+ text=>$breadcrumb_text{'userpicked'},
faq=>282,bug=>'Instructor Interface',});
}
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
- text=>"Set user role",
+ ({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
+ text=>$breadcrumb_text{'modify'},
faq=>282,bug=>'Instructor Interface',});
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
my $forminfo =<<"ENDFORMINFO";
-<form action="/adm/createuser" method="post" name="cu">
+<form action="/adm/createuser" method="post" name="$formname">
<input type="hidden" name="phase" value="update_user_data" />
<input type="hidden" name="ccuname" value="$ccuname" />
<input type="hidden" name="ccdomain" value="$ccdomain" />
@@ -766,7 +637,7 @@
$inccourses{$1.'_'.$2}=1;
}
}
- if ($uhome eq 'no_host') {
+ if ($newuser) {
my $portfolioform;
if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
# Current user has quota modification privileges
@@ -789,7 +660,7 @@
$loginscript
</script>
<input type='hidden' name='makeuser' value='1' />
-<h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
+<h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
ENDTITLE
if ($env{'form.action'} eq 'singlestudent') {
$r->print(' ('.$lt{'ast'}.')');
@@ -866,7 +737,7 @@
$permission));
}
$r->print('</div><div class="LC_clear_float_footer"></div>');
- } else { # user already exist-
+ } else { # user already exists
my %lt=&Apache::lonlocal::texthash(
'cup' => "Modify existing user: ",
'ens' => "Enroll one student: ",
@@ -1291,6 +1162,37 @@
return $output;
}
+sub validation_javascript {
+ my ($context,$ccdomain,$pjump_def,$groupslist,$newuser,$formname,
+ $loaditem) = @_;
+ my $dc_setcourse_code = '';
+ my $nondc_setsection_code = '';
+ if ($context eq 'domain') {
+ my $dcdom = $env{'request.role.domain'};
+ $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
+ $dc_setcourse_code = &Apache::lonuserutils::dc_setcourse_js('cu','singleuser');
+ } else {
+ $nondc_setsection_code =
+ &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
+ }
+ my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
+ $nondc_setsection_code,$groupslist);
+
+ my ($jsback,$elements) = &crumb_utilities();
+ my $javascript_validations;
+ if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($newuser)) {
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($ccdomain);
+ $javascript_validations =
+ &Apache::lonuserutils::javascript_validations('createuser',$krbdefdom,undef,
+ undef,$ccdomain);
+ }
+ $js .= "\n".
+ '<script type="text/javascript">'."\n".$jsback."\n".
+ $javascript_validations.'</script>';
+ return $js;
+}
+
sub user_authentication {
my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.18 loncom/interface/lonuserutils.pm:1.19
--- loncom/interface/lonuserutils.pm:1.18 Fri Dec 21 09:05:40 2007
+++ loncom/interface/lonuserutils.pm Fri Dec 21 10:22:01 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.18 2007/12/21 14:05:40 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.19 2007/12/21 15:22:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3940,6 +3940,143 @@
return ($cnum,$cdom,$cdesc);
}
+sub dc_setcourse_js {
+ my ($formname,$mode) = @_;
+ my $dc_setcourse_code;
+ my $cctext = &Apache::lonnet::plaintext('cc');
+ my %alerts = §ioncheck_alerts();
+ my $role = 'role';
+ if ($mode eq 'upload') {
+ $role = 'courserole';
+ }
+ $dc_setcourse_code = (<<"SCRIPTTOP");
+function setCourse() {
+ var course = document.$formname.dccourse.value;
+ if (course != "") {
+ if (document.$formname.dcdomain.value != document.$formname.origdom.value) {
+ alert("$alerts{'curd'}");
+ return;
+ }
+ var userrole = document.$formname.$role.options[document.$formname.$role.selectedIndex].value
+ var section="";
+ var numsections = 0;
+ var newsecs = new Array();
+ for (var i=0; i<document.$formname.currsec.length; i++) {
+ if (document.$formname.currsec.options[i].selected == true ) {
+ if (document.$formname.currsec.options[i].value != "" && document.$formname.currsec.options[i].value != null) {
+ if (numsections == 0) {
+ section = document.$formname.currsec.options[i].value
+ numsections = 1;
+ }
+ else {
+ section = section + "," + document.$formname.currsec.options[i].value
+ numsections ++;
+ }
+ }
+ }
+ }
+ if (document.$formname.newsec.value != "" && document.$formname.newsec.value != null) {
+ if (numsections == 0) {
+ section = document.$formname.newsec.value
+ }
+ else {
+ section = section + "," + document.$formname.newsec.value
+ }
+ newsecs = document.$formname.newsec.value.split(/,/g);
+ numsections = numsections + newsecs.length;
+ }
+ if ((userrole == 'st') && (numsections > 1)) {
+ alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ return;
+ }
+ for (var j=0; j<newsecs.length; j++) {
+ if ((newsecs[j] == 'all') || (newsecs[j] == 'none')) {
+ alert("'"+newsecs[j]+"' $alerts{'mayn'}.\\n$alerts{'plsc'}.");
+ return;
+ }
+ if (document.$formname.groups.value != '') {
+ var groups = document.$formname.groups.value.split(/,/g);
+ for (var k=0; k<groups.length; k++) {
+ if (newsecs[j] == groups[k]) {
+ alert("'"+newsecs[j]+"' $alerts{'mayt'}.\\n$alerts{'secn'}. $alerts{'plsc'}.");
+ return;
+ }
+ }
+ }
+ }
+ if ((userrole == 'cc') && (numsections > 0)) {
+ alert("$alerts{'secd'} $cctext $alerts{'role'}.\\n$alerts{'accr'}.");
+ section = "";
+ }
+SCRIPTTOP
+ if ($mode ne 'upload') {
+ $dc_setcourse_code .= (<<"ENDSCRIPT");
+ var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
+ var numcourse = getIndex(document.$formname.dccourse);
+ if (numcourse == "-1") {
+ alert("$alerts{'thwa'}");
+ return;
+ }
+ else {
+ document.$formname.elements[numcourse].name = "act"+coursename;
+ var numnewsec = getIndex(document.$formname.newsec);
+ if (numnewsec != "-1") {
+ document.$formname.elements[numnewsec].name = "sec"+coursename;
+ document.$formname.elements[numnewsec].value = section;
+ }
+ var numstart = getIndex(document.$formname.start);
+ if (numstart != "-1") {
+ document.$formname.elements[numstart].name = "start"+coursename;
+ }
+ var numend = getIndex(document.$formname.end);
+ if (numend != "-1") {
+ document.$formname.elements[numend].name = "end"+coursename
+ }
+ }
+ }
+ document.$formname.submit();
+}
+
+ENDSCRIPT
+ } else {
+ $dc_setcourse_code .= "
+ document.$formname.sections.value = section;
+ }
+ return 'ok';
+}
+";
+ }
+ $dc_setcourse_code .= (<<"ENDSCRIPT");
+
+ function getIndex(caller) {
+ for (var i=0;i<document.$formname.elements.length;i++) {
+ if (document.$formname.elements[i] == caller) {
+ return i;
+ }
+ }
+ return -1;
+ }
+ENDSCRIPT
+}
+
+sub sectioncheck_alerts {
+ my %alerts = &Apache::lonlocal::texthash(
+ curd => 'You must select a course in the current domain',
+ inea => 'In each course, each user may only have one student role at a time',
+ youh => 'You had selected',
+ sect => 'sections',
+ plsm => 'Please modify your selections so they include no more than one section',
+ mayn => 'may not be used as the name for a section, as it is a reserved word',
+ plsc => 'Please choose a different section name',
+ mayt => 'may not be used as the name for a section, as it is the name of a course group',
+ secn => 'Section names and group names must be distinct',
+ secd => 'Section designations do not apply to ',
+ role => 'roles',
+ accr => 'role will be added with access to all sections',
+ thwa => 'There was a problem with your course selection'
+ );
+ return %alerts;
+}
1;
--raeburn1198250525--