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

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # a pile of common html routines
                      3: #
1.316   ! raeburn     4: # $Id: lonhtmlcommon.pm,v 1.315 2012/05/28 19:05:21 raeburn Exp $
1.2       www         5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.10      matthew    28: ######################################################################
                     29: ######################################################################
                     30: 
                     31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::lonhtmlcommon - routines to do common html things
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Referenced by other mod_perl Apache modules.
                     40: 
                     41: =head1 INTRODUCTION
                     42: 
                     43: lonhtmlcommon is a collection of subroutines used to present information
                     44: in a consistent html format, or provide other functionality related to
                     45: html.
                     46: 
                     47: =head2 General Subroutines
                     48: 
                     49: =over 4
                     50: 
                     51: =cut 
                     52: 
                     53: ######################################################################
                     54: ######################################################################
1.2       www        55: 
1.1       stredwic   56: package Apache::lonhtmlcommon;
                     57: 
1.104     albertel   58: use strict;
1.10      matthew    59: use Time::Local;
1.47      sakharuk   60: use Time::HiRes;
1.30      www        61: use Apache::lonlocal;
1.104     albertel   62: use Apache::lonnet;
1.286     www        63: use HTML::Entities();
1.130     www        64: use LONCAPA;
1.1       stredwic   65: 
1.284     www        66: sub java_not_enabled {
                     67:    return "\n".'<span class="LC_error">'.
                     68:           &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
                     69:           "</span>\n";
                     70: }
1.247     www        71: 
                     72: sub coursepreflink {
                     73:    my ($text,$category)=@_;
                     74:    if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
1.296     www        75:       return '<a target="_top" href="'.&HTML::Entities::encode("/adm/courseprefs?phase=display&actions=$category",'<>&"').'"><span class="LC_setting">'.$text.'</span></a>';
1.247     www        76:    } else {
                     77:       return '';
                     78:    }
                     79: }
                     80: 
1.253     www        81: sub raw_href_to_link {
                     82:    my ($message)=@_;
1.264     faziophi   83:    $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/<a href="$1"><tt>$1<\/tt><\/a>$2/gi;
1.253     www        84:    return $message;
                     85: }
                     86: 
1.286     www        87: sub entity_encode {
                     88:     my ($text)=@_;
                     89:     return &HTML::Entities::encode($text, '<>&"');
                     90: }
                     91: 
                     92: sub direct_parm_link {
                     93:     my ($linktext,$symb,$filter,$part,$target)=@_;
                     94:     $symb=&entity_encode($symb);
                     95:     $filter=&entity_encode($filter);
                     96:     $part=&entity_encode($part);
                     97:     if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
1.315     raeburn    98:        return "<a target='_top' href='/adm/parmset?symb=$symb&amp;filter=$filter&amp;part=$part'><span class='LC_setting'>$linktext</span></a>";
1.286     www        99:     } else {
                    100:        return $linktext;
                    101:     }
                    102: }
1.208     www       103: ##############################################
                    104: ##############################################
                    105: 
1.309     raeburn   106: =item &confirm_success()
1.208     www       107: 
                    108: Successful completion of an operation message
                    109: 
                    110: =cut
                    111: 
                    112: sub confirm_success {
1.209     www       113:    my ($message,$failure)=@_;
                    114:    if ($failure) {
1.265     wenzelju  115:       return '<span class="LC_error" style="font-size: inherit;">'."\n"
1.218     bisitz    116:             .'<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.&mt('Error').'" /> '."\n"
1.211     bisitz    117:             .$message."\n"
                    118:             .'</span>'."\n";
1.209     www       119:    } else {
1.211     bisitz    120:       return '<span class="LC_success">'."\n"
1.233     raeburn   121:             .'<img src="/adm/lonIcons/navmap.correct.gif" alt="'.&mt('OK').'" /> '."\n"
1.211     bisitz    122:             .$message."\n"
                    123:             .'</span>'."\n";
1.209     www       124:    }
1.208     www       125: }
1.176     foxr      126: 
                    127: ##############################################
                    128: ##############################################
                    129: 
                    130: =pod
                    131: 
1.309     raeburn   132: =item &dragmath_button()
1.176     foxr      133: 
1.177     raeburn   134: Creates a button that launches a dragmath popup-window, in which an 
                    135: expression can be edited and pasted as LaTeX into a specified textarea. 
                    136: 
                    137:   textarea - Name of the textarea to edit.
                    138:   helpicon - If true, show a help icon to the right of the button.
1.176     foxr      139: 
                    140: =cut
                    141: 
1.177     raeburn   142: sub dragmath_button {
                    143:     my ($textarea,$helpicon) = @_;
                    144:     my $help_text; 
                    145:     if ($helpicon) {
1.282     raeburn   146:         $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
1.177     raeburn   147:     }
1.178     bisitz    148:     my $buttontext=&mt('Edit Math');
1.177     raeburn   149:     return <<ENDDRAGMATH;
1.246     bisitz    150:                 <input type="button" value="$buttontext" onclick="javascript:mathedit('$textarea',document)" />$help_text
1.177     raeburn   151: ENDDRAGMATH
                    152: }
                    153: 
1.176     foxr      154: ##############################################
                    155: 
1.177     raeburn   156: =pod
                    157: 
1.309     raeburn   158: =item &dragmath_js()
1.177     raeburn   159: 
                    160: Javascript used to open pop-up window containing dragmath applet which 
                    161: can be used to paste LaTeX into a textarea.
1.309     raeburn   162: 
1.177     raeburn   163: =cut
1.176     foxr      164: 
1.177     raeburn   165: sub dragmath_js {
1.182     foxr      166:     my ($popup) = @_;
1.177     raeburn   167:     return <<ENDDRAGMATHJS;
                    168:                 <script type="text/javascript">
1.218     bisitz    169:                 // <![CDATA[
1.176     foxr      170:                   function mathedit(textarea, doc) {
                    171:                      targetEntry = textarea;
1.177     raeburn   172:                      targetDoc   = doc;
1.182     foxr      173:                      newwin  = window.open("/adm/dragmath/applet/$popup.html","","width=565,height=500,resizable");
1.176     foxr      174:                   }
1.218     bisitz    175:                 // ]]>
1.176     foxr      176:                 </script>
1.177     raeburn   177: 
                    178: ENDDRAGMATHJS
1.176     foxr      179: }
                    180: 
1.309     raeburn   181: ##############################################
                    182: ##############################################
                    183: 
                    184: =pod
                    185: 
                    186: =item &dependencies_button()
                    187: 
                    188: Creates a button that launches a popup-window, in which dependencies  
                    189: for the web page in the main window can be added to, replaced or deleted.  
                    190: 
                    191: =cut
                    192: 
                    193: sub dependencies_button {
                    194:     my $buttontext=&mt('Manage Dependencies');
                    195:     return <<"END";
                    196:                 <input type="button" value="$buttontext" onclick="javascript:dependencycheck();" />
                    197: END
                    198: }
                    199: 
                    200: ##############################################
                    201: 
                    202: =pod
                    203: 
                    204: =item &dependencycheck_js()
                    205: 
                    206: Javascript used to open pop-up window containing interface to manage 
                    207: dependencies for a web page uploaded diretcly to a course.
                    208: 
                    209: =cut
                    210: 
                    211: sub dependencycheck_js {
                    212:     my ($symb,$title) = @_;
                    213:     my $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"').
                    214:                '&title='.&HTML::Entities::encode($title,'<>&"');
                    215:     return <<ENDJS;
                    216:                 <script type="text/javascript">
                    217:                 // <![CDATA[
                    218:                   function dependencycheck() {
                    219:                      depwin  = window.open("$link","","width=750,height=500,resizable,scrollbars=yes");
                    220:                   }
                    221:                 // ]]>
                    222:                 </script>
                    223: ENDJS
                    224: }
1.182     foxr      225: 
1.40      www       226: ##############################################
                    227: ##############################################
                    228: 
                    229: =pod
                    230: 
1.309     raeburn   231: =item &authorbombs()
1.40      www       232: 
                    233: =cut
                    234: 
                    235: ##############################################
                    236: ##############################################
                    237: 
                    238: sub authorbombs {
                    239:     my $url=shift;
                    240:     $url=&Apache::lonnet::declutter($url);
1.155     albertel  241:     my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
1.40      www       242:     my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
1.232     raeburn   243:     foreach my $bomb (keys(%bombs)) {
                    244: 	if ($bomb =~ /^$udom\/$uname\//) {
1.40      www       245: 	    return '<a href="/adm/bombs/'.$url.
1.218     bisitz    246: 		'"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/bomb.gif').'" alt="'.&mt('Bomb').'" border="0" /></a>'.
1.40      www       247: 		&Apache::loncommon::help_open_topic('About_Bombs');
                    248: 	}
                    249:     }
                    250:     return '';
                    251: }
1.26      matthew   252: 
                    253: ##############################################
                    254: ##############################################
                    255: 
1.41      www       256: sub recent_filename {
                    257:     my $area=shift;
1.130     www       258:     return 'nohist_recent_'.&escape($area);
1.41      www       259: }
                    260: 
                    261: sub store_recent {
1.136     albertel  262:     my ($area,$name,$value,$freeze)=@_;
1.41      www       263:     my $file=&recent_filename($area);
                    264:     my %recent=&Apache::lonnet::dump($file);
1.111     www       265:     if (scalar(keys(%recent))>20) {
1.41      www       266: # remove oldest value
1.136     albertel  267: 	my $oldest=time();
1.41      www       268: 	my $delkey='';
1.136     albertel  269: 	foreach my $item (keys(%recent)) {
                    270: 	    my $thistime=(split(/\&/,$recent{$item}))[0];
                    271: 	    if (($thistime ne "always_include") && ($thistime<$oldest)) {
1.41      www       272: 		$oldest=$thistime;
1.136     albertel  273: 		$delkey=$item;
1.41      www       274: 	    }
                    275: 	}
                    276: 	&Apache::lonnet::del($file,[$delkey]);
                    277:     }
                    278: # store new value
1.136     albertel  279:     my $timestamp;
                    280:     if ($freeze) {
                    281:         $timestamp = "always_include";
                    282:     } else {
                    283:         $timestamp = time();
                    284:     }   
1.41      www       285:     &Apache::lonnet::put($file,{ $name => 
1.136     albertel  286: 				 $timestamp.'&'.&escape($value) });
1.41      www       287: }
                    288: 
1.89      banghart  289: sub remove_recent {
                    290:     my ($area,$names)=@_;
                    291:     my $file=&recent_filename($area);
                    292:     return &Apache::lonnet::del($file,$names);
                    293: }
                    294: 
1.41      www       295: sub select_recent {
                    296:     my ($area,$fieldname,$event)=@_;
                    297:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
                    298:     my $return="\n<select name='$fieldname'".
1.96      albertel  299: 	($event?" onchange='$event'":'').
1.41      www       300: 	">\n<option value=''>--- ".&mt('Recent')." ---</option>";
1.136     albertel  301:     foreach my $value (sort(keys(%recent))) {
                    302: 	unless ($value =~/^error\:/) {
                    303: 	    my $escaped = &Apache::loncommon::escape_url($value);
1.160     albertel  304: 	    &Apache::loncommon::inhibit_menu_check(\$escaped);
1.251     raeburn   305:             if ($area eq 'residx') {
                    306:                 next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
                    307:             }
1.94      foxr      308: 	    $return.="\n<option value='$escaped'>".
1.136     albertel  309: 		&unescape((split(/\&/,$recent{$value}))[1]).
1.41      www       310: 		'</option>';
                    311: 	}
                    312:     }
                    313:     $return.="\n</select>\n";
                    314:     return $return;
                    315: }
                    316: 
1.97      albertel  317: sub get_recent {
                    318:     my ($area, $n) = @_;
                    319:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
                    320: 
                    321: # Create hash with key as time and recent as value
1.136     albertel  322: # Begin filling return_hash with any 'always_include' option
1.97      albertel  323:     my %time_hash = ();
1.136     albertel  324:     my %return_hash = ();
1.232     raeburn   325:     foreach my $item (keys(%recent)) {
1.136     albertel  326:         my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
                    327:         if ($thistime eq 'always_include') {
                    328:             $return_hash{$item} = &unescape($thisvalue);
                    329:             $n--;
                    330:         } else {
                    331:             $time_hash{$thistime} = $item;
1.133     albertel  332:         }
1.97      albertel  333:     }
                    334: 
                    335: # Sort by decreasing time and return key value pairs
                    336:     my $idx = 1;
1.136     albertel  337:     foreach my $item (reverse(sort(keys(%time_hash)))) {
                    338:        $return_hash{$time_hash{$item}} =
                    339:                   &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
1.97      albertel  340:        if ($n && ($idx++ >= $n)) {last;}
                    341:     }
                    342: 
                    343:     return %return_hash;
                    344: }
                    345: 
1.136     albertel  346: sub get_recent_frozen {
                    347:     my ($area) = @_;
                    348:     my %recent=&Apache::lonnet::dump(&recent_filename($area));
                    349: 
                    350: # Create hash with all 'frozen' items
                    351:     my %return_hash = ();
                    352:     foreach my $item (keys(%recent)) {
                    353:         my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
                    354:         if ($thistime eq 'always_include') {
                    355:             $return_hash{$item} = &unescape($thisvalue);
                    356:         }
                    357:     }
                    358:     return %return_hash;
                    359: }
                    360: 
1.97      albertel  361: 
1.41      www       362: 
1.26      matthew   363: =pod
                    364: 
1.309     raeburn   365: =item &textbox()
1.26      matthew   366: 
                    367: =cut
                    368: 
                    369: ##############################################
                    370: ##############################################
                    371: sub textbox {
                    372:     my ($name,$value,$size,$special) = @_;
                    373:     $size = 40 if (! defined($size));
1.128     albertel  374:     $value = &HTML::Entities::encode($value,'<>&"');
1.26      matthew   375:     my $Str = '<input type="text" name="'.$name.'" size="'.$size.'" '.
                    376:         'value="'.$value.'" '.$special.' />';
                    377:     return $Str;
                    378: }
                    379: 
                    380: ##############################################
                    381: ##############################################
                    382: 
                    383: =pod
                    384: 
1.309     raeburn   385: =item &checkbox()
1.26      matthew   386: 
                    387: =cut
                    388: 
                    389: ##############################################
                    390: ##############################################
                    391: sub checkbox {
1.68      matthew   392:     my ($name,$checked,$value) = @_;
                    393:     my $Str = '<input type="checkbox" name="'.$name.'" ';
                    394:     if (defined($value)) {
                    395:         $Str .= 'value="'.$value.'"';
                    396:     } 
                    397:     if ($checked) {
1.206     bisitz    398:         $Str .= ' checked="checked"';
1.68      matthew   399:     }
                    400:     $Str .= ' />';
1.26      matthew   401:     return $Str;
                    402: }
                    403: 
1.120     albertel  404: 
                    405: =pod
                    406: 
1.309     raeburn   407: =item &radiobutton()
1.120     albertel  408: 
                    409: =cut
                    410: 
                    411: ##############################################
                    412: ##############################################
                    413: sub radio {
                    414:     my ($name,$checked,$value) = @_;
                    415:     my $Str = '<input type="radio" name="'.$name.'" ';
                    416:     if (defined($value)) {
                    417:         $Str .= 'value="'.$value.'"';
                    418:     } 
                    419:     if ($checked eq $value) {
1.206     bisitz    420:         $Str .= ' checked="checked"';
1.120     albertel  421:     }
                    422:     $Str .= ' />';
                    423:     return $Str;
                    424: }
                    425: 
1.10      matthew   426: ##############################################
                    427: ##############################################
                    428: 
                    429: =pod
                    430: 
