--- loncom/interface/loncommon.pm 2010/10/04 18:01:31 1.925.2.14
+++ loncom/interface/loncommon.pm 2010/02/12 15:42:39 1.937
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.925.2.14 2010/10/04 18:01:31 raeburn Exp $
+# $Id: loncommon.pm,v 1.937 2010/02/12 15:42:39 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -483,9 +483,9 @@ ENDAUTHORBRW
sub coursebrowser_javascript {
my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
- my $wintitle = &mt('Course Browser');
- if ($crstype ne '') {
- $wintitle = &mt($crstype);
+ my $wintitle = 'Course_Browser';
+ if ($crstype eq 'Community') {
+ $wintitle = 'Community_Browser';
}
my $id_functions = &javascript_index_functions();
my $output = '
@@ -1127,7 +1127,7 @@ sub help_open_topic {
$template.=' '
.'';
if ($text ne "") {
$template.='';
@@ -1719,10 +1719,13 @@ sub create_workbook {
my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
if (! defined($workbook)) {
$r->log_error("Error creating excel spreadsheet $filename: $!");
- $r->print('
'.&mt("Unable to create new Excel file. ".
- "This error has been logged. ".
- "Please alert your LON-CAPA administrator").
- '
');
+ $r->print(
+ '
'
+ .&mt('Problems occurred in creating the new Excel file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
return (undef);
}
#
@@ -1762,9 +1765,13 @@ sub create_text_file {
$fh = Apache::File->new('>/home/httpd'.$filename);
if (! defined($fh)) {
$r->log_error("Couldn't open $filename for output $!");
- $r->print(&mt('Problems occurred in creating the output file. '
- .'This error has been logged. '
- .'Please alert your LON-CAPA administrator.'));
+ $r->print(
+ '
'
+ .&mt('Problems occurred in creating the output file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
}
return ($fh,$filename)
}
@@ -1978,16 +1985,7 @@ sub select_dom_form {
($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
if ($showdomdesc) {
if ($dom ne '') {
- my $domdesc;
- if ($name eq 'srchdomain') {
- if ($dom eq 'gci') {
- $domdesc = 'Faculty';
- } else {
- $domdesc = 'Students';
- }
- } else {
- $domdesc = &Apache::lonnet::domain($dom,'description');
- }
+ my $domdesc = &Apache::lonnet::domain($dom,'description');
if ($domdesc ne '') {
$selectdomain .= ' ('.$domdesc.')';
}
@@ -2478,11 +2476,9 @@ sub authform_internal{
}
$autharg = '';
- my $authtext = '[_1] Internally authenticated (with initial password [_2])';
- if ($in{'caller'} eq 'requestcrs') {
- $authtext = "[_1] Students' password, if none in the uploaded file: [_2]";
- }
- $result = &mt($authtext,''.$autharg);
+ $result = &mt
+ ('[_1] Internally authenticated (with initial password [_2])',
+ ''.$autharg);
$result.="';
return $result;
}
@@ -4478,10 +4474,6 @@ sub bodytag {
'link' => &designparm($function.'.link',$domain),);
@design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
- my $custommenu;
- if ($env{'environment.remote'} eq 'off') {
- $custommenu = &needs_gci_custom();
- }
# role and realm
my ($role,$realm) = split(/\./,$env{'request.role'},2);
if ($role eq 'ca') {
@@ -4491,22 +4483,14 @@ sub bodytag {
# realm
if ($env{'request.course.id'}) {
if ($env{'request.role'} !~ /^cr/) {
- if (($custommenu) && ($role eq 'cm')) {
- undef($role);
- } else {
- $role = &Apache::lonnet::plaintext($role,&course_type());
- }
+ $role = &Apache::lonnet::plaintext($role,&course_type());
}
if ($env{'request.course.sec'}) {
$role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
}
$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
} else {
- if (($custommenu) && ($role eq 'cm')) {
- undef($role);
- } else {
- $role = &Apache::lonnet::plaintext($role);
- }
+ $role = &Apache::lonnet::plaintext($role);
}
if (!$realm) { $realm=' '; }
@@ -4557,66 +4541,7 @@ sub bodytag {
# $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
# }
- my $role_selector;
- if (($custommenu) && ($env{'request.course.id'}) &&
- ($env{'course.'.$env{'request.course.id'}.'.domain'} eq 'gcitest')) {
- $role_selector = &Apache::lonmenu::roles_selector(
- $env{'course.' . $env{'request.course.id'} . '.domain'},
- $env{'course.' . $env{'request.course.id'} . '.num'} );
- if ($role_selector) {
- $role_selector = ' '.$role_selector;
- }
- }
- my $cid = $env{'request.course.id'};
- my %gcicourses = (
- gci_9615072b469884921gcil1 => 'review',
- gci_1H96711d710194bfegcil1 => 'submit',
- gci_5422913620b814c90gcil1 => 'tutorial',
- );
- if (($custommenu && $cid && !$gcicourses{$cid}) || ($env{'user.domain'} eq 'gcitest')) {
- my $role = 'st';
- if ($custommenu) {
- $role = 'cc';
- }
- my ($switcher_js,$switcher,$formname);
- $formname = 'pickrole';
- my %courses = &existing_gcitest_courses($role);
- my $numcourses = keys(%courses);
- my $reqdcount = 0;
- if ($cid) {
- if ($courses{$cid}) {
- $reqdcount = 1;
- }
- }
- if ($numcourses > $reqdcount) {
- $switcher = &gcitest_switcher($role,$formname,%courses);
- my $current;
- if ($cid) {
- $current = $role.'./'.$env{'course.'.$cid.'.domain'}.
- '/'.$env{'course.'.$cid.'.num'};
- }
- $switcher_js = &Apache::loncommon::gcitest_switcher_js($current,$numcourses,$formname);
- if ($switcher_js) {
- $switcher_js= <<"ENDSCRIPT";
-
-ENDSCRIPT
- }
- }
- if ($switcher) {
- $switcher = $switcher_js.$switcher;
- if ($role_selector) {
- $role_selector .= ' '.$switcher;
- } else {
- $role_selector .= ' '.$switcher;
- }
- }
- }
if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
if ($dc_info) {
@@ -4627,13 +4552,12 @@ ENDSCRIPT
return $bodytag;
}
- if ($cid && $gcicourses{$cid} eq 'tutorial') {
- $bodytag .= '
'
.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
- .' '
- .&mt('Enter a valid e-mail address as the username for the new user.').' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.'
- ,'','')
+ .' '
+ .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
+ ,'','')
.'
';
}
}
@@ -10211,19 +9977,19 @@ sub check_clone {
my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
my $clonemsg;
my $can_clone = 0;
- my $lctype = lc($args->{'crstype'});
+ my $lctype = lc($args->{'type'});
if ($lctype ne 'community') {
$lctype = 'course';
}
if ($clonehome eq 'no_host') {
- if ($args->{'crstype'} eq 'Community') {
+ if ($args->{'type'} eq 'Community') {
$clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
} else {
$clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
}
} else {
my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
- if ($args->{'crstype'} eq 'Community') {
+ if ($args->{'type'} eq 'Community') {
if ($clonedesc{'type'} ne 'Community') {
$clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
return ($can_clone, $clonemsg, $cloneid, $clonehome);
@@ -10242,7 +10008,7 @@ sub check_clone {
$can_clone = 1;
} else {
my $ccrole = 'cc';
- if ($args->{'crstype'} eq 'Community') {
+ if ($args->{'type'} eq 'Community') {
$ccrole = 'co';
}
my %roleshash =
@@ -10253,7 +10019,7 @@ sub check_clone {
if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
$can_clone = 1;
} else {
- if ($args->{'crstype'} eq 'Community') {
+ if ($args->{'type'} eq 'Community') {
$clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
} else {
$clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
@@ -10592,21 +10358,6 @@ sub construct_course {
$outcome .= ($fatal?$errtext:'write ok').$linefeed;
}
- if ($args->{'cloneroster'}) {
- my ($numadded,$clisterror) = &Apache::lonclonecourse::copyroster($cloneid,$$courseid,$args->{'startaccess'},$args->{'endaccess'});
- if ($clisterror) {
- $outcome .= "\0".&mt('An error occurred when copying the student roster from the old course to the new course; the error was: [_1].',$clisterror).$linefeed;
- if ($numadded) {
- $outcome .= &mt('Although [quant,_1,student] have received roles in the new course the roster does not report this. It is ').$linefeed;
- }
- } else {
- if ($numadded) {
- $outcome .= "\0".&mt('[quant,_1,student] copied from roster for old course to roster for new course.',$numadded).$linefeed;
- } else {
- $outcome .= "\0".&mt('No students have been enrolled in the new Concept Test.').' '.&mt('This is because either (a) an error occurred, or (b) there were no students with either current access or access which ended on/after the current default end date set for access to the old course.').$linefeed;
- }
- }
- }
return (1,$outcome);
}
@@ -10873,60 +10624,6 @@ sub _add_to_env {
}
}
-sub new_roles_update {
- my $rolecount = 0;
- foreach my $envkey (keys(%env)) {
- next unless ($envkey =~ /^user\.role\./);
- $rolecount ++;
- }
- my $newrolecount = 0;
- if (!$rolecount) {
- my %userenv;
- foreach my $crstype ('official','unofficial','community') {
- $userenv{'canrequest.'.$crstype} =
- &Apache::lonnet::usertools_access($env{'user.name'},
- $env{'user.domain'},$crstype,'reload','requestcourses');
- }
- my $then=$env{'user.login.time'};
- my $refresh=time;
- my (%userroles,%allroles,%allgroups,@newroles);
- my %roleshash =
- &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',['active','future','previous'],undef,undef,1);
- foreach my $item (keys(%roleshash)) {
- my ($uname,$udom,$role,$section) = split(':',$item);
- my $where = '/'.$udom.'/'.$uname;
- my ($tstart,$tend) = split(':',$roleshash{$item});
- if ($section ne '') {
- $where .= '/'.$section;
- }
- my $spec = $role.'.'.$where;
- &Apache::lonnet::set_arearole($role,$where,$tstart,$tend,
- $env{'user.domain'},$env{'user.name'});
- $userroles{'user.role.'.$spec} = $tstart.'.'.$tend;
- $newrolecount ++;
- unless (grep(/^\Q$role\E$/,@newroles)) {
- push(@newroles,$role);
- }
- my $status =
- &Apache::lonnet::curr_role_status($tstart,$tend,$refresh,$then);
- if ($status eq 'active') {
- &Apache::lonnet::gather_roleprivs(\%allroles,\%allgroups,\%userroles,
- $where,$role,$tstart,$tend);
- }
- }
- if (@newroles) {
- my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles,
- \%allgroups);
- &Apache::lonnet::appenv(\%userroles,[@newroles,'cm']);
- $userenv{'user.adv'} = $adv;
- $userenv{'user.author'} = $author;
- $userenv{'user.refresh.time'} = $refresh;
- }
- &Apache::lonnet::appenv(\%userenv);
- }
- return $newrolecount;
-}
-
# --- Get the symbolic name of a problem and the url
sub get_symb {
my ($request,$silent) = @_;
@@ -10968,151 +10665,6 @@ sub clean_symb {
return ($symb,$enc);
}
-sub needs_gci_custom {
- my $custommenu;
- my $numdc = &check_for_gci_dc();
- unless ($numdc) {
- my $then=$env{'user.login.time'};
- my $now = time;
- my %cnums = (
- review => '9615072b469884921gcil1',
- submit => '1H96711d710194bfegcil1',
- );
- if ($env{'user.role.st./gci/'.$cnums{'review'}}) {
- my ($start,$end) =
- split('.',$env{'user.role.st./gci/'.$cnums{'review'}});
- if (((!$start) || ($start && $start <= $now)) &&
- ((!$end) || ($end > $now))) {
- $custommenu = 1;
- if ($env{'user.role.cc./gci/'.$cnums{'review'}}) {
- my ($ccstart,$ccend) =
- split('.',$env{'user.role.cc./gci/'.$cnums{'review'}});
- if (((!$start) || ($start && $start <= $now)) &&
- ((!$end) || ($end > $now))) {
- $custommenu = '';
- }
- }
- }
- }
- }
- return $custommenu;
-}
-
-sub check_for_gci_dc {
- my $then=$env{'user.login.time'};
- my $numdc = 0;
- foreach my $dom ('gci','gcitest') {
- if ($env{'user.role.dc./'.$dom.'/'}) {
- my $livedc = 1;
- my ($tstart,$tend)=split(/\./,$env{'user.role.dc./'.$dom.'/'});
- if ($tstart && $tstart>$then) { $livedc = 0; }
- if ($tend && $tend <$then) { $livedc = 0; }
- if ($livedc) {
- $numdc++;
- }
- }
- }
- return $numdc;
-}
-
-sub existing_gcitest_courses {
- my ($role) = @_;
- my %courses;
- my $cdom = 'gcitest';
- my $now = time;
- foreach my $envkey (keys(%env)) {
- my $cnum;
- if ($envkey =~ m{^user\.role\.\Q$role\E\./\Q$cdom\E/($match_courseid)$}) {
- $cnum = $1;
- } else {
- next;
- }
- my ($tstart,$tend) = split('.',$env{$envkey});
- if (((!$tstart) || ($tstart < $now)) && ((!$tend) || ($tend > $now))) {
- my $descr = $env{'course.'.$cdom.'_'.$cnum.'.description'};
- if ($descr ne '') {
- $courses{$cdom.'_'.$cnum}{'description'} = $descr;
- }
- }
- }
- return %courses;
-}
-
-sub gcitest_switcher {
- my ($role,$formname,%courses) = @_;
- my $output;
- my %Sortby;
- foreach my $course (sort(keys(%courses))) {
- next unless (ref($courses{$course}) eq 'HASH');
- my $clean_title = $courses{$course}{'description'};
- $clean_title =~ s/\W+//g;
- if ($clean_title eq '') {
- $clean_title = $courses{$course}{'description'};
- }
- push(@{$Sortby{$clean_title}},$course);
- }
- my @sorted_courses = sort { lc($a) cmp lc($b) } (keys(%Sortby));
- my $default;
- if (@sorted_courses > 1) {
- if (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
- $default = &mt('Switch concept test ...');
- } else {
- $default = &mt('Select a concept test ...');
- }
- } else {
- unless (($env{'request.course.id'}) && ($courses{$env{'request.course.id'}})) {
- $default = &mt('Select concept test ...');
- }
- }
- if ($default) {
- $output = '';
- }
- return $output;
-}
-
-sub gcitest_switcher_js {
- my ($current,$numcourses,$formname) = @_;
- my $output = <<"ENDJS";
-
-function courseswitcher(caller) {
- var numcourses = $numcourses;
- var current = '$current';
- var choice = document.$formname.newrole.options[document.$formname.newrole.selectedIndex].value;
- if (choice == '') {
- if (caller == 'icon') {
- alert('No Concept Test selected');
- }
- document.$formname.selectrole.value = '';
- return;
- }
- if (choice == current) {
- if ((caller != 'icon') && (numcourses > 1)) {
- alert('You have selected the current course.\\nPlease select a different Concept Test course');
- }
- document.$formname.newrole.selectedIndex = 0;
- document.$formname.selectrole.value = '';
- return;
- }
- document.$formname.selectrole.value = '1';
- document.$formname.submit();
- return;
-}
-
-ENDJS
- return $output;
-}
-
-
-
=pod
=back