--- loncom/interface/loncommon.pm 2004/02/04 15:29:06 1.179 +++ loncom/interface/loncommon.pm 2004/07/21 20:23:34 1.202 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.179 2004/02/04 15:29:06 matthew Exp $ +# $Id: loncommon.pm,v 1.202 2004/07/21 20:23:34 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -74,6 +74,7 @@ my $readit; my %language; my %supported_language; my %cprtag; +my %scprtag; my %fe; my %fd; my %category_extensions; @@ -131,6 +132,20 @@ BEGIN { close($fh); } } +# ------------------------------------------------------------------ source copyrights + { + my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}. + '/source_copyright.tab'; + if ( open (my $fh,"<$sourcecopyrightfile") ) { + while (<$fh>) { + next if /^\#/; + chomp; + my ($key,$val)=(split(/\s+/,$_,2)); + $scprtag{$key}=$val; + } + close($fh); + } + } # -------------------------------------------------------------- domain designs @@ -220,10 +235,10 @@ formname and elementname indicate the na the element that the results of the browsing selection are to be placed in. Specifying 'only' will restrict the browser to displaying only files -with the given extension. Can be a comma seperated list. +with the given extension. Can be a comma separated list. Specifying 'omit' will restrict the browser to NOT displaying files -with the given extension. Can be a comma seperated list. +with the given extension. Can be a comma separated list. =item * opensearcher(formname, elementname) [javascript] @@ -235,6 +250,8 @@ of the element the selection from the se =cut sub browser_and_searcher_javascript { + my ($mode)=@_; + if (!defined($mode)) { $mode='edit'; } my $resurl=&lastresurl(); return < var stdeditbrowser; - function opencrsbrowser(formname,uname,udom) { + function opencrsbrowser(formname,uname,udom,desc) { var url = '/adm/pickcourse?'; var filter; if (filter != null) { @@ -368,7 +385,8 @@ sub coursebrowser_javascript { } } url += 'form=' + formname + '&cnumelement='+uname+ - '&cdomelement='+udom; + '&cdomelement='+udom+ + '&cnameelement='+desc; var title = 'Course_Browser'; var options = 'scrollbars=1,resizable=1,menubar=0'; options += ',width=700,height=600'; @@ -380,9 +398,9 @@ ENDSTDBRW } sub selectcourse_link { - my ($form,$unameele,$udomele)=@_; + my ($form,$unameele,$udomele,$desc)=@_; return "".&mt('Select Course').""; + '","'.$udomele.'","'.$desc.'");'."'>".&mt('Select Course').""; } =pod @@ -621,6 +639,61 @@ 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; + } + $width = 620 if (not defined $width); + $height = 600 if (not defined $height); + my $link=''; + my $title = &mt('Get help'); + my $origurl = $ENV{'REQUEST_URI'}; + my $timestamp = time; + foreach (\$color,\$function,\$topic,\$component_help,\$faq,\$bug,\$origurl) { + $$_ = &Apache::lonnet::escape($$_); + } + + if (!$stayOnPage) { + $link = "javascript:helpMenu('open')"; + } else { + $link = "javascript:helpMenu('display')"; + } + 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"; + } + $template .= <<"ENDTEMPLATE"; + + (Help Menu) +ENDTEMPLATE + if ($text ne '') { $template.='
' }; + return $template; +} + sub help_open_bug { my ($topic, $text, $stayOnPage, $width, $height) = @_; unless ($ENV{'user.adv'}) { return ''; } @@ -631,8 +704,8 @@ sub help_open_bug { $ENV{'environment.remote'} eq 'off' ) { $stayOnPage=1; } - $width = 350 if (not defined $width); - $height = 400 if (not defined $height); + $width = 600 if (not defined $width); + $height = 600 if (not defined $height); $topic=~s/\W+/\+/g; my $link=''; @@ -709,15 +782,20 @@ ENDTEMPLATE } +############################################################### +############################################################### + =pod =item * csv_translate($text) -Translate $text to allow it to be output as a 'comma seperated values' +Translate $text to allow it to be output as a 'comma separated values' format. =cut +############################################################### +############################################################### sub csv_translate { my $text = shift; $text =~ s/\"/\"\"/g; @@ -725,6 +803,60 @@ sub csv_translate { return $text; } + +############################################################### +############################################################### + +=pod + +=item * define_excel_formats + +Define some commonly used Excel cell formats. + +Currently supported formats: + +=over 4 + +=item header + +=item bold + +=item h1 + +=item h2 + +=item h3 + +=item date + +=back + +Inputs: $workbook + +Returns: $format, a hash reference. + +=cut + +############################################################### +############################################################### +sub define_excel_formats { + my ($workbook) = @_; + my $format; + $format->{'header'} = $workbook->add_format(bold => 1, + bottom => 1, + align => 'center'); + $format->{'bold'} = $workbook->add_format(bold=>1); + $format->{'h1'} = $workbook->add_format(bold=>1, size=>18); + $format->{'h2'} = $workbook->add_format(bold=>1, size=>16); + $format->{'h3'} = $workbook->add_format(bold=>1, size=>14); + $format->{'date'} = $workbook->add_format(num_format=> + 'mmm d yyyy hh:mm AM/PM'); + return $format; +} + +############################################################### +############################################################### + =pod =item * change_content_javascript(): @@ -847,21 +979,27 @@ sub domain_select { } &get_domains; if ($multiple) { $domains{''}=&mt('Any domain'); - return &multiple_select_form($name,$value,%domains); + return &multiple_select_form($name,$value,4,%domains); } else { return &select_form($name,$value,%domains); } } sub multiple_select_form { - my ($name,$value,%hash)=@_; + my ($name,$value,$size,%hash)=@_; my %selected = map { $_ => 1 } ref($value)?@{$value}:($value); my $output=''; - my $size =(scalar keys %hash<4?scalar keys %hash:4); + if (! defined($size)) { + $size = 4; + if (scalar(keys(%hash))<4) { + $size = scalar(keys(%hash)); + } + } $output.="\n\n"; return $output; @@ -1591,6 +1729,7 @@ sub plainname { $names{'lastname'}.' '.$names{'generation'}; $name=~s/\s+$//; $name=~s/\s+/ /g; + if ($name !~ /\S/) { $name=$uname.'@'.$udom; } return $name; } @@ -1648,9 +1787,11 @@ sub screenname { # ------------------------------------------------------------- Message Wrapper sub messagewrapper { - my ($link,$un,$do)=@_; + my ($link,$username,$domain)=@_; return -"$link"; + ''.$link.''; } # --------------------------------------------------------------- Notes Wrapper @@ -1663,8 +1804,8 @@ sub noteswrapper { sub aboutmewrapper { my ($link,$username,$domain,$target)=@_; - return "$link"; + return ''.$link.''; } # ------------------------------------------------------------ Syllabus Wrapper @@ -1747,6 +1888,30 @@ sub copyrightdescription { =pod +=item * source_copyrightids() + +returns list of all source copyrights + +=cut + +sub source_copyrightids { + return sort(keys(%scprtag)); +} + +=pod + +=item * source_copyrightdescription() + +returns description of a specified source copyright id + +=cut + +sub source_copyrightdescription { + return &mt($scprtag{shift(@_)}); +} + +=pod + =item * filecategories() returns list of all file categories @@ -1785,7 +1950,7 @@ sub fileembstyle { sub filecategoryselect { my ($name,$value)=@_; - return &select_form($name,$value, + return &select_form($value,$name, '' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))); } @@ -1799,7 +1964,9 @@ returns description for a specified file =cut sub filedescription { - return &mt($fd{lc(shift(@_))}); + my $file_description = $fd{lc(shift())}; + $file_description =~ s:([\[\]]):~$1:g; + return &mt($file_description); } =pod @@ -1813,7 +1980,9 @@ extra formatting sub filedescriptionex { my $ex=shift; - return '.'.$ex.' '.&mt($fd{lc($ex)}); + my $file_description = $fd{lc($ex)}; + $file_description =~ s:([\[\]]):~$1:g; + return '.'.$ex.' '.&mt($file_description); } # End of .tab access @@ -2034,22 +2203,19 @@ show a snapshot of what student was look =cut sub get_student_view { - my ($symb,$username,$domain,$courseid,$target) = @_; + my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_; my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb); - my (%old,%moreenv); + my (%form); my @elements=('symb','courseid','domain','username'); foreach my $element (@elements) { - $old{$element}=$ENV{'form.grade_'.$element}; - $moreenv{'form.grade_'.$element}=eval '$'.$element #' + $form{'grade_'.$element}=eval '$'.$element #' } - if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';} - &Apache::lonnet::appenv(%moreenv); - $feedurl=&Apache::lonnet::clutter($feedurl); - my $userview=&Apache::lonnet::ssi_body($feedurl); - &Apache::lonnet::delenv('form.grade_'); - foreach my $element (@elements) { - $ENV{'form.grade_'.$element}=$old{$element}; + if (defined($moreenv)) { + %form=(%form,%{$moreenv}); } + if ($target eq 'tex') {$form{'grade_target'} = 'tex';} + $feedurl=&Apache::lonnet::clutter($feedurl); + my $userview=&Apache::lonnet::ssi_body($feedurl,%form); $userview=~s/\]*\>//gi; $userview=~s/\<\/body\>//gi; $userview=~s/\//gi; @@ -2072,19 +2238,14 @@ show a snapshot of how student was answe sub get_student_answers { my ($symb,$username,$domain,$courseid,%form) = @_; my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb); - my (%old,%moreenv); + my (%moreenv); my @elements=('symb','courseid','domain','username'); foreach my $element (@elements) { - $old{$element}=$ENV{'form.grade_'.$element}; - $moreenv{'form.grade_'.$element}=eval '$'.$element #' - } - $moreenv{'form.grade_target'}='answer'; - &Apache::lonnet::appenv(%moreenv); - my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%form); - &Apache::lonnet::delenv('form.grade_'); - foreach my $element (@elements) { - $ENV{'form.grade_'.$element}=$old{$element}; + $moreenv{'grade_'.$element}=eval '$'.$element #' } + $moreenv{'grade_target'}='answer'; + %moreenv=(%form,%moreenv); + my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%moreenv); return $userview; } @@ -2300,19 +2461,7 @@ other decorations will be returned. sub bodytag { my ($title,$function,$addentries,$bodyonly,$domain,$forcereg)=@_; $title=&mt($title); - unless ($function) { - $function='student'; - if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { - $function='coordinator'; - } - if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { - $function='admin'; - } - if (($ENV{'request.role'}=~/^(au|ca)/) || - ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) { - $function='author'; - } - } + $function = &get_users_function() if (!$function); my $img=&designparm($function.'.img',$domain); my $pgbg=&designparm($function.'.pgbg',$domain); my $tabbg=&designparm($function.'.tabbg',$domain); @@ -2394,12 +2543,39 @@ $upperleft $realm  -
+
ENDBODY } ############################################### +=pod + +=item get_users_function + +Used by &bodytag to determine the current users primary role. +Returns either 'student','coordinator','admin', or 'author'. + +=cut + +############################################### +sub get_users_function { + my $function = 'student'; + if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { + $function='coordinator'; + } + if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { + $function='admin'; + } + if (($ENV{'request.role'}=~/^(au|ca)/) || + ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) { + $function='author'; + } + return $function; +} + +############################################### + sub get_posted_cgi { my $r=shift; @@ -2534,11 +2710,16 @@ sub no_cache { } sub content_type { - my ($r,$type,$charset) = @_; - unless ($charset) { - $charset=&Apache::lonlocal::current_encoding; - } - $r->content_type($type.($charset?'; charset='.$charset:'')); + my ($r,$type,$charset) = @_; + unless ($charset) { + $charset=&Apache::lonlocal::current_encoding; + } + if ($charset) { $type.='; charset='.$charset; } + if ($r) { + $r->content_type($type); + } else { + print("Content-type: $type\n\n"); + } } =pod @@ -3119,7 +3300,7 @@ plotted in. If undefined, default value =item $Xlabels: Array ref containing the labels to be used for the X-axis. =item $Ydata: Array ref containing Array refs. -Each of the contained arrays will be plotted as a seperate curve. +Each of the contained arrays will be plotted as a separate curve. =item %Values: hash indicating or overriding any default values which are passed to graph.png.