1.309     raeburn   431: =item &date_setter()
1.10      matthew   432: 
1.22      matthew   433: &date_setter returns html and javascript for a compact date-setting form.
1.309     raeburn   434: To retrieve values from it, use &get_date_from_form.
1.22      matthew   435: 
1.10      matthew   436: Inputs
                    437: 
                    438: =over 4
                    439: 
                    440: =item $dname 
                    441: 
                    442: The name to prepend to the form elements.  
                    443: The form elements defined will be dname_year, dname_month, dname_day,
                    444: dname_hour, dname_min, and dname_sec.
                    445: 
                    446: =item $currentvalue
                    447: 
                    448: The current setting for this time parameter.  A unix format time
                    449: (time in seconds since the beginning of Jan 1st, 1970, GMT.  
1.257     faziophi  450: An undefined value is taken to indicate the value is the current time
                    451: unless it is requested to leave it empty. See $includeempty.
1.10      matthew   452: Also, to be explicit, a value of 'now' also indicates the current time.
                    453: 
1.26      matthew   454: =item $special
                    455: 
                    456: Additional html/javascript to be associated with each element in
                    457: the date_setter.  See lonparmset for example usage.
                    458: 
1.59      matthew   459: =item $includeempty 
                    460: 
1.257     faziophi  461: If it is set (true) and no date/time value is provided,
                    462: the date/time fields are left empty.
                    463: 
1.59      matthew   464: =item $state
                    465: 
                    466: Specifies the initial state of the form elements.  Either 'disabled' or empty.
                    467: Defaults to empty, which indiciates the form elements are not disabled. 
                    468: 
1.22      matthew   469: =back
                    470: 
                    471: Bugs
                    472: 
                    473: The method used to restrict user input will fail in the year 2400.
                    474: 
1.10      matthew   475: =cut
                    476: 
                    477: ##############################################
                    478: ##############################################
                    479: sub date_setter {
1.67      matthew   480:     my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
1.134     raeburn   481:         $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
1.175     raeburn   482:     my $now = time;
1.257     faziophi  483: 
                    484:     my $tzname;
                    485:     my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
                    486:     #other potentially useful values:    wkday,yrday,is_daylight_savings
                    487: 
1.59      matthew   488:     if (! defined($state) || $state ne 'disabled') {
                    489:         $state = '';
                    490:     }
1.67      matthew   491:     if (! defined($no_hh_mm_ss)) {
                    492:         $no_hh_mm_ss = 0;
                    493:     }
1.110     www       494:     if ($currentvalue eq 'now') {
1.257     faziophi  495:         $currentvalue = $now;
1.110     www       496:     }
1.257     faziophi  497:     
                    498:     # Default value: Set empty date field to current time
                    499:     # unless empty inclusion is requested
                    500:     if ((!$includeempty) && (!$currentvalue)) {
                    501:         $currentvalue = $now;
1.10      matthew   502:     }
1.257     faziophi  503:     # Do we have a date? Split it!
1.39      www       504:     if ($currentvalue) {
1.257     faziophi  505: 	($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
                    506: 
                    507:         #No values provided for hour, min, sec? Use default 0
                    508:         if (($defhour) || ($defmin) || ($defsec)) {
                    509:             $sec  = ($defsec  ? $defsec  : 0);
                    510:             $min  = ($defmin  ? $defmin  : 0);
                    511:             $hour = ($defhour ? $defhour : 0);
                    512:         }
1.107     www       513:     }
1.10      matthew   514:     my $result = "\n<!-- $dname date setting form -->\n";
                    515:     $result .= <<ENDJS;
1.135     albertel  516: <script type="text/javascript">
1.218     bisitz    517: // <![CDATA[
1.10      matthew   518:     function $dname\_checkday() {
                    519:         var day   = document.$formname.$dname\_day.value;
                    520:         var month = document.$formname.$dname\_month.value;
                    521:         var year  = document.$formname.$dname\_year.value;
                    522:         var valid = true;
                    523:         if (day < 1) {
                    524:             document.$formname.$dname\_day.value = 1;
                    525:         } 
                    526:         if (day > 31) {
                    527:             document.$formname.$dname\_day.value = 31;
                    528:         }
                    529:         if ((month == 1)  || (month == 3)  || (month == 5)  ||
                    530:             (month == 7)  || (month == 8)  || (month == 10) ||
                    531:             (month == 12)) {
                    532:             if (day > 31) {
                    533:                 document.$formname.$dname\_day.value = 31;
                    534:                 day = 31;
                    535:             }
                    536:         } else if (month == 2 ) {
                    537:             if ((year % 4 == 0) && (year % 100 != 0)) {
                    538:                 if (day > 29) {
                    539:                     document.$formname.$dname\_day.value = 29;
                    540:                 }
                    541:             } else if (day > 29) {
                    542:                 document.$formname.$dname\_day.value = 28;
                    543:             }
                    544:         } else if (day > 30) {
                    545:             document.$formname.$dname\_day.value = 30;
                    546:         }
                    547:     }
1.95      matthew   548:     
1.59      matthew   549:     function $dname\_disable() {
                    550:         document.$formname.$dname\_month.disabled=true;
                    551:         document.$formname.$dname\_day.disabled=true;
                    552:         document.$formname.$dname\_year.disabled=true;
                    553:         document.$formname.$dname\_hour.disabled=true;
                    554:         document.$formname.$dname\_minute.disabled=true;
                    555:         document.$formname.$dname\_second.disabled=true;
                    556:     }
                    557: 
                    558:     function $dname\_enable() {
                    559:         document.$formname.$dname\_month.disabled=false;
                    560:         document.$formname.$dname\_day.disabled=false;
                    561:         document.$formname.$dname\_year.disabled=false;
                    562:         document.$formname.$dname\_hour.disabled=false;
                    563:         document.$formname.$dname\_minute.disabled=false;
                    564:         document.$formname.$dname\_second.disabled=false;        
                    565:     }
                    566: 
1.29      www       567:     function $dname\_opencalendar() {
1.59      matthew   568:         if (! document.$formname.$dname\_month.disabled) {
                    569:             var calwin=window.open(
1.29      www       570: "/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
                    571: document.$formname.$dname\_month.value+"&year="+
                    572: document.$formname.$dname\_year.value,
                    573:              "LONCAPAcal",
                    574:               "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
1.59      matthew   575:         }
1.29      www       576: 
                    577:     }
1.218     bisitz    578: // ]]>
1.10      matthew   579: </script>
                    580: ENDJS
1.192     bisitz    581:     $result .= '  <span class="LC_nobreak">';
1.96      albertel  582:     my $monthselector = qq{<select name="$dname\_month" $special $state onchange="javascript:$dname\_checkday()" >};
1.67      matthew   583:     # Month
1.10      matthew   584:     my @Months = qw/January February  March     April   May      June 
                    585:                     July    August    September October November December/;
                    586:     # Pad @Months with a bogus value to make indexing easier
                    587:     unshift(@Months,'If you can read this an error occurred');
1.95      matthew   588:     if ($includeempty) { $monthselector.="<option value=''></option>"; }
1.10      matthew   589:     for(my $m = 1;$m <=$#Months;$m++) {
1.228     bisitz    590:         $monthselector .= qq{      <option value="$m"};
                    591:         $monthselector .= ' selected="selected"' if ($m-1 eq $month);
                    592:         $monthselector .= '> '.&mt($Months[$m]).' </option>'."\n";
1.10      matthew   593:     }
1.95      matthew   594:     $monthselector.= '  </select>';
1.67      matthew   595:     # Day
1.96      albertel  596:     my $dayselector = qq{<input type="text" name="$dname\_day" $state value="$mday" size="3" $special onchange="javascript:$dname\_checkday()" />};
1.67      matthew   597:     # Year
1.226     bisitz    598:     my $yearselector = qq{<input type="text" name="$dname\_year" $state value="$year" size="5" $special onchange="javascript:$dname\_checkday()" />};
1.95      matthew   599:     #
                    600:     my $hourselector = qq{<select name="$dname\_hour" $special $state >};
                    601:     if ($includeempty) { 
                    602:         $hourselector.=qq{<option value=''></option>};
                    603:     }
                    604:     for (my $h = 0;$h<24;$h++) {
1.228     bisitz    605:         $hourselector .= qq{<option value="$h"};
                    606:         $hourselector .= ' selected="selected"' if (defined($hour) && $hour == $h);
1.95      matthew   607:         $hourselector .= ">";
                    608:         my $timest='';
                    609:         if ($h == 0) {
                    610:             $timest .= "12 am";
                    611:         } elsif($h == 12) {
                    612:             $timest .= "12 noon";
                    613:         } elsif($h < 12) {
                    614:             $timest .= "$h am";
                    615:         } else {
                    616:             $timest .= $h-12 ." pm";
                    617:         }
                    618:         $timest=&mt($timest);
                    619:         $hourselector .= $timest." </option>\n";
                    620:     }
                    621:     $hourselector .= "  </select>\n";
                    622:     my $minuteselector = qq{<input type="text" name="$dname\_minute" $special $state value="$min" size="3" />};
                    623:     my $secondselector= qq{<input type="text" name="$dname\_second" $special $state value="$sec" size="3" />};
1.134     raeburn   624:     my $cal_link;
                    625:     if (!$nolink) {
                    626:         $cal_link = qq{<a href="javascript:$dname\_opencalendar()">};
                    627:     }
1.95      matthew   628:     #
1.175     raeburn   629:     my $tzone = ' '.$tzname.' ';
1.95      matthew   630:     if ($no_hh_mm_ss) {
1.134     raeburn   631:         $result .= &mt('[_1] [_2] [_3] ',
1.174     raeburn   632:                        $monthselector,$dayselector,$yearselector).
                    633:                    $tzone;
1.134     raeburn   634:         if (!$nolink) {
1.141     albertel  635:             $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134     raeburn   636:         }
1.95      matthew   637:     } else {
1.134     raeburn   638:         $result .= &mt('[_1] [_2] [_3] [_4] [_5]m [_6]s ',
                    639:                       $monthselector,$dayselector,$yearselector,
1.174     raeburn   640:                       $hourselector,$minuteselector,$secondselector).
                    641:                    $tzone;
1.134     raeburn   642:         if (!$nolink) {
1.141     albertel  643:             $result .= &mt('[_1]Select Date[_2]',$cal_link,'</a>');
1.134     raeburn   644:         }
1.67      matthew   645:     }
1.135     albertel  646:     $result .= "</span>\n<!-- end $dname date setting form -->\n";
1.10      matthew   647:     return $result;
                    648: }
                    649: 
1.175     raeburn   650: sub get_timedates {
                    651:     my ($epoch) = @_;
                    652:     my $dt = DateTime->from_epoch(epoch => $epoch)
                    653:                      ->set_time_zone(&Apache::lonlocal::gettimezone());
                    654:     my $tzname = $dt->time_zone_short_name();
                    655:     my $sec = $dt->second;
                    656:     my $min = $dt->minute;
                    657:     my $hour = $dt->hour;
                    658:     my $mday = $dt->day;
                    659:     my $month = $dt->month;
                    660:     if ($month) {
                    661:         $month --;
                    662:     }
                    663:     my $year = $dt->year;
                    664:     return ($tzname,$sec,$min,$hour,$mday,$month,$year);
                    665: }
1.166     banghart  666: 
                    667: sub build_url {
                    668:     my ($base, $fields)=@_;
                    669:     my $url;
                    670:     $url = $base.'?';
1.168     albertel  671:     foreach my $key (keys(%$fields)) {
                    672:         $url.=&escape($key).'='.&escape($$fields{$key}).'&amp;';
1.166     banghart  673:     }
                    674:     $url =~ s/&amp;$//;
                    675:     return $url;
                    676: }
                    677: 
                    678: 
1.10      matthew   679: ##############################################
                    680: ##############################################
                    681: 
1.22      matthew   682: =pod
                    683: 
1.309     raeburn   684: =item &get_date_from_form()
1.22      matthew   685: 
                    686: get_date_from_form retrieves the date specified in an &date_setter form.
1.10      matthew   687: 
                    688: Inputs:
                    689: 
                    690: =over 4
                    691: 
                    692: =item $dname
                    693: 
1.226     bisitz    694: The name passed to &date_setter, which prefixes the form elements.
1.10      matthew   695: 
                    696: =item $defaulttime
                    697: 
                    698: The unix time to use as the default in case of poor inputs.
                    699: 
                    700: =back
                    701: 
                    702: Returns: Unix time represented in the form.
                    703: 
                    704: =cut
                    705: 
                    706: ##############################################
                    707: ##############################################
                    708: sub get_date_from_form {
                    709:     my ($dname) = @_;
                    710:     my ($sec,$min,$hour,$day,$month,$year);
                    711:     #
1.104     albertel  712:     if (defined($env{'form.'.$dname.'_second'})) {
                    713:         my $tmpsec = $env{'form.'.$dname.'_second'};
1.10      matthew   714:         if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
                    715:             $sec = $tmpsec;
                    716:         }
1.64      albertel  717: 	if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
1.67      matthew   718:     } else {
                    719:         $sec = 0;
1.10      matthew   720:     }
1.104     albertel  721:     if (defined($env{'form.'.$dname.'_minute'})) {
                    722:         my $tmpmin = $env{'form.'.$dname.'_minute'};
1.10      matthew   723:         if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
                    724:             $min = $tmpmin;
                    725:         }
1.64      albertel  726: 	if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
1.67      matthew   727:     } else {
                    728:         $min = 0;
1.10      matthew   729:     }
1.104     albertel  730:     if (defined($env{'form.'.$dname.'_hour'})) {
                    731:         my $tmphour = $env{'form.'.$dname.'_hour'};
1.33      matthew   732:         if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
1.10      matthew   733:             $hour = $tmphour;
                    734:         }
1.67      matthew   735:     } else {
                    736:         $hour = 0;
1.10      matthew   737:     }
1.104     albertel  738:     if (defined($env{'form.'.$dname.'_day'})) {
                    739:         my $tmpday = $env{'form.'.$dname.'_day'};
1.10      matthew   740:         if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
                    741:             $day = $tmpday;
                    742:         }
                    743:     }
1.104     albertel  744:     if (defined($env{'form.'.$dname.'_month'})) {
                    745:         my $tmpmonth = $env{'form.'.$dname.'_month'};
1.10      matthew   746:         if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
1.175     raeburn   747:             $month = $tmpmonth;
1.10      matthew   748:         }
                    749:     }
1.104     albertel  750:     if (defined($env{'form.'.$dname.'_year'})) {
                    751:         my $tmpyear = $env{'form.'.$dname.'_year'};
1.175     raeburn   752:         if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
                    753:             $year = $tmpyear;
1.10      matthew   754:         }
                    755:     }
1.175     raeburn   756:     if (($year<1970) || ($year>2037)) { return undef; }
1.33      matthew   757:     if (defined($sec) && defined($min)   && defined($hour) &&
1.175     raeburn   758:         defined($day) && defined($month) && defined($year)) {
                    759:         my $timezone = &Apache::lonlocal::gettimezone();
                    760:         my $dt = DateTime->new( year   => $year,
                    761:                                 month  => $month,
                    762:                                 day    => $day,
                    763:                                 hour   => $hour,
                    764:                                 minute => $min,
                    765:                                 second => $sec,
                    766:                                 time_zone => $timezone,
                    767:                               );
                    768:         my $epoch_time  = $dt->epoch;
                    769:         if ($epoch_time ne '') {
                    770:             return $epoch_time;
                    771:         } else {
                    772:             return undef;
                    773:         }
1.10      matthew   774:     } else {
                    775:         return undef;
                    776:     }
1.20      matthew   777: }
                    778: 
                    779: ##############################################
                    780: ##############################################
                    781: 
                    782: =pod
                    783: 
                    784: =item &pjump_javascript_definition()
                    785: 
                    786: Returns javascript defining the 'pjump' function, which opens up a
                    787: parameter setting wizard.
                    788: 
                    789: =cut
                    790: 
                    791: ##############################################
                    792: ##############################################
                    793: sub pjump_javascript_definition {
                    794:     my $Str = <<END;
1.109     www       795:     function pjump(type,dis,value,marker,ret,call,hour,min,sec) {
1.295     www       796:         openMyModal("/adm/rat/parameter.html?type="+escape(type)
1.20      matthew   797:                  +"&value="+escape(value)+"&marker="+escape(marker)
                    798:                  +"&return="+escape(ret)
1.109     www       799:                  +"&call="+escape(call)+"&name="+escape(dis)
                    800:                  +"&defhour="+escape(hour)+"&defmin="+escape(min)
1.295     www       801:                  +"&defsec="+escape(sec)+"&modal=1",350,350,'no');
1.20      matthew   802:     }
                    803: END
                    804:     return $Str;
1.10      matthew   805: }
                    806: 
                    807: ##############################################
                    808: ##############################################
1.17      matthew   809: 
                    810: =pod
                    811: 
                    812: =item &javascript_nothing()
                    813: 
                    814: Return an appropriate null for the users browser.  This is used
                    815: as the first arguement for window.open calls when you want a blank
                    816: window that you can then write to.
                    817: 
                    818: =cut
                    819: 
                    820: ##############################################
                    821: ##############################################
                    822: sub javascript_nothing {
                    823:     # mozilla and other browsers work with "''", but IE on mac does not.
                    824:     my $nothing = "''";
                    825:     my $user_browser;
                    826:     my $user_os;
1.104     albertel  827:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
                    828:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
1.17      matthew   829:     if (! defined($user_browser) || ! defined($user_os)) {
                    830:         (undef,$user_browser,undef,undef,undef,$user_os) = 
                    831:                            &Apache::loncommon::decode_user_agent();
                    832:     }
                    833:     if ($user_browser eq 'explorer' && $user_os =~ 'mac') {
                    834:         $nothing = "'javascript:void(0);'";
                    835:     }
                    836:     return $nothing;
                    837: }
                    838: 
1.90      www       839: ##############################################
                    840: ##############################################
                    841: sub javascript_docopen {
1.171     albertel  842:     my ($mimetype) = @_;
                    843:     $mimetype ||= 'text/html';
1.90      www       844:     # safari does not understand document.open() and loads "text/html"
                    845:     my $nothing = "''";
                    846:     my $user_browser;
                    847:     my $user_os;
1.104     albertel  848:     $user_browser = $env{'browser.type'} if (exists($env{'browser.type'}));
                    849:     $user_os      = $env{'browser.os'}   if (exists($env{'browser.os'}));
1.90      www       850:     if (! defined($user_browser) || ! defined($user_os)) {
                    851:         (undef,$user_browser,undef,undef,undef,$user_os) = 
                    852:                            &Apache::loncommon::decode_user_agent();
                    853:     }
                    854:     if ($user_browser eq 'safari' && $user_os =~ 'mac') {
                    855:         $nothing = "document.clear()";
                    856:     } else {
1.171     albertel  857: 	$nothing = "document.open('$mimetype','replace')";
1.90      www       858:     }
                    859:     return $nothing;
                    860: }
                    861: 
1.21      matthew   862: 
1.17      matthew   863: ##############################################
                    864: ##############################################
                    865: 
1.21      matthew   866: =pod
1.17      matthew   867: 
1.21      matthew   868: =item &StatusOptions()
1.10      matthew   869: 
1.21      matthew   870: Returns html for a selection box which allows the user to choose the
                    871: enrollment status of students.  The selection box name is 'Status'.
1.6       stredwic  872: 
1.21      matthew   873: Inputs:
1.6       stredwic  874: 
1.21      matthew   875: $status: the currently selected status.  If undefined the value of
1.104     albertel  876: $env{'form.Status'} is taken.  If that is undefined, a value of 'Active'
1.21      matthew   877: is used.
1.6       stredwic  878: 
1.21      matthew   879: $formname: The name of the form.  If defined the onchange attribute of
                    880: the selection box is set to document.$formname.submit().
1.6       stredwic  881: 
1.21      matthew   882: $size: the size (number of lines) of the selection box.
1.6       stredwic  883: 
1.27      matthew   884: $onchange: javascript to use when the value is changed.  Enclosed in 
                    885: double quotes, ""s, not single quotes.
                    886: 
1.21      matthew   887: Returns: a perl string as described.
1.1       stredwic  888: 
1.21      matthew   889: =cut
1.9       stredwic  890: 
1.21      matthew   891: ##############################################
                    892: ##############################################
                    893: sub StatusOptions {
1.165     banghart  894:     my ($status, $formName,$size,$onchange,$mult)=@_;
1.21      matthew   895:     $size = 1 if (!defined($size));
                    896:     if (! defined($status)) {
                    897:         $status = 'Active';
1.104     albertel  898:         $status = $env{'form.Status'} if (exists($env{'form.Status'}));
1.9       stredwic  899:     }
1.1       stredwic  900: 
                    901:     my $Str = '';
                    902:     $Str .= '<select name="Status"';
1.165     banghart  903:     if (defined($mult)){
                    904:         $Str .= ' multiple="multiple" ';
                    905:     }
1.27      matthew   906:     if(defined($formName) && $formName ne '' && ! defined($onchange)) {
1.1       stredwic  907:         $Str .= ' onchange="document.'.$formName.'.submit()"';
1.27      matthew   908:     }
                    909:     if (defined($onchange)) {
                    910:         $Str .= ' onchange="'.$onchange.'"';
1.1       stredwic  911:     }
1.21      matthew   912:     $Str .= ' size="'.$size.'" ';
1.1       stredwic  913:     $Str .= '>'."\n";
1.153     raeburn   914:     foreach my $type (['Active',  &mt('Currently Has Access')],
                    915: 		      ['Future',  &mt('Will Have Future Access')],
                    916: 		      ['Expired', &mt('Previously Had Access')],
                    917: 		      ['Any',     &mt('Any Access Status')]) {
1.151     albertel  918: 	my ($name,$label) = @$type;
                    919: 	$Str .= '<option value="'.$name.'" ';
                    920: 	if ($status eq $name) {
                    921: 	    $Str .= 'selected="selected" ';
                    922: 	}
                    923: 	$Str .= '>'.$label.'</option>'."\n";
                    924:     }
                    925: 
1.1       stredwic  926:     $Str .= '</select>'."\n";
1.7       stredwic  927: }
1.12      matthew   928: 
                    929: ########################################################
                    930: ########################################################
