--- loncom/interface/lonhtmlcommon.pm 2006/06/22 23:22:41 1.136 +++ loncom/interface/lonhtmlcommon.pm 2010/01/23 22:23:53 1.182.4.11 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.136 2006/06/22 23:22:41 albertel Exp $ +# $Id: lonhtmlcommon.pm,v 1.182.4.11 2010/01/23 22:23:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,9 +60,104 @@ use Time::Local; use Time::HiRes; use Apache::lonlocal; use Apache::lonnet; -use lib '/home/httpd/lib/perl/'; use LONCAPA; +sub coursepreflink { + my ($text,$category)=@_; + if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) { + return ''.$text.''; + } else { + return ''; + } +} + +sub raw_href_to_link { + my ($message)=@_; + $message=~s/(https?\:\/\/[^\s\'\"]+)(\s|$)/$1<\/tt><\/a>$2/gi; + return $message; +} + +############################################## +############################################## + +=pod + +=item confirm_success + +Successful completion of an operation message + +=cut + +sub confirm_success { + my ($message,$failure)=@_; + if ($failure) { + return ''."\n" + .''.&mt('Error').' '."\n" + .$message."\n" + .''."\n"; + } else { + return ''."\n" + .''.&mt('OK').' '."\n" + .$message."\n" + .''."\n"; + } +} + +############################################## +############################################## + +=pod + +=item dragmath_button + +Creates a button that launches a dragmath popup-window, in which an +expression can be edited and pasted as LaTeX into a specified textarea. + + textarea - Name of the textarea to edit. + helpicon - If true, show a help icon to the right of the button. + +=cut + +sub dragmath_button { + my ($textarea,$helpicon) = @_; + my $help_text; + if ($helpicon) { + $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor'); + } + my $buttontext=&mt('Edit Math'); + return <$help_text +ENDDRAGMATH +} + +############################################## + +=pod + +=item dragmath_js + +Javascript used to open pop-up window containing dragmath applet which +can be used to paste LaTeX into a textarea. + +=cut + +sub dragmath_js { + my ($popup) = @_; + return < + // + + +ENDDRAGMATHJS +} + + ############################################## ############################################## @@ -78,7 +173,7 @@ use LONCAPA; sub authorbombs { my $url=shift; $url=&Apache::lonnet::declutter($url); - my ($udom,$uname)=($url=~/^(\w+)\/(\w+)\//); + my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/}); my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom); foreach (keys %bombs) { if ($_=~/^$udom\/$uname\//) { @@ -141,6 +236,10 @@ sub select_recent { foreach my $value (sort(keys(%recent))) { unless ($value =~/^error\:/) { my $escaped = &Apache::loncommon::escape_url($value); + &Apache::loncommon::inhibit_menu_check(\$escaped); + if ($area eq 'residx') { + next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value))); + } $return.="\n'; @@ -231,7 +330,7 @@ sub checkbox { $Str .= 'value="'.$value.'"'; } if ($checked) { - $Str .= ' checked="1"'; + $Str .= ' checked="checked"'; } $Str .= ' />'; return $Str; @@ -253,7 +352,7 @@ sub radio { $Str .= 'value="'.$value.'"'; } if ($checked eq $value) { - $Str .= ' checked="1"'; + $Str .= ' checked="checked"'; } $Str .= ' />'; return $Str; @@ -311,6 +410,7 @@ The method used to restrict user input w sub date_setter { my ($formname,$dname,$currentvalue,$special,$includeempty,$state, $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_; + my $now = time; my $wasdefined=1; if (! defined($state) || $state ne 'disabled') { $state = ''; @@ -319,28 +419,25 @@ sub date_setter { $no_hh_mm_ss = 0; } if ($currentvalue eq 'now') { - $currentvalue=time; + $currentvalue = $now; } if ((!defined($currentvalue)) || ($currentvalue eq '')) { $wasdefined=0; if ($includeempty) { $currentvalue = 0; } else { - $currentvalue = time; + $currentvalue = $now; } } # other potentially useful values: wkday,yrday,is_daylight_savings + my $tzname; my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','',''); if ($currentvalue) { - ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = - localtime($currentvalue); - $year += 1900; + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); } unless ($wasdefined) { if (($defhour) || ($defmin) || ($defsec)) { - ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = - localtime(time); - $year += 1900; + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now); $sec=($defsec?$defsec:0); $min=($defmin?$defmin:0); $hour=($defhour?$defhour:0); @@ -353,6 +450,7 @@ sub date_setter { my $result = "\n\n"; $result .= < +// ENDJS $result .= ' '; @@ -424,23 +523,23 @@ ENDJS unshift(@Months,'If you can read this an error occurred'); if ($includeempty) { $monthselector.=""; } for(my $m = 1;$m <=$#Months;$m++) { - $monthselector .= qq{ '."\n"; - $Str .= ''."\n"; - $Str .= ''."\n"; + foreach my $type (['Active', &mt('Currently Has Access')], + ['Future', &mt('Will Have Future Access')], + ['Expired', &mt('Previously Had Access')], + ['Any', &mt('Any Access Status')]) { + my ($name,$label) = @$type; + $Str .= '
'); + &r_print($r,''); } else { $prog_state{'formname'}=$formname; } if (!$inputname) { $prog_state{'inputname'}=&get_uniq_name(); - &r_print($r,$heading.' '); + &r_print($r,&mt("$heading [_1]",' ')); } else { $prog_state{'inputname'}=$inputname; @@ -894,10 +1043,14 @@ sub Create_PrgWin { # update progress sub Update_PrgWin { my ($r,$prog_state,$displayString)=@_; - &r_print($r,''); + $displayString.'";'."\n". + '// ]]>'."\n". + ''); $$prog_state{'laststart'}=&Time::HiRes::time(); } @@ -950,11 +1103,15 @@ sub Increment_PrgWin { if ($user_browser eq 'explorer' && $user_os =~ 'mac') { $lasttime = ''; } - &r_print($r,''); + ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'."\n". + '// ]]>'."\n". + ''); $$prog_state{'laststart'}=&Time::HiRes::time(); } @@ -962,7 +1119,11 @@ sub Increment_PrgWin { sub Close_PrgWin { my ($r,$prog_state)=@_; if ($$prog_state{'type'} eq 'popup') { - &r_print($r,''."\n"); + &r_print($r,''."\n"); } elsif ($$prog_state{'type'} eq 'inline') { &Update_PrgWin($r,$prog_state,&mt('Done')); } @@ -993,7 +1154,7 @@ sub crumbs { my $output=''; unless ($noformat) { $output.='
'; } $output.=''.$prefix.'/'; - if ($env{'user.adv'}) { + if (($env{'user.adv'}) || ($env{'user.author'})) { my $path=$prefix.'/'; foreach my $dir (split('/',$uri)) { if (! $dir) { next; } @@ -1005,18 +1166,23 @@ sub crumbs { } } else { $path.='/'; + } + my $href_path = &HTML::Entities::encode($path,'<>&"'); + &Apache::loncommon::inhibit_menu_check(\$href_path); + if ($form) { + my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();'; + $output.=qq{
$dir/}; + } else { + $output.=qq{$dir/}; } - my $linkpath = &Apache::loncommon::escape_single($path); - if ($form) { - $linkpath= - qq{javascript:$form.action='$linkpath';$form.submit();}; - } - $output.=qq{$dir/}; } } else { - $output.=$uri; + foreach my $dir (split('/',$uri)) { + if (! $dir) { next; } + $output.=$dir.'/'; + } } - unless ($uri=~/\/$/) { $output=~s/\/$//; } + if ($uri !~ m|/$|) { $output=~s|/$||; } return $output.''.($noformat?'':'
'); } @@ -1025,24 +1191,32 @@ sub crumbs { sub spellheader { my $start_page= &Apache::loncommon::start_page('Speller Suggestions',undef, - {'only_body' => 1, - 'js_ready' => 1, - 'bgcolor' => '#DDDDDD',}); + {'only_body' => 1, + 'js_ready' => 1, + 'bgcolor' => '#DDDDDD', + 'add_entries' => { + 'onload' => + 'document.forms.spellcheckform.submit()', + } + }); my $end_page= &Apache::loncommon::end_page({'js_ready' => 1}); my $nothing=&javascript_nothing(); return (< + ENDCHECK } @@ -1053,7 +1227,7 @@ sub spelllink { my ($form,$field)=@_; my $linktext=&mt('Check Spelling'); return (<$linktext +$linktext ENDLINK } @@ -1076,45 +1250,13 @@ ENDLINK } sub htmlareaheaders { - if (&htmlareablocked()) { return ''; } - unless (&htmlareabrowser()) { return ''; } - my $lang='en'; - if (&mt('htmlarea_lang') ne 'htmlarea_lang') { - $lang=&mt('htmlarea_lang'); - } + return if (&htmlareablocked()); + return if (!&htmlareabrowser()); return (< -_editor_url='/htmlarea/'; -_editor_lang='$lang'; - - + ENDHEADERS } -# ------------------------------------------------- Activate additional buttons - -sub htmlareaaddbuttons { - if (&htmlareablocked()) { return ''; } - unless (&htmlareabrowser()) { return ''; } - return (<\$','\$ '); - } - ); - config.registerButton('ed_math_eqn','LaTeX Equation', - '/htmlarea/images/ed_math_eqn.gif',false, - function(editor,id) { - editor.surroundHTML( - ' \\n
\\\\[','\\\\]
\\n '); - } - ); - config.toolbar.push(['ed_math','ed_math_eqn']); -ENDADDBUTTON -} - # ----------------------------------------------------------------- Preferences sub disablelink { @@ -1133,6 +1275,15 @@ sub enablelink { return ''.&mt('Enable WYSIWYG Editor').''; } +# ------------------------------------------------- lang to use in html editor +sub htmlarea_lang { + my $lang='en'; + if (&mt('htmlarea_lang') ne 'htmlarea_lang') { + $lang=&mt('htmlarea_lang'); + } + return $lang; +} + # ----------------------------------------- Script to activate only some fields sub htmlareaselectactive { @@ -1140,11 +1291,22 @@ sub htmlareaselectactive { unless (&htmlareabrowser()) { return ''; } if (&htmlareablocked()) { return '
'.&enablelink(@fields); } my $output='
". + '// '."\n". + '
'. &disablelink(@fields); return $output; } @@ -1178,13 +1340,11 @@ A link to help for the component will be All inputs can be undef without problems. -Inputs: $color (the background color of the table returned), - $component (the large text on the right side of the table), +Inputs: $component (the large text on the right side of the table), $component_help - $function (role to get colors from) - $domain (domian of role) $menulink (boolean, controls whether to include a link to /adm/menu) - + $helplink (if 'nohelp' don't include the orange help link) + $css_class (optional name for the class to apply to the table for CSS) Returns a string containing breadcrumbs for the current page. =item clear_breadcrumbs @@ -1197,7 +1357,8 @@ Pushes a breadcrumb on the stack of crum input: $breadcrumb, a hash reference. The keys 'href','title', and 'text' are required. If present the keys 'faq' and 'bug' will be used to provide -links to the FAQ and bug sites. +links to the FAQ and bug sites. If the key 'no_mt' is present the 'title' +and 'text' values won't be sent through &mt() returns: nothing @@ -1209,14 +1370,17 @@ returns: nothing my @Crumbs; sub breadcrumbs { - my ($component,$component_help,$menulink,$helplink) = @_; + my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt) = @_; # - my $Str = "\n".' - + - +ENDTWO + if (!$no_separator) { + $output .= <<"ENDTWO"; - ENDTWO + } return $output; } +} # End: row_count block for pick_box + + sub role_select_row { - my ($roles,$col_width,$tablecolor,$title) = @_; + my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_; + my $crstype = 'Course'; + if ($cdom ne '' && $cnum ne '') { + $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum); + } my $output; if (defined($title)) { - $output = &row_title($col_width,$tablecolor,$title); + $output = &row_title($title,$css_class); } - $output .= qq| \n|; + $output .= qq| \n|; if (defined($title)) { $output .= &row_closure(); } @@ -1442,11 +1654,19 @@ sub role_select_row { } sub course_select_row { - my ($col_width,$tablecolor,$title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles) = @_; - my $output = &row_title($col_width,$tablecolor,$title); - $output .= "
'; + $css_class ||= 'LC_breadcrumbs'; + my $Str = "\n".''; # if (defined($component)) { - $Str .= ''; + $Str .= ''; } $Str .= '
'; # # Make the faq and bug data cascade my $faq = ''; my $bug = ''; my $help=''; + # Crumb Symbol + my $crumbsymbol = '» '; # The last breadcrumb does not have a link, so handle it separately. my $last = pop(@Crumbs); # @@ -1224,20 +1388,23 @@ returns: nothing if (!defined($menulink)) { $menulink=1; } if ($menulink) { my $description = 'Menu'; + my $no_mt_descr = 0; if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') { $description = $env{'course.'.$env{'request.course.id'}.'.description'}; + $no_mt_descr = 1; } unshift(@Crumbs,{ href =>'/adm/menu', title =>'Go to main menu', target =>'_top', text =>$description, + no_mt =>$no_mt_descr, }); } my $links .= - join('->', + join($crumbsymbol, map { $faq = $_->{'faq'} if (exists($_->{'faq'})); $bug = $_->{'bug'} if (exists($_->{'bug'})); @@ -1246,13 +1413,22 @@ returns: nothing if (defined($_->{'target'}) && $_->{'target'} ne '') { $result .= 'target="'.$_->{'target'}.'" '; } - $result .='title="'.&mt($_->{'title'}).'">'. - &mt($_->{'text'}).''; + if ($_->{'no_mt'}) { + $result .='title="'.$_->{'title'}.'">'. + $_->{'text'}.''; + } else { + $result .='title="'.&mt($_->{'title'}).'">'. + &mt($_->{'text'}).''; + } $result; } @Crumbs ); - $links .= '->' if ($links ne ''); - $links .= ''.&mt($last->{'text'}).''; + $links .= $crumbsymbol if ($links ne ''); + if ($last->{'no_mt'}) { + $links .= ''.$last->{'text'}.''; + } else { + $links .= ''.&mt($last->{'text'}).''; + } # my $icons = ''; $faq = $last->{'faq'} if (exists($last->{'faq'})); @@ -1265,20 +1441,25 @@ returns: nothing # if ($bug ne '') { # $icons .= &Apache::loncommon::help_open_bug($bug); # } - if ($helplink ne 'nohelp') { - $icons .= &Apache::loncommon::help_open_menu(undef,$component, + if ($faq ne '' || $component_help ne '' || $bug ne '') { + $icons .= &Apache::loncommon::help_open_menu($component, $component_help, - undef,$faq,$bug); + $faq,$bug); } - if ($icons ne '') { - $Str .= $icons.' '; - } # $Str .= $links.''. - &mt($component).''; + if ($no_mt) { + $Str .= $component; + } else { + $Str .= &mt($component); + } + if ($icons ne '') { + $Str .= ' '.$icons; + } + $Str .= '
'."\n"; # @@ -1313,8 +1494,8 @@ returns: nothing # row1 # row2 # row3 ... etc. -# &submit_row(0 -# &end_pickbox() +# &submit_row() +# &end_pick_box() # # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row, # &status_select_row and &email_default_row @@ -1355,86 +1536,117 @@ returns: nothing # routines, but can also be called directly to start and end rows which have # needs that are not accommodated by the *_select_row() routines. +{ # Start: row_count block for pick_box +my @row_count; + sub start_pick_box { - my ($table_width) = @_; + my ($css_class) = @_; + if (defined($css_class)) { + $css_class = 'class="'.$css_class.'"'; + } else { + $css_class= 'class="LC_pick_box"'; + } + unshift(@row_count,0); my $output = <<"END"; - - - - -
- - - - -
- +
END return $output; } sub end_pick_box { + shift(@row_count); my $output = <<"END";
-
-
+END + return $output; +} + +sub row_headline { + my $output = <<"END"; +
END return $output; } sub row_title { - my ($col_width,$tablecolor,$title) = @_; + my ($title,$css_title_class,$css_value_class) = @_; + $row_count[0]++; + my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row'; + $css_title_class ||= 'LC_pick_box_title'; + $css_title_class = 'class="'.$css_title_class.'"'; + + $css_value_class ||= 'LC_pick_box_value'; + + if ($title ne '') { + $title .= ':'; + } my $output = <<"ENDONE"; -
- - - - -
$title: -
+
+ $title - - + -
ENDONE return $output; } sub row_closure { + my ($no_separator) =@_; my $output = <<"ENDTWO"; -
-
+
- \n|; foreach my $role (@$roles) { my $plrole; if ($role eq 'ow') { $plrole = &mt('Course Owner'); + } elsif ($role eq 'cr') { + if ($show_separate_custom) { + if ($cdom ne '' && $cnum ne '') { + my %course_customroles = &course_custom_roles($cdom,$cnum); + foreach my $crrole (sort(keys(%course_customroles))) { + my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|); + $output .= ' '; + } + } + } else { + $plrole = &mt('Custom Role'); + } } else { - $plrole=&Apache::lonnet::plaintext($role); + $plrole=&Apache::lonnet::plaintext($role,$crstype); + } + if (($role ne 'cr') || (!$show_separate_custom)) { + $output .= ' '; } - $output .= ' '; } - $output .= qq| - \n"; - $output .= qq| - |; + + my ($allcrs,$pickspec); + if ($crstype eq 'Community') { + $allcrs = &mt('All communities'); + $pickspec = &mt('Pick specific communities:'); + } else { + $allcrs = &mt('All courses'); + $pickspec = &mt('Pick specific course(s):'); + } + my $courseform=''.&Apache::loncommon::selectcourse_link - ($formname,'pickcourse','pickdomain','coursedesc','',1).''; - $output .= ''.&mt('All courses').'
'; + ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).''; + $output .= ''.$allcrs.'
'; if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { @@ -1518,24 +1749,22 @@ sub course_select_row { $output .= '

