File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.253.2.6: download - view: text, annotated - select for diffs
Mon Nov 29 04:40:12 2010 UTC (13 years, 6 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3
  - Course timezone specified when creating a new Concept Test.

    1: # The LearningOnline Network with CAPA
    2: # a pile of common html routines
    3: #
    4: # $Id: lonhtmlcommon.pm,v 1.253.2.6 2010/11/29 04:40:12 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ######################################################################
   29: ######################################################################
   30: 
   31: =pod
   32: 
   33: =head1 NAME
   34: 
   35: Apache::lonhtmlcommon - routines to do common html things
   36: 
   37: =head1 SYNOPSIS
   38: 
   39: Referenced by other mod_perl Apache modules.
   40: 
   41: =head1 INTRODUCTION
   42: 
   43: lonhtmlcommon is a collection of subroutines used to present information
   44: in a consistent html format, or provide other functionality related to
   45: html.
   46: 
   47: =head2 General Subroutines
   48: 
   49: =over 4
   50: 
   51: =cut 
   52: 
   53: ######################################################################
   54: ######################################################################
   55: 
   56: package Apache::lonhtmlcommon;
   57: 
   58: use strict;
   59: use Time::Local;
   60: use Time::HiRes;
   61: use Apache::lonlocal;
   62: use Apache::lonnet;
   63: use LONCAPA;
   64: 
   65: 
   66: sub coursepreflink {
   67:    my ($text,$category)=@_;
   68:    if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
   69:       return '<a href="/adm/courseprefs?phase=display&actions='.$category.'">'.$text.'</a>';
   70:    } else {
   71:       return '';
   72:    }
   73: }
   74: 
   75: sub raw_href_to_link {
   76:    my ($message)=@_;
   77:    $message=~s/(https?\:\/\/[^\s\'\"]+)(\s|$)/<a href="$1"><tt>$1<\/tt><\/a>$2/gi;
   78:    return $message;
   79: }
   80: 
   81: ##############################################
   82: ##############################################
   83: 
   84: =pod
   85: 
   86: =item confirm_success
   87: 
   88: Successful completion of an operation message
   89: 
   90: =cut
   91: 
   92: sub confirm_success {
   93:    my ($message,$failure)=@_;
   94:    if ($failure) {
   95:       return '<span class="LC_error">'."\n"
   96:             .'<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.&mt('Error').'" /> '."\n"
   97:             .$message."\n"
   98:             .'</span>'."\n";
   99:    } else {
  100:       return '<span class="LC_success">'."\n"
  101:             .'<img src="/adm/lonIcons/navmap.correct.gif" alt="'.&mt('OK').'" /> '."\n"
  102:             .$message."\n"
  103:             .'</span>'."\n";
  104:    }
  105: }
  106: 
  107: ##############################################
  108: ##############################################
  109: 
  110: =pod
  111: 
  112: =item dragmath_button
  113: 
  114: Creates a button that launches a dragmath popup-window, in which an 
  115: expression can be edited and pasted as LaTeX into a specified textarea. 
  116: 
  117:   textarea - Name of the textarea to edit.
  118:   helpicon - If true, show a help icon to the right of the button.
  119: 
  120: =cut
  121: 
  122: sub dragmath_button {
  123:     my ($textarea,$helpicon) = @_;
  124:     my $help_text; 
  125:     if ($helpicon) {
  126:         $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor');
  127:     }
  128:     my $buttontext=&mt('Edit Math');
  129:     return <<ENDDRAGMATH;
  130:                 <input type="button" value="$buttontext" onclick="javascript:mathedit('$textarea',document)" />$help_text
  131: ENDDRAGMATH
  132: }
  133: 
  134: ##############################################
  135: 
  136: =pod
  137: 
  138: =item dragmath_js
  139: 
  140: Javascript used to open pop-up window containing dragmath applet which 
  141: can be used to paste LaTeX into a textarea.
  142:  
  143: =cut
  144: 
  145: sub dragmath_js {
  146:     my ($popup) = @_;
  147:     return <<ENDDRAGMATHJS;
  148:                 <script type="text/javascript">
  149:                 // <![CDATA[
  150:                   function mathedit(textarea, doc) {
  151:                      targetEntry = textarea;
  152:                      targetDoc   = doc;
  153:                      newwin  = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable");
  154:                   }
  155:                 // ]]>
  156:                 </script>
  157: 
  158: ENDDRAGMATHJS
  159: }
  160: 
  161: 
  162: ##############################################
  163: ##############################################
  164: 
  165: =pod
  166: 
  167: =item authorbombs
  168: 
  169: =cut
  170: 
  171: ##############################################
  172: ##############################################
  173: 
  174: sub authorbombs {
  175:     my $url=shift;
  176:     $url=&Apache::lonnet::declutter($url);
  177:     my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
  178:     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
  179:     foreach my $bomb (keys(%bombs)) {
  180: 	if ($bomb =~ /^$udom\/$uname\//) {
  181: 	    return '<a href="/adm/bombs/'.$url.
  182: 		'"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" alt="'.&mt('Bomb').'" border="0" /></a>'.
  183: 		&Apache::loncommon::help_open_topic('About_Bombs');
  184: 	}
  185:     }
  186:     return '';
  187: }
  188: 
  189: ##############################################
  190: ##############################################
  191: 
  192: sub recent_filename {
  193:     my $area=shift;
  194:     return 'nohist_recent_'.&escape($area);
  195: }
  196: 
  197: sub store_recent {
  198:     my ($area,$name,$value,$freeze)=@_;
  199:     my $file=&recent_filename($area);
  200:     my %recent=&Apache::lonnet::dump($file);
  201:     if (scalar(keys(%recent))>20) {
  202: # remove oldest value
  203: 	my $oldest=time();
  204: 	my $delkey='';
  205: 	foreach my $item (keys(%recent)) {
  206: 	    my $thistime=(split(/\&/,$recent{$item}))[0];
  207: 	    if (($thistime ne "always_include") && ($thistime<$oldest)) {
  208: 		$oldest=$thistime;
  209: 		$delkey=$item;
  210: 	    }
  211: 	}
  212: 	&Apache::lonnet::del($file,[$delkey]);
  213:     }
  214: # store new value
  215:     my $timestamp;
  216:     if ($freeze) {
  217:         $timestamp = "always_include";
  218:     } else {
  219:         $timestamp = time();
  220:     }   
  221:     &Apache::lonnet::put($file,{ $name => 
  222: 				 $timestamp.'&'.&escape($value) });
  223: }
  224: 
  225: sub remove_recent {
  226:     my ($area,$names)=@_;
  227:     my $file=&recent_filename($area);
  228:     return &Apache::lonnet::del($file,$names);
  229: }
  230: 
  231: sub select_recent {
  232:     my ($area,$fieldname,$event)=@_;
  233:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  234:     my $return="\n<select name='$fieldname'".
  235: 	($event?" onchange='$event'":'').
  236: 	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
  237:     foreach my $value (sort(keys(%recent))) {
  238: 	unless ($value =~/^error\:/) {
  239: 	    my $escaped = &Apache::loncommon::escape_url($value);
  240: 	    &Apache::loncommon::inhibit_menu_check(\$escaped);
  241:             if ($area eq 'residx') {
  242:                 next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
  243:             }
  244: 	    $return.="\n<option value='$escaped'>".
  245: 		&unescape((split(/\&/,$recent{$value}))[1]).
  246: 		'</option>';
  247: 	}
  248:     }
  249:     $return.="\n</select>\n";
  250:     return $return;
  251: }
  252: 
  253: sub get_recent {
  254:     my ($area, $n) = @_;
  255:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  256: 
  257: # Create hash with key as time and recent as value
  258: # Begin filling return_hash with any 'always_include' option
  259:     my %time_hash = ();
  260:     my %return_hash = ();
  261:     foreach my $item (keys(%recent)) {
  262:         my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
  263:         if ($thistime eq 'always_include') {
  264:             $return_hash{$item} = &unescape($thisvalue);
  265:             $n--;
  266:         } else {
  267:             $time_hash{$thistime} = $item;
  268:         }
  269:     }
  270: 
  271: # Sort by decreasing time and return key value pairs
  272:     my $idx = 1;
  273:     foreach my $item (reverse(sort(keys(%time_hash)))) {
  274:        $return_hash{$time_hash{$item}} =
  275:                   &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
  276:        if ($n && ($idx++ >= $n)) {last;}
  277:     }
  278: 
  279:     return %return_hash;
  280: }
  281: 
  282: sub get_recent_frozen {
  283:     my ($area) = @_;
  284:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
  285: 
  286: # Create hash with all 'frozen' items
  287:     my %return_hash = ();
  288:     foreach my $item (keys(%recent)) {
  289:         my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
  290:         if ($thistime eq 'always_include') {
  291:             $return_hash{$item} = &unescape($thisvalue);
  292:         }
  293:     }
  294:     return %return_hash;
  295: }
  296: 
  297: 
  298: 
  299: =pod
  300: 
  301: =item textbox
  302: 
  303: =cut
  304: 
  305: ##############################################
  306: ##############################################
  307: sub textbox {
  308:     my ($name,$value,$size,$special) = @_;
  309:     $size = 40 if (! defined($size));
  310:     $value = &HTML::Entities::encode($value,'<>&"');
  311:     my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
  312:         'value="'.$value.'" '.$special.' />';
  313:     return $Str;
  314: }
  315: 
  316: ##############################################
  317: ##############################################
  318: 
  319: =pod
  320: 
  321: =item checkbox
  322: 
  323: =cut
  324: 
  325: ##############################################
  326: ##############################################
  327: sub checkbox {
  328:     my ($name,$checked,$value) = @_;
  329:     my $Str = '<input type="checkbox" name="'.$name.'" ';
  330:     if (defined($value)) {
  331:         $Str .= 'value="'.$value.'"';
  332:     } 
  333:     if ($checked) {
  334:         $Str .= ' checked="checked"';
  335:     }
  336:     $Str .= ' />';
  337:     return $Str;
  338: }
  339: 
  340: 
  341: =pod
  342: 
  343: =item radiobutton
  344: 
  345: =cut
  346: 
  347: ##############################################
  348: ##############################################
  349: sub radio {
  350:     my ($name,$checked,$value) = @_;
  351:     my $Str = '<input type="radio" name="'.$name.'" ';
  352:     if (defined($value)) {
  353:         $Str .= 'value="'.$value.'"';
  354:     } 
  355:     if ($checked eq $value) {
  356:         $Str .= ' checked="checked"';
  357:     }
  358:     $Str .= ' />';
  359:     return $Str;
  360: }
  361: 
  362: ##############################################
  363: ##############################################
  364: 
  365: =pod
  366: 
  367: =item &date_setter
  368: 
  369: &date_setter returns html and javascript for a compact date-setting form.
  370: To retrieve values from it, use &get_date_from_form().
  371: 
  372: Inputs
  373: 
  374: =over 4
  375: 
  376: =item $dname 
  377: 
  378: The name to prepend to the form elements.  
  379: The form elements defined will be dname_year, dname_month, dname_day,
  380: dname_hour, dname_min, and dname_sec.
  381: 
  382: =item $currentvalue
  383: 
  384: The current setting for this time parameter.  A unix format time
  385: (time in seconds since the beginning of Jan 1st, 1970, GMT.  
  386: An undefined value is taken to indicate the value is the current time.
  387: Also, to be explicit, a value of 'now' also indicates the current time.
  388: 
  389: =item $special
  390: 
  391: Additional html/javascript to be associated with each element in
  392: the date_setter.  See lonparmset for example usage.
  393: 
  394: =item $includeempty 
  395: 
  396: =item $state
  397: 
  398: Specifies the initial state of the form elements.  Either 'disabled' or empty.
  399: Defaults to empty, which indiciates the form elements are not disabled. 
  400: 
  401: =back
  402: 
  403: Bugs
  404: 
  405: The method used to restrict user input will fail in the year 2400.
  406: 
  407: =cut
  408: 
  409: ##############################################
  410: ##############################################
  411: sub date_setter {
  412:     my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
  413:         $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$hide_timezone) = @_;
  414:     my $now = time;
  415:     my $wasdefined=1;
  416:     if (! defined($state) || $state ne 'disabled') {
  417:         $state = '';
  418:     }
  419:     if (! defined($no_hh_mm_ss)) {
  420:         $no_hh_mm_ss = 0;
  421:     }
  422:     if ($currentvalue eq 'now') {
  423: 	$currentvalue = $now;
  424:     }
  425:     if ((!defined($currentvalue)) || ($currentvalue eq '')) {
  426: 	$wasdefined=0;
  427: 	if ($includeempty) {
  428: 	    $currentvalue = 0;
  429: 	} else {
  430: 	    $currentvalue = $now;
  431: 	}
  432:     }
  433:     # other potentially useful values:     wkday,yrday,is_daylight_savings
  434:     my $tzname;
  435:     my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
  436:     if ($currentvalue) {
  437:         ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); 
  438:     }
  439:     unless ($wasdefined) {
  440:         ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now);
  441: 	if (($defhour) || ($defmin) || ($defsec)) {
  442: 	    $sec=($defsec?$defsec:0);
  443: 	    $min=($defmin?$defmin:0);
  444: 	    $hour=($defhour?$defhour:0);
  445: 	} elsif (!$includeempty) {
  446: 	    $sec=0;
  447: 	    $min=0;
  448: 	    $hour=0;
  449: 	}
  450:     }
  451:     my $result = "\n<!-- $dname date setting form -->\n";
  452:     $result .= <<ENDJS;
  453: <script type="text/javascript">
  454: // <![CDATA[
  455:     function $dname\_checkday() {
  456:         var day   = document.$formname.$dname\_day.value;
  457:         var month = document.$formname.$dname\_month.value;
  458:         var year  = document.$formname.$dname\_year.value;
  459:         var valid = true;
  460:         if (day < 1) {
  461:             document.$formname.$dname\_day.value = 1;
  462:         } 
  463:         if (day > 31) {
  464:             document.$formname.$dname\_day.value = 31;
  465:         }
  466:         if ((month == 1)  || (month == 3)  || (month == 5)  ||
  467:             (month == 7)  || (month == 8)  || (month == 10) ||
  468:             (month == 12)) {
  469:             if (day > 31) {
  470:                 document.$formname.$dname\_day.value = 31;
  471:                 day = 31;
  472:             }
  473:         } else if (month == 2 ) {
  474:             if ((year % 4 == 0) && (year % 100 != 0)) {
  475:                 if (day > 29) {
  476:                     document.$formname.$dname\_day.value = 29;
  477:                 }
  478:             } else if (day > 29) {
  479:                 document.$formname.$dname\_day.value = 28;
  480:             }
  481:         } else if (day > 30) {
  482:             document.$formname.$dname\_day.value = 30;
  483:         }
  484:     }
  485:     
  486:     function $dname\_disable() {
  487:         document.$formname.$dname\_month.disabled=true;
  488:         document.$formname.$dname\_day.disabled=true;
  489:         document.$formname.$dname\_year.disabled=true;
  490:         document.$formname.$dname\_hour.disabled=true;
  491:         document.$formname.$dname\_minute.disabled=true;
  492:         document.$formname.$dname\_second.disabled=true;
  493:     }
  494: 
  495:     function $dname\_enable() {
  496:         document.$formname.$dname\_month.disabled=false;
  497:         document.$formname.$dname\_day.disabled=false;
  498:         document.$formname.$dname\_year.disabled=false;
  499:         document.$formname.$dname\_hour.disabled=false;
  500:         document.$formname.$dname\_minute.disabled=false;
  501:         document.$formname.$dname\_second.disabled=false;        
  502:     }
  503: 
  504:     function $dname\_opencalendar() {
  505:         if (! document.$formname.$dname\_month.disabled) {
  506:             var calwin=window.open(
  507: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
  508: document.$formname.$dname\_month.value+"&year="+
  509: document.$formname.$dname\_year.value,
  510:              "LONCAPAcal",
  511:               "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
  512:         }
  513: 
  514:     }
  515: // ]]>
  516: </script>
  517: ENDJS
  518:     $result .= '  <span class="LC_nobreak">';
  519:     my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
  520:     # Month
  521:     my @Months = qw/January February  March     April   May      June 
  522:                     July    August    September October November December/;
  523:     # Pad @Months with a bogus value to make indexing easier
  524:     unshift(@Months,'If you can read this an error occurred');
  525:     if ($includeempty) { $monthselector.="<option value=''></option>"; }
  526:     for(my $m = 1;$m <=$#Months;$m++) {
  527:         $monthselector .= qq{      <option value="$m"};
  528:         $monthselector .= ' selected="selected"' if ($m-1 eq $month);
  529:         $monthselector .= '> '.&mt($Months[$m]).' </option>'."\n";
  530:     }
  531:     $monthselector.= '  </select>';
  532:     # Day
  533:     my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
  534:     # Year
  535:     my $yearselector = qq{<input type="text" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
  536:     #
  537:     my $hourselector = qq{<select name="$dname\_hour" $special $state >};
  538:     if ($includeempty) { 
  539:         $hourselector.=qq{<option value=''></option>};
  540:     }
  541:     for (my $h = 0;$h<24;$h++) {
  542:         $hourselector .= qq{<option value="$h"};
  543:         $hourselector .= ' selected="selected"' if (defined($hour) && $hour == $h);
  544:         $hourselector .= ">";
  545:         my $timest='';
  546:         if ($h == 0) {
  547:             $timest .= "12 am";
  548:         } elsif($h == 12) {
  549:             $timest .= "12 noon";
  550:         } elsif($h < 12) {
  551:             $timest .= "$h am";
  552:         } else {
  553:             $timest .= $h-12 ." pm";
  554:         }
  555:         $timest=&mt($timest);
  556:         $hourselector .= $timest." </option>\n";
  557:     }
  558:     $hourselector .= "  </select>\n";
  559:     my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
  560:     my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
  561:     my $cal_link;
  562:     if (!$nolink) {
  563:         $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
  564:     }
  565:     #
  566:     my $tzone;
  567:     unless ($hide_timezone) {
  568:         $tzone = ' '.$tzname.' ';
  569:     }
  570:     if ($no_hh_mm_ss) {
  571:         $result .= &mt('[_1] [_2] [_3] ',
  572:                        $monthselector,$dayselector,$yearselector).
  573:                    $tzone;
  574:         if (!$nolink) {
  575:             $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
  576:         }
  577:     } else {
  578:         $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
  579:                       $monthselector,$dayselector,$yearselector,
  580:                       $hourselector,$minuteselector,$secondselector).
  581:                    $tzone;
  582:         if (!$nolink) {
  583:             $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
  584:         }
  585:     }
  586:     $result .= "</span>\n<!-- end $dname date setting form -->\n";
  587:     return $result;
  588: }
  589: 
  590: sub get_timedates {
  591:     my ($epoch) = @_;
  592:     my $dt = DateTime->from_epoch(epoch => $epoch)
  593:                      ->set_time_zone(&Apache::lonlocal::gettimezone());
  594:     my $tzname = $dt->time_zone_short_name();
  595:     my $sec = $dt->second;
  596:     my $min = $dt->minute;
  597:     my $hour = $dt->hour;
  598:     my $mday = $dt->day;
  599:     my $month = $dt->month;
  600:     if ($month) {
  601:         $month --;
  602:     }
  603:     my $year = $dt->year;
  604:     return ($tzname,$sec,$min,$hour,$mday,$month,$year);
  605: }
  606: 
  607: sub build_url {
  608:     my ($base, $fields)=@_;
  609:     my $url;
  610:     $url = $base.'?';
  611:     foreach my $key (keys(%$fields)) {
  612:         $url.=&escape($key).'='.&escape($$fields{$key}).'&amp;';
  613:     }
  614:     $url =~ s/&amp;$//;
  615:     return $url;
  616: }
  617: 
  618: 
  619: ##############################################
  620: ##############################################
  621: 
  622: =pod
  623: 
  624: =item &get_date_from_form
  625: 
  626: get_date_from_form retrieves the date specified in an &date_setter form.
  627: 
  628: Inputs:
  629: 
  630: =over 4
  631: 
  632: =item $dname
  633: 
  634: The name passed to &date_setter, which prefixes the form elements.
  635: 
  636: =item $defaulttime
  637: 
  638: The unix time to use as the default in case of poor inputs.
  639: 
  640: =back
  641: 
  642: Returns: Unix time represented in the form.
  643: 
  644: =cut
  645: 
  646: ##############################################
  647: ##############################################
  648: sub get_date_from_form {
  649:     my ($dname,$timezone) = @_;
  650:     my ($sec,$min,$hour,$day,$month,$year);
  651:     #
  652:     if (defined($env{'form.'.$dname.'_second'})) {
  653:         my $tmpsec = $env{'form.'.$dname.'_second'};
  654:         if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
  655:             $sec = $tmpsec;
  656:         }
  657: 	if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
  658:     } else {
  659:         $sec = 0;
  660:     }
  661:     if (defined($env{'form.'.$dname.'_minute'})) {
  662:         my $tmpmin = $env{'form.'.$dname.'_minute'};
  663:         if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
  664:             $min = $tmpmin;
  665:         }
  666: 	if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
  667:     } else {
  668:         $min = 0;
  669:     }
  670:     if (defined($env{'form.'.$dname.'_hour'})) {
  671:         my $tmphour = $env{'form.'.$dname.'_hour'};
  672:         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
  673:             $hour = $tmphour;
  674:         }
  675:     } else {
  676:         $hour = 0;
  677:     }
  678:     if (defined($env{'form.'.$dname.'_day'})) {
  679:         my $tmpday = $env{'form.'.$dname.'_day'};
  680:         if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
  681:             $day = $tmpday;
  682:         }
  683:     }
  684:     if (defined($env{'form.'.$dname.'_month'})) {
  685:         my $tmpmonth = $env{'form.'.$dname.'_month'};
  686:         if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
  687:             $month = $tmpmonth;
  688:         }
  689:     }
  690:     if (defined($env{'form.'.$dname.'_year'})) {
  691:         my $tmpyear = $env{'form.'.$dname.'_year'};
  692:         if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
  693:             $year = $tmpyear;
  694:         }
  695:     }
  696:     if (($year<1970) || ($year>2037)) { return undef; }
  697:     if (defined($sec) && defined($min)   && defined($hour) &&
  698:         defined($day) && defined($month) && defined($year)) {
  699:         if (defined($timezone)) {
  700:             if (&Apache::lonlocal::gettimezone($timezone) eq 'local') {
  701:                 $timezone = &Apache::lonlocal::gettimezone();
  702:             }
  703:         }
  704:         my $dt = DateTime->new( year   => $year,
  705:                                 month  => $month,
  706:                                 day    => $day,
  707:                                 hour   => $hour,
  708:                                 minute => $min,
  709:                                 second => $sec,
  710:                                 time_zone => $timezone,
  711:                               );
  712:         my $epoch_time  = $dt->epoch;
  713:         if ($epoch_time ne '') {
  714:             return $epoch_time;
  715:         } else {
  716:             return undef;
  717:         }
  718:     } else {
  719:         return undef;
  720:     }
  721: }
  722: 
  723: ##############################################
  724: ##############################################
  725: 
  726: =pod
  727: 
  728: =item &pjump_javascript_definition()
  729: 
  730: Returns javascript defining the 'pjump' function, which opens up a
  731: parameter setting wizard.
  732: 
  733: =cut
  734: 
  735: ##############################################
  736: ##############################################
  737: sub pjump_javascript_definition {
  738:     my $Str = <<END;
  739:     function pjump(type,dis,value,marker,ret,call,hour,min,sec) {
  740:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
  741:                  +"&value="+escape(value)+"&marker="+escape(marker)
  742:                  +"&return="+escape(ret)
  743:                  +"&call="+escape(call)+"&name="+escape(dis)
  744:                  +"&defhour="+escape(hour)+"&defmin="+escape(min)
  745:                  +"&defsec="+escape(sec),"LONCAPAparms",
  746:                  "height=350,width=350,scrollbars=no,menubar=no");
  747:     }
  748: END
  749:     return $Str;
  750: }
  751: 
  752: ##############################################
  753: ##############################################
  754: 
  755: =pod
  756: 
  757: =item &javascript_nothing()
  758: 
  759: Return an appropriate null for the users browser.  This is used
  760: as the first arguement for window.open calls when you want a blank
  761: window that you can then write to.
  762: 
  763: =cut
  764: 
  765: ##############################################
  766: ##############################################
  767: sub javascript_nothing {
  768:     # mozilla and other browsers work with "''", but IE on mac does not.
  769:     my $nothing = "''";
  770:     my $user_browser;
  771:     my $user_os;
  772:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
  773:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
  774:     if (! defined($user_browser) || ! defined($user_os)) {
  775:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  776:                            &Apache::loncommon::decode_user_agent();
  777:     }
  778:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
  779:         $nothing = "'javascript:void(0);'";
  780:     }
  781:     return $nothing;
  782: }
  783: 
  784: ##############################################
  785: ##############################################
  786: sub javascript_docopen {
  787:     my ($mimetype) = @_;
  788:     $mimetype ||= 'text/html';
  789:     # safari does not understand document.open() and loads "text/html"
  790:     my $nothing = "''";
  791:     my $user_browser;
  792:     my $user_os;
  793:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
  794:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
  795:     if (! defined($user_browser) || ! defined($user_os)) {
  796:         (undef,$user_browser,undef,undef,undef,$user_os) = 
  797:                            &Apache::loncommon::decode_user_agent();
  798:     }
  799:     if ($user_browser eq 'safari' && $user_os =~ 'mac') {
  800:         $nothing = "document.clear()";
  801:     } else {
  802: 	$nothing = "document.open('$mimetype','replace')";
  803:     }
  804:     return $nothing;
  805: }
  806: 
  807: 
  808: ##############################################
  809: ##############################################
  810: 
  811: =pod
  812: 
  813: =item &StatusOptions()
  814: 
  815: Returns html for a selection box which allows the user to choose the
  816: enrollment status of students.  The selection box name is 'Status'.
  817: 
  818: Inputs:
  819: 
  820: $status: the currently selected status.  If undefined the value of
  821: $env{'form.Status'} is taken.  If that is undefined, a value of 'Active'
  822: is used.
  823: 
  824: $formname: The name of the form.  If defined the onchange attribute of
  825: the selection box is set to document.$formname.submit().
  826: 
  827: $size: the size (number of lines) of the selection box.
  828: 
  829: $onchange: javascript to use when the value is changed.  Enclosed in 
  830: double quotes, ""s, not single quotes.
  831: 
  832: Returns: a perl string as described.
  833: 
  834: =cut
  835: 
  836: ##############################################
  837: ##############################################
  838: sub StatusOptions {
  839:     my ($status, $formName,$size,$onchange,$mult)=@_;
  840:     $size = 1 if (!defined($size));
  841:     if (! defined($status)) {
  842:         $status = 'Active';
  843:         $status = $env{'form.Status'} if (exists($env{'form.Status'}));
  844:     }
  845: 
  846:     my $Str = '';
  847:     $Str .= '<select name="Status"';
  848:     if (defined($mult)){
  849:         $Str .= ' multiple="multiple" ';
  850:     }
  851:     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
  852:         $Str .= ' onchange="document.'.$formName.'.submit()"';
  853:     }
  854:     if (defined($onchange)) {
  855:         $Str .= ' onchange="'.$onchange.'"';
  856:     }
  857:     $Str .= ' size="'.$size.'" ';
  858:     $Str .= '>'."\n";
  859:     foreach my $type (['Active',  &mt('Currently Has Access')],
  860: 		      ['Future',  &mt('Will Have Future Access')],
  861: 		      ['Expired', &mt('Previously Had Access')],
  862: 		      ['Any',     &mt('Any Access Status')]) {
  863: 	my ($name,$label) = @$type;
  864: 	$Str .= '<option value="'.$name.'" ';
  865: 	if ($status eq $name) {
  866: 	    $Str .= 'selected="selected" ';
  867: 	}
  868: 	$Str .= '>'.$label.'</option>'."\n";
  869:     }
  870: 
  871:     $Str .= '</select>'."\n";
  872: }
  873: 
  874: ########################################################
  875: ########################################################
  876: 
  877: =pod
  878: 
  879: =item Progess Window Handling Routines
  880: 
  881: These routines handle the creation, update, increment, and closure of 
  882: progress windows.  The progress window reports to the user the number
  883: of items completed and an estimate of the time required to complete the rest.
  884: 
  885: =over 4
  886: 
  887: 
  888: =item &Create_PrgWin
  889: 
  890: Writes javascript to the client to open a progress window and returns a
  891: data structure used for bookkeeping.
  892: 
  893: Inputs
  894: 
  895: =over 4
  896: 
  897: =item $r Apache request
  898: 
  899: =item $title The title of the progress window
  900: 
  901: =item $heading A description (usually 1 line) of the process being initiated.
  902: 
  903: =item $number_to_do The total number of items being processed.
  904: 
  905: =item $type Either 'popup' or 'inline' (popup is assumed if nothing is
  906:        specified)
  907: 
  908: =item $width Specify the width in charaters of the input field.
  909: 
  910: =item $formname Only useful in the inline case, if a form already exists, this needs to be used and specfiy the name of the form, otherwise the Progress line will be created in a new form of it's own
  911: 
  912: =item $inputname Only useful in the inline case, if a form and an input of type text exists, use this to specify the name of the input field 
  913: 
  914: =back
  915: 
  916: Returns a hash containing the progress state data structure.
  917: 
  918: 
  919: =item &Update_PrgWin
  920: 
  921: Updates the text in the progress indicator.  Does not increment the count.
  922: See &Increment_PrgWin.
  923: 
  924: Inputs:
  925: 
  926: =over 4
  927: 
  928: =item $r Apache request
  929: 
  930: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
  931: 
  932: =item $displaystring The string to write to the status indicator
  933: 
  934: =back
  935: 
  936: Returns: none
  937: 
  938: 
  939: =item Increment_PrgWin
  940: 
  941: Increment the count of items completed for the progress window by 1.  
  942: 
  943: Inputs:
  944: 
  945: =over 4
  946: 
  947: =item $r Apache request
  948: 
  949: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  950: 
  951: =item $extraInfo A description of the items being iterated over.  Typically
  952: 'student'.
  953: 
  954: =back
  955: 
  956: Returns: none
  957: 
  958: 
  959: =item Close_PrgWin
  960: 
  961: Closes the progress window.
  962: 
  963: Inputs:
  964: 
  965: =over 4 
  966: 
  967: =item $r Apache request
  968: 
  969: =item $prog_state Pointer to the data structure returned by Create_PrgWin
  970: 
  971: =back
  972: 
  973: Returns: none
  974: 
  975: =back
  976: 
  977: =cut
  978: 
  979: ########################################################
  980: ########################################################
  981: 
  982: my $uniq=0;
  983: sub get_uniq_name {
  984:     $uniq++;
  985:     return 'uniquename'.$uniq;
  986: }
  987: 
  988: # Create progress
  989: sub Create_PrgWin {
  990:     my ($r, $title, $heading, $number_to_do,$type,$width,$formname,
  991: 	$inputname)=@_;
  992:     if (!defined($type)) { $type='popup'; }
  993:     if (!defined($width)) { $width=55; }
  994:     my %prog_state;
  995:     $prog_state{'type'}=$type;
  996:     if ($type eq 'popup') {
  997: 	$prog_state{'window'}='popwin';
  998: 	my $start_page =
  999: 	    &Apache::loncommon::start_page($title,undef,
 1000: 					   {'only_body' => 1,
 1001: 					    'bgcolor'   => '#88DDFF',
 1002: 					    'js_ready'  => 1});
 1003: 	my $end_page = &Apache::loncommon::end_page({'js_ready'  => 1});
 1004: 
 1005: 	#the whole function called through timeout is due to issues
 1006: 	#in mozilla Read BUG #2665 if you want to know the whole story
 1007: 	&r_print($r,&Apache::lonhtmlcommon::scripttag(
 1008:         "var popwin;
 1009:          function openpopwin () {
 1010:          popwin=open(\'\',\'popwin\',\'width=400,height=100\');".
 1011:         "popwin.document.writeln(\'".$start_page.
 1012:               "<h4>".&mt("$heading")."<\/h4>".
 1013:               "<form action=\"\" name=\"popremain\" method=\"post\">".
 1014:               '<input type="text" size="'.$width.'" name="remaining" value="'.
 1015: 	      &mt('Starting').'" /><\\/form>'.$end_page.
 1016:               "\');".
 1017:         "popwin.document.close();}".
 1018:         "\nwindow.setTimeout(openpopwin,0)"
 1019:     ));
 1020: 	$prog_state{'formname'}='popremain';
 1021: 	$prog_state{'inputname'}="remaining";
 1022:     } elsif ($type eq 'inline') {
 1023: 	$prog_state{'window'}='window';
 1024: 	if (!$formname) {
 1025: 	    $prog_state{'formname'}=&get_uniq_name();
 1026: 	    &r_print($r,'<form action="" name="'.$prog_state{'formname'}.'">');
 1027: 	} else {
 1028: 	    $prog_state{'formname'}=$formname;
 1029: 	}
 1030: 	if (!$inputname) {
 1031: 	    $prog_state{'inputname'}=&get_uniq_name();
 1032: 	    &r_print($r,&mt("$heading [_1]",' <input type="text" name="'.$prog_state{'inputname'}.'" size="'.$width.'" />'));
 1033: 	} else {
 1034: 	    $prog_state{'inputname'}=$inputname;
 1035: 	    
 1036: 	}
 1037: 	if (!$formname) { &r_print($r,'</form>'); }
 1038: 	&Update_PrgWin($r,\%prog_state,&mt('Starting'));
 1039:     }
 1040: 
 1041:     $prog_state{'done'}=0;
 1042:     $prog_state{'firststart'}=&Time::HiRes::time();
 1043:     $prog_state{'laststart'}=&Time::HiRes::time();
 1044:     $prog_state{'max'}=$number_to_do;
 1045:     
 1046:     return %prog_state;
 1047: }
 1048: 
 1049: # update progress
 1050: sub Update_PrgWin {
 1051:     my ($r,$prog_state,$displayString)=@_;
 1052:     &r_print($r,&Apache::lonhtmlcommon::scripttag(
 1053:         $$prog_state{'window'}.'.document.'.
 1054:         $$prog_state{'formname'}.'.'.
 1055:         $$prog_state{'inputname'}.'.value="'.
 1056:         $displayString.'";'
 1057:     ));
 1058:     $$prog_state{'laststart'}=&Time::HiRes::time();
 1059: }
 1060: 
 1061: # increment progress state
 1062: sub Increment_PrgWin {
 1063:     my ($r,$prog_state,$extraInfo)=@_;
 1064:     $$prog_state{'done'}++;
 1065:     my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
 1066:         $$prog_state{'done'} *
 1067: 	($$prog_state{'max'}-$$prog_state{'done'});
 1068:     $time_est = int($time_est);
 1069:     #
 1070:     my $min = int($time_est/60);
 1071:     my $sec = $time_est % 60;
 1072:     # 
 1073:     my $str;
 1074:     if ($min == 0 && $sec > 1) {
 1075:         $str = '[_2] seconds';
 1076:     } elsif ($min == 1 && $sec > 1) {
 1077:         $str = '1 minute [_2] seconds';
 1078:     } elsif ($min == 1 && $sec < 2) {
 1079:         $str = '1 minute';
 1080:     } elsif ($min < 10 && $sec > 1) {
 1081:         $str = '[_1] minutes, [_2] seconds';
 1082:     } elsif ($min >= 10 || $sec < 2) {
 1083:         $str = '[_1] minutes';
 1084:     }
 1085:     $time_est = &mt($str,$min,$sec);
 1086:     #
 1087:     my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
 1088:     if ($lasttime > 9) {
 1089:         $lasttime = int($lasttime);
 1090:     } elsif ($lasttime < 0.01) {
 1091:         $lasttime = 0;
 1092:     } else {
 1093:         $lasttime = sprintf("%3.2f",$lasttime);
 1094:     }
 1095:     if ($lasttime == 1) {
 1096:         $lasttime = '('.$lasttime.' '.&mt('second for').' '.$extraInfo.')';
 1097:     } else {
 1098:         $lasttime = '('.$lasttime.' '.&mt('seconds for').' '.$extraInfo.')';
 1099:     }
 1100:     #
 1101:     my $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
 1102:     my $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
 1103:     if (! defined($user_browser) || ! defined($user_os)) {
 1104:         (undef,$user_browser,undef,undef,undef,$user_os) = 
 1105:                            &Apache::loncommon::decode_user_agent();
 1106:     }
 1107:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
 1108:         $lasttime = '';
 1109:     }
 1110:     &r_print($r,&Apache::lonhtmlcommon::scripttag(
 1111:         $$prog_state{'window'}.'.document.'.
 1112:         $$prog_state{'formname'}.'.'.
 1113:         $$prog_state{'inputname'}.'.value="'.
 1114:         $$prog_state{'done'}.'/'.$$prog_state{'max'}.
 1115:         ': '.$time_est.' '.&mt('remaining').' '.$lasttime.'";'
 1116:     ));
 1117:     $$prog_state{'laststart'}=&Time::HiRes::time();
 1118: }
 1119: 
 1120: # close Progress Line
 1121: sub Close_PrgWin {
 1122:     my ($r,$prog_state)=@_;
 1123:     if ($$prog_state{'type'} eq 'popup') {
 1124:         &r_print($r,&Apache::lonhtmlcommon::scripttag(
 1125:             'popwin.close()'
 1126:         ));
 1127:     } elsif ($$prog_state{'type'} eq 'inline') {
 1128: 	&Update_PrgWin($r,$prog_state,&mt('Done'));
 1129:     }
 1130:     undef(%$prog_state);
 1131: }
 1132: 
 1133: sub r_print {
 1134:     my ($r,$to_print)=@_;
 1135:     if ($r) {
 1136: 	$r->print($to_print);
 1137: 	$r->rflush();
 1138:     } else {
 1139: 	print($to_print);
 1140:     }
 1141: }
 1142: 
 1143: # ------------------------------------------------------- Puts directory header
 1144: 
 1145: sub crumbs {
 1146:     my ($uri,$target,$prefix,$form,$skiplast)=@_;
 1147:     if ($target) {
 1148:         $target = ' target="'.
 1149:                   &Apache::loncommon::escape_single($target).'"';
 1150:     }
 1151:     my $output='<span class="LC_filename">';
 1152:     $output.=$prefix.'/';
 1153:     if (($env{'user.adv'}) || ($env{'user.author'})) {
 1154:         my $path=$prefix.'/';
 1155:         foreach my $dir (split('/',$uri)) {
 1156:             if (! $dir) { next; }
 1157:             $path .= $dir;
 1158:             if ($path eq $uri) {
 1159:                 if ($skiplast) {
 1160:                     $output.=$dir;
 1161:                     last;
 1162:                 } 
 1163:             } else {
 1164:                 $path.='/'; 
 1165:             }
 1166:             my $href_path = &HTML::Entities::encode($path,'<>&"');
 1167:             &Apache::loncommon::inhibit_menu_check(\$href_path);
 1168:             if ($form) {
 1169:                 my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
 1170:                 $output.=qq{<a href="$href"$target>$dir</a>/};
 1171:             } else {
 1172:                 $output.=qq{<a href="$href_path"$target>$dir</a>/};
 1173:             }
 1174:         }
 1175:     } else {
 1176:         foreach my $dir (split('/',$uri)) {
 1177:             if (! $dir) { next; }
 1178:             $output.=$dir.'/';
 1179:         }
 1180:     }
 1181:     if ($uri !~ m|/$|) { $output=~s|/$||; }
 1182:     $output.='</span>';
 1183: 
 1184:     return $output;
 1185: }
 1186: 
 1187: # --------------------- A function that generates a window for the spellchecker
 1188: 
 1189: sub spellheader {
 1190:     my $start_page=
 1191: 	&Apache::loncommon::start_page('Speller Suggestions',undef,
 1192: 				       {'only_body'   => 1,
 1193: 					'js_ready'    => 1,
 1194: 					'bgcolor'     => '#DDDDDD',
 1195: 				        'add_entries' => {
 1196: 					    'onload' => 
 1197:                                                'document.forms.spellcheckform.submit()',
 1198:                                              }
 1199: 				        });
 1200:     my $end_page=
 1201: 	&Apache::loncommon::end_page({'js_ready'  => 1}); 
 1202: 
 1203:     my $nothing=&javascript_nothing();
 1204:     return (<<ENDCHECK);
 1205: <script type="text/javascript"> 
 1206: // <![CDATA[
 1207: //<!-- BEGIN LON-CAPA Internal
 1208: var checkwin;
 1209: 
 1210: function spellcheckerwindow(string) {
 1211:     var esc_string = string.replace(/\"/g,'&quot;');
 1212:     checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1213:     checkwin.document.writeln('$start_page<form name="spellcheckform" action="/adm/spellcheck" method="post"><input type="hidden" name="text" value="'+esc_string+'" /><\\/form>$end_page');
 1214:     checkwin.document.close();
 1215: }
 1216: // END LON-CAPA Internal -->
 1217: // ]]>
 1218: </script>
 1219: ENDCHECK
 1220: }
 1221: 
 1222: # ---------------------------------- Generate link to spell checker for a field
 1223: 
 1224: sub spelllink {
 1225:     my ($form,$field)=@_;
 1226:     my $linktext=&mt('Check Spelling');
 1227:     return (<<ENDLINK);
 1228: <a href="javascript:if (typeof(document.$form.onsubmit)!='undefined') { if (document.$form.onsubmit!=null) { document.$form.onsubmit();}};spellcheckerwindow(this.document.forms.$form.$field.value);">$linktext</a>
 1229: ENDLINK
 1230: }
 1231: 
 1232: # ------------------------------------------------- Output headers for HTMLArea
 1233: 
 1234: {
 1235:     my @htmlareafields;
 1236:     sub init_htmlareafields {
 1237: 	undef(@htmlareafields);
 1238:     }
 1239:     
 1240:     sub add_htmlareafields {
 1241: 	my (@newfields) = @_;
 1242: 	push(@htmlareafields,@newfields);
 1243:     }
 1244: 
 1245:     sub get_htmlareafields {
 1246: 	return @htmlareafields;
 1247:     }
 1248: }
 1249: 
 1250: sub htmlareaheaders {
 1251:     return if (&htmlareablocked());
 1252:     return if (!&htmlareabrowser());
 1253:     return (<<ENDHEADERS);
 1254: <script type="text/javascript" src="/fckeditor/fckeditor.js"></script>
 1255: ENDHEADERS
 1256: }
 1257: 
 1258: # ----------------------------------------------------------------- Preferences
 1259: 
 1260: sub disablelink {
 1261:     my @fields=@_;
 1262:     if (defined($#fields)) {
 1263: 	unless ($#fields>=0) { return ''; }
 1264:     }
 1265:     return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=off&returnurl=','<>&"').&escape($ENV{'REQUEST_URI'}).'">'.&mt('Disable WYSIWYG Editor').'</a>';
 1266: }
 1267: 
 1268: sub enablelink {
 1269:     my @fields=@_;
 1270:     if (defined($#fields)) {
 1271: 	unless ($#fields>=0) { return ''; }
 1272:     }
 1273:     return '<a href="'.&HTML::Entities::encode('/adm/preferences?action=set_wysiwyg&wysiwyg=on&returnurl=','<>&"').&escape($ENV{'REQUEST_URI'}).'">'.&mt('Enable WYSIWYG Editor').'</a>';
 1274: }
 1275: 
 1276: # ------------------------------------------------- lang to use in html editor
 1277: sub htmlarea_lang {
 1278:     my $lang='en';
 1279:     if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
 1280: 	$lang=&mt('htmlarea_lang');
 1281:     }
 1282:     return $lang;
 1283: }
 1284: 
 1285: # ----------------------------------------- Script to activate only some fields
 1286: 
 1287: sub htmlareaselectactive {
 1288:     my @fields=@_;
 1289:     unless (&htmlareabrowser()) { return ''; }
 1290:     if (&htmlareablocked()) { return '<br />'.&enablelink(@fields); }
 1291:     my $output='<script type="text/javascript" defer="1">'."\n"
 1292:               .'// <![CDATA['."\n";
 1293:     my $lang = &htmlarea_lang();
 1294:     foreach my $field (@fields) {
 1295: 	$output.="
 1296: {
 1297:     var oFCKeditor = new FCKeditor('$field');
 1298:     oFCKeditor.Config['CustomConfigurationsPath'] = 
 1299: 	'/fckeditor/loncapaconfig.js';    
 1300:     oFCKeditor.ReplaceTextarea();
 1301:     oFCKeditor.Config['AutoDetectLanguage'] = false;
 1302:     oFCKeditor.Config['DefaultLanguage'] = '$lang';
 1303: }";
 1304:     }
 1305:     $output.="\nwindow.status='Activated Editfields';\n"
 1306:             .'// ]]>'."\n"
 1307:             .'</script><br />'.
 1308: 	&disablelink(@fields);
 1309:     return $output;
 1310: }
 1311: 
 1312: # --------------------------------------------------------------------- Blocked
 1313: 
 1314: sub htmlareablocked {
 1315:     unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
 1316:     return 0;
 1317: }
 1318: 
 1319: # ---------------------------------------- Browser capable of running HTMLArea?
 1320: 
 1321: sub htmlareabrowser {
 1322:     return 1;
 1323: }
 1324: 
 1325: ############################################################
 1326: ############################################################
 1327: 
 1328: =pod
 1329: 
 1330: =item breadcrumbs
 1331: 
 1332: Compiles the previously registered breadcrumbs into an series of links.
 1333: Additionally supports a 'component', which will be displayed on the
 1334: right side of the breadcrumbs enclosing div (without a link).
 1335: A link to help for the component will be included if one is specified.
 1336: 
 1337: All inputs can be undef without problems.
 1338: 
 1339: Inputs: $component (the text on the right side of the breadcrumbs trail),
 1340:         $component_help
 1341:         $menulink (boolean, controls whether to include a link to /adm/menu)
 1342:         $helplink (if 'nohelp' don't include the orange help link)
 1343:         $css_class (optional name for the class to apply to the table for CSS)
 1344:         $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component
 1345:            when including the text on the right.
 1346: Returns a string containing breadcrumbs for the current page.
 1347: 
 1348: =item clear_breadcrumbs
 1349: 
 1350: Clears the previously stored breadcrumbs.
 1351: 
 1352: =item add_breadcrumb
 1353: 
 1354: Pushes a breadcrumb on the stack of crumbs.
 1355: 
 1356: input: $breadcrumb, a hash reference.  The keys 'href','title', and 'text'
 1357: are required.  If present the keys 'faq' and 'bug' will be used to provide
 1358: links to the FAQ and bug sites. If the key 'no_mt' is present the 'title' 
 1359: and 'text' values won't be sent through &mt()
 1360: 
 1361: returns: nothing    
 1362: 
 1363: =cut
 1364: 
 1365: ############################################################
 1366: ############################################################
 1367: {
 1368:     my @Crumbs;
 1369:     my %tools = ();
 1370:     
 1371:     sub breadcrumbs {
 1372:         my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, $CourseBreadcrumbs) = @_;
 1373:         #
 1374:         $css_class ||= 'LC_breadcrumbs';
 1375: 
 1376:         # Make the faq and bug data cascade
 1377:         my $faq  = '';
 1378:         my $bug  = '';
 1379:         my $help = '';
 1380:         # Crumb Symbol
 1381:         my $crumbsymbol = '&raquo;';
 1382:         # The last breadcrumb does not have a link, so handle it separately.
 1383:         my $last = pop(@Crumbs);
 1384:         #
 1385:         # The first one should be the course or a menu link
 1386:         if (!defined($menulink)) { $menulink=1; }
 1387:         if ($menulink) {
 1388:             if ($menulink eq '_nomenu') {
 1389:                 return unless($last);
 1390:             } else {
 1391:                 my $description = 'Menu';
 1392:                 my $href = '/adm/menu';
 1393:                 my $tooltip = 'Go to main menu';
 1394:                 my $no_mt_descr = 0;
 1395:                 if ((exists($env{'request.course.id'})) &&
 1396:                     ($env{'request.course.id'} ne '') && 
 1397:                     !($env{'form.context'} eq 'requestcrs')) {
 1398:                     if ((&Apache::loncommon::needs_gci_custom()) || ($env{'user.domain'} eq 'gcitest')) {
 1399:                         if ($env{'environment.remotenavmap'} eq 'on') {
 1400:                             # open link using javascript when remote navmap is activated
 1401:                             $href = "javascript:gonav('/adm/navmaps');";
 1402:                         } else {
 1403:                             $href = '/adm/navmaps';
 1404:                         }
 1405:                         $tooltip = 'Contents';
 1406:                     }
 1407:                     if ($env{'course.'.$env{'request.course.id'}.'.description'} ne '') {
 1408:                         $description =
 1409:                             $env{'course.'.$env{'request.course.id'}.'.description'};
 1410:                         $no_mt_descr = 1;
 1411:                     }
 1412:                 }
 1413:                 $menulink =  {  href   => $href,
 1414:                                 title  => $tooltip,
 1415:                                 target => '_top',
 1416:                                 text   => $description,
 1417:                                 no_mt  => $no_mt_descr, };
 1418:                 if ($last) {
 1419:                     #$last set, so we have some crumbs
 1420:                     unshift(@Crumbs,$menulink);
 1421:                 } else {
 1422:                     #only menulink crumb present
 1423:                     $last = $menulink;
 1424:                 }
 1425:             }
 1426:         }
 1427:         my $links = join "", 
 1428:                  map {
 1429:                      $faq  = $_->{'faq'}  if (exists($_->{'faq'}));
 1430:                      $bug  = $_->{'bug'}  if (exists($_->{'bug'}));
 1431:                      $help = $_->{'help'} if (exists($_->{'help'}));
 1432: 
 1433:                      my $result = $_->{no_mt} ? $_->{text} : mt($_->{text});
 1434: 
 1435:                      if ($_->{href}){
 1436:                          $result = htmltag( 'a', $result, 
 1437:                                            { 
 1438:                                                href   => $_->{href},
 1439:                                                title  => $_->{no_mt} ? 
 1440:                                                 $_->{title} : mt($_->{title}),
 1441:                                                target => $_->{target},
 1442:                                            });
 1443:                      }
 1444: 
 1445:                      $result = htmltag( 'li', "$result $crumbsymbol");
 1446:                  } @Crumbs;
 1447: 
 1448:         #should the last Element be translated?
 1449: 
 1450:         my $lasttext = $last->{'no_mt'} ? $last->{'text'}
 1451:                      : mt( $last->{'text'} );
 1452: 
 1453:         # last breadcrumb is the first order heading of a page
 1454:         # for course breadcrumbs it's just bold
 1455:         $links .= htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
 1456:                            $lasttext), {title => $lasttext});
 1457: 
 1458:         my $icons = '';
 1459:         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
 1460:         $bug  = $last->{'bug'}  if (exists($last->{'bug'}));
 1461:         $help = $last->{'help'} if (exists($last->{'help'}));
 1462:         $component_help=($component_help?$component_help:$help);
 1463: #        if ($faq ne '') {
 1464: #            $icons .= &Apache::loncommon::help_open_faq($faq);
 1465: #        }
 1466: #        if ($bug ne '') {
 1467: #            $icons .= &Apache::loncommon::help_open_bug($bug);
 1468: #        }
 1469:         if ($faq ne '' || $component_help ne '' || $bug ne '') {
 1470:             $icons .= &Apache::loncommon::help_open_menu($component,
 1471:                                                          $component_help,
 1472:                                                          $faq,$bug);
 1473:         }
 1474:         #
 1475: 		
 1476: 
 1477:         unless ($CourseBreadcrumbs) {
 1478:             $links = htmltag('ol',  $links, { id => "LC_MenuBreadcrumbs"   });
 1479:         } else {
 1480:             $links = htmltag('ul',  $links, { class => "LC_CourseBreadcrumbs" });
 1481:         }
 1482: 
 1483:         if ($component) {
 1484:             $links = htmltag('span', 
 1485:                              ( $no_mt ? $component : mt($component) ).
 1486:                              ( $icons ? $icons : '' ),
 1487:                              { class => 'LC_breadcrumbs_component' } )
 1488:                              .$links;
 1489:         }
 1490:         
 1491:         render_tools(\$links);
 1492:         $links = htmltag('div', $links, 
 1493:                         { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
 1494:         render_advtools(\$links);
 1495: 
 1496:         # Return the @Crumbs stack to what we started with
 1497:         push(@Crumbs,$last);
 1498:         shift(@Crumbs);
 1499:         # Return the breadcrumb's line
 1500:         return "$links";
 1501:     }
 1502: 
 1503:     sub clear_breadcrumbs {
 1504:         undef(@Crumbs);
 1505:         undef(%tools);
 1506:     }
 1507: 
 1508:     sub add_breadcrumb {
 1509:         push(@Crumbs,@_);
 1510:     }
 1511:     
 1512: =item add_breadcrumb_tool($category, $html)
 1513: 
 1514: Adds $html to $category of the breadcrumb toolbar container.
 1515: 
 1516: $html is usually a link to a page that invokes a function on the currently
 1517: displayed data (e.g. print when viewing a problem)
 1518: 
 1519: Currently there are 3 possible values for $category:
 1520: 
 1521: =over
 1522: 
 1523: =item navigation
 1524: left of breadcrumbs line
 1525: 
 1526: =item tools
 1527: right of breadcrumbs line
 1528: 
 1529: =item advtools
 1530: advanced tools shown in a separate box below breadcrumbs line
 1531: 
 1532: =back
 1533: 
 1534: returns: nothing
 1535: 
 1536: =cut
 1537: 
 1538:     sub add_breadcrumb_tool {
 1539:         my ($category, @html) = @_;
 1540:         return unless @html;
 1541:         if (!defined(%tools)) {
 1542:             %tools = ( navigation => [], tools => [], advtools => []);
 1543:         }
 1544: 
 1545:         #this cleans data received from lonmenu::innerregister
 1546:         @html = grep {defined $_ && $_ ne ''} @html;
 1547:         for (@html) {
 1548:             s/align="(right|left)"//;
 1549:             s/<span.*?\/span>// if $category ne 'advtools';
 1550:         }
 1551: 
 1552:         push @{$tools{$category}}, @html;
 1553:     }
 1554: 
 1555: =item clear_breadcrumb_tools()
 1556: 
 1557: Clears the breadcrumb toolbar container.
 1558: 
 1559: returns: nothing
 1560: 
 1561: =cut
 1562: 
 1563:     sub clear_breadcrumb_tools {
 1564:         undef(%tools);
 1565:     }
 1566: 
 1567: =item render_tools(\$breadcrumbs)
 1568: 
 1569: Creates html for breadcrumb tools (categories navigation and tools) and inserts
 1570: \$breadcrumbs at the correct position.
 1571: 
 1572: input: \$breadcrumbs - a reference to the string containing prepared
 1573: breadcrumbs.
 1574: 
 1575: returns: nothing
 1576: =cut
 1577: 
 1578: #TODO might split this in separate functions for each category
 1579:     sub render_tools {
 1580:         my ($breadcrumbs) = @_;
 1581:         return unless defined %tools;
 1582: 
 1583:         my $navigation = list_from_array($tools{navigation},
 1584:                    { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
 1585:         my $tools = list_from_array($tools{tools},
 1586:                    { listattr => { class=>"LC_breadcrumb_tools_tools" } });
 1587:         $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
 1588:                    { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
 1589:     }
 1590: 
 1591: =item render_advtools(\$breadcrumbs,$legend)
 1592: 
 1593: Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
 1594: at the correct position.
 1595: 
 1596: input: \$breadcrumbs - a reference to the string containing prepared
 1597: breadcrumbs (after render_tools call).
 1598: 
 1599: returns: nothing
 1600: =cut
 1601: 
 1602:     sub render_advtools {
 1603:         my ($breadcrumbs,$legend) = @_;
 1604:         return unless     (defined $tools{'advtools'})
 1605:                       and (scalar(@{$tools{'advtools'}}) > 0);
 1606:         my $args;
 1607:         if ($legend) {
 1608:             $args = {legend => $legend};
 1609:         }
 1610:         $$breadcrumbs .= Apache::loncommon::head_subbox(
 1611:                             funclist_from_array($tools{'advtools'},$args));
 1612:     }
 1613: 
 1614: } # End of scope for @Crumbs
 1615: 
 1616: ############################################################
 1617: ############################################################
 1618: 
 1619: # Nested table routines.
 1620: #
 1621: # Routines to display form items in a multi-row table with 2 columns.
 1622: # Uses nested tables to divide form elements into segments.
 1623: # For examples of use see loncom/interface/lonnotify.pm 
 1624: #
 1625: # Can be used in following order: ...
 1626: # &start_pick_box()
 1627: # row1
 1628: # row2
 1629: # row3   ... etc.
 1630: # &submit_row()
 1631: # &end_pick_box()
 1632: #
 1633: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
 1634: # &status_select_row and &email_default_row
 1635: #
 1636: # Can also be used in following order:
 1637: #
 1638: # &start_pick_box()
 1639: # &row_title()
 1640: # &row_closure()
 1641: # &row_title()
 1642: # &row_closure()  ... etc.
 1643: # &submit_row()
 1644: # &end_pick_box()
 1645: #
 1646: # In general a &submit_row() call should proceed the call to &end_pick_box(),
 1647: # as this routine adds a button for form submission.
 1648: # &submit_row() does not require a &row_closure after it.
 1649: #  
 1650: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
 1651: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
 1652: #
 1653: # &row_title() adds a title in the left column for each segment.
 1654: # &row_closure() closes a row with a 1-pixel wide black line.
 1655: #
 1656: # &role_select_row() provides a select box from which to choose 1 or more roles 
 1657: # &course_select_row provides ways of picking groups of courses
 1658: #    radio buttons: all, by category or by picking from a course picker pop-up
 1659: #      note: by category option is only displayed if a domain has implemented 
 1660: #                selection by year, semester, department, number etc.
 1661: #
 1662: # &status_select_row() provides a select box from which to choose 1 or more
 1663: #  access types (current access, prior access, and future access)  
 1664: #
 1665: # &email_default_row() provides text boxes for default e-mail suffixes for
 1666: #  different authentication types in a domain.
 1667: #
 1668: # &row_title() and &row_closure() are called internally by the &*_select_row
 1669: # routines, but can also be called directly to start and end rows which have 
 1670: # needs that are not accommodated by the *_select_row() routines.    
 1671: 
 1672: { # Start: row_count block for pick_box
 1673: my @row_count;
 1674: 
 1675: sub start_pick_box {
 1676:     my ($css_class) = @_;
 1677:     if (defined($css_class)) {
 1678: 	$css_class = 'class="'.$css_class.'"';
 1679:     } else {
 1680: 	$css_class= 'class="LC_pick_box"';
 1681:     }
 1682:     unshift(@row_count,0);
 1683:     my $output = <<"END";
 1684:  <table $css_class>
 1685: END
 1686:     return $output;
 1687: }
 1688: 
 1689: sub end_pick_box {
 1690:     shift(@row_count);
 1691:     my $output = <<"END";
 1692:        </table>
 1693: END
 1694:     return $output;
 1695: }
 1696: 
 1697: sub row_headline {
 1698:     my $output = <<"END";
 1699:            <tr><td colspan="2">
 1700: END
 1701:     return $output;
 1702: }
 1703: 
 1704: sub row_title {
 1705:     my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
 1706:     $row_count[0]++;
 1707:     my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
 1708:     $css_title_class ||= 'LC_pick_box_title';
 1709:     $css_title_class = 'class="'.$css_title_class.'"';
 1710: 
 1711:     $css_value_class ||= 'LC_pick_box_value';
 1712: 
 1713:     if ($title ne '') {
 1714:         $title .= ':';
 1715:     }
 1716:     my $output = <<"ENDONE";
 1717:            <tr class="LC_pick_box_row" $css_value_furtherAttributes> 
 1718:             <td $css_title_class>
 1719: 	       $title
 1720:             </td>
 1721:             <td class="$css_value_class $css_class">
 1722: ENDONE
 1723:     return $output;
 1724: }
 1725: 
 1726: sub row_closure {
 1727:     my ($no_separator) =@_;
 1728:     my $output = <<"ENDTWO";
 1729:             </td>
 1730:            </tr>
 1731: ENDTWO
 1732:     if (!$no_separator) {
 1733:         $output .= <<"ENDTWO";
 1734:            <tr>
 1735:             <td colspan="2" class="LC_pick_box_separator">
 1736:             </td>
 1737:            </tr>
 1738: ENDTWO
 1739:     }
 1740:     return $output;
 1741: }
 1742: 
 1743: } # End: row_count block for pick_box
 1744: 
 1745: sub role_select_row {
 1746:     my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
 1747:     my $crstype = 'Course';
 1748:     if ($cdom ne '' && $cnum ne '') {
 1749:         $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
 1750:     }
 1751:     my $output;
 1752:     if (defined($title)) {
 1753:         $output = &row_title($title,$css_class);
 1754:     }
 1755:     $output .= qq|
 1756:                                   <select name="roles" multiple="multiple">\n|;
 1757:     foreach my $role (@$roles) {
 1758:         my $plrole;
 1759:         if ($role eq 'ow') {
 1760:             $plrole = &mt('Course Owner');
 1761:         } elsif ($role eq 'cr') {
 1762:             if ($show_separate_custom) {
 1763:                 if ($cdom ne '' && $cnum ne '') {
 1764:                     my %course_customroles = &course_custom_roles($cdom,$cnum);
 1765:                     foreach my $crrole (sort(keys(%course_customroles))) {
 1766:                         my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
 1767:                         $output .= '  <option value="'.$crrole.'">'.$plcrrole.
 1768:                                    '</option>';
 1769:                     }
 1770:                 }
 1771:             } else {
 1772:                 $plrole = &mt('Custom Role');
 1773:             }
 1774:         } else {
 1775:             $plrole=&Apache::lonnet::plaintext($role,$crstype);
 1776:         }
 1777:         if (($role ne 'cr') || (!$show_separate_custom)) {
 1778:             $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
 1779:         }
 1780:     }
 1781:     $output .= qq|                </select>\n|;
 1782:     if (defined($title)) {
 1783:         $output .= &row_closure();
 1784:     }
 1785:     return $output;
 1786: }
 1787: 
 1788: sub course_select_row {
 1789:     my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
 1790: 	$css_class,$crstype) = @_;
 1791:     my $output = &row_title($title,$css_class);
 1792:     $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype);
 1793:     $output .= &row_closure();
 1794:     return $output;
 1795: }
 1796: 
 1797: sub course_selection {
 1798:     my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype) = @_;
 1799:     my $output = qq|
 1800: <script type="text/javascript">
 1801: // <![CDATA[
 1802:     function coursePick (formname) {
 1803:         for  (var i=0; i<formname.coursepick.length; i++) {
 1804:             if (formname.coursepick[i].value == 'category') {
 1805:                 courseSet('');
 1806:             }
 1807:             if (!formname.coursepick[i].checked) {
 1808:                 if (formname.coursepick[i].value == 'specific') {
 1809:                     formname.coursetotal.value = 0;
 1810:                     formname.courselist = '';
 1811:                 }
 1812:             }
 1813:         }
 1814:     }
 1815:     function setPick (formname) {
 1816:         for  (var i=0; i<formname.coursepick.length; i++) {
 1817:             if (formname.coursepick[i].value == 'category') {
 1818:                 formname.coursepick[i].checked = true;
 1819:             }
 1820:             formname.coursetotal.value = 0;
 1821:             formname.courselist = '';
 1822:         }
 1823:     }
 1824: // ]]>
 1825: </script>
 1826:     |;
 1827: 
 1828:     my ($allcrs,$pickspec);
 1829:     if ($crstype eq 'Community') {
 1830:         $allcrs = &mt('All communities');
 1831:         $pickspec = &mt('Pick specific communities:');
 1832:     } else {
 1833:         $allcrs = &mt('All courses');
 1834:         $pickspec = &mt('Pick specific course(s):');
 1835:     }
 1836: 
 1837:     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
 1838:                      ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'</b>';
 1839:         $output .= '<input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.$allcrs.'<br />';
 1840:     if ($totcodes > 0) {
 1841:         my $numtitles = @$codetitles;
 1842:         if ($numtitles > 0) {
 1843:             $output .= '<input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&mt('Choose categories, from left to right')."'".')" />'.&mt('Pick courses by category:').' <br />';
 1844:             $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
 1845:                '<select name="'.$$codetitles[0].
 1846:                '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
 1847:                ' <option value="-1" />Select'."\n";
 1848:             my @items = ();
 1849:             my @longitems = ();
 1850:             if ($$idlist{$$codetitles[0]} =~ /","/) {
 1851:                 @items = split(/","/,$$idlist{$$codetitles[0]});
 1852:             } else {
 1853:                 $items[0] = $$idlist{$$codetitles[0]};
 1854:             }
 1855:             if (defined($$idlist_titles{$$codetitles[0]})) {
 1856:                 if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
 1857:                     @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
 1858:                 } else {
 1859:                     $longitems[0] = $$idlist_titles{$$codetitles[0]};
 1860:                 }
 1861:                 for (my $i=0; $i<@longitems; $i++) {
 1862:                     if ($longitems[$i] eq '') {
 1863:                         $longitems[$i] = $items[$i];
 1864:                     }
 1865:                 }
 1866:             } else {
 1867:                 @longitems = @items;
 1868:             }
 1869:             for (my $i=0; $i<@items; $i++) {
 1870:                 $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
 1871:             }
 1872:             $output .= '</select></td>';
 1873:             for (my $i=1; $i<$numtitles; $i++) {
 1874:                 $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
 1875:                           '<select name="'.$$codetitles[$i].
 1876:                           '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
 1877:                           '<option value="-1">&lt;-Pick '.$$codetitles[$i-1].'</option>'."\n".
 1878:                           '</select>'."\n".
 1879:                           '</td>';
 1880:             }
 1881:             $output .= '</tr></table><br />';
 1882:         }
 1883:     }
 1884:     $output .= '<input type="radio" name="coursepick" value="specific" onclick="coursePick(this.form);opencrsbrowser('."'".$formname."','dccourse','dcdomain','coursedesc','','1','$crstype'".')" />'.$pickspec.' '.$courseform.'&nbsp;&nbsp;<input type="text" value="0" size="4" name="coursetotal" /><input type="hidden" name="courselist" value="" />selected.<br />'."\n";
 1885:     return $output;
 1886: }
 1887: 
 1888: sub status_select_row {
 1889:     my ($types,$title,$css_class) = @_;
 1890:     my $output; 
 1891:     if (defined($title)) {
 1892:         $output = &row_title($title,$css_class,'LC_pick_box_select');
 1893:     }
 1894:     $output .= qq|
 1895:                                     <select name="types" multiple="multiple">\n|;
 1896:     foreach my $status_type (sort(keys(%{$types}))) {
 1897:         $output .= '  <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
 1898:     }
 1899:     $output .= qq|                   </select>\n|; 
 1900:     if (defined($title)) {
 1901:         $output .= &row_closure();
 1902:     }
 1903:     return $output;
 1904: }
 1905: 
 1906: sub email_default_row {
 1907:     my ($authtypes,$title,$descrip,$css_class) = @_;
 1908:     my $output = &row_title($title,$css_class);
 1909:     $output .= $descrip.
 1910: 	&Apache::loncommon::start_data_table().
 1911: 	&Apache::loncommon::start_data_table_header_row().
 1912: 	'<th>'.&mt('Authentication Method').'</th>'.
 1913: 	'<th align="right">'.&mt('Username -> e-mail conversion').'</th>'."\n".
 1914: 	&Apache::loncommon::end_data_table_header_row();
 1915:     my $rownum = 0;
 1916:     foreach my $auth (sort(keys(%{$authtypes}))) {
 1917:         my ($userentry,$size);
 1918:         if ($auth =~ /^krb/) {
 1919:             $userentry = '';
 1920:             $size = 25;
 1921:         } else {
 1922:             $userentry = 'username@';
 1923:             $size = 15;
 1924:         }
 1925:         $output .= &Apache::loncommon::start_data_table_row().
 1926: 	    '<td>  '.$$authtypes{$auth}.'</td>'.
 1927: 	    '<td align="right">'.$userentry.
 1928: 	    '<input type="text" name="'.$auth.'" size="'.$size.'" /></td>'.
 1929: 	    &Apache::loncommon::end_data_table_row();
 1930:     }
 1931:     $output .= &Apache::loncommon::end_data_table();
 1932:     $output .= &row_closure();
 1933:     return $output;
 1934: }
 1935: 
 1936: 
 1937: sub submit_row {
 1938:     my ($title,$cmd,$submit_text,$css_class) = @_;
 1939:     my $output = &row_title($title,$css_class,'LC_pick_box_submit');
 1940:     $output .= qq|
 1941:              <br />
 1942:              <input type="hidden" name="command" value="$cmd" />
 1943:              <input type="submit" value="$submit_text"/> &nbsp;
 1944:              <br /><br />
 1945:             \n|;
 1946:     return $output;
 1947: }
 1948: 
 1949: sub course_custom_roles {
 1950:     my ($cdom,$cnum) = @_;
 1951:     my %returnhash=();
 1952:     my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
 1953:     foreach my $person (sort(keys(%coursepersonnel))) {
 1954:         my ($role) = ($person =~ /^([^:]+):/);
 1955:         my ($end,$start) = split(/:/,$coursepersonnel{$person});
 1956:         if ($end == -1 && $start == -1) {
 1957:             next;
 1958:         }
 1959:         if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
 1960:             $returnhash{$role} ++;
 1961:         }
 1962:     }
 1963:     return %returnhash;
 1964: }
 1965: 
 1966: 
 1967: ##############################################
 1968: ##############################################
 1969: 
 1970: # topic_bar
 1971: #
 1972: # Generates a div containing an (optional) number with a white background followed by a 
 1973: # title with a background color defined in the corresponding CSS: LC_topic_bar
 1974: # Inputs:
 1975: # 1. number to display.
 1976: #    If input for number is empty only the title will be displayed. 
 1977: # 2. title text to display.
 1978: # Outputs - a scalar containing html mark-up for the div.
 1979: 
 1980: sub topic_bar {
 1981:     my ($num,$title) = @_;
 1982:     my $number = '';
 1983:     if ($num ne '') {
 1984:         $number = '<span>'.$num.'</span>';
 1985:     }
 1986:     return '<div class="LC_topic_bar">'.$number.$title.'</div>';
 1987: }
 1988: 
 1989: ##############################################
 1990: ##############################################
 1991: # echo_form_input
 1992: #
 1993: # Generates html markup to add form elements from the referrer page
 1994: # as hidden form elements (values encoded) in the new page.
 1995: #
 1996: # Intended to support two types of use 
 1997: # (a) to allow backing up to earlier pages in a multi-page 
 1998: # form submission process using a breadcrumb trail.
 1999: #
 2000: # (b) to allow the current page to be reloaded with form elements
 2001: # set on previous page to remain unchanged.  An example would
 2002: # be where the a page containing a dynamically-built table of data is 
 2003: # is to be redisplayed, with only the sort order of the data changed. 
 2004: #  
 2005: # Inputs:
 2006: # 1. Reference to array of form elements in the submitted form on 
 2007: # the referrer page which are to be excluded from the echoed elements.
 2008: #
 2009: # 2. Reference to array of regular expressions, which if matched in the  
 2010: # name of the form element n the referrer page will be omitted from echo. 
 2011: #
 2012: # Outputs: A scalar containing the html markup for the echoed form
 2013: # elements (all as hidden elements, with values encoded). 
 2014: 
 2015: 
 2016: sub echo_form_input {
 2017:     my ($excluded,$regexps) = @_;
 2018:     my $output = '';
 2019:     foreach my $key (keys(%env)) {
 2020:         if ($key =~ /^form\.(.+)$/) {
 2021:             my $name = $1;
 2022:             my $match = 0;
 2023:             if ((!@{$excluded}) || (!grep/^$name$/,@{$excluded})) {
 2024:                 if (defined($regexps)) {
 2025:                     if (@{$regexps} > 0) {
 2026:                         foreach my $regexp (@{$regexps}) {
 2027:                             if ($name =~ /\Q$regexp\E/) {
 2028:                                 $match = 1;
 2029:                                 last;
 2030:                             }
 2031:                         }
 2032:                     }
 2033:                 }
 2034:                 if (!$match) {
 2035:                     if (ref($env{$key})) {
 2036:                         foreach my $value (@{$env{$key}}) {
 2037:                             $value = &HTML::Entities::encode($value,'<>&"');
 2038:                             $output .= '<input type="hidden" name="'.$name.
 2039:                                              '" value="'.$value.'" />'."\n";
 2040:                         }
 2041:                     } else {
 2042:                         my $value = &HTML::Entities::encode($env{$key},'<>&"');
 2043:                         $output .= '<input type="hidden" name="'.$name.
 2044:                                              '" value="'.$value.'" />'."\n";
 2045:                     }
 2046:                 }
 2047:             }
 2048:         }
 2049:     }
 2050:     return $output;
 2051: }
 2052: 
 2053: ##############################################
 2054: ##############################################
 2055: # set_form_elements
 2056: #
 2057: # Generates javascript to set form elements to values based on
 2058: # corresponding values for the same form elements when the page was
 2059: # previously submitted.
 2060: #     
 2061: # Last submission values are read from hidden form elements in referring 
 2062: # page which have the same name, i.e., generated by &echo_form_input(). 
 2063: #
 2064: # Intended to be called by onload event.
 2065: #
 2066: # Inputs:
 2067: # (a) Reference to hash of echoed form elements to be set.
 2068: #
 2069: # In the hash, keys are the form element names, and the values are the
 2070: # element type (selectbox, radio, checkbox or text -for textbox, textarea or
 2071: # hidden).
 2072: #
 2073: # (b) Optional reference to hash of stored elements to be set.
 2074: #
 2075: # If the page being displayed is a page which permits modification of
 2076: # previously stored data, e.g., the first page in a multi-page submission,
 2077: # then if stored is supplied, form elements will be set to the last stored
 2078: # values.  If user supplied values are also available for the same elements
 2079: # these will replace the stored values. 
 2080: #        
 2081: # Output:
 2082: #  
 2083: # javascript function - set_form_elements() which sets form elements,
 2084: # expects an argument: formname - the name of the form according to 
 2085: # the DOM, e.g., document.compose
 2086: 
 2087: sub set_form_elements {
 2088:     my ($elements,$stored) = @_;
 2089:     my %values;
 2090:     my $output .= 'function setFormElements(courseForm) {
 2091: ';
 2092:     if (defined($stored)) {
 2093:         foreach my $name (keys(%{$stored})) {
 2094:             if (exists($$elements{$name})) {
 2095:                 if (ref($$stored{$name}) eq 'ARRAY') {
 2096:                     $values{$name} = $$stored{$name};
 2097:                 } else {
 2098:                     @{$values{$name}} = ($$stored{$name});
 2099:                 }
 2100:             }
 2101:         }
 2102:     }
 2103: 
 2104:     foreach my $key (keys(%env)) {
 2105:         if ($key =~ /^form\.(.+)$/) {
 2106:             my $name = $1;
 2107:             if (exists($$elements{$name})) {
 2108:                 @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
 2109:             }
 2110:         }
 2111:     }
 2112: 
 2113:     foreach my $name (keys(%values)) {
 2114:         for (my $i=0; $i<@{$values{$name}}; $i++) {
 2115:             $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
 2116:             $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
 2117:             $values{$name}[$i] =~ s/"/\\"/g;
 2118:         }
 2119:         if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
 2120:             my $numvalues = @{$values{$name}};
 2121:             if ($numvalues > 1) {
 2122:                 my $valuestring = join('","',@{$values{$name}});
 2123:                 $output .= qq|
 2124:   var textvalues = new Array ("$valuestring");
 2125:   var total = courseForm.elements['$name'].length;
 2126:   if (total > $numvalues) {
 2127:       total = $numvalues;
 2128:   }    
 2129:   for (var i=0; i<total; i++) {
 2130:       courseForm.elements['$name']\[i].value = textvalues[i];
 2131:   }
 2132: |;
 2133:             } else {
 2134:                 $output .= qq|
 2135:   courseForm.elements['$name'].value = "$values{$name}[0]";
 2136: |;
 2137:             }
 2138:         } else {
 2139:             $output .=  qq|
 2140:   var elementLength = courseForm.elements['$name'].length;
 2141:   if (elementLength==undefined) {
 2142: |;
 2143:             foreach my $value (@{$values{$name}}) {
 2144:                 if ($$elements{$name} eq 'selectbox') {
 2145:                     $output .=  qq|
 2146:       if (courseForm.elements['$name'].options[0].value == "$value") {
 2147:           courseForm.elements['$name'].options[0].selected = true;
 2148:       }|;
 2149:                 } elsif (($$elements{$name} eq 'radio') ||
 2150:                          ($$elements{$name} eq 'checkbox')) {
 2151:                     $output .= qq|
 2152:       if (courseForm.elements['$name'].value == "$value") {
 2153:           courseForm.elements['$name'].checked = true;
 2154:       } else {
 2155:           courseForm.elements['$name'].checked = false;
 2156:       }|;
 2157:                 }
 2158:             }
 2159:             $output .= qq|
 2160:   }
 2161:   else {
 2162:       for (var i=0; i<courseForm.elements['$name'].length; i++) {
 2163: |;
 2164:             if ($$elements{$name} eq 'selectbox') {
 2165:                 $output .=  qq|
 2166:           courseForm.elements['$name'].options[i].selected = false;|;
 2167:             } elsif (($$elements{$name} eq 'radio') || 
 2168:                      ($$elements{$name} eq 'checkbox')) {
 2169:                 $output .= qq|
 2170:           courseForm.elements['$name']\[i].checked = false;|; 
 2171:             }
 2172:             $output .= qq|
 2173:       }
 2174:       for (var j=0; j<courseForm.elements['$name'].length; j++) {
 2175: |;
 2176:             foreach my $value (@{$values{$name}}) {
 2177:                 if ($$elements{$name} eq 'selectbox') {
 2178:                     $output .=  qq|
 2179:           if (courseForm.elements['$name'].options[j].value == "$value") {
 2180:               courseForm.elements['$name'].options[j].selected = true;
 2181:           }|;
 2182:                 } elsif (($$elements{$name} eq 'radio') ||
 2183:                          ($$elements{$name} eq 'checkbox')) { 
 2184:                       $output .= qq|
 2185:           if (courseForm.elements['$name']\[j].value == "$value") {
 2186:               courseForm.elements['$name']\[j].checked = true;
 2187:           }|;
 2188:                 }
 2189:             }
 2190:             $output .= qq|
 2191:       }
 2192:   }
 2193: |;
 2194:         }
 2195:     }
 2196:     $output .= "
 2197:     return;
 2198: }\n";
 2199:     return $output;
 2200: }
 2201: 
 2202: ##############################################
 2203: ##############################################
 2204: 
 2205: # javascript_valid_email
 2206: #
 2207: # Generates javascript to validate an e-mail address.
 2208: # Returns a javascript function which accetps a form field as argumnent, and
 2209: # returns false if field.value does not satisfy two regular expression matches
 2210: # for a valid e-mail address.  Backwards compatible with old browsers without
 2211: # support for javascript RegExp (just checks for @ in field.value in this case). 
 2212: 
 2213: sub javascript_valid_email {
 2214:     my $scripttag .= <<'END';
 2215: function validmail(field) {
 2216:     var str = field.value;
 2217:     if (window.RegExp) {
 2218:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
 2219:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
 2220:         var reg1 = new RegExp(reg1str);
 2221:         var reg2 = new RegExp(reg2str);
 2222:         if (!reg1.test(str) && reg2.test(str)) {
 2223:             return true;
 2224:         }
 2225:         return false;
 2226:     }
 2227:     else
 2228:     {
 2229:         if(str.indexOf("@") >= 0) {
 2230:             return true;
 2231:         }
 2232:         return false;
 2233:     }
 2234: }
 2235: END
 2236:     return $scripttag;
 2237: }
 2238: 
 2239: 
 2240: # USAGE: htmltag(element, content, {attribute => value,...});
 2241: #
 2242: # EXAMPLES: 
 2243: #  - htmltag('a', 'this is an anchor', {href  => 'www.example.com', 
 2244: #                                       title => 'this is a title'})
 2245: #
 2246: #  - You might want to set up needed tags like: 
 2247: #
 2248: #     my $h3  = sub { return htmltag( "h3",  @_ ) };
 2249: #
 2250: #    ... and use them: $h3->("This is a headline")
 2251: #
 2252: #  - To set up a couple of tags, see sub inittags
 2253: #
 2254: # NOTES:
 2255: # - Empty elements, such as <br/> are correctly terminated, 
 2256: #   i.e. htmltag('br') returns <br/> 
 2257: # - Empty attributes (title="") are filtered out.
 2258: # - The function will not check for deprecated attributes.
 2259: #
 2260: # OUTPUT: content enclosed in xhtml conform tags
 2261: sub htmltag{
 2262:     return
 2263:         qq|<$_[0]|
 2264:         . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
 2265:         . ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n";
 2266: };
 2267: 
 2268: 
 2269: # USAGE: inittags(@tags);
 2270: #
 2271: # EXAMPLES:
 2272: #  - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
 2273: #    $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
 2274: #
 2275: # NOTES: See sub htmltag for further information.
 2276: #
 2277: # OUTPUT: List of subroutines. 
 2278: sub inittags {
 2279:     my @tags = @_;
 2280:     return map { my $tag = $_;
 2281:                  sub { return htmltag( $tag, @_ ) }
 2282:                } @tags;
 2283: }
 2284: 
 2285: 
 2286: # USAGE: scripttag(scriptcode, [start|end|both]);
 2287: #
 2288: # EXAMPLES: 
 2289: #  - scripttag("alert('Hello World!')", 'both') 
 2290: #    returns:
 2291: #    <script type="text/javascript">
 2292: #    // BEGIN LON-CAPA Internal
 2293: #    alert(Hello World!')
 2294: #    // END LON-CAPA Internal
 2295: #    </script>
 2296: #
 2297: # NOTES:
 2298: # - works currently only for javascripts
 2299: #
 2300: # OUTPUT: 
 2301: # Scriptcode properly enclosed in <script> and CDATA tags (and LC
 2302: # Internal markers if 2nd argument is given)
 2303: sub scripttag {
 2304:     my ( $content, $marker ) = @_;
 2305:     return unless defined $content;
 2306: 
 2307:     my $begin = "\n// BEGIN LON-CAPA Internal\n";
 2308:     my $end   = "\n// END LON-CAPA Internal\n";
 2309: 
 2310:     if ($marker) {
 2311:         $content  = $begin . $content if $marker eq 'start' or $marker eq 'both';
 2312:         $content .= $end              if $marker eq 'end'   or $marker eq 'both';
 2313:     }
 2314: 
 2315:     $content = "\n// <![CDATA[\n$content\n// ]]>\n";
 2316: 
 2317:     return htmltag('script', $content, {type => 'text/javascript'});
 2318: };
 2319: 
 2320: 
 2321: =item list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
 2322: 
 2323: Constructs a XHTML list from \@array.
 2324: 
 2325: input:
 2326: 
 2327: =over
 2328: 
 2329: =item \@array
 2330: 
 2331: A reference to the array containing text that will be wrapped in <li></li> tags.
 2332: 
 2333: =item { listattr => {}, itemattr =>{} }
 2334: 
 2335: Attributes for <ul> and <li> passed in as hash references.
 2336: See htmltag() for more details.
 2337: 
 2338: =back
 2339: 
 2340: returns: XHTML list as String.
 2341: 
 2342: =cut
 2343: 
 2344: # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
 2345: sub list_from_array {
 2346:     my ($items, $args) = @_;
 2347:     return unless scalar @$items;
 2348:     my ($ul, $li) = inittags( qw(ul li) );
 2349:     my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
 2350:     return $ul->( $listitems, $args->{listattr} );
 2351: }
 2352: 
 2353: 
 2354: ##############################################
 2355: ##############################################
 2356: 
 2357: # generate_menu
 2358: #
 2359: # Generates html markup for a menu. 
 2360: #
 2361: # Inputs:
 2362: # An array of following structure:
 2363: #   ({	categorytitle => 'Categorytitle',
 2364: #	items => [
 2365: #		    {	
 2366: #           linktext    =>	'Text to be displayed',
 2367: #			url	        =>	'URL the link is pointing to, i.e. /adm/site?action=dosomething',
 2368: #			permission  =>	'Contains permissions as returned from lonnet::allowed(),
 2369: #					         must evaluate to true in order to activate the link',
 2370: #			icon        =>  'icon filename',
 2371: #			alttext	    =>	'alt text for the icon',
 2372: #			help	    =>	'Name of the corresponding helpfile',
 2373: #			linktitle   =>	'Description of the link (used for title tag)'
 2374: #		    },
 2375: #		    ...
 2376: #		]
 2377: #   }, 
 2378: #   ...
 2379: #   )
 2380: #
 2381: # Outputs: A scalar containing the html markup for the menu.
 2382: 
 2383: sub generate_menu {
 2384:     my @menu = @_;
 2385:     # subs for specific html elements
 2386:     my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) ); 
 2387:     
 2388:     my @categories; # each element represents the entire markup for a category
 2389:    
 2390:     foreach my $category (@menu) {
 2391:         my @links;  # contains the links for the current $category
 2392:         foreach my $link (@{$$category{items}}) {
 2393:             next unless $$link{permission};
 2394:             
 2395:             # create the markup for the current $link and push it into @links.
 2396:             # each entry consists of an image and a text optionally followed 
 2397:             # by a help link.
 2398:             my $src;
 2399:             if ($$link{icon} ne '') {
 2400:                 $src = '/res/adm/pages/'.$$link{icon};
 2401:             }
 2402:             push(@links,$li->(
 2403:                         $a->(
 2404:                             $img->("", {
 2405:                                 class => "LC_noBorder LC_middle",
 2406:                                 src   => $src,
 2407:                                 alt   => mt(defined($$link{alttext}) ?
 2408:                                 $$link{alttext} : $$link{linktext})
 2409:                             }), {
 2410:                             href  => $$link{url},
 2411:                             title => mt($$link{linktitle})
 2412:                             }).
 2413:                         $a->(mt($$link{linktext}), {
 2414:                             href  => $$link{url},
 2415:                             title => mt($$link{linktitle}),
 2416:                             class => "LC_menubuttons_link"
 2417:                             }).
 2418:                          (defined($$link{help}) ? 
 2419:                          Apache::loncommon::help_open_topic($$link{help}) : ''),
 2420:                          {class => "LC_menubuttons_inline_text"}));
 2421:         }
 2422: 
 2423:         # wrap categorytitle in <h3>, concatenate with 
 2424:         # joined and in <ul> tags wrapped @links
 2425:         # and wrap everything in an enclosing <div> and push it into
 2426:         # @categories
 2427:         # such that each element looks like:
 2428:         # <div><h3>title</h3><ul><li>...</li>...</ul></div>
 2429:         # the category won't be added if there aren't any links
 2430:         push(@categories, 
 2431:             $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
 2432:             $ul->(join('' ,@links),  {class =>"LC_ListStyleNormal" }),
 2433:             {class=>"LC_Box LC_400Box"})) if scalar(@links);
 2434:     }
 2435: 
 2436:     # wrap the joined @categories in another <div> (column layout)
 2437:     return $div->(join('', @categories), {class => "LC_columnSection"});
 2438: }
 2439: 
 2440: ##############################################
 2441: ##############################################
 2442: 
 2443: =pod
 2444: 
 2445: =item &start_funclist
 2446: 
 2447: Start list of available functions
 2448: 
 2449: Typically used to offer a simple list of available functions
 2450: at top or bottom of page.
 2451: All available functions/actions for the current page
 2452: should be included in this list.
 2453: 
 2454: If the optional headline text is not provided, a default text will be used.
 2455: 
 2456: 
 2457: Related routines:
 2458: =over 4
 2459: add_item_funclist
 2460: end_funclist
 2461: =back
 2462: 
 2463: 
 2464: Inputs: (optional) headline text
 2465: 
 2466: Returns: HTML code with function list start
 2467: 
 2468: =cut
 2469: 
 2470: ##############################################
 2471: ##############################################
 2472: 
 2473: sub start_funclist {
 2474:     my($legendtext)=@_;
 2475:     $legendtext=&mt('Functions') if !$legendtext;
 2476:     return '<ul class="LC_funclist"><li style="font-weight:bold; margin-left:0.8em;">'.$legendtext.'</li>'."\n";
 2477: }
 2478: 
 2479: 
 2480: ##############################################
 2481: ##############################################
 2482: 
 2483: =pod
 2484: 
 2485: =item &add_item_funclist
 2486: 
 2487: Adds an item to the list of available functions
 2488: 
 2489: Related routines:
 2490: =over 4
 2491: start_funclist
 2492: end_funclist
 2493: =back
 2494: 
 2495: Inputs: content item with text and link to function
 2496: 
 2497: Returns: HTML code with list item for funclist
 2498: 
 2499: =cut
 2500: 
 2501: ##############################################
 2502: ##############################################
 2503: 
 2504: sub add_item_funclist {
 2505:     my($content) = @_;
 2506:     return '<li>'.$content.'</li>'."\n";
 2507: }
 2508: 
 2509: =pod
 2510: 
 2511: =item &end_funclist
 2512: 
 2513: End list of available functions
 2514: 
 2515: Related routines:
 2516: =over 4
 2517: start_funclist
 2518: add_item_funclist
 2519: =back
 2520: 
 2521: Inputs: ./.
 2522: 
 2523: Returns: HTML code with function list end
 2524: =cut
 2525: 
 2526: sub end_funclist {
 2527:     return "</ul>\n";
 2528: }
 2529: 
 2530: =pod
 2531: 
 2532: =item funclist_from_array( \@array, {legend => 'text for legend'} )
 2533: 
 2534: Constructs a XHTML list from \@array with the first item being visually
 2535: highlighted and set to the value of legend or 'Functions' if legend is
 2536: empty.
 2537: 
 2538: =over
 2539: 
 2540: =item \@array
 2541: 
 2542: A reference to the array containing text that will be wrapped in <li></li> tags.
 2543: 
 2544: =item { legend => 'text' }
 2545: 
 2546: A string that's used as visually highlighted first item. 'Functions' is used if
 2547: it's value evaluates to false.
 2548: 
 2549: =back
 2550: 
 2551: returns: XHTML list as string.
 2552: 
 2553: =back
 2554: 
 2555: =cut
 2556: 
 2557: sub funclist_from_array {
 2558:     my ($items, $args) = @_;
 2559:     $args->{legend} ||= mt('Functions');
 2560:     return list_from_array( [$args->{legend}, @$items],
 2561:                { listattr => {class => 'LC_funclist'} });
 2562: }
 2563: 
 2564: 1;
 2565: 
 2566: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>