--- loncom/interface/loncommon.pm 2007/08/30 16:03:29 1.573 +++ loncom/interface/loncommon.pm 2008/05/27 22:26:11 1.654 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.573 2007/08/30 16:03:29 raeburn Exp $ +# $Id: loncommon.pm,v 1.654 2008/05/27 22:26:11 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,6 +78,76 @@ my $readit; ## Global Variables ## + +# ----------------------------------------------- SSI with retries: +# + +=pod + +=head1 Server Side include with retries: + +=over 4 + +=item * &ssi_with_retries(resource,retries form) + +Performs an ssi with some number of retries. Retries continue either +until the result is ok or until the retry count supplied by the +caller is exhausted. + +Inputs: + +=over 4 + +resource - Identifies the resource to insert. + +retries - Count of the number of retries allowed. + +form - Hash that identifies the rendering options. + +=back + +Returns: + +=over 4 + +content - The content of the response. If retries were exhausted this is empty. + +response - The response from the last attempt (which may or may not have been successful. + +=back + +=back + +=cut + +sub ssi_with_retries { + my ($resource, $retries, %form) = @_; + + + my $ok = 0; # True if we got a good response. + my $content; + my $response; + + # Try to get the ssi done. within the retries count: + + do { + ($content, $response) = &Apache::lonnet::ssi($resource, %form); + $ok = $response->is_success; + if (!$ok) { + &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message); + } + $retries--; + } while (!$ok && ($retries > 0)); + + if (!$ok) { + $content = ''; # On error return an empty content. + } + return ($content, $response); + +} + + + # ----------------------------------------------- Filetypes/Languages/Copyright my %language; my %supported_language; @@ -214,14 +284,14 @@ BEGIN { =over 4 -=item * browser_and_searcher_javascript () +=item * &browser_and_searcher_javascript() XXReturns a string containing javascript with two functions, C and C. Returned string does not contain EscriptE tags. -=item * openbrowser(formname,elementname,only,omit) [javascript] +=item * &openbrowser(formname,elementname,only,omit) [javascript] inputs: formname, elementname, only, omit @@ -234,7 +304,7 @@ with the given extension. Can be a comm Specifying 'omit' will restrict the browser to NOT displaying files with the given extension. Can be a comma separated list. -=item * opensearcher(formname, elementname) [javascript] +=item * &opensearcher(formname,elementname) [javascript] Inputs: formname, elementname @@ -257,6 +327,7 @@ sub browser_and_searcher_javascript { } url += 'catalogmode=interactive&'; url += 'mode=$mode&'; + url += 'inhibitmenu=yes&'; url += 'form=' + formname + '&'; if (only != null) { url += 'only=' + only + '&'; @@ -318,7 +389,7 @@ sub storeresurl { unless ($resurl=~/^\/res/) { return 0; } $resurl=~s/\/$//; &Apache::lonnet::put('environment',{'lastresurl' => $resurl}); - &Apache::lonnet::appenv('environment.lastresurl' => $resurl); + &Apache::lonnet::appenv({'environment.lastresurl' => $resurl}); return 1; } @@ -367,7 +438,7 @@ sub selectstudent_link { return ''; } return "".&mt('Select User').""; + '","'.$udomele.'");'."'>".&mt('Select User').""; } if ($env{'request.role'}=~/^(au|dc|su)/) { return " +var stdeditbrowser; + +function openauthorbrowser(formname,udom) { + var url = '/adm/pickauthor?'; + url += 'form='+formname+'&roledom='+udom; + var title = 'Author_Browser'; + var options = 'scrollbars=1,resizable=1,menubar=0'; + options += ',width=700,height=600'; + stdeditbrowser = open(url,title,options,'1'); + stdeditbrowser.focus(); +} + + +ENDAUTHORBRW +} + sub coursebrowser_javascript { my ($domainfilter,$sec_element,$formname)=@_; my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role'); @@ -407,7 +497,7 @@ sub coursebrowser_javascript { '&cdomelement='+udom+ '&cnameelement='+desc; if (extra_element !=null && extra_element != '') { - if (formname == 'rolechoice') { + if (formname == 'rolechoice' || formname == 'studentform') { url += '&roleelement='+extra_element; if (domainfilter == null || domainfilter == '') { url += '&domainfilter='+extra_element; @@ -471,7 +561,10 @@ sub setsec_javascript { my ($sec_element,$formname) = @_; my $setsections = qq| function setSect(sectionlist) { - var sectionsArray = sectionlist.split(","); + var sectionsArray = new Array(); + if ((sectionlist != '') && (typeof sectionlist != "undefined")) { + sectionsArray = sectionlist.split(","); + } var numSections = sectionsArray.length; document.$formname.$sec_element.length = 0; if (numSections == 0) { @@ -510,6 +603,12 @@ sub selectcourse_link { '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course').""; } +sub selectauthor_link { + my ($form,$udom)=@_; + return ''. + &mt('Select Author').''; +} + sub check_uncheck_jscript { my $jscript = <<"ENDSCRT"; function checkAll(field) { @@ -538,13 +637,13 @@ ENDSCRT =pod -=item * linked_select_forms(...) +=item * &linked_select_forms(...) linked_select_forms returns a string containing a block and html for two \n"; - foreach my $value (sort(keys(%$hashref))) { + my @order = sort(keys(%{$hashref})); + if (ref($menuorder) eq 'ARRAY') { + @order = @{$menuorder}; + } + foreach my $value (@order) { $result.=" \n"; @@ -673,7 +785,12 @@ END $result .= $middletext; $result .= "