'; } } - $output .= ''.&mt('Pick specific course(s):').' '.$courseform.'  selected.
'."\n"; - $output .= &row_closure(); + $output .= ''.$pickspec.' '.$courseform.'  selected.
'."\n"; return $output; } sub status_select_row { - my ($types,$col_width,$tablecolor,$title) = @_; + my ($types,$title,$css_class) = @_; my $output; if (defined($title)) { - $output = &row_title($col_width,$tablecolor,$title); + $output = &row_title($title,$css_class,'LC_pick_box_select'); } - $output .= qq| - \n|; foreach my $status_type (sort(keys(%{$types}))) { $output .= ' '; } - $output .= qq| - \n|; + $output .= qq| \n|; if (defined($title)) { $output .= &row_closure(); } @@ -1543,18 +1772,17 @@ sub status_select_row { } sub email_default_row { - my ($authtypes,$col_width,$tablecolor,$title,$descrip) = @_; - my $output = &row_title($col_width,$tablecolor,$title); - my @rowcols = ('#eeeeee','#dddddd'); - $output .= ' '.$descrip; - $output .= &start_pick_box(''); - $output .= ' - '.&mt('Authentication Method').''.&mt('Username -> e-mail conversion').' - '."\n"; + my ($authtypes,$title,$descrip,$css_class) = @_; + my $output = &row_title($title,$css_class); + $output .= $descrip. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('Authentication Method').''. + ''.&mt('Username -> e-mail conversion').''."\n". + &Apache::loncommon::end_data_table_header_row(); my $rownum = 0; foreach my $auth (sort(keys(%{$authtypes}))) { my ($userentry,$size); - my $rowiter = $rownum%2; if ($auth =~ /^krb/) { $userentry = ''; $size = 25; @@ -1562,29 +1790,66 @@ sub email_default_row { $userentry = 'username@'; $size = 15; } - $output .= ' '.$$authtypes{$auth}.''.$userentry.''; - $rownum ++; + $output .= &Apache::loncommon::start_data_table_row(). + ' '.$$authtypes{$auth}.''. + ''.$userentry. + ''. + &Apache::loncommon::end_data_table_row(); } - $output .= &end_pick_box(); - $output .= "
\n"; + $output .= &Apache::loncommon::end_data_table(); $output .= &row_closure(); return $output; } sub submit_row { - my ($col_width,$tablecolor,$title,$cmd,$submit_text) = @_; - my $output = &row_title($col_width,$tablecolor,$title); + my ($title,$cmd,$submit_text,$css_class) = @_; + my $output = &row_title($title,$css_class,'LC_pick_box_submit'); $output .= qq| -
 

