--- loncom/interface/lonhtmlcommon.pm 2007/10/04 01:16:58 1.166 +++ loncom/interface/lonhtmlcommon.pm 2008/12/03 19:34:01 1.191 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.166 2007/10/04 01:16:58 banghart Exp $ +# $Id: lonhtmlcommon.pm,v 1.191 2008/12/03 19:34:01 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,6 +62,60 @@ use Apache::lonlocal; use Apache::lonnet; use LONCAPA; + +############################################## +############################################## + +=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 < + function mathedit(textarea, doc) { + targetEntry = textarea; + targetDoc = doc; + newwin = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable"); + } + + +ENDDRAGMATHJS +} + + ############################################## ############################################## @@ -311,6 +365,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 +374,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) { + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now); if (($defhour) || ($defmin) || ($defsec)) { - ($sec,$min,$hour,$mday,$month,$year,undef,undef,undef) = - localtime(time); - $year += 1900; $sec=($defsec?$defsec:0); $min=($defmin?$defmin:0); $hour=($defhour?$defhour:0); @@ -463,16 +515,19 @@ ENDJS $cal_link = qq{}; } # + my $tzone = ' '.$tzname.' '; if ($no_hh_mm_ss) { $result .= &mt('[_1] [_2] [_3] ', - $monthselector,$dayselector,$yearselector); + $monthselector,$dayselector,$yearselector). + $tzone; if (!$nolink) { $result .= &mt('[_1]Select Date[_2]',$cal_link,''); } } else { $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ', $monthselector,$dayselector,$yearselector, - $hourselector,$minuteselector,$secondselector); + $hourselector,$minuteselector,$secondselector). + $tzone; if (!$nolink) { $result .= &mt('[_1]Select Date[_2]',$cal_link,''); } @@ -481,13 +536,29 @@ ENDJS return $result; } +sub get_timedates { + my ($epoch) = @_; + my $dt = DateTime->from_epoch(epoch => $epoch) + ->set_time_zone(&Apache::lonlocal::gettimezone()); + my $tzname = $dt->time_zone_short_name(); + my $sec = $dt->second; + my $min = $dt->minute; + my $hour = $dt->hour; + my $mday = $dt->day; + my $month = $dt->month; + if ($month) { + $month --; + } + my $year = $dt->year; + return ($tzname,$sec,$min,$hour,$mday,$month,$year); +} sub build_url { my ($base, $fields)=@_; my $url; $url = $base.'?'; - foreach my $key(keys(%$fields)) { - $url.=$key.'='.$$fields{$key}.'&'; + foreach my $key (keys(%$fields)) { + $url.=&escape($key).'='.&escape($$fields{$key}).'&'; } $url =~ s/&$//; return $url; @@ -562,20 +633,33 @@ sub get_date_from_form { if (defined($env{'form.'.$dname.'_month'})) { my $tmpmonth = $env{'form.'.$dname.'_month'}; if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) { - $month = $tmpmonth - 1; + $month = $tmpmonth; } } if (defined($env{'form.'.$dname.'_year'})) { my $tmpyear = $env{'form.'.$dname.'_year'}; - if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) { - $year = $tmpyear - 1900; + if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) { + $year = $tmpyear; } } - if (($year<70) || ($year>137)) { return undef; } + if (($year<1970) || ($year>2037)) { return undef; } if (defined($sec) && defined($min) && defined($hour) && - defined($day) && defined($month) && defined($year) && - eval('&timelocal($sec,$min,$hour,$day,$month,$year)')) { - return &timelocal($sec,$min,$hour,$day,$month,$year); + defined($day) && defined($month) && defined($year)) { + my $timezone = &Apache::lonlocal::gettimezone(); + my $dt = DateTime->new( year => $year, + month => $month, + day => $day, + hour => $hour, + minute => $min, + second => $sec, + time_zone => $timezone, + ); + my $epoch_time = $dt->epoch; + if ($epoch_time ne '') { + return $epoch_time; + } else { + return undef; + } } else { return undef; } @@ -645,6 +729,8 @@ sub javascript_nothing { ############################################## ############################################## sub javascript_docopen { + my ($mimetype) = @_; + $mimetype ||= 'text/html'; # safari does not understand document.open() and loads "text/html" my $nothing = "''"; my $user_browser; @@ -658,7 +744,7 @@ sub javascript_docopen { if ($user_browser eq 'safari' && $user_os =~ 'mac') { $nothing = "document.clear()"; } else { - $nothing = "document.open('text/html','replace')"; + $nothing = "document.open('$mimetype','replace')"; } return $nothing; } @@ -868,7 +954,7 @@ sub Create_PrgWin { function openpopwin () { popwin=open(\'\',\'popwin\',\'width=400,height=100\');". "popwin.document.writeln(\'".$start_page. - "

$heading<\/h4>". + "

".&mt("$heading")."<\/h4>". "
". '<\\/form>'.$end_page. @@ -887,8 +973,7 @@ sub Create_PrgWin { } if (!$inputname) { $prog_state{'inputname'}=&get_uniq_name(); - &r_print($r,$heading.' '); + &r_print($r,&mt("$heading [_1]",' ')); } else { $prog_state{'inputname'}=$inputname; @@ -1101,46 +1186,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 { @@ -1159,16 +1211,33 @@ 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 { my @fields=@_; unless (&htmlareabrowser()) { return ''; } if (&htmlareablocked()) { return '
'.&enablelink(@fields); } - my $output='
". &disablelink(@fields); @@ -1243,6 +1312,8 @@ returns: nothing 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); # @@ -1250,20 +1321,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'})); @@ -1282,7 +1356,7 @@ returns: nothing $result; } @Crumbs ); - $links .= '->' if ($links ne ''); + $links .= $crumbsymbol if ($links ne ''); if ($last->{'no_mt'}) { $links .= ''.$last->{'text'}.''; } else { @@ -1349,7 +1423,7 @@ returns: nothing # row1 # row2 # row3 ... etc. -# &submit_row(0 +# &submit_row() # &end_pick_box() # # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row, @@ -1411,6 +1485,13 @@ END return $output; } +sub row_headline { + my $output = <<"END"; + +END + return $output; +} + sub row_title { my ($title,$css_title_class,$css_value_class) = @_; $css_title_class ||= 'LC_pick_box_title'; @@ -1419,10 +1500,13 @@ sub row_title { $css_value_class ||= 'LC_pick_box_value'; $css_value_class = 'class="'.$css_value_class.'"'; + if ($title ne '') { + $title .= ':'; + } my $output = <<"ENDONE"; - $title: + $title ENDONE @@ -1489,7 +1573,14 @@ sub course_select_row { my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles, $css_class) = @_; my $output = &row_title($title,$css_class); - $output .= qq| + $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles); + $output .= &row_closure(); + return $output; +} + +sub course_selection { + my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles) = @_; + my $output = qq|