--- loncom/interface/loncommon.pm 2006/05/01 20:48:55 1.359
+++ loncom/interface/loncommon.pm 2006/08/30 19:36:49 1.448
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.359 2006/05/01 20:48:55 albertel Exp $
+# $Id: loncommon.pm,v 1.448 2006/08/30 19:36:49 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -64,6 +64,8 @@ use HTML::Entities;
use Apache::lonhtmlcommon();
use Apache::loncoursedata();
use Apache::lontexconvert();
+use Apache::lonclonecourse();
+use LONCAPA;
my $readit;
@@ -284,7 +286,7 @@ sub browser_and_searcher_javascript {
}
url += 'element=' + elementname + '';
var title = 'Browser';
- var options = 'scrollbars=1,resizable=1,menubar=1,location=1';
+ var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
options += ',width=700,height=600';
editbrowser = open(url,title,options,'1');
editbrowser.focus();
@@ -305,7 +307,7 @@ sub browser_and_searcher_javascript {
}
url += 'element=' + elementname + '';
var title = 'Search';
- var options = 'scrollbars=1,resizable=1,menubar=0';
+ var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
options += ',width=700,height=600';
editsearcher = open(url,title,options,'1');
editsearcher.focus();
@@ -385,10 +387,11 @@ sub selectstudent_link {
sub coursebrowser_javascript {
my ($domainfilter)=@_;
+ my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
return (<
var stdeditbrowser;
- function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag) {
+ function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
var url = '/adm/pickcourse?';
var filter;
if (filter != null) {
@@ -414,6 +417,18 @@ sub coursebrowser_javascript {
if (multflag !=null && multflag != '') {
url += '&multiple='+multflag;
}
+ if (crstype == 'Course/Group') {
+ if (formname == 'cu') {
+ crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value;
+ if (crstype == "") {
+ alert("$crs_or_grp_alert");
+ return;
+ }
+ }
+ }
+ if (crstype !=null && crstype != '') {
+ url += '&type='+crstype;
+ }
var title = 'Course_Browser';
var options = 'scrollbars=1,resizable=1,menubar=0';
options += ',width=700,height=600';
@@ -425,9 +440,9 @@ ENDSTDBRW
}
sub selectcourse_link {
- my ($form,$unameele,$udomele,$desc,$extra_element,$multflag)=@_;
+ my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
return "".&mt('Select Course')."";
+ '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select [_1]',$selecttype)."";
}
sub check_uncheck_jscript {
@@ -658,14 +673,14 @@ sub help_open_topic {
{
$template .=
"".
- "$text";
+ " | $text";
}
# Add the graphic
my $title = &mt('Online Help');
my $helpicon=&lonhttpdurl("/adm/help/gif/smallHelp.gif");
$template .= <<"ENDTEMPLATE";
-
+
ENDTEMPLATE
if ($text ne '') { $template.=' |
' };
return $template;
@@ -692,40 +707,95 @@ sub helpLatexCheatsheet {
.'';
}
-sub help_open_menu {
- my ($color,$topic,$component_help,$function,$faq,$bug,$stayOnPage,$width,$height,$text) = @_;
- $text = "" if (not defined $text);
- $stayOnPage = 0 if (not defined $stayOnPage);
- if ($env{'browser.interface'} eq 'textual' ||
- $env{'environment.remote'} eq 'off' ) {
- $stayOnPage=1;
+sub general_help {
+ my $helptopic='Student_Intro';
+ if ($env{'request.role'}=~/^(ca|au)/) {
+ $helptopic='Authoring_Intro';
+ } elsif ($env{'request.role'}=~/^cc/) {
+ $helptopic='Course_Coordination_Intro';
}
- $width = 620 if (not defined $width);
- $height = 600 if (not defined $height);
- my $link='';
- my $title = &mt('Get help');
+ return $helptopic;
+}
+
+sub update_help_link {
+ my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
my $origurl = $ENV{'REQUEST_URI'};
$origurl=~s|^/~|/priv/|;
my $timestamp = time;
- foreach my $datum (\$color,\$function,\$topic,\$component_help,\$faq,
- \$bug,\$origurl) {
- $$datum = &Apache::lonnet::escape($$datum);
+ foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
+ $$datum = &escape($$datum);
}
- if (!$stayOnPage) {
- $link = "javascript:helpMenu('open')";
- } else {
- $link = "javascript:helpMenu('display')";
+
+ my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
+ my $output .= <<"ENDOUTPUT";
+
+ENDOUTPUT
+ return $output;
+}
+
+# now just updates the help link and generates a blue icon
+sub help_open_menu {
+ my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
+ = @_;
+
+ $stayOnPage = 0 if (not defined $stayOnPage);
+ if ($env{'browser.interface'} eq 'textual' ||
+ $env{'environment.remote'} eq 'off' ) {
+ $stayOnPage=1;
}
- my $banner_link = "/adm/helpmenu?page=banner&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
- my $details_link = "/adm/helpmenu?page=body&color=$color&function=$function&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp";
- my $template;
- if ($text ne "") {
- $template .=
- "".
- "$text";
+ my $output;
+ if ($component_help) {
+ if (!$text) {
+ $output=&help_open_topic($component_help,undef,$stayOnPage,
+ $width,$height);
+ } else {
+ my $help_text;
+ $help_text=&unescape($topic);
+ $output=''.
+ &help_open_topic($component_help,$help_text,$stayOnPage,
+ $width,$height).' | ';
+ }
}
+ my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
+ return $output.$banner_link;
+}
+
+sub top_nav_help {
+ my ($text) = @_;
+
+ $text = &mt($text);
+
+ my $stayOnPage =
+ ($env{'browser.interface'} eq 'textual' ||
+ $env{'environment.remote'} eq 'off' );
+ my $link= ($stayOnPage) ? "javascript:helpMenu('display')"
+ : "javascript:helpMenu('open')";
+ my $banner_link = &update_help_link(undef,undef,undef,undef,$stayOnPage);
+
+ my $title = &mt('Get help');
+
+ return <<"END";
+$banner_link
+ $text
+END
+}
+
+sub help_menu_js {
+ my ($text) = @_;
+
+ my $stayOnPage =
+ ($env{'browser.interface'} eq 'textual' ||
+ $env{'environment.remote'} eq 'off' );
+
+ my $width = 620;
+ my $height = 600;
+ my $helptopic=&general_help();
+ my $details_link = '/adm/help/'.$helptopic.'.hlp';
my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
- my $helpicon=&lonhttpdurl("/adm/lonIcons/helpgateway.gif");
my $start_page =
&Apache::loncommon::start_page('Help Menu', undef,
{'frameset' => 1,
@@ -737,10 +807,11 @@ sub help_open_menu {
&Apache::loncommon::end_page({'frameset' => 1,
'js_ready' => 1,});
- $template .= <<"ENDTEMPLATE";
-
-
+
ENDTEMPLATE
- if ($component_help) {
- if (!$text) {
- $template=&help_open_topic($component_help,undef,$stayOnPage,
- $width,$height).' '.$template;
- } else {
- my $help_text;
- $help_text=&Apache::lonnet::unescape($topic);
- $template=''.
- &help_open_topic($component_help,$help_text,$stayOnPage,
- $width,$height).' | '.$template.
- ' | ';
- }
- }
- if ($text ne '') { $template.=' |
' };
return $template;
}
@@ -802,8 +858,8 @@ sub help_open_bug {
$topic=~s/\W+/\+/g;
my $link='';
my $template='';
- my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
- &Apache::lonnet::escape($ENV{'REQUEST_URI'}).'&component='.$topic;
+ my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
+ &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
if (!$stayOnPage)
{
$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
@@ -817,14 +873,14 @@ sub help_open_bug {
{
$template .=
"".
- "$text";
+ " | $text";
}
# Add the graphic
my $title = &mt('Report a Bug');
my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
$template .= <<"ENDTEMPLATE";
-
+
ENDTEMPLATE
if ($text ne '') { $template.=' |
' };
return $template;
@@ -862,14 +918,14 @@ sub help_open_faq {
{
$template .=
"".
- "$text";
+ " | $text";
}
# Add the graphic
my $title = &mt('View the FAQ');
my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
$template .= <<"ENDTEMPLATE";
-
+
ENDTEMPLATE
if ($text ne '') { $template.=' |
' };
return $template;
@@ -1905,12 +1961,20 @@ sub get_related_words {
return ();
}
my @Words=();
+ my $count=0;
if (exists($thesaurus_db{$keyword})) {
# The first element is the number of times
# the word appears. We do not need it now.
- (undef,@Words) = (split(/:/,$thesaurus_db{$keyword}));
- for (my $i=0;$i<=$#Words;$i++) {
- ($Words[$i],undef)= split(/\,/,$Words[$i]);
+ my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
+ my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
+ my $threshold=$mostfrequentcount/10;
+ foreach my $possibleword (@RelatedWords) {
+ my ($word,$wordcount)=split(/\,/,$possibleword);
+ if ($wordcount>$threshold) {
+ push(@Words,$word);
+ $count++;
+ if ($count>10) { last; }
+ }
}
}
untie %thesaurus_db;
@@ -1989,6 +2053,9 @@ sub nickname {
sub getnames {
my ($uname,$udom)=@_;
+ if ($udom eq 'public' && $uname eq 'public') {
+ return ('lastname' => &mt('Public'));
+ }
my $id=$uname.':'.$udom;
my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
if ($cached) {
@@ -2024,10 +2091,11 @@ sub screenname {
# ------------------------------------------------------------- Message Wrapper
sub messagewrapper {
- my ($link,$username,$domain)=@_;
+ my ($link,$username,$domain,$subject,$text)=@_;
return
- ''.$link.'';
}
# --------------------------------------------------------------- Notes Wrapper
@@ -2041,6 +2109,9 @@ sub noteswrapper {
sub aboutmewrapper {
my ($link,$username,$domain,$target)=@_;
+ if (!defined($username) && !defined($domain)) {
+ return;
+ }
return ''.$link.'';
}
@@ -2071,7 +2142,9 @@ sub track_student_link {
$target = '';
}
if ($start) { $link.='&start='.$start; }
- return qq{$linktext};
+
+ return qq{$linktext}.
+ &help_open_topic('View_recent_activity');
}
=pod
@@ -2394,7 +2467,7 @@ sub get_previous_attempt {
} else {
$value=$returnhash{$version.':'.$key};
}
- $prevattempts.=''.&Apache::lonnet::unescape($value).' | ';
+ $prevattempts.=''.&unescape($value).' | ';
}
}
}
@@ -2406,7 +2479,7 @@ sub get_previous_attempt {
} else {
$value=$lasthash{$key};
}
- $value=&Apache::lonnet::unescape($value);
+ $value=&unescape($value);
if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
$prevattempts.=''.$value.' | ';
}
@@ -2528,7 +2601,7 @@ sub submlink {
if (!$symb) { $symb=$cursymb; }
}
if (!$symb) { $symb=&Apache::lonnet::symbread(); }
- $symb=&Apache::lonnet::escape($symb);
+ $symb=&escape($symb);
if ($target) { $target="target=\"$target\""; }
return ' 'margin-top: 0px',
@@ -2802,15 +2881,24 @@ sub bodytag {
'alink' => &designparm($function.'.alink',$domain),
'vlink' => &designparm($function.'.vlink',$domain),
'link' => &designparm($function.'.link',$domain),);
- @$addentries{keys(%design)} = @design{keys(%design)};
+ @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
# role and realm
- my ($role,$realm) =
- &Apache::lonnet::plaintext((split(/\./,$env{'request.role'}))[0]);
+ my ($role,$realm) = split(/\./,$env{'request.role'},2);
+ if ($role eq 'ca') {
+ my ($rdom,$rname) = ($realm =~ m-^/(\w+)/(\w+)$-);
+ $realm = &plainname($rname,$rdom).':'.$rdom;
+ }
# realm
if ($env{'request.course.id'}) {
+ if ($env{'request.role'} !~ /^cr/) {
+ $role = &Apache::lonnet::plaintext($role,&course_type());
+ }
$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
+ } else {
+ $role = &Apache::lonnet::plaintext($role);
}
+
if (!$realm) { $realm=' '; }
# Set messages
my $messages=&domainlogo($domain);
@@ -2818,7 +2906,7 @@ sub bodytag {
my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
- my $extra_body_attr = &make_attr_string($forcereg,$addentries);
+ my $extra_body_attr = &make_attr_string($forcereg,\%design);
# construct main body tag
my $bodytag = "".
@@ -2838,21 +2926,24 @@ sub bodytag {
return $bodytag;
}
-
+ my $name = &plainname($env{'user.name'},$env{'user.domain'});
+ if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
+ undef($role);
+ } else {
+ $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
+ }
my $roleinfo=(<
- $env{'environment.firstname'}
- $env{'environment.middlename'}
- $env{'environment.lastname'}
- $env{'environment.generation'}
+ $name
+
-$role
+$role
-$realm
+$realm
ENDROLE
@@ -2869,6 +2960,7 @@ ENDROLE
'.domain'}.'/'})) {
my $cid = $env{'request.course.id'};
$dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
+ $dc_info =~ s/\s+$//;
$dc_info = '('.$dc_info.')';
}
@@ -2895,7 +2987,7 @@ ENDROLE
$lastitem = $thisdisfn;
}
$titleinfo =
- &Apache::loncommon::help_open_menu('','','','',3,'Authoring').
+ &Apache::loncommon::help_open_menu('','',3,'Authoring').
'Construction Space: '.
'
';
+ }
+ }
+ if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
+ if ($args->{'setpolicy'}) {
+ $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
+ }
+ if ($args->{'setcontent'}) {
+ $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
+ }
+ }
+ if ($args->{'reshome'}) {
+ $cenv{'reshome'}=$args->{'reshome'}.'/';
+ $cenv{'reshome'}=~s/\/+$/\//;
+ }
+#
+# course has keyed access
+#
+ if ($args->{'setkeys'}) {
+ $cenv{'keyaccess'}='yes';
+ }
+# if specified, key authority is not course, but user
+# only active if keyaccess is yes
+ if ($args->{'keyauth'}) {
+ $args->{'keyauth'}=~s/[^\w\@]//g;
+ if ($args->{'keyauth'}) {
+ $cenv{'keyauth'}=$args->{'keyauth'};
+ }
+ }
+
+ if ($args->{'disresdis'}) {
+ $cenv{'pch.roles.denied'}='st';
+ }
+ if ($args->{'disablechat'}) {
+ $cenv{'plc.roles.denied'}='st';
+ }
+
+ # Record we've not yet viewed the Course Initialization Helper for this
+ # course
+ $cenv{'course.helper.not.run'} = 1;
+ #
+ # Use new Randomseed
+ #
+ $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
+ $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
+ #
+ # The encryption code and receipt prefix for this course
+ #
+ $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
+ $cenv{'internal.encpref'}=100+int(9*rand(99));
+ #
+ # By default, use standard grading
+ if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
+
+ $outcome .= ('
'.&mt('Setting environment').': '.
+ &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).'
');
+#
+# Open all assignments
+#
+ if ($args->{'openall'}) {
+ my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
+ my %storecontent = ($storeunder => time,
+ $storeunder.'.type' => 'date_start');
+
+ $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
+ ('resourcedata',\%storecontent,$$crsudom,$$crsunum).'
';
+ }
+#
+# Set first page
+#
+ unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
+ || ($cloneid)) {
+ use LONCAPA::map;
+ $outcome .= &mt('Setting first resource').': ';
+
+ my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
+ my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
+
+ $outcome .= ($fatal?$errtext:'read ok').' - ';
+ my $title; my $url;
+ if ($args->{'firstres'} eq 'syl') {
+ $title='Syllabus';
+ $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
+ } else {
+ $title='Navigate Contents';
+ $url='/adm/navmaps';
+ }
+
+ $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
+ (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+
+ if ($errtext) { $fatal=2; }
+ $outcome .= ($fatal?$errtext:'write ok').'
';
+ }
+ return $outcome;
+}
+
+############################################################
+############################################################
+
+sub course_type {
+ my ($cid) = @_;
+ if (!defined($cid)) {
+ $cid = $env{'request.course.id'};
+ }
+ if (defined($env{'course.'.$cid.'.type'})) {
+ return $env{'course.'.$cid.'.type'};
+ } else {
+ return 'Course';
+ }
+}
+
+sub group_term {
+ my $crstype = &course_type();
+ my %names = (
+ 'Course' => 'group',
+ 'Group' => 'team',
+ );
+ return $names{$crstype};
+}
sub icon {
my ($file)=@_;
@@ -5096,6 +5927,15 @@ sub lonhttpdurl {
return 'http://'.$ENV{'SERVER_NAME'}.':'.$lonhttpd_port.$url;
}
+sub absolute_url {
+ my ($host_name) = @_;
+ my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://');
+ if ($host_name eq '') {
+ $host_name = $ENV{'SERVER_NAME'};
+ }
+ return $protocol.$host_name;
+}
+
sub connection_aborted {
my ($r)=@_;
$r->print(" ");$r->rflush();
@@ -5125,7 +5965,7 @@ sub escape_double {
sub escape_url {
my ($url) = @_;
my @urlslices = split(/\//, $url,-1);
- my $lastitem = &Apache::lonnet::escape(pop(@urlslices));
+ my $lastitem = &escape(pop(@urlslices));
return join('/',@urlslices).'/'.$lastitem;
}
=pod