Annotation of loncom/interface/lonhtmlcommon.pm, revision 1.285

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

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