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

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

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