File:  [LON-CAPA] / loncom / interface / lonhtmlcommon.pm
Revision 1.348: download - view: text, annotated - select for diffs
Tue Jul 2 19:04:37 2013 UTC (10 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Disk quotas for authoring spaces.
  - Default is 500 MB, unless set at domain level, or individual user level.
  - Domain default set via "Blogs, personal web pages, webDAV/quotas, portfolio" in
    "Set domain configuration" by DC.
  - Quota for individual user's authoring space set via:
    "Create users or modify the roles and privileges of users" by DC
  - &display_usage() moved from portfolio.pm to lonhtmlcommon.pm to
    facilitate re-use. In portfolio.pm &display_portfolio_usage() now calls
    lonhtmlcommon::display_usage().

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

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