1.7       stredwic  931: 
1.23      matthew   932: =pod
                    933: 
                    934: =item Progess Window Handling Routines
                    935: 
                    936: These routines handle the creation, update, increment, and closure of 
                    937: progress windows.  The progress window reports to the user the number
                    938: of items completed and an estimate of the time required to complete the rest.
                    939: 
                    940: =over 4
                    941: 
                    942: 
1.309     raeburn   943: =item &Create_PrgWin()
1.23      matthew   944: 
                    945: Writes javascript to the client to open a progress window and returns a
                    946: data structure used for bookkeeping.
                    947: 
                    948: Inputs
                    949: 
                    950: =over 4
                    951: 
                    952: =item $r Apache request
                    953: 
                    954: =item $number_to_do The total number of items being processed.
1.50      albertel  955: 
1.23      matthew   956: =back
                    957: 
                    958: Returns a hash containing the progress state data structure.
                    959: 
                    960: 
1.309     raeburn   961: =item &Update_PrgWin()
1.23      matthew   962: 
                    963: Updates the text in the progress indicator.  Does not increment the count.
                    964: See &Increment_PrgWin.
                    965: 
                    966: Inputs:
                    967: 
                    968: =over 4
                    969: 
                    970: =item $r Apache request
                    971: 
                    972: =item $prog_state Pointer to the data structure returned by &Create_PrgWin
                    973: 
                    974: =item $displaystring The string to write to the status indicator
                    975: 
                    976: =back
                    977: 
                    978: Returns: none
                    979: 
                    980: 
1.309     raeburn   981: =item Increment_PrgWin()
1.23      matthew   982: 
1.276     bisitz    983: Increment the count of items completed for the progress window by $step or 1 if no step is provided.
1.23      matthew   984: 
                    985: Inputs:
                    986: 
                    987: =over 4
                    988: 
                    989: =item $r Apache request
                    990: 
                    991: =item $prog_state Pointer to the data structure returned by Create_PrgWin
                    992: 
                    993: =item $extraInfo A description of the items being iterated over.  Typically
                    994: 'student'.
                    995: 
1.279     bisitz    996: =item $step (optional) counter step. Will be set to default 1 if ommited. step must be greater than 0 or empty.
1.276     bisitz    997: 
1.23      matthew   998: =back
                    999: 
                   1000: Returns: none
                   1001: 
                   1002: 
1.309     raeburn  1003: =item &Close_PrgWin()
1.23      matthew  1004: 
                   1005: Closes the progress window.
                   1006: 
                   1007: Inputs:
                   1008: 
                   1009: =over 4 
                   1010: 
                   1011: =item $r Apache request
                   1012: 
                   1013: =item $prog_state Pointer to the data structure returned by Create_PrgWin
                   1014: 
                   1015: =back
                   1016: 
                   1017: Returns: none
                   1018: 
                   1019: =back
                   1020: 
                   1021: =cut
                   1022: 
                   1023: ########################################################
                   1024: ########################################################
                   1025: 
1.51      albertel 1026: 
1.7       stredwic 1027: # Create progress
                   1028: sub Create_PrgWin {
1.297     www      1029:     my ($r,$number_to_do)=@_;
1.49      albertel 1030:     my %prog_state;
1.16      albertel 1031:     $prog_state{'done'}=0;
1.23      matthew  1032:     $prog_state{'firststart'}=&Time::HiRes::time();
                   1033:     $prog_state{'laststart'}=&Time::HiRes::time();
1.16      albertel 1034:     $prog_state{'max'}=$number_to_do;
1.297     www      1035:     &Apache::loncommon::LCprogressbar($r); 
1.14      albertel 1036:     return %prog_state;
1.7       stredwic 1037: }
                   1038: 
                   1039: # update progress
                   1040: sub Update_PrgWin {
1.14      albertel 1041:     my ($r,$prog_state,$displayString)=@_;
1.297     www      1042:     &Apache::loncommon::LCprogressbarUpdate($r,undef,$displayString);
1.23      matthew  1043:     $$prog_state{'laststart'}=&Time::HiRes::time();
1.14      albertel 1044: }
                   1045: 
                   1046: # increment progress state
                   1047: sub Increment_PrgWin {
1.275     bisitz   1048:     my ($r,$prog_state,$extraInfo,$step)=@_;
1.279     bisitz   1049:     $step = $step > 0 ? $step : 1;
1.275     bisitz   1050:     $$prog_state{'done'} += $step;
                   1051: 
                   1052:     # Catch (max modulo step) <> 0
                   1053:     my $current = $$prog_state{'done'};
                   1054:     my $last = ($$prog_state{'max'} - $current);
                   1055:     if ($last <= 0) {
                   1056:         $last = 1;
                   1057:         $current = $$prog_state{'max'};
                   1058:     }
                   1059: 
1.23      matthew  1060:     my $time_est= (&Time::HiRes::time() - $$prog_state{'firststart'})/
1.275     bisitz   1061:         $current * $last;
1.16      albertel 1062:     $time_est = int($time_est);
1.80      matthew  1063:     #
                   1064:     my $min = int($time_est/60);
                   1065:     my $sec = $time_est % 60;
1.278     bisitz   1066: 
1.23      matthew  1067:     my $lasttime = &Time::HiRes::time()-$$prog_state{'laststart'};
                   1068:     if ($lasttime > 9) {
                   1069:         $lasttime = int($lasttime);
                   1070:     } elsif ($lasttime < 0.01) {
                   1071:         $lasttime = 0;
                   1072:     } else {
                   1073:         $lasttime = sprintf("%3.2f",$lasttime);
                   1074:     }
1.278     bisitz   1075: 
                   1076:     $sec = 0 if ($min >= 10); # Don't show seconds if remaining time >= 10 min.
                   1077:     $sec = 1 if ( ($min == 0) && ($sec == 0) ); # Little cheating: pretend to have 1 second remaining instead of 0 to have something to display
                   1078: 
                   1079:     my $timeinfo =
                   1080:         &mt('[_1]/[_2]:'
                   1081:            .' [quant,_3,minute,minutes,] [quant,_4,second ,seconds ,]remaining'
                   1082:            .' ([quant,_5,second] for '.$extraInfo.')',
                   1083:             $current,
                   1084:             $$prog_state{'max'},
                   1085:             $min,
                   1086:             $sec,
                   1087:             $lasttime);
1.297     www      1088:     my $percent=0;
                   1089:     if ($$prog_state{'max'}) {
                   1090:        $percent=int(100.*$current/$$prog_state{'max'});
                   1091:     }
                   1092:     &Apache::loncommon::LCprogressbarUpdate($r,$percent,$timeinfo);
1.23      matthew  1093:     $$prog_state{'laststart'}=&Time::HiRes::time();
1.7       stredwic 1094: }
                   1095: 
                   1096: # close Progress Line
                   1097: sub Close_PrgWin {
1.14      albertel 1098:     my ($r,$prog_state)=@_;
1.297     www      1099:     &Apache::loncommon::LCprogressbarClose($r);
1.48      albertel 1100:     undef(%$prog_state);
                   1101: }
                   1102: 
1.34      www      1103: # ------------------------------------------------------- Puts directory header
                   1104: 
                   1105: sub crumbs {
1.252     bisitz   1106:     my ($uri,$target,$prefix,$form,$skiplast)=@_;
1.303     www      1107: # You cannot crumbnify uploaded or adm resources
                   1108:     if ($uri=~/^\/*(uploaded|adm)\//) { return &mt('(Internal Course/Group Content)'); }
1.100     raeburn  1109:     if ($target) {
                   1110:         $target = ' target="'.
                   1111:                   &Apache::loncommon::escape_single($target).'"';
                   1112:     }
1.252     bisitz   1113:     my $output='<span class="LC_filename">';
                   1114:     $output.=$prefix.'/';
1.249     raeburn  1115:     if (($env{'user.adv'}) || ($env{'user.author'})) {
1.252     bisitz   1116:         my $path=$prefix.'/';
                   1117:         foreach my $dir (split('/',$uri)) {
1.99      matthew  1118:             if (! $dir) { next; }
                   1119:             $path .= $dir;
1.252     bisitz   1120:             if ($path eq $uri) {
                   1121:                 if ($skiplast) {
                   1122:                     $output.=$dir;
1.132     www      1123:                     last;
1.252     bisitz   1124:                 } 
                   1125:             } else {
                   1126:                 $path.='/'; 
                   1127:             }
1.157     albertel 1128:             my $href_path = &HTML::Entities::encode($path,'<>&"');
1.252     bisitz   1129:             &Apache::loncommon::inhibit_menu_check(\$href_path);
                   1130:             if ($form) {
                   1131:                 my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
                   1132:                 $output.=qq{<a href="$href"$target>$dir</a>/};
                   1133:             } else {
                   1134:                 $output.=qq{<a href="$href_path"$target>$dir</a>/};
                   1135:             }
                   1136:         }
1.35      www      1137:     } else {
1.252     bisitz   1138:         foreach my $dir (split('/',$uri)) {
1.149     albertel 1139:             if (! $dir) { next; }
1.252     bisitz   1140:             $output.=$dir.'/';
                   1141:         }
1.34      www      1142:     }
1.149     albertel 1143:     if ($uri !~ m|/$|) { $output=~s|/$||; }
1.252     bisitz   1144:     $output.='</span>';
                   1145: 
1.304     foxr     1146: 
1.252     bisitz   1147:     return $output;
1.34      www      1148: }
                   1149: 
1.85      www      1150: # --------------------- A function that generates a window for the spellchecker
                   1151: 
                   1152: sub spellheader {
1.123     albertel 1153:     my $start_page=
                   1154: 	&Apache::loncommon::start_page('Speller Suggestions',undef,
1.140     albertel 1155: 				       {'only_body'   => 1,
                   1156: 					'js_ready'    => 1,
                   1157: 					'bgcolor'     => '#DDDDDD',
                   1158: 				        'add_entries' => {
                   1159: 					    'onload' => 
                   1160:                                                'document.forms.spellcheckform.submit()',
                   1161:                                              }
                   1162: 				        });
1.123     albertel 1163:     my $end_page=
                   1164: 	&Apache::loncommon::end_page({'js_ready'  => 1}); 
                   1165: 
1.105     www      1166:     my $nothing=&javascript_nothing();
1.85      www      1167:     return (<<ENDCHECK);
                   1168: <script type="text/javascript"> 
1.218     bisitz   1169: // <![CDATA[
1.92      albertel 1170: //<!-- BEGIN LON-CAPA Internal
1.85      www      1171: var checkwin;
                   1172: 
1.140     albertel 1173: function spellcheckerwindow(string) {
                   1174:     var esc_string = string.replace(/\"/g,'&quot;');
1.105     www      1175:     checkwin=window.open($nothing,'spellcheckwin','height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.154     albertel 1176:     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      1177:     checkwin.document.close();
                   1178: }
1.92      albertel 1179: // END LON-CAPA Internal -->
1.218     bisitz   1180: // ]]>
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.281     raeburn  1195: # ------------------------------------------------- Output headers for CKEditor
1.124     albertel 1196: 
1.52      www      1197: sub htmlareaheaders {
1.255     faziophi 1198: 	my $s="";
1.260     faziophi 1199: 	if (&htmlareabrowser()) {
1.255     faziophi 1200: 		$s.=(<<ENDEDITOR);
                   1201: <script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
                   1202: ENDEDITOR
                   1203: 	}
                   1204:     $s.=(<<ENDJQUERY);
1.294     raeburn  1205: <script type="text/javascript" src="/adm/jQuery/js/jquery-1.6.2.min.js"></script>
                   1206: <script type="text/javascript" src="/adm/jQuery/js/jquery-ui-1.8.16.custom.min.js"></script>
                   1207: <link rel="stylesheet" type="text/css" href="/adm/jQuery/css/smoothness/jquery-ui-1.8.16.custom.css" />
1.301     foxr     1208: <script type="text/javascript" src="/adm/jpicker/js/jpicker-1.1.6.min.js" >
                   1209: </script>
                   1210: <link rel="stylesheet" type="text/css" href="/adm/jpicker/css/jPicker-1.1.6.min.css" />
1.310     raeburn  1211: <script type="text/javascript" src="/adm/countdown/js/jquery.countdown.js"></script>
                   1212: <link rel="stylesheet" type="text/css" href="/adm/countdown/css/jquery.countdown.css" />
1.255     faziophi 1213: ENDJQUERY
                   1214: 	return $s;
1.52      www      1215: }
                   1216: 
1.76      www      1217: # ----------------------------------------------------------------- Preferences
                   1218: 
1.167     albertel 1219: # ------------------------------------------------- lang to use in html editor
                   1220: sub htmlarea_lang {
                   1221:     my $lang='en';
                   1222:     if (&mt('htmlarea_lang') ne 'htmlarea_lang') {
                   1223: 	$lang=&mt('htmlarea_lang');
                   1224:     }
                   1225:     return $lang;
                   1226: }
                   1227: 
1.72      www      1228: # ----------------------------------------- Script to activate only some fields
                   1229: 
                   1230: sub htmlareaselectactive {
1.281     raeburn  1231:     my ($args) = @_; 
1.76      www      1232:     unless (&htmlareabrowser()) { return ''; }
1.262     raeburn  1233:     my $output='<script type="text/javascript" defer="defer">'."\n"
1.230     bisitz   1234:               .'// <![CDATA['."\n";
1.167     albertel 1235:     my $lang = &htmlarea_lang();
1.281     raeburn  1236:     my $fullpage = 'false';
1.282     raeburn  1237:     my ($dragmath_prefix,$dragmath_helpicon,$dragmath_whitespace);
1.281     raeburn  1238:     if (ref($args) eq 'HASH') {
                   1239:         if (exists($args->{'lang'})) {
                   1240:             if ($args->{'lang'} ne '') {
                   1241:                 $lang = $args->{'lang'};
                   1242:             }
                   1243:         }
                   1244:         if (exists($args->{'fullpage'})) { 
                   1245:             if ($args->{'fullpage'} eq 'true') {
                   1246:                 $fullpage = $args->{'fullpage'};
                   1247:             }
                   1248:         }
                   1249:         if (exists($args->{'dragmath'})) {
                   1250:             if ($args->{'dragmath'} ne '') {
                   1251:                 $dragmath_prefix = $args->{'dragmath'};
1.282     raeburn  1252:                 $dragmath_helpicon=&Apache::loncommon::lonhttpdurl("/adm/help/help.png");
                   1253:                 $dragmath_whitespace=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/transparent1x1.gif");
1.281     raeburn  1254:             }
                   1255:         }
                   1256:     }
1.255     faziophi 1257:     $output.='
                   1258:     
                   1259:     function containsBlockHtml(id) {
1.281     raeburn  1260: 		var re = $("#"+id).html().search(/(?:\&lt\;|\<)(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)[\s]*((?:[\/]*[\s]*(?:\&gt\;|\>)|(?:\&gt\;|\>)[\s\S]*(?:\&lt\;|\<)\/[\s]*\1[\s]*\(?:\&gt\;|\>))/im);
1.255     faziophi 1261:     	return (re >= 0);
                   1262:     }
                   1263:     
                   1264:     function startRichEditor(id) {
                   1265:     	CKEDITOR.replace(id, 
                   1266:     		{
1.281     raeburn  1267:     			customConfig: "/ckeditor/loncapaconfig.js",
                   1268:                         language : "'.$lang.'",
                   1269:                         fullPage : '.$fullpage.',
1.255     faziophi 1270:     		}
                   1271:     	);
                   1272:     }
                   1273:     
                   1274:     function destroyRichEditor(id) {
                   1275:     	CKEDITOR.instances[id].destroy();
1.72      www      1276:     }
1.255     faziophi 1277:     
                   1278:     function editorHandler(event) {
                   1279:     	var rawid = $(this).attr("id");
1.281     raeburn  1280:     	var id = new RegExp("LC_rt_(.*)").exec(rawid)[1];
1.255     faziophi 1281:     	event.preventDefault();
1.281     raeburn  1282:     	var rt_enabled  = $(this).hasClass("LC_enable_rt");
                   1283:         if (rt_enabled) {
1.255     faziophi 1284:     		startRichEditor(id);
                   1285: 			$("#LC_rt_"+id).html("<b>&laquo; Plain text</b>");
                   1286: 			$("#LC_rt_"+id).attr("title", "Disable rich text formatting and edit in plain text");
                   1287: 			$("#LC_rt_"+id).addClass("LC_disable_rt");
                   1288: 			$("#LC_rt_"+id).removeClass("LC_enable_rt");
                   1289:     	} else {
                   1290: 			destroyRichEditor(id);
                   1291: 			$("#LC_rt_"+id).html("<b>Rich formatting &raquo;</b>");
                   1292: 			$("#LC_rt_"+id).attr("title", "Enable rich text formatting (bold, italic, etc.)");
                   1293: 			$("#LC_rt_"+id).addClass("LC_enable_rt");
                   1294: 			$("#LC_rt_"+id).removeClass("LC_disable_rt");
1.281     raeburn  1295: 	}';
                   1296:     if ($dragmath_prefix ne '') {
                   1297:         $output .= "\n                 var visible = '';
                   1298:                                        if (rt_enabled) {
                   1299:                                            visible = 'none';
                   1300:                                        }
                   1301:                                        editmath_visibility(id,visible);\n";
                   1302:     }
                   1303:     $output .= '
                   1304:     }
1.255     faziophi 1305:     $(document).ready(function(){
                   1306: 		$(".LC_richAlwaysOn").each(function() {
                   1307: 			startRichEditor($(this).attr("id"));
                   1308: 		});
                   1309: 		$(".LC_richDetectHtml").each(function() {
                   1310: 			var id = $(this).attr("id");
1.281     raeburn  1311:                         var rt_enabled = containsBlockHtml(id);
                   1312: 			if(rt_enabled) {
1.255     faziophi 1313: 				$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>&laquo; Plain text</b></a></div>");				
                   1314: 				startRichEditor(id);
1.281     raeburn  1315: 				$("#LC_rt_"+id).click(editorHandler);
1.255     faziophi 1316: 			}
                   1317: 			else {
                   1318: 				$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
                   1319: 				$("#LC_rt_"+id).click(editorHandler);
1.281     raeburn  1320: 			}';
                   1321:     if ($dragmath_prefix ne '') {
                   1322:         $output .= "\n                 var visible = '';
                   1323:                                        if (rt_enabled) {
                   1324:                                            visible = 'none';
                   1325:                                        }
                   1326:                                        editmath_visibility(id,visible);\n";
                   1327:     }
                   1328:     $output .= '
1.255     faziophi 1329: 		});
                   1330: 		$(".LC_richDefaultOn").each(function() {
                   1331: 			var id = $(this).attr("id");
                   1332: 			$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Disable rich text formatting and edit in plain text\" class=\"LC_disable_rt\"><b>&laquo; Plain text</b></a></div>");				
                   1333: 			startRichEditor(id);
                   1334: 			$("#LC_rt_"+id).click(editorHandler);
                   1335: 		});
                   1336: 		$(".LC_richDefaultOff").each(function() {
                   1337: 			var id = $(this).attr("id");
                   1338: 			$(this).before("<div><a href=\"#\" id=\"LC_rt_"+id+"\" title=\"Enable rich text formatting (bold, italic, etc.)\" class=\"LC_enable_rt\"><b>Rich formatting &raquo;</b></a></div>");
1.281     raeburn  1339: 			$("#LC_rt_"+id).click(editorHandler);
1.255     faziophi 1340: 		});
1.301     foxr     1341:                 $.fn.jPicker.defaults.images.clientPath="/adm/jpicker/images/";
                   1342:                 $(".colorchooser").jPicker();
                   1343: 
1.304     foxr     1344: 
1.302     foxr     1345: 	});
1.281     raeburn  1346: ';
1.306     foxr     1347:     # Code to put a due date countdown in 'duedatecountdown' span.
                   1348:     # This is currently located in the breadcrumb headers.
                   1349:     # note that the dueDateLayout is internatinoalized below.
                   1350:     # Here document is used to support the substitution into the javascript below.
1.307     foxr     1351:     # ..which unforunately necessitates escaping the $'s in the javascript.
                   1352:     # There are several times of importance
                   1353:     #
                   1354:     # serverDueDate -  The absolute time at which the problem expires.
                   1355:     # serverTime    -  The server's time when the problem finished computing.
                   1356:     # clientTime    -  The client's time...as close to serverTime as possible.
                   1357:     #                  The clientTime will be slightly later due to
                   1358:     #                  1. The latency between problem computation and 
                   1359:     #                     the first network action.
                   1360:     #                  2. The time required between the page load-start and the actual
                   1361:     #                     initial javascript execution that got clientTime.
                   1362:     # These are used as follows:
                   1363:     #   The difference between clientTime and serverTime are used to 
                   1364:     #   correct for differences in clock settings between the browser's system and the
                   1365:     #   server's.
                   1366:     #
                   1367:     #   The difference between clientTime and the time at which the ready() method
                   1368:     #   starts executing is used to estimate latencies for page load and submission.
                   1369:     #   Since this is an estimate, it is doubled.  The latency estimate + one minute
                   1370:     #   is used to determine when the countdown timer turns red to warn the user
                   1371:     #   to think about submitting.
1.306     foxr     1372: 
1.314     raeburn  1373:     my $dueDateLayout = &mt('Due in: {dn} {dl} {hnn}{sep}{mnn}{sep}{snn} [_1]',"<span id='submitearly'></span>");
                   1374:     my $early = '- <b>'.&mt('Submit Early').'</b>';
                   1375:     my $pastdue = '- <b>'.&mt('Past Due').'</b>';
1.306     foxr     1376:     $output .= <<JAVASCRIPT;
1.307     foxr     1377: 
                   1378:     var documentReadyTime;
                   1379: 
1.306     foxr     1380: \$(document).ready(function() {
                   1381:    if (typeof(dueDate) != "undefined") {
1.307     foxr     1382:        documentReadyTime = (new Date()).getTime();
1.306     foxr     1383:       \$("#duedatecountdown").countdown({until: dueDate, compact: true, 
                   1384:          layout: "$dueDateLayout",
                   1385:          onTick: function (periods) {
1.307     foxr     1386: 	    var latencyEstimate = (documentReadyTime - clientTime) * 2;
1.314     raeburn  1387:             if(\$.countdown.periodsToSeconds(periods) < (300 + latencyEstimate)) {
                   1388:                \$("#submitearly").html("$early");
                   1389:                if (\$.countdown.periodsToSeconds(periods) < 1) {
                   1390:                     \$("#submitearly").html("$pastdue");
                   1391:                }
                   1392:             }
1.307     foxr     1393:             if(\$.countdown.periodsToSeconds(periods) < (60 + latencyEstimate)) {
1.306     foxr     1394:                \$(this).css("color", "red");   //Highlight last minute.
                   1395:             }
                   1396:          }
                   1397:       });
                   1398:    }
                   1399: });
                   1400: JAVASCRIPT
1.281     raeburn  1401:     if ($dragmath_prefix ne '') {
                   1402:         $output .= '
                   1403: 
                   1404:      function editmath_visibility(id,value) {
                   1405: 
                   1406:          if ((id == "") || (id == null)) {
                   1407:              return;
                   1408:          }
                   1409:          var mathid = "'.$dragmath_prefix.'_"+id;
                   1410:          mathele = document.getElementById(mathid);
                   1411:          if (mathele == null) {
                   1412:              return;
                   1413:          }
                   1414:          mathele.style.display = value;
1.282     raeburn  1415:          var mathhelpicon = "'.$dragmath_prefix.'helpicon'.'_"+id;
                   1416:          mathhelpiconele = document.getElementById(mathhelpicon);
                   1417:          if (mathhelpiconele == null) {
                   1418:              return;
                   1419:          }
                   1420:          if (value == "none") {
                   1421:              mathhelpiconele.src = "'.$dragmath_whitespace.'";
                   1422:          } else {
                   1423:              mathhelpiconele.src = "'.$dragmath_helpicon.'";
                   1424:          }
1.281     raeburn  1425:      }
                   1426: ';
                   1427: 
                   1428:     }
1.218     bisitz   1429:     $output.="\nwindow.status='Activated Editfields';\n"
1.230     bisitz   1430:             .'// ]]>'."\n"
1.281     raeburn  1431:             .'</script>';
1.72      www      1432:     return $output;
                   1433: }
                   1434: 
1.61      www      1435: # --------------------------------------------------------------------- Blocked
                   1436: 
                   1437: sub htmlareablocked {
1.104     albertel 1438:     unless ($env{'environment.wysiwygeditor'} eq 'on') { return 1; }
1.71      www      1439:     return 0;
1.52      www      1440: }
                   1441: 
                   1442: # ---------------------------------------- Browser capable of running HTMLArea?
                   1443: 
                   1444: sub htmlareabrowser {
                   1445:     return 1;
                   1446: }
1.53      matthew  1447: 
1.287     www      1448: #
                   1449: # Should the "return to content" link be shown?
                   1450: #
                   1451: 
                   1452: sub show_return_link {
1.289     www      1453: 
                   1454:     unless ($env{'request.course.id'}) { return 0; }
                   1455:     if ($env{'request.noversionuri'}=~m{^/priv/} ||
                   1456:         $env{'request.uri'}=~m{^/~}) { return 1; }
                   1457: 
1.287     www      1458:     if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)})
                   1459:         || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) {
                   1460: 
                   1461:         return if ($env{'form.register'});
                   1462:     }
                   1463:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
                   1464:              $env{'request.symb'} eq '')
                   1465:             ||
                   1466:             ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
                   1467:             ||
                   1468:             (($env{'request.noversionuri'}=~/^\/adm\//) &&
                   1469:              ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                   1470:              ($env{'request.noversionuri'}!~
                   1471:               m{^/adm/.*/(smppg|bulletinboard)($|\?)})
                   1472:            ));
                   1473: }
                   1474: 
                   1475: 