- \n|; + \n|; return $output; } +sub course_custom_roles { + my ($cdom,$cnum) = @_; + my %returnhash=(); + my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum); + foreach my $person (sort(keys(%coursepersonnel))) { + my ($role) = ($person =~ /^([^:]+):/); + my ($end,$start) = split(/:/,$coursepersonnel{$person}); + if ($end == -1 && $start == -1) { + next; + } + if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) { + $returnhash{$role} ++; + } + } + return %returnhash; +} + + +############################################## +############################################## + +# topic_bar +# +# Generates a div containing a numbered (static image) followed by a title +# with a background color defined in the corresponding CSS: LC_topic_bar +# +sub topic_bar { + my ($imgnum,$title) = @_; + return ' +
+ '.&mt('Step [_1]',$imgnum).
+              ' '.$title.' +
+'; +} + ############################################## ############################################## @@ -1717,72 +1982,74 @@ sub set_form_elements { $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g; $values{$name}[$i] =~ s/"/\\"/g; } - if ($$elements{$name} eq 'text') { + if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) { my $numvalues = @{$values{$name}}; if ($numvalues > 1) { my $valuestring = join('","',@{$values{$name}}); $output .= qq| var textvalues = new Array ("$valuestring"); - var total = courseForm.$name.length; + var total = courseForm.elements['$name'].length; if (total > $numvalues) { total = $numvalues; } for (var i=0; i= 0) { + return true; + } + return false; + } +} +END + return $scripttag; +} + + + 1; __END__