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

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

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