1.304     foxr     1476: ##
                   1477: #   Set the dueDate variable...note this is done in the timezone
                   1478: #   of the browser.
                   1479: #
                   1480: # @param epoch relative time at which the problem is due.
                   1481: #
                   1482: # @return the javascript fragment to set the date:
                   1483: #
                   1484: sub set_due_date {
                   1485:     my $dueStamp = shift;
                   1486:     my $duems    = $dueStamp * 1000; # Javascript Date object needs ms not seconds.
                   1487: 
                   1488:     my $now = time()*1000;
                   1489: 
                   1490:     # This slightly obscure bit of javascript sets the dueDate variable
                   1491:     # to the time in the browser at which the problem was due.  
                   1492:     # The code should correct for gross differences between the server
                   1493:     # and client's time setting
                   1494: 
1.315     raeburn  1495:      return <<"END";
                   1496: 
                   1497: <script type="text/javascript">
1.304     foxr     1498:   //<![CDATA[
                   1499: var serverDueDate = $duems;
                   1500: var serverTime    = $now;
                   1501: var clientTime    = (new Date()).getTime();
                   1502: var dueDate       = new Date(serverDueDate + (clientTime - serverTime));
                   1503: 
                   1504:   //]]>
                   1505: </script>
                   1506: 
1.315     raeburn  1507: END
1.307     foxr     1508: }
                   1509: ##
                   1510: # Sets the time at which the problem finished computing.
                   1511: # This just updates the serverTime and clientTime variables above.
                   1512: # Calling this in e.g. end_problem provides a better estimate of the
                   1513: # difference beetween the server and client time setting as 
                   1514: # the difference contains less of the latency/problem compute time.
                   1515: #
                   1516: sub set_compute_end_time {
                   1517: 
                   1518:     my $now = time()*1000;	# Javascript times are in ms.
1.316   ! raeburn  1519:     return <<"END";
        !          1520: 
        !          1521: <script type="text/javascript">
1.307     foxr     1522: //<![CDATA[
                   1523: serverTime = $now;
                   1524: clientTime = (new Date()).getTime();
                   1525: //]]>
                   1526: </script>
                   1527: 
1.316   ! raeburn  1528: END
1.304     foxr     1529: }
                   1530: 
1.53      matthew  1531: ############################################################
                   1532: ############################################################
                   1533: 
                   1534: =pod
                   1535: 
1.309     raeburn  1536: =item &breadcrumbs()
1.53      matthew  1537: 
                   1538: Compiles the previously registered breadcrumbs into an series of links.
                   1539: Additionally supports a 'component', which will be displayed on the
1.223     droeschl 1540: right side of the breadcrumbs enclosing div (without a link).
1.53      matthew  1541: A link to help for the component will be included if one is specified.
                   1542: 
                   1543: All inputs can be undef without problems.
                   1544: 
