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

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

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