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

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

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