1.223     droeschl 1545: Inputs: $component (the text on the right side of the breadcrumbs trail),
1.53      matthew  1546:         $component_help
1.63      albertel 1547:         $menulink (boolean, controls whether to include a link to /adm/menu)
1.138     albertel 1548:         $helplink (if 'nohelp' don't include the orange help link)
                   1549:         $css_class (optional name for the class to apply to the table for CSS)
1.197     raeburn  1550:         $no_mt (optional flag, 1 if &mt() is _not_ to be applied to $component
                   1551:            when including the text on the right.
1.53      matthew  1552: Returns a string containing breadcrumbs for the current page.
                   1553: 
1.309     raeburn  1554: =item &clear_breadcrumbs()
1.53      matthew  1555: 
                   1556: Clears the previously stored breadcrumbs.
                   1557: 
1.309     raeburn  1558: =item &add_breadcrumb()
1.53      matthew  1559: 
                   1560: Pushes a breadcrumb on the stack of crumbs.
                   1561: 
                   1562: input: $breadcrumb, a hash reference.  The keys 'href','title', and 'text'
                   1563: are required.  If present the keys 'faq' and 'bug' will be used to provide
1.156     albertel 1564: links to the FAQ and bug sites. If the key 'no_mt' is present the 'title' 
                   1565: and 'text' values won't be sent through &mt()
1.53      matthew  1566: 
                   1567: returns: nothing    
                   1568: 
                   1569: =cut
                   1570: 
                   1571: ############################################################
                   1572: ############################################################
                   1573: {
                   1574:     my @Crumbs;
1.242     droeschl 1575:     my %tools = ();
1.57      matthew  1576:     
1.53      matthew  1577:     sub breadcrumbs {
1.314     raeburn  1578:         my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, 
                   1579:             $CourseBreadcrumbs) = @_;
1.53      matthew  1580:         #
1.215     droeschl 1581:         $css_class ||= 'LC_breadcrumbs';
1.205     amueller 1582: 
1.57      matthew  1583:         # Make the faq and bug data cascade
1.223     droeschl 1584:         my $faq  = '';
                   1585:         my $bug  = '';
                   1586:         my $help = '';
1.215     droeschl 1587:         # Crumb Symbol
1.223     droeschl 1588:         my $crumbsymbol = '&raquo;';
1.60      www      1589:         # The last breadcrumb does not have a link, so handle it separately.
1.53      matthew  1590:         my $last = pop(@Crumbs);
1.57      matthew  1591:         #
1.70      matthew  1592:         # The first one should be the course or a menu link
1.215     droeschl 1593:         if (!defined($menulink)) { $menulink=1; }
1.70      matthew  1594:         if ($menulink) {
                   1595:             my $description = 'Menu';
1.172     raeburn  1596:             my $no_mt_descr = 0;
1.269     raeburn  1597:             if ((exists($env{'request.course.id'})) && 
                   1598:                 ($env{'request.course.id'} ne '') && 
                   1599:                 ($env{'course.'.$env{'request.course.id'}.'.description'} ne '')) {
1.70      matthew  1600:                 $description = 
1.104     albertel 1601:                     $env{'course.'.$env{'request.course.id'}.'.description'};
1.172     raeburn  1602:                 $no_mt_descr = 1;
1.70      matthew  1603:             }
1.215     droeschl 1604:             $menulink =  {  href   =>'/adm/menu',
                   1605:                             title  =>'Go to main menu',
                   1606:                             target =>'_top',
                   1607:                             text   =>$description,
                   1608:                             no_mt  =>$no_mt_descr, };
                   1609:             if($last) {
                   1610:                 #$last set, so we have some crumbs
                   1611:                 unshift(@Crumbs,$menulink);
                   1612:             } else {
                   1613:                 #only menulink crumb present
                   1614:                 $last = $menulink;
                   1615:             }
1.53      matthew  1616:         }
1.287     www      1617:         my $links;
                   1618:         if ((&show_return_link) && (!$CourseBreadcrumbs)) {
1.299     raeburn  1619:             my $alttext = &mt('Go Back');
1.298     raeburn  1620:             $links=&htmltag( 'a',"<img src='/res/adm/pages/reload.png' border='0' style='vertical-align:middle;' alt='$alttext' />",
1.287     www      1621:                             { href => '/adm/flip?postdata=return:',
                   1622:                               title => &mt("Back to most recent content resource") });
1.299     raeburn  1623:             $links=&htmltag('li',$links);
1.287     www      1624:         }
                   1625:         $links.= join "", 
1.261     droeschl 1626:              map {
                   1627:                  $faq  = $_->{'faq'}  if (exists($_->{'faq'}));
                   1628:                  $bug  = $_->{'bug'}  if (exists($_->{'bug'}));
                   1629:                  $help = $_->{'help'} if (exists($_->{'help'}));
                   1630: 
1.287     www      1631:                  my $result = $_->{no_mt} ? $_->{text} : &mt($_->{text});
1.261     droeschl 1632: 
                   1633:                  if ($_->{href}){
1.287     www      1634:                      $result = &htmltag( 'a', $result, 
1.261     droeschl 1635:                        { href   => $_->{href},
1.287     www      1636:                          title  => $_->{no_mt} ? $_->{title} : &mt($_->{title}),
1.261     droeschl 1637:                          target => $_->{target}, });
                   1638:                  }
                   1639: 
1.287     www      1640:                  $result = &htmltag( 'li', "$result $crumbsymbol");
1.261     droeschl 1641:              } @Crumbs;
1.223     droeschl 1642: 
                   1643:         #should the last Element be translated?
1.261     droeschl 1644: 
                   1645:         my $lasttext = $last->{'no_mt'} ? $last->{'text'} 
                   1646:                      : mt( $last->{'text'} );
                   1647: 
1.274     droeschl 1648:         # last breadcrumb is the first order heading of a page
                   1649:         # for course breadcrumbs it's just bold
1.304     foxr     1650: 
1.287     www      1651:         $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
1.274     droeschl 1652:                 $lasttext), {title => $lasttext});
1.223     droeschl 1653: 
1.54      matthew  1654:         my $icons = '';
1.223     droeschl 1655:         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
                   1656:         $bug  = $last->{'bug'}  if (exists($last->{'bug'}));
1.106     www      1657:         $help = $last->{'help'} if (exists($last->{'help'}));
                   1658:         $component_help=($component_help?$component_help:$help);
1.145     albertel 1659: #        if ($faq ne '') {
                   1660: #            $icons .= &Apache::loncommon::help_open_faq($faq);
                   1661: #        }
1.79      raeburn  1662: #        if ($bug ne '') {
                   1663: #            $icons .= &Apache::loncommon::help_open_bug($bug);
                   1664: #        }
1.223     droeschl 1665:         if ($faq ne '' || $component_help ne '' || $bug ne '') {
                   1666:             $icons .= &Apache::loncommon::help_open_menu($component,
                   1667:                                                          $component_help,
                   1668:                                                          $faq,$bug);
                   1669:         }
1.54      matthew  1670:         #
1.304     foxr     1671: 
1.205     amueller 1672: 		
                   1673: 
1.223     droeschl 1674:         unless ($CourseBreadcrumbs) {
1.287     www      1675:             $links = &htmltag('ol',  $links, { id => "LC_MenuBreadcrumbs"   });
1.223     droeschl 1676:         } else {
1.287     www      1677:             $links = &htmltag('ul',  $links, { class => "LC_CourseBreadcrumbs" });
1.53      matthew  1678:         }
1.223     droeschl 1679: 
1.304     foxr     1680: 
1.223     droeschl 1681:         if ($component) {
1.287     www      1682:             $links = &htmltag('span', 
1.223     droeschl 1683:                              ( $no_mt ? $component : mt($component) ).
                   1684:                              ( $icons ? $icons : '' ),
                   1685:                              { class => 'LC_breadcrumbs_component' } )
1.304     foxr     1686:                              .$links 
                   1687: ;
1.223     droeschl 1688:         }
                   1689:         
1.287     www      1690:         &render_tools(\$links);
                   1691:         $links = &htmltag('div', $links, 
1.225     bisitz   1692:                         { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
1.287     www      1693:         &render_advtools(\$links);
1.223     droeschl 1694: 
1.53      matthew  1695:         # Return the @Crumbs stack to what we started with
                   1696:         push(@Crumbs,$last);
                   1697:         shift(@Crumbs);
1.304     foxr     1698: 
                   1699: 
1.223     droeschl 1700:         # Return the breadcrumb's line
1.304     foxr     1701: 
                   1702:     
                   1703: 
1.223     droeschl 1704:         return "$links";
1.53      matthew  1705:     }
                   1706: 
                   1707:     sub clear_breadcrumbs {
                   1708:         undef(@Crumbs);
1.242     droeschl 1709:         undef(%tools);
1.53      matthew  1710:     }
                   1711: 
                   1712:     sub add_breadcrumb {
1.232     raeburn  1713:         push(@Crumbs,@_);
1.53      matthew  1714:     }
1.242     droeschl 1715:     
1.309     raeburn  1716: =item &add_breadcrumb_tool($category, $html)
1.261     droeschl 1717: 
                   1718: Adds $html to $category of the breadcrumb toolbar container.
                   1719: 
                   1720: $html is usually a link to a page that invokes a function on the currently 
                   1721: displayed data (e.g. print when viewing a problem)
                   1722: 
                   1723: Currently there are 3 possible values for $category: 
                   1724: 
                   1725: =over 
                   1726: 
                   1727: =item navigation 
                   1728: left of breadcrumbs line
                   1729: 
                   1730: =item tools 
1.314     raeburn  1731: remaining items in right of breadcrumbs line
1.261     droeschl 1732: 
                   1733: =item advtools 
                   1734: advanced tools shown in a separate box below breadcrumbs line 
                   1735: 
                   1736: =back
                   1737:  
                   1738: returns: nothing
                   1739: 
                   1740: =cut
1.242     droeschl 1741: 
                   1742:     sub add_breadcrumb_tool {
1.261     droeschl 1743:         my ($category, @html) = @_;
                   1744:         return unless @html;
1.285     raeburn  1745:         if (!keys(%tools)) { 
1.261     droeschl 1746:             %tools = ( navigation => [], tools => [], advtools => []);
1.242     droeschl 1747:         }
1.261     droeschl 1748: 
                   1749:         #this cleans data received from lonmenu::innerregister
                   1750:         @html = grep {defined $_ && $_ ne ''} @html;
                   1751:         for (@html) { 
                   1752:             s/align="(right|left)"//; 
1.288     www      1753: #            s/<span.*?\/span>// if $category ne 'advtools'; 
1.261     droeschl 1754:         } 
                   1755: 
                   1756:         push @{$tools{$category}}, @html;
1.242     droeschl 1757:     }
                   1758: 
1.309     raeburn  1759: =item &clear_breadcrumb_tools()
1.261     droeschl 1760: 
                   1761: Clears the breadcrumb toolbar container.
                   1762: 
                   1763: returns: nothing
                   1764: 
                   1765: =cut
                   1766: 
1.245     droeschl 1767:     sub clear_breadcrumb_tools {
                   1768:         undef(%tools);
                   1769:     }
                   1770: 
1.309     raeburn  1771: =item &render_tools(\$breadcrumbs)
1.261     droeschl 1772: 
                   1773: Creates html for breadcrumb tools (categories navigation and tools) and inserts 
                   1774: \$breadcrumbs at the correct position.
                   1775: 
                   1776: input: \$breadcrumbs - a reference to the string containing prepared 
                   1777: breadcrumbs.
                   1778: 
                   1779: returns: nothing
1.309     raeburn  1780: 
1.261     droeschl 1781: =cut
                   1782: 
                   1783: #TODO might split this in separate functions for each category
                   1784:     sub render_tools {
                   1785:         my ($breadcrumbs) = @_;
1.285     raeburn  1786:         return unless (keys(%tools));
1.261     droeschl 1787: 
                   1788:         my $navigation = list_from_array($tools{navigation}, 
                   1789:                    { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
                   1790:         my $tools = list_from_array($tools{tools}, 
                   1791:                    { listattr => { class=>"LC_breadcrumb_tools_tools" } });
                   1792:         $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs], 
                   1793:                    { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
                   1794:     }
                   1795: 
1.309     raeburn  1796: =pod
                   1797: 
                   1798: =item &render_advtools(\$breadcrumbs)
1.261     droeschl 1799: 
                   1800: Creates html for advanced tools (category advtools) and inserts \$breadcrumbs 
                   1801: at the correct position.
                   1802: 
                   1803: input: \$breadcrumbs - a reference to the string containing prepared 
                   1804: breadcrumbs (after render_tools call).
                   1805: 
                   1806: returns: nothing
1.309     raeburn  1807: 
1.261     droeschl 1808: =cut
                   1809: 
                   1810:     sub render_advtools {
                   1811:         my ($breadcrumbs) = @_;
                   1812:         return unless     (defined $tools{'advtools'}) 
                   1813:                       and (scalar(@{$tools{'advtools'}}) > 0);
                   1814: 
                   1815:         $$breadcrumbs .= Apache::loncommon::head_subbox(
                   1816:                             funclist_from_array($tools{'advtools'}) );
1.242     droeschl 1817:     }
1.53      matthew  1818: 
1.57      matthew  1819: } # End of scope for @Crumbs
1.53      matthew  1820: 
                   1821: ############################################################
                   1822: ############################################################
                   1823: 
1.112     raeburn  1824: # Nested table routines.
                   1825: #
                   1826: # Routines to display form items in a multi-row table with 2 columns.
                   1827: # Uses nested tables to divide form elements into segments.
                   1828: # For examples of use see loncom/interface/lonnotify.pm 
                   1829: #
                   1830: # Can be used in following order: ...
                   1831: # &start_pick_box()
                   1832: # row1
                   1833: # row2
                   1834: # row3   ... etc.
1.173     raeburn  1835: # &submit_row()
1.161     raeburn  1836: # &end_pick_box()
1.112     raeburn  1837: #
                   1838: # where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
                   1839: # &status_select_row and &email_default_row
                   1840: #
                   1841: # Can also be used in following order:
                   1842: #
                   1843: # &start_pick_box()
                   1844: # &row_title()
                   1845: # &row_closure()
                   1846: # &row_title()
                   1847: # &row_closure()  ... etc.
                   1848: # &submit_row()
                   1849: # &end_pick_box()
                   1850: #
                   1851: # In general a &submit_row() call should proceed the call to &end_pick_box(),
                   1852: # as this routine adds a button for form submission.
1.113     raeburn  1853: # &submit_row() does not require a &row_closure after it.
1.112     raeburn  1854: #  
                   1855: # &start_pick_box() creates a bounding table with 1-pixel wide black border.
                   1856: # rows should be placed between calls to &start_pick_box() and &end_pick_box.
                   1857: #
                   1858: # &row_title() adds a title in the left column for each segment.
                   1859: # &row_closure() closes a row with a 1-pixel wide black line.
                   1860: #
                   1861: # &role_select_row() provides a select box from which to choose 1 or more roles 
                   1862: # &course_select_row provides ways of picking groups of courses
                   1863: #    radio buttons: all, by category or by picking from a course picker pop-up
                   1864: #      note: by category option is only displayed if a domain has implemented 
                   1865: #                selection by year, semester, department, number etc.
                   1866: #
                   1867: # &status_select_row() provides a select box from which to choose 1 or more
                   1868: #  access types (current access, prior access, and future access)  
                   1869: #
                   1870: # &email_default_row() provides text boxes for default e-mail suffixes for
                   1871: #  different authentication types in a domain.
                   1872: #
                   1873: # &row_title() and &row_closure() are called internally by the &*_select_row
                   1874: # routines, but can also be called directly to start and end rows which have 
                   1875: # needs that are not accommodated by the *_select_row() routines.    
                   1876: 
1.193     bisitz   1877: { # Start: row_count block for pick_box
                   1878: my @row_count;
                   1879: 
1.112     raeburn  1880: sub start_pick_box {
1.313     raeburn  1881:     my ($css_class,$id) = @_;
1.142     albertel 1882:     if (defined($css_class)) {
                   1883: 	$css_class = 'class="'.$css_class.'"';
                   1884:     } else {
                   1885: 	$css_class= 'class="LC_pick_box"';
                   1886:     }
1.313     raeburn  1887:     my $table_id;
                   1888:     if (defined($id)) {
                   1889:         $table_id = ' id="'.$id.'"';
                   1890:     }
1.193     bisitz   1891:     unshift(@row_count,0);
1.112     raeburn  1892:     my $output = <<"END";
1.313     raeburn  1893:  <table $css_class $table_id>
1.112     raeburn  1894: END
                   1895:     return $output;
                   1896: }
                   1897: 
                   1898: sub end_pick_box {
1.193     bisitz   1899:     shift(@row_count);
1.112     raeburn  1900:     my $output = <<"END";
                   1901:        </table>
                   1902: END
                   1903:     return $output;
                   1904: }
                   1905: 
1.181     bisitz   1906: sub row_headline {
                   1907:     my $output = <<"END";
                   1908:            <tr><td colspan="2">
                   1909: END
                   1910:     return $output;
                   1911: }
                   1912: 
1.112     raeburn  1913: sub row_title {
1.243     amueller 1914:     my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
1.193     bisitz   1915:     $row_count[0]++;
                   1916:     my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.142     albertel 1917:     $css_title_class ||= 'LC_pick_box_title';
                   1918:     $css_title_class = 'class="'.$css_title_class.'"';
                   1919: 
                   1920:     $css_value_class ||= 'LC_pick_box_value';
                   1921: 
1.173     raeburn  1922:     if ($title ne '') {
                   1923:         $title .= ':';
                   1924:     }
1.112     raeburn  1925:     my $output = <<"ENDONE";
1.243     amueller 1926:            <tr class="LC_pick_box_row" $css_value_furtherAttributes> 
1.142     albertel 1927:             <td $css_title_class>
1.173     raeburn  1928: 	       $title
1.112     raeburn  1929:             </td>
1.193     bisitz   1930:             <td class="$css_value_class $css_class">
1.112     raeburn  1931: ENDONE
                   1932:     return $output;
                   1933: }
                   1934: 
                   1935: sub row_closure {
1.143     albertel 1936:     my ($no_separator) =@_;
1.113     raeburn  1937:     my $output = <<"ENDTWO";
1.112     raeburn  1938:             </td>
                   1939:            </tr>
1.143     albertel 1940: ENDTWO
                   1941:     if (!$no_separator) {
                   1942:         $output .= <<"ENDTWO";
1.112     raeburn  1943:            <tr>
1.143     albertel 1944:             <td colspan="2" class="LC_pick_box_separator">
1.112     raeburn  1945:             </td>
                   1946:            </tr>
                   1947: ENDTWO
1.143     albertel 1948:     }
1.112     raeburn  1949:     return $output;
                   1950: }
                   1951: 
1.193     bisitz   1952: } # End: row_count block for pick_box
                   1953: 
1.112     raeburn  1954: sub role_select_row {
1.147     raeburn  1955:     my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_;
1.236     raeburn  1956:     my $crstype = 'Course';
                   1957:     if ($cdom ne '' && $cnum ne '') {
                   1958:         $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
                   1959:     }
1.116     raeburn  1960:     my $output;
                   1961:     if (defined($title)) {
1.142     albertel 1962:         $output = &row_title($title,$css_class);
1.116     raeburn  1963:     }
1.142     albertel 1964:     $output .= qq|
1.198     bisitz   1965:                                   <select name="roles" multiple="multiple">\n|;
1.113     raeburn  1966:     foreach my $role (@$roles) {
1.114     raeburn  1967:         my $plrole;
                   1968:         if ($role eq 'ow') {
                   1969:             $plrole = &mt('Course Owner');
1.147     raeburn  1970:         } elsif ($role eq 'cr') {
                   1971:             if ($show_separate_custom) {
                   1972:                 if ($cdom ne '' && $cnum ne '') {
                   1973:                     my %course_customroles = &course_custom_roles($cdom,$cnum);
                   1974:                     foreach my $crrole (sort(keys(%course_customroles))) {
                   1975:                         my ($plcrrole) = ($crrole =~ m|^cr/[^/]+/[^/]+/(.+)$|);
                   1976:                         $output .= '  <option value="'.$crrole.'">'.$plcrrole.
                   1977:                                    '</option>';
                   1978:                     }
                   1979:                 }
                   1980:             } else {
                   1981:                 $plrole = &mt('Custom Role');
                   1982:             }
1.114     raeburn  1983:         } else {
1.236     raeburn  1984:             $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.114     raeburn  1985:         }
1.147     raeburn  1986:         if (($role ne 'cr') || (!$show_separate_custom)) {
                   1987:             $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
                   1988:         }
1.112     raeburn  1989:     }
1.142     albertel 1990:     $output .= qq|                </select>\n|;
1.116     raeburn  1991:     if (defined($title)) {
                   1992:         $output .= &row_closure();
                   1993:     }
1.112     raeburn  1994:     return $output;
                   1995: }
                   1996: 
                   1997: sub course_select_row {
1.142     albertel 1998:     my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
1.280     raeburn  1999: 	$css_class,$crstype,$standardnames) = @_;
1.142     albertel 2000:     my $output = &row_title($title,$css_class);
1.280     raeburn  2001:     $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
1.169     raeburn  2002:     $output .= &row_closure();
                   2003:     return $output;
                   2004: }
                   2005: 
                   2006: sub course_selection {
1.280     raeburn  2007:     my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
1.169     raeburn  2008:     my $output = qq|
1.142     albertel 2009: <script type="text/javascript">
1.218     bisitz   2010: // <![CDATA[
1.112     raeburn  2011:     function coursePick (formname) {
                   2012:         for  (var i=0; i<formname.coursepick.length; i++) {
1.114     raeburn  2013:             if (formname.coursepick[i].value == 'category') {
                   2014:                 courseSet('');
                   2015:             }
1.112     raeburn  2016:             if (!formname.coursepick[i].checked) {
                   2017:                 if (formname.coursepick[i].value == 'specific') {
                   2018:                     formname.coursetotal.value = 0;
                   2019:                     formname.courselist = '';
                   2020:                 }
                   2021:             }
                   2022:         }
                   2023:     }
1.114     raeburn  2024:     function setPick (formname) {
                   2025:         for  (var i=0; i<formname.coursepick.length; i++) {
                   2026:             if (formname.coursepick[i].value == 'category') {
                   2027:                 formname.coursepick[i].checked = true;
                   2028:             }
                   2029:             formname.coursetotal.value = 0;
                   2030:             formname.courselist = '';
                   2031:         }
                   2032:     }
1.218     bisitz   2033: // ]]>
1.112     raeburn  2034: </script>
                   2035:     |;
1.237     raeburn  2036: 
                   2037:     my ($allcrs,$pickspec);
                   2038:     if ($crstype eq 'Community') {
                   2039:         $allcrs = &mt('All communities');
                   2040:         $pickspec = &mt('Pick specific communities:');
                   2041:     } else {
                   2042:         $allcrs = &mt('All courses');
                   2043:         $pickspec = &mt('Pick specific course(s):');
                   2044:     }
                   2045: 
1.112     raeburn  2046:     my $courseform='<b>'.&Apache::loncommon::selectcourse_link
1.237     raeburn  2047:                      ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).'</b>';
                   2048:         $output .= '<input type="radio" name="coursepick" value="all" onclick="coursePick(this.form)" />'.$allcrs.'<br />';
1.112     raeburn  2049:     if ($totcodes > 0) {
                   2050:         my $numtitles = @$codetitles;
                   2051:         if ($numtitles > 0) {
1.129     raeburn  2052:             $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  2053:             $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
1.280     raeburn  2054:                '<select name="'.$standardnames->[0].
1.114     raeburn  2055:                '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
1.112     raeburn  2056:                ' <option value="-1" />Select'."\n";
                   2057:             my @items = ();
                   2058:             my @longitems = ();
                   2059:             if ($$idlist{$$codetitles[0]} =~ /","/) {
1.113     raeburn  2060:                 @items = split(/","/,$$idlist{$$codetitles[0]});
1.112     raeburn  2061:             } else {
                   2062:                 $items[0] = $$idlist{$$codetitles[0]};
                   2063:             }
                   2064:             if (defined($$idlist_titles{$$codetitles[0]})) {
                   2065:                 if ($$idlist_titles{$$codetitles[0]} =~ /","/) {
1.113     raeburn  2066:                     @longitems = split(/","/,$$idlist_titles{$$codetitles[0]});
1.112     raeburn  2067:                 } else {
                   2068:                     $longitems[0] = $$idlist_titles{$$codetitles[0]};
                   2069:                 }
                   2070:                 for (my $i=0; $i<@longitems; $i++) {
                   2071:                     if ($longitems[$i] eq '') {
                   2072:                         $longitems[$i] = $items[$i];
                   2073:                     }
                   2074:                 }
                   2075:             } else {
                   2076:                 @longitems = @items;
                   2077:             }
                   2078:             for (my $i=0; $i<@items; $i++) {
                   2079:                 $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>';
                   2080:             }
                   2081:             $output .= '</select></td>';
                   2082:             for (my $i=1; $i<$numtitles; $i++) {
                   2083:                 $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
1.280     raeburn  2084:                           '<select name="'.$standardnames->[$i].
1.112     raeburn  2085:                           '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
                   2086:                           '<option value="-1">&lt;-Pick '.$$codetitles[$i-1].'</option>'."\n".
                   2087:                           '</select>'."\n".
                   2088:                           '</td>';
                   2089:             }
                   2090:             $output .= '</tr></table><br />';
                   2091:         }
                   2092:     }
1.238     raeburn  2093:     $output .= '<input type="radio" name="coursepick" value="specific" onclick="coursePick(this.form);opencrsbrowser('."'".$formname."','dccourse','dcdomain','coursedesc','','1','$crstype'".')" />'.$pickspec.' '.$courseform.'&nbsp;&nbsp;<input type="text" value="0" size="4" name="coursetotal" /><input type="hidden" name="courselist" value="" />selected.<br />'."\n";
1.112     raeburn  2094:     return $output;
                   2095: }
                   2096: 
                   2097: sub status_select_row {
1.142     albertel 2098:     my ($types,$title,$css_class) = @_;
1.117     raeburn  2099:     my $output; 
                   2100:     if (defined($title)) {
1.142     albertel 2101:         $output = &row_title($title,$css_class,'LC_pick_box_select');
1.117     raeburn  2102:     }
1.142     albertel 2103:     $output .= qq|
1.198     bisitz   2104:                                     <select name="types" multiple="multiple">\n|;
1.113     raeburn  2105:     foreach my $status_type (sort(keys(%{$types}))) {
1.112     raeburn  2106:         $output .= '  <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
                   2107:     }
1.142     albertel 2108:     $output .= qq|                   </select>\n|; 
1.117     raeburn  2109:     if (defined($title)) {
                   2110:         $output .= &row_closure();
                   2111:     }
1.112     raeburn  2112:     return $output;
                   2113: }
                   2114: 
                   2115: sub email_default_row {
1.142     albertel 2116:     my ($authtypes,$title,$descrip,$css_class) = @_;
                   2117:     my $output = &row_title($title,$css_class);
                   2118:     $output .= $descrip.
                   2119: 	&Apache::loncommon::start_data_table().
                   2120: 	&Apache::loncommon::start_data_table_header_row().
                   2121: 	'<th>'.&mt('Authentication Method').'</th>'.
                   2122: 	'<th align="right">'.&mt('Username -> e-mail conversion').'</th>'."\n".
                   2123: 	&Apache::loncommon::end_data_table_header_row();
1.112     raeburn  2124:     my $rownum = 0;
1.113     raeburn  2125:     foreach my $auth (sort(keys(%{$authtypes}))) {
1.112     raeburn  2126:         my ($userentry,$size);
                   2127:         if ($auth =~ /^krb/) {
                   2128:             $userentry = '';
                   2129:             $size = 25;
                   2130:         } else {
                   2131:             $userentry = 'username@';
                   2132:             $size = 15;
                   2133:         }
1.142     albertel 2134:         $output .= &Apache::loncommon::start_data_table_row().
                   2135: 	    '<td>  '.$$authtypes{$auth}.'</td>'.
                   2136: 	    '<td align="right">'.$userentry.
                   2137: 	    '<input type="text" name="'.$auth.'" size="'.$size.'" /></td>'.
                   2138: 	    &Apache::loncommon::end_data_table_row();
1.112     raeburn  2139:     }
1.142     albertel 2140:     $output .= &Apache::loncommon::end_data_table();
1.112     raeburn  2141:     $output .= &row_closure();
                   2142:     return $output;
                   2143: }
                   2144: 
                   2145: 
                   2146: sub submit_row {
1.142     albertel 2147:     my ($title,$cmd,$submit_text,$css_class) = @_;
                   2148:     my $output = &row_title($title,$css_class,'LC_pick_box_submit');
1.112     raeburn  2149:     $output .= qq|
                   2150:              <br />
                   2151:              <input type="hidden" name="command" value="$cmd" />
                   2152:              <input type="submit" value="$submit_text"/> &nbsp;
                   2153:              <br /><br />
1.142     albertel 2154:             \n|;
1.112     raeburn  2155:     return $output;
                   2156: }
1.1       stredwic 2157: 
1.147     raeburn  2158: sub course_custom_roles {
                   2159:     my ($cdom,$cnum) = @_;
                   2160:     my %returnhash=();
                   2161:     my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   2162:     foreach my $person (sort(keys(%coursepersonnel))) {
                   2163:         my ($role) = ($person =~ /^([^:]+):/);
                   2164:         my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   2165:         if ($end == -1 && $start == -1) {
                   2166:             next;
                   2167:         }
                   2168:         if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
                   2169:             $returnhash{$role} ++;
                   2170:         }
                   2171:     }
                   2172:     return %returnhash;
                   2173: }
                   2174: 
                   2175: 
1.270     www      2176: sub resource_info_box {
1.300     raeburn  2177:    my ($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp)=@_;
1.270     www      2178:    my $return='';
1.300     raeburn  2179:    if ($stuvcurrent ne '') {
                   2180:        $return = '<div class="LC_left_float">';
                   2181:    }
1.270     www      2182:    if ($symb) {
1.300     raeburn  2183:        $return.=&Apache::loncommon::start_data_table();
1.271     www      2184:        my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symb);
                   2185:        my $folder=&Apache::lonnet::gettitle($map);
                   2186:        $return.=&Apache::loncommon::start_data_table_row().
1.300     raeburn  2187:                     '<th align="left">'.&mt('Folder:').'</th><td>'.$folder.'</td>'.
1.271     www      2188:                     &Apache::loncommon::end_data_table_row();
1.270     www      2189:        unless ($onlyfolderflag) {
                   2190:           $return.=&Apache::loncommon::start_data_table_row().
1.300     raeburn  2191:                     '<th align="left">'.&mt('Resource:').'</th><td>'.&Apache::lonnet::gettitle($symb).'</td>'.
                   2192:                     &Apache::loncommon::end_data_table_row();
                   2193:        }
                   2194:        if ($stuvcurrent ne '') {
                   2195:            $return .= &Apache::loncommon::start_data_table_row().
                   2196:                     '<th align="left">'.&mt("Student's current version:").'</th><td>'.$stuvcurrent.'</td>'.
                   2197:                     &Apache::loncommon::end_data_table_row();
                   2198:        }
                   2199:        if ($stuvdisp ne '') {
                   2200:            $return .= &Apache::loncommon::start_data_table_row().
                   2201:                     '<th align="left">'.&mt("Student's version displayed:").'</th><td>'.$stuvdisp.'</td>'.
1.270     www      2202:                     &Apache::loncommon::end_data_table_row();
                   2203:        }
1.271     www      2204:        $return.=&Apache::loncommon::end_data_table();
1.270     www      2205:     } else {
                   2206:        $return='<p><span class="LC_error">'.&mt('No context provided.').'</span></p>';
                   2207:     }
1.300     raeburn  2208:     if ($stuvcurrent ne '') {
                   2209:         $return .= '</div>';
                   2210:     }
1.270     www      2211:     return $return;
                   2212: }
                   2213: 
1.119     raeburn  2214: ##############################################
                   2215: ##############################################
1.179     raeburn  2216: 
                   2217: # topic_bar
                   2218: #
1.248     wenzelju 2219: # Generates a div containing an (optional) number with a white background followed by a 
1.240     raeburn  2220: # title with a background color defined in the corresponding CSS: LC_topic_bar
                   2221: # Inputs:
1.248     wenzelju 2222: # 1. number to display.
                   2223: #    If input for number is empty only the title will be displayed. 
1.240     raeburn  2224: # 2. title text to display.
1.313     raeburn  2225: # 3. optional id for the <div>
1.240     raeburn  2226: # Outputs - a scalar containing html mark-up for the div.
                   2227: 
1.179     raeburn  2228: sub topic_bar {
1.313     raeburn  2229:     my ($num,$title,$id) = @_;
1.248     wenzelju 2230:     my $number = '';
                   2231:     if ($num ne '') {
                   2232:         $number = '<span>'.$num.'</span>';
1.239     amueller 2233:     }
1.313     raeburn  2234:     if ($id ne '') {
                   2235:         $id = 'id="'.$id.'"';
                   2236:     }
                   2237:     return '<div class="LC_topic_bar" '.$id.'>'.$number.$title.'</div>';
1.179     raeburn  2238: }
                   2239: 
                   2240: ##############################################
                   2241: ##############################################
1.119     raeburn  2242: # echo_form_input
                   2243: #
                   2244: # Generates html markup to add form elements from the referrer page
                   2245: # as hidden form elements (values encoded) in the new page.
                   2246: #
                   2247: # Intended to support two types of use 
                   2248: # (a) to allow backing up to earlier pages in a multi-page 
                   2249: # form submission process using a breadcrumb trail.
                   2250: #
                   2251: # (b) to allow the current page to be reloaded with form elements
                   2252: # set on previous page to remain unchanged.  An example would
                   2253: # be where the a page containing a dynamically-built table of data is 
                   2254: # is to be redisplayed, with only the sort order of the data changed. 
                   2255: #  
                   2256: # Inputs:
                   2257: # 1. Reference to array of form elements in the submitted form on 
                   2258: # the referrer page which are to be excluded from the echoed elements.
                   2259: #
                   2260: # 2. Reference to array of regular expressions, which if matched in the  
                   2261: # name of the form element n the referrer page will be omitted from echo. 
                   2262: #
                   2263: # Outputs: A scalar containing the html markup for the echoed form
                   2264: # elements (all as hidden elements, with values encoded). 
                   2265: 
                   2266: 
                   2267: sub echo_form_input {
                   2268:     my ($excluded,$regexps) = @_;
                   2269:     my $output = '';
                   2270:     foreach my $key (keys(%env)) {
                   2271:         if ($key =~ /^form\.(.+)$/) {
                   2272:             my $name = $1;
                   2273:             my $match = 0;
1.285     raeburn  2274:             if (ref($excluded) eq 'ARRAY') {    
                   2275:                 next if (grep(/^\Q$name\E$/,@{$excluded}));
                   2276:             }
                   2277:             if (ref($regexps) eq 'ARRAY') {
                   2278:                 if (@{$regexps} > 0) {
                   2279:                     foreach my $regexp (@{$regexps}) {
                   2280:                         if ($name =~ /$regexp/) {
                   2281:                             $match = 1;
                   2282:                             last;
1.119     raeburn  2283:                         }
                   2284:                     }
                   2285:                 }
1.285     raeburn  2286:             }
                   2287:             next if ($match);
                   2288:             if (ref($env{$key}) eq 'ARRAY') {
                   2289:                 foreach my $value (@{$env{$key}}) {
                   2290:                     $value = &HTML::Entities::encode($value,'<>&"');
                   2291:                     $output .= '<input type="hidden" name="'.$name.
                   2292:                                '" value="'.$value.'" />'."\n";
1.119     raeburn  2293:                 }
1.285     raeburn  2294:             } else {
                   2295:                 my $value = &HTML::Entities::encode($env{$key},'<>&"');
                   2296:                 $output .= '<input type="hidden" name="'.$name.
                   2297:                            '" value="'.$value.'" />'."\n";
1.119     raeburn  2298:             }
                   2299:         }
                   2300:     }
                   2301:     return $output;
                   2302: }
                   2303: 
                   2304: ##############################################
                   2305: ##############################################
                   2306: # set_form_elements
                   2307: #
                   2308: # Generates javascript to set form elements to values based on
                   2309: # corresponding values for the same form elements when the page was
                   2310: # previously submitted.
                   2311: #     
                   2312: # Last submission values are read from hidden form elements in referring 
                   2313: # page which have the same name, i.e., generated by &echo_form_input(). 
                   2314: #
                   2315: # Intended to be called by onload event.
                   2316: #
1.121     raeburn  2317: # Inputs:
                   2318: # (a) Reference to hash of echoed form elements to be set.
1.119     raeburn  2319: #
                   2320: # In the hash, keys are the form element names, and the values are the
                   2321: # element type (selectbox, radio, checkbox or text -for textbox, textarea or
                   2322: # hidden).
1.121     raeburn  2323: #
                   2324: # (b) Optional reference to hash of stored elements to be set.
                   2325: #
                   2326: # If the page being displayed is a page which permits modification of
                   2327: # previously stored data, e.g., the first page in a multi-page submission,
                   2328: # then if stored is supplied, form elements will be set to the last stored
                   2329: # values.  If user supplied values are also available for the same elements
                   2330: # these will replace the stored values. 
                   2331: #        
1.119     raeburn  2332: # Output:
                   2333: #  
                   2334: # javascript function - set_form_elements() which sets form elements,
                   2335: # expects an argument: formname - the name of the form according to 
                   2336: # the DOM, e.g., document.compose
                   2337: 
                   2338: sub set_form_elements {
1.121     raeburn  2339:     my ($elements,$stored) = @_;
                   2340:     my %values;
1.119     raeburn  2341:     my $output .= 'function setFormElements(courseForm) {
1.121     raeburn  2342: ';
                   2343:     if (defined($stored)) {
                   2344:         foreach my $name (keys(%{$stored})) {
                   2345:             if (exists($$elements{$name})) {
                   2346:                 if (ref($$stored{$name}) eq 'ARRAY') {
                   2347:                     $values{$name} = $$stored{$name};
                   2348:                 } else {
                   2349:                     @{$values{$name}} = ($$stored{$name});
                   2350:                 }
                   2351:             }
                   2352:         }
                   2353:     }
                   2354: 
1.119     raeburn  2355:     foreach my $key (keys(%env)) {
                   2356:         if ($key =~ /^form\.(.+)$/) {
                   2357:             my $name = $1;
                   2358:             if (exists($$elements{$name})) {
1.121     raeburn  2359:                 @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
                   2360:             }
                   2361:         }
                   2362:     }
                   2363: 
                   2364:     foreach my $name (keys(%values)) {
                   2365:         for (my $i=0; $i<@{$values{$name}}; $i++) {
                   2366:             $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
                   2367:             $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
                   2368:             $values{$name}[$i] =~ s/"/\\"/g;
                   2369:         }
1.234     raeburn  2370:         if (($$elements{$name} eq 'text') || ($$elements{$name} eq 'hidden')) {
1.121     raeburn  2371:             my $numvalues = @{$values{$name}};
                   2372:             if ($numvalues > 1) {
                   2373:                 my $valuestring = join('","',@{$values{$name}});
                   2374:                 $output .= qq|
1.119     raeburn  2375:   var textvalues = new Array ("$valuestring");
1.147     raeburn  2376:   var total = courseForm.elements['$name'].length;
1.119     raeburn  2377:   if (total > $numvalues) {
                   2378:       total = $numvalues;
                   2379:   }    
                   2380:   for (var i=0; i<total; i++) {
1.147     raeburn  2381:       courseForm.elements['$name']\[i].value = textvalues[i];
1.119     raeburn  2382:   }
                   2383: |;
1.121     raeburn  2384:             } else {
                   2385:                 $output .= qq|
1.147     raeburn  2386:   courseForm.elements['$name'].value = "$values{$name}[0]";
1.119     raeburn  2387: |;
1.121     raeburn  2388:             }
                   2389:         } else {
                   2390:             $output .=  qq|
1.147     raeburn  2391:   var elementLength = courseForm.elements['$name'].length;
1.119     raeburn  2392:   if (elementLength==undefined) {
                   2393: |;
1.121     raeburn  2394:             foreach my $value (@{$values{$name}}) {
                   2395:                 if ($$elements{$name} eq 'selectbox') {
                   2396:                     $output .=  qq|
1.147     raeburn  2397:       if (courseForm.elements['$name'].options[0].value == "$value") {
                   2398:           courseForm.elements['$name'].options[0].selected = true;
1.119     raeburn  2399:       }|;
1.121     raeburn  2400:                 } elsif (($$elements{$name} eq 'radio') ||
                   2401:                          ($$elements{$name} eq 'checkbox')) {
                   2402:                     $output .= qq|
1.147     raeburn  2403:       if (courseForm.elements['$name'].value == "$value") {
1.148     albertel 2404:           courseForm.elements['$name'].checked = true;
1.234     raeburn  2405:       } else {
                   2406:           courseForm.elements['$name'].checked = false;
1.119     raeburn  2407:       }|;
1.121     raeburn  2408:                 }
                   2409:             }
                   2410:             $output .= qq|
1.119     raeburn  2411:   }
                   2412:   else {
1.147     raeburn  2413:       for (var i=0; i<courseForm.elements['$name'].length; i++) {
1.119     raeburn  2414: |;
1.121     raeburn  2415:             if ($$elements{$name} eq 'selectbox') {
                   2416:                 $output .=  qq|
1.147     raeburn  2417:           courseForm.elements['$name'].options[i].selected = false;|;
1.121     raeburn  2418:             } elsif (($$elements{$name} eq 'radio') || 
                   2419:                      ($$elements{$name} eq 'checkbox')) {
                   2420:                 $output .= qq|
1.147     raeburn  2421:           courseForm.elements['$name']\[i].checked = false;|; 
1.121     raeburn  2422:             }
                   2423:             $output .= qq|
1.119     raeburn  2424:       }
1.147     raeburn  2425:       for (var j=0; j<courseForm.elements['$name'].length; j++) {
1.119     raeburn  2426: |;
1.121     raeburn  2427:             foreach my $value (@{$values{$name}}) {
                   2428:                 if ($$elements{$name} eq 'selectbox') {
                   2429:                     $output .=  qq|
1.147     raeburn  2430:           if (courseForm.elements['$name'].options[j].value == "$value") {
                   2431:               courseForm.elements['$name'].options[j].selected = true;
1.119     raeburn  2432:           }|;
1.121     raeburn  2433:                 } elsif (($$elements{$name} eq 'radio') ||
                   2434:                          ($$elements{$name} eq 'checkbox')) { 
                   2435:                       $output .= qq|
1.147     raeburn  2436:           if (courseForm.elements['$name']\[j].value == "$value") {
                   2437:               courseForm.elements['$name']\[j].checked = true;
1.119     raeburn  2438:           }|;
1.121     raeburn  2439:                 }
                   2440:             }
                   2441:             $output .= qq|
1.119     raeburn  2442:       }
                   2443:   }
                   2444: |;
                   2445:         }
                   2446:     }
                   2447:     $output .= "
1.235     raeburn  2448:     return;
1.119     raeburn  2449: }\n";
                   2450:     return $output;
                   2451: }
                   2452: 
1.158     raeburn  2453: ##############################################
                   2454: ##############################################
                   2455: 
1.291     raeburn  2456: sub file_submissionchk_js {
                   2457:     my ($turninpaths,$multiples) = @_;
                   2458:     my $overwritewarn = &mt('File(s) you uploaded for your submission will overwrite existing file(s) submitted for this item').'\\n'.
                   2459:                       &mt('Continue submission and overwrite the file(s)?');
                   2460:     my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'.
                   2461:                       &mt('Continue submission with these files removed?');
1.292     raeburn  2462:     my ($turninpathtext,$multtext,$arrayindexofjs);
1.291     raeburn  2463:     if (ref($turninpaths) eq 'HASH') {
                   2464:         foreach my $key (sort(keys(%{$turninpaths}))) {
                   2465:             $turninpathtext .= "    if (prefix == '$key') {\n".
                   2466:                                "        return '$turninpaths->{$key}';\n".
                   2467:                                "    }\n";
                   2468:         }
                   2469:     }
                   2470:     $turninpathtext .= "    return '';\n";
                   2471:     if (ref($multiples) eq 'HASH') {
                   2472:         foreach my $key (sort(keys(%{$multiples}))) {
                   2473:             $multtext .= "    if (prefix == '$key') {\n".
                   2474:                          "        return '$multiples->{$key}';\n".
                   2475:                          "    }\n";
                   2476:         }
                   2477:     }
                   2478:     $multtext .= "    return '';\n";
1.292     raeburn  2479: 
1.293     raeburn  2480:     $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
1.291     raeburn  2481:     return <<"ENDSCRIPT";
                   2482: <script type="text/javascript">
                   2483: // <![CDATA[
                   2484: 
                   2485: function file_submission_check(formname,path,multiresp) {
                   2486:     var elemnum = formname.elements.length;
                   2487:     if (elemnum == 0) {
                   2488:         return true;
                   2489:     }
                   2490:     var alloverwrites = [];
                   2491:     var alldelconfirm = [];
                   2492:     var result = [];
                   2493:     var submitter;
                   2494:     var subprefix;
                   2495:     var allsub = getIndexByName(formname,'all_submit');
                   2496:     if (allsub == -1) {
                   2497:         var idx = getIndexByName(formname,'submitted');
                   2498:         if (idx != -1) {
                   2499:             var subval = String(formname.elements[idx].value);
                   2500:             submitter = subval.replace(/^part_/,'');
                   2501:             result = overwritten_check(formname,path,multiresp,submitter);
                   2502:             alloverwrites.push.apply(alloverwrites,result['overwrite']);
                   2503:             alldelconfirm.push.apply(alldelconfirm,result['delete']);
                   2504:         }
                   2505:     } else {
                   2506:         if (formname.elements[allsub].type == 'submit') {
                   2507:             var partsub = /^\\d+\\.\\d+_submit_.+\$/;
                   2508:             var allprefixes = [];
                   2509:             var allparts = [];
                   2510:             for (var i=0; i<formname.elements.length; i++) {
                   2511:                 if (formname.elements[i].type == 'submit') {
                   2512:                     var elemname = formname.elements[i].name;
                   2513:                     var subname = String(elemname);
                   2514:                     var savesub = String(elemname);
                   2515:                     if (partsub.test(subname)) {
                   2516:                         var prefix = subname.replace(/_submit_.+\$/,'');
                   2517:                         if (allprefixes.indexOf(prefix) == -1) {
                   2518:                             allprefixes.push(prefix);
                   2519:                             allparts[prefix] = [];
                   2520:                         }
                   2521:                         var part = savesub.replace(/^\\d+\\.\\d+_submit_/,'');
                   2522:                         allparts[prefix].push(part);
                   2523:                     }
                   2524:                 }
                   2525:             }
                   2526:             for (var k=0; k<allprefixes.length; k++) {
                   2527:                 var idx = getIndexByName(formname,allprefixes[k]+'_submitted');
                   2528:                 if (idx > -1) {
                   2529:                     if (formname.elements[idx].value != 'yes') {
                   2530:                         submitterval = formname.elements[idx].value;
                   2531:                         submitter = submitterval.replace(/^part_/,'');
                   2532:                         subprefix = allprefixes[k];
                   2533:                         result = overwritten_check(formname,path,multiresp,submitter,subprefix);
                   2534:                         alloverwrites.push.apply(alloverwrites,result['overwrite']);
                   2535:                         alldelconfirm.push.apply(alldelconfirm,result['delete']);
                   2536:                         break;
                   2537:                     }
                   2538:                 }
                   2539:             }
                   2540:             if (submitter == '' || submitter == undefined) {
                   2541:                 for (var m=0; m<allprefixes.length; m++) {
                   2542:                     for (var n=0; n<allparts[allprefixes[m]].length; n++) {
                   2543:                         var result = overwritten_check(formname,path,multiresp,allparts[allprefixes[m]][n],allprefixes[m]);
                   2544:                         alloverwrites.push.apply(alloverwrites,result['overwrite']);
                   2545:                         alldelconfirm.push.apply(alldelconfirm,result['delete']);
                   2546:                     }
                   2547:                 }
                   2548:             }
                   2549:         }
                   2550:     }
                   2551:     if (alloverwrites.length > 0) {
                   2552:         if (!confirm("$overwritewarn")) {
                   2553:             for (var n=0; n<alloverwrites.length; n++) {
                   2554:                 formname.elements[alloverwrites[n]].value = "";
                   2555:             }
                   2556:             return false;
                   2557:         }
                   2558:     }
                   2559:     if (alldelconfirm.length > 0) {
                   2560:         if (!confirm("$delfilewarn")) {
                   2561:             for (var p=0; p<alldelconfirm.length; p++) {
                   2562:                 formname.elements[alldelconfirm[p]].checked = false;
                   2563:             }
                   2564:             return false;
                   2565:         }
                   2566:     }
                   2567:     return true;
                   2568: }
                   2569: 
                   2570: function getIndexByName(formname,item) {
                   2571:     for (var i=0;i<formname.elements.length;i++) {
                   2572:         if (formname.elements[i].name == item) {
                   2573:             return i;
                   2574:         }
                   2575:     }
                   2576:     return -1;
                   2577: }
                   2578: 
                   2579: function overwritten_check(formname,path,multiresp,part,prefix) {
                   2580:     var result = [];
                   2581:     result['overwrite'] = [];
                   2582:     result['delete'] = [];
                   2583:     var elemnum = formname.elements.length;
                   2584:     if (elemnum == 0) {
                   2585:         return result;
                   2586:     }
                   2587:     var uploadstr;
                   2588:     var deletestr;
                   2589:     if ((prefix != undefined) && (prefix != '')) {
                   2590:         var prepend = prefix+'_';
                   2591:         uploadstr = new RegExp("^"+prepend+"HWFILE"+part+".+\$");
                   2592:         deletestr = new RegExp("^"+prepend+"HWFILE"+part+".+_\\\\d+_delete\$");
                   2593:         multiresp = check_for_multiples(prepend);
                   2594:         path = check_for_turninpath(prepend);
                   2595:     } else {
                   2596:         uploadstr = new RegExp("^HWFILE"+part+".+\$");
                   2597:         deletestr = new RegExp("^HWFILE"+part+".+_\\\\d+_delete\$");
                   2598:     }
                   2599:     var alluploads = [];
                   2600:     var allchecked = [];
                   2601:     var allskipdel = [];
                   2602:     var fnametrim = /[^\\/\\\\]+\$/;
                   2603:     for (var i=0; i<formname.elements.length; i++) {
                   2604:         var id = formname.elements[i].id;
                   2605:         if (id != '') {
                   2606:             if (uploadstr.test(id)) {
                   2607:                 if (formname.elements[i].type == 'file') {
                   2608:                     alluploads.push(id);
                   2609:                 } else {
                   2610:                     if (deletestr.test(id)) {
                   2611:                         if (formname.elements[i].type == 'checkbox') {
                   2612:                             if (formname.elements[i].checked) {
                   2613:                                 allchecked.push(id);
                   2614:                             }
                   2615:                         }
                   2616:                     }
                   2617:                 }
                   2618:             }
                   2619:         }
                   2620:     }
                   2621:     for (var j=0; j<alluploads.length; j++) {
                   2622:         var delstr = new RegExp("^"+alluploads[j]+"_\\\\d+_delete\$");
                   2623:         var delboxes = [];
                   2624:         for (var k=0; k<formname.elements.length; k++) {
                   2625:             var id = formname.elements[k].id;
                   2626:             if ((id != '') && (id != undefined)) {
                   2627:                 if (delstr.test(id)) {
                   2628:                     if (formname.elements[k].type == 'checkbox') {
                   2629:                         delboxes.push(id);
                   2630:                     }
                   2631:                 }
                   2632:             }
                   2633:         }
                   2634:         if (delboxes.length > 0) {
                   2635:             if ((formname.elements[alluploads[j]].value != undefined) &&
                   2636:                 (formname.elements[alluploads[j]].value != '')) {
                   2637:                 var filepath = formname.elements[alluploads[j]].value;
                   2638:                 var newfilename = fnametrim.exec(filepath);
                   2639:                 if (newfilename != null) {
                   2640:                     var filename = String(newfilename);
                   2641:                     var nospaces = filename.replace(/\\s+/g,'_');
                   2642:                     var nospecials = nospaces.replace(/[^\\/\\w\\.\\-]/g,'');
                   2643:                     var cleanfilename = nospecials.replace(/\\.(\\d+\\.)/g,"_\$1");
                   2644:                     if (cleanfilename != '') {
                   2645:                         var fullpath = path+"/"+cleanfilename;
                   2646:                         if (multiresp == 1) {
                   2647:                             var partid = String(alluploads[i]);
                   2648:                             var subdir = partid.replace(/^\\d*.?\\d*_?HWFILE/,'');
                   2649:                             if (subdir != "" && subdir != undefined) {
                   2650:                                 fullpath = path+"/"+subdir+"/"+cleanfilename;
                   2651:                             }
                   2652:                         }
                   2653:                         for (var m=0; m<delboxes.length; m++) {
                   2654:                             if (fullpath == formname.elements[delboxes[m]].value) {
                   2655:                                 if (formname.elements[delboxes[m]].checked) {
                   2656:                                     allskipdel.push(delboxes[m]);
                   2657:                                 } else {
                   2658:                                     result['overwrite'].push(alluploads[j]);
                   2659:                                 }
                   2660:                                 break;
                   2661:                             }
                   2662:                         }
                   2663:                     }
                   2664:                 }
                   2665:             }
                   2666:         }
                   2667:     }
                   2668:     if (allchecked.length > 0) {
                   2669:         if (allskipdel.length > 0) {
                   2670:             for (var n=0; n<allchecked.length; n++) {
                   2671:                 if (allskipdel.indexOf(allchecked[n]) == -1) {
                   2672:                     result['delete'].push(allchecked[n]);
                   2673:                 }
                   2674:             }
                   2675:         } else {
                   2676:             result['delete'].push.apply(result['delete'],allchecked);
                   2677:         }
                   2678:     }
                   2679:     return result;
                   2680: }
                   2681: 
                   2682: function check_for_multiples(prefix) {
                   2683: $multtext
                   2684: }
                   2685: 
                   2686: function check_for_turninpath(prefix) {
                   2687: $turninpathtext
                   2688: }
                   2689: 
                   2690: // ]]>
                   2691: </script>
                   2692: 
1.292     raeburn  2693: $arrayindexofjs
                   2694: 
1.291     raeburn  2695: ENDSCRIPT
                   2696: }
                   2697: 
                   2698: ##############################################
                   2699: ##############################################
                   2700: 
1.313     raeburn  2701: sub resize_scrollbox_js {
                   2702:     my ($context,$tabidstr) = @_;
                   2703:     my (%names,$paddingwfrac,$offsetwfrac,$offsetv,$minw,$minv);
                   2704:     if ($context eq 'docs') {
                   2705:         %names = (
                   2706:                    boxw   => 'contenteditor',
                   2707:                    item   => 'contentlist',
                   2708:                    header => 'uploadfileresult',
                   2709:                    scroll => 'contentscroll',
                   2710:                    boxh   => 'contenteditor',
                   2711:                  );
                   2712:         $paddingwfrac = 0.09; 
                   2713:         $offsetwfrac = 0.015;
                   2714:         $offsetv = 20;
                   2715:         $minw = 250;
                   2716:         $minv = 200;
                   2717:     } elsif ($context eq 'params') {
                   2718:         %names = (
                   2719:                    boxw   => 'parameditor',
                   2720:                    item   => 'mapmenuinner',
                   2721:                    header => 'parmstep1',
                   2722:                    scroll => 'mapmenuscroll',
                   2723:                    boxh   => 'parmlevel',
                   2724:                  );
                   2725:         $paddingwfrac = 0.2;
                   2726:         $offsetwfrac = 0.015;
                   2727:         $offsetv = 80;
                   2728:         $minw = 100;
                   2729:         $minv = 100; 
                   2730:     }
                   2731:     my $viewport_js = &Apache::loncommon::viewport_geometry_js();
                   2732:     my $output = '
                   2733: 
                   2734: window.onresize=callResize;
                   2735: 
                   2736: ';
                   2737:     if ($context eq 'docs') {
                   2738:         $output .= '
                   2739: var activeTab;
                   2740: ';
                   2741:     }
                   2742:     $output .=  <<"FIRST";
                   2743: 
                   2744: $viewport_js
                   2745: 
                   2746: function resize_scrollbox(scrollboxname,chkw,chkh) {
                   2747:     var scrollboxid = 'div_'+scrollboxname;
                   2748:     var scrolltableid = 'table_'+scrollboxname;
                   2749:     var scrollbox;
                   2750:     var scrolltable;
                   2751: 
                   2752:     if (document.getElementById("$names{'boxw'}") == null) {
                   2753:         return;
                   2754:     }
                   2755: 
                   2756:     if (document.getElementById(scrollboxid) == null) {
                   2757:         return;
                   2758:     } else {
                   2759:         scrollbox = document.getElementById(scrollboxid);
                   2760:     }
                   2761: 
                   2762: 
                   2763:     if (document.getElementById(scrolltableid) == null) {
                   2764:         return;
                   2765:     } else {
                   2766:         scrolltable = document.getElementById(scrolltableid);
                   2767:     }
                   2768: 
                   2769:     init_geometry();
                   2770:     var vph = Geometry.getViewportHeight();
                   2771:     var vpw = Geometry.getViewportWidth();
                   2772: 
                   2773: FIRST
                   2774:     if ($context eq 'docs') {
                   2775:         $output .= "
                   2776:     var alltabs = ['$tabidstr'];
                   2777: ";
                   2778:     } elsif ($context eq 'params') {
                   2779:         $output .= "
                   2780:     if (document.getElementById('$names{'boxh'}') == null) {
                   2781:         return;
                   2782:     }
                   2783: ";
                   2784:     }
                   2785:     $output .= <<"SECOND";
                   2786:     var listwchange;
                   2787:     if (chkw == 1) {
                   2788:         var boxw = document.getElementById("$names{'boxw'}").offsetWidth;
                   2789:         var itemw;
                   2790:         var itemid = document.getElementById("$names{'item'}");
                   2791:         if (itemid != null) {
                   2792:             itemw = itemid.offsetWidth;
                   2793:         }
                   2794:         var itemwstart = itemw;
                   2795: 
                   2796:         var scrollboxw = scrollbox.offsetWidth;
                   2797:         var scrollboxscrollw = scrollbox.scrollWidth;
                   2798: 
                   2799:         var offsetw = parseInt(vpw * $offsetwfrac);
                   2800:         var paddingw = parseInt(vpw * $paddingwfrac);
                   2801: 
                   2802:         var minscrollboxw = $minw;
                   2803:         var maxcolw = 0;
                   2804: SECOND
                   2805:     if ($context eq 'docs') {
                   2806:         $output .= <<"DOCSONE";
                   2807:         var actabw = 0;
                   2808:         for (var i=0; i<alltabs.length; i++) {
                   2809:             if (activeTab == alltabs[i]) {
                   2810:                 actabw = document.getElementById(alltabs[i]).offsetWidth;
                   2811:                 if (actabw > maxcolw) {
                   2812:                     maxcolw = actabw;
                   2813:                 }
                   2814:             } else {
                   2815:                 if (document.getElementById(alltabs[i]) != null) {
                   2816:                     var thistab = document.getElementById(alltabs[i]);
                   2817:                     thistab.style.visibility = 'hidden';
                   2818:                     thistab.style.display = 'block';
                   2819:                     var tabw = document.getElementById(alltabs[i]).offsetWidth;
                   2820:                     thistab.style.display = 'none';
                   2821:                     thistab.style.visibility = '';
                   2822:                     if (tabw > maxcolw) {
                   2823:                         maxcolw = tabw;
                   2824:                     }
                   2825:                 }
                   2826:             }
                   2827:         }
                   2828: DOCSONE
                   2829:     } elsif ($context eq 'params') {
                   2830:         $output .= <<"PARAMSONE";
                   2831:         var parmlevelrows = new Array();
                   2832:         var mapmenucells = new Array();
                   2833:         parmlevelrows = document.getElementById("$names{'boxh'}").rows;
                   2834:         var numrows = parmlevelrows.length;
                   2835:         if (numrows > 1) {
                   2836:             mapmenucells = parmlevelrows[2].getElementsByTagName('td');
                   2837:         }
                   2838:         maxcolw = mapmenucells[0].offsetWidth;
                   2839: PARAMSONE
                   2840:     }
                   2841:     $output .= <<"THIRD";
                   2842:         if (maxcolw > 0) {
                   2843:             var newscrollboxw;
                   2844:             if (maxcolw+paddingw+scrollboxscrollw<boxw) {
                   2845:                 newscrollboxw = boxw-paddingw-maxcolw;
                   2846:                 if (newscrollboxw < minscrollboxw) {
                   2847:                     newscrollboxw = minscrollboxw;
                   2848:                 }
                   2849:                 scrollbox.style.width = newscrollboxw+"px";
                   2850:                 if (newscrollboxw != scrollboxw) {
                   2851:                     var newitemw = newscrollboxw-offsetw;
                   2852:                     itemid.style.width = newitemw+"px";
                   2853:                 }
                   2854:             } else {
                   2855:                 newscrollboxw = boxw-paddingw-maxcolw;
                   2856:                 if (newscrollboxw < minscrollboxw) {
                   2857:                     newscrollboxw = minscrollboxw;
                   2858:                 }
                   2859:                 scrollbox.style.width = newscrollboxw+"px";
                   2860:                 if (newscrollboxw != scrollboxw) {
                   2861:                     var newitemw = newscrollboxw-offsetw;
                   2862:                     itemid.style.width = newitemw+"px";
                   2863:                 }
                   2864:             }
                   2865: 
                   2866:             if (newscrollboxw != scrollboxw) {
                   2867:                 var newscrolltablew = newscrollboxw+offsetw;
                   2868:                 scrolltable.style.width = newscrolltablew+"px";
                   2869:             }
                   2870:         }
                   2871: 
                   2872:         if (itemid.offsetWidth != itemwstart) {
                   2873:             listwchange = 1;
                   2874:         }
                   2875: THIRD
                   2876:     if ($context eq 'docs') {
                   2877:         $output .= <<"DOCSTWO";
                   2878:         if (activeTab == 'cc1') {
                   2879:             if (document.getElementById('cc_hrule') != null) {
                   2880:                 document.getElementById('cc_hrule').style.width=actabw+"px";
                   2881:             }
                   2882:         } else {
                   2883:             if (activeTab == 'bb1') {
                   2884:                 if (document.getElementById('bb_hrule') != null) {
                   2885:                     document.getElementById('bb_hrule').style.width=actabw+"px";
                   2886:                 }
                   2887:             } else {
                   2888:                 if (activeTab == 'ee2') {
                   2889:                     if (document.getElementById('ee_hrule') != null) {
                   2890:                         document.getElementById('ee_hrule').style.width=actabw+"px";
                   2891:                     }
                   2892:                 }
                   2893:             }
                   2894:         }
                   2895: DOCSTWO
                   2896:     }
                   2897:     $output .= <<"FOURTH";
                   2898:     }
                   2899:     if ((chkh == 1) || (listwchange)) {
                   2900:         var primaryheight = document.getElementById('LC_nav_bar').offsetHeight;
                   2901:         var secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight;
                   2902:         var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight;
                   2903:         var dccidheight = 0;
                   2904:         if (document.getElementById('dccid') != null) {
                   2905:             dccidheight = document.getElementById('dccid').offsetHeight;
                   2906:         }
                   2907:         var headerheight = 0;
                   2908:         if (document.getElementById("$names{'header'}") != null) {
                   2909:             headerheight = document.getElementById("$names{'header'}").offsetHeight;
                   2910:         }
                   2911:         var tabbedheight = document.getElementById("tabbededitor").offsetHeight;
                   2912:         var boxheight = document.getElementById("$names{'boxh'}").offsetHeight;
                   2913:         var freevspace = vph-(primaryheight+secondaryheight+crumbsheight+dccidheight+headerheight+tabbedheight+boxheight);
                   2914: 
                   2915:         var scrollboxheight = scrollbox.offsetHeight;
                   2916:         var scrollboxscrollheight = scrollbox.scrollHeight;
                   2917: 
                   2918:         var minvscrollbox = $minv;
                   2919:         var offsetv = $offsetv;
                   2920:         var newscrollboxheight;
                   2921:         if (freevspace < 0) {
                   2922:             newscrollboxheight = scrollboxheight+freevspace-offsetv;
                   2923:             if (newscrollboxheight < minvscrollbox) {
                   2924:                 newscrollboxheight = minvscrollbox;
                   2925:             }
                   2926:             scrollbox.style.height = newscrollboxheight + "px";
                   2927:         } else {
                   2928:             if (scrollboxscrollheight > scrollboxheight) {
                   2929:                 if (freevspace > offsetv) {
                   2930:                     newscrollboxheight = scrollboxheight+freevspace-offsetv;
                   2931:                     if (newscrollboxheight < minvscrollbox) {
                   2932:                         newscrollboxheight = minvscrollbox;
                   2933:                     }
                   2934:                     scrollbox.style.height = newscrollboxheight+"px";
                   2935:                 }
                   2936:             }
                   2937:         }
                   2938:         scrollboxheight = scrollbox.offsetHeight;
                   2939:         var itemh = document.getElementById("$names{'item'}").offsetHeight;
                   2940: 
                   2941:         if (scrollboxscrollheight <= scrollboxheight) {
                   2942:             if ((itemh+offsetv)<scrollboxheight) {
                   2943:                 newscrollheight = itemh+offsetv;
                   2944:                 scrollbox.style.height = newscrollheight+"px";
                   2945:             }
                   2946:         }
                   2947:     }
                   2948:     return;
                   2949: }
                   2950: 
                   2951: function callResize() {
                   2952:     var timer;
                   2953:     clearTimeout(timer);
                   2954:     timer=setTimeout('resize_scrollbox("$names{'scroll'}","1","1")',500);
                   2955: }
                   2956: 
                   2957: FOURTH
                   2958:     return $output;
                   2959: }
                   2960: 
                   2961: 
                   2962: ##############################################
                   2963: ##############################################
                   2964: 
1.158     raeburn  2965: # javascript_valid_email
                   2966: #
                   2967: # Generates javascript to validate an e-mail address.
                   2968: # Returns a javascript function which accetps a form field as argumnent, and
                   2969: # returns false if field.value does not satisfy two regular expression matches
                   2970: # for a valid e-mail address.  Backwards compatible with old browsers without
                   2971: # support for javascript RegExp (just checks for @ in field.value in this case). 
                   2972: 
                   2973: sub javascript_valid_email {
                   2974:     my $scripttag .= <<'END';
                   2975: function validmail(field) {
                   2976:     var str = field.value;
                   2977:     if (window.RegExp) {
                   2978:         var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
                   2979:         var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"; //"
                   2980:         var reg1 = new RegExp(reg1str);
                   2981:         var reg2 = new RegExp(reg2str);
                   2982:         if (!reg1.test(str) && reg2.test(str)) {
                   2983:             return true;
                   2984:         }
                   2985:         return false;
                   2986:     }
                   2987:     else
                   2988:     {
                   2989:         if(str.indexOf("@") >= 0) {
                   2990:             return true;
                   2991:         }
                   2992:         return false;
                   2993:     }
                   2994: }
                   2995: END
                   2996:     return $scripttag;
                   2997: }
                   2998: 
1.219     droeschl 2999: 
                   3000: # USAGE: htmltag(element, content, {attribute => value,...});
                   3001: #
                   3002: # EXAMPLES: 
                   3003: #  - htmltag('a', 'this is an anchor', {href  => 'www.example.com', 
                   3004: #                                       title => 'this is a title'})
                   3005: #
                   3006: #  - You might want to set up needed tags like: 
                   3007: #
                   3008: #     my $h3  = sub { return htmltag( "h3",  @_ ) };
                   3009: #
                   3010: #    ... and use them: $h3->("This is a headline")
                   3011: #
                   3012: #  - To set up a couple of tags, see sub inittags
                   3013: #
                   3014: # NOTES:
                   3015: # - Empty elements, such as <br/> are correctly terminated, 
                   3016: #   i.e. htmltag('br') returns <br/> 
                   3017: # - Empty attributes (title="") are filtered out.
                   3018: # - The function will not check for deprecated attributes.
                   3019: #
                   3020: # OUTPUT: content enclosed in xhtml conform tags
                   3021: sub htmltag{
                   3022:     return
                   3023:         qq|<$_[0]|
                   3024:         . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
                   3025:         . ($_[1] ? qq|>$_[1]</$_[0]>| : qq|/>|). "\n";
                   3026: };
                   3027: 
                   3028: 
                   3029: # USAGE: inittags(@tags);
                   3030: #
                   3031: # EXAMPLES:
1.261     droeschl 3032: #  - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
1.219     droeschl 3033: #    $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
                   3034: #
                   3035: # NOTES: See sub htmltag for further information.
                   3036: #
                   3037: # OUTPUT: List of subroutines. 
                   3038: sub inittags {
                   3039:     my @tags = @_;
                   3040:     return map { my $tag = $_;
                   3041:                  sub { return htmltag( $tag, @_ ) }
                   3042:                } @tags;
                   3043: }
                   3044: 
                   3045: 
1.231     droeschl 3046: # USAGE: scripttag(scriptcode, [start|end|both]);
1.229     droeschl 3047: #
                   3048: # EXAMPLES: 
1.231     droeschl 3049: #  - scripttag("alert('Hello World!')", 'both') 
                   3050: #    returns:
                   3051: #    <script type="text/javascript">
                   3052: #    // BEGIN LON-CAPA Internal
                   3053: #    alert(Hello World!')
                   3054: #    // END LON-CAPA Internal
                   3055: #    </script>
1.229     droeschl 3056: #
                   3057: # NOTES:
                   3058: # - works currently only for javascripts
                   3059: #
1.231     droeschl 3060: # OUTPUT: 
                   3061: # Scriptcode properly enclosed in <script> and CDATA tags (and LC
                   3062: # Internal markers if 2nd argument is given)
1.229     droeschl 3063: sub scripttag {
1.231     droeschl 3064:     my ( $content, $marker ) = @_;
                   3065:     return unless defined $content;
                   3066: 
                   3067:     my $begin = "\n// BEGIN LON-CAPA Internal\n";
                   3068:     my $end   = "\n// END LON-CAPA Internal\n";
                   3069: 
                   3070:     if ($marker) {
                   3071:         $content  = $begin . $content if $marker eq 'start' or $marker eq 'both';
                   3072:         $content .= $end              if $marker eq 'end'   or $marker eq 'both';
                   3073:     }
                   3074: 
1.229     droeschl 3075:     $content = "\n// <![CDATA[\n$content\n// ]]>\n";
1.231     droeschl 3076: 
                   3077:     return htmltag('script', $content, {type => 'text/javascript'});
1.229     droeschl 3078: };
                   3079: 
1.309     raeburn  3080: =pod
1.229     droeschl 3081: 
1.309     raeburn  3082: =item &list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
1.261     droeschl 3083: 
                   3084: Constructs a XHTML list from \@array.
                   3085: 
                   3086: input: 
                   3087: 
                   3088: =over
                   3089: 
                   3090: =item \@array 
                   3091: 
                   3092: A reference to the array containing text that will be wrapped in <li></li> tags.
                   3093: 
                   3094: =item { listattr => {}, itemattr =>{} } 
                   3095: 
                   3096: Attributes for <ul> and <li> passed in as hash references. 
                   3097: See htmltag() for more details.
                   3098: 
                   3099: =back
                   3100:  
                   3101: returns: XHTML list as String. 
                   3102: 
                   3103: =cut   
                   3104: 
                   3105: # \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
                   3106: sub list_from_array {
                   3107:     my ($items, $args) = @_;
1.285     raeburn  3108:     return unless (ref($items) eq 'ARRAY');
1.273     droeschl 3109:     return unless scalar @$items;
1.261     droeschl 3110:     my ($ul, $li) = inittags( qw(ul li) );
                   3111:     my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
                   3112:     return $ul->( $listitems, $args->{listattr} );
                   3113: }
                   3114: 
                   3115: 
1.183     droeschl 3116: ##############################################
                   3117: ##############################################
                   3118: 
                   3119: # generate_menu
                   3120: #
                   3121: # Generates html markup for a menu. 
                   3122: #
                   3123: # Inputs:
                   3124: # An array of following structure:
                   3125: #   ({	categorytitle => 'Categorytitle',
                   3126: #	items => [
1.201     droeschl 3127: #		    {	
                   3128: #           linktext    =>	'Text to be displayed',
                   3129: #			url	        =>	'URL the link is pointing to, i.e. /adm/site?action=dosomething',
1.183     droeschl 3130: #			permission  =>	'Contains permissions as returned from lonnet::allowed(),
1.201     droeschl 3131: #					         must evaluate to true in order to activate the link',
1.184     droeschl 3132: #			icon        =>  'icon filename',
1.186     droeschl 3133: #			alttext	    =>	'alt text for the icon',
1.183     droeschl 3134: #			help	    =>	'Name of the corresponding helpfile',
                   3135: #			linktitle   =>	'Description of the link (used for title tag)'
                   3136: #		    },
                   3137: #		    ...
                   3138: #		]
                   3139: #   }, 
                   3140: #   ...
                   3141: #   )
                   3142: #
                   3143: # Outputs: A scalar containing the html markup for the menu.
                   3144: 
                   3145: sub generate_menu {
                   3146:     my @menu = @_;
1.201     droeschl 3147:     # subs for specific html elements
1.219     droeschl 3148:     my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) ); 
1.201     droeschl 3149:     
                   3150:     my @categories; # each element represents the entire markup for a category
                   3151:    
                   3152:     foreach my $category (@menu) {
                   3153:         my @links;  # contains the links for the current $category
                   3154:         foreach my $link (@{$$category{items}}) {
                   3155:             next unless $$link{permission};
                   3156:             
                   3157:             # create the markup for the current $link and push it into @links.
                   3158:             # each entry consists of an image and a text optionally followed 
                   3159:             # by a help link.
1.283     raeburn  3160:             my $src;
                   3161:             if ($$link{icon} ne '') {
                   3162:                 $src = '/res/adm/pages/'.$$link{icon};
                   3163:             }
1.232     raeburn  3164:             push(@links,$li->(
1.201     droeschl 3165:                         $a->(
                   3166:                             $img->("", {
                   3167:                                 class => "LC_noBorder LC_middle",
1.283     raeburn  3168:                                 src   => $src,
1.202     droeschl 3169:                                 alt   => mt(defined($$link{alttext}) ?
                   3170:                                 $$link{alttext} : $$link{linktext})
1.201     droeschl 3171:                             }), {
                   3172:                             href  => $$link{url},
1.308     raeburn  3173:                             title => mt($$link{linktitle}),
                   3174:                             class => 'LC_menubuttons_link'
1.201     droeschl 3175:                             }).
1.202     droeschl 3176:                         $a->(mt($$link{linktext}), {
1.201     droeschl 3177:                             href  => $$link{url},
1.202     droeschl 3178:                             title => mt($$link{linktitle}),
1.201     droeschl 3179:                             class => "LC_menubuttons_link"
                   3180:                             }).
                   3181:                          (defined($$link{help}) ? 
                   3182:                          Apache::loncommon::help_open_topic($$link{help}) : ''),
1.232     raeburn  3183:                          {class => "LC_menubuttons_inline_text"}));
1.201     droeschl 3184:         }
                   3185: 
                   3186:         # wrap categorytitle in <h3>, concatenate with 
                   3187:         # joined and in <ul> tags wrapped @links
                   3188:         # and wrap everything in an enclosing <div> and push it into
                   3189:         # @categories
                   3190:         # such that each element looks like:
                   3191:         # <div><h3>title</h3><ul><li>...</li>...</ul></div>
                   3192:         # the category won't be added if there aren't any links
1.232     raeburn  3193:         push(@categories, 
1.202     droeschl 3194:             $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
1.201     droeschl 3195:             $ul->(join('' ,@links),  {class =>"LC_ListStyleNormal" }),
1.232     raeburn  3196:             {class=>"LC_Box LC_400Box"})) if scalar(@links);
1.183     droeschl 3197:     }
1.201     droeschl 3198: 
                   3199:     # wrap the joined @categories in another <div> (column layout)
                   3200:     return $div->(join('', @categories), {class => "LC_columnSection"});
1.183     droeschl 3201: }
1.176     foxr     3202: 
1.224     bisitz   3203: ##############################################
                   3204: ##############################################
                   3205: 
                   3206: =pod
                   3207: 
1.309     raeburn  3208: =item &start_funclist()
1.224     bisitz   3209: 
                   3210: Start list of available functions
                   3211: 
                   3212: Typically used to offer a simple list of available functions
                   3213: at top or bottom of page.
                   3214: All available functions/actions for the current page
                   3215: should be included in this list.
                   3216: 
                   3217: If the optional headline text is not provided, a default text will be used.
                   3218: 
                   3219: 
                   3220: Related routines:
                   3221: =over 4
                   3222: add_item_funclist
                   3223: end_funclist
                   3224: =back
                   3225: 
                   3226: 
                   3227: Inputs: (optional) headline text
                   3228: 
                   3229: Returns: HTML code with function list start
                   3230: 
                   3231: =cut
                   3232: 
                   3233: ##############################################
                   3234: ##############################################
                   3235: 
                   3236: sub start_funclist {
                   3237:     my($legendtext)=@_;
                   3238:     $legendtext=&mt('Functions') if !$legendtext;
1.244     droeschl 3239:     return '<ul class="LC_funclist"><li style="font-weight:bold; margin-left:0.8em;">'.$legendtext.'</li>'."\n";
1.224     bisitz   3240: }
                   3241: 
                   3242: 
                   3243: ##############################################
                   3244: ##############################################
                   3245: 
                   3246: =pod
                   3247: 
1.309     raeburn  3248: =item &add_item_funclist()
1.224     bisitz   3249: 
                   3250: Adds an item to the list of available functions
                   3251: 
                   3252: Related routines:
                   3253: =over 4
                   3254: start_funclist
                   3255: end_funclist
                   3256: =back
                   3257: 
                   3258: Inputs: content item with text and link to function
                   3259: 
                   3260: Returns: HTML code with list item for funclist
                   3261: 
                   3262: =cut
                   3263: 
                   3264: ##############################################
                   3265: ##############################################
                   3266: 
                   3267: sub add_item_funclist {
                   3268:     my($content) = @_;
                   3269:     return '<li>'.$content.'</li>'."\n";
                   3270: }
                   3271: 
                   3272: =pod
                   3273: 
1.309     raeburn  3274: =item &end_funclist()
1.224     bisitz   3275: 
                   3276: End list of available functions
                   3277: 
                   3278: Related routines:
                   3279: =over 4
                   3280: start_funclist
                   3281: add_item_funclist
                   3282: =back
                   3283: 
                   3284: Inputs: ./.
                   3285: 
                   3286: Returns: HTML code with function list end
                   3287: =cut
                   3288: 
                   3289: sub end_funclist {
1.246     bisitz   3290:     return "</ul>\n";
1.224     bisitz   3291: }
                   3292: 
1.261     droeschl 3293: =pod
                   3294: 
1.309     raeburn  3295: =item &funclist_from_array( \@array, {legend => 'text for legend'} )
1.261     droeschl 3296: 
                   3297: Constructs a XHTML list from \@array with the first item being visually
                   3298: highlighted and set to the value of legend or 'Functions' if legend is
                   3299: empty. 
                   3300: 
                   3301: =over
                   3302: 
                   3303: =item \@array
                   3304: 
                   3305: A reference to the array containing text that will be wrapped in <li></li> tags.
                   3306: 
                   3307: =item { legend => 'text' }
                   3308: 
                   3309: A string that's used as visually highlighted first item. 'Functions' is used if
                   3310: it's value evaluates to false.
                   3311: 
                   3312: =back
                   3313:  
                   3314: returns: XHTML list as string. 
                   3315: 
                   3316: =back
                   3317: 
                   3318: =cut  
                   3319: 
                   3320: sub funclist_from_array {
                   3321:     my ($items, $args) = @_;
1.285     raeburn  3322:     return unless(ref($items) eq 'ARRAY');
1.261     droeschl 3323:     $args->{legend} ||= mt('Functions');
                   3324:     return list_from_array( [$args->{legend}, @$items], 
                   3325:                { listattr => {class => 'LC_funclist'} });
                   3326: }   
                   3327: 
1.1       stredwic 3328: 1;
1.23      matthew  3329: 
1.1       stredwic 3330: